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

Unified Diff: third_party/WebKit/Source/core/dom/AccessibleNode.cpp

Issue 2805493002: Boolean properties for Accessibility Object Model Phase 1 (Closed)
Patch Set: Back to previous patchset, ready to land Created 3 years, 7 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
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 a8dd6c111a06a752f8f053130bee947a37b7df45..4f6eaa48eb7cf63d3f84da146e5e4d88c65080e5 100644
--- a/third_party/WebKit/Source/core/dom/AccessibleNode.cpp
+++ b/third_party/WebKit/Source/core/dom/AccessibleNode.cpp
@@ -27,7 +27,7 @@ const AtomicString& AccessibleNode::GetProperty(Element* element,
if (AccessibleNode* accessible_node = element->ExistingAccessibleNode()) {
for (const auto& item : accessible_node->string_properties_) {
- if (item.first == property)
+ if (item.first == property && !item.second.IsNull())
return item.second;
}
}
@@ -36,6 +36,26 @@ const AtomicString& AccessibleNode::GetProperty(Element* element,
}
// 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;
+ }
+ }
+ }
+
+ return false;
+}
+
+// static
const AtomicString& AccessibleNode::GetPropertyOrARIAAttribute(
Element* element,
AOMStringProperty property) {
@@ -49,39 +69,102 @@ const AtomicString& AccessibleNode::GetPropertyOrARIAAttribute(
// Fall back on the equivalent ARIA attribute.
switch (property) {
case AOMStringProperty::kAutocomplete:
- return element->getAttribute(aria_autocompleteAttr);
+ return element->FastGetAttribute(aria_autocompleteAttr);
case AOMStringProperty::kChecked:
- return element->getAttribute(aria_checkedAttr);
+ return element->FastGetAttribute(aria_checkedAttr);
case AOMStringProperty::kCurrent:
- return element->getAttribute(aria_currentAttr);
+ return element->FastGetAttribute(aria_currentAttr);
case AOMStringProperty::kInvalid:
- return element->getAttribute(aria_invalidAttr);
+ return element->FastGetAttribute(aria_invalidAttr);
case AOMStringProperty::kKeyShortcuts:
- return element->getAttribute(aria_keyshortcutsAttr);
+ return element->FastGetAttribute(aria_keyshortcutsAttr);
case AOMStringProperty::kLabel:
- return element->getAttribute(aria_labelAttr);
+ return element->FastGetAttribute(aria_labelAttr);
case AOMStringProperty::kLive:
- return element->getAttribute(aria_liveAttr);
+ return element->FastGetAttribute(aria_liveAttr);
case AOMStringProperty::kOrientation:
- return element->getAttribute(aria_orientationAttr);
+ return element->FastGetAttribute(aria_orientationAttr);
case AOMStringProperty::kPlaceholder:
- return element->getAttribute(aria_placeholderAttr);
+ return element->FastGetAttribute(aria_placeholderAttr);
case AOMStringProperty::kRelevant:
- return element->getAttribute(aria_relevantAttr);
+ return element->FastGetAttribute(aria_relevantAttr);
case AOMStringProperty::kRole:
- return element->getAttribute(roleAttr);
+ return element->FastGetAttribute(roleAttr);
case AOMStringProperty::kRoleDescription:
- return element->getAttribute(aria_roledescriptionAttr);
+ return element->FastGetAttribute(aria_roledescriptionAttr);
case AOMStringProperty::kSort:
- return element->getAttribute(aria_sortAttr);
+ return element->FastGetAttribute(aria_sortAttr);
case AOMStringProperty::kValueText:
- return element->getAttribute(aria_valuetextAttr);
+ return element->FastGetAttribute(aria_valuetextAttr);
}
NOTREACHED();
return g_null_atom;
}
+// static
+bool AccessibleNode::GetPropertyOrARIAAttribute(Element* element,
+ AOMBooleanProperty property,
+ bool& is_null) {
+ is_null = true;
+ if (!element)
+ return false;
+
+ bool result = GetProperty(element, property, is_null);
+ if (!is_null)
+ return result;
+
+ // Fall back on the equivalent ARIA attribute.
+ AtomicString attr_value;
+ switch (property) {
+ case AOMBooleanProperty::kAtomic:
+ attr_value = element->FastGetAttribute(aria_atomicAttr);
+ break;
+ case AOMBooleanProperty::kBusy:
+ attr_value = element->FastGetAttribute(aria_busyAttr);
+ break;
+ case AOMBooleanProperty::kDisabled:
+ attr_value = element->FastGetAttribute(aria_disabledAttr);
+ break;
+ case AOMBooleanProperty::kExpanded:
+ attr_value = element->FastGetAttribute(aria_expandedAttr);
+ break;
+ case AOMBooleanProperty::kHidden:
+ attr_value = element->FastGetAttribute(aria_hiddenAttr);
+ break;
+ case AOMBooleanProperty::kModal:
+ attr_value = element->FastGetAttribute(aria_modalAttr);
+ break;
+ case AOMBooleanProperty::kMultiline:
+ attr_value = element->FastGetAttribute(aria_multilineAttr);
+ break;
+ case AOMBooleanProperty::kMultiselectable:
+ attr_value = element->FastGetAttribute(aria_multiselectableAttr);
+ break;
+ case AOMBooleanProperty::kReadOnly:
+ attr_value = element->FastGetAttribute(aria_readonlyAttr);
+ break;
+ case AOMBooleanProperty::kRequired:
+ attr_value = element->FastGetAttribute(aria_requiredAttr);
+ break;
+ case AOMBooleanProperty::kSelected:
+ attr_value = element->FastGetAttribute(aria_selectedAttr);
+ break;
+ }
+
+ is_null = attr_value.IsNull();
+ return EqualIgnoringASCIICase(attr_value, "true");
+}
+
+bool AccessibleNode::atomic(bool& is_null) const {
+ return GetProperty(element_, AOMBooleanProperty::kAtomic, is_null);
+}
+
+void AccessibleNode::setAtomic(bool atomic, bool is_null) {
+ SetBooleanProperty(AOMBooleanProperty::kAtomic, atomic, is_null);
+ NotifyAttributeChanged(aria_atomicAttr);
+}
+
AtomicString AccessibleNode::autocomplete() const {
return GetProperty(element_, AOMStringProperty::kAutocomplete);
}
@@ -91,6 +174,15 @@ void AccessibleNode::setAutocomplete(const AtomicString& autocomplete) {
NotifyAttributeChanged(aria_autocompleteAttr);
}
+bool AccessibleNode::busy(bool& is_null) const {
+ return GetProperty(element_, AOMBooleanProperty::kBusy, is_null);
+}
+
+void AccessibleNode::setBusy(bool busy, bool is_null) {
+ SetBooleanProperty(AOMBooleanProperty::kBusy, busy, is_null);
+ NotifyAttributeChanged(aria_busyAttr);
+}
+
AtomicString AccessibleNode::checked() const {
return GetProperty(element_, AOMStringProperty::kChecked);
}
@@ -111,6 +203,33 @@ void AccessibleNode::setCurrent(const AtomicString& current) {
cache->HandleAttributeChanged(aria_currentAttr, element_);
}
+bool AccessibleNode::disabled(bool& is_null) const {
+ return GetProperty(element_, AOMBooleanProperty::kDisabled, is_null);
+}
+
+void AccessibleNode::setDisabled(bool disabled, bool is_null) {
+ SetBooleanProperty(AOMBooleanProperty::kDisabled, disabled, is_null);
+ NotifyAttributeChanged(aria_disabledAttr);
+}
+
+bool AccessibleNode::expanded(bool& is_null) const {
+ return GetProperty(element_, AOMBooleanProperty::kExpanded, is_null);
+}
+
+void AccessibleNode::setExpanded(bool expanded, bool is_null) {
+ SetBooleanProperty(AOMBooleanProperty::kExpanded, expanded, is_null);
+ NotifyAttributeChanged(aria_expandedAttr);
+}
+
+bool AccessibleNode::hidden(bool& is_null) const {
+ return GetProperty(element_, AOMBooleanProperty::kHidden, is_null);
+}
+
+void AccessibleNode::setHidden(bool hidden, bool is_null) {
+ SetBooleanProperty(AOMBooleanProperty::kHidden, hidden, is_null);
+ NotifyAttributeChanged(aria_hiddenAttr);
+}
+
AtomicString AccessibleNode::invalid() const {
return GetProperty(element_, AOMStringProperty::kInvalid);
}
@@ -147,6 +266,34 @@ void AccessibleNode::setLive(const AtomicString& live) {
NotifyAttributeChanged(aria_liveAttr);
}
+bool AccessibleNode::modal(bool& is_null) const {
+ return GetProperty(element_, AOMBooleanProperty::kModal, is_null);
+}
+
+void AccessibleNode::setModal(bool modal, bool is_null) {
+ SetBooleanProperty(AOMBooleanProperty::kModal, modal, is_null);
+ NotifyAttributeChanged(aria_modalAttr);
+}
+
+bool AccessibleNode::multiline(bool& is_null) const {
+ return GetProperty(element_, AOMBooleanProperty::kMultiline, is_null);
+}
+
+void AccessibleNode::setMultiline(bool multiline, bool is_null) {
+ SetBooleanProperty(AOMBooleanProperty::kMultiline, multiline, is_null);
+ NotifyAttributeChanged(aria_multilineAttr);
+}
+
+bool AccessibleNode::multiselectable(bool& is_null) const {
+ return GetProperty(element_, AOMBooleanProperty::kMultiselectable, is_null);
+}
+
+void AccessibleNode::setMultiselectable(bool multiselectable, bool is_null) {
+ SetBooleanProperty(AOMBooleanProperty::kMultiselectable, multiselectable,
+ is_null);
+ NotifyAttributeChanged(aria_multiselectableAttr);
+}
+
AtomicString AccessibleNode::orientation() const {
return GetProperty(element_, AOMStringProperty::kOrientation);
}
@@ -165,6 +312,15 @@ void AccessibleNode::setPlaceholder(const AtomicString& placeholder) {
NotifyAttributeChanged(aria_placeholderAttr);
}
+bool AccessibleNode::readOnly(bool& is_null) const {
+ return GetProperty(element_, AOMBooleanProperty::kReadOnly, is_null);
+}
+
+void AccessibleNode::setReadOnly(bool read_only, bool is_null) {
+ SetBooleanProperty(AOMBooleanProperty::kReadOnly, read_only, is_null);
+ NotifyAttributeChanged(aria_readonlyAttr);
+}
+
AtomicString AccessibleNode::relevant() const {
return GetProperty(element_, AOMStringProperty::kRelevant);
}
@@ -174,6 +330,15 @@ void AccessibleNode::setRelevant(const AtomicString& relevant) {
NotifyAttributeChanged(aria_relevantAttr);
}
+bool AccessibleNode::required(bool& is_null) const {
+ return GetProperty(element_, AOMBooleanProperty::kRequired, is_null);
+}
+
+void AccessibleNode::setRequired(bool required, bool is_null) {
+ SetBooleanProperty(AOMBooleanProperty::kRequired, required, is_null);
+ NotifyAttributeChanged(aria_requiredAttr);
+}
+
AtomicString AccessibleNode::role() const {
return GetProperty(element_, AOMStringProperty::kRole);
}
@@ -192,6 +357,15 @@ void AccessibleNode::setRoleDescription(const AtomicString& role_description) {
NotifyAttributeChanged(aria_roledescriptionAttr);
}
+bool AccessibleNode::selected(bool& is_null) const {
+ return GetProperty(element_, AOMBooleanProperty::kSelected, is_null);
+}
+
+void AccessibleNode::setSelected(bool selected, bool is_null) {
+ SetBooleanProperty(AOMBooleanProperty::kSelected, selected, is_null);
+ NotifyAttributeChanged(aria_selectedAttr);
+}
+
AtomicString AccessibleNode::sort() const {
return GetProperty(element_, AOMStringProperty::kSort);
}
@@ -222,6 +396,23 @@ 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];
+ if (item.first == property) {
+ if (is_null)
+ boolean_properties_.erase(i);
+ else
+ item.second = value;
+ return;
+ }
+ }
+
+ boolean_properties_.push_back(std::make_pair(property, value));
+}
+
void AccessibleNode::NotifyAttributeChanged(
const blink::QualifiedName& attribute) {
// TODO(dmazzoni): Make a cleaner API for this rather than pretending
« no previous file with comments | « third_party/WebKit/Source/core/dom/AccessibleNode.h ('k') | third_party/WebKit/Source/core/dom/AccessibleNode.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698