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

Unified Diff: ui/views/accessibility/native_view_accessibility_base.cc

Issue 2119413004: a11y: Exclude children of nested keyboard accessible controls from a11y tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switch to OS-specific methods of ignoring a11y elements. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
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_;
}
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_win.cc ('k') | ui/views/accessibility/native_view_accessibility_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698