Commit 0e8e56f1 authored by Lucas Radaelli's avatar Lucas Radaelli Committed by Commit Bot

[fuchsia][a11y] Converts AxRole to Fuchsia Semantic Roles.

The Fuchsia Semantics API changed, so this change converts the new added
roles.

Note that this change is not converting the added roles related to
lists, which will be solved in a future change.

Test: AXTreeConverterTest.ConvertRoles
Bug: fuchsia:60180,1136536
Change-Id: I23e8b0dc02e2e9f85cae16be81c400744831905a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461954
Commit-Queue: Lucas Radaelli <lucasradaelli@google.com>
Reviewed-by: default avatarSharon Yang <yangsharon@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816302}
parent ef5cfe63
......@@ -29,21 +29,6 @@ constexpr uint32_t kFuchsiaRootNodeId = 0;
// so as to not conflict with other values used by Chromium.
constexpr uint32_t kZeroIdRemappedForFuchsia = 1u + INT32_MAX;
fuchsia::accessibility::semantics::Role ConvertRole(ax::mojom::Role role) {
if (role == ax::mojom::Role::kButton)
return fuchsia::accessibility::semantics::Role::BUTTON;
if (role == ax::mojom::Role::kHeader)
return fuchsia::accessibility::semantics::Role::HEADER;
if (role == ax::mojom::Role::kImage)
return fuchsia::accessibility::semantics::Role::IMAGE;
if (role == ax::mojom::Role::kSlider)
return fuchsia::accessibility::semantics::Role::SLIDER;
if (role == ax::mojom::Role::kTextField)
return fuchsia::accessibility::semantics::Role::TEXT_FIELD;
return fuchsia::accessibility::semantics::Role::UNKNOWN;
}
fuchsia::accessibility::semantics::Attributes ConvertAttributes(
const ui::AXNodeData& node) {
fuchsia::accessibility::semantics::Attributes attributes;
......@@ -79,6 +64,35 @@ fuchsia::accessibility::semantics::Attributes ConvertAttributes(
return attributes;
}
// Converts an ax::mojom::Role to a fuchsia::accessibility::semantics::Role.
fuchsia::accessibility::semantics::Role AxRoleToFuchsiaSemanticRole(
ax::mojom::Role role) {
switch (role) {
case ax::mojom::Role::kButton:
return fuchsia::accessibility::semantics::Role::BUTTON;
case ax::mojom::Role::kCheckBox:
return fuchsia::accessibility::semantics::Role::CHECK_BOX;
case ax::mojom::Role::kHeader:
return fuchsia::accessibility::semantics::Role::HEADER;
case ax::mojom::Role::kImage:
return fuchsia::accessibility::semantics::Role::IMAGE;
case ax::mojom::Role::kLink:
return fuchsia::accessibility::semantics::Role::LINK;
case ax::mojom::Role::kRadioButton:
return fuchsia::accessibility::semantics::Role::RADIO_BUTTON;
case ax::mojom::Role::kSlider:
return fuchsia::accessibility::semantics::Role::SLIDER;
case ax::mojom::Role::kTextField:
return fuchsia::accessibility::semantics::Role::TEXT_FIELD;
case ax::mojom::Role::kStaticText:
return fuchsia::accessibility::semantics::Role::STATIC_TEXT;
default:
return fuchsia::accessibility::semantics::Role::UNKNOWN;
}
return fuchsia::accessibility::semantics::Role::UNKNOWN;
}
// This function handles conversions for all data that is part of a Semantic
// Node's state. The corresponding data in an AXNodeData is stored in various
// attributes.
......@@ -196,7 +210,7 @@ fuchsia::accessibility::semantics::Node AXNodeDataToSemanticNode(
const ui::AXNodeData& node) {
fuchsia::accessibility::semantics::Node fuchsia_node;
fuchsia_node.set_node_id(base::checked_cast<uint32_t>(node.id));
fuchsia_node.set_role(ConvertRole(node.role));
fuchsia_node.set_role(AxRoleToFuchsiaSemanticRole(node.role));
fuchsia_node.set_states(ConvertStates(node));
fuchsia_node.set_attributes(ConvertAttributes(node));
fuchsia_node.set_actions(ConvertActions(node));
......
......@@ -250,4 +250,44 @@ TEST_F(AXTreeConverterTest, ConvertToFuchsiaNodeId) {
EXPECT_EQ(10u, ConvertToFuchsiaNodeId(10, 0));
}
TEST_F(AXTreeConverterTest, ConvertRoles) {
ui::AXNodeData node;
node.id = 0;
node.role = ax::mojom::Role::kButton;
EXPECT_EQ(fuchsia::accessibility::semantics::Role::BUTTON,
AXNodeDataToSemanticNode(node).role());
node.role = ax::mojom::Role::kCheckBox;
EXPECT_EQ(fuchsia::accessibility::semantics::Role::CHECK_BOX,
AXNodeDataToSemanticNode(node).role());
node.role = ax::mojom::Role::kHeader;
EXPECT_EQ(fuchsia::accessibility::semantics::Role::HEADER,
AXNodeDataToSemanticNode(node).role());
node.role = ax::mojom::Role::kImage;
EXPECT_EQ(fuchsia::accessibility::semantics::Role::IMAGE,
AXNodeDataToSemanticNode(node).role());
node.role = ax::mojom::Role::kLink;
EXPECT_EQ(fuchsia::accessibility::semantics::Role::LINK,
AXNodeDataToSemanticNode(node).role());
node.role = ax::mojom::Role::kRadioButton;
EXPECT_EQ(fuchsia::accessibility::semantics::Role::RADIO_BUTTON,
AXNodeDataToSemanticNode(node).role());
node.role = ax::mojom::Role::kSlider;
EXPECT_EQ(fuchsia::accessibility::semantics::Role::SLIDER,
AXNodeDataToSemanticNode(node).role());
node.role = ax::mojom::Role::kTextField;
EXPECT_EQ(fuchsia::accessibility::semantics::Role::TEXT_FIELD,
AXNodeDataToSemanticNode(node).role());
node.role = ax::mojom::Role::kStaticText;
EXPECT_EQ(fuchsia::accessibility::semantics::Role::STATIC_TEXT,
AXNodeDataToSemanticNode(node).role());
}
} // namespace
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