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