1/*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
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 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.
16 *
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.
27 */
28
29#pragma once
30
31#include "AccessibilityNodeObject.h"
32#include "LayoutRect.h"
33#include "RenderObject.h"
34#include <wtf/Forward.h>
35#include <wtf/WeakPtr.h>
36
37namespace WebCore {
38
39class AccessibilitySVGRoot;
40class AXObjectCache;
41class Element;
42class FrameView;
43class HTMLAreaElement;
44class HTMLElement;
45class HTMLLabelElement;
46class HTMLMapElement;
47class IntPoint;
48class IntSize;
49class Node;
50class RenderTextControl;
51class RenderView;
52class VisibleSelection;
53class Widget;
54
55class AccessibilityRenderObject : public AccessibilityNodeObject, public CanMakeWeakPtr<AccessibilityRenderObject> {
56public:
57 static Ref<AccessibilityRenderObject> create(RenderObject*);
58 virtual ~AccessibilityRenderObject();
59
60 void init() override;
61
62 bool isAttachment() const override;
63 bool isFileUploadButton() const override;
64
65 bool isSelected() const override;
66 bool isFocused() const override;
67 bool isLoaded() const override;
68 bool isOffScreen() const override;
69 bool isUnvisited() const override;
70 bool isVisited() const override;
71 bool isLinked() const override;
72 bool hasBoldFont() const override;
73 bool hasItalicFont() const override;
74 bool hasPlainText() const override;
75 bool hasSameFont(RenderObject*) const override;
76 bool hasSameFontColor(RenderObject*) const override;
77 bool hasSameStyle(RenderObject*) const override;
78 bool hasUnderline() const override;
79
80 bool canSetTextRangeAttributes() const override;
81 bool canSetExpandedAttribute() const override;
82
83 void setAccessibleName(const AtomicString&) override;
84
85 // Provides common logic used by all elements when determining isIgnored.
86 AccessibilityObjectInclusion defaultObjectInclusion() const override;
87
88 int layoutCount() const override;
89 double estimatedLoadingProgress() const override;
90
91 AccessibilityObject* firstChild() const override;
92 AccessibilityObject* lastChild() const override;
93 AccessibilityObject* previousSibling() const override;
94 AccessibilityObject* nextSibling() const override;
95 AccessibilityObject* parentObject() const override;
96 AccessibilityObject* parentObjectIfExists() const override;
97 AccessibilityObject* observableObject() const override;
98 void linkedUIElements(AccessibilityChildrenVector&) const override;
99 bool exposesTitleUIElement() const override;
100 AccessibilityObject* titleUIElement() const override;
101 AccessibilityObject* correspondingControlForLabelElement() const override;
102 AccessibilityObject* correspondingLabelForControlElement() const override;
103
104 bool supportsARIAOwns() const override;
105 bool isPresentationalChildOfAriaRole() const override;
106 bool ariaRoleHasPresentationalChildren() const override;
107
108 // Should be called on the root accessibility object to kick off a hit test.
109 AccessibilityObjectInterface* accessibilityHitTest(const IntPoint&) const override;
110
111 Element* anchorElement() const override;
112
113 LayoutRect boundingBoxRect() const override;
114 LayoutRect elementRect() const override;
115 IntPoint clickPoint() override;
116
117 void setRenderer(RenderObject*);
118 RenderObject* renderer() const override { return m_renderer.get(); }
119 RenderBoxModelObject* renderBoxModelObject() const;
120 Node* node() const override;
121
122 Document* document() const override;
123
124 RenderView* topRenderer() const;
125 RenderTextControl* textControl() const;
126 HTMLLabelElement* labelElementContainer() const;
127
128 URL url() const override;
129 PlainTextRange selectedTextRange() const override;
130 VisibleSelection selection() const override;
131 String stringValue() const override;
132 String helpText() const override;
133 String textUnderElement(AccessibilityTextUnderElementMode = AccessibilityTextUnderElementMode()) const override;
134 String text() const override;
135 int textLength() const override;
136 String selectedText() const override;
137 const AtomicString& accessKey() const override;
138 virtual const String& actionVerb() const;
139 Widget* widget() const override;
140 Widget* widgetForAttachmentView() const override;
141 virtual void getDocumentLinks(AccessibilityChildrenVector&);
142 FrameView* documentFrameView() const override;
143
144 void clearChildren() override;
145 void updateChildrenIfNecessary() override;
146
147 void setFocused(bool) override;
148 void setSelectedTextRange(const PlainTextRange&) override;
149 void setValue(const String&) override;
150 void setSelectedRows(AccessibilityChildrenVector&) override;
151 AccessibilityOrientation orientation() const override;
152
153 void detach(AccessibilityDetachmentType, AXObjectCache*) override;
154 void textChanged() override;
155 void addChildren() override;
156 bool canHaveChildren() const override;
157 bool canHaveSelectedChildren() const override;
158 void selectedChildren(AccessibilityChildrenVector&) override;
159 void visibleChildren(AccessibilityChildrenVector&) override;
160 void tabChildren(AccessibilityChildrenVector&) override;
161 bool shouldFocusActiveDescendant() const override;
162 bool shouldNotifyActiveDescendant() const;
163 AccessibilityObject* activeDescendant() const override;
164 void handleActiveDescendantChanged() override;
165 void handleAriaExpandedChanged() override;
166
167 VisiblePositionRange visiblePositionRange() const override;
168 VisiblePositionRange visiblePositionRangeForLine(unsigned) const override;
169 IntRect boundsForVisiblePositionRange(const VisiblePositionRange&) const override;
170 IntRect boundsForRange(const RefPtr<Range>) const override;
171 void setSelectedVisiblePositionRange(const VisiblePositionRange&) const override;
172 bool isVisiblePositionRangeInDifferentDocument(const VisiblePositionRange&) const;
173 bool hasPopup() const override;
174
175 bool supportsARIADropping() const override;
176 bool supportsARIADragging() const override;
177 bool isARIAGrabbed() override;
178 Vector<String> determineARIADropEffects() override;
179
180 VisiblePosition visiblePositionForPoint(const IntPoint&) const override;
181 VisiblePosition visiblePositionForIndex(unsigned indexValue, bool lastIndexOK) const override;
182 int index(const VisiblePosition&) const override;
183
184 VisiblePosition visiblePositionForIndex(int) const override;
185 int indexForVisiblePosition(const VisiblePosition&) const override;
186
187 void lineBreaks(Vector<int>&) const override;
188 PlainTextRange doAXRangeForLine(unsigned) const override;
189 PlainTextRange doAXRangeForIndex(unsigned) const override;
190
191 String doAXStringForRange(const PlainTextRange&) const override;
192 IntRect doAXBoundsForRange(const PlainTextRange&) const override;
193 IntRect doAXBoundsForRangeUsingCharacterOffset(const PlainTextRange&) const override;
194
195 String stringValueForMSAA() const override;
196 String stringRoleForMSAA() const override;
197 String nameForMSAA() const override;
198 String descriptionForMSAA() const override;
199 AccessibilityRole roleValueForMSAA() const override;
200
201 String passwordFieldValue() const override;
202 void titleElementText(Vector<AccessibilityText>&) const override;
203
204protected:
205 explicit AccessibilityRenderObject(RenderObject*);
206 ScrollableArea* getScrollableAreaIfScrollable() const override;
207 void scrollTo(const IntPoint&) const override;
208
209 bool isDetached() const override { return !m_renderer; }
210
211 AccessibilityRole determineAccessibilityRole() override;
212 bool computeAccessibilityIsIgnored() const override;
213
214#if ENABLE(MATHML)
215 virtual bool isIgnoredElementWithinMathTree() const;
216#endif
217
218 WeakPtr<RenderObject> m_renderer;
219
220private:
221 bool isAccessibilityRenderObject() const final { return true; }
222 void ariaListboxSelectedChildren(AccessibilityChildrenVector&);
223 void ariaListboxVisibleChildren(AccessibilityChildrenVector&);
224 bool isAllowedChildOfTree() const;
225 bool hasTextAlternative() const;
226 String positionalDescriptionForMSAA() const;
227 PlainTextRange documentBasedSelectedTextRange() const;
228 Element* rootEditableElementForPosition(const Position&) const;
229 bool nodeIsTextControl(const Node*) const;
230 void setNeedsToUpdateChildren() override { m_childrenDirty = true; }
231 bool needsToUpdateChildren() const override { return m_childrenDirty; }
232 void setNeedsToUpdateSubtree() override { m_subtreeDirty = true; }
233 Path elementPath() const override;
234
235 bool isTabItemSelected() const;
236 LayoutRect checkboxOrRadioRect() const;
237 void addRadioButtonGroupMembers(AccessibilityChildrenVector& linkedUIElements) const;
238 void addRadioButtonGroupChildren(AccessibilityObject*, AccessibilityChildrenVector&) const;
239 AccessibilityObject* internalLinkElement() const;
240 AccessibilityObject* accessibilityImageMapHitTest(HTMLAreaElement*, const IntPoint&) const;
241 AccessibilityObject* accessibilityParentForImageMap(HTMLMapElement*) const;
242 AccessibilityObjectInterface* elementAccessibilityHitTest(const IntPoint&) const override;
243
244 bool renderObjectIsObservable(RenderObject&) const;
245 RenderObject* renderParentObject() const;
246 bool isDescendantOfElementType(const QualifiedName& tagName) const;
247 bool isDescendantOfElementType(const HashSet<QualifiedName>&) const;
248
249 bool isSVGImage() const;
250 void detachRemoteSVGRoot();
251 enum CreationChoice { Create, Retrieve };
252 AccessibilitySVGRoot* remoteSVGRootElement(CreationChoice createIfNecessary) const;
253 AccessibilityObjectInterface* remoteSVGElementHitTest(const IntPoint&) const;
254 void offsetBoundingBoxForRemoteSVGElement(LayoutRect&) const;
255 bool supportsPath() const override;
256
257 void addHiddenChildren();
258 void addTextFieldChildren();
259 void addImageMapChildren();
260 void addCanvasChildren();
261 void addAttachmentChildren();
262 void addRemoteSVGChildren();
263#if PLATFORM(COCOA)
264 void updateAttachmentViewParents();
265#endif
266 String expandedTextValue() const override;
267 bool supportsExpandedTextValue() const override;
268 void updateRoleAfterChildrenCreation();
269
270 void ariaSelectedRows(AccessibilityChildrenVector&);
271
272 bool elementAttributeValue(const QualifiedName&) const;
273 void setElementAttributeValue(const QualifiedName&, bool);
274
275 OptionSet<SpeakAs> speakAsProperty() const override;
276
277 const String liveRegionStatus() const override;
278 const String liveRegionRelevant() const override;
279 bool liveRegionAtomic() const override;
280 bool isBusy() const override;
281
282 bool inheritsPresentationalRole() const override;
283
284 bool shouldGetTextFromNode(AccessibilityTextUnderElementMode) const;
285
286#if ENABLE(APPLE_PAY)
287 bool isApplePayButton() const;
288 ApplePayButtonType applePayButtonType() const;
289 String applePayButtonDescription() const;
290#endif
291
292 RenderObject* targetElementForActiveDescendant(const QualifiedName&, AccessibilityObject*) const;
293 bool canHavePlainText() const;
294 // Special handling of click point for links.
295 IntPoint linkClickPoint();
296 // Rects utilities.
297 static IntRect boundsForRects(LayoutRect const&, LayoutRect const&, RefPtr<Range> const&);
298};
299
300} // namespace WebCore
301
302SPECIALIZE_TYPE_TRAITS_ACCESSIBILITY(AccessibilityRenderObject, isAccessibilityRenderObject())
303