Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(187)

Unified Diff: ui/accessibility/ax_node_data.cc

Issue 2873373005: Add custom action support (Closed)
Patch Set: Migrate to DataObjectBuilder. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/accessibility/ax_node_data.h ('k') | ui/accessibility/ax_tree.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/accessibility/ax_node_data.cc
diff --git a/ui/accessibility/ax_node_data.cc b/ui/accessibility/ax_node_data.cc
index 35955d2dcef02b1d60424d38fd15b415ff251080..eedfdd982913d7158f5738022b0b44f64aad3118 100644
--- a/ui/accessibility/ax_node_data.cc
+++ b/ui/accessibility/ax_node_data.cc
@@ -62,6 +62,16 @@ std::string IntVectorToString(const std::vector<int>& items) {
return str;
}
+std::string StringVectorToString(const std::vector<std::string>& items) {
+ std::string str;
+ for (size_t i = 0; i < items.size(); ++i) {
+ if (i > 0)
+ str += ",";
+ str += items[i];
+ }
+ return str;
+}
+
// Predicate that returns true if the first value of a pair is |first|.
template<typename FirstType, typename SecondType>
struct FirstIs {
@@ -178,6 +188,7 @@ bool IsNodeIdIntListAttribute(AXIntListAttribute attr) {
case AX_ATTR_CACHED_LINE_STARTS:
case AX_ATTR_WORD_STARTS:
case AX_ATTR_WORD_ENDS:
+ case AX_ATTR_CUSTOM_ACTION_IDS:
return false;
}
@@ -205,6 +216,7 @@ AXNodeData::AXNodeData(const AXNodeData& other) {
float_attributes = other.float_attributes;
bool_attributes = other.bool_attributes;
intlist_attributes = other.intlist_attributes;
+ stringlist_attributes = other.stringlist_attributes;
html_attributes = other.html_attributes;
child_ids = other.child_ids;
location = other.location;
@@ -223,6 +235,7 @@ AXNodeData& AXNodeData::operator=(AXNodeData other) {
float_attributes = other.float_attributes;
bool_attributes = other.bool_attributes;
intlist_attributes = other.intlist_attributes;
+ stringlist_attributes = other.stringlist_attributes;
html_attributes = other.html_attributes;
child_ids = other.child_ids;
location = other.location;
@@ -369,6 +382,31 @@ bool AXNodeData::GetIntListAttribute(AXIntListAttribute attribute,
return false;
}
+bool AXNodeData::HasStringListAttribute(AXStringListAttribute attribute) const {
+ auto iter = FindInVectorOfPairs(attribute, stringlist_attributes);
+ return iter != stringlist_attributes.end();
+}
+
+const std::vector<std::string>& AXNodeData::GetStringListAttribute(
+ AXStringListAttribute attribute) const {
+ CR_DEFINE_STATIC_LOCAL(std::vector<std::string>, empty_vector, ());
+ auto iter = FindInVectorOfPairs(attribute, stringlist_attributes);
+ if (iter != stringlist_attributes.end())
+ return iter->second;
+ return empty_vector;
+}
+
+bool AXNodeData::GetStringListAttribute(AXStringListAttribute attribute,
+ std::vector<std::string>* value) const {
+ auto iter = FindInVectorOfPairs(attribute, stringlist_attributes);
+ if (iter != stringlist_attributes.end()) {
+ *value = iter->second;
+ return true;
+ }
+
+ return false;
+}
+
bool AXNodeData::GetHtmlAttribute(
const char* html_attr, std::string* value) const {
for (size_t i = 0; i < html_attributes.size(); ++i) {
@@ -416,6 +454,11 @@ void AXNodeData::AddIntListAttribute(AXIntListAttribute attribute,
intlist_attributes.push_back(std::make_pair(attribute, value));
}
+void AXNodeData::AddStringListAttribute(AXStringListAttribute attribute,
+ const std::vector<std::string>& value) {
+ stringlist_attributes.push_back(std::make_pair(attribute, value));
+}
+
void AXNodeData::SetName(const std::string& name) {
for (size_t i = 0; i < string_attributes.size(); ++i) {
if (string_attributes[i].first == AX_ATTR_NAME) {
@@ -475,6 +518,7 @@ void AXNodeData::AddAction(AXAction action_enum) {
(action_enum == AX_ACTION_BLUR) ? AX_ACTION_FOCUS : AX_ACTION_BLUR;
DCHECK(HasAction(excluded_action));
} break;
+ case AX_ACTION_CUSTOM_ACTION:
case AX_ACTION_DECREMENT:
case AX_ACTION_DO_DEFAULT:
case AX_ACTION_GET_IMAGE_DATA:
@@ -958,11 +1002,26 @@ std::string AXNodeData::ToString() const {
case AX_ATTR_WORD_ENDS:
result += " word_ends=" + IntVectorToString(values);
break;
+ case AX_ATTR_CUSTOM_ACTION_IDS:
+ result += " custom_action_ids=" + IntVectorToString(values);
+ break;
case AX_INT_LIST_ATTRIBUTE_NONE:
break;
}
}
+ for (size_t i = 0; i < stringlist_attributes.size(); ++i) {
+ const std::vector<std::string>& values = stringlist_attributes[i].second;
+ switch (stringlist_attributes[i].first) {
+ case AX_ATTR_CUSTOM_ACTION_DESCRIPTIONS:
+ result +=
+ " custom_action_descriptions: " + StringVectorToString(values);
+ break;
+ case AX_STRING_LIST_ATTRIBUTE_NONE:
+ break;
+ }
+ }
+
result += " actions=" + ActionsBitfieldToString(actions);
if (!child_ids.empty())
« no previous file with comments | « ui/accessibility/ax_node_data.h ('k') | ui/accessibility/ax_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698