| 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.
|
|
|