Chromium Code Reviews| Index: ui/views/accessibility/native_view_accessibility_base.cc |
| diff --git a/ui/views/accessibility/native_view_accessibility_base.cc b/ui/views/accessibility/native_view_accessibility_base.cc |
| index b1feda15fed7f03f4589ae7ac0405febe6064a5e..48f733a3991191fcc5c763eb5d1e1a714a528703 100644 |
| --- a/ui/views/accessibility/native_view_accessibility_base.cc |
| +++ b/ui/views/accessibility/native_view_accessibility_base.cc |
| @@ -14,6 +14,28 @@ |
| namespace views { |
| +namespace { |
| +bool IsAccessibilityFocusableWhenEnabled(View* view) { |
|
tapted
2017/05/24 11:05:31
nit: (if clang format lets you) blank line before
|
| + return view->focus_behavior() != View::FocusBehavior::NEVER && |
| + view->IsDrawn(); |
| +} |
| + |
| +// Used to determine if a View should be ignored by accessibility clients by |
| +// being a non-keyboard-focusable child of a keyboard-focusable ancestor. E.g., |
| +// LabelButtons contain Labels, but a11y should just show that there's a button. |
| +bool IsViewUnfocusableChildOfFocusableAncestor(View* view) { |
| + if (IsAccessibilityFocusableWhenEnabled(view)) |
| + return false; |
| + |
| + while (view->parent()) { |
| + view = view->parent(); |
| + if (IsAccessibilityFocusableWhenEnabled(view)) |
| + return true; |
| + } |
| + return false; |
| +} |
| +} |
|
tapted
2017/05/24 11:05:31
nit: // namespace
|
| + |
| NativeViewAccessibilityBase::NativeViewAccessibilityBase(View* view) |
| : view_(view), |
| parent_widget_(nullptr), |
| @@ -65,6 +87,11 @@ const ui::AXNodeData& NativeViewAccessibilityBase::GetData() const { |
| if (!view_->IsDrawn()) |
| data_.AddState(ui::AX_STATE_INVISIBLE); |
| + // Make sure this element is excluded from the a11y tree if there's a |
| + // focusable parent. All keyboard focusable elements should be leaf nodes. |
| + // Exceptions to this rule will themselves be accessibility focusable. |
| + if (IsViewUnfocusableChildOfFocusableAncestor(view_)) |
| + data_.role = ui::AX_ROLE_IGNORED; |
| return data_; |
| } |