OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/views/accessibility/native_view_accessibility.h" | 5 #include "ui/views/accessibility/native_view_accessibility.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "ui/events/event_utils.h" | 8 #include "ui/events/event_utils.h" |
9 #include "ui/gfx/native_widget_types.h" | 9 #include "ui/gfx/native_widget_types.h" |
10 #include "ui/views/controls/native/native_view_host.h" | 10 #include "ui/views/controls/native/native_view_host.h" |
11 #include "ui/views/view.h" | 11 #include "ui/views/view.h" |
12 #include "ui/views/widget/widget.h" | 12 #include "ui/views/widget/widget.h" |
13 | 13 |
14 namespace views { | 14 namespace views { |
15 | 15 |
16 #if defined(OS_MACOSX) | |
17 namespace { | |
18 | |
19 bool IsAccessibilityFocusableWhenEnabled(View* view) { | |
20 return view->focus_behavior() != View::FocusBehavior::NEVER && | |
21 view->IsDrawn(); | |
22 } | |
23 | |
24 bool ViewHasFocusableAncestor(View* parent) { | |
tapted
2016/11/29 03:12:49
nit: parent -> view (since it's not the parent tha
Patti Lor
2016/11/29 23:26:18
Done.
| |
25 while ((parent = parent->parent())) { | |
26 if (IsAccessibilityFocusableWhenEnabled(parent)) | |
27 return true; | |
28 } | |
29 return false; | |
30 } | |
31 } | |
tapted
2016/11/29 03:12:49
nit: // namespace (and and a blank line before,
Patti Lor
2016/11/29 23:26:18
Thanks - it seems to not let you if you've only go
| |
32 #endif | |
33 | |
16 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) | 34 #if !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) |
17 // static | 35 // static |
18 NativeViewAccessibility* NativeViewAccessibility::Create(View* view) { | 36 NativeViewAccessibility* NativeViewAccessibility::Create(View* view) { |
19 return new NativeViewAccessibility(view); | 37 return new NativeViewAccessibility(view); |
20 } | 38 } |
21 #endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) | 39 #endif // !defined(PLATFORM_HAS_NATIVE_VIEW_ACCESSIBILITY_IMPL) |
22 | 40 |
23 NativeViewAccessibility::NativeViewAccessibility(View* view) | 41 NativeViewAccessibility::NativeViewAccessibility(View* view) |
24 : view_(view), | 42 : view_(view), |
25 parent_widget_(nullptr), | 43 parent_widget_(nullptr), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 } | 91 } |
74 | 92 |
75 view_->GetAccessibleNodeData(&data_); | 93 view_->GetAccessibleNodeData(&data_); |
76 data_.location = gfx::RectF(view_->GetBoundsInScreen()); | 94 data_.location = gfx::RectF(view_->GetBoundsInScreen()); |
77 base::string16 description; | 95 base::string16 description; |
78 view_->GetTooltipText(gfx::Point(), &description); | 96 view_->GetTooltipText(gfx::Point(), &description); |
79 data_.AddStringAttribute(ui::AX_ATTR_DESCRIPTION, | 97 data_.AddStringAttribute(ui::AX_ATTR_DESCRIPTION, |
80 base::UTF16ToUTF8(description)); | 98 base::UTF16ToUTF8(description)); |
81 | 99 |
82 if (view_->IsAccessibilityFocusable()) | 100 if (view_->IsAccessibilityFocusable()) |
83 data_.state |= (1 << ui::AX_STATE_FOCUSABLE); | 101 data_.AddStateFlag(ui::AX_STATE_FOCUSABLE); |
84 | 102 |
85 if (!view_->enabled()) | 103 if (!view_->enabled()) |
86 data_.state |= (1 << ui::AX_STATE_DISABLED); | 104 data_.AddStateFlag(ui::AX_STATE_DISABLED); |
87 | 105 |
88 if (!view_->visible()) | 106 if (!view_->visible()) |
89 data_.state |= (1 << ui::AX_STATE_INVISIBLE); | 107 data_.AddStateFlag(ui::AX_STATE_INVISIBLE); |
108 | |
109 #if defined(OS_MACOSX) | |
110 // Make sure this element is ignored if there's a focusable parent. All | |
111 // keyboard focusable elements should be leaf nodes in the accessibility tree. | |
112 // Exceptions to this rule will themselves be accessibility focusable. | |
113 if (!IsAccessibilityFocusableWhenEnabled(view_) && | |
114 ViewHasFocusableAncestor(view_)) | |
115 data_.role = ui::AX_ROLE_UNKNOWN; | |
116 #endif | |
90 | 117 |
91 return data_; | 118 return data_; |
92 } | 119 } |
93 | 120 |
94 int NativeViewAccessibility::GetChildCount() { | 121 int NativeViewAccessibility::GetChildCount() { |
95 int child_count = view_->child_count(); | 122 int child_count = view_->child_count(); |
96 | 123 |
97 std::vector<Widget*> child_widgets; | 124 std::vector<Widget*> child_widgets; |
98 PopulateChildWidgetVector(&child_widgets); | 125 PopulateChildWidgetVector(&child_widgets); |
99 child_count += child_widgets.size(); | 126 child_count += child_widgets.size(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 return view_->GetWidget()->GetNativeView(); | 160 return view_->GetWidget()->GetNativeView(); |
134 #endif | 161 #endif |
135 | 162 |
136 if (parent_widget_) | 163 if (parent_widget_) |
137 return parent_widget_->GetRootView()->GetNativeViewAccessible(); | 164 return parent_widget_->GetRootView()->GetNativeViewAccessible(); |
138 | 165 |
139 return nullptr; | 166 return nullptr; |
140 } | 167 } |
141 | 168 |
142 gfx::Vector2d NativeViewAccessibility::GetGlobalCoordinateOffset() { | 169 gfx::Vector2d NativeViewAccessibility::GetGlobalCoordinateOffset() { |
143 return gfx::Vector2d(0, 0); // location is already in screen coordinates. | 170 return gfx::Vector2d(0, 0); // Location is already in screen coordinates. |
144 } | 171 } |
145 | 172 |
146 gfx::NativeViewAccessible NativeViewAccessibility::HitTestSync(int x, int y) { | 173 gfx::NativeViewAccessible NativeViewAccessibility::HitTestSync(int x, int y) { |
147 if (!view_ || !view_->GetWidget()) | 174 if (!view_ || !view_->GetWidget()) |
148 return nullptr; | 175 return nullptr; |
149 | 176 |
150 // Search child widgets first, since they're on top in the z-order. | 177 // Search child widgets first, since they're on top in the z-order. |
151 std::vector<Widget*> child_widgets; | 178 std::vector<Widget*> child_widgets; |
152 PopulateChildWidgetVector(&child_widgets); | 179 PopulateChildWidgetVector(&child_widgets); |
153 for (Widget* child_widget : child_widgets) { | 180 for (Widget* child_widget : child_widgets) { |
154 View* child_root_view = child_widget->GetRootView(); | 181 View* child_root_view = child_widget->GetRootView(); |
155 gfx::Point point(x, y); | 182 gfx::Point point(x, y); |
156 View::ConvertPointFromScreen(child_root_view, &point); | 183 View::ConvertPointFromScreen(child_root_view, &point); |
157 if (child_root_view->HitTestPoint(point)) | 184 if (child_root_view->HitTestPoint(point)) |
158 return child_root_view->GetNativeViewAccessible(); | 185 return child_root_view->GetNativeViewAccessible(); |
159 } | 186 } |
160 | 187 |
161 gfx::Point point(x, y); | 188 gfx::Point point(x, y); |
162 View::ConvertPointFromScreen(view_, &point); | 189 View::ConvertPointFromScreen(view_, &point); |
163 if (!view_->HitTestPoint(point)) | 190 if (!view_->HitTestPoint(point)) |
164 return nullptr; | 191 return nullptr; |
165 | 192 |
166 // Check if the point is within any of the immediate children of this | 193 // Check if the point is within any of the immediate children of this view. We |
167 // view. We don't have to search further because AXPlatformNode will | 194 // don't have to search further because AXPlatformNodeWin will do a recursive |
168 // do a recursive hit test if we return anything other than |this| or NULL. | 195 // hit test if we return anything other than GetNativeObject() or nullptr. |
169 for (int i = view_->child_count() - 1; i >= 0; --i) { | 196 for (int i = view_->child_count() - 1; i >= 0; --i) { |
170 View* child_view = view_->child_at(i); | 197 View* child_view = view_->child_at(i); |
171 if (!child_view->visible()) | 198 if (!child_view->visible()) |
172 continue; | 199 continue; |
173 | 200 |
174 gfx::Point point_in_child_coords(point); | 201 gfx::Point point_in_child_coords(point); |
175 view_->ConvertPointToTarget(view_, child_view, &point_in_child_coords); | 202 view_->ConvertPointToTarget(view_, child_view, &point_in_child_coords); |
176 if (child_view->HitTestPoint(point_in_child_coords)) | 203 if (child_view->HitTestPoint(point_in_child_coords)) |
177 return child_view->GetNativeViewAccessible(); | 204 return child_view->GetNativeViewAccessible(); |
178 } | 205 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 child_widget_platform_node->GetDelegate()); | 303 child_widget_platform_node->GetDelegate()); |
277 if (child_widget_view_accessibility->parent_widget() != widget) | 304 if (child_widget_view_accessibility->parent_widget() != widget) |
278 child_widget_view_accessibility->SetParentWidget(widget); | 305 child_widget_view_accessibility->SetParentWidget(widget); |
279 } | 306 } |
280 | 307 |
281 result_child_widgets->push_back(child_widget); | 308 result_child_widgets->push_back(child_widget); |
282 } | 309 } |
283 } | 310 } |
284 | 311 |
285 } // namespace views | 312 } // namespace views |
OLD | NEW |