Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: third_party/WebKit/Source/modules/accessibility/AXObject.h

Issue 2858493002: Rename AXObject to AXObjectImpl in modules/ and web/ (Closed)
Patch Set: Review feedback Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 "platform/wtf/Forward.h"
41 #include "platform/wtf/Vector.h"
42
43 class SkMatrix44;
44
45 namespace blink {
46
47 class AXObject;
48 class AXObjectCacheImpl;
49 class Element;
50 class FrameView;
51 class IntPoint;
52 class Node;
53 class LayoutObject;
54 class ScrollableArea;
55
56 enum class AOMStringProperty;
57
58 typedef unsigned AXID;
59
60 enum AccessibilityRole {
61 kUnknownRole = 0,
62 kAbbrRole, // No mapping to ARIA role.
63 kAlertDialogRole,
64 kAlertRole,
65 kAnchorRole, // No mapping to ARIA role.
66 kAnnotationRole, // No mapping to ARIA role.
67 kApplicationRole,
68 kArticleRole,
69 kAudioRole, // No mapping to ARIA role.
70 kBannerRole,
71 kBlockquoteRole, // No mapping to ARIA role.
72 kBusyIndicatorRole, // No mapping to ARIA role.
73 kButtonRole,
74 kCanvasRole, // No mapping to ARIA role.
75 kCaptionRole, // No mapping to ARIA role.
76 kCellRole,
77 kCheckBoxRole,
78 kColorWellRole, // No mapping to ARIA role.
79 kColumnHeaderRole,
80 kColumnRole, // No mapping to ARIA role.
81 kComboBoxRole,
82 kComplementaryRole,
83 kContentInfoRole,
84 kDateRole, // No mapping to ARIA role.
85 kDateTimeRole, // No mapping to ARIA role.
86 kDefinitionRole,
87 kDescriptionListDetailRole, // No mapping to ARIA role.
88 kDescriptionListRole, // No mapping to ARIA role.
89 kDescriptionListTermRole, // No mapping to ARIA role.
90 kDetailsRole, // No mapping to ARIA role.
91 kDialogRole,
92 kDirectoryRole,
93 kDisclosureTriangleRole, // No mapping to ARIA role.
94 kDivRole, // No mapping to ARIA role.
95 kDocumentRole,
96 kEmbeddedObjectRole, // No mapping to ARIA role.
97 kFeedRole,
98 kFigcaptionRole, // No mapping to ARIA role.
99 kFigureRole,
100 kFooterRole,
101 kFormRole,
102 kGridRole,
103 kGroupRole,
104 kHeadingRole,
105 kIframePresentationalRole, // No mapping to ARIA role.
106 kIframeRole, // No mapping to ARIA role.
107 kIgnoredRole, // No mapping to ARIA role.
108 kImageMapLinkRole, // No mapping to ARIA role.
109 kImageMapRole, // No mapping to ARIA role.
110 kImageRole,
111 kInlineTextBoxRole, // No mapping to ARIA role.
112 kInputTimeRole, // No mapping to ARIA role.
113 kLabelRole,
114 kLegendRole, // No mapping to ARIA role.
115 kLineBreakRole, // No mapping to ARIA role.
116 kLinkRole,
117 kListBoxOptionRole,
118 kListBoxRole,
119 kListItemRole,
120 kListMarkerRole, // No mapping to ARIA role.
121 kListRole,
122 kLogRole,
123 kMainRole,
124 kMarkRole, // No mapping to ARIA role.
125 kMarqueeRole,
126 kMathRole,
127 kMenuBarRole,
128 kMenuButtonRole,
129 kMenuItemRole,
130 kMenuItemCheckBoxRole,
131 kMenuItemRadioRole,
132 kMenuListOptionRole,
133 kMenuListPopupRole,
134 kMenuRole,
135 kMeterRole,
136 kNavigationRole,
137 kNoneRole, // No mapping to ARIA role.
138 kNoteRole,
139 kOutlineRole, // No mapping to ARIA role.
140 kParagraphRole, // No mapping to ARIA role.
141 kPopUpButtonRole,
142 kPreRole, // No mapping to ARIA role.
143 kPresentationalRole,
144 kProgressIndicatorRole,
145 kRadioButtonRole,
146 kRadioGroupRole,
147 kRegionRole,
148 kRootWebAreaRole, // No mapping to ARIA role.
149 kRowHeaderRole,
150 kRowRole,
151 kRubyRole, // No mapping to ARIA role.
152 kRulerRole, // No mapping to ARIA role.
153 kSVGRootRole, // No mapping to ARIA role.
154 kScrollAreaRole, // No mapping to ARIA role.
155 kScrollBarRole,
156 kSeamlessWebAreaRole, // No mapping to ARIA role.
157 kSearchRole,
158 kSearchBoxRole,
159 kSliderRole,
160 kSliderThumbRole, // No mapping to ARIA role.
161 kSpinButtonPartRole, // No mapping to ARIA role.
162 kSpinButtonRole,
163 kSplitterRole,
164 kStaticTextRole, // No mapping to ARIA role.
165 kStatusRole,
166 kSwitchRole,
167 kTabGroupRole, // No mapping to ARIA role.
168 kTabListRole,
169 kTabPanelRole,
170 kTabRole,
171 kTableHeaderContainerRole, // No mapping to ARIA role.
172 kTableRole,
173 kTermRole,
174 kTextFieldRole,
175 kTimeRole, // No mapping to ARIA role.
176 kTimerRole,
177 kToggleButtonRole,
178 kToolbarRole,
179 kTreeGridRole,
180 kTreeItemRole,
181 kTreeRole,
182 kUserInterfaceTooltipRole,
183 kVideoRole, // No mapping to ARIA role.
184 kWebAreaRole, // No mapping to ARIA role.
185 kWindowRole, // No mapping to ARIA role.
186 kNumRoles
187 };
188
189 enum AccessibilityTextSource {
190 kAlternativeText,
191 kChildrenText,
192 kSummaryText,
193 kHelpText,
194 kVisibleText,
195 kTitleTagText,
196 kPlaceholderText,
197 kLabelByElementText,
198 };
199
200 enum AccessibilityState {
201 kAXBusyState,
202 kAXCheckedState,
203 kAXEnabledState,
204 kAXExpandedState,
205 kAXFocusableState,
206 kAXFocusedState,
207 kAXHaspopupState,
208 kAXHoveredState,
209 kAXInvisibleState,
210 kAXLinkedState,
211 kAXMultilineState,
212 kAXMultiselectableState,
213 kAXOffscreenState,
214 kAXPressedState,
215 kAXProtectedState,
216 kAXReadonlyState,
217 kAXRequiredState,
218 kAXSelectableState,
219 kAXSelectedState,
220 kAXVerticalState,
221 kAXVisitedState
222 };
223
224 class AccessibilityText final
225 : public GarbageCollectedFinalized<AccessibilityText> {
226 WTF_MAKE_NONCOPYABLE(AccessibilityText);
227
228 public:
229 DEFINE_INLINE_TRACE() { visitor->Trace(text_element_); }
230
231 private:
232 AccessibilityText(const String& text,
233 const AccessibilityTextSource& source,
234 AXObject* element)
235 : text_(text), text_element_(element) {}
236
237 String text_;
238 Member<AXObject> text_element_;
239 };
240
241 enum AccessibilityOrientation {
242 kAccessibilityOrientationUndefined = 0,
243 kAccessibilityOrientationVertical,
244 kAccessibilityOrientationHorizontal,
245 };
246
247 enum AXObjectInclusion {
248 kIncludeObject,
249 kIgnoreObject,
250 kDefaultBehavior,
251 };
252
253 enum class AXSupportedAction {
254 kNone = 0,
255 kActivate,
256 kCheck,
257 kClick,
258 kJump,
259 kOpen,
260 kPress,
261 kSelect,
262 kUncheck
263 };
264
265 enum AccessibilityButtonState {
266 kButtonStateOff = 0,
267 kButtonStateOn,
268 kButtonStateMixed,
269 };
270
271 enum AccessibilityTextDirection {
272 kAccessibilityTextDirectionLTR,
273 kAccessibilityTextDirectionRTL,
274 kAccessibilityTextDirectionTTB,
275 kAccessibilityTextDirectionBTT
276 };
277
278 enum SortDirection {
279 kSortDirectionUndefined = 0,
280 kSortDirectionNone,
281 kSortDirectionAscending,
282 kSortDirectionDescending,
283 kSortDirectionOther
284 };
285
286 enum AccessibilityExpanded {
287 kExpandedUndefined = 0,
288 kExpandedCollapsed,
289 kExpandedExpanded,
290 };
291
292 enum AccessibilityOptionalBool {
293 kOptionalBoolUndefined = 0,
294 kOptionalBoolTrue,
295 kOptionalBoolFalse
296 };
297
298 enum AriaCurrentState {
299 kAriaCurrentStateUndefined = 0,
300 kAriaCurrentStateFalse,
301 kAriaCurrentStateTrue,
302 kAriaCurrentStatePage,
303 kAriaCurrentStateStep,
304 kAriaCurrentStateLocation,
305 kAriaCurrentStateDate,
306 kAriaCurrentStateTime
307 };
308
309 enum InvalidState {
310 kInvalidStateUndefined = 0,
311 kInvalidStateFalse,
312 kInvalidStateTrue,
313 kInvalidStateSpelling,
314 kInvalidStateGrammar,
315 kInvalidStateOther
316 };
317
318 enum TextStyle {
319 kTextStyleNone = 0,
320 kTextStyleBold = 1 << 0,
321 kTextStyleItalic = 1 << 1,
322 kTextStyleUnderline = 1 << 2,
323 kTextStyleLineThrough = 1 << 3
324 };
325
326 enum TextUnderElementMode {
327 kTextUnderElementAll,
328 kTextUnderElementAny // If the text is unimportant, just whether or not it's
329 // present
330 };
331
332 enum class AXBoolAttribute {};
333
334 enum class AXStringAttribute {
335 kAriaKeyShortcuts,
336 kAriaRoleDescription,
337 };
338
339 enum class AXObjectAttribute {
340 kAriaActiveDescendant,
341 kAriaErrorMessage,
342 };
343
344 enum class AXObjectVectorAttribute {
345 kAriaControls,
346 kAriaDetails,
347 kAriaFlowTo,
348 };
349
350 class AXSparseAttributeClient {
351 public:
352 virtual void AddBoolAttribute(AXBoolAttribute, bool) = 0;
353 virtual void AddStringAttribute(AXStringAttribute, const String&) = 0;
354 virtual void AddObjectAttribute(AXObjectAttribute, AXObject&) = 0;
355 virtual void AddObjectVectorAttribute(AXObjectVectorAttribute,
356 HeapVector<Member<AXObject>>&) = 0;
357 };
358
359 // The source of the accessible name of an element. This is needed
360 // because on some platforms this determines how the accessible name
361 // is exposed.
362 enum AXNameFrom {
363 kAXNameFromUninitialized = -1,
364 kAXNameFromAttribute = 0,
365 kAXNameFromAttributeExplicitlyEmpty,
366 kAXNameFromCaption,
367 kAXNameFromContents,
368 kAXNameFromPlaceholder,
369 kAXNameFromRelatedElement,
370 kAXNameFromValue,
371 kAXNameFromTitle,
372 };
373
374 // The potential native HTML-based text (name, description or placeholder)
375 // sources for an element. See
376 // http://rawgit.com/w3c/aria/master/html-aam/html-aam.html#accessible-name-and- description-calculation
377 enum AXTextFromNativeHTML {
378 kAXTextFromNativeHTMLUninitialized = -1,
379 kAXTextFromNativeHTMLFigcaption,
380 kAXTextFromNativeHTMLLabel,
381 kAXTextFromNativeHTMLLabelFor,
382 kAXTextFromNativeHTMLLabelWrapped,
383 kAXTextFromNativeHTMLLegend,
384 kAXTextFromNativeHTMLTableCaption,
385 kAXTextFromNativeHTMLTitleElement,
386 };
387
388 // The source of the accessible description of an element. This is needed
389 // because on some platforms this determines how the accessible description
390 // is exposed.
391 enum AXDescriptionFrom {
392 kAXDescriptionFromUninitialized = -1,
393 kAXDescriptionFromAttribute = 0,
394 kAXDescriptionFromContents,
395 kAXDescriptionFromRelatedElement,
396 };
397
398 enum AXIgnoredReason {
399 kAXActiveModalDialog,
400 kAXAncestorDisallowsChild,
401 kAXAncestorIsLeafNode,
402 kAXAriaHidden,
403 kAXAriaHiddenRoot,
404 kAXEmptyAlt,
405 kAXEmptyText,
406 kAXInert,
407 kAXInheritsPresentation,
408 kAXLabelContainer,
409 kAXLabelFor,
410 kAXNotRendered,
411 kAXNotVisible,
412 kAXPresentationalRole,
413 kAXProbablyPresentational,
414 kAXStaticTextUsedAsNameFor,
415 kAXUninteresting
416 };
417
418 class IgnoredReason {
419 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
420
421 public:
422 AXIgnoredReason reason;
423 Member<const AXObject> related_object;
424
425 explicit IgnoredReason(AXIgnoredReason reason)
426 : reason(reason), related_object(nullptr) {}
427
428 IgnoredReason(AXIgnoredReason r, const AXObject* obj)
429 : reason(r), related_object(obj) {}
430
431 DEFINE_INLINE_TRACE() { visitor->Trace(related_object); }
432 };
433
434 class NameSourceRelatedObject
435 : public GarbageCollectedFinalized<NameSourceRelatedObject> {
436 WTF_MAKE_NONCOPYABLE(NameSourceRelatedObject);
437
438 public:
439 WeakMember<AXObject> object;
440 String text;
441
442 NameSourceRelatedObject(AXObject* object, String text)
443 : object(object), text(text) {}
444
445 DEFINE_INLINE_TRACE() { visitor->Trace(object); }
446 };
447
448 typedef HeapVector<Member<NameSourceRelatedObject>> AXRelatedObjectVector;
449 class NameSource {
450 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
451
452 public:
453 String text;
454 bool superseded = false;
455 bool invalid = false;
456 AXNameFrom type = kAXNameFromUninitialized;
457 const QualifiedName& attribute;
458 AtomicString attribute_value;
459 AXTextFromNativeHTML native_source = kAXTextFromNativeHTMLUninitialized;
460 AXRelatedObjectVector related_objects;
461
462 NameSource(bool superseded, const QualifiedName& attr)
463 : superseded(superseded), attribute(attr) {}
464
465 explicit NameSource(bool superseded)
466 : superseded(superseded), attribute(QualifiedName::Null()) {}
467
468 DEFINE_INLINE_TRACE() { visitor->Trace(related_objects); }
469 };
470
471 class DescriptionSource {
472 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
473
474 public:
475 String text;
476 bool superseded = false;
477 bool invalid = false;
478 AXDescriptionFrom type = kAXDescriptionFromUninitialized;
479 const QualifiedName& attribute;
480 AtomicString attribute_value;
481 AXTextFromNativeHTML native_source = kAXTextFromNativeHTMLUninitialized;
482 AXRelatedObjectVector related_objects;
483
484 DescriptionSource(bool superseded, const QualifiedName& attr)
485 : superseded(superseded), attribute(attr) {}
486
487 explicit DescriptionSource(bool superseded)
488 : superseded(superseded), attribute(QualifiedName::Null()) {}
489
490 DEFINE_INLINE_TRACE() { visitor->Trace(related_objects); }
491 };
492
493 } // namespace blink
494
495 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::IgnoredReason);
496 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::NameSource);
497 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::DescriptionSource);
498
499 namespace blink {
500
501 class MODULES_EXPORT AXObject : public GarbageCollectedFinalized<AXObject> {
502 WTF_MAKE_NONCOPYABLE(AXObject);
503
504 public:
505 typedef HeapVector<Member<AXObject>> AXObjectVector;
506
507 struct AXRange {
508 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
509 // The deepest descendant in which the range starts.
510 // (nullptr means the current object.)
511 Persistent<AXObject> anchor_object;
512 // The number of characters and child objects in the anchor object
513 // before the range starts.
514 int anchor_offset;
515 // When the same character offset could correspond to two possible
516 // cursor positions, upstream means it's on the previous line rather
517 // than the next line.
518 TextAffinity anchor_affinity;
519
520 // The deepest descendant in which the range ends.
521 // (nullptr means the current object.)
522 Persistent<AXObject> focus_object;
523 // The number of characters and child objects in the focus object
524 // before the range ends.
525 int focus_offset;
526 // When the same character offset could correspond to two possible
527 // cursor positions, upstream means it's on the previous line rather
528 // than the next line.
529 TextAffinity focus_affinity;
530
531 AXRange()
532 : anchor_object(nullptr),
533 anchor_offset(-1),
534 anchor_affinity(TextAffinity::kUpstream),
535 focus_object(nullptr),
536 focus_offset(-1),
537 focus_affinity(TextAffinity::kDownstream) {}
538
539 AXRange(int start_offset, int end_offset)
540 : anchor_object(nullptr),
541 anchor_offset(start_offset),
542 anchor_affinity(TextAffinity::kUpstream),
543 focus_object(nullptr),
544 focus_offset(end_offset),
545 focus_affinity(TextAffinity::kDownstream) {}
546
547 AXRange(AXObject* anchor_object,
548 int anchor_offset,
549 TextAffinity anchor_affinity,
550 AXObject* focus_object,
551 int focus_offset,
552 TextAffinity focus_affinity)
553 : anchor_object(anchor_object),
554 anchor_offset(anchor_offset),
555 anchor_affinity(anchor_affinity),
556 focus_object(focus_object),
557 focus_offset(focus_offset),
558 focus_affinity(focus_affinity) {}
559
560 bool IsValid() const {
561 return ((anchor_object && focus_object) ||
562 (!anchor_object && !focus_object)) &&
563 anchor_offset >= 0 && focus_offset >= 0;
564 }
565
566 // Determines if the range only refers to text offsets under the current
567 // object.
568 bool IsSimple() const {
569 return anchor_object == focus_object || !anchor_object || !focus_object;
570 }
571 };
572
573 protected:
574 AXObject(AXObjectCacheImpl&);
575
576 public:
577 virtual ~AXObject();
578 DECLARE_VIRTUAL_TRACE();
579
580 static unsigned NumberOfLiveAXObjects() { return number_of_live_ax_objects_; }
581
582 // After constructing an AXObject, it must be given a
583 // unique ID, then added to AXObjectCacheImpl, and finally init() must
584 // be called last.
585 void SetAXObjectID(AXID ax_object_id) { id_ = ax_object_id; }
586 virtual void Init() {}
587
588 // When the corresponding WebCore object that this AXObject
589 // wraps is deleted, it must be detached.
590 virtual void Detach();
591 virtual bool IsDetached() const;
592
593 // If the parent of this object is known, this can be faster than using
594 // computeParent().
595 virtual void SetParent(AXObject* parent) { parent_ = parent; }
596
597 // The AXObjectCacheImpl that owns this object, and its unique ID within this
598 // cache.
599 AXObjectCacheImpl& AxObjectCache() const {
600 DCHECK(ax_object_cache_);
601 return *ax_object_cache_;
602 }
603
604 AXID AxObjectID() const { return id_; }
605
606 // Wrappers that retrieve either an Accessibility Object Model property,
607 // or the equivalent ARIA attribute, in that order.
608 // TODO(dmazzoni): Add equivalents for other types of properties besides
609 // just strings.
610 const AtomicString& GetAOMPropertyOrARIAAttribute(AOMStringProperty) const;
611
612 virtual void GetSparseAXAttributes(AXSparseAttributeClient&) const {}
613
614 // Determine subclass type.
615 virtual bool IsAXNodeObject() const { return false; }
616 virtual bool IsAXLayoutObject() const { return false; }
617 virtual bool IsAXListBox() const { return false; }
618 virtual bool IsAXListBoxOption() const { return false; }
619 virtual bool IsAXRadioInput() const { return false; }
620 virtual bool IsAXSVGRoot() const { return false; }
621
622 // Check object role or purpose.
623 virtual AccessibilityRole RoleValue() const { return role_; }
624 bool IsARIATextControl() const;
625 virtual bool IsARIATreeGridRow() const { return false; }
626 virtual bool IsAXTable() const { return false; }
627 virtual bool IsAnchor() const { return false; }
628 bool IsButton() const;
629 bool IsCheckable() const;
630 bool IsCanvas() const { return RoleValue() == kCanvasRole; }
631 bool IsCheckbox() const { return RoleValue() == kCheckBoxRole; }
632 bool IsCheckboxOrRadio() const { return IsCheckbox() || IsRadioButton(); }
633 bool IsColorWell() const { return RoleValue() == kColorWellRole; }
634 bool IsComboBox() const { return RoleValue() == kComboBoxRole; }
635 virtual bool IsControl() const { return false; }
636 virtual bool IsDataTable() const { return false; }
637 virtual bool IsEmbeddedObject() const { return false; }
638 virtual bool IsFieldset() const { return false; }
639 virtual bool IsHeading() const { return false; }
640 virtual bool IsImage() const { return false; }
641 virtual bool IsImageMapLink() const { return false; }
642 virtual bool IsInputImage() const { return false; }
643 bool IsLandmarkRelated() const;
644 virtual bool IsLink() const { return false; }
645 virtual bool IsInPageLinkTarget() const { return false; }
646 virtual bool IsList() const { return false; }
647 virtual bool IsMenu() const { return false; }
648 virtual bool IsMenuButton() const { return false; }
649 virtual bool IsMenuList() const { return false; }
650 virtual bool IsMenuListOption() const { return false; }
651 virtual bool IsMenuListPopup() const { return false; }
652 bool IsMenuRelated() const;
653 virtual bool IsMeter() const { return false; }
654 virtual bool IsMockObject() const { return false; }
655 virtual bool IsNativeSpinButton() const { return false; }
656 virtual bool IsNativeTextControl() const {
657 return false;
658 } // input or textarea
659 virtual bool IsNonNativeTextControl() const {
660 return false;
661 } // contenteditable or role=textbox
662 virtual bool IsPasswordField() const { return false; }
663 virtual bool IsPasswordFieldAndShouldHideValue() const;
664 bool IsPresentational() const {
665 return RoleValue() == kNoneRole || RoleValue() == kPresentationalRole;
666 }
667 virtual bool IsProgressIndicator() const { return false; }
668 bool IsRadioButton() const { return RoleValue() == kRadioButtonRole; }
669 bool IsRange() const {
670 return RoleValue() == kProgressIndicatorRole ||
671 RoleValue() == kScrollBarRole || RoleValue() == kSliderRole ||
672 RoleValue() == kSpinButtonRole;
673 }
674 bool IsScrollbar() const { return RoleValue() == kScrollBarRole; }
675 virtual bool IsSlider() const { return false; }
676 virtual bool IsNativeSlider() const { return false; }
677 virtual bool IsSpinButton() const { return RoleValue() == kSpinButtonRole; }
678 virtual bool IsSpinButtonPart() const { return false; }
679 bool IsTabItem() const { return RoleValue() == kTabRole; }
680 virtual bool IsTableCell() const { return false; }
681 virtual bool IsTableRow() const { return false; }
682 virtual bool IsTextControl() const { return false; }
683 virtual bool IsTableCol() const { return false; }
684 bool IsTree() const { return RoleValue() == kTreeRole; }
685 bool IsWebArea() const { return RoleValue() == kWebAreaRole; }
686
687 // Check object state.
688 virtual bool IsClickable() const;
689 virtual bool IsCollapsed() const { return false; }
690 virtual bool IsEnabled() const { return false; }
691 virtual AccessibilityExpanded IsExpanded() const {
692 return kExpandedUndefined;
693 }
694 virtual bool IsFocused() const { return false; }
695 virtual bool IsHovered() const { return false; }
696 virtual bool IsLinked() const { return false; }
697 virtual bool IsLoaded() const { return false; }
698 virtual bool IsModal() const { return false; }
699 virtual bool IsMultiSelectable() const { return false; }
700 virtual bool IsOffScreen() const { return false; }
701 virtual bool IsPressed() const { return false; }
702 virtual bool IsReadOnly() const { return false; }
703 virtual bool IsRequired() const { return false; }
704 virtual bool IsSelected() const { return false; }
705 virtual bool IsSelectedOptionActive() const { return false; }
706 virtual bool IsVisible() const { return true; }
707 virtual bool IsVisited() const { return false; }
708
709 // Check whether certain properties can be modified.
710 virtual bool CanSetFocusAttribute() const { return false; }
711 virtual bool CanSetValueAttribute() const { return false; }
712 virtual bool CanSetSelectedAttribute() const { return false; }
713
714 // Whether objects are ignored, i.e. not included in the tree.
715 bool AccessibilityIsIgnored() const;
716 typedef HeapVector<IgnoredReason> IgnoredReasons;
717 virtual bool ComputeAccessibilityIsIgnored(IgnoredReasons* = nullptr) const {
718 return true;
719 }
720 bool AccessibilityIsIgnoredByDefault(IgnoredReasons* = nullptr) const;
721 AXObjectInclusion AccessibilityPlatformIncludesObject() const;
722 virtual AXObjectInclusion DefaultObjectInclusion(
723 IgnoredReasons* = nullptr) const;
724 bool IsInertOrAriaHidden() const;
725 const AXObject* AriaHiddenRoot() const;
726 bool ComputeIsInertOrAriaHidden(IgnoredReasons* = nullptr) const;
727 bool IsDescendantOfLeafNode() const;
728 AXObject* LeafNodeAncestor() const;
729 bool IsDescendantOfDisabledNode() const;
730 const AXObject* DisabledAncestor() const;
731 bool LastKnownIsIgnoredValue();
732 void SetLastKnownIsIgnoredValue(bool);
733 bool HasInheritedPresentationalRole() const;
734 bool IsPresentationalChild() const;
735 bool AncestorExposesActiveDescendant() const;
736 bool ComputeAncestorExposesActiveDescendant() const;
737
738 //
739 // Accessible name calculation
740 //
741
742 // Retrieves the accessible name of the object, an enum indicating where the
743 // name was derived from, and a list of objects that were used to derive the
744 // name, if any.
745 virtual String GetName(AXNameFrom&, AXObjectVector* name_objects) const;
746
747 typedef HeapVector<NameSource> NameSources;
748 // Retrieves the accessible name of the object and a list of all potential
749 // sources for the name, indicating which were used.
750 virtual String GetName(NameSources*) const;
751
752 typedef HeapVector<DescriptionSource> DescriptionSources;
753 // Takes the result of nameFrom from calling |name|, above, and retrieves the
754 // accessible description of the object, which is secondary to |name|, an enum
755 // indicating where the description was derived from, and a list of objects
756 // that were used to derive the description, if any.
757 virtual String Description(AXNameFrom,
758 AXDescriptionFrom&,
759 AXObjectVector* description_objects) const {
760 return String();
761 }
762
763 // Same as above, but returns a list of all potential sources for the
764 // description, indicating which were used.
765 virtual String Description(AXNameFrom,
766 AXDescriptionFrom&,
767 DescriptionSources*,
768 AXRelatedObjectVector*) const {
769 return String();
770 }
771
772 // Takes the result of nameFrom and descriptionFrom from calling |name| and
773 // |description|, above, and retrieves the placeholder of the object, if
774 // present and if it wasn't already exposed by one of the two functions above.
775 virtual String Placeholder(AXNameFrom) const { return String(); }
776
777 // Internal functions used by name and description, above.
778 typedef HeapHashSet<Member<const AXObject>> AXObjectSet;
779 virtual String TextAlternative(bool recursive,
780 bool in_aria_labelled_by_traversal,
781 AXObjectSet& visited,
782 AXNameFrom& name_from,
783 AXRelatedObjectVector* related_objects,
784 NameSources* name_sources) const {
785 return String();
786 }
787 virtual String TextFromDescendants(AXObjectSet& visited,
788 bool recursive) const {
789 return String();
790 }
791
792 // Returns result of Accessible Name Calculation algorithm.
793 // This is a simpler high-level interface to |name| used by Inspector.
794 String ComputedName() const;
795
796 // Internal function used to determine whether the result of calling |name| on
797 // this object would return text that came from the an HTML label element or
798 // not. This is intended to be faster than calling |name| or
799 // |textAlternative|, and without side effects (it won't call
800 // axObjectCache->getOrCreate).
801 virtual bool NameFromLabelElement() const { return false; }
802
803 //
804 // Properties of static elements.
805 //
806
807 virtual const AtomicString& AccessKey() const { return g_null_atom; }
808 RGBA32 BackgroundColor() const;
809 virtual RGBA32 ComputeBackgroundColor() const { return Color::kTransparent; }
810 virtual RGBA32 GetColor() const { return Color::kBlack; }
811 // Used by objects of role ColorWellRole.
812 virtual RGBA32 ColorValue() const { return Color::kTransparent; }
813 virtual bool CanvasHasFallbackContent() const { return false; }
814 virtual String FontFamily() const { return g_null_atom; }
815 // Font size is in pixels.
816 virtual float FontSize() const { return 0.0f; }
817 // Value should be 1-based. 0 means not supported.
818 virtual int HeadingLevel() const { return 0; }
819 // Value should be 1-based. 0 means not supported.
820 virtual unsigned HierarchicalLevel() const { return 0; }
821 // Return the content of an image or canvas as an image data url in
822 // PNG format. If |maxSize| is not empty and if the image is larger than
823 // those dimensions, the image will be resized proportionally first to fit.
824 virtual String ImageDataUrl(const IntSize& max_size) const {
825 return g_null_atom;
826 }
827 virtual AXObject* InPageLinkTarget() const { return nullptr; }
828 virtual AccessibilityOrientation Orientation() const;
829 virtual String GetText() const { return String(); }
830 virtual AccessibilityTextDirection GetTextDirection() const {
831 return kAccessibilityTextDirectionLTR;
832 }
833 virtual int TextLength() const { return 0; }
834 virtual TextStyle GetTextStyle() const { return kTextStyleNone; }
835 virtual AXObjectVector RadioButtonsInGroup() const {
836 return AXObjectVector();
837 }
838 virtual KURL Url() const { return KURL(); }
839
840 // Load inline text boxes for just this node, even if
841 // settings->inlineTextBoxAccessibilityEnabled() is false.
842 virtual void LoadInlineTextBoxes() {}
843
844 // Walk the AXObjects on the same line. This is supported on any
845 // object type but primarily intended to be used for inline text boxes.
846 virtual AXObject* NextOnLine() const { return nullptr; }
847 virtual AXObject* PreviousOnLine() const { return nullptr; }
848
849 // For all node objects. The start and end character offset of each
850 // marker, such as spelling or grammar error.
851 virtual void Markers(Vector<DocumentMarker::MarkerType>&,
852 Vector<AXRange>&) const {}
853 // For an inline text box.
854 // The integer horizontal pixel offset of each character in the string;
855 // negative values for RTL.
856 virtual void TextCharacterOffsets(Vector<int>&) const {}
857 // The start and end character offset of each word in the object's text.
858 virtual void GetWordBoundaries(Vector<AXRange>&) const {}
859
860 // Properties of interactive elements.
861 AXSupportedAction Action() const;
862 AccessibilityButtonState CheckedState() const;
863 virtual AriaCurrentState GetAriaCurrentState() const {
864 return kAriaCurrentStateUndefined;
865 }
866 virtual InvalidState GetInvalidState() const {
867 return kInvalidStateUndefined;
868 }
869 // Only used when invalidState() returns InvalidStateOther.
870 virtual String AriaInvalidValue() const { return String(); }
871 virtual String ValueDescription() const { return String(); }
872 virtual float ValueForRange() const { return 0.0f; }
873 virtual float MaxValueForRange() const { return 0.0f; }
874 virtual float MinValueForRange() const { return 0.0f; }
875 virtual String StringValue() const { return String(); }
876
877 // ARIA attributes.
878 virtual AXObject* ActiveDescendant() { return nullptr; }
879 virtual String AriaAutoComplete() const { return String(); }
880 virtual void AriaOwnsElements(AXObjectVector& owns) const {}
881 virtual void AriaDescribedbyElements(AXObjectVector&) const {}
882 virtual void AriaLabelledbyElements(AXObjectVector&) const {}
883 virtual bool AriaHasPopup() const { return false; }
884 virtual bool IsEditable() const { return false; }
885 bool IsMultiline() const;
886 virtual bool IsRichlyEditable() const { return false; }
887 bool AriaPressedIsPresent() const;
888 virtual AccessibilityRole AriaRoleAttribute() const { return kUnknownRole; }
889 virtual bool AriaRoleHasPresentationalChildren() const { return false; }
890 virtual AXObject* AncestorForWhichThisIsAPresentationalChild() const {
891 return 0;
892 }
893 bool SupportsActiveDescendant() const;
894 bool SupportsARIAAttributes() const;
895 virtual bool SupportsARIADragging() const { return false; }
896 virtual bool SupportsARIADropping() const { return false; }
897 virtual bool SupportsARIAFlowTo() const { return false; }
898 virtual bool SupportsARIAOwns() const { return false; }
899 bool SupportsRangeValue() const;
900 virtual SortDirection GetSortDirection() const {
901 return kSortDirectionUndefined;
902 }
903
904 // Returns 0-based index.
905 int IndexInParent() const;
906
907 // Value should be 1-based. 0 means not supported.
908 virtual int PosInSet() const { return 0; }
909 virtual int SetSize() const { return 0; }
910 bool SupportsSetSizeAndPosInSet() const;
911
912 // ARIA live-region features.
913 bool IsLiveRegion() const;
914 AXObject* LiveRegionRoot() const;
915 virtual const AtomicString& LiveRegionStatus() const { return g_null_atom; }
916 virtual const AtomicString& LiveRegionRelevant() const { return g_null_atom; }
917 virtual bool LiveRegionAtomic() const { return false; }
918 virtual bool LiveRegionBusy() const { return false; }
919
920 const AtomicString& ContainerLiveRegionStatus() const;
921 const AtomicString& ContainerLiveRegionRelevant() const;
922 bool ContainerLiveRegionAtomic() const;
923 bool ContainerLiveRegionBusy() const;
924
925 // Every object's bounding box is returned relative to a
926 // container object (which is guaranteed to be an ancestor) and
927 // optionally a transformation matrix that needs to be applied too.
928 // To compute the absolute bounding box of an element, start with its
929 // boundsInContainer and apply the transform. Then as long as its container is
930 // not null, walk up to its container and offset by the container's offset
931 // from origin, the container's scroll position if any, and apply the
932 // container's transform. Do this until you reach the root of the tree.
933 virtual void GetRelativeBounds(AXObject** out_container,
934 FloatRect& out_bounds_in_container,
935 SkMatrix44& out_container_transform) const;
936
937 // Get the bounds in frame-relative coordinates as a LayoutRect.
938 LayoutRect GetBoundsInFrameCoordinates() const;
939
940 // Explicitly set an object's bounding rect and offset container.
941 void SetElementRect(LayoutRect r, AXObject* container) {
942 explicit_element_rect_ = r;
943 explicit_container_id_ = container->AxObjectID();
944 }
945
946 // Hit testing.
947 // Called on the root AX object to return the deepest available element.
948 virtual AXObject* AccessibilityHitTest(const IntPoint&) const { return 0; }
949 // Called on the AX object after the layout tree determines which is the right
950 // AXLayoutObject.
951 virtual AXObject* ElementAccessibilityHitTest(const IntPoint&) const;
952
953 // High-level accessibility tree access. Other modules should only use these
954 // functions.
955 const AXObjectVector& Children();
956 AXObject* ParentObject() const;
957 AXObject* ParentObjectIfExists() const;
958 virtual AXObject* ComputeParent() const = 0;
959 virtual AXObject* ComputeParentIfExists() const { return 0; }
960 AXObject* CachedParentObject() const { return parent_; }
961 AXObject* ParentObjectUnignored() const;
962
963 // Low-level accessibility tree exploration, only for use within the
964 // accessibility module.
965 virtual AXObject* RawFirstChild() const { return 0; }
966 virtual AXObject* RawNextSibling() const { return 0; }
967 virtual void AddChildren() {}
968 virtual bool CanHaveChildren() const { return true; }
969 bool HasChildren() const { return have_children_; }
970 virtual void UpdateChildrenIfNecessary();
971 virtual bool NeedsToUpdateChildren() const { return false; }
972 virtual void SetNeedsToUpdateChildren() {}
973 virtual void ClearChildren();
974 virtual void DetachFromParent() { parent_ = 0; }
975 virtual AXObject* ScrollBar(AccessibilityOrientation) { return 0; }
976
977 // Properties of the object's owning document or page.
978 virtual double EstimatedLoadingProgress() const { return 0; }
979
980 // DOM and layout tree access.
981 virtual Node* GetNode() const { return 0; }
982 virtual LayoutObject* GetLayoutObject() const { return 0; }
983 virtual Document* GetDocument() const;
984 virtual FrameView* DocumentFrameView() const;
985 virtual Element* AnchorElement() const { return 0; }
986 virtual Element* ActionElement() const { return 0; }
987 String Language() const;
988 bool HasAttribute(const QualifiedName&) const;
989 const AtomicString& GetAttribute(const QualifiedName&) const;
990
991 // Methods that retrieve or manipulate the current selection.
992
993 // Get the current selection from anywhere in the accessibility tree.
994 virtual AXRange Selection() const { return AXRange(); }
995 // Gets only the start and end offsets of the selection computed using the
996 // current object as the starting point. Returns a null selection if there is
997 // no selection in the subtree rooted at this object.
998 virtual AXRange SelectionUnderObject() const { return AXRange(); }
999 virtual void SetSelection(const AXRange&) {}
1000
1001 // Scrollable containers.
1002 bool IsScrollableContainer() const;
1003 IntPoint GetScrollOffset() const;
1004 IntPoint MinimumScrollOffset() const;
1005 IntPoint MaximumScrollOffset() const;
1006 void SetScrollOffset(const IntPoint&) const;
1007
1008 // If this object itself scrolls, return its ScrollableArea.
1009 virtual ScrollableArea* GetScrollableAreaIfScrollable() const { return 0; }
1010
1011 // Modify or take an action on an object.
1012 virtual void Increment() {}
1013 virtual void Decrement() {}
1014 bool PerformDefaultAction() { return Press(); }
1015 virtual bool Press();
1016 // Make this object visible by scrolling as many nested scrollable views as
1017 // needed.
1018 void ScrollToMakeVisible() const;
1019 // Same, but if the whole object can't be made visible, try for this subrect,
1020 // in local coordinates.
1021 void ScrollToMakeVisibleWithSubFocus(const IntRect&) const;
1022 // Scroll this object to a given point in global coordinates of the top-level
1023 // window.
1024 void ScrollToGlobalPoint(const IntPoint&) const;
1025 virtual void SetFocused(bool) {}
1026 virtual void SetSelected(bool) {}
1027 virtual void SetSequentialFocusNavigationStartingPoint();
1028 virtual void SetValue(const String&) {}
1029 virtual void SetValue(float) {}
1030
1031 // Notifications that this object may have changed.
1032 virtual void ChildrenChanged() {}
1033 virtual void HandleActiveDescendantChanged() {}
1034 virtual void HandleAriaExpandedChanged() {}
1035 void NotifyIfIgnoredValueChanged();
1036 virtual void SelectionChanged();
1037 virtual void TextChanged() {}
1038 virtual void UpdateAccessibilityRole() {}
1039
1040 // Text metrics. Most of these should be deprecated, needs major cleanup.
1041 virtual VisiblePosition VisiblePositionForIndex(int) const {
1042 return VisiblePosition();
1043 }
1044 int LineForPosition(const VisiblePosition&) const;
1045 virtual int Index(const VisiblePosition&) const { return -1; }
1046 virtual void LineBreaks(Vector<int>&) const {}
1047
1048 // Static helper functions.
1049 static bool IsARIAControl(AccessibilityRole);
1050 static bool IsARIAInput(AccessibilityRole);
1051 static AccessibilityRole AriaRoleToWebCoreRole(const String&);
1052 static const AtomicString& RoleName(AccessibilityRole);
1053 static const AtomicString& InternalRoleName(AccessibilityRole);
1054 static bool IsInsideFocusableElementOrARIAWidget(const Node&);
1055
1056 protected:
1057 AXID id_;
1058 AXObjectVector children_;
1059 mutable bool have_children_;
1060 AccessibilityRole role_;
1061 AXObjectInclusion last_known_is_ignored_value_;
1062 LayoutRect explicit_element_rect_;
1063 AXID explicit_container_id_;
1064
1065 // Used only inside textAlternative():
1066 static String CollapseWhitespace(const String&);
1067 static String RecursiveTextAlternative(const AXObject&,
1068 bool in_aria_labelled_by_traversal,
1069 AXObjectSet& visited);
1070 bool IsHiddenForTextAlternativeCalculation() const;
1071 String AriaTextAlternative(bool recursive,
1072 bool in_aria_labelled_by_traversal,
1073 AXObjectSet& visited,
1074 AXNameFrom&,
1075 AXRelatedObjectVector*,
1076 NameSources*,
1077 bool* found_text_alternative) const;
1078 String TextFromElements(bool in_aria_labelled_by_traversal,
1079 AXObjectSet& visited,
1080 HeapVector<Member<Element>>& elements,
1081 AXRelatedObjectVector* related_objects) const;
1082 void TokenVectorFromAttribute(Vector<String>&, const QualifiedName&) const;
1083 void ElementsFromAttribute(HeapVector<Member<Element>>& elements,
1084 const QualifiedName&) const;
1085 void AriaLabelledbyElementVector(HeapVector<Member<Element>>& elements) const;
1086 String TextFromAriaLabelledby(AXObjectSet& visited,
1087 AXRelatedObjectVector* related_objects) const;
1088 String TextFromAriaDescribedby(AXRelatedObjectVector* related_objects) const;
1089
1090 virtual const AXObject* InheritsPresentationalRoleFrom() const { return 0; }
1091
1092 virtual bool NameFromContents() const;
1093
1094 AccessibilityRole ButtonRoleType() const;
1095
1096 virtual LayoutObject* LayoutObjectForRelativeBounds() const {
1097 return nullptr;
1098 }
1099
1100 mutable Member<AXObject> parent_;
1101
1102 // The following cached attribute values (the ones starting with m_cached*)
1103 // are only valid if m_lastModificationCount matches
1104 // AXObjectCacheImpl::modificationCount().
1105 mutable int last_modification_count_;
1106 mutable RGBA32 cached_background_color_;
1107 mutable bool cached_is_ignored_ : 1;
1108 mutable bool cached_is_inert_or_aria_hidden_ : 1;
1109 mutable bool cached_is_descendant_of_leaf_node_ : 1;
1110 mutable bool cached_is_descendant_of_disabled_node_ : 1;
1111 mutable bool cached_has_inherited_presentational_role_ : 1;
1112 mutable bool cached_is_presentational_child_ : 1;
1113 mutable bool cached_ancestor_exposes_active_descendant_ : 1;
1114 mutable Member<AXObject> cached_live_region_root_;
1115
1116 Member<AXObjectCacheImpl> ax_object_cache_;
1117
1118 // Updates the cached attribute values. This may be recursive, so to prevent
1119 // deadlocks,
1120 // functions called here may only search up the tree (ancestors), not down.
1121 void UpdateCachedAttributeValuesIfNeeded() const;
1122
1123 private:
1124 static bool IsNativeInputInMixedState(const Node*);
1125 static bool IncludesARIAWidgetRole(const String&);
1126 static bool HasInteractiveARIAAttribute(const Element&);
1127
1128 static unsigned number_of_live_ax_objects_;
1129 };
1130
1131 #define DEFINE_AX_OBJECT_TYPE_CASTS(thisType, predicate) \
1132 DEFINE_TYPE_CASTS(thisType, AXObject, object, object->predicate, \
1133 object.predicate)
1134
1135 } // namespace blink
1136
1137 #endif // AXObject_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698