2 * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nuanti Ltd.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "AccessibilityObjectInterface.h"
33 #include "FloatQuad.h"
34 #include "LayoutRect.h"
36 #include <wtf/Forward.h>
37 #include <wtf/Function.h>
38 #include <wtf/RefPtr.h>
39 #include <wtf/Vector.h>
42 #include <wtf/RetainPtr.h>
46 #include <wtf/glib/GRefPtr.h>
52 OBJC_CLASS NSAttributedString
;
54 OBJC_CLASS NSMutableAttributedString
;
63 class AccessibilityObject
;
68 struct AccessibilityText
{
70 AccessibilityTextSource textSource
;
72 AccessibilityText(const String
& t
, const AccessibilityTextSource
& s
)
78 bool nodeHasPresentationRole(Node
*);
80 class AccessibilityObject
: public AXCoreObject
{
82 virtual ~AccessibilityObject();
84 // After constructing an AccessibilityObject, it must be given a
85 // unique ID, then added to AXObjectCache, and finally init() must
87 void setObjectID(AXID id
) override
{ m_id
= id
; }
88 void init() override
{ }
90 // Prefer using the dedicated functions over consuming these flag values directly, as the flags can sometimes be uninitialized.
91 // Also, the dedicated functions traverse for you if the flags aren't yet initialized.
92 // For example, use `hasDocumentRoleAncestor()` instead of `ancestorFlags().contains(AXAncestorFlag::HasDocumentRoleAncestor)`.
93 OptionSet
<AXAncestorFlag
> ancestorFlags() const { return m_ancestorFlags
; }
95 void addAncestorFlags(const OptionSet
<AXAncestorFlag
>& flags
) { m_ancestorFlags
.add(flags
); }
96 bool ancestorFlagsAreInitialized() const { return m_ancestorFlags
.contains(AXAncestorFlag::FlagsInitialized
); }
97 // Computes the flags that this object matches (no traversal is done).
98 OptionSet
<AXAncestorFlag
> computeAncestorFlags() const;
99 // Computes the flags that this object and all ancestors match, traversing all the way to the root.
100 OptionSet
<AXAncestorFlag
> computeAncestorFlagsWithTraversal() const;
101 void initializeAncestorFlags(const OptionSet
<AXAncestorFlag
>&);
102 bool hasAncestorMatchingFlag(AXAncestorFlag
) const;
103 bool matchesAncestorFlag(AXAncestorFlag
) const;
105 bool hasDocumentRoleAncestor() const override
;
106 bool hasWebApplicationAncestor() const override
;
107 bool isInDescriptionListDetail() const override
;
108 bool isInDescriptionListTerm() const override
;
109 bool isInCell() const override
;
111 bool isDetached() const override
;
113 bool isAccessibilityNodeObject() const override
{ return false; }
114 bool isAccessibilityRenderObject() const override
{ return false; }
115 bool isAccessibilityScrollbar() const override
{ return false; }
116 bool isAccessibilityScrollViewInstance() const override
{ return false; }
117 bool isAXImageInstance() const override
{ return false; }
118 bool isAccessibilitySVGRoot() const override
{ return false; }
119 bool isAccessibilitySVGElement() const override
{ return false; }
120 bool isAccessibilityTableInstance() const override
{ return false; }
121 bool isAccessibilityTableColumnInstance() const override
{ return false; }
122 bool isAccessibilityProgressIndicatorInstance() const override
{ return false; }
123 bool isAccessibilityListBoxInstance() const override
{ return false; }
124 bool isAXIsolatedObjectInstance() const override
{ return false; }
126 bool isAttachmentElement() const override
{ return false; }
127 bool isHeading() const override
{ return false; }
128 bool isLink() const override
{ return false; }
129 bool isNativeImage() const override
{ return false; }
130 bool isImageButton() const override
{ return false; }
131 bool isPasswordField() const override
{ return false; }
132 bool isContainedByPasswordField() const override
;
133 AccessibilityObject
* passwordFieldOrContainingPasswordField() override
{ return nullptr; }
134 bool isNativeTextControl() const override
{ return false; }
135 bool isSearchField() const override
{ return false; }
136 bool isListBoxOption() const override
{ return false; }
137 bool isAttachment() const override
{ return false; }
138 bool isMediaTimeline() const override
{ return false; }
139 bool isMenuRelated() const override
{ return false; }
140 bool isMenu() const override
{ return false; }
141 bool isMenuBar() const override
{ return false; }
142 bool isMenuButton() const override
{ return false; }
143 bool isMenuItem() const override
{ return false; }
144 bool isFileUploadButton() const override
;
145 bool isInputImage() const override
{ return false; }
146 bool isProgressIndicator() const override
{ return false; }
147 bool isSlider() const override
{ return false; }
148 bool isSliderThumb() const override
{ return false; }
149 bool isInputSlider() const override
{ return false; }
150 bool isControl() const override
{ return false; }
151 bool isLabel() const override
{ return false; }
153 bool isList() const override
{ return false; }
154 bool isUnorderedList() const override
{ return false; }
155 bool isOrderedList() const override
{ return false; }
156 bool isDescriptionList() const override
{ return false; }
159 bool isTable() const override
{ return false; }
160 bool isExposable() const override
{ return true; }
161 bool isDataTable() const override
{ return false; }
162 int tableLevel() const override
{ return 0; }
163 bool supportsSelectedRows() const override
{ return false; }
164 AccessibilityChildrenVector
columns() override
{ return AccessibilityChildrenVector(); }
165 AccessibilityChildrenVector
rows() override
{ return AccessibilityChildrenVector(); }
166 unsigned columnCount() override
{ return 0; }
167 unsigned rowCount() override
{ return 0; }
168 AccessibilityChildrenVector
cells() override
{ return AccessibilityChildrenVector(); }
169 AXCoreObject
* cellForColumnAndRow(unsigned, unsigned) override
{ return nullptr; }
170 AccessibilityChildrenVector
columnHeaders() override
{ return AccessibilityChildrenVector(); }
171 AccessibilityChildrenVector
rowHeaders() override
{ return AccessibilityChildrenVector(); }
172 AccessibilityChildrenVector
visibleRows() override
{ return AccessibilityChildrenVector(); }
173 AXCoreObject
* headerContainer() override
{ return nullptr; }
174 int axColumnCount() const override
{ return 0; }
175 int axRowCount() const override
{ return 0; }
177 // Table cell support.
178 bool isTableCell() const override
{ return false; }
179 // Returns the start location and row span of the cell.
180 std::pair
<unsigned, unsigned> rowIndexRange() const override
{ return { 0, 1 }; }
181 // Returns the start location and column span of the cell.
182 std::pair
<unsigned, unsigned> columnIndexRange() const override
{ return { 0, 1 }; }
183 bool isColumnHeaderCell() const override
{ return false; }
184 bool isRowHeaderCell() const override
{ return false; }
185 int axColumnIndex() const override
{ return -1; }
186 int axRowIndex() const override
{ return -1; }
188 // Table column support.
189 bool isTableColumn() const override
{ return false; }
190 unsigned columnIndex() const override
{ return 0; }
191 AXCoreObject
* columnHeader() override
{ return nullptr; }
193 // Table row support.
194 bool isTableRow() const override
{ return false; }
195 unsigned rowIndex() const override
{ return 0; }
197 // ARIA tree/grid row support.
198 bool isARIATreeGridRow() const override
{ return false; }
199 AccessibilityChildrenVector
disclosedRows() override
; // ARIATreeItem implementation. AccessibilityARIAGridRow overrides this method.
200 AXCoreObject
* disclosedByRow() const override
{ return nullptr; }
202 bool isFieldset() const override
{ return false; }
203 bool isGroup() const override
{ return false; }
204 bool isImageMapLink() const override
{ return false; }
205 bool isMenuList() const override
{ return false; }
206 bool isMenuListPopup() const override
{ return false; }
207 bool isMenuListOption() const override
{ return false; }
208 bool isNativeSpinButton() const override
{ return false; }
209 AXCoreObject
* incrementButton() override
{ return nullptr; }
210 AXCoreObject
* decrementButton() override
{ return nullptr; }
211 bool isSpinButtonPart() const override
{ return false; }
212 bool isIncrementor() const override
{ return false; }
213 bool isMockObject() const override
{ return false; }
214 virtual bool isMediaControlLabel() const { return false; }
215 bool isMediaObject() const override
{ return false; }
216 bool isTextControl() const override
;
217 bool isARIATextControl() const override
;
218 bool isNonNativeTextControl() const override
;
219 bool isButton() const override
;
220 bool isLandmark() const override
;
221 bool isRangeControl() const override
;
222 bool isMeter() const override
;
223 bool isStyleFormatGroup() const override
;
224 bool isFigureElement() const override
;
225 bool isKeyboardFocusable() const override
;
226 bool isOutput() const override
;
228 bool isChecked() const override
{ return false; }
229 bool isEnabled() const override
{ return false; }
230 bool isSelected() const override
{ return false; }
231 bool isFocused() const override
{ return false; }
232 bool isHovered() const override
{ return false; }
233 bool isIndeterminate() const override
{ return false; }
234 bool isLoaded() const override
{ return false; }
235 bool isMultiSelectable() const override
{ return false; }
236 bool isOffScreen() const override
{ return false; }
237 bool isPressed() const override
{ return false; }
238 bool isUnvisited() const override
{ return false; }
239 bool isVisited() const override
{ return false; }
240 bool isRequired() const override
{ return false; }
241 bool supportsRequiredAttribute() const override
{ return false; }
242 bool isLinked() const override
{ return false; }
243 bool isExpanded() const override
;
244 bool isVisible() const override
{ return true; }
245 bool isCollapsed() const override
{ return false; }
246 void setIsExpanded(bool) override
{ }
247 FloatRect
relativeFrame() const override
;
248 FloatRect
convertFrameToSpace(const FloatRect
&, AccessibilityConversionSpace
) const override
;
249 HashMap
<String
, AXEditingStyleValueVariant
> resolvedEditingStyles() const override
;
251 // In a multi-select list, many items can be selected but only one is active at a time.
252 bool isSelectedOptionActive() const override
{ return false; }
254 bool hasBoldFont() const override
{ return false; }
255 bool hasItalicFont() const override
{ return false; }
256 bool hasMisspelling() const override
;
257 std::optional
<SimpleRange
> misspellingRange(const SimpleRange
& start
, AccessibilitySearchDirection
) const override
;
258 bool hasPlainText() const override
{ return false; }
259 bool hasSameFont(const AXCoreObject
&) const override
{ return false; }
260 bool hasSameFontColor(const AXCoreObject
&) const override
{ return false; }
261 bool hasSameStyle(const AXCoreObject
&) const override
{ return false; }
262 bool hasUnderline() const override
{ return false; }
263 bool hasHighlighting() const override
;
265 bool supportsDatetimeAttribute() const override
;
266 String
datetimeAttributeValue() const override
;
268 bool canSetFocusAttribute() const override
{ return false; }
269 bool canSetTextRangeAttributes() const override
{ return false; }
270 bool canSetValueAttribute() const override
{ return false; }
271 bool canSetNumericValue() const override
{ return false; }
272 bool canSetSelectedAttribute() const override
{ return false; }
273 bool canSetSelectedChildren() const override
{ return false; }
274 bool canSetExpandedAttribute() const override
{ return false; }
276 Element
* element() const override
;
277 Node
* node() const override
{ return nullptr; }
278 RenderObject
* renderer() const override
{ return nullptr; }
279 // Note: computeAccessibilityIsIgnored does not consider whether an object is ignored due to presence of modals.
280 // Use accessibilityIsIgnored as the word of law when determining if an object is ignored.
281 virtual bool computeAccessibilityIsIgnored() const { return true; }
282 bool accessibilityIsIgnored() const override
;
283 AccessibilityObjectInclusion
defaultObjectInclusion() const override
;
284 bool accessibilityIsIgnoredByDefault() const override
;
286 bool isShowingValidationMessage() const override
;
287 String
validationMessage() const override
;
289 unsigned blockquoteLevel() const override
;
290 unsigned headingLevel() const override
{ return 0; }
291 AccessibilityButtonState
checkboxOrRadioValue() const override
;
292 String
valueDescription() const override
{ return String(); }
293 float valueForRange() const override
{ return 0.0f
; }
294 float maxValueForRange() const override
{ return 0.0f
; }
295 float minValueForRange() const override
{ return 0.0f
; }
296 float stepValueForRange() const override
{ return 0.0f
; }
297 AXCoreObject
* selectedRadioButton() override
{ return nullptr; }
298 AXCoreObject
* selectedTabItem() override
{ return nullptr; }
299 AXCoreObject
* selectedListItem() override
;
300 int layoutCount() const override
{ return 0; }
301 double loadingProgress() const override
{ return 0; }
302 WEBCORE_EXPORT
static bool isARIAControl(AccessibilityRole
);
303 bool supportsCheckedState() const override
;
305 bool supportsARIAOwns() const override
{ return false; }
306 bool isActiveDescendantOfFocusedContainer() const override
;
307 void ariaActiveDescendantReferencingElements(AccessibilityChildrenVector
&) const override
;
308 void ariaControlsElements(AccessibilityChildrenVector
&) const override
;
309 void ariaControlsReferencingElements(AccessibilityChildrenVector
&) const override
;
310 void ariaDescribedByElements(AccessibilityChildrenVector
&) const override
;
311 void ariaDescribedByReferencingElements(AccessibilityChildrenVector
&) const override
;
312 void ariaDetailsElements(AccessibilityChildrenVector
&) const override
;
313 void ariaDetailsReferencingElements(AccessibilityChildrenVector
&) const override
;
314 void ariaErrorMessageElements(AccessibilityChildrenVector
&) const override
;
315 void ariaErrorMessageReferencingElements(AccessibilityChildrenVector
&) const override
;
316 void ariaFlowToElements(AccessibilityChildrenVector
&) const override
;
317 void ariaFlowToReferencingElements(AccessibilityChildrenVector
&) const override
;
318 void ariaLabelledByElements(AccessibilityChildrenVector
&) const override
;
319 void ariaLabelledByReferencingElements(AccessibilityChildrenVector
&) const override
;
320 void ariaOwnsElements(AccessibilityChildrenVector
&) const override
;
321 void ariaOwnsReferencingElements(AccessibilityChildrenVector
&) const override
;
323 bool hasPopup() const override
{ return false; }
324 String
popupValue() const override
;
325 bool hasDatalist() const override
;
326 bool supportsHasPopup() const override
;
327 bool pressedIsPresent() const override
;
328 bool ariaIsMultiline() const override
;
329 String
invalidStatus() const override
;
330 bool supportsPressed() const override
;
331 bool supportsExpanded() const override
;
332 bool supportsChecked() const override
;
333 bool supportsRowCountChange() const override
;
334 AccessibilitySortDirection
sortDirection() const override
;
335 bool canvasHasFallbackContent() const override
{ return false; }
336 bool supportsRangeValue() const override
;
337 String
identifierAttribute() const override
;
338 String
linkRelValue() const override
;
339 void classList(Vector
<String
>&) const override
;
340 AccessibilityCurrentState
currentState() const override
;
341 String
currentValue() const override
;
342 bool supportsCurrent() const override
;
343 const String
keyShortcutsValue() const override
;
345 // This function checks if the object should be ignored when there's a modal dialog displayed.
346 virtual bool ignoredFromModalPresence() const;
347 bool isModalDescendant(Node
*) const override
;
348 bool isModalNode() const override
;
350 bool supportsSetSize() const override
;
351 bool supportsPosInSet() const override
;
352 int setSize() const override
;
353 int posInSet() const override
;
355 // ARIA drag and drop
356 bool supportsDropping() const override
{ return false; }
357 bool supportsDragging() const override
{ return false; }
358 bool isGrabbed() override
{ return false; }
359 void setARIAGrabbed(bool) override
{ }
360 Vector
<String
> determineDropEffects() const override
{ return { }; }
362 // Called on the root AX object to return the deepest available element.
363 AXCoreObject
* accessibilityHitTest(const IntPoint
&) const override
{ return nullptr; }
364 // Called on the AX object after the render tree determines which is the right AccessibilityRenderObject.
365 AXCoreObject
* elementAccessibilityHitTest(const IntPoint
&) const override
;
367 AXCoreObject
* focusedUIElement() const override
;
369 AccessibilityObject
* firstChild() const override
{ return nullptr; }
370 AccessibilityObject
* lastChild() const override
{ return nullptr; }
371 AccessibilityObject
* previousSibling() const override
{ return nullptr; }
372 AccessibilityObject
* nextSibling() const override
{ return nullptr; }
373 AccessibilityObject
* nextSiblingUnignored(int limit
) const override
;
374 AccessibilityObject
* previousSiblingUnignored(int limit
) const override
;
375 AccessibilityObject
* parentObject() const override
{ return nullptr; }
376 AXCoreObject
* parentObjectUnignored() const override
;
377 AccessibilityObject
* parentObjectIfExists() const override
{ return nullptr; }
378 static AccessibilityObject
* firstAccessibleObjectFromNode(const Node
*);
379 void findMatchingObjects(AccessibilitySearchCriteria
*, AccessibilityChildrenVector
&) override
;
380 bool isDescendantOfBarrenParent() const override
{ return false; }
382 bool isDescendantOfRole(AccessibilityRole
) const override
;
385 Vector
<SimpleRange
> findTextRanges(const AccessibilitySearchTextCriteria
&) const override
;
386 Vector
<String
> performTextOperation(AccessibilityTextOperation
const&) override
;
388 AccessibilityObject
* observableObject() const override
{ return nullptr; }
389 void linkedUIElements(AccessibilityChildrenVector
&) const override
{ }
390 AccessibilityObject
* titleUIElement() const override
{ return nullptr; }
391 AccessibilityObject
* correspondingLabelForControlElement() const override
{ return nullptr; }
392 AccessibilityObject
* correspondingControlForLabelElement() const override
{ return nullptr; }
393 AccessibilityObject
* scrollBar(AccessibilityOrientation
) override
{ return nullptr; }
395 AccessibilityRole
ariaRoleAttribute() const override
{ return AccessibilityRole::Unknown
; }
396 bool isPresentationalChildOfAriaRole() const override
{ return false; }
397 bool ariaRoleHasPresentationalChildren() const override
{ return false; }
398 bool inheritsPresentationalRole() const override
{ return false; }
400 // Accessibility Text
401 void accessibilityText(Vector
<AccessibilityText
>&) const override
{ };
402 // A single method for getting a computed label for an AXObject. It condenses the nuances of accessibilityText. Used by Inspector.
403 String
computedLabel() override
;
405 // A programmatic way to set a name on an AccessibleObject.
406 void setAccessibleName(const AtomString
&) override
{ }
407 bool hasAttributesRequiredForInclusion() const override
;
409 // Accessibility Text - (To be deprecated).
410 String
accessibilityDescription() const override
{ return String(); }
411 String
title() const override
{ return String(); }
412 String
helpText() const override
{ return String(); }
414 // Methods for determining accessibility text.
415 bool isARIAStaticText() const override
{ return ariaRoleAttribute() == AccessibilityRole::StaticText
; }
416 String
stringValue() const override
{ return String(); }
417 String
textUnderElement(AccessibilityTextUnderElementMode
= AccessibilityTextUnderElementMode()) const override
{ return String(); }
418 String
text() const override
{ return String(); }
419 int textLength() const override
{ return 0; }
420 String
ariaLabeledByAttribute() const override
{ return String(); }
421 String
ariaDescribedByAttribute() const override
{ return String(); }
422 const String
placeholderValue() const override
;
423 bool accessibleNameDerivesFromContent() const override
;
424 String
brailleLabel() const override
{ return getAttribute(HTMLNames::aria_braillelabelAttr
); }
425 String
brailleRoleDescription() const override
{ return getAttribute(HTMLNames::aria_brailleroledescriptionAttr
); }
426 String
embeddedImageDescription() const override
;
427 std::optional
<AccessibilityChildrenVector
> imageOverlayElements() override
{ return std::nullopt
; }
430 String
expandedTextValue() const override
{ return String(); }
431 bool supportsExpandedTextValue() const override
{ return false; }
433 void elementsFromAttribute(Vector
<Element
*>&, const QualifiedName
&) const override
;
435 // Only if isColorWell()
436 SRGBA
<uint8_t> colorValue() const override
{ return Color::transparentBlack
; }
438 AccessibilityRole
roleValue() const override
{ return m_role
; }
439 String
rolePlatformString() const override
;
440 String
roleDescription() const override
;
441 String
subrolePlatformString() const override
;
442 String
ariaLandmarkRoleDescription() const override
;
444 AXObjectCache
* axObjectCache() const override
;
445 AXID
objectID() const override
{ return m_id
; }
447 static AccessibilityObject
* anchorElementForNode(Node
*);
448 static AccessibilityObject
* headingElementForNode(Node
*);
449 Element
* anchorElement() const override
{ return nullptr; }
450 bool supportsPressAction() const override
;
451 Element
* actionElement() const override
{ return nullptr; }
452 LayoutRect
boundingBoxRect() const override
{ return LayoutRect(); }
453 LayoutRect
elementRect() const override
= 0;
454 IntPoint
clickPoint() override
;
455 static IntRect
boundingBoxForQuads(RenderObject
*, const Vector
<FloatQuad
>&);
456 Path
elementPath() const override
{ return Path(); }
457 bool supportsPath() const override
{ return false; }
459 TextIteratorBehaviors
textIteratorBehaviorForTextRange() const override
;
460 PlainTextRange
selectedTextRange() const override
{ return { }; }
461 int insertionPointLineNumber() const override
{ return -1; }
463 URL
url() const override
{ return URL(); }
464 VisibleSelection
selection() const override
{ return VisibleSelection(); }
465 String
selectedText() const override
{ return String(); }
466 String
accessKey() const override
{ return nullAtom(); }
467 String
localizedActionVerb() const override
;
468 String
actionVerb() const override
;
470 bool isWidget() const override
{ return false; }
471 Widget
* widget() const override
{ return nullptr; }
472 PlatformWidget
platformWidget() const override
{ return nullptr; }
473 Widget
* widgetForAttachmentView() const override
{ return nullptr; }
476 RemoteAXObjectRef
remoteParentObject() const override
;
477 FloatRect
convertRectToPlatformSpace(const FloatRect
&, AccessibilityConversionSpace
) const override
;
479 Page
* page() const override
;
480 Document
* document() const override
;
481 FrameView
* documentFrameView() const override
;
482 Frame
* frame() const override
;
483 Frame
* mainFrame() const override
;
484 Document
* topDocument() const override
;
485 ScrollView
* scrollView() const override
{ return nullptr; }
486 ScrollView
* scrollViewAncestor() const override
;
487 String
language() const override
;
488 // 1-based, to match the aria-level spec.
489 unsigned hierarchicalLevel() const override
{ return 0; }
490 bool isInlineText() const override
;
492 // Ensures that the view is focused and active before attempting to set focus to an AccessibilityObject.
493 // Subclasses that override setFocused should call this base implementation first.
494 void setFocused(bool) override
;
496 void setSelectedText(const String
&) override
{ }
497 void setSelectedTextRange(const PlainTextRange
&) override
{ }
498 bool setValue(const String
&) override
{ return false; }
499 bool replaceTextInRange(const String
&, const PlainTextRange
&) override
;
500 bool insertText(const String
&) override
;
502 bool setValue(float) override
{ return false; }
503 void setSelected(bool) override
{ }
504 void setSelectedRows(AccessibilityChildrenVector
&) override
{ }
506 void makeRangeVisible(const PlainTextRange
&) override
{ }
507 bool press() override
;
508 bool performDefaultAction() override
{ return press(); }
510 AccessibilityOrientation
orientation() const override
;
511 void increment() override
{ }
512 void decrement() override
{ }
514 virtual void updateAccessibilityRole() { }
515 const AccessibilityChildrenVector
& children(bool updateChildrenIfNeeded
= true) override
;
516 virtual void addChildren() { }
517 enum class DescendIfIgnored
: uint8_t { No
, Yes
};
518 virtual void addChild(AXCoreObject
*, DescendIfIgnored
= DescendIfIgnored::Yes
);
519 virtual void insertChild(AXCoreObject
*, unsigned, DescendIfIgnored
= DescendIfIgnored::Yes
);
520 virtual bool canHaveChildren() const { return true; }
521 void updateChildrenIfNecessary() override
;
522 virtual void setNeedsToUpdateChildren() { }
523 virtual void setNeedsToUpdateSubtree() { }
524 virtual void clearChildren();
525 virtual bool needsToUpdateChildren() const { return false; }
527 void detachFromParent() override
;
529 void detachFromParent() override
{ }
531 bool isDetachedFromParent() override
{ return false; }
533 bool canHaveSelectedChildren() const override
{ return false; }
534 void selectedChildren(AccessibilityChildrenVector
&) override
{ }
535 void setSelectedChildren(const AccessibilityChildrenVector
&) override
{ }
536 void visibleChildren(AccessibilityChildrenVector
&) override
{ }
537 void tabChildren(AccessibilityChildrenVector
&) override
{ }
538 bool shouldFocusActiveDescendant() const override
{ return false; }
539 AccessibilityObject
* activeDescendant() const override
{ return nullptr; }
540 void handleActiveDescendantChanged() override
{ }
541 AccessibilityObject
* firstAnonymousBlockChild() const override
;
543 WEBCORE_EXPORT
static AccessibilityRole
ariaRoleToWebCoreRole(const String
&);
544 virtual bool hasAttribute(const QualifiedName
&) const;
545 virtual const AtomString
& getAttribute(const QualifiedName
&) const;
546 std::optional
<String
> attributeValue(const String
&) const override
;
547 int getIntegralAttribute(const QualifiedName
&) const;
548 bool hasTagName(const QualifiedName
&) const override
;
549 String
tagName() const override
;
551 VisiblePositionRange
visiblePositionRange() const override
{ return VisiblePositionRange(); }
552 VisiblePositionRange
visiblePositionRangeForLine(unsigned) const override
{ return VisiblePositionRange(); }
554 std::optional
<SimpleRange
> elementRange() const override
;
555 static bool replacedNodeNeedsCharacter(Node
* replacedNode
);
557 VisiblePositionRange
visiblePositionRangeForUnorderedPositions(const VisiblePosition
&, const VisiblePosition
&) const override
;
558 VisiblePositionRange
positionOfLeftWord(const VisiblePosition
&) const override
;
559 VisiblePositionRange
positionOfRightWord(const VisiblePosition
&) const override
;
560 VisiblePositionRange
leftLineVisiblePositionRange(const VisiblePosition
&) const override
;
561 VisiblePositionRange
rightLineVisiblePositionRange(const VisiblePosition
&) const override
;
562 VisiblePositionRange
sentenceForPosition(const VisiblePosition
&) const override
;
563 VisiblePositionRange
paragraphForPosition(const VisiblePosition
&) const override
;
564 VisiblePositionRange
styleRangeForPosition(const VisiblePosition
&) const override
;
565 VisiblePositionRange
visiblePositionRangeForRange(const PlainTextRange
&) const override
;
566 VisiblePositionRange
lineRangeForPosition(const VisiblePosition
&) const override
;
567 VisiblePositionRange
selectedVisiblePositionRange() const override
{ return { }; }
569 std::optional
<SimpleRange
> rangeForPlainTextRange(const PlainTextRange
&) const override
;
571 AXTextMarkerRangeRef
textMarkerRangeForNSRange(const NSRange
&) const override
;
574 static String
stringForVisiblePositionRange(const VisiblePositionRange
&);
575 String
stringForRange(const SimpleRange
&) const override
;
576 IntRect
boundsForVisiblePositionRange(const VisiblePositionRange
&) const override
{ return IntRect(); }
577 IntRect
boundsForRange(const SimpleRange
&) const override
{ return IntRect(); }
578 int lengthForVisiblePositionRange(const VisiblePositionRange
&) const override
;
579 void setSelectedVisiblePositionRange(const VisiblePositionRange
&) const override
{ }
581 VisiblePosition
visiblePositionForBounds(const IntRect
&, AccessibilityVisiblePositionForBounds
) const override
;
582 VisiblePosition
visiblePositionForPoint(const IntPoint
&) const override
{ return VisiblePosition(); }
583 VisiblePosition
nextVisiblePosition(const VisiblePosition
& visiblePos
) const override
{ return visiblePos
.next(); }
584 VisiblePosition
previousVisiblePosition(const VisiblePosition
& visiblePos
) const override
{ return visiblePos
.previous(); }
585 VisiblePosition
nextWordEnd(const VisiblePosition
&) const override
;
586 VisiblePosition
previousWordStart(const VisiblePosition
&) const override
;
587 VisiblePosition
nextLineEndPosition(const VisiblePosition
&) const override
;
588 VisiblePosition
previousLineStartPosition(const VisiblePosition
&) const override
;
589 VisiblePosition
nextSentenceEndPosition(const VisiblePosition
&) const override
;
590 VisiblePosition
previousSentenceStartPosition(const VisiblePosition
&) const override
;
591 VisiblePosition
nextParagraphEndPosition(const VisiblePosition
&) const override
;
592 VisiblePosition
previousParagraphStartPosition(const VisiblePosition
&) const override
;
593 VisiblePosition
visiblePositionForIndex(unsigned, bool /*lastIndexOK */) const override
{ return VisiblePosition(); }
595 VisiblePosition
visiblePositionForIndex(int) const override
{ return VisiblePosition(); }
596 int indexForVisiblePosition(const VisiblePosition
&) const override
{ return 0; }
598 AccessibilityObject
* accessibilityObjectForPosition(const VisiblePosition
&) const override
;
599 int lineForPosition(const VisiblePosition
&) const override
;
600 PlainTextRange
plainTextRangeForVisiblePositionRange(const VisiblePositionRange
&) const override
;
601 int index(const VisiblePosition
&) const override
{ return -1; }
603 void lineBreaks(Vector
<int>&) const override
{ }
604 PlainTextRange
doAXRangeForLine(unsigned) const override
{ return PlainTextRange(); }
605 PlainTextRange
doAXRangeForPosition(const IntPoint
&) const override
;
606 PlainTextRange
doAXRangeForIndex(unsigned) const override
{ return PlainTextRange(); }
607 PlainTextRange
doAXStyleRangeForIndex(unsigned) const override
;
609 String
doAXStringForRange(const PlainTextRange
&) const override
{ return String(); }
610 IntRect
doAXBoundsForRange(const PlainTextRange
&) const override
{ return IntRect(); }
611 IntRect
doAXBoundsForRangeUsingCharacterOffset(const PlainTextRange
&) const override
{ return IntRect(); }
612 static String
listMarkerTextForNodeAndPosition(Node
*, const VisiblePosition
&);
614 unsigned doAXLineForIndex(unsigned) override
;
616 String
computedRoleString() const override
;
618 String
stringValueForMSAA() const override
{ return String(); }
619 String
stringRoleForMSAA() const override
{ return String(); }
620 String
nameForMSAA() const override
{ return String(); }
621 String
descriptionForMSAA() const override
{ return String(); }
622 AccessibilityRole
roleValueForMSAA() const override
{ return roleValue(); }
624 String
passwordFieldValue() const override
{ return String(); }
625 bool isValueAutofilled() const override
;
626 bool isValueAutofillAvailable() const override
;
627 AutoFillButtonType
valueAutofillButtonType() const override
;
629 // Used by an ARIA tree to get all its rows.
630 void ariaTreeRows(AccessibilityChildrenVector
&) override
;
631 // Used by an ARIA tree item to get only its content, and not its child tree items and groups.
632 void ariaTreeItemContent(AccessibilityChildrenVector
&) override
;
634 // ARIA live-region features.
635 bool supportsLiveRegion(bool excludeIfOff
= true) const override
;
636 bool isInsideLiveRegion(bool excludeIfOff
= true) const override
;
637 AccessibilityObject
* liveRegionAncestor(bool excludeIfOff
= true) const override
;
638 const String
liveRegionStatus() const override
{ return String(); }
639 const String
liveRegionRelevant() const override
{ return nullAtom(); }
640 bool liveRegionAtomic() const override
{ return false; }
641 bool isBusy() const override
{ return false; }
642 static const String
defaultLiveRegionStatusForRole(AccessibilityRole
);
643 static bool liveRegionStatusIsEnabled(const AtomString
&);
644 static bool contentEditableAttributeIsEnabled(Element
*);
645 bool hasContentEditableAttributeSet() const override
;
647 bool supportsReadOnly() const override
;
648 String
readOnlyValue() const override
;
650 bool supportsAutoComplete() const override
;
651 String
autoCompleteValue() const override
;
653 bool hasARIAValueNow() const override
{ return hasAttribute(HTMLNames::aria_valuenowAttr
); }
654 bool supportsARIAAttributes() const override
;
656 // CSS3 Speech properties.
657 OptionSet
<SpeakAs
> speakAsProperty() const override
{ return OptionSet
<SpeakAs
> { }; }
659 // Make this object visible by scrolling as many nested scrollable views as needed.
660 void scrollToMakeVisible() const override
;
661 // Same, but if the whole object can't be made visible, try for this subrect, in local coordinates.
662 void scrollToMakeVisibleWithSubFocus(const IntRect
&) const override
;
663 // Scroll this object to a given point in global coordinates of the top-level window.
664 void scrollToGlobalPoint(const IntPoint
&) const override
;
666 bool scrollByPage(ScrollByPageDirection
) const override
;
667 IntPoint
scrollPosition() const override
;
668 AccessibilityChildrenVector
contents() override
;
669 IntSize
scrollContentsSize() const override
;
670 IntRect
scrollVisibleContentRect() const override
;
671 void scrollToMakeVisible(const ScrollRectToVisibleOptions
&) const override
;
673 bool lastKnownIsIgnoredValue();
674 void setLastKnownIsIgnoredValue(bool);
675 bool hasIgnoredValueChanged();
677 // All math elements return true for isMathElement().
678 bool isMathElement() const override
{ return false; }
679 bool isMathFraction() const override
{ return false; }
680 bool isMathFenced() const override
{ return false; }
681 bool isMathSubscriptSuperscript() const override
{ return false; }
682 bool isMathRow() const override
{ return false; }
683 bool isMathUnderOver() const override
{ return false; }
684 bool isMathRoot() const override
{ return false; }
685 bool isMathSquareRoot() const override
{ return false; }
686 bool isMathText() const override
{ return false; }
687 bool isMathNumber() const override
{ return false; }
688 bool isMathOperator() const override
{ return false; }
689 bool isMathFenceOperator() const override
{ return false; }
690 bool isMathSeparatorOperator() const override
{ return false; }
691 bool isMathIdentifier() const override
{ return false; }
692 bool isMathTable() const override
{ return false; }
693 bool isMathTableRow() const override
{ return false; }
694 bool isMathTableCell() const override
{ return false; }
695 bool isMathMultiscript() const override
{ return false; }
696 bool isMathToken() const override
{ return false; }
697 bool isMathScriptObject(AccessibilityMathScriptObjectType
) const override
{ return false; }
698 bool isMathMultiscriptObject(AccessibilityMathMultiscriptObjectType
) const override
{ return false; }
701 std::optional
<AccessibilityChildrenVector
> mathRadicand() override
{ return std::nullopt
; }
702 AXCoreObject
* mathRootIndexObject() override
{ return nullptr; }
704 // Under over components.
705 AXCoreObject
* mathUnderObject() override
{ return nullptr; }
706 AXCoreObject
* mathOverObject() override
{ return nullptr; }
708 // Fraction components.
709 AXCoreObject
* mathNumeratorObject() override
{ return nullptr; }
710 AXCoreObject
* mathDenominatorObject() override
{ return nullptr; }
712 // Subscript/superscript components.
713 AXCoreObject
* mathBaseObject() override
{ return nullptr; }
714 AXCoreObject
* mathSubscriptObject() override
{ return nullptr; }
715 AXCoreObject
* mathSuperscriptObject() override
{ return nullptr; }
717 // Fenced components.
718 String
mathFencedOpenString() const override
{ return String(); }
719 String
mathFencedCloseString() const override
{ return String(); }
720 int mathLineThickness() const override
{ return 0; }
721 bool isAnonymousMathOperator() const override
{ return false; }
723 // Multiscripts components.
724 void mathPrescripts(AccessibilityMathMultiscriptPairs
&) override
{ }
725 void mathPostscripts(AccessibilityMathMultiscriptPairs
&) override
{ }
728 bool isAXHidden() const override
;
729 bool isDOMHidden() const override
;
730 bool isHidden() const override
{ return isAXHidden() || isDOMHidden(); }
733 void overrideAttachmentParent(AXCoreObject
* parent
) override
;
735 void overrideAttachmentParent(AXCoreObject
*) override
{ }
738 #if ENABLE(ACCESSIBILITY)
739 // a platform-specific method for determining if an attachment is ignored
740 bool accessibilityIgnoreAttachment() const override
;
741 // gives platforms the opportunity to indicate if and how an object should be included
742 AccessibilityObjectInclusion
accessibilityPlatformIncludesObject() const override
;
744 bool accessibilityIgnoreAttachment() const override
{ return true; }
745 AccessibilityObjectInclusion
accessibilityPlatformIncludesObject() const override
{ return AccessibilityObjectInclusion::DefaultBehavior
; }
748 #if PLATFORM(IOS_FAMILY)
749 int accessibilityPasswordFieldLength() override
;
750 bool hasTouchEventListener() const override
;
751 bool isInputTypePopupButton() const override
;
754 // allows for an AccessibilityObject to update its render tree or perform
755 // other operations update type operations
756 void updateBackingStore() override
;
759 bool preventKeyboardDOMEventDispatch() const override
;
760 void setPreventKeyboardDOMEventDispatch(bool) override
;
761 bool fileUploadButtonReturnsValueInTitle() const override
;
762 String
speechHintAttributeValue() const override
;
763 String
descriptionAttributeValue() const override
;
764 String
helpTextAttributeValue() const override
;
765 String
titleAttributeValue() const override
;
766 bool hasApplePDFAnnotationAttribute() const override
{ return hasAttribute(HTMLNames::x_apple_pdf_annotationAttr
); }
770 bool caretBrowsingEnabled() const override
;
771 void setCaretBrowsingEnabled(bool) override
;
774 AccessibilityObject
* focusableAncestor() override
;
775 AccessibilityObject
* editableAncestor() override
;
776 AccessibilityObject
* highestEditableAncestor() override
;
778 const AccessibilityScrollView
* ancestorAccessibilityScrollView(bool includeSelf
) const override
;
779 AccessibilityObject
* webAreaObject() const override
{ return nullptr; }
781 void clearIsIgnoredFromParentData() override
{ m_isIgnoredFromParentData
= { }; }
782 void setIsIgnoredFromParentDataForChild(AXCoreObject
*) override
;
784 PAL::SessionID
sessionID() const override
;
785 String
documentURI() const override
;
786 String
documentEncoding() const override
;
787 AccessibilityChildrenVector
documentLinks() override
{ return AccessibilityChildrenVector(); }
790 AccessibilityObject() = default;
792 // FIXME: Make more of these member functions private.
794 void detachRemoteParts(AccessibilityDetachmentType
) override
;
795 void detachPlatformWrapper(AccessibilityDetachmentType
) override
;
797 void setIsIgnoredFromParentData(AccessibilityIsIgnoredFromParentData
& data
) override
{ m_isIgnoredFromParentData
= data
; }
799 bool isAccessibilityObject() const override
{ return true; }
801 // If this object itself scrolls, return its ScrollableArea.
802 virtual ScrollableArea
* getScrollableAreaIfScrollable() const { return nullptr; }
803 virtual void scrollTo(const IntPoint
&) const { }
804 ScrollableArea
* scrollableAreaAncestor() const;
805 void scrollAreaAndAncestor(std::pair
<ScrollableArea
*, AccessibilityObject
*>&) const;
807 virtual bool shouldIgnoreAttributeRole() const { return false; }
808 virtual AccessibilityRole
buttonRoleType() const;
809 String
rolePlatformDescription() const;
810 bool isOnScreen() const override
;
811 bool dispatchTouchEvent();
813 static bool isARIAInput(AccessibilityRole
);
814 void ariaElementsFromAttribute(AccessibilityChildrenVector
&, const QualifiedName
&) const;
815 void ariaElementsReferencedByAttribute(AccessibilityChildrenVector
&, const QualifiedName
&) const;
816 virtual bool exposesTitleUIElement() const { return true; }
817 FloatRect
unobscuredContentRect() const override
;
818 AccessibilityObject
* radioGroupAncestor() const;
820 bool allowsTextRanges() const;
821 unsigned getLengthForTextRange() const;
822 String
innerHTML() const override
;
823 String
outerHTML() const override
;
826 bool hasAncestorFlag(AXAncestorFlag flag
) const { return ancestorFlagsAreInitialized() && m_ancestorFlags
.contains(flag
); }
827 std::optional
<SimpleRange
> rangeOfStringClosestToRangeInDirection(const SimpleRange
&, AccessibilitySearchDirection
, const Vector
<String
>&) const;
828 std::optional
<SimpleRange
> selectionRange() const;
829 std::optional
<SimpleRange
> findTextRange(const Vector
<String
>& searchStrings
, const SimpleRange
& start
, AccessibilitySearchTextDirection
) const;
830 std::optional
<SimpleRange
> visibleCharacterRange() const override
;
832 void ariaTreeRows(AccessibilityChildrenVector
& rows
, AccessibilityChildrenVector
& ancestors
);
834 #if PLATFORM(COCOA) && ENABLE(MODEL_ELEMENT)
835 Vector
<RetainPtr
<id
>> modelElementChildren() override
;
838 protected: // FIXME: Make the data members private.
839 bool childrenInitialized() const { return m_childrenInitialized
; }
840 AccessibilityChildrenVector m_children
;
841 mutable bool m_childrenInitialized
{ false };
842 AccessibilityRole m_role
{ AccessibilityRole::Unknown
};
845 OptionSet
<AXAncestorFlag
> m_ancestorFlags
;
846 AccessibilityObjectInclusion m_lastKnownIsIgnoredValue
{ AccessibilityObjectInclusion::DefaultBehavior
};
847 protected: // FIXME: Make the data members private.
848 // FIXME: This can be replaced by AXAncestorFlags.
849 AccessibilityIsIgnoredFromParentData m_isIgnoredFromParentData
;
850 bool m_childrenDirty
{ false };
851 bool m_subtreeDirty
{ false };
854 #if !ENABLE(ACCESSIBILITY)
855 inline const AccessibilityObject::AccessibilityChildrenVector
& AccessibilityObject::children(bool) { return m_children
; }
856 inline String
AccessibilityObject::localizedActionVerb() const { return emptyString(); }
857 inline String
AccessibilityObject::actionVerb() const { return emptyString(); }
858 inline int AccessibilityObject::lineForPosition(const VisiblePosition
&) const { return -1; }
859 inline void AccessibilityObject::updateBackingStore() { }
860 inline void AccessibilityObject::detachPlatformWrapper(AccessibilityDetachmentType
) { }
863 #if !(ENABLE(ACCESSIBILITY) && (USE(ATK) || USE(ATSPI)))
864 inline bool AccessibilityObject::allowsTextRanges() const { return true; }
865 inline unsigned AccessibilityObject::getLengthForTextRange() const { return text().length(); }
868 AccessibilityObject
* firstAccessibleObjectFromNode(const Node
*, const Function
<bool(const AccessibilityObject
&)>& isAccessible
);
870 namespace Accessibility
{
872 using PlatformRoleMap
= HashMap
<AccessibilityRole
, String
, DefaultHash
<unsigned>, WTF::UnsignedWithZeroKeyHashTraits
<unsigned>>;
874 PlatformRoleMap
createPlatformRoleMap();
875 String
roleToPlatformString(AccessibilityRole
);
877 } // namespace Accessibility
879 } // namespace WebCore
881 #define SPECIALIZE_TYPE_TRAITS_ACCESSIBILITY(ToValueTypeName, predicate) \
882 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \
883 static bool isType(const WebCore::AXCoreObject& object) { return object.predicate; } \
884 SPECIALIZE_TYPE_TRAITS_END()
886 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::AccessibilityObject
)
887 static bool isType(const WebCore::AXCoreObject
& context
) { return context
.isAccessibilityObject(); }
888 SPECIALIZE_TYPE_TRAITS_END()