Skip to content

Commit

Permalink
Refactoring AXNodeData to use AXRelativeBounds.
Browse files Browse the repository at this point in the history
R=dmazzoni, aboxhall

Change-Id: Iaaf842abe6071fc63550ee6ae68442b719597002
Reviewed-on: https://chromium-review.googlesource.com/c/1278623
Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: Luke Halliwell <halliwell@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Chris Hall <chrishall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607795}
  • Loading branch information
Chris Hall authored and Commit Bot committed Nov 13, 2018
1 parent bf310bd commit d83381a
Show file tree
Hide file tree
Showing 56 changed files with 390 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,9 @@ void AccessibilityNodeInfoDataWrapper::Serialize(
: wm_helper->GetActiveWindow();
const gfx::Rect& local_bounds = tree_source_->GetBounds(
tree_source_->GetFromId(GetId()), active_window);
out_data->location.SetRect(local_bounds.x(), local_bounds.y(),
local_bounds.width(), local_bounds.height());
out_data->relative_bounds.bounds.SetRect(local_bounds.x(), local_bounds.y(),
local_bounds.width(),
local_bounds.height());
}

// Integer properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ void AccessibilityWindowInfoDataWrapper::Serialize(
: wm_helper->GetActiveWindow();
const gfx::Rect& local_bounds = tree_source_->GetBounds(
tree_source_->GetFromId(GetId()), active_window);
out_data->location.SetRect(local_bounds.x(), local_bounds.y(),
local_bounds.width(), local_bounds.height());
out_data->relative_bounds.bounds.SetRect(local_bounds.x(), local_bounds.y(),
local_bounds.width(),
local_bounds.height());
}

// Not all properties are currently used in Chrome Accessibility.
Expand Down
4 changes: 1 addition & 3 deletions chrome/common/extensions/chrome_extension_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ IPC_STRUCT_TRAITS_BEGIN(ui::AXNodeData)
IPC_STRUCT_TRAITS_MEMBER(role)
IPC_STRUCT_TRAITS_MEMBER(state)
IPC_STRUCT_TRAITS_MEMBER(actions)
IPC_STRUCT_TRAITS_MEMBER(location)
IPC_STRUCT_TRAITS_MEMBER(transform)
IPC_STRUCT_TRAITS_MEMBER(string_attributes)
IPC_STRUCT_TRAITS_MEMBER(int_attributes)
IPC_STRUCT_TRAITS_MEMBER(float_attributes)
Expand All @@ -46,7 +44,7 @@ IPC_STRUCT_TRAITS_BEGIN(ui::AXNodeData)
IPC_STRUCT_TRAITS_MEMBER(stringlist_attributes)
IPC_STRUCT_TRAITS_MEMBER(html_attributes)
IPC_STRUCT_TRAITS_MEMBER(child_ids)
IPC_STRUCT_TRAITS_MEMBER(offset_container_id)
IPC_STRUCT_TRAITS_MEMBER(relative_bounds)
IPC_STRUCT_TRAITS_END()

IPC_STRUCT_TRAITS_BEGIN(ui::AXTreeData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,9 @@ void AutomationInternalCustomBindings::AddRoutes() {
}

// Use character offsets to compute the local bounds of this subrange.
gfx::RectF local_bounds(0, 0, node->data().location.width(),
node->data().location.height());
gfx::RectF local_bounds(0, 0,
node->data().relative_bounds.bounds.width(),
node->data().relative_bounds.bounds.height());
std::string name =
node->data().GetStringAttribute(ax::mojom::StringAttribute::kName);
std::vector<int> character_offsets = node->data().GetIntListAttribute(
Expand Down
4 changes: 1 addition & 3 deletions chromecast/common/extensions_api/cast_extension_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ IPC_STRUCT_TRAITS_BEGIN(ui::AXNodeData)
IPC_STRUCT_TRAITS_MEMBER(role)
IPC_STRUCT_TRAITS_MEMBER(state)
IPC_STRUCT_TRAITS_MEMBER(actions)
IPC_STRUCT_TRAITS_MEMBER(location)
IPC_STRUCT_TRAITS_MEMBER(transform)
IPC_STRUCT_TRAITS_MEMBER(string_attributes)
IPC_STRUCT_TRAITS_MEMBER(int_attributes)
IPC_STRUCT_TRAITS_MEMBER(float_attributes)
Expand All @@ -46,7 +44,7 @@ IPC_STRUCT_TRAITS_BEGIN(ui::AXNodeData)
IPC_STRUCT_TRAITS_MEMBER(stringlist_attributes)
IPC_STRUCT_TRAITS_MEMBER(html_attributes)
IPC_STRUCT_TRAITS_MEMBER(child_ids)
IPC_STRUCT_TRAITS_MEMBER(offset_container_id)
IPC_STRUCT_TRAITS_MEMBER(relative_bounds)
IPC_STRUCT_TRAITS_END()

IPC_STRUCT_TRAITS_BEGIN(ui::AXTreeData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,9 @@ void AutomationInternalCustomBindings::AddRoutes() {
}

// Use character offsets to compute the local bounds of this subrange.
gfx::RectF local_bounds(0, 0, node->data().location.width(),
node->data().location.height());
gfx::RectF local_bounds(0, 0,
node->data().relative_bounds.bounds.width(),
node->data().relative_bounds.bounds.height());
std::string name =
node->data().GetStringAttribute(ax::mojom::StringAttribute::kName);
std::vector<int> character_offsets = node->data().GetIntListAttribute(
Expand Down
22 changes: 13 additions & 9 deletions components/pdf/renderer/pdf_accessibility_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ void PdfAccessibilityTree::SetAccessibilityViewportInfo(
if (render_accessibility && tree_.size() > 1) {
ui::AXNode* root = tree_.root();
ui::AXNodeData root_data = root->data();
root_data.transform = base::WrapUnique(MakeTransformFromViewInfo());
root_data.relative_bounds.transform =
base::WrapUnique(MakeTransformFromViewInfo());
root->SetData(root_data);
UpdateAXTreeDataFromSelection();
render_accessibility->OnPluginRootNodeUpdated();
Expand All @@ -95,7 +96,7 @@ void PdfAccessibilityTree::SetAccessibilityDocInfo(
// doc's coordinates, the origin of the doc must be (0, 0). Its
// width and height will be updated as we add each page so that the
// doc's bounding box surrounds all pages.
doc_node_->location = gfx::RectF(0, 0, 1, 1);
doc_node_->relative_bounds.bounds = gfx::RectF(0, 0, 1, 1);
}

void PdfAccessibilityTree::SetAccessibilityPageInfo(
Expand All @@ -116,8 +117,8 @@ void PdfAccessibilityTree::SetAccessibilityPageInfo(
l10n_util::GetPluralStringFUTF8(IDS_PDF_PAGE_INDEX, page_index + 1));

gfx::RectF page_bounds = ToRectF(page_info.bounds);
page_node->location = page_bounds;
doc_node_->location.Union(page_node->location);
page_node->relative_bounds.bounds = page_bounds;
doc_node_->relative_bounds.bounds.Union(page_node->relative_bounds.bounds);
doc_node_->child_ids.push_back(page_node->id);

double heading_font_size_threshold = 0;
Expand Down Expand Up @@ -170,13 +171,15 @@ void PdfAccessibilityTree::SetAccessibilityPageInfo(
chars_utf8);
gfx::RectF text_run_bounds = ToGfxRectF(text_run.bounds);
text_run_bounds += page_bounds.OffsetFromOrigin();
inline_text_box_node->location = text_run_bounds;
inline_text_box_node->relative_bounds.bounds = text_run_bounds;
inline_text_box_node->AddIntListAttribute(
ax::mojom::IntListAttribute::kCharacterOffsets, char_offsets);
AddWordStartsAndEnds(inline_text_box_node);

para_node->location.Union(inline_text_box_node->location);
static_text_node->location.Union(inline_text_box_node->location);
para_node->relative_bounds.bounds.Union(
inline_text_box_node->relative_bounds.bounds);
static_text_node->relative_bounds.bounds.Union(
inline_text_box_node->relative_bounds.bounds);

if (i == text_runs.size() - 1) {
static_text_node->AddStringAttribute(ax::mojom::StringAttribute::kName,
Expand All @@ -202,7 +205,8 @@ void PdfAccessibilityTree::SetAccessibilityPageInfo(
}

void PdfAccessibilityTree::Finish() {
doc_node_->transform = base::WrapUnique(MakeTransformFromViewInfo());
doc_node_->relative_bounds.transform =
base::WrapUnique(MakeTransformFromViewInfo());

ui::AXTreeUpdate update;
update.root_id = doc_node_->id;
Expand Down Expand Up @@ -347,7 +351,7 @@ ui::AXNodeData* PdfAccessibilityTree::CreateNode(ax::mojom::Role role) {
// All nodes other than the first one have coordinates relative to
// the first node.
if (nodes_.size() > 0)
node->offset_container_id = nodes_[0]->id;
node->relative_bounds.offset_container_id = nodes_[0]->id;

nodes_.push_back(base::WrapUnique(node));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ void AccessibilityTreeFormatterBlink::AddProperties(

dict->SetString("internalRole", ui::ToString(node.GetData().role));

gfx::Rect bounds = gfx::ToEnclosingRect(node.GetData().location);
gfx::Rect bounds =
gfx::ToEnclosingRect(node.GetData().relative_bounds.bounds);
dict->SetInteger("boundsX", bounds.x());
dict->SetInteger("boundsY", bounds.y());
dict->SetInteger("boundsWidth", bounds.width());
Expand All @@ -155,8 +156,8 @@ void AccessibilityTreeFormatterBlink::AddProperties(
dict->SetInteger("pageBoundsHeight", page_bounds.height());

dict->SetBoolean("transform",
node.GetData().transform &&
!node.GetData().transform->IsIdentity());
node.GetData().relative_bounds.transform &&
!node.GetData().relative_bounds.transform->IsIdentity());

gfx::Rect unclipped_bounds = node.GetPageBoundsRect(&offscreen, false);
dict->SetInteger("unclippedBoundsX", unclipped_bounds.x());
Expand Down
2 changes: 1 addition & 1 deletion content/browser/accessibility/browser_accessibility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ int32_t BrowserAccessibility::GetId() const {
}

gfx::RectF BrowserAccessibility::GetLocation() const {
return GetData().location;
return GetData().relative_bounds.bounds;
}

ax::mojom::Role BrowserAccessibility::GetRole() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ void RebuildAccessibilityTree() {
// times in a test.
root_ = ui::AXNodeData();
root_.id = 1000;
root_.location.set_width(500);
root_.location.set_height(100);
root_.relative_bounds.bounds.set_width(500);
root_.relative_bounds.bounds.set_height(100);
root_.role = ax::mojom::Role::kRootWebArea;
root_.AddStringAttribute(ax::mojom::StringAttribute::kDescription,
"HelpText");
Expand All @@ -91,15 +91,15 @@ void RebuildAccessibilityTree() {
ui::AXNodeData child1;
child1.id = 1001;
child1.SetName("Child1");
child1.location.set_width(250);
child1.location.set_height(100);
child1.relative_bounds.bounds.set_width(250);
child1.relative_bounds.bounds.set_height(100);
child1.role = ax::mojom::Role::kButton;

ui::AXNodeData child2;
child2.id = 1002;
child2.location.set_x(250);
child2.location.set_width(250);
child2.location.set_height(100);
child2.relative_bounds.bounds.set_x(250);
child2.relative_bounds.bounds.set_width(250);
child2.relative_bounds.bounds.set_height(100);
child2.role = ax::mojom::Role::kHeading;

manager_.reset(new BrowserAccessibilityManagerMac(
Expand Down
Loading

0 comments on commit d83381a

Please sign in to comment.