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 Computer, 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.
33 #include "core/editing/VisiblePosition.h"
34 #include "core/editing/markers/DocumentMarker.h"
35 #include "core/inspector/protocol/Accessibility.h"
36 #include "modules/ModulesExport.h"
37 #include "platform/geometry/FloatQuad.h"
38 #include "platform/geometry/LayoutRect.h"
39 #include "platform/graphics/Color.h"
40 #include "wtf/Forward.h"
41 #include "wtf/Vector.h"
49 class AXObjectCacheImpl;
57 typedef unsigned AXID;
59 enum AccessibilityRole {
61 AbbrRole, // No mapping to ARIA role.
64 AnnotationRole, // No mapping to ARIA role.
67 AudioRole, // No mapping to ARIA role.
69 BlockquoteRole, // No mapping to ARIA role.
70 BusyIndicatorRole, // No mapping to ARIA role.
72 CanvasRole, // No mapping to ARIA role.
73 CaptionRole, // No mapping to ARIA role.
76 ColorWellRole, // No mapping to ARIA role.
78 ColumnRole, // No mapping to ARIA role.
82 DateRole, // No mapping to ARIA role.
83 DateTimeRole, // No mapping to ARIA role.
85 DescriptionListDetailRole, // No mapping to ARIA role.
86 DescriptionListRole, // No mapping to ARIA role.
87 DescriptionListTermRole, // No mapping to ARIA role.
88 DetailsRole, // No mapping to ARIA role.
91 DisclosureTriangleRole, // No mapping to ARIA role.
92 DivRole, // No mapping to ARIA role.
94 EmbeddedObjectRole, // No mapping to ARIA role.
95 FigcaptionRole, // No mapping to ARIA role.
96 FigureRole, // No mapping to ARIA role.
102 IframePresentationalRole, // No mapping to ARIA role.
103 IframeRole, // No mapping to ARIA role.
104 IgnoredRole, // No mapping to ARIA role.
105 ImageMapLinkRole, // No mapping to ARIA role.
106 ImageMapRole, // No mapping to ARIA role.
108 InlineTextBoxRole, // No mapping to ARIA role.
109 InputTimeRole, // No mapping to ARIA role.
111 LegendRole, // No mapping to ARIA role.
112 LineBreakRole, // No mapping to ARIA role.
117 ListMarkerRole, // No mapping to ARIA role.
121 MarkRole, // No mapping to ARIA role.
127 MenuItemCheckBoxRole,
134 NoneRole, // No mapping to ARIA role.
136 OutlineRole, // No mapping to ARIA role.
137 ParagraphRole, // No mapping to ARIA role.
139 PreRole, // No mapping to ARIA role.
141 ProgressIndicatorRole,
145 RootWebAreaRole, // No mapping to ARIA role.
148 RubyRole, // No mapping to ARIA role.
149 RulerRole, // No mapping to ARIA role.
150 SVGRootRole, // No mapping to ARIA role.
151 ScrollAreaRole, // No mapping to ARIA role.
153 SeamlessWebAreaRole, // No mapping to ARIA role.
157 SliderThumbRole, // No mapping to ARIA role.
158 SpinButtonPartRole, // No mapping to ARIA role.
161 StaticTextRole, // No mapping to ARIA role.
164 TabGroupRole, // No mapping to ARIA role.
168 TableHeaderContainerRole, // No mapping to ARIA role.
171 TimeRole, // No mapping to ARIA role.
178 UserInterfaceTooltipRole,
179 VideoRole, // No mapping to ARIA role.
180 WebAreaRole, // No mapping to ARIA role.
181 WindowRole, // No mapping to ARIA role.
185 enum AccessibilityTextSource {
196 enum AccessibilityState {
208 AXMultiselectableState,
220 class AccessibilityText final
221 : public GarbageCollectedFinalized<AccessibilityText> {
222 WTF_MAKE_NONCOPYABLE(AccessibilityText);
225 DEFINE_INLINE_TRACE() { visitor->trace(m_textElement); }
228 AccessibilityText(const String& text,
229 const AccessibilityTextSource& source,
231 : m_text(text), m_textElement(element) {}
234 Member<AXObject> m_textElement;
237 enum AccessibilityOrientation {
238 AccessibilityOrientationUndefined = 0,
239 AccessibilityOrientationVertical,
240 AccessibilityOrientationHorizontal,
243 enum AXObjectInclusion {
249 enum AccessibilityButtonState {
255 enum AccessibilityTextDirection {
256 AccessibilityTextDirectionLTR,
257 AccessibilityTextDirectionRTL,
258 AccessibilityTextDirectionTTB,
259 AccessibilityTextDirectionBTT
263 SortDirectionUndefined = 0,
265 SortDirectionAscending,
266 SortDirectionDescending,
270 enum AccessibilityExpanded {
271 ExpandedUndefined = 0,
276 enum AccessibilityOptionalBool {
277 OptionalBoolUndefined = 0,
282 enum AriaCurrentState {
283 AriaCurrentStateUndefined = 0,
284 AriaCurrentStateFalse,
285 AriaCurrentStateTrue,
286 AriaCurrentStatePage,
287 AriaCurrentStateStep,
288 AriaCurrentStateLocation,
289 AriaCurrentStateDate,
294 InvalidStateUndefined = 0,
297 InvalidStateSpelling,
304 TextStyleBold = 1 << 0,
305 TextStyleItalic = 1 << 1,
306 TextStyleUnderline = 1 << 2,
307 TextStyleLineThrough = 1 << 3
310 enum TextUnderElementMode {
312 TextUnderElementAny // If the text is unimportant, just whether or not it's
316 // The source of the accessible name of an element. This is needed
317 // because on some platforms this determines how the accessible name
320 AXNameFromUninitialized = -1,
321 AXNameFromAttribute = 0,
324 AXNameFromPlaceholder,
325 AXNameFromRelatedElement,
330 // The potential native HTML-based text (name, description or placeholder)
331 // sources for an element. See
332 // http://rawgit.com/w3c/aria/master/html-aam/html-aam.html#accessible-name-and-description-calculation
333 enum AXTextFromNativeHTML {
334 AXTextFromNativeHTMLUninitialized = -1,
335 AXTextFromNativeHTMLFigcaption,
336 AXTextFromNativeHTMLLabel,
337 AXTextFromNativeHTMLLabelFor,
338 AXTextFromNativeHTMLLabelWrapped,
339 AXTextFromNativeHTMLLegend,
340 AXTextFromNativeHTMLTableCaption,
341 AXTextFromNativeHTMLTitleElement,
344 // The source of the accessible description of an element. This is needed
345 // because on some platforms this determines how the accessible description
347 enum AXDescriptionFrom {
348 AXDescriptionFromUninitialized = -1,
349 AXDescriptionFromAttribute = 0,
350 AXDescriptionFromContents,
351 AXDescriptionFromPlaceholder,
352 AXDescriptionFromRelatedElement,
355 enum AXIgnoredReason {
357 AXAncestorDisallowsChild,
358 AXAncestorIsLeafNode,
364 AXInheritsPresentation,
369 AXPresentationalRole,
370 AXProbablyPresentational,
371 AXStaticTextUsedAsNameFor,
375 class IgnoredReason {
376 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
379 AXIgnoredReason reason;
380 Member<const AXObject> relatedObject;
382 explicit IgnoredReason(AXIgnoredReason reason)
383 : reason(reason), relatedObject(nullptr) {}
385 IgnoredReason(AXIgnoredReason r, const AXObject* obj)
386 : reason(r), relatedObject(obj) {}
388 DEFINE_INLINE_TRACE() { visitor->trace(relatedObject); }
391 class NameSourceRelatedObject
392 : public GarbageCollectedFinalized<NameSourceRelatedObject> {
393 WTF_MAKE_NONCOPYABLE(NameSourceRelatedObject);
396 WeakMember<AXObject> object;
399 NameSourceRelatedObject(AXObject* object, String text)
400 : object(object), text(text) {}
402 DEFINE_INLINE_TRACE() { visitor->trace(object); }
405 typedef HeapVector<Member<NameSourceRelatedObject>> AXRelatedObjectVector;
407 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
411 bool superseded = false;
412 bool invalid = false;
413 AXNameFrom type = AXNameFromUninitialized;
414 const QualifiedName& attribute;
415 AtomicString attributeValue;
416 AXTextFromNativeHTML nativeSource = AXTextFromNativeHTMLUninitialized;
417 AXRelatedObjectVector relatedObjects;
419 NameSource(bool superseded, const QualifiedName& attr)
420 : superseded(superseded), attribute(attr) {}
422 explicit NameSource(bool superseded)
423 : superseded(superseded), attribute(QualifiedName::null()) {}
425 DEFINE_INLINE_TRACE() { visitor->trace(relatedObjects); }
428 class DescriptionSource {
429 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
433 bool superseded = false;
434 bool invalid = false;
435 AXDescriptionFrom type = AXDescriptionFromUninitialized;
436 const QualifiedName& attribute;
437 AtomicString attributeValue;
438 AXTextFromNativeHTML nativeSource = AXTextFromNativeHTMLUninitialized;
439 AXRelatedObjectVector relatedObjects;
441 DescriptionSource(bool superseded, const QualifiedName& attr)
442 : superseded(superseded), attribute(attr) {}
444 explicit DescriptionSource(bool superseded)
445 : superseded(superseded), attribute(QualifiedName::null()) {}
447 DEFINE_INLINE_TRACE() { visitor->trace(relatedObjects); }
452 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::IgnoredReason);
453 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::NameSource);
454 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::DescriptionSource);
458 class MODULES_EXPORT AXObject : public GarbageCollectedFinalized<AXObject> {
459 WTF_MAKE_NONCOPYABLE(AXObject);
462 typedef HeapVector<Member<AXObject>> AXObjectVector;
465 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
466 // The deepest descendant in which the range starts.
467 // (nullptr means the current object.)
468 Persistent<AXObject> anchorObject;
469 // The number of characters and child objects in the anchor object
470 // before the range starts.
472 // When the same character offset could correspond to two possible
473 // cursor positions, upstream means it's on the previous line rather
474 // than the next line.
475 TextAffinity anchorAffinity;
477 // The deepest descendant in which the range ends.
478 // (nullptr means the current object.)
479 Persistent<AXObject> focusObject;
480 // The number of characters and child objects in the focus object
481 // before the range ends.
483 // When the same character offset could correspond to two possible
484 // cursor positions, upstream means it's on the previous line rather
485 // than the next line.
486 TextAffinity focusAffinity;
489 : anchorObject(nullptr),
491 anchorAffinity(TextAffinity::Upstream),
492 focusObject(nullptr),
494 focusAffinity(TextAffinity::Downstream) {}
496 AXRange(int startOffset, int endOffset)
497 : anchorObject(nullptr),
498 anchorOffset(startOffset),
499 anchorAffinity(TextAffinity::Upstream),
500 focusObject(nullptr),
501 focusOffset(endOffset),
502 focusAffinity(TextAffinity::Downstream) {}
504 AXRange(AXObject* anchorObject,
506 TextAffinity anchorAffinity,
507 AXObject* focusObject,
509 TextAffinity focusAffinity)
510 : anchorObject(anchorObject),
511 anchorOffset(anchorOffset),
512 anchorAffinity(anchorAffinity),
513 focusObject(focusObject),
514 focusOffset(focusOffset),
515 focusAffinity(focusAffinity) {}
517 bool isValid() const {
518 return ((anchorObject && focusObject) ||
519 (!anchorObject && !focusObject)) &&
520 anchorOffset >= 0 && focusOffset >= 0;
523 // Determines if the range only refers to text offsets under the current
525 bool isSimple() const {
526 return anchorObject == focusObject || !anchorObject || !focusObject;
531 AXObject(AXObjectCacheImpl&);
535 DECLARE_VIRTUAL_TRACE();
537 static unsigned numberOfLiveAXObjects() { return s_numberOfLiveAXObjects; }
539 // After constructing an AXObject, it must be given a
540 // unique ID, then added to AXObjectCacheImpl, and finally init() must
542 void setAXObjectID(AXID axObjectID) { m_id = axObjectID; }
543 virtual void init() {}
545 // When the corresponding WebCore object that this AXObject
546 // wraps is deleted, it must be detached.
547 virtual void detach();
548 virtual bool isDetached() const;
550 // If the parent of this object is known, this can be faster than using
552 virtual void setParent(AXObject* parent) { m_parent = parent; }
554 // The AXObjectCacheImpl that owns this object, and its unique ID within this
556 AXObjectCacheImpl& axObjectCache() const {
557 ASSERT(m_axObjectCache);
558 return *m_axObjectCache;
561 AXID axObjectID() const { return m_id; }
563 // Determine subclass type.
564 virtual bool isAXNodeObject() const { return false; }
565 virtual bool isAXLayoutObject() const { return false; }
566 virtual bool isAXListBox() const { return false; }
567 virtual bool isAXListBoxOption() const { return false; }
568 virtual bool isAXRadioInput() const { return false; }
569 virtual bool isAXSVGRoot() const { return false; }
571 // Check object role or purpose.
572 virtual AccessibilityRole roleValue() const { return m_role; }
573 bool isARIATextControl() const;
574 virtual bool isARIATreeGridRow() const { return false; }
575 virtual bool isAXTable() const { return false; }
576 virtual bool isAnchor() const { return false; }
577 bool isButton() const;
578 bool isCanvas() const { return roleValue() == CanvasRole; }
579 bool isCheckbox() const { return roleValue() == CheckBoxRole; }
580 bool isCheckboxOrRadio() const { return isCheckbox() || isRadioButton(); }
581 bool isColorWell() const { return roleValue() == ColorWellRole; }
582 bool isComboBox() const { return roleValue() == ComboBoxRole; }
583 virtual bool isControl() const { return false; }
584 virtual bool isDataTable() const { return false; }
585 virtual bool isEmbeddedObject() const { return false; }
586 virtual bool isFieldset() const { return false; }
587 virtual bool isHeading() const { return false; }
588 virtual bool isImage() const { return false; }
589 virtual bool isImageMapLink() const { return false; }
590 virtual bool isInputImage() const { return false; }
591 bool isLandmarkRelated() const;
592 virtual bool isLink() const { return false; }
593 virtual bool isList() const { return false; }
594 virtual bool isMenu() const { return false; }
595 virtual bool isMenuButton() const { return false; }
596 virtual bool isMenuList() const { return false; }
597 virtual bool isMenuListOption() const { return false; }
598 virtual bool isMenuListPopup() const { return false; }
599 bool isMenuRelated() const;
600 virtual bool isMeter() const { return false; }
601 virtual bool isMockObject() const { return false; }
602 virtual bool isNativeSpinButton() const { return false; }
603 virtual bool isNativeTextControl() const {
605 } // input or textarea
606 virtual bool isNonNativeTextControl() const {
608 } // contenteditable or role=textbox
609 virtual bool isPasswordField() const { return false; }
610 virtual bool isPasswordFieldAndShouldHideValue() const;
611 bool isPresentational() const {
612 return roleValue() == NoneRole || roleValue() == PresentationalRole;
614 virtual bool isProgressIndicator() const { return false; }
615 bool isRadioButton() const { return roleValue() == RadioButtonRole; }
616 bool isRange() const {
617 return roleValue() == ProgressIndicatorRole ||
618 roleValue() == ScrollBarRole || roleValue() == SliderRole ||
619 roleValue() == SpinButtonRole;
621 bool isScrollbar() const { return roleValue() == ScrollBarRole; }
622 virtual bool isSlider() const { return false; }
623 virtual bool isNativeSlider() const { return false; }
624 virtual bool isSpinButton() const { return roleValue() == SpinButtonRole; }
625 virtual bool isSpinButtonPart() const { return false; }
626 bool isTabItem() const { return roleValue() == TabRole; }
627 virtual bool isTableCell() const { return false; }
628 virtual bool isTableRow() const { return false; }
629 virtual bool isTextControl() const { return false; }
630 virtual bool isTableCol() const { return false; }
631 bool isTree() const { return roleValue() == TreeRole; }
632 bool isWebArea() const { return roleValue() == WebAreaRole; }
634 // Check object state.
635 virtual bool isChecked() const { return false; }
636 virtual bool isClickable() const;
637 virtual bool isCollapsed() const { return false; }
638 virtual bool isEnabled() const { return false; }
639 virtual AccessibilityExpanded isExpanded() const { return ExpandedUndefined; }
640 virtual bool isFocused() const { return false; }
641 virtual bool isHovered() const { return false; }
642 virtual bool isLinked() const { return false; }
643 virtual bool isLoaded() const { return false; }
644 virtual bool isMultiSelectable() const { return false; }
645 virtual bool isOffScreen() const { return false; }
646 virtual bool isPressed() const { return false; }
647 virtual bool isReadOnly() const { return false; }
648 virtual bool isRequired() const { return false; }
649 virtual bool isSelected() const { return false; }
650 virtual bool isSelectedOptionActive() const { return false; }
651 virtual bool isVisible() const { return true; }
652 virtual bool isVisited() const { return false; }
654 // Check whether certain properties can be modified.
655 virtual bool canSetFocusAttribute() const { return false; }
656 virtual bool canSetValueAttribute() const { return false; }
657 virtual bool canSetSelectedAttribute() const { return false; }
659 // Whether objects are ignored, i.e. not included in the tree.
660 bool accessibilityIsIgnored() const;
661 typedef HeapVector<IgnoredReason> IgnoredReasons;
662 virtual bool computeAccessibilityIsIgnored(IgnoredReasons* = nullptr) const {
665 bool accessibilityIsIgnoredByDefault(IgnoredReasons* = nullptr) const;
666 AXObjectInclusion accessibilityPlatformIncludesObject() const;
667 virtual AXObjectInclusion defaultObjectInclusion(
668 IgnoredReasons* = nullptr) const;
669 bool isInertOrAriaHidden() const;
670 const AXObject* ariaHiddenRoot() const;
671 bool computeIsInertOrAriaHidden(IgnoredReasons* = nullptr) const;
672 bool isDescendantOfLeafNode() const;
673 AXObject* leafNodeAncestor() const;
674 bool isDescendantOfDisabledNode() const;
675 const AXObject* disabledAncestor() const;
676 bool lastKnownIsIgnoredValue();
677 void setLastKnownIsIgnoredValue(bool);
678 bool hasInheritedPresentationalRole() const;
679 bool isPresentationalChild() const;
680 bool ancestorExposesActiveDescendant() const;
681 bool computeAncestorExposesActiveDescendant() const;
684 // Accessible name calculation
687 // Retrieves the accessible name of the object, an enum indicating where the
688 // name was derived from, and a list of objects that were used to derive the
690 virtual String name(AXNameFrom&, AXObjectVector* nameObjects) const;
692 typedef HeapVector<NameSource> NameSources;
693 // Retrieves the accessible name of the object and a list of all potential
694 // sources for the name, indicating which were used.
695 virtual String name(NameSources*) const;
697 typedef HeapVector<DescriptionSource> DescriptionSources;
698 // Takes the result of nameFrom from calling |name|, above, and retrieves the
699 // accessible description of the object, which is secondary to |name|, an enum
700 // indicating where the description was derived from, and a list of objects
701 // that were used to derive the description, if any.
702 virtual String description(AXNameFrom,
704 AXObjectVector* descriptionObjects) const {
708 // Same as above, but returns a list of all potential sources for the
709 // description, indicating which were used.
710 virtual String description(AXNameFrom,
713 AXRelatedObjectVector*) const {
717 // Takes the result of nameFrom and descriptionFrom from calling |name| and
718 // |description|, above, and retrieves the placeholder of the object, if
719 // present and if it wasn't already exposed by one of the two functions above.
720 virtual String placeholder(AXNameFrom, AXDescriptionFrom) const {
724 // Internal functions used by name and description, above.
725 typedef HeapHashSet<Member<const AXObject>> AXObjectSet;
726 virtual String textAlternative(bool recursive,
727 bool inAriaLabelledByTraversal,
728 AXObjectSet& visited,
729 AXNameFrom& nameFrom,
730 AXRelatedObjectVector* relatedObjects,
731 NameSources* nameSources) const {
734 virtual String textFromDescendants(AXObjectSet& visited,
735 bool recursive) const {
739 // Returns result of Accessible Name Calculation algorithm.
740 // This is a simpler high-level interface to |name| used by Inspector.
741 String computedName() const;
743 // Internal function used to determine whether the result of calling |name| on
744 // this object would return text that came from the an HTML label element or
745 // not. This is intended to be faster than calling |name| or
746 // |textAlternative|, and without side effects (it won't call
747 // axObjectCache->getOrCreate).
748 virtual bool nameFromLabelElement() const { return false; }
751 // Properties of static elements.
754 virtual const AtomicString& accessKey() const { return nullAtom; }
755 RGBA32 backgroundColor() const;
756 virtual RGBA32 computeBackgroundColor() const { return Color::transparent; }
757 virtual RGBA32 color() const { return Color::black; }
758 // Used by objects of role ColorWellRole.
759 virtual RGBA32 colorValue() const { return Color::transparent; }
760 virtual bool canvasHasFallbackContent() const { return false; }
761 virtual String fontFamily() const { return nullAtom; }
762 // Font size is in pixels.
763 virtual float fontSize() const { return 0.0f; }
764 // Value should be 1-based. 0 means not supported.
765 virtual int headingLevel() const { return 0; }
766 // Value should be 1-based. 0 means not supported.
767 virtual unsigned hierarchicalLevel() const { return 0; }
768 virtual AccessibilityOrientation orientation() const;
769 virtual String text() const { return String(); }
770 virtual AccessibilityTextDirection textDirection() const {
771 return AccessibilityTextDirectionLTR;
773 virtual int textLength() const { return 0; }
774 virtual TextStyle getTextStyle() const { return TextStyleNone; }
775 virtual KURL url() const { return KURL(); }
777 // Load inline text boxes for just this node, even if
778 // settings->inlineTextBoxAccessibilityEnabled() is false.
779 virtual void loadInlineTextBoxes() {}
781 // Walk the AXObjects on the same line. This is supported on any
782 // object type but primarily intended to be used for inline text boxes.
783 virtual AXObject* nextOnLine() const { return nullptr; }
784 virtual AXObject* previousOnLine() const { return nullptr; }
786 // For all node objects. The start and end character offset of each
787 // marker, such as spelling or grammar error.
788 virtual void markers(Vector<DocumentMarker::MarkerType>&,
789 Vector<AXRange>&) const {}
790 // For an inline text box.
791 // The integer horizontal pixel offset of each character in the string;
792 // negative values for RTL.
793 virtual void textCharacterOffsets(Vector<int>&) const {}
794 // The start and end character offset of each word in the object's text.
795 virtual void wordBoundaries(Vector<AXRange>&) const {}
797 // Properties of interactive elements.
798 String actionVerb() const;
799 virtual AccessibilityButtonState checkboxOrRadioValue() const;
800 virtual AriaCurrentState ariaCurrentState() const {
801 return AriaCurrentStateUndefined;
803 virtual InvalidState getInvalidState() const { return InvalidStateUndefined; }
804 // Only used when invalidState() returns InvalidStateOther.
805 virtual String ariaInvalidValue() const { return String(); }
806 virtual String valueDescription() const { return String(); }
807 virtual float valueForRange() const { return 0.0f; }
808 virtual float maxValueForRange() const { return 0.0f; }
809 virtual float minValueForRange() const { return 0.0f; }
810 virtual String stringValue() const { return String(); }
813 virtual AXObject* activeDescendant() { return nullptr; }
814 virtual String ariaAutoComplete() const { return String(); }
815 virtual void ariaFlowToElements(AXObjectVector&) const {}
816 virtual void ariaControlsElements(AXObjectVector&) const {}
817 virtual void ariaOwnsElements(AXObjectVector& owns) const {}
818 virtual void ariaDescribedbyElements(AXObjectVector&) const {}
819 virtual void ariaLabelledbyElements(AXObjectVector&) const {}
820 virtual bool ariaHasPopup() const { return false; }
821 virtual bool isEditable() const { return false; }
822 bool isMultiline() const;
823 virtual bool isRichlyEditable() const { return false; }
824 bool ariaPressedIsPresent() const;
825 virtual AccessibilityRole ariaRoleAttribute() const { return UnknownRole; }
826 virtual bool ariaRoleHasPresentationalChildren() const { return false; }
827 virtual AXObject* ancestorForWhichThisIsAPresentationalChild() const {
830 bool supportsActiveDescendant() const;
831 bool supportsARIAAttributes() const;
832 virtual bool supportsARIADragging() const { return false; }
833 virtual bool supportsARIADropping() const { return false; }
834 virtual bool supportsARIAFlowTo() const { return false; }
835 virtual bool supportsARIAOwns() const { return false; }
836 bool supportsRangeValue() const;
837 virtual SortDirection getSortDirection() const {
838 return SortDirectionUndefined;
841 // Returns 0-based index.
842 int indexInParent() const;
844 // Value should be 1-based. 0 means not supported.
845 virtual int posInSet() const { return 0; }
846 virtual int setSize() const { return 0; }
847 bool supportsSetSizeAndPosInSet() const;
849 // ARIA live-region features.
850 bool isLiveRegion() const;
851 AXObject* liveRegionRoot() const;
852 virtual const AtomicString& liveRegionStatus() const { return nullAtom; }
853 virtual const AtomicString& liveRegionRelevant() const { return nullAtom; }
854 virtual bool liveRegionAtomic() const { return false; }
855 virtual bool liveRegionBusy() const { return false; }
857 const AtomicString& containerLiveRegionStatus() const;
858 const AtomicString& containerLiveRegionRelevant() const;
859 bool containerLiveRegionAtomic() const;
860 bool containerLiveRegionBusy() const;
862 // Every object's bounding box is returned relative to a
863 // container object (which is guaranteed to be an ancestor) and
864 // optionally a transformation matrix that needs to be applied too.
865 // To compute the absolute bounding box of an element, start with its
866 // boundsInContainer and apply the transform. Then as long as its container is
867 // not null, walk up to its container and offset by the container's offset
868 // from origin, the container's scroll position if any, and apply the
869 // container's transform. Do this until you reach the root of the tree.
870 virtual void getRelativeBounds(AXObject** outContainer,
871 FloatRect& outBoundsInContainer,
872 SkMatrix44& outContainerTransform) const;
874 // Get the bounds in frame-relative coordinates as a LayoutRect.
875 LayoutRect getBoundsInFrameCoordinates() const;
877 // Explicitly set an object's bounding rect and offset container.
878 void setElementRect(LayoutRect r, AXObject* container) {
879 m_explicitElementRect = r;
880 m_explicitContainerID = container->axObjectID();
884 // Called on the root AX object to return the deepest available element.
885 virtual AXObject* accessibilityHitTest(const IntPoint&) const { return 0; }
886 // Called on the AX object after the layout tree determines which is the right
888 virtual AXObject* elementAccessibilityHitTest(const IntPoint&) const;
890 // High-level accessibility tree access. Other modules should only use these
892 const AXObjectVector& children();
893 AXObject* parentObject() const;
894 AXObject* parentObjectIfExists() const;
895 virtual AXObject* computeParent() const = 0;
896 virtual AXObject* computeParentIfExists() const { return 0; }
897 AXObject* cachedParentObject() const { return m_parent; }
898 AXObject* parentObjectUnignored() const;
900 // Low-level accessibility tree exploration, only for use within the
901 // accessibility module.
902 virtual AXObject* rawFirstChild() const { return 0; }
903 virtual AXObject* rawNextSibling() const { return 0; }
904 virtual void addChildren() {}
905 virtual bool canHaveChildren() const { return true; }
906 bool hasChildren() const { return m_haveChildren; }
907 virtual void updateChildrenIfNecessary();
908 virtual bool needsToUpdateChildren() const { return false; }
909 virtual void setNeedsToUpdateChildren() {}
910 virtual void clearChildren();
911 virtual void detachFromParent() { m_parent = 0; }
912 virtual AXObject* scrollBar(AccessibilityOrientation) { return 0; }
914 // Properties of the object's owning document or page.
915 virtual double estimatedLoadingProgress() const { return 0; }
917 // DOM and layout tree access.
918 virtual Node* getNode() const { return 0; }
919 virtual LayoutObject* getLayoutObject() const { return 0; }
920 virtual Document* getDocument() const;
921 virtual FrameView* documentFrameView() const;
922 virtual Element* anchorElement() const { return 0; }
923 virtual Element* actionElement() const { return 0; }
924 String language() const;
925 bool hasAttribute(const QualifiedName&) const;
926 const AtomicString& getAttribute(const QualifiedName&) const;
928 // Methods that retrieve or manipulate the current selection.
930 // Get the current selection from anywhere in the accessibility tree.
931 virtual AXRange selection() const { return AXRange(); }
932 // Gets only the start and end offsets of the selection computed using the
933 // current object as the starting point. Returns a null selection if there is
934 // no selection in the subtree rooted at this object.
935 virtual AXRange selectionUnderObject() const { return AXRange(); }
936 virtual void setSelection(const AXRange&) {}
938 // Scrollable containers.
939 bool isScrollableContainer() const;
940 IntPoint scrollOffset() const;
941 IntPoint minimumScrollOffset() const;
942 IntPoint maximumScrollOffset() const;
943 void setScrollOffset(const IntPoint&) const;
945 // If this object itself scrolls, return its ScrollableArea.
946 virtual ScrollableArea* getScrollableAreaIfScrollable() const { return 0; }
948 // Modify or take an action on an object.
949 virtual void increment() {}
950 virtual void decrement() {}
951 bool performDefaultAction() const { return press(); }
952 virtual bool press() const;
953 // Make this object visible by scrolling as many nested scrollable views as
955 void scrollToMakeVisible() const;
956 // Same, but if the whole object can't be made visible, try for this subrect,
957 // in local coordinates.
958 void scrollToMakeVisibleWithSubFocus(const IntRect&) const;
959 // Scroll this object to a given point in global coordinates of the top-level
961 void scrollToGlobalPoint(const IntPoint&) const;
962 virtual void setFocused(bool) {}
963 virtual void setSelected(bool) {}
964 virtual void setSequentialFocusNavigationStartingPoint();
965 virtual void setValue(const String&) {}
966 virtual void setValue(float) {}
968 // Notifications that this object may have changed.
969 virtual void childrenChanged() {}
970 virtual void handleActiveDescendantChanged() {}
971 virtual void handleAriaExpandedChanged() {}
972 void notifyIfIgnoredValueChanged();
973 virtual void selectionChanged();
974 virtual void textChanged() {}
975 virtual void updateAccessibilityRole() {}
977 // Text metrics. Most of these should be deprecated, needs major cleanup.
978 virtual VisiblePosition visiblePositionForIndex(int) const {
979 return VisiblePosition();
981 int lineForPosition(const VisiblePosition&) const;
982 virtual int index(const VisiblePosition&) const { return -1; }
983 virtual void lineBreaks(Vector<int>&) const {}
985 // Static helper functions.
986 static bool isARIAControl(AccessibilityRole);
987 static bool isARIAInput(AccessibilityRole);
988 static AccessibilityRole ariaRoleToWebCoreRole(const String&);
989 static const AtomicString& roleName(AccessibilityRole);
990 static const AtomicString& internalRoleName(AccessibilityRole);
991 static bool isInsideFocusableElementOrARIAWidget(const Node&);
995 AXObjectVector m_children;
996 mutable bool m_haveChildren;
997 AccessibilityRole m_role;
998 AXObjectInclusion m_lastKnownIsIgnoredValue;
999 LayoutRect m_explicitElementRect;
1000 AXID m_explicitContainerID;
1002 // Used only inside textAlternative():
1003 static String collapseWhitespace(const String&);
1004 static String recursiveTextAlternative(const AXObject&,
1005 bool inAriaLabelledByTraversal,
1006 AXObjectSet& visited);
1007 bool isHiddenForTextAlternativeCalculation() const;
1008 String ariaTextAlternative(bool recursive,
1009 bool inAriaLabelledByTraversal,
1010 AXObjectSet& visited,
1012 AXRelatedObjectVector*,
1014 bool* foundTextAlternative) const;
1015 String textFromElements(bool inAriaLabelledByTraversal,
1016 AXObjectSet& visited,
1017 HeapVector<Member<Element>>& elements,
1018 AXRelatedObjectVector* relatedObjects) const;
1019 void tokenVectorFromAttribute(Vector<String>&, const QualifiedName&) const;
1020 void elementsFromAttribute(HeapVector<Member<Element>>& elements,
1021 const QualifiedName&) const;
1022 void ariaLabelledbyElementVector(HeapVector<Member<Element>>& elements) const;
1023 String textFromAriaLabelledby(AXObjectSet& visited,
1024 AXRelatedObjectVector* relatedObjects) const;
1025 String textFromAriaDescribedby(AXRelatedObjectVector* relatedObjects) const;
1027 virtual const AXObject* inheritsPresentationalRoleFrom() const { return 0; }
1029 virtual bool nameFromContents() const;
1031 AccessibilityRole buttonRoleType() const;
1033 virtual LayoutObject* layoutObjectForRelativeBounds() const {
1037 mutable Member<AXObject> m_parent;
1039 // The following cached attribute values (the ones starting with m_cached*)
1040 // are only valid if m_lastModificationCount matches
1041 // AXObjectCacheImpl::modificationCount().
1042 mutable int m_lastModificationCount;
1043 mutable RGBA32 m_cachedBackgroundColor;
1044 mutable bool m_cachedIsIgnored : 1;
1045 mutable bool m_cachedIsInertOrAriaHidden : 1;
1046 mutable bool m_cachedIsDescendantOfLeafNode : 1;
1047 mutable bool m_cachedIsDescendantOfDisabledNode : 1;
1048 mutable bool m_cachedHasInheritedPresentationalRole : 1;
1049 mutable bool m_cachedIsPresentationalChild : 1;
1050 mutable bool m_cachedAncestorExposesActiveDescendant : 1;
1051 mutable Member<AXObject> m_cachedLiveRegionRoot;
1053 Member<AXObjectCacheImpl> m_axObjectCache;
1055 // Updates the cached attribute values. This may be recursive, so to prevent
1057 // functions called here may only search up the tree (ancestors), not down.
1058 void updateCachedAttributeValuesIfNeeded() const;
1061 static bool includesARIAWidgetRole(const String&);
1062 static bool hasInteractiveARIAAttribute(const Element&);
1064 static unsigned s_numberOfLiveAXObjects;
1067 #define DEFINE_AX_OBJECT_TYPE_CASTS(thisType, predicate) \
1068 DEFINE_TYPE_CASTS(thisType, AXObject, object, object->predicate, \
1071 } // namespace blink
1073 #endif // AXObject_h