Commit fd5349d6 authored by Aran Gilman's avatar Aran Gilman Committed by Commit Bot

Display computed table attributes instead of raw table attributes in Blink tests.

Also move a helper method out of the class definition and into an anonymous namespace in the implementation, remove a fixed TODO, and let the autoformatter fix some formatting errors.

Bug: 904896
Change-Id: I1384de5b4b457bf78f79e7fe42cc26d72850ed1e
Reviewed-on: https://chromium-review.googlesource.com/c/1343356
Commit-Queue: Aran Gilman <gilmanmh@google.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611141}
parent cf5112a6
...@@ -16,46 +16,87 @@ ...@@ -16,46 +16,87 @@
#include "base/values.h" #include "base/values.h"
#include "content/browser/accessibility/browser_accessibility_manager.h" #include "content/browser/accessibility/browser_accessibility_manager.h"
#include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node.h"
#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
namespace content { namespace content {
namespace {
// Compute the attribute value instead of returning the "raw" attribute value
// for those attributes that have computation methods.
int32_t GetIntAttribute(const BrowserAccessibility& node,
ax::mojom::IntAttribute attr) {
ui::AXNode* ax_node = node.node();
if (ax_node == nullptr) {
return node.GetIntAttribute(attr);
}
AccessibilityTreeFormatterBlink::AccessibilityTreeFormatterBlink() // If the current node is not a cell, then trying to compute cell-related
: AccessibilityTreeFormatterBrowser() {} // attributes will return incorrect results. We should fall back to the raw
// attribute value when that happens.
bool is_cell = ax_node->IsTableCellOrHeader();
AccessibilityTreeFormatterBlink::~AccessibilityTreeFormatterBlink() { switch (attr) {
} case ax::mojom::IntAttribute::kAriaCellColumnIndex:
if (is_cell) {
return ax_node->GetTableCellAriaColIndex();
}
break;
const char* const TREE_DATA_ATTRIBUTES[] = {"TreeData.textSelStartOffset", case ax::mojom::IntAttribute::kAriaCellRowIndex:
"TreeData.textSelEndOffset"}; if (is_cell) {
return ax_node->GetTableCellAriaRowIndex();
}
break;
const char* STATE_FOCUSED = "focused"; case ax::mojom::IntAttribute::kAriaColumnCount:
const char* STATE_OFFSCREEN = "offscreen"; return ax_node->GetTableAriaColCount();
case ax::mojom::IntAttribute::kAriaRowCount:
return ax_node->GetTableAriaRowCount();
uint32_t AccessibilityTreeFormatterBlink::ChildCount( case ax::mojom::IntAttribute::kTableCellColumnIndex:
const BrowserAccessibility& node) const { if (is_cell) {
if (node.HasStringAttribute(ax::mojom::StringAttribute::kChildTreeId)) return ax_node->GetTableCellColIndex();
return node.PlatformChildCount(); }
else break;
return node.InternalChildCount();
}
BrowserAccessibility* AccessibilityTreeFormatterBlink::GetChild( case ax::mojom::IntAttribute::kTableCellRowIndex:
const BrowserAccessibility& node, if (is_cell) {
uint32_t i) const { return ax_node->GetTableCellRowIndex();
if (node.HasStringAttribute(ax::mojom::StringAttribute::kChildTreeId)) }
return node.PlatformGetChild(i); break;
else
return node.InternalGetChild(i); case ax::mojom::IntAttribute::kTableCellColumnSpan:
if (is_cell) {
return ax_node->GetTableCellColSpan();
}
break;
case ax::mojom::IntAttribute::kTableCellRowSpan:
if (is_cell) {
return ax_node->GetTableCellRowSpan();
}
break;
case ax::mojom::IntAttribute::kTableColumnCount:
return ax_node->GetTableColCount();
case ax::mojom::IntAttribute::kTableRowCount:
return ax_node->GetTableRowCount();
case ax::mojom::IntAttribute::kTableRowIndex:
return ax_node->GetTableRowRowIndex();
default:
break;
}
return node.GetIntAttribute(attr);
} }
// TODO(aleventhal) Convert ax enums to friendly strings, e.g. std::string IntAttrToString(const BrowserAccessibility& node,
// ax::mojom::CheckedState. ax::mojom::IntAttribute attr,
std::string AccessibilityTreeFormatterBlink::IntAttrToString( int32_t value) {
const BrowserAccessibility& node,
ax::mojom::IntAttribute attr,
int value) const {
if (ui::IsNodeIdIntAttribute(attr)) { if (ui::IsNodeIdIntAttribute(attr)) {
// Relation // Relation
BrowserAccessibility* target = node.manager()->GetFromID(value); BrowserAccessibility* target = node.manager()->GetFromID(value);
...@@ -133,6 +174,36 @@ std::string AccessibilityTreeFormatterBlink::IntAttrToString( ...@@ -133,6 +174,36 @@ std::string AccessibilityTreeFormatterBlink::IntAttrToString(
return std::to_string(value); return std::to_string(value);
} }
} // namespace
AccessibilityTreeFormatterBlink::AccessibilityTreeFormatterBlink()
: AccessibilityTreeFormatterBrowser() {}
AccessibilityTreeFormatterBlink::~AccessibilityTreeFormatterBlink() {}
const char* const TREE_DATA_ATTRIBUTES[] = {"TreeData.textSelStartOffset",
"TreeData.textSelEndOffset"};
const char* STATE_FOCUSED = "focused";
const char* STATE_OFFSCREEN = "offscreen";
uint32_t AccessibilityTreeFormatterBlink::ChildCount(
const BrowserAccessibility& node) const {
if (node.HasStringAttribute(ax::mojom::StringAttribute::kChildTreeId))
return node.PlatformChildCount();
else
return node.InternalChildCount();
}
BrowserAccessibility* AccessibilityTreeFormatterBlink::GetChild(
const BrowserAccessibility& node,
uint32_t i) const {
if (node.HasStringAttribute(ax::mojom::StringAttribute::kChildTreeId))
return node.PlatformGetChild(i);
else
return node.InternalGetChild(i);
}
void AccessibilityTreeFormatterBlink::AddProperties( void AccessibilityTreeFormatterBlink::AddProperties(
const BrowserAccessibility& node, const BrowserAccessibility& node,
base::DictionaryValue* dict) { base::DictionaryValue* dict) {
...@@ -206,7 +277,7 @@ void AccessibilityTreeFormatterBlink::AddProperties( ...@@ -206,7 +277,7 @@ void AccessibilityTreeFormatterBlink::AddProperties(
++attr_index) { ++attr_index) {
auto attr = static_cast<ax::mojom::IntAttribute>(attr_index); auto attr = static_cast<ax::mojom::IntAttribute>(attr_index);
if (node.HasIntAttribute(attr)) { if (node.HasIntAttribute(attr)) {
int value = node.GetIntAttribute(attr); int32_t value = GetIntAttribute(node, attr);
dict->SetString(ui::ToString(attr), IntAttrToString(node, attr, value)); dict->SetString(ui::ToString(attr), IntAttrToString(node, attr, value));
} }
} }
...@@ -320,20 +391,19 @@ base::string16 AccessibilityTreeFormatterBlink::ProcessTreeForOutput( ...@@ -320,20 +391,19 @@ base::string16 AccessibilityTreeFormatterBlink::ProcessTreeForOutput(
if (focused) if (focused)
WriteAttribute(false, STATE_FOCUSED, &line); WriteAttribute(false, STATE_FOCUSED, &line);
WriteAttribute(false, WriteAttribute(
FormatCoordinates("location", "boundsX", "boundsY", dict), false, FormatCoordinates("location", "boundsX", "boundsY", dict), &line);
&line);
WriteAttribute(false, WriteAttribute(false,
FormatCoordinates("size", "boundsWidth", "boundsHeight", dict), FormatCoordinates("size", "boundsWidth", "boundsHeight", dict),
&line); &line);
WriteAttribute(
false,
FormatCoordinates("pageLocation", "pageBoundsX", "pageBoundsY", dict),
&line);
WriteAttribute(false, WriteAttribute(false,
FormatCoordinates("pageLocation", FormatCoordinates("pageSize", "pageBoundsWidth",
"pageBoundsX", "pageBoundsY", dict), "pageBoundsHeight", dict),
&line);
WriteAttribute(false,
FormatCoordinates("pageSize",
"pageBoundsWidth", "pageBoundsHeight", dict),
&line); &line);
WriteAttribute(false, WriteAttribute(false,
FormatCoordinates("unclippedLocation", "unclippedBoundsX", FormatCoordinates("unclippedLocation", "unclippedBoundsX",
......
...@@ -27,9 +27,6 @@ class CONTENT_EXPORT AccessibilityTreeFormatterBlink ...@@ -27,9 +27,6 @@ class CONTENT_EXPORT AccessibilityTreeFormatterBlink
uint32_t i) const override; uint32_t i) const override;
void AddProperties(const BrowserAccessibility& node, void AddProperties(const BrowserAccessibility& node,
base::DictionaryValue* dict) override; base::DictionaryValue* dict) override;
std::string IntAttrToString(const BrowserAccessibility& node,
ax::mojom::IntAttribute attr,
int value) const;
base::string16 ProcessTreeForOutput( base::string16 ProcessTreeForOutput(
const base::DictionaryValue& node, const base::DictionaryValue& node,
base::DictionaryValue* filtered_dict_result = nullptr) override; base::DictionaryValue* filtered_dict_result = nullptr) override;
......
...@@ -21,13 +21,13 @@ rootWebArea ...@@ -21,13 +21,13 @@ rootWebArea
++++++++staticText name='Sunny' ++++++++staticText name='Sunny'
++++++++++inlineTextBox name='Sunny' ++++++++++inlineTextBox name='Sunny'
++++row selected=false ++++row selected=false
++++++cell name='January' ariaCellColumnIndex=1 ariaCellRowIndex=2 selected=false ++++++cell name='January' ariaCellColumnIndex=1 ariaCellRowIndex=3 selected=false
++++++++staticText name='January' ++++++++staticText name='January'
++++++++++inlineTextBox name='January' ++++++++++inlineTextBox name='January'
++++++cell name='02' ariaCellColumnIndex=2 ariaCellRowIndex=2 selected=false ++++++cell name='02' ariaCellColumnIndex=2 ariaCellRowIndex=3 selected=false
++++++++staticText name='02' ++++++++staticText name='02'
++++++++++inlineTextBox name='02' ++++++++++inlineTextBox name='02'
++++++cell name='Rainy' ariaCellColumnIndex=4 ariaCellRowIndex=2 selected=false ++++++cell name='Rainy' ariaCellColumnIndex=4 ariaCellRowIndex=3 selected=false
++++++++staticText name='Rainy' ++++++++staticText name='Rainy'
++++++++++inlineTextBox name='Rainy' ++++++++++inlineTextBox name='Rainy'
++paragraph ++paragraph
......
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