OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/accessibility/platform/ax_fake_caret_win.h" | 5 #include "ui/accessibility/platform/ax_system_caret_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/accessibility/ax_enums.h" | 10 #include "ui/accessibility/ax_enums.h" |
11 #include "ui/accessibility/platform/ax_platform_node_win.h" | 11 #include "ui/accessibility/platform/ax_platform_node_win.h" |
12 #include "ui/accessibility/platform/ax_platform_unique_id.h" | 12 #include "ui/accessibility/platform/ax_platform_unique_id.h" |
13 #include "ui/gfx/geometry/rect_conversions.h" | 13 #include "ui/gfx/geometry/rect_conversions.h" |
14 #include "ui/gfx/geometry/rect_f.h" | 14 #include "ui/gfx/geometry/rect_f.h" |
15 | 15 |
16 namespace ui { | 16 namespace ui { |
17 | 17 |
18 AXFakeCaretWin::AXFakeCaretWin(gfx::AcceleratedWidget event_target) | 18 AXSystemCaretWin::AXSystemCaretWin(gfx::AcceleratedWidget event_target) |
19 : event_target_(event_target) { | 19 : event_target_(event_target) { |
20 caret_ = static_cast<AXPlatformNodeWin*>(AXPlatformNodeWin::Create(this)); | 20 caret_ = static_cast<AXPlatformNodeWin*>(AXPlatformNodeWin::Create(this)); |
21 data_.id = GetNextAXPlatformNodeUniqueId(); | 21 data_.id = GetNextAXPlatformNodeUniqueId(); |
22 data_.role = AX_ROLE_CARET; | 22 data_.role = AX_ROLE_CARET; |
| 23 // |get_accState| should return 0 which means that the caret is visible. |
23 data_.state = 0; | 24 data_.state = 0; |
24 data_.SetName(L"caret"); | 25 // According to MSDN, "Edit" should be the name of the caret object. |
| 26 data_.SetName(L"Edit"); |
25 data_.offset_container_id = -1; | 27 data_.offset_container_id = -1; |
26 } | 28 } |
27 | 29 |
28 AXFakeCaretWin::~AXFakeCaretWin() { | 30 AXSystemCaretWin::~AXSystemCaretWin() { |
29 caret_->Destroy(); | 31 caret_->Destroy(); |
30 caret_ = nullptr; | 32 caret_ = nullptr; |
31 } | 33 } |
32 | 34 |
33 base::win::ScopedComPtr<IAccessible> AXFakeCaretWin::GetCaret() const { | 35 base::win::ScopedComPtr<IAccessible> AXSystemCaretWin::GetCaret() const { |
34 base::win::ScopedComPtr<IAccessible> caret_accessible; | 36 base::win::ScopedComPtr<IAccessible> caret_accessible; |
35 HRESULT hr = caret_->QueryInterface( | 37 HRESULT hr = caret_->QueryInterface( |
36 IID_IAccessible, | 38 IID_IAccessible, |
37 reinterpret_cast<void**>(caret_accessible.GetAddressOf())); | 39 reinterpret_cast<void**>(caret_accessible.GetAddressOf())); |
38 DCHECK(SUCCEEDED(hr)); | 40 DCHECK(SUCCEEDED(hr)); |
39 return caret_accessible; | 41 return caret_accessible; |
40 } | 42 } |
41 | 43 |
42 void AXFakeCaretWin::MoveCaretTo(const gfx::Rect& bounds) { | 44 void AXSystemCaretWin::MoveCaretTo(const gfx::Rect& bounds) { |
43 if (bounds.IsEmpty()) | 45 if (bounds.IsEmpty()) |
44 return; | 46 return; |
45 data_.location = gfx::RectF(bounds); | 47 data_.location = gfx::RectF(bounds); |
46 if (event_target_) { | 48 if (event_target_) { |
47 ::NotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, event_target_, OBJID_CARET, | 49 ::NotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, event_target_, OBJID_CARET, |
48 -data_.id); | 50 -data_.id); |
49 } | 51 } |
50 } | 52 } |
51 | 53 |
52 const AXNodeData& AXFakeCaretWin::GetData() const { | 54 const AXNodeData& AXSystemCaretWin::GetData() const { |
53 return data_; | 55 return data_; |
54 } | 56 } |
55 | 57 |
56 const ui::AXTreeData& AXFakeCaretWin::GetTreeData() const { | 58 const ui::AXTreeData& AXSystemCaretWin::GetTreeData() const { |
57 CR_DEFINE_STATIC_LOCAL(ui::AXTreeData, empty_data, ()); | 59 CR_DEFINE_STATIC_LOCAL(ui::AXTreeData, empty_data, ()); |
58 return empty_data; | 60 return empty_data; |
59 } | 61 } |
60 | 62 |
61 gfx::NativeWindow AXFakeCaretWin::GetTopLevelWidget() { | 63 gfx::NativeWindow AXSystemCaretWin::GetTopLevelWidget() { |
62 return nullptr; | 64 return nullptr; |
63 } | 65 } |
64 | 66 |
65 gfx::NativeViewAccessible AXFakeCaretWin::GetParent() { | 67 gfx::NativeViewAccessible AXSystemCaretWin::GetParent() { |
66 if (!event_target_) | 68 if (!event_target_) |
67 return nullptr; | 69 return nullptr; |
68 | 70 |
69 gfx::NativeViewAccessible parent; | 71 gfx::NativeViewAccessible parent; |
70 HRESULT hr = | 72 HRESULT hr = |
71 ::AccessibleObjectFromWindow(event_target_, OBJID_WINDOW, IID_IAccessible, | 73 ::AccessibleObjectFromWindow(event_target_, OBJID_WINDOW, IID_IAccessible, |
72 reinterpret_cast<void**>(&parent)); | 74 reinterpret_cast<void**>(&parent)); |
73 if (SUCCEEDED(hr)) | 75 if (SUCCEEDED(hr)) |
74 return parent; | 76 return parent; |
75 return nullptr; | 77 return nullptr; |
76 } | 78 } |
77 | 79 |
78 int AXFakeCaretWin::GetChildCount() { | 80 int AXSystemCaretWin::GetChildCount() { |
79 return 0; | 81 return 0; |
80 } | 82 } |
81 | 83 |
82 gfx::NativeViewAccessible AXFakeCaretWin::ChildAtIndex(int index) { | 84 gfx::NativeViewAccessible AXSystemCaretWin::ChildAtIndex(int index) { |
83 return nullptr; | 85 return nullptr; |
84 } | 86 } |
85 | 87 |
86 gfx::Rect AXFakeCaretWin::GetScreenBoundsRect() const { | 88 gfx::Rect AXSystemCaretWin::GetScreenBoundsRect() const { |
87 gfx::Rect bounds = ToEnclosingRect(data_.location); | 89 gfx::Rect bounds = ToEnclosingRect(data_.location); |
88 return bounds; | 90 return bounds; |
89 } | 91 } |
90 | 92 |
91 gfx::NativeViewAccessible AXFakeCaretWin::HitTestSync(int x, int y) { | 93 gfx::NativeViewAccessible AXSystemCaretWin::HitTestSync(int x, int y) { |
92 return nullptr; | 94 return nullptr; |
93 } | 95 } |
94 | 96 |
95 gfx::NativeViewAccessible AXFakeCaretWin::GetFocus() { | 97 gfx::NativeViewAccessible AXSystemCaretWin::GetFocus() { |
96 return nullptr; | 98 return nullptr; |
97 } | 99 } |
98 | 100 |
99 gfx::AcceleratedWidget AXFakeCaretWin::GetTargetForNativeAccessibilityEvent() { | 101 gfx::AcceleratedWidget |
| 102 AXSystemCaretWin::GetTargetForNativeAccessibilityEvent() { |
100 return event_target_; | 103 return event_target_; |
101 } | 104 } |
102 | 105 |
103 bool AXFakeCaretWin::AccessibilityPerformAction(const ui::AXActionData& data) { | 106 bool AXSystemCaretWin::AccessibilityPerformAction( |
| 107 const ui::AXActionData& data) { |
104 return false; | 108 return false; |
105 } | 109 } |
106 | 110 |
107 bool AXFakeCaretWin::ShouldIgnoreHoveredStateForTesting() { | 111 bool AXSystemCaretWin::ShouldIgnoreHoveredStateForTesting() { |
108 return true; | 112 return false; |
109 } | 113 } |
110 | 114 |
111 } // namespace ui | 115 } // namespace ui |
OLD | NEW |