Commit 6f3a47b1 authored by Sharon Yang's avatar Sharon Yang Committed by Commit Bot

[Fuchsia] Add additional fields to Semantic Node conversion

More fields have been added to a FIDL Semantic Node. This CL adds
support for those new fields.

Test: Updated existing unit tests.

Bug: fuchsia:41000
Bug: 973095
Change-Id: I7e397875206362ebf68e65b7466f6890255322da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1988160
Commit-Queue: Sharon Yang <yangsharon@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729491}
parent b8c32658
...@@ -15,66 +15,109 @@ ...@@ -15,66 +15,109 @@
#include "ui/accessibility/ax_tree_id.h" #include "ui/accessibility/ax_tree_id.h"
#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/geometry/rect_f.h"
using fuchsia::accessibility::semantics::MAX_LABEL_SIZE;
namespace { namespace {
fuchsia::accessibility::semantics::Role ConvertRole(ax::mojom::Role role) { fuchsia::accessibility::semantics::Role ConvertRole(ax::mojom::Role role) {
if (role == ax::mojom::Role::kUnknown) if (role == ax::mojom::Role::kButton)
return fuchsia::accessibility::semantics::Role::UNKNOWN; 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::kTextField)
return fuchsia::accessibility::semantics::Role::TEXT_FIELD;
// TODO(crbug.com/973095): Currently Fuchsia only has one Role option. Add
// more and update tests as they become supported.
return fuchsia::accessibility::semantics::Role::UNKNOWN; return fuchsia::accessibility::semantics::Role::UNKNOWN;
} }
fuchsia::accessibility::semantics::Attributes SetAttributes(std::string name) { fuchsia::accessibility::semantics::Attributes ConvertAttributes(
const ui::AXNodeData& node) {
fuchsia::accessibility::semantics::Attributes attributes; fuchsia::accessibility::semantics::Attributes attributes;
attributes.set_label(name); if (node.HasStringAttribute(ax::mojom::StringAttribute::kName)) {
const std::string& name =
node.GetStringAttribute(ax::mojom::StringAttribute::kName);
attributes.set_label(name.substr(0, MAX_LABEL_SIZE));
}
if (node.HasStringAttribute(ax::mojom::StringAttribute::kDescription)) {
const std::string& description =
node.GetStringAttribute(ax::mojom::StringAttribute::kDescription);
attributes.set_secondary_label(description.substr(0, MAX_LABEL_SIZE));
}
return attributes; return attributes;
} }
// 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.
fuchsia::accessibility::semantics::States ConvertStates(
const ui::AXNodeData& node) {
fuchsia::accessibility::semantics::States states;
// Converts checked state of a node.
if (node.HasIntAttribute(ax::mojom::IntAttribute::kCheckedState)) {
ax::mojom::CheckedState ax_state = node.GetCheckedState();
switch (ax_state) {
case ax::mojom::CheckedState::kNone:
states.set_checked_state(
fuchsia::accessibility::semantics::CheckedState::NONE);
break;
case ax::mojom::CheckedState::kTrue:
states.set_checked_state(
fuchsia::accessibility::semantics::CheckedState::CHECKED);
break;
case ax::mojom::CheckedState::kFalse:
states.set_checked_state(
fuchsia::accessibility::semantics::CheckedState::UNCHECKED);
break;
case ax::mojom::CheckedState::kMixed:
states.set_checked_state(
fuchsia::accessibility::semantics::CheckedState::MIXED);
break;
}
}
// Indicates whether a node has been selected.
if (node.HasBoolAttribute(ax::mojom::BoolAttribute::kSelected)) {
states.set_selected(
node.GetBoolAttribute(ax::mojom::BoolAttribute::kSelected));
}
// Indicates if the node is hidden.
states.set_hidden(node.HasState(ax::mojom::State::kInvisible));
// The user entered value of the node, if applicable.
if (node.HasStringAttribute(ax::mojom::StringAttribute::kValue)) {
const std::string& value =
node.GetStringAttribute(ax::mojom::StringAttribute::kValue);
states.set_value(value.substr(0, MAX_LABEL_SIZE));
}
return states;
}
std::vector<fuchsia::accessibility::semantics::Action> ConvertActions( std::vector<fuchsia::accessibility::semantics::Action> ConvertActions(
uint32_t actions) { const ui::AXNodeData& node) {
std::vector<fuchsia::accessibility::semantics::Action> fuchsia_actions; std::vector<fuchsia::accessibility::semantics::Action> fuchsia_actions;
ax::mojom::Action action_enum = static_cast<ax::mojom::Action>(actions);
if (node.HasAction(ax::mojom::Action::kDoDefault)) {
switch (action_enum) { fuchsia_actions.push_back(
case ax::mojom::Action::kDoDefault: fuchsia::accessibility::semantics::Action::DEFAULT);
fuchsia_actions.push_back( }
fuchsia::accessibility::semantics::Action::DEFAULT); if (node.HasAction(ax::mojom::Action::kFocus)) {
break; fuchsia_actions.push_back(
case ax::mojom::Action::kNone: fuchsia::accessibility::semantics::Action::SET_FOCUS);
case ax::mojom::Action::kAnnotatePageImages: }
case ax::mojom::Action::kBlur: if (node.HasAction(ax::mojom::Action::kSetValue)) {
case ax::mojom::Action::kClearAccessibilityFocus: fuchsia_actions.push_back(
case ax::mojom::Action::kCustomAction: fuchsia::accessibility::semantics::Action::SET_VALUE);
case ax::mojom::Action::kDecrement: }
case ax::mojom::Action::kFocus: if (node.HasAction(ax::mojom::Action::kScrollToMakeVisible)) {
case ax::mojom::Action::kGetImageData: fuchsia_actions.push_back(
case ax::mojom::Action::kGetTextLocation: fuchsia::accessibility::semantics::Action::SHOW_ON_SCREEN);
case ax::mojom::Action::kHideTooltip:
case ax::mojom::Action::kHitTest:
case ax::mojom::Action::kIncrement:
case ax::mojom::Action::kInternalInvalidateTree:
case ax::mojom::Action::kLoadInlineTextBoxes:
case ax::mojom::Action::kReplaceSelectedText:
case ax::mojom::Action::kScrollBackward:
case ax::mojom::Action::kScrollDown:
case ax::mojom::Action::kScrollForward:
case ax::mojom::Action::kScrollLeft:
case ax::mojom::Action::kScrollRight:
case ax::mojom::Action::kScrollUp:
case ax::mojom::Action::kScrollToMakeVisible:
case ax::mojom::Action::kScrollToPoint:
case ax::mojom::Action::kSetAccessibilityFocus:
case ax::mojom::Action::kSetScrollOffset:
case ax::mojom::Action::kSetSelection:
case ax::mojom::Action::kSetSequentialFocusNavigationStartingPoint:
case ax::mojom::Action::kSetValue:
case ax::mojom::Action::kShowContextMenu:
case ax::mojom::Action::kSignalEndOfTest:
case ax::mojom::Action::kShowTooltip:
DVLOG(2) << "Action: " << action_enum;
break;
} }
return fuchsia_actions; return fuchsia_actions;
...@@ -116,12 +159,9 @@ fuchsia::accessibility::semantics::Node AXNodeDataToSemanticNode( ...@@ -116,12 +159,9 @@ fuchsia::accessibility::semantics::Node AXNodeDataToSemanticNode(
fuchsia::accessibility::semantics::Node fuchsia_node; fuchsia::accessibility::semantics::Node fuchsia_node;
fuchsia_node.set_node_id(bit_cast<uint32_t>(node.id)); fuchsia_node.set_node_id(bit_cast<uint32_t>(node.id));
fuchsia_node.set_role(ConvertRole(node.role)); fuchsia_node.set_role(ConvertRole(node.role));
// TODO(fxb/18796): Handle node state conversions once available. fuchsia_node.set_states(ConvertStates(node));
if (node.HasStringAttribute(ax::mojom::StringAttribute::kName)) { fuchsia_node.set_attributes(ConvertAttributes(node));
fuchsia_node.set_attributes(SetAttributes( fuchsia_node.set_actions(ConvertActions(node));
node.GetStringAttribute(ax::mojom::StringAttribute::kName)));
}
fuchsia_node.set_actions(ConvertActions(node.actions));
fuchsia_node.set_child_ids(ConvertChildIds(node.child_ids)); fuchsia_node.set_child_ids(ConvertChildIds(node.child_ids));
fuchsia_node.set_location(ConvertBoundingBox(node.relative_bounds.bounds)); fuchsia_node.set_location(ConvertBoundingBox(node.relative_bounds.bounds));
if (node.relative_bounds.transform) { if (node.relative_bounds.transform) {
......
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