Commit fef162d0 authored by Hiroki Sato's avatar Hiroki Sato Committed by Commit Bot

Clean up ARC a11y standard action lookup.

This CL adds HasStandardAction in arc accessibility util.

Bug: none.
Test: unit_test
Change-Id: I1380f1f89647bbe2b39dedc3da0f28ffb3fd90b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2091098Reviewed-by: default avatarSara Kato <sarakato@chromium.org>
Commit-Queue: Hiroki Sato <hirokisato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748070}
parent cfc9baf5
...@@ -455,30 +455,21 @@ void AccessibilityNodeInfoDataWrapper::Serialize( ...@@ -455,30 +455,21 @@ void AccessibilityNodeInfoDataWrapper::Serialize(
ToLiveStatusString(container_live_status_)); ToLiveStatusString(container_live_status_));
} }
std::vector<int32_t> standard_action_ids; // Standard actions.
if (GetProperty(AXIntListProperty::STANDARD_ACTION_IDS, if (HasStandardAction(AXActionType::SCROLL_BACKWARD))
&standard_action_ids)) { out_data->AddAction(ax::mojom::Action::kScrollBackward);
for (size_t i = 0; i < standard_action_ids.size(); ++i) {
switch (static_cast<AXActionType>(standard_action_ids[i])) { if (HasStandardAction(AXActionType::SCROLL_FORWARD))
case AXActionType::SCROLL_BACKWARD: out_data->AddAction(ax::mojom::Action::kScrollForward);
out_data->AddAction(ax::mojom::Action::kScrollBackward);
break; if (HasStandardAction(AXActionType::EXPAND)) {
case AXActionType::SCROLL_FORWARD: out_data->AddAction(ax::mojom::Action::kExpand);
out_data->AddAction(ax::mojom::Action::kScrollForward); out_data->AddState(ax::mojom::State::kCollapsed);
break; }
case AXActionType::EXPAND:
out_data->AddAction(ax::mojom::Action::kExpand); if (HasStandardAction(AXActionType::COLLAPSE)) {
out_data->AddState(ax::mojom::State::kCollapsed); out_data->AddAction(ax::mojom::Action::kCollapse);
break; out_data->AddState(ax::mojom::State::kExpanded);
case AXActionType::COLLAPSE:
out_data->AddAction(ax::mojom::Action::kCollapse);
out_data->AddState(ax::mojom::State::kExpanded);
break;
default:
// unmapped
break;
}
}
} }
// Custom actions. // Custom actions.
...@@ -545,6 +536,11 @@ bool AccessibilityNodeInfoDataWrapper::GetProperty( ...@@ -545,6 +536,11 @@ bool AccessibilityNodeInfoDataWrapper::GetProperty(
return arc::GetProperty(node_ptr_->string_list_properties, prop, out_value); return arc::GetProperty(node_ptr_->string_list_properties, prop, out_value);
} }
bool AccessibilityNodeInfoDataWrapper::HasStandardAction(
AXActionType action) const {
return arc::HasStandardAction(node_ptr_, action);
}
bool AccessibilityNodeInfoDataWrapper::HasCoveringSpan( bool AccessibilityNodeInfoDataWrapper::HasCoveringSpan(
AXStringProperty prop, AXStringProperty prop,
mojom::SpanType span_type) const { mojom::SpanType span_type) const {
......
...@@ -57,6 +57,8 @@ class AccessibilityNodeInfoDataWrapper : public AccessibilityInfoDataWrapper { ...@@ -57,6 +57,8 @@ class AccessibilityNodeInfoDataWrapper : public AccessibilityInfoDataWrapper {
bool GetProperty(mojom::AccessibilityStringListProperty prop, bool GetProperty(mojom::AccessibilityStringListProperty prop,
std::vector<std::string>* out_value) const; std::vector<std::string>* out_value) const;
bool HasStandardAction(mojom::AccessibilityActionType action) const;
bool HasCoveringSpan(mojom::AccessibilityStringProperty prop, bool HasCoveringSpan(mojom::AccessibilityStringProperty prop,
mojom::SpanType span_type) const; mojom::SpanType span_type) const;
......
...@@ -145,21 +145,9 @@ bool IsImportantInAndroid(AXNodeInfoData* node) { ...@@ -145,21 +145,9 @@ bool IsImportantInAndroid(AXNodeInfoData* node) {
// WebView and its child nodes do not have accessibility importance set. // WebView and its child nodes do not have accessibility importance set.
// This logic can be removed once the change in crrev/c/1890402 landed // This logic can be removed once the change in crrev/c/1890402 landed
// in all ARC containers. // in all ARC containers.
std::vector<int32_t> standard_action_ids; if (HasStandardAction(node, AXActionType::NEXT_HTML_ELEMENT) ||
if (GetProperty(node->int_list_properties, HasStandardAction(node, AXActionType::PREVIOUS_HTML_ELEMENT))
AXIntListProperty::STANDARD_ACTION_IDS, return true;
&standard_action_ids)) {
for (const int32_t id : standard_action_ids) {
switch (static_cast<AXActionType>(id)) {
case AXActionType::NEXT_HTML_ELEMENT:
case AXActionType::PREVIOUS_HTML_ELEMENT:
return true;
default:
// unused.
break;
}
}
}
return false; return false;
} }
...@@ -180,24 +168,28 @@ bool HasImportantProperty(AXNodeInfoData* node) { ...@@ -180,24 +168,28 @@ bool HasImportantProperty(AXNodeInfoData* node) {
GetBooleanProperty(node, AXBooleanProperty::SELECTED)) GetBooleanProperty(node, AXBooleanProperty::SELECTED))
return true; return true;
std::vector<int32_t> standard_action_ids; if (HasStandardAction(node, AXActionType::CLICK) ||
if (GetProperty(node->int_list_properties, HasStandardAction(node, AXActionType::FOCUS))
AXIntListProperty::STANDARD_ACTION_IDS, return true;
&standard_action_ids)) {
for (const int32_t id : standard_action_ids) {
switch (static_cast<AXActionType>(id)) {
case AXActionType::CLICK:
case AXActionType::FOCUS:
return true;
default:
// unused.
break;
}
}
}
// TODO(hirokisato) Also check LABELED_BY and ui::IsControl(role) // TODO(hirokisato) Also check LABELED_BY and ui::IsControl(role)
return false; return false;
} }
bool HasStandardAction(AXNodeInfoData* node, AXActionType action) {
if (!node || !node->int_list_properties)
return false;
auto itr =
node->int_list_properties->find(AXIntListProperty::STANDARD_ACTION_IDS);
if (itr == node->int_list_properties->end())
return false;
for (const auto supported_action : itr->second) {
if (static_cast<AXActionType>(supported_action) == action)
return true;
}
return false;
}
} // namespace arc } // namespace arc
...@@ -27,6 +27,9 @@ bool IsImportantInAndroid(mojom::AccessibilityNodeInfoData* node); ...@@ -27,6 +27,9 @@ bool IsImportantInAndroid(mojom::AccessibilityNodeInfoData* node);
bool HasImportantProperty(mojom::AccessibilityNodeInfoData* node); bool HasImportantProperty(mojom::AccessibilityNodeInfoData* node);
bool HasStandardAction(mojom::AccessibilityNodeInfoData* node,
mojom::AccessibilityActionType action);
template <class DataType, class PropType> template <class DataType, class PropType>
bool GetBooleanProperty(DataType* node, PropType prop) { bool GetBooleanProperty(DataType* node, PropType prop) {
if (!node->boolean_properties) if (!node->boolean_properties)
......
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