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

Unified Diff: ui/views/accessibility/native_view_accessibility.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: Before revert of cross-platform ignored a11y elements. Created 4 years, 2 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.cc
diff --git a/ui/views/accessibility/native_view_accessibility.cc b/ui/views/accessibility/native_view_accessibility.cc
index a984c3c6c08c901fbe65b13d87166e5c075d3a78..3af5f52fef15530d6404de36c842d5b6b9dc552f 100644
--- a/ui/views/accessibility/native_view_accessibility.cc
+++ b/ui/views/accessibility/native_view_accessibility.cc
@@ -96,7 +96,16 @@ const ui::AXNodeData& NativeViewAccessibility::GetData() {
}
int NativeViewAccessibility::GetChildCount() {
- int child_count = view_->child_count();
+ int child_count = 0;
+ for (int i = 0; i < view_->child_count(); ++i) {
+ View* child = view_->child_at(i);
+ if (child->GetNativeViewAccessibility()->IsIgnored()) {
+ // If not visible to accessibility clients, then use the children instead.
+ child_count += child->GetNativeViewAccessibility()->GetChildCount();
+ } else {
+ ++child_count;
+ }
+ }
std::vector<Widget*> child_widgets;
PopulateChildWidgetVector(&child_widgets);
@@ -106,14 +115,32 @@ int NativeViewAccessibility::GetChildCount() {
}
gfx::NativeViewAccessible NativeViewAccessibility::ChildAtIndex(int index) {
- // If this is a root view, our widget might have child widgets. Include
+ if (IsLeafElement())
+ return nullptr;
+
+ // Include the child widgets that may be present if this is a root view.
std::vector<Widget*> child_widgets;
PopulateChildWidgetVector(&child_widgets);
int child_widget_count = static_cast<int>(child_widgets.size());
- if (index < view_->child_count()) {
- return view_->child_at(index)->GetNativeViewAccessible();
- } else if (index < view_->child_count() + child_widget_count) {
+ int ax_child_count = GetChildCount();
+ if (index < ax_child_count) {
+ int curr_child_count = 0;
+ for (int i = 0; i < view_->child_count(); ++i) {
+ View* child = view_->child_at(i);
+ bool ignored = child->GetNativeViewAccessibility()->IsIgnored();
+ int pending_children =
+ ignored ? child->GetNativeViewAccessibility()->GetChildCount() : 1;
+ if (index < curr_child_count + pending_children) {
+ if (ignored) {
+ return child->GetNativeViewAccessibility()->ChildAtIndex(
+ index - curr_child_count);
+ }
+ return child->GetNativeViewAccessible();
+ }
+ curr_child_count += pending_children;
+ }
+ } else if (index < ax_child_count + child_widget_count) {
Widget* child_widget = child_widgets[index - view_->child_count()];
return child_widget->GetRootView()->GetNativeViewAccessible();
}
@@ -128,8 +155,13 @@ gfx::NativeWindow NativeViewAccessibility::GetTopLevelWidget() {
}
gfx::NativeViewAccessible NativeViewAccessibility::GetParent() {
- if (view_->parent())
- return view_->parent()->GetNativeViewAccessible();
+ View* parent_view = view_->parent();
+ if (parent_view) {
+ if (parent_view->GetNativeViewAccessibility()->IsIgnored())
+ return parent_view->GetNativeViewAccessibility()->GetParent();
+ else
+ return parent_view->GetNativeViewAccessible();
+ }
// TODO: move this to NativeViewAccessibilityMac.
#if defined(OS_MACOSX)
@@ -162,14 +194,20 @@ gfx::NativeViewAccessible NativeViewAccessibility::HitTestSync(int x, int y) {
return child_root_view->GetNativeViewAccessible();
}
+ if (IsLeafElement()) {
+ if (IsIgnored())
+ return GetParent();
+ return GetNativeObject();
+ }
+
gfx::Point point(x, y);
View::ConvertPointFromScreen(view_, &point);
if (!view_->HitTestPoint(point))
return nullptr;
- // Check if the point is within any of the immediate children of this
- // view. We don't have to search further because AXPlatformNode will
- // do a recursive hit test if we return anything other than |this| or NULL.
+ // Check if the point is within any of the immediate children of this view. We
+ // don't have to search further because AXPlatformNodeWin will do a recursive
+ // hit test if we return anything other than |GetNativeObject()| or nullptr.
for (int i = view_->child_count() - 1; i >= 0; --i) {
View* child_view = view_->child_at(i);
if (!child_view->visible())
@@ -245,6 +283,18 @@ void NativeViewAccessibility::SetParentWidget(Widget* parent_widget) {
parent_widget_->AddObserver(this);
}
+bool NativeViewAccessibility::IsLeafElement() {
+ if (GetChildCount() != 0)
+ return false;
+ return true;
+}
+
+bool NativeViewAccessibility::IsIgnored() {
+ if (view_->focus_behavior() == ClientView::FocusBehavior::NEVER)
+ return true;
+ return false;
+}
+
void NativeViewAccessibility::PopulateChildWidgetVector(
std::vector<Widget*>* result_child_widgets) {
// Only attach child widgets to the root view.
« no previous file with comments | « ui/views/accessibility/native_view_accessibility.h ('k') | ui/views/accessibility/native_view_accessibility_auralinux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698