Commit abd56651 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

views: return correct AXRelativeBounds for table rows and cells

Despite the name, AXRelativeBounds are actually the absolute bounds
when used with Views views. The code in TableView was treating them
as though they were relative, which led to table rows and cells
having their virtual positions near the origin of the screen. After
this change, they are correctly positioned.

This change also implements AXVirtualView::GetNSWindow, which is
being called by VoiceOver when navigating these table cells. It
doesn't seem to matter whether it returns a correct value or not
but having it NOTREACHED() causes the browser to crash in dcheck
builds, which is bad.

Bug: 1009024
Change-Id: I67c0cd05786896de873fc8a36129cd2f0f3dff75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1894308
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712210}
parent 76cf90bd
......@@ -290,6 +290,7 @@ jumbo_component("views") {
"accessibility/ax_event_manager.cc",
"accessibility/ax_event_observer.cc",
"accessibility/ax_virtual_view.cc",
"accessibility/ax_virtual_view_mac.mm",
"accessibility/view_accessibility.cc",
"accessibility/view_accessibility_utils.cc",
"accessible_pane_view.cc",
......
......@@ -240,10 +240,12 @@ gfx::NativeViewAccessible AXVirtualView::ChildAtIndex(int index) {
return nullptr;
}
#if !defined(OS_MACOSX)
gfx::NativeViewAccessible AXVirtualView::GetNSWindow() {
NOTREACHED();
return nullptr;
}
#endif
gfx::NativeViewAccessible AXVirtualView::GetNativeViewAccessible() {
return GetNativeObject();
......
......@@ -123,7 +123,8 @@ class VIEWS_EXPORT AXVirtualView : public ui::AXPlatformNodeDelegateBase {
base::RepeatingCallback<void(const View&, ui::AXNodeData*)> callback);
void UnsetPopulateDataCallback();
// ui::AXPlatformNodeDelegate
// ui::AXPlatformNodeDelegate. Note that some of these functions have
// Mac-specific implementations in ax_virtual_view_mac.mm.
const ui::AXNodeData& GetData() const override;
int GetChildCount() override;
gfx::NativeViewAccessible ChildAtIndex(int index) override;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/accessibility/ax_virtual_view.h"
#include "ui/views/cocoa/native_widget_mac_ns_window_host.h"
#include "ui/views/widget/widget.h"
namespace views {
gfx::NativeViewAccessible AXVirtualView::GetNSWindow() {
View* owner = GetOwnerView();
if (!owner)
return nil;
Widget* widget = owner->GetWidget();
if (!widget)
return nil;
auto* window_host = NativeWidgetMacNSWindowHost::GetFromNativeWindow(
widget->GetNativeWindow());
if (!window_host)
return nil;
return window_host->GetNativeViewAccessibleForNSWindow();
}
} // namespace views
......@@ -1201,7 +1201,7 @@ void TableView::UpdateVirtualAccessibilityChildren() {
ui::AXNodeData& header_data = ax_header->GetCustomData();
header_data.role = ax::mojom::Role::kRow;
header_data.relative_bounds.bounds =
gfx::RectF(header_->GetVisibleBounds());
AdjustRectForAXRelativeBounds(header_->GetVisibleBounds());
for (size_t visible_column_index = 0;
visible_column_index < visible_columns_.size();
......@@ -1215,7 +1215,8 @@ void TableView::UpdateVirtualAccessibilityChildren() {
cell_data.SetName(column.title);
gfx::Rect header_cell_bounds(visible_column.x, header_->y(),
visible_column.width, header_->height());
cell_data.relative_bounds.bounds = gfx::RectF(header_cell_bounds);
cell_data.relative_bounds.bounds =
AdjustRectForAXRelativeBounds(header_cell_bounds);
cell_data.AddIntAttribute(ax::mojom::IntAttribute::kTableCellColumnIndex,
static_cast<int32_t>(visible_column_index));
cell_data.AddIntAttribute(ax::mojom::IntAttribute::kTableCellColumnSpan,
......@@ -1260,7 +1261,7 @@ void TableView::UpdateVirtualAccessibilityChildren() {
row_data.AddIntAttribute(ax::mojom::IntAttribute::kTableRowIndex,
static_cast<int32_t>(view_index));
gfx::Rect row_bounds = GetRowBounds(view_index);
row_data.relative_bounds.bounds = gfx::RectF(row_bounds);
row_data.relative_bounds.bounds = AdjustRectForAXRelativeBounds(row_bounds);
if (!single_selection_)
row_data.AddState(ax::mojom::State::kMultiselectable);
......@@ -1291,7 +1292,8 @@ void TableView::UpdateVirtualAccessibilityChildren() {
if (PlatformStyle::kTableViewSupportsKeyboardNavigationByCell)
cell_data.AddState(ax::mojom::State::kFocusable);
gfx::Rect cell_bounds = GetCellBounds(view_index, visible_column_index);
cell_data.relative_bounds.bounds = gfx::RectF(cell_bounds);
cell_data.relative_bounds.bounds =
AdjustRectForAXRelativeBounds(cell_bounds);
cell_data.AddIntAttribute(ax::mojom::IntAttribute::kTableCellRowIndex,
static_cast<int32_t>(view_index));
......@@ -1412,6 +1414,11 @@ AXVirtualView* TableView::GetVirtualAccessibilityCell(
return i->get();
}
gfx::RectF TableView::AdjustRectForAXRelativeBounds(gfx::Rect rect) const {
View::ConvertRectToScreen(this, &rect);
return gfx::RectF(rect);
}
DEFINE_ENUM_CONVERTERS(TableTypes,
{TableTypes::TEXT_ONLY, base::ASCIIToUTF16("TEXT_ONLY")},
{TableTypes::ICON_AND_TEXT,
......
......@@ -357,6 +357,10 @@ class VIEWS_EXPORT TableView
// |visible_column_index| indexes into |visible_columns_|.
AXVirtualView* GetVirtualAccessibilityCell(int row, int visible_column_index);
// Returns |rect|, adjusted for use in AXRelativeBounds by converting it to
// gfx::RectF and translating it into screen coordinates.
gfx::RectF AdjustRectForAXRelativeBounds(gfx::Rect rect) const;
ui::TableModel* model_ = nullptr;
std::vector<ui::TableColumn> columns_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment