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

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

Issue 2750533006: Initial skeleton of Accessibility Object Model Phase 1 (Closed)
Patch Set: Add comment about ugly AXObjectCache interface Created 3 years, 9 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
new file mode 100644
index 0000000000000000000000000000000000000000..6fc8b8090bdef9499e26ceed3c77ab518b62a814
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/AccessibleNode.cpp
@@ -0,0 +1,75 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/dom/AccessibleNode.h"
+
+#include "core/dom/AXObjectCache.h"
+#include "core/dom/AXUtils.h"
+#include "core/dom/Element.h"
+#include "core/frame/Settings.h"
+
+namespace blink {
+
+AccessibleNode::AccessibleNode(Element* element) : m_element(element) {
+ DCHECK(RuntimeEnabledFeatures::accessibilityObjectModelEnabled());
+}
+
+AccessibleNode::~AccessibleNode() {}
+
+const AtomicString& AccessibleNode::getProperty(
+ AOMStringProperty property) const {
+ if (!m_element)
+ return nullAtom;
+
+ const AtomicString& result = m_stringProperties.at(property);
esprehn 2017/03/22 03:40:31 I'd suggest using a vector instead, you probably w
dmazzoni 2017/03/23 03:36:40 The reason I did this was memory. There are 48 pro
+ if (result.isNull())
+ return nullAtom;
+
+ switch (property) {
+ case AOMStringProperty::Role:
+ if (!AXUtils::getInstance()->isValidRoleAttribute(result))
esprehn 2017/03/22 03:40:31 This feels like over abstraction going through a s
dmazzoni 2017/03/23 03:36:40 Removed, we're not doing validation for now.
+ return nullAtom;
+ break;
+ case AOMStringProperty::Label:
+ // No validation needed.
+ break;
+ case AOMStringProperty::None:
+ NOTREACHED();
+ return nullAtom;
+ }
+
+ return result;
+}
+
+String AccessibleNode::role() const {
esprehn 2017/03/22 03:40:31 return AtomicString
dmazzoni 2017/03/23 03:36:40 Done throughout.
+ return getProperty(AOMStringProperty::Role);
+}
+
+void AccessibleNode::setRole(const String& role) {
esprehn 2017/03/22 03:40:31 Take an AtomicString here instead
+ if (!m_element)
+ return;
+
+ m_stringProperties.set(AOMStringProperty::Role, AtomicString(role));
+
+ // TODO(dmazzoni): Make a cleaner API for this rather than pretending
+ // the DOM attribute changed.
+ if (AXObjectCache* cache = m_element->document().axObjectCache())
+ cache->handleAttributeChanged(HTMLNames::roleAttr, m_element);
+}
+
+String AccessibleNode::label() const {
esprehn 2017/03/22 03:40:31 ditto
+ return getProperty(AOMStringProperty::Label);
+}
+
+void AccessibleNode::setLabel(const String& label) {
esprehn 2017/03/22 03:40:31 ditto
+ m_stringProperties.set(AOMStringProperty::Label, AtomicString(label));
+ if (AXObjectCache* cache = m_element->document().axObjectCache())
+ cache->handleAttributeChanged(HTMLNames::aria_labelAttr, m_element);
+}
+
+DEFINE_TRACE(AccessibleNode) {
+ visitor->trace(m_element);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698