69ebc35548aaca9bff168e5b0dc3ece4718ee0fc
[platform/framework/web/crosswalk-tizen.git] /
1 /*
2  * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Nuanti Ltd.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
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.
17  *
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.
28  */
29
30 #ifndef AXObject_h
31 #define AXObject_h
32
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"
42
43 class SkMatrix44;
44
45 namespace blink {
46
47 class AXObject;
48 class AXObjectCache;
49 class AXObjectCacheImpl;
50 class Element;
51 class FrameView;
52 class IntPoint;
53 class Node;
54 class LayoutObject;
55 class ScrollableArea;
56
57 typedef unsigned AXID;
58
59 enum AccessibilityRole {
60   UnknownRole = 0,
61   AbbrRole,  // No mapping to ARIA role.
62   AlertDialogRole,
63   AlertRole,
64   AnnotationRole,  // No mapping to ARIA role.
65   ApplicationRole,
66   ArticleRole,
67   AudioRole,  // No mapping to ARIA role.
68   BannerRole,
69   BlockquoteRole,     // No mapping to ARIA role.
70   BusyIndicatorRole,  // No mapping to ARIA role.
71   ButtonRole,
72   CanvasRole,   // No mapping to ARIA role.
73   CaptionRole,  // No mapping to ARIA role.
74   CellRole,
75   CheckBoxRole,
76   ColorWellRole,  // No mapping to ARIA role.
77   ColumnHeaderRole,
78   ColumnRole,  // No mapping to ARIA role.
79   ComboBoxRole,
80   ComplementaryRole,
81   ContentInfoRole,
82   DateRole,      // No mapping to ARIA role.
83   DateTimeRole,  // No mapping to ARIA role.
84   DefinitionRole,
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.
89   DialogRole,
90   DirectoryRole,
91   DisclosureTriangleRole,  // No mapping to ARIA role.
92   DivRole,                 // No mapping to ARIA role.
93   DocumentRole,
94   EmbeddedObjectRole,  // No mapping to ARIA role.
95   FigcaptionRole,      // No mapping to ARIA role.
96   FigureRole,          // No mapping to ARIA role.
97   FooterRole,
98   FormRole,
99   GridRole,
100   GroupRole,
101   HeadingRole,
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.
107   ImageRole,
108   InlineTextBoxRole,  // No mapping to ARIA role.
109   InputTimeRole,      // No mapping to ARIA role.
110   LabelRole,
111   LegendRole,     // No mapping to ARIA role.
112   LineBreakRole,  // No mapping to ARIA role.
113   LinkRole,
114   ListBoxOptionRole,
115   ListBoxRole,
116   ListItemRole,
117   ListMarkerRole,  // No mapping to ARIA role.
118   ListRole,
119   LogRole,
120   MainRole,
121   MarkRole,  // No mapping to ARIA role.
122   MarqueeRole,
123   MathRole,
124   MenuBarRole,
125   MenuButtonRole,
126   MenuItemRole,
127   MenuItemCheckBoxRole,
128   MenuItemRadioRole,
129   MenuListOptionRole,
130   MenuListPopupRole,
131   MenuRole,
132   MeterRole,
133   NavigationRole,
134   NoneRole,  // No mapping to ARIA role.
135   NoteRole,
136   OutlineRole,    // No mapping to ARIA role.
137   ParagraphRole,  // No mapping to ARIA role.
138   PopUpButtonRole,
139   PreRole,  // No mapping to ARIA role.
140   PresentationalRole,
141   ProgressIndicatorRole,
142   RadioButtonRole,
143   RadioGroupRole,
144   RegionRole,
145   RootWebAreaRole,  // No mapping to ARIA role.
146   RowHeaderRole,
147   RowRole,
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.
152   ScrollBarRole,
153   SeamlessWebAreaRole,  // No mapping to ARIA role.
154   SearchRole,
155   SearchBoxRole,
156   SliderRole,
157   SliderThumbRole,     // No mapping to ARIA role.
158   SpinButtonPartRole,  // No mapping to ARIA role.
159   SpinButtonRole,
160   SplitterRole,
161   StaticTextRole,  // No mapping to ARIA role.
162   StatusRole,
163   SwitchRole,
164   TabGroupRole,  // No mapping to ARIA role.
165   TabListRole,
166   TabPanelRole,
167   TabRole,
168   TableHeaderContainerRole,  // No mapping to ARIA role.
169   TableRole,
170   TextFieldRole,
171   TimeRole,  // No mapping to ARIA role.
172   TimerRole,
173   ToggleButtonRole,
174   ToolbarRole,
175   TreeGridRole,
176   TreeItemRole,
177   TreeRole,
178   UserInterfaceTooltipRole,
179   VideoRole,    // No mapping to ARIA role.
180   WebAreaRole,  // No mapping to ARIA role.
181   WindowRole,   // No mapping to ARIA role.
182   NumRoles
183 };
184
185 enum AccessibilityTextSource {
186   AlternativeText,
187   ChildrenText,
188   SummaryText,
189   HelpText,
190   VisibleText,
191   TitleTagText,
192   PlaceholderText,
193   LabelByElementText,
194 };
195
196 enum AccessibilityState {
197   AXBusyState,
198   AXCheckedState,
199   AXEnabledState,
200   AXExpandedState,
201   AXFocusableState,
202   AXFocusedState,
203   AXHaspopupState,
204   AXHoveredState,
205   AXInvisibleState,
206   AXLinkedState,
207   AXMultilineState,
208   AXMultiselectableState,
209   AXOffscreenState,
210   AXPressedState,
211   AXProtectedState,
212   AXReadonlyState,
213   AXRequiredState,
214   AXSelectableState,
215   AXSelectedState,
216   AXVerticalState,
217   AXVisitedState
218 };
219
220 class AccessibilityText final
221     : public GarbageCollectedFinalized<AccessibilityText> {
222   WTF_MAKE_NONCOPYABLE(AccessibilityText);
223
224  public:
225   DEFINE_INLINE_TRACE() { visitor->trace(m_textElement); }
226
227  private:
228   AccessibilityText(const String& text,
229                     const AccessibilityTextSource& source,
230                     AXObject* element)
231       : m_text(text), m_textElement(element) {}
232
233   String m_text;
234   Member<AXObject> m_textElement;
235 };
236
237 enum AccessibilityOrientation {
238   AccessibilityOrientationUndefined = 0,
239   AccessibilityOrientationVertical,
240   AccessibilityOrientationHorizontal,
241 };
242
243 enum AXObjectInclusion {
244   IncludeObject,
245   IgnoreObject,
246   DefaultBehavior,
247 };
248
249 enum AccessibilityButtonState {
250   ButtonStateOff = 0,
251   ButtonStateOn,
252   ButtonStateMixed,
253 };
254
255 enum AccessibilityTextDirection {
256   AccessibilityTextDirectionLTR,
257   AccessibilityTextDirectionRTL,
258   AccessibilityTextDirectionTTB,
259   AccessibilityTextDirectionBTT
260 };
261
262 enum SortDirection {
263   SortDirectionUndefined = 0,
264   SortDirectionNone,
265   SortDirectionAscending,
266   SortDirectionDescending,
267   SortDirectionOther
268 };
269
270 enum AccessibilityExpanded {
271   ExpandedUndefined = 0,
272   ExpandedCollapsed,
273   ExpandedExpanded,
274 };
275
276 enum AccessibilityOptionalBool {
277   OptionalBoolUndefined = 0,
278   OptionalBoolTrue,
279   OptionalBoolFalse
280 };
281
282 enum AriaCurrentState {
283   AriaCurrentStateUndefined = 0,
284   AriaCurrentStateFalse,
285   AriaCurrentStateTrue,
286   AriaCurrentStatePage,
287   AriaCurrentStateStep,
288   AriaCurrentStateLocation,
289   AriaCurrentStateDate,
290   AriaCurrentStateTime
291 };
292
293 enum InvalidState {
294   InvalidStateUndefined = 0,
295   InvalidStateFalse,
296   InvalidStateTrue,
297   InvalidStateSpelling,
298   InvalidStateGrammar,
299   InvalidStateOther
300 };
301
302 enum TextStyle {
303   TextStyleNone = 0,
304   TextStyleBold = 1 << 0,
305   TextStyleItalic = 1 << 1,
306   TextStyleUnderline = 1 << 2,
307   TextStyleLineThrough = 1 << 3
308 };
309
310 enum TextUnderElementMode {
311   TextUnderElementAll,
312   TextUnderElementAny  // If the text is unimportant, just whether or not it's
313                        // present
314 };
315
316 // The source of the accessible name of an element. This is needed
317 // because on some platforms this determines how the accessible name
318 // is exposed.
319 enum AXNameFrom {
320   AXNameFromUninitialized = -1,
321   AXNameFromAttribute = 0,
322   AXNameFromCaption,
323   AXNameFromContents,
324   AXNameFromPlaceholder,
325   AXNameFromRelatedElement,
326   AXNameFromValue,
327   AXNameFromTitle,
328 };
329
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,
342 };
343
344 // The source of the accessible description of an element. This is needed
345 // because on some platforms this determines how the accessible description
346 // is exposed.
347 enum AXDescriptionFrom {
348   AXDescriptionFromUninitialized = -1,
349   AXDescriptionFromAttribute = 0,
350   AXDescriptionFromContents,
351   AXDescriptionFromPlaceholder,
352   AXDescriptionFromRelatedElement,
353 };
354
355 enum AXIgnoredReason {
356   AXActiveModalDialog,
357   AXAncestorDisallowsChild,
358   AXAncestorIsLeafNode,
359   AXAriaHidden,
360   AXAriaHiddenRoot,
361   AXEmptyAlt,
362   AXEmptyText,
363   AXInert,
364   AXInheritsPresentation,
365   AXLabelContainer,
366   AXLabelFor,
367   AXNotRendered,
368   AXNotVisible,
369   AXPresentationalRole,
370   AXProbablyPresentational,
371   AXStaticTextUsedAsNameFor,
372   AXUninteresting
373 };
374
375 class IgnoredReason {
376   DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
377
378  public:
379   AXIgnoredReason reason;
380   Member<const AXObject> relatedObject;
381
382   explicit IgnoredReason(AXIgnoredReason reason)
383       : reason(reason), relatedObject(nullptr) {}
384
385   IgnoredReason(AXIgnoredReason r, const AXObject* obj)
386       : reason(r), relatedObject(obj) {}
387
388   DEFINE_INLINE_TRACE() { visitor->trace(relatedObject); }
389 };
390
391 class NameSourceRelatedObject
392     : public GarbageCollectedFinalized<NameSourceRelatedObject> {
393   WTF_MAKE_NONCOPYABLE(NameSourceRelatedObject);
394
395  public:
396   WeakMember<AXObject> object;
397   String text;
398
399   NameSourceRelatedObject(AXObject* object, String text)
400       : object(object), text(text) {}
401
402   DEFINE_INLINE_TRACE() { visitor->trace(object); }
403 };
404
405 typedef HeapVector<Member<NameSourceRelatedObject>> AXRelatedObjectVector;
406 class NameSource {
407   DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
408
409  public:
410   String text;
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;
418
419   NameSource(bool superseded, const QualifiedName& attr)
420       : superseded(superseded), attribute(attr) {}
421
422   explicit NameSource(bool superseded)
423       : superseded(superseded), attribute(QualifiedName::null()) {}
424
425   DEFINE_INLINE_TRACE() { visitor->trace(relatedObjects); }
426 };
427
428 class DescriptionSource {
429   DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
430
431  public:
432   String text;
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;
440
441   DescriptionSource(bool superseded, const QualifiedName& attr)
442       : superseded(superseded), attribute(attr) {}
443
444   explicit DescriptionSource(bool superseded)
445       : superseded(superseded), attribute(QualifiedName::null()) {}
446
447   DEFINE_INLINE_TRACE() { visitor->trace(relatedObjects); }
448 };
449
450 }  // namespace blink
451
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);
455
456 namespace blink {
457
458 class MODULES_EXPORT AXObject : public GarbageCollectedFinalized<AXObject> {
459   WTF_MAKE_NONCOPYABLE(AXObject);
460
461  public:
462   typedef HeapVector<Member<AXObject>> AXObjectVector;
463
464   struct AXRange {
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.
471     int anchorOffset;
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;
476
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.
482     int focusOffset;
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;
487
488     AXRange()
489         : anchorObject(nullptr),
490           anchorOffset(-1),
491           anchorAffinity(TextAffinity::Upstream),
492           focusObject(nullptr),
493           focusOffset(-1),
494           focusAffinity(TextAffinity::Downstream) {}
495
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) {}
503
504     AXRange(AXObject* anchorObject,
505             int anchorOffset,
506             TextAffinity anchorAffinity,
507             AXObject* focusObject,
508             int focusOffset,
509             TextAffinity focusAffinity)
510         : anchorObject(anchorObject),
511           anchorOffset(anchorOffset),
512           anchorAffinity(anchorAffinity),
513           focusObject(focusObject),
514           focusOffset(focusOffset),
515           focusAffinity(focusAffinity) {}
516
517     bool isValid() const {
518       return ((anchorObject && focusObject) ||
519               (!anchorObject && !focusObject)) &&
520              anchorOffset >= 0 && focusOffset >= 0;
521     }
522
523     // Determines if the range only refers to text offsets under the current
524     // object.
525     bool isSimple() const {
526       return anchorObject == focusObject || !anchorObject || !focusObject;
527     }
528   };
529
530  protected:
531   AXObject(AXObjectCacheImpl&);
532
533  public:
534   virtual ~AXObject();
535   DECLARE_VIRTUAL_TRACE();
536
537   static unsigned numberOfLiveAXObjects() { return s_numberOfLiveAXObjects; }
538
539   // After constructing an AXObject, it must be given a
540   // unique ID, then added to AXObjectCacheImpl, and finally init() must
541   // be called last.
542   void setAXObjectID(AXID axObjectID) { m_id = axObjectID; }
543   virtual void init() {}
544
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;
549
550   // If the parent of this object is known, this can be faster than using
551   // computeParent().
552   virtual void setParent(AXObject* parent) { m_parent = parent; }
553
554   // The AXObjectCacheImpl that owns this object, and its unique ID within this
555   // cache.
556   AXObjectCacheImpl& axObjectCache() const {
557     ASSERT(m_axObjectCache);
558     return *m_axObjectCache;
559   }
560
561   AXID axObjectID() const { return m_id; }
562
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; }
570
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 {
604     return false;
605   }  // input or textarea
606   virtual bool isNonNativeTextControl() const {
607     return false;
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;
613   }
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;
620   }
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; }
633
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; }
653
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; }
658
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 {
663     return true;
664   }
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;
682
683   //
684   // Accessible name calculation
685   //
686
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
689   // name, if any.
690   virtual String name(AXNameFrom&, AXObjectVector* nameObjects) const;
691
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;
696
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,
703                              AXDescriptionFrom&,
704                              AXObjectVector* descriptionObjects) const {
705     return String();
706   }
707
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,
711                              AXDescriptionFrom&,
712                              DescriptionSources*,
713                              AXRelatedObjectVector*) const {
714     return String();
715   }
716
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 {
721     return String();
722   }
723
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 {
732     return String();
733   }
734   virtual String textFromDescendants(AXObjectSet& visited,
735                                      bool recursive) const {
736     return String();
737   }
738
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;
742
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; }
749
750   //
751   // Properties of static elements.
752   //
753
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;
772   }
773   virtual int textLength() const { return 0; }
774   virtual TextStyle getTextStyle() const { return TextStyleNone; }
775   virtual KURL url() const { return KURL(); }
776
777   // Load inline text boxes for just this node, even if
778   // settings->inlineTextBoxAccessibilityEnabled() is false.
779   virtual void loadInlineTextBoxes() {}
780
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; }
785
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 {}
796
797   // Properties of interactive elements.
798   String actionVerb() const;
799   virtual AccessibilityButtonState checkboxOrRadioValue() const;
800   virtual AriaCurrentState ariaCurrentState() const {
801     return AriaCurrentStateUndefined;
802   }
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(); }
811
812   // ARIA attributes.
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 {
828     return 0;
829   }
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;
839   }
840
841   // Returns 0-based index.
842   int indexInParent() const;
843
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;
848
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; }
856
857   const AtomicString& containerLiveRegionStatus() const;
858   const AtomicString& containerLiveRegionRelevant() const;
859   bool containerLiveRegionAtomic() const;
860   bool containerLiveRegionBusy() const;
861
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;
873
874   // Get the bounds in frame-relative coordinates as a LayoutRect.
875   LayoutRect getBoundsInFrameCoordinates() const;
876
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();
881   }
882
883   // Hit testing.
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
887   // AXLayoutObject.
888   virtual AXObject* elementAccessibilityHitTest(const IntPoint&) const;
889
890   // High-level accessibility tree access. Other modules should only use these
891   // functions.
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;
899
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; }
913
914   // Properties of the object's owning document or page.
915   virtual double estimatedLoadingProgress() const { return 0; }
916
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;
927
928   // Methods that retrieve or manipulate the current selection.
929
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&) {}
937
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;
944
945   // If this object itself scrolls, return its ScrollableArea.
946   virtual ScrollableArea* getScrollableAreaIfScrollable() const { return 0; }
947
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
954   // needed.
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
960   // window.
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) {}
967
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() {}
976
977   // Text metrics. Most of these should be deprecated, needs major cleanup.
978   virtual VisiblePosition visiblePositionForIndex(int) const {
979     return VisiblePosition();
980   }
981   int lineForPosition(const VisiblePosition&) const;
982   virtual int index(const VisiblePosition&) const { return -1; }
983   virtual void lineBreaks(Vector<int>&) const {}
984
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&);
992
993  protected:
994   AXID m_id;
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;
1001
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,
1011                              AXNameFrom&,
1012                              AXRelatedObjectVector*,
1013                              NameSources*,
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;
1026
1027   virtual const AXObject* inheritsPresentationalRoleFrom() const { return 0; }
1028
1029   virtual bool nameFromContents() const;
1030
1031   AccessibilityRole buttonRoleType() const;
1032
1033   virtual LayoutObject* layoutObjectForRelativeBounds() const {
1034     return nullptr;
1035   }
1036
1037   mutable Member<AXObject> m_parent;
1038
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;
1052
1053   Member<AXObjectCacheImpl> m_axObjectCache;
1054
1055   // Updates the cached attribute values. This may be recursive, so to prevent
1056   // deadlocks,
1057   // functions called here may only search up the tree (ancestors), not down.
1058   void updateCachedAttributeValuesIfNeeded() const;
1059
1060  private:
1061   static bool includesARIAWidgetRole(const String&);
1062   static bool hasInteractiveARIAAttribute(const Element&);
1063
1064   static unsigned s_numberOfLiveAXObjects;
1065 };
1066
1067 #define DEFINE_AX_OBJECT_TYPE_CASTS(thisType, predicate)           \
1068   DEFINE_TYPE_CASTS(thisType, AXObject, object, object->predicate, \
1069                     object.predicate)
1070
1071 }  // namespace blink
1072
1073 #endif  // AXObject_h