Commit 9a4b0cb6 authored by Dominic Mazzoni's avatar Dominic Mazzoni Committed by Commit Bot

[AXOnionSoup] refactor html attribute serialization

This patch has no functional difference, it is just a refactor.

AX-Relnotes: N/A
Bug: 1068668
Change-Id: I5aad36bf020733721649db6f7308e32bef1ade50
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450612Reviewed-by: default avatarMeredith Lane <meredithl@chromium.org>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815242}
parent 3dc4fb53
...@@ -223,48 +223,6 @@ bool FindExactlyOneInnerImageInMaxDepthThree(WebAXObject obj, ...@@ -223,48 +223,6 @@ bool FindExactlyOneInnerImageInMaxDepthThree(WebAXObject obj,
return SearchForExactlyOneInnerImage(obj, inner_image, /* max_depth = */ 3); return SearchForExactlyOneInnerImage(obj, inner_image, /* max_depth = */ 3);
} }
std::string GetEquivalentAriaRoleString(const ax::mojom::Role role) {
switch (role) {
case ax::mojom::Role::kArticle:
return "article";
case ax::mojom::Role::kBanner:
return "banner";
case ax::mojom::Role::kButton:
return "button";
case ax::mojom::Role::kComplementary:
return "complementary";
case ax::mojom::Role::kFigure:
return "figure";
case ax::mojom::Role::kFooter:
return "contentinfo";
case ax::mojom::Role::kHeader:
return "banner";
case ax::mojom::Role::kHeading:
return "heading";
case ax::mojom::Role::kImage:
return "img";
case ax::mojom::Role::kMain:
return "main";
case ax::mojom::Role::kNavigation:
return "navigation";
case ax::mojom::Role::kRadioButton:
return "radio";
case ax::mojom::Role::kRegion:
return "region";
case ax::mojom::Role::kSection:
// A <section> element uses the 'region' ARIA role mapping.
return "region";
case ax::mojom::Role::kSlider:
return "slider";
case ax::mojom::Role::kTime:
return "time";
default:
break;
}
return std::string();
}
} // namespace } // namespace
ScopedFreezeBlinkAXTreeSource::ScopedFreezeBlinkAXTreeSource( ScopedFreezeBlinkAXTreeSource::ScopedFreezeBlinkAXTreeSource(
...@@ -621,7 +579,6 @@ void BlinkAXTreeSource::SerializeNode(WebAXObject src, ...@@ -621,7 +579,6 @@ void BlinkAXTreeSource::SerializeNode(WebAXObject src,
WebElement element = node.To<WebElement>(); WebElement element = node.To<WebElement>();
is_iframe = element.HasHTMLTagName("iframe"); is_iframe = element.HasHTMLTagName("iframe");
SerializeElementAttributes(src, element, dst);
if (accessibility_mode_.has_mode(ui::AXMode::kHTML)) { if (accessibility_mode_.has_mode(ui::AXMode::kHTML)) {
SerializeHTMLAttributes(src, element, dst); SerializeHTMLAttributes(src, element, dst);
} }
...@@ -1119,26 +1076,6 @@ void BlinkAXTreeSource::SerializeEditableTextAttributes( ...@@ -1119,26 +1076,6 @@ void BlinkAXTreeSource::SerializeEditableTextAttributes(
} }
} }
void BlinkAXTreeSource::SerializeElementAttributes(WebAXObject src,
WebElement element,
ui::AXNodeData* dst) const {
if (element.HasAttribute("class")) {
TruncateAndAddStringAttribute(dst, ax::mojom::StringAttribute::kClassName,
element.GetAttribute("class").Utf8());
}
// ARIA role.
if (element.HasAttribute("role")) {
TruncateAndAddStringAttribute(dst, ax::mojom::StringAttribute::kRole,
element.GetAttribute("role").Utf8());
} else {
std::string role = GetEquivalentAriaRoleString(dst->role);
if (!role.empty())
TruncateAndAddStringAttribute(dst, ax::mojom::StringAttribute::kRole,
role);
}
}
void BlinkAXTreeSource::SerializeHTMLAttributes(WebAXObject src, void BlinkAXTreeSource::SerializeHTMLAttributes(WebAXObject src,
WebElement element, WebElement element,
ui::AXNodeData* dst) const { ui::AXNodeData* dst) const {
......
...@@ -160,9 +160,6 @@ class CONTENT_EXPORT BlinkAXTreeSource ...@@ -160,9 +160,6 @@ class CONTENT_EXPORT BlinkAXTreeSource
ui::AXNodeData* dst) const; ui::AXNodeData* dst) const;
void SerializeEditableTextAttributes(blink::WebAXObject src, void SerializeEditableTextAttributes(blink::WebAXObject src,
ui::AXNodeData* dst) const; ui::AXNodeData* dst) const;
void SerializeElementAttributes(blink::WebAXObject src,
blink::WebElement element,
ui::AXNodeData* dst) const;
void SerializeHTMLAttributes(blink::WebAXObject src, void SerializeHTMLAttributes(blink::WebAXObject src,
blink::WebElement element, blink::WebElement element,
ui::AXNodeData* dst) const; ui::AXNodeData* dst) const;
......
...@@ -514,6 +514,49 @@ HTMLDialogElement* GetActiveDialogElement(Node* node) { ...@@ -514,6 +514,49 @@ HTMLDialogElement* GetActiveDialogElement(Node* node) {
return node->GetDocument().ActiveModalDialog(); return node->GetDocument().ActiveModalDialog();
} }
// TODO(dmazzoni): replace this with a call to RoleName().
std::string GetEquivalentAriaRoleString(const ax::mojom::blink::Role role) {
switch (role) {
case ax::mojom::blink::Role::kArticle:
return "article";
case ax::mojom::blink::Role::kBanner:
return "banner";
case ax::mojom::blink::Role::kButton:
return "button";
case ax::mojom::blink::Role::kComplementary:
return "complementary";
case ax::mojom::blink::Role::kFigure:
return "figure";
case ax::mojom::blink::Role::kFooter:
return "contentinfo";
case ax::mojom::blink::Role::kHeader:
return "banner";
case ax::mojom::blink::Role::kHeading:
return "heading";
case ax::mojom::blink::Role::kImage:
return "img";
case ax::mojom::blink::Role::kMain:
return "main";
case ax::mojom::blink::Role::kNavigation:
return "navigation";
case ax::mojom::blink::Role::kRadioButton:
return "radio";
case ax::mojom::blink::Role::kRegion:
return "region";
case ax::mojom::blink::Role::kSection:
// A <section> element uses the 'region' ARIA role mapping.
return "region";
case ax::mojom::blink::Role::kSlider:
return "slider";
case ax::mojom::blink::Role::kTime:
return "time";
default:
break;
}
return std::string();
}
} // namespace } // namespace
unsigned AXObject::number_of_live_ax_objects_ = 0; unsigned AXObject::number_of_live_ax_objects_ = 0;
...@@ -885,6 +928,28 @@ void AXObject::Serialize(ui::AXNodeData* node_data, ...@@ -885,6 +928,28 @@ void AXObject::Serialize(ui::AXNodeData* node_data,
} }
SerializePartialSparseAttributes(node_data); SerializePartialSparseAttributes(node_data);
if (Element* element = this->GetElement()) {
if (const AtomicString& class_name = element->GetClassAttribute()) {
TruncateAndAddStringAttribute(
node_data, ax::mojom::blink::StringAttribute::kClassName,
class_name.Utf8());
}
if (const AtomicString& aria_role =
GetAOMPropertyOrARIAAttribute(AOMStringProperty::kRole)) {
TruncateAndAddStringAttribute(node_data,
ax::mojom::blink::StringAttribute::kRole,
aria_role.Utf8());
} else {
std::string role_str = GetEquivalentAriaRoleString(RoleValue());
if (!role_str.empty()) {
TruncateAndAddStringAttribute(node_data,
ax::mojom::blink::StringAttribute::kRole,
GetEquivalentAriaRoleString(RoleValue()));
}
}
}
} }
void AXObject::SerializeTableAttributes(ui::AXNodeData* node_data) { void AXObject::SerializeTableAttributes(ui::AXNodeData* node_data) {
......
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