Chromium Code Reviews| 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..f8e725b718de0436166b712796824b8d554bb115 100644 |
| --- a/third_party/WebKit/Source/core/dom/AccessibleNode.cpp |
| +++ b/third_party/WebKit/Source/core/dom/AccessibleNode.cpp |
| @@ -35,27 +35,78 @@ const AtomicString& AccessibleNode::GetProperty(Element* element, |
| return g_null_atom; |
| } |
| +template <typename P, typename T> |
| +static T GetPropertyHelper(P property, |
|
aboxhall
2017/05/19 05:09:47
Naming suggestion: FindPropertyValue
dmazzoni
2017/05/19 20:23:08
Done.
|
| + 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; |
| - } |
| - } |
| + if (element && element->ExistingAccessibleNode()) { |
| + return GetPropertyHelper( |
| + property, is_null, |
| + element->ExistingAccessibleNode()->boolean_properties_, false); |
| } |
| return false; |
| } |
| // static |
| +float AccessibleNode::GetProperty(Element* element, |
| + AOMFloatProperty property, |
| + bool& is_null) { |
| + is_null = true; |
| + if (element && element->ExistingAccessibleNode()) { |
| + return GetPropertyHelper( |
| + property, is_null, element->ExistingAccessibleNode()->float_properties_, |
| + 0.0f); |
| + } |
| + |
| + return 0.0; |
|
aboxhall
2017/05/19 05:09:47
Why not something like:
float default = 0.0f;
if
dmazzoni
2017/05/19 20:23:08
Good suggestions, done.
|
| +} |
| + |
| +// static |
| +int32_t AccessibleNode::GetProperty(Element* element, |
| + AOMIntProperty property, |
| + bool& is_null) { |
| + is_null = true; |
| + if (element && element->ExistingAccessibleNode()) { |
| + return GetPropertyHelper(property, is_null, |
| + element->ExistingAccessibleNode()->int_properties_, |
| + 0); |
| + } |
| + |
| + return 0; |
| +} |
| + |
| +// static |
| +uint32_t AccessibleNode::GetProperty(Element* element, |
| + AOMUIntProperty property, |
| + bool& is_null) { |
| + is_null = true; |
| + if (element && element->ExistingAccessibleNode()) { |
| + return GetPropertyHelper( |
| + property, is_null, element->ExistingAccessibleNode()->uint_properties_, |
| + 0U); |
| + } |
| + |
| + return 0; |
| +} |
| + |
| +// static |
| const AtomicString& AccessibleNode::GetPropertyOrARIAAttribute( |
| Element* element, |
| AOMStringProperty property) { |
| @@ -156,6 +207,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(); |
| +} |
| + |
| +// 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(); |
| +} |
| + |
| bool AccessibleNode::atomic(bool& is_null) const { |
| return GetProperty(element_, AOMBooleanProperty::kAtomic, is_null); |
| } |
| @@ -192,6 +342,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 +434,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 +498,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 +552,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 +588,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 +606,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 +654,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( |