Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / modules / accessibility / AXNodeObject.h
blob79c0765c764e7cb2b197134bef62f4d797096e9b
1 /*
2 * Copyright (C) 2012, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 #ifndef AXNodeObject_h
30 #define AXNodeObject_h
32 #include "modules/ModulesExport.h"
33 #include "modules/accessibility/AXObject.h"
34 #include "wtf/Forward.h"
36 namespace blink {
38 class AXObjectCacheImpl;
39 class Element;
40 class HTMLLabelElement;
41 class LayoutRect;
42 class Node;
44 class MODULES_EXPORT AXNodeObject : public AXObject {
45 protected:
46 AXNodeObject(Node*, AXObjectCacheImpl&);
48 public:
49 static AXNodeObject* create(Node*, AXObjectCacheImpl&);
50 ~AXNodeObject() override;
51 DECLARE_VIRTUAL_TRACE();
53 protected:
54 // Protected data.
55 AccessibilityRole m_ariaRole;
56 bool m_childrenDirty;
57 #if ENABLE(ASSERT)
58 bool m_initialized;
59 #endif
61 bool computeAccessibilityIsIgnored(IgnoredReasons* = nullptr) const override;
62 const AXObject* inheritsPresentationalRoleFrom() const override;
63 virtual AccessibilityRole determineAccessibilityRole();
64 AccessibilityRole determineAccessibilityRoleUtil();
65 String accessibilityDescriptionForElements(WillBeHeapVector<RawPtrWillBeMember<Element>> &elements) const;
66 void alterSliderValue(bool increase);
67 String ariaAccessibilityDescription() const;
68 String ariaAutoComplete() const;
69 void ariaLabelledbyElements(WillBeHeapVector<RawPtrWillBeMember<Element>>& elements) const;
70 AccessibilityRole determineAriaRoleAttribute() const;
71 void tokenVectorFromAttribute(Vector<String>&, const QualifiedName&) const;
72 void elementsFromAttribute(WillBeHeapVector<RawPtrWillBeMember<Element>>& elements, const QualifiedName&) const;
73 void accessibilityChildrenFromAttribute(QualifiedName attr, AccessibilityChildrenVector&) const;
75 bool hasContentEditableAttributeSet() const;
76 bool isTextControl() const override;
77 bool allowsTextRanges() const { return isTextControl(); }
78 // This returns true if it's focusable but it's not content editable and it's not a control or ARIA control.
79 bool isGenericFocusableElement() const;
80 HTMLLabelElement* labelForElement(const Element*) const;
81 AXObject* menuButtonForMenu() const;
82 Element* menuItemElementForMenu() const;
83 Element* mouseButtonListener() const;
84 String deprecatedPlaceholder() const;
85 AccessibilityRole remapAriaRoleDueToParent(AccessibilityRole) const;
86 bool isNativeCheckboxOrRadio() const;
87 void setNode(Node*);
88 AXObject* correspondingControlForLabelElement() const;
89 HTMLLabelElement* labelElementContainer() const;
92 // Overridden from AXObject.
95 void init() override;
96 void detach() override;
97 bool isDetached() const override { return !m_node; }
98 bool isAXNodeObject() const final { return true; }
100 // Check object role or purpose.
101 bool isAnchor() const final;
102 bool isControl() const override;
103 bool isControllingVideoElement() const;
104 bool isEditable() const override { return isTextControl(); }
105 bool isEmbeddedObject() const final;
106 bool isFieldset() const final;
107 bool isHeading() const final;
108 bool isHovered() const final;
109 bool isImage() const final;
110 bool isImageButton() const;
111 bool isInputImage() const final;
112 bool isLink() const final;
113 bool isMenu() const final;
114 bool isMenuButton() const final;
115 bool isMeter() const final;
116 bool isMultiSelectable() const override;
117 bool isNativeImage() const;
118 bool isNativeTextControl() const final;
119 bool isNonNativeTextControl() const final;
120 bool isPasswordField() const final;
121 bool isProgressIndicator() const override;
122 bool isRichlyEditable() const override { return hasContentEditableAttributeSet(); }
123 bool isSlider() const override;
124 bool isNativeSlider() const override;
126 // Check object state.
127 bool isChecked() const final;
128 bool isClickable() const final;
129 bool isEnabled() const override;
130 AccessibilityExpanded isExpanded() const override;
131 bool isIndeterminate() const final;
132 bool isPressed() const final;
133 bool isReadOnly() const override;
134 bool isRequired() const final;
136 // Check whether certain properties can be modified.
137 bool canSetFocusAttribute() const override;
138 bool canSetValueAttribute() const override;
140 // Properties of static elements.
141 RGBA32 colorValue() const final;
142 bool canvasHasFallbackContent() const final;
143 bool deprecatedExposesTitleUIElement() const override;
144 int headingLevel() const final;
145 unsigned hierarchicalLevel() const final;
146 AccessibilityOrientation orientation() const override;
147 String text() const override;
148 AXObject* deprecatedTitleUIElement() const override;
150 // Properties of interactive elements.
151 AccessibilityButtonState checkboxOrRadioValue() const final;
152 InvalidState invalidState() const final;
153 // Only used when invalidState() returns InvalidStateOther.
154 String ariaInvalidValue() const final;
155 String valueDescription() const override;
156 float valueForRange() const override;
157 float maxValueForRange() const override;
158 float minValueForRange() const override;
159 String stringValue() const override;
161 // ARIA attributes.
162 String ariaDescribedByAttribute() const final;
163 String ariaLabelledbyAttribute() const final;
164 AccessibilityRole ariaRoleAttribute() const final;
166 // Accessibility Text.
167 String deprecatedTextUnderElement(TextUnderElementMode) const override;
168 String deprecatedAccessibilityDescription() const override;
169 String deprecatedTitle(TextUnderElementMode) const override;
170 String deprecatedHelpText() const override;
171 String computedName() const override;
173 // New AX name calculation.
174 String textAlternative(bool recursive, bool inAriaLabelledByTraversal, AXObjectSet& visited, AXNameFrom&, AXObjectVector* nameObjects, NameSources*) const override;
176 // Location and click point in frame-relative coordinates.
177 LayoutRect elementRect() const override;
179 // High-level accessibility tree access.
180 AXObject* computeParent() const override;
181 AXObject* computeParentIfExists() const override;
183 // Low-level accessibility tree exploration.
184 AXObject* firstChild() const override;
185 AXObject* nextSibling() const override;
186 void addChildren() override;
187 bool canHaveChildren() const override;
188 void addChild(AXObject*);
189 void insertChild(AXObject*, unsigned index);
191 // DOM and Render tree access.
192 Element* actionElement() const final;
193 Element* anchorElement() const override;
194 Document* document() const override;
195 Node* node() const override { return m_node; }
197 // Modify or take an action on an object.
198 void setFocused(bool) final;
199 void increment() final;
200 void decrement() final;
202 // Notifications that this object may have changed.
203 void childrenChanged() override;
204 void selectionChanged() final;
205 void textChanged() override;
206 void updateAccessibilityRole() final;
208 // Position in set and Size of set
209 int posInSet() const override;
210 int setSize() const override;
212 // Aria-owns.
213 void computeAriaOwnsChildren(HeapVector<Member<AXObject>>& ownedChildren);
215 private:
216 RawPtrWillBeMember<Node> m_node;
218 String deprecatedAlternativeTextForWebArea() const;
219 void deprecatedAlternativeText(HeapVector<Member<AccessibilityText>>&) const;
220 void deprecatedAriaLabelledbyText(HeapVector<Member<AccessibilityText>>&) const;
222 String textFromDescendants(AXObjectSet& visited) const;
223 String textFromElements(bool inAriaLabelledByTraversal, AXObjectSet& visited, WillBeHeapVector<RawPtrWillBeMember<Element>>& elements, AXObjectVector* nameObjects) const;
224 String textFromAriaLabelledby(AXObjectSet& visited, AXObjectVector* nameObjects) const;
225 String nativeTextAlternative(AXObjectSet& visited, AXNameFrom&, AXObjectVector* nameObjects, NameSources*, bool* foundTextAlternative) const;
226 float stepValueForRange() const;
227 AXObject* findChildWithTagName(const HTMLQualifiedName&) const;
228 bool isDescendantOfElementType(const HTMLQualifiedName& tagName) const;
231 DEFINE_AX_OBJECT_TYPE_CASTS(AXNodeObject, isAXNodeObject());
233 } // namespace blink
235 #endif // AXNodeObject_h