Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: ui/accessibility/platform/ax_fake_caret_win.cc

Issue 2781613003: Added a class acting as a fake caret for accessibility. (Closed)
Patch Set: Added lib to build file. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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 {
17
18 base::LazyInstance<ui::AXFakeCaretWin>::Leaky g_ax_fake_caret_win =
19 LAZY_INSTANCE_INITIALIZER;
20
21 } // namespace
22
23 namespace ui {
24
25 AXFakeCaretWin::AXFakeCaretWin() : event_target_(gfx::kNullAcceleratedWidget) {
26 caret_ = static_cast<AXPlatformNodeWin*>(AXPlatformNodeWin::Create(this));
27 data_.id = GetNextAXPlatformNodeUniqueId();
28 data_.role = AX_ROLE_CARET;
29 data_.state = 0;
30 data_.SetName(L"caret");
31 data_.offset_container_id = -1;
32 }
33
34 AXFakeCaretWin::~AXFakeCaretWin() {
35 caret_->Destroy();
36 caret_ = nullptr;
37 }
38
39 // static
40 AXFakeCaretWin* AXFakeCaretWin::Get() {
41 return g_ax_fake_caret_win.Pointer();
42 }
43
44 base::win::ScopedComPtr<IAccessible> AXFakeCaretWin::GetCaret() const {
45 base::win::ScopedComPtr<IAccessible> caret_accessible;
46 HRESULT hr = caret_->QueryInterface(
47 IID_IAccessible, reinterpret_cast<void**>(caret_accessible.Receive()));
48 DCHECK(SUCCEEDED(hr));
49 return caret_accessible;
50 }
51
52 void AXFakeCaretWin::MoveCaretTo(gfx::Rect bounds) {
53 data_.location = gfx::RectF(bounds);
54 if (event_target_) {
55 ::NotifyWinEvent(EVENT_OBJECT_LOCATIONCHANGE, event_target_, OBJID_CARET,
56 -data_.id);
57 }
58 }
59
60 void AXFakeCaretWin::SetTargetForNativeAccessibilityEvent(
61 gfx::AcceleratedWidget event_target) {
62 event_target_ = event_target;
dmazzoni 2017/04/21 21:06:30 So yeah, my suggestion would be that rather than m
63 }
64
65 const AXNodeData& AXFakeCaretWin::GetData() const {
66 return data_;
67 }
68
69 gfx::NativeWindow AXFakeCaretWin::GetTopLevelWidget() {
70 return nullptr;
71 }
72
73 gfx::NativeViewAccessible AXFakeCaretWin::GetParent() {
74 if (!event_target_)
75 return nullptr;
76
77 gfx::NativeViewAccessible parent;
78 HRESULT hr =
79 ::AccessibleObjectFromWindow(event_target_, OBJID_WINDOW, IID_IAccessible,
80 reinterpret_cast<void**>(&parent));
81 if (SUCCEEDED(hr))
82 return parent;
83 return nullptr;
84 }
85
86 int AXFakeCaretWin::GetChildCount() {
87 return 0;
88 }
89
90 gfx::NativeViewAccessible AXFakeCaretWin::ChildAtIndex(int index) {
91 return nullptr;
92 }
93
94 gfx::Rect AXFakeCaretWin::GetScreenBoundsRect() const {
95 gfx::Rect bounds = ToEnclosingRect(data_.location);
96 return bounds;
97 }
98
99 gfx::NativeViewAccessible AXFakeCaretWin::HitTestSync(int x, int y) {
100 return nullptr;
101 }
102
103 gfx::NativeViewAccessible AXFakeCaretWin::GetFocus() {
104 return nullptr;
105 }
106
107 gfx::AcceleratedWidget AXFakeCaretWin::GetTargetForNativeAccessibilityEvent() {
108 return event_target_;
109 }
110
111 bool AXFakeCaretWin::AccessibilityPerformAction(const ui::AXActionData& data) {
112 return false;
113 }
114
115 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698