Index: third_party/WebKit/Source/core/dom/AccessibleNode.cpp |
diff --git a/third_party/WebKit/Source/core/dom/AccessibleNode.cpp b/third_party/WebKit/Source/core/dom/AccessibleNode.cpp |
index 4f6eaa48eb7cf63d3f84da146e5e4d88c65080e5..81dd859004d268c777122972cce2f3427c3b0170 100644 |
--- a/third_party/WebKit/Source/core/dom/AccessibleNode.cpp |
+++ b/third_party/WebKit/Source/core/dom/AccessibleNode.cpp |
@@ -35,24 +35,79 @@ const AtomicString& AccessibleNode::GetProperty(Element* element, |
return g_null_atom; |
} |
+template <typename P, typename T> |
+static T FindPropertyValue(P property, |
+ bool& is_null, |
+ Vector<std::pair<P, T>>& properties, |
+ T default_value) { |
+ for (const auto& item : properties) { |
+ if (item.first == property) { |
+ is_null = false; |
+ return item.second; |
+ } |
+ } |
+ |
+ return default_value; |
+} |
+ |
// static |
bool AccessibleNode::GetProperty(Element* element, |
AOMBooleanProperty property, |
bool& is_null) { |
is_null = true; |
- if (!element) |
- return false; |
- if (AccessibleNode* accessible_node = element->ExistingAccessibleNode()) { |
- for (const auto& item : accessible_node->boolean_properties_) { |
- if (item.first == property) { |
- is_null = false; |
- return item.second; |
- } |
- } |
- } |
+ bool default_value = false; |
+ if (!element || !element->ExistingAccessibleNode()) |
+ return default_value; |
+ |
+ return FindPropertyValue( |
+ property, is_null, element->ExistingAccessibleNode()->boolean_properties_, |
+ default_value); |
+} |
+ |
+// static |
+float AccessibleNode::GetProperty(Element* element, |
+ AOMFloatProperty property, |
+ bool& is_null) { |
+ is_null = true; |
+ |
+ float default_value = 0.0; |
+ if (!element || !element->ExistingAccessibleNode()) |
+ return default_value; |
+ |
+ return FindPropertyValue(property, is_null, |
+ element->ExistingAccessibleNode()->float_properties_, |
+ default_value); |
+} |
+ |
+// static |
+int32_t AccessibleNode::GetProperty(Element* element, |
+ AOMIntProperty property, |
+ bool& is_null) { |
+ is_null = true; |
+ |
+ int32_t default_value = 0; |
+ if (!element || !element->ExistingAccessibleNode()) |
+ return default_value; |
- return false; |
+ return FindPropertyValue(property, is_null, |
+ element->ExistingAccessibleNode()->int_properties_, |
+ default_value); |
+} |
+ |
+// static |
+uint32_t AccessibleNode::GetProperty(Element* element, |
+ AOMUIntProperty property, |
+ bool& is_null) { |
+ is_null = true; |
+ |
+ uint32_t default_value = 0; |
+ if (!element || !element->ExistingAccessibleNode()) |
+ return default_value; |
+ |
+ return FindPropertyValue(property, is_null, |
+ element->ExistingAccessibleNode()->uint_properties_, |
+ default_value); |
} |
// static |
@@ -156,6 +211,105 @@ bool AccessibleNode::GetPropertyOrARIAAttribute(Element* element, |
return EqualIgnoringASCIICase(attr_value, "true"); |
} |
+// static |
+float AccessibleNode::GetPropertyOrARIAAttribute(Element* element, |
+ AOMFloatProperty property, |
+ bool& is_null) { |
+ is_null = true; |
+ if (!element) |
+ return 0.0; |
+ |
+ float result = GetProperty(element, property, is_null); |
+ if (!is_null) |
+ return result; |
+ |
+ // Fall back on the equivalent ARIA attribute. |
+ AtomicString attr_value; |
+ switch (property) { |
+ case AOMFloatProperty::kValueMax: |
+ attr_value = element->FastGetAttribute(aria_valuemaxAttr); |
+ break; |
+ case AOMFloatProperty::kValueMin: |
+ attr_value = element->FastGetAttribute(aria_valueminAttr); |
+ break; |
+ case AOMFloatProperty::kValueNow: |
+ attr_value = element->FastGetAttribute(aria_valuenowAttr); |
+ break; |
+ } |
+ |
+ is_null = attr_value.IsNull(); |
+ return attr_value.ToFloat(); |
+} |
+ |
+// static |
+uint32_t AccessibleNode::GetPropertyOrARIAAttribute(Element* element, |
+ AOMUIntProperty property, |
+ bool& is_null) { |
+ is_null = true; |
+ if (!element) |
+ return 0; |
+ |
+ int32_t result = GetProperty(element, property, is_null); |
+ if (!is_null) |
+ return result; |
+ |
+ // Fall back on the equivalent ARIA attribute. |
+ AtomicString attr_value; |
+ switch (property) { |
+ case AOMUIntProperty::kColIndex: |
+ attr_value = element->FastGetAttribute(aria_colindexAttr); |
+ break; |
+ case AOMUIntProperty::kColSpan: |
+ attr_value = element->FastGetAttribute(aria_colspanAttr); |
+ break; |
+ case AOMUIntProperty::kLevel: |
+ attr_value = element->FastGetAttribute(aria_levelAttr); |
+ break; |
+ case AOMUIntProperty::kPosInSet: |
+ attr_value = element->FastGetAttribute(aria_posinsetAttr); |
+ break; |
+ case AOMUIntProperty::kRowIndex: |
+ attr_value = element->FastGetAttribute(aria_rowindexAttr); |
+ break; |
+ case AOMUIntProperty::kRowSpan: |
+ attr_value = element->FastGetAttribute(aria_rowspanAttr); |
+ break; |
+ } |
+ |
+ is_null = attr_value.IsNull(); |
+ return attr_value.GetString().ToUInt(); |
tkent
2017/07/28 02:31:14
Is String::ToUInt() correct for aria attribute par
|
+} |
+ |
+// static |
+int32_t AccessibleNode::GetPropertyOrARIAAttribute(Element* element, |
+ AOMIntProperty property, |
+ bool& is_null) { |
+ is_null = true; |
+ if (!element) |
+ return 0; |
+ |
+ int32_t result = GetProperty(element, property, is_null); |
+ if (!is_null) |
+ return result; |
+ |
+ // Fall back on the equivalent ARIA attribute. |
+ AtomicString attr_value; |
+ switch (property) { |
+ case AOMIntProperty::kColCount: |
+ attr_value = element->FastGetAttribute(aria_colcountAttr); |
+ break; |
+ case AOMIntProperty::kRowCount: |
+ attr_value = element->FastGetAttribute(aria_rowcountAttr); |
+ break; |
+ case AOMIntProperty::kSetSize: |
+ attr_value = element->FastGetAttribute(aria_setsizeAttr); |
+ break; |
+ } |
+ |
+ is_null = attr_value.IsNull(); |
+ return attr_value.ToInt(); |
tkent
2017/07/28 02:31:14
Ditto.
|
+} |
+ |
bool AccessibleNode::atomic(bool& is_null) const { |
return GetProperty(element_, AOMBooleanProperty::kAtomic, is_null); |
} |
@@ -192,6 +346,33 @@ void AccessibleNode::setChecked(const AtomicString& checked) { |
NotifyAttributeChanged(aria_checkedAttr); |
} |
+int32_t AccessibleNode::colCount(bool& is_null) const { |
+ return GetProperty(element_, AOMIntProperty::kColCount, is_null); |
+} |
+ |
+void AccessibleNode::setColCount(int32_t col_count, bool is_null) { |
+ SetIntProperty(AOMIntProperty::kColCount, col_count, is_null); |
+ NotifyAttributeChanged(aria_colcountAttr); |
+} |
+ |
+uint32_t AccessibleNode::colIndex(bool& is_null) const { |
+ return GetProperty(element_, AOMUIntProperty::kColIndex, is_null); |
+} |
+ |
+void AccessibleNode::setColIndex(uint32_t col_index, bool is_null) { |
+ SetUIntProperty(AOMUIntProperty::kColIndex, col_index, is_null); |
+ NotifyAttributeChanged(aria_colindexAttr); |
+} |
+ |
+uint32_t AccessibleNode::colSpan(bool& is_null) const { |
+ return GetProperty(element_, AOMUIntProperty::kColSpan, is_null); |
+} |
+ |
+void AccessibleNode::setColSpan(uint32_t col_span, bool is_null) { |
+ SetUIntProperty(AOMUIntProperty::kColSpan, col_span, is_null); |
+ NotifyAttributeChanged(aria_colspanAttr); |
+} |
+ |
AtomicString AccessibleNode::current() const { |
return GetProperty(element_, AOMStringProperty::kCurrent); |
} |
@@ -257,6 +438,15 @@ void AccessibleNode::setLabel(const AtomicString& label) { |
NotifyAttributeChanged(aria_labelAttr); |
} |
+uint32_t AccessibleNode::level(bool& is_null) const { |
+ return GetProperty(element_, AOMUIntProperty::kLevel, is_null); |
+} |
+ |
+void AccessibleNode::setLevel(uint32_t level, bool is_null) { |
+ SetUIntProperty(AOMUIntProperty::kLevel, level, is_null); |
+ NotifyAttributeChanged(aria_levelAttr); |
+} |
+ |
AtomicString AccessibleNode::live() const { |
return GetProperty(element_, AOMStringProperty::kLive); |
} |
@@ -312,6 +502,15 @@ void AccessibleNode::setPlaceholder(const AtomicString& placeholder) { |
NotifyAttributeChanged(aria_placeholderAttr); |
} |
+uint32_t AccessibleNode::posInSet(bool& is_null) const { |
+ return GetProperty(element_, AOMUIntProperty::kPosInSet, is_null); |
+} |
+ |
+void AccessibleNode::setPosInSet(uint32_t pos_in_set, bool is_null) { |
+ SetUIntProperty(AOMUIntProperty::kPosInSet, pos_in_set, is_null); |
+ NotifyAttributeChanged(aria_posinsetAttr); |
+} |
+ |
bool AccessibleNode::readOnly(bool& is_null) const { |
return GetProperty(element_, AOMBooleanProperty::kReadOnly, is_null); |
} |
@@ -357,6 +556,33 @@ void AccessibleNode::setRoleDescription(const AtomicString& role_description) { |
NotifyAttributeChanged(aria_roledescriptionAttr); |
} |
+int32_t AccessibleNode::rowCount(bool& is_null) const { |
+ return GetProperty(element_, AOMIntProperty::kRowCount, is_null); |
+} |
+ |
+void AccessibleNode::setRowCount(int32_t row_count, bool is_null) { |
+ SetIntProperty(AOMIntProperty::kRowCount, row_count, is_null); |
+ NotifyAttributeChanged(aria_rowcountAttr); |
+} |
+ |
+uint32_t AccessibleNode::rowIndex(bool& is_null) const { |
+ return GetProperty(element_, AOMUIntProperty::kRowIndex, is_null); |
+} |
+ |
+void AccessibleNode::setRowIndex(uint32_t row_index, bool is_null) { |
+ SetUIntProperty(AOMUIntProperty::kRowIndex, row_index, is_null); |
+ NotifyAttributeChanged(aria_rowindexAttr); |
+} |
+ |
+uint32_t AccessibleNode::rowSpan(bool& is_null) const { |
+ return GetProperty(element_, AOMUIntProperty::kRowSpan, is_null); |
+} |
+ |
+void AccessibleNode::setRowSpan(uint32_t row_span, bool is_null) { |
+ SetUIntProperty(AOMUIntProperty::kRowSpan, row_span, is_null); |
+ NotifyAttributeChanged(aria_rowspanAttr); |
+} |
+ |
bool AccessibleNode::selected(bool& is_null) const { |
return GetProperty(element_, AOMBooleanProperty::kSelected, is_null); |
} |
@@ -366,6 +592,15 @@ void AccessibleNode::setSelected(bool selected, bool is_null) { |
NotifyAttributeChanged(aria_selectedAttr); |
} |
+int32_t AccessibleNode::setSize(bool& is_null) const { |
+ return GetProperty(element_, AOMIntProperty::kSetSize, is_null); |
+} |
+ |
+void AccessibleNode::setSetSize(int32_t set_size, bool is_null) { |
+ SetIntProperty(AOMIntProperty::kSetSize, set_size, is_null); |
+ NotifyAttributeChanged(aria_setsizeAttr); |
+} |
+ |
AtomicString AccessibleNode::sort() const { |
return GetProperty(element_, AOMStringProperty::kSort); |
} |
@@ -375,6 +610,33 @@ void AccessibleNode::setSort(const AtomicString& sort) { |
NotifyAttributeChanged(aria_sortAttr); |
} |
+float AccessibleNode::valueMax(bool& is_null) const { |
+ return GetProperty(element_, AOMFloatProperty::kValueMax, is_null); |
+} |
+ |
+void AccessibleNode::setValueMax(float value_max, bool is_null) { |
+ SetFloatProperty(AOMFloatProperty::kValueMax, value_max, is_null); |
+ NotifyAttributeChanged(aria_valuemaxAttr); |
+} |
+ |
+float AccessibleNode::valueMin(bool& is_null) const { |
+ return GetProperty(element_, AOMFloatProperty::kValueMin, is_null); |
+} |
+ |
+void AccessibleNode::setValueMin(float value_min, bool is_null) { |
+ SetFloatProperty(AOMFloatProperty::kValueMin, value_min, is_null); |
+ NotifyAttributeChanged(aria_valueminAttr); |
+} |
+ |
+float AccessibleNode::valueNow(bool& is_null) const { |
+ return GetProperty(element_, AOMFloatProperty::kValueNow, is_null); |
+} |
+ |
+void AccessibleNode::setValueNow(float value_now, bool is_null) { |
+ SetFloatProperty(AOMFloatProperty::kValueNow, value_now, is_null); |
+ NotifyAttributeChanged(aria_valuenowAttr); |
+} |
+ |
AtomicString AccessibleNode::valueText() const { |
return GetProperty(element_, AOMStringProperty::kValueText); |
} |
@@ -396,21 +658,47 @@ void AccessibleNode::SetStringProperty(AOMStringProperty property, |
string_properties_.push_back(std::make_pair(property, value)); |
} |
-void AccessibleNode::SetBooleanProperty(AOMBooleanProperty property, |
- bool value, |
- bool is_null) { |
- for (size_t i = 0; i < boolean_properties_.size(); i++) { |
- auto& item = boolean_properties_[i]; |
+template <typename P, typename T> |
+static void SetProperty(P property, |
+ T value, |
+ bool is_null, |
+ Vector<std::pair<P, T>>& properties) { |
+ for (size_t i = 0; i < properties.size(); i++) { |
+ auto& item = properties[i]; |
if (item.first == property) { |
if (is_null) |
- boolean_properties_.erase(i); |
+ properties.erase(i); |
else |
item.second = value; |
return; |
} |
} |
- boolean_properties_.push_back(std::make_pair(property, value)); |
+ properties.push_back(std::make_pair(property, value)); |
+} |
+ |
+void AccessibleNode::SetBooleanProperty(AOMBooleanProperty property, |
+ bool value, |
+ bool is_null) { |
+ SetProperty(property, value, is_null, boolean_properties_); |
+} |
+ |
+void AccessibleNode::SetIntProperty(AOMIntProperty property, |
+ int32_t value, |
+ bool is_null) { |
+ SetProperty(property, value, is_null, int_properties_); |
+} |
+ |
+void AccessibleNode::SetUIntProperty(AOMUIntProperty property, |
+ uint32_t value, |
+ bool is_null) { |
+ SetProperty(property, value, is_null, uint_properties_); |
+} |
+ |
+void AccessibleNode::SetFloatProperty(AOMFloatProperty property, |
+ float value, |
+ bool is_null) { |
+ SetProperty(property, value, is_null, float_properties_); |
} |
void AccessibleNode::NotifyAttributeChanged( |