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

Side by Side Diff: third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp

Issue 2589273002: Add sparse accessibility attribute interface to Blink (Closed)
Patch Set: Try to fix win component build compile Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012, Google Inc. All rights reserved. 2 * Copyright (C) 2012, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 14 matching lines...) Expand all
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "modules/accessibility/AXNodeObject.h" 29 #include "modules/accessibility/AXNodeObject.h"
30 30
31 #include "core/InputTypeNames.h" 31 #include "core/InputTypeNames.h"
32 #include "core/dom/DocumentUserGestureToken.h" 32 #include "core/dom/DocumentUserGestureToken.h"
33 #include "core/dom/Element.h" 33 #include "core/dom/Element.h"
34 #include "core/dom/NodeTraversal.h" 34 #include "core/dom/NodeTraversal.h"
35 #include "core/dom/QualifiedName.h"
35 #include "core/dom/Text.h" 36 #include "core/dom/Text.h"
36 #include "core/dom/shadow/FlatTreeTraversal.h" 37 #include "core/dom/shadow/FlatTreeTraversal.h"
37 #include "core/editing/EditingUtilities.h" 38 #include "core/editing/EditingUtilities.h"
38 #include "core/editing/markers/DocumentMarkerController.h" 39 #include "core/editing/markers/DocumentMarkerController.h"
39 #include "core/frame/FrameView.h" 40 #include "core/frame/FrameView.h"
40 #include "core/html/HTMLDListElement.h" 41 #include "core/html/HTMLDListElement.h"
41 #include "core/html/HTMLFieldSetElement.h" 42 #include "core/html/HTMLFieldSetElement.h"
42 #include "core/html/HTMLFrameElementBase.h" 43 #include "core/html/HTMLFrameElementBase.h"
43 #include "core/html/HTMLImageElement.h" 44 #include "core/html/HTMLImageElement.h"
44 #include "core/html/HTMLInputElement.h" 45 #include "core/html/HTMLInputElement.h"
(...skipping 18 matching lines...) Expand all
63 #include "core/svg/SVGElement.h" 64 #include "core/svg/SVGElement.h"
64 #include "modules/accessibility/AXObjectCacheImpl.h" 65 #include "modules/accessibility/AXObjectCacheImpl.h"
65 #include "platform/UserGestureIndicator.h" 66 #include "platform/UserGestureIndicator.h"
66 #include "platform/text/PlatformLocale.h" 67 #include "platform/text/PlatformLocale.h"
67 #include "wtf/text/StringBuilder.h" 68 #include "wtf/text/StringBuilder.h"
68 69
69 namespace blink { 70 namespace blink {
70 71
71 using namespace HTMLNames; 72 using namespace HTMLNames;
72 73
74 class AddSparseAttributeHelper {
75 public:
76 virtual void Run(const AXObject*,
77 AXSparseAttributeMap&,
78 const AtomicString& value) = 0;
79 };
80
81 typedef HashMap<QualifiedName, AddSparseAttributeHelper*>
82 AXSparseAttributeHelperMap;
83
84 class AddBoolAttributeHelper : public AddSparseAttributeHelper {
85 public:
86 AddBoolAttributeHelper(AXBoolAttribute attribute) : m_attribute(attribute) {}
87
88 private:
89 AXBoolAttribute m_attribute;
90
91 void Run(const AXObject* obj,
92 AXSparseAttributeMap& attributeMap,
93 const AtomicString& value) override {
94 attributeMap.addBoolAttribute(m_attribute,
95 equalIgnoringCase(value, "true"));
96 }
97 };
98
99 class AddStringAttributeHelper : public AddSparseAttributeHelper {
100 public:
101 AddStringAttributeHelper(AXStringAttribute attribute)
102 : m_attribute(attribute) {}
103
104 private:
105 AXStringAttribute m_attribute;
106
107 void Run(const AXObject* obj,
108 AXSparseAttributeMap& attributeMap,
109 const AtomicString& value) override {
110 attributeMap.addStringAttribute(m_attribute, value);
111 }
112 };
113
114 class AddObjectAttributeHelper : public AddSparseAttributeHelper {
115 public:
116 AddObjectAttributeHelper(AXObjectAttribute attribute)
117 : m_attribute(attribute) {}
118
119 private:
120 AXObjectAttribute m_attribute;
121
122 void Run(const AXObject* obj,
123 AXSparseAttributeMap& attributeMap,
124 const AtomicString& value) override {
125 if (value.isNull() || value.isEmpty())
126 return;
127
128 Node* node = obj->getNode();
129 if (!node || !node->isElementNode())
130 return;
131 Element* target = toElement(node)->treeScope().getElementById(value);
132 if (!target)
133 return;
134 AXObject* axTarget = obj->axObjectCache().getOrCreate(target);
135 if (axTarget)
136 attributeMap.addObjectAttribute(m_attribute, axTarget);
137 }
138 };
139
140 class AddObjectVectorAttributeHelper : public AddSparseAttributeHelper {
141 public:
142 AddObjectVectorAttributeHelper(AXObjectVectorAttribute attribute)
143 : m_attribute(attribute) {}
144
145 private:
146 AXObjectVectorAttribute m_attribute;
147
148 void Run(const AXObject* obj,
149 AXSparseAttributeMap& attributeMap,
150 const AtomicString& value) override {
151 Node* node = obj->getNode();
152 if (!node || !node->isElementNode())
153 return;
154
155 String attributeValue = value.getString();
156 if (attributeValue.isEmpty())
157 return;
158
159 attributeValue.simplifyWhiteSpace();
160 Vector<String> ids;
161 attributeValue.split(' ', ids);
162 if (ids.isEmpty())
163 return;
164
165 HeapVector<Member<AXObject>> objects;
166 TreeScope& scope = node->treeScope();
167 for (const auto& id : ids) {
168 if (Element* idElement = scope.getElementById(AtomicString(id))) {
169 AXObject* axIdElement = obj->axObjectCache().getOrCreate(idElement);
170 if (axIdElement && !axIdElement->accessibilityIsIgnored())
171 objects.append(axIdElement);
172 }
173 }
174
175 attributeMap.addObjectVectorAttribute(m_attribute, objects);
176 }
177 };
178
73 AXNodeObject::AXNodeObject(Node* node, AXObjectCacheImpl& axObjectCache) 179 AXNodeObject::AXNodeObject(Node* node, AXObjectCacheImpl& axObjectCache)
74 : AXObject(axObjectCache), 180 : AXObject(axObjectCache),
75 m_ariaRole(UnknownRole), 181 m_ariaRole(UnknownRole),
76 m_childrenDirty(false), 182 m_childrenDirty(false),
77 #if ENABLE(ASSERT) 183 #if ENABLE(ASSERT)
78 m_initialized(false), 184 m_initialized(false),
79 #endif 185 #endif
80 m_node(node) { 186 m_node(node) {
81 } 187 }
82 188
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 m_initialized = true; 851 m_initialized = true;
746 #endif 852 #endif
747 m_role = determineAccessibilityRole(); 853 m_role = determineAccessibilityRole();
748 } 854 }
749 855
750 void AXNodeObject::detach() { 856 void AXNodeObject::detach() {
751 AXObject::detach(); 857 AXObject::detach();
752 m_node = nullptr; 858 m_node = nullptr;
753 } 859 }
754 860
861 void AXNodeObject::getSparseAXAttributes(
862 AXSparseAttributeMap& sparseAttributeMap) const {
863 Node* node = this->getNode();
864 if (!node || !node->isElementNode())
865 return;
866
867 // Use a map from attribute name to properties of that attribute.
868 // That way we only need to iterate over the list of attributes once,
869 // rather than calling getAttribute() once for each possible obscure
870 // accessibility attribute.
871 DEFINE_STATIC_LOCAL(AXSparseAttributeHelperMap, axSparseAttributeHelperMap,
872 ());
873 if (axSparseAttributeHelperMap.isEmpty()) {
874 axSparseAttributeHelperMap.set(
aboxhall 2017/01/10 05:59:59 Perhaps pull this block out into a helper function
dmazzoni 2017/01/12 03:36:24 Done.
875 aria_activedescendantAttr,
876 new AddObjectAttributeHelper(AXObjectAttribute::AriaActiveDescendant));
877 axSparseAttributeHelperMap.set(aria_controlsAttr,
878 new AddObjectVectorAttributeHelper(
879 AXObjectVectorAttribute::AriaControls));
880 axSparseAttributeHelperMap.set(aria_detailsAttr,
881 new AddObjectVectorAttributeHelper(
882 AXObjectVectorAttribute::AriaDetails));
883 axSparseAttributeHelperMap.set(
884 aria_errormessageAttr,
885 new AddObjectAttributeHelper(AXObjectAttribute::AriaErrorMessage));
886 axSparseAttributeHelperMap.set(aria_flowtoAttr,
887 new AddObjectVectorAttributeHelper(
888 AXObjectVectorAttribute::AriaFlowTo));
889 axSparseAttributeHelperMap.set(
890 aria_keyshortcutsAttr,
891 new AddStringAttributeHelper(AXStringAttribute::AriaKeyShortcuts));
892 axSparseAttributeHelperMap.set(
893 aria_modalAttr, new AddBoolAttributeHelper(AXBoolAttribute::AriaModal));
894 axSparseAttributeHelperMap.set(
895 aria_roledescriptionAttr,
896 new AddStringAttributeHelper(AXStringAttribute::AriaRoleDescription));
897 }
898
899 AttributeCollection attributes = toElement(node)->attributesWithoutUpdate();
900 for (const Attribute& attr : attributes) {
901 AddSparseAttributeHelper* helper =
902 axSparseAttributeHelperMap.get(attr.name());
903 if (helper)
904 helper->Run(this, sparseAttributeMap, attr.value());
905 }
906 }
907
755 bool AXNodeObject::isAnchor() const { 908 bool AXNodeObject::isAnchor() const {
756 return !isNativeImage() && isLink(); 909 return !isNativeImage() && isLink();
757 } 910 }
758 911
759 bool AXNodeObject::isControl() const { 912 bool AXNodeObject::isControl() const {
760 Node* node = this->getNode(); 913 Node* node = this->getNode();
761 if (!node) 914 if (!node)
762 return false; 915 return false;
763 916
764 return ((node->isElementNode() && toElement(node)->isFormControlElement()) || 917 return ((node->isElementNode() && toElement(node)->isFormControlElement()) ||
(...skipping 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2892 return String(); 3045 return String();
2893 return toTextControlElement(node)->strippedPlaceholder(); 3046 return toTextControlElement(node)->strippedPlaceholder();
2894 } 3047 }
2895 3048
2896 DEFINE_TRACE(AXNodeObject) { 3049 DEFINE_TRACE(AXNodeObject) {
2897 visitor->trace(m_node); 3050 visitor->trace(m_node);
2898 AXObject::trace(visitor); 3051 AXObject::trace(visitor);
2899 } 3052 }
2900 3053
2901 } // namespace blink 3054 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698