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_base.h" | 5 #include "ui/views/accessibility/native_view_accessibility_base.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "ui/events/event_utils.h" | 9 #include "ui/events/event_utils.h" |
10 #include "ui/gfx/native_widget_types.h" | 10 #include "ui/gfx/native_widget_types.h" |
11 #include "ui/views/controls/native/native_view_host.h" | 11 #include "ui/views/controls/native/native_view_host.h" |
12 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
13 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
14 | 14 |
15 namespace views { | 15 namespace views { |
16 | 16 |
17 namespace { | |
18 bool IsAccessibilityFocusableWhenEnabled(View* view) { | |
tapted
2017/05/24 11:05:31
nit: (if clang format lets you) blank line before
| |
19 return view->focus_behavior() != View::FocusBehavior::NEVER && | |
20 view->IsDrawn(); | |
21 } | |
22 | |
23 // Used to determine if a View should be ignored by accessibility clients by | |
24 // being a non-keyboard-focusable child of a keyboard-focusable ancestor. E.g., | |
25 // LabelButtons contain Labels, but a11y should just show that there's a button. | |
26 bool IsViewUnfocusableChildOfFocusableAncestor(View* view) { | |
27 if (IsAccessibilityFocusableWhenEnabled(view)) | |
28 return false; | |
29 | |
30 while (view->parent()) { | |
31 view = view->parent(); | |
32 if (IsAccessibilityFocusableWhenEnabled(view)) | |
33 return true; | |
34 } | |
35 return false; | |
36 } | |
37 } | |
tapted
2017/05/24 11:05:31
nit: // namespace
| |
38 | |
17 NativeViewAccessibilityBase::NativeViewAccessibilityBase(View* view) | 39 NativeViewAccessibilityBase::NativeViewAccessibilityBase(View* view) |
18 : view_(view), | 40 : view_(view), |
19 parent_widget_(nullptr), | 41 parent_widget_(nullptr), |
20 ax_node_(ui::AXPlatformNode::Create(this)) { | 42 ax_node_(ui::AXPlatformNode::Create(this)) { |
21 DCHECK(ax_node_); | 43 DCHECK(ax_node_); |
22 } | 44 } |
23 | 45 |
24 NativeViewAccessibilityBase::~NativeViewAccessibilityBase() { | 46 NativeViewAccessibilityBase::~NativeViewAccessibilityBase() { |
25 ax_node_->Destroy(); | 47 ax_node_->Destroy(); |
26 if (parent_widget_) | 48 if (parent_widget_) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 | 80 |
59 if (view_->IsAccessibilityFocusable()) | 81 if (view_->IsAccessibilityFocusable()) |
60 data_.AddState(ui::AX_STATE_FOCUSABLE); | 82 data_.AddState(ui::AX_STATE_FOCUSABLE); |
61 | 83 |
62 if (!view_->enabled()) | 84 if (!view_->enabled()) |
63 data_.AddState(ui::AX_STATE_DISABLED); | 85 data_.AddState(ui::AX_STATE_DISABLED); |
64 | 86 |
65 if (!view_->IsDrawn()) | 87 if (!view_->IsDrawn()) |
66 data_.AddState(ui::AX_STATE_INVISIBLE); | 88 data_.AddState(ui::AX_STATE_INVISIBLE); |
67 | 89 |
90 // Make sure this element is excluded from the a11y tree if there's a | |
91 // focusable parent. All keyboard focusable elements should be leaf nodes. | |
92 // Exceptions to this rule will themselves be accessibility focusable. | |
93 if (IsViewUnfocusableChildOfFocusableAncestor(view_)) | |
94 data_.role = ui::AX_ROLE_IGNORED; | |
68 return data_; | 95 return data_; |
69 } | 96 } |
70 | 97 |
71 int NativeViewAccessibilityBase::GetChildCount() { | 98 int NativeViewAccessibilityBase::GetChildCount() { |
72 int child_count = view_->child_count(); | 99 int child_count = view_->child_count(); |
73 | 100 |
74 std::vector<Widget*> child_widgets; | 101 std::vector<Widget*> child_widgets; |
75 PopulateChildWidgetVector(&child_widgets); | 102 PopulateChildWidgetVector(&child_widgets); |
76 child_count += child_widgets.size(); | 103 child_count += child_widgets.size(); |
77 | 104 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 child_widget_platform_node->GetDelegate()); | 246 child_widget_platform_node->GetDelegate()); |
220 if (child_widget_view_accessibility->parent_widget() != widget) | 247 if (child_widget_view_accessibility->parent_widget() != widget) |
221 child_widget_view_accessibility->SetParentWidget(widget); | 248 child_widget_view_accessibility->SetParentWidget(widget); |
222 } | 249 } |
223 | 250 |
224 result_child_widgets->push_back(child_widget); | 251 result_child_widgets->push_back(child_widget); |
225 } | 252 } |
226 } | 253 } |
227 | 254 |
228 } // namespace views | 255 } // namespace views |
OLD | NEW |