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