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 "platform/geometry/FloatQuad.h" 35 #include "platform/geometry/LayoutRect.h" 36 #include "wtf/Forward.h" 37 #include "wtf/RefPtr.h" 38 #include "wtf/Vector.h" 39 40 namespace WebCore { 41 42 class AXObject; 43 class AXObjectCache; 44 class Element; 45 class Frame; 46 class FrameView; 47 class HTMLAnchorElement; 48 class HTMLAreaElement; 49 class IntPoint; 50 class IntSize; 51 class Node; 52 class RenderObject; 53 class RenderListItem; 54 class ScrollableArea; 55 class VisibleSelection; 56 class Widget; 57 58 typedef unsigned AXID; 59 60 enum AccessibilityRole { 61 AlertDialogRole = 1, 62 AlertRole, 63 AnnotationRole, 64 ApplicationRole, 65 ArticleRole, 66 BannerRole, 67 BrowserRole, 68 BusyIndicatorRole, 69 ButtonRole, 70 CanvasRole, 71 CellRole, 72 CheckBoxRole, 73 ColorWellRole, 74 ColumnHeaderRole, 75 ColumnRole, 76 ComboBoxRole, 77 ComplementaryRole, 78 ContentInfoRole, 79 DefinitionRole, 80 DescriptionListDetailRole, 81 DescriptionListTermRole, 82 DialogRole, 83 DirectoryRole, 84 DisclosureTriangleRole, 85 DivRole, 86 DocumentRole, 87 DrawerRole, 88 EditableTextRole, 89 FooterRole, 90 FormRole, 91 GridRole, 92 GroupRole, 93 GrowAreaRole, 94 HeadingRole, 95 HelpTagRole, 96 HorizontalRuleRole, 97 IgnoredRole, 98 ImageMapLinkRole, 99 ImageMapRole, 100 ImageRole, 101 IncrementorRole, 102 InlineTextBoxRole, 103 LabelRole, 104 LegendRole, 105 LinkRole, 106 ListBoxOptionRole, 107 ListBoxRole, 108 ListItemRole, 109 ListMarkerRole, 110 ListRole, 111 LogRole, 112 MainRole, 113 MarqueeRole, 114 MathElementRole, 115 MathRole, 116 MatteRole, 117 MenuBarRole, 118 MenuButtonRole, 119 MenuItemRole, 120 MenuListOptionRole, 121 MenuListPopupRole, 122 MenuRole, 123 NavigationRole, 124 NoteRole, 125 OutlineRole, 126 ParagraphRole, 127 PopUpButtonRole, 128 PresentationalRole, 129 ProgressIndicatorRole, 130 RadioButtonRole, 131 RadioGroupRole, 132 RegionRole, 133 RootWebAreaRole, 134 RowHeaderRole, 135 RowRole, 136 RulerMarkerRole, 137 RulerRole, 138 SVGRootRole, 139 ScrollAreaRole, 140 ScrollBarRole, 141 SeamlessWebAreaRole, 142 SearchRole, 143 SheetRole, 144 SliderRole, 145 SliderThumbRole, 146 SpinButtonPartRole, 147 SpinButtonRole, 148 SplitGroupRole, 149 SplitterRole, 150 StaticTextRole, 151 StatusRole, 152 SystemWideRole, 153 TabGroupRole, 154 TabListRole, 155 TabPanelRole, 156 TabRole, 157 TableHeaderContainerRole, 158 TableRole, 159 TextAreaRole, 160 TextFieldRole, 161 TimerRole, 162 ToggleButtonRole, 163 ToolbarRole, 164 TreeGridRole, 165 TreeItemRole, 166 TreeRole, 167 UnknownRole, 168 UserInterfaceTooltipRole, 169 ValueIndicatorRole, 170 WebAreaRole, 171 WindowRole, 172 }; 173 174 enum AccessibilityTextSource { 175 AlternativeText, 176 ChildrenText, 177 SummaryText, 178 HelpText, 179 VisibleText, 180 TitleTagText, 181 PlaceholderText, 182 LabelByElementText, 183 }; 184 185 enum AccessibilityState { 186 AXBusyState, 187 AXCheckedState, 188 AXCollapsedState, 189 AXEnabledState, 190 AXExpandedState, 191 AXFocusableState, 192 AXFocusedState, 193 AXHaspopupState, 194 AXHoveredState, 195 AXIndeterminateState, 196 AXInvisibleState, 197 AXLinkedState, 198 AXMultiselectableState, 199 AXOffscreenState, 200 AXPressedState, 201 AXProtectedState, 202 AXReadonlyState, 203 AXRequiredState, 204 AXSelectableState, 205 AXSelectedState, 206 AXVerticalState, 207 AXVisitedState 208 }; 209 210 struct AccessibilityText { 211 String text; 212 AccessibilityTextSource textSource; 213 RefPtr<AXObject> textElement; 214 215 AccessibilityText(const String& t, const AccessibilityTextSource& s) 216 : text(t) 217 , textSource(s) 218 { } 219 220 AccessibilityText(const String& t, const AccessibilityTextSource& s, const RefPtr<AXObject> element) 221 : text(t) 222 , textSource(s) 223 , textElement(element) 224 { } 225 }; 226 227 enum AccessibilityOrientation { 228 AccessibilityOrientationVertical, 229 AccessibilityOrientationHorizontal, 230 }; 231 232 enum AXObjectInclusion { 233 IncludeObject, 234 IgnoreObject, 235 DefaultBehavior, 236 }; 237 238 enum AccessibilityButtonState { 239 ButtonStateOff = 0, 240 ButtonStateOn, 241 ButtonStateMixed, 242 }; 243 244 enum AccessibilityTextDirection { 245 AccessibilityTextDirectionLeftToRight, 246 AccessibilityTextDirectionRightToLeft, 247 AccessibilityTextDirectionTopToBottom, 248 AccessibilityTextDirectionBottomToTop 249 }; 250 251 class AXObject : public RefCounted<AXObject> { 252 public: 253 typedef Vector<RefPtr<AXObject> > AccessibilityChildrenVector; 254 255 struct PlainTextRange { 256 257 unsigned start; 258 unsigned length; 259 260 PlainTextRange() 261 : start(0) 262 , length(0) 263 { } 264 265 PlainTextRange(unsigned s, unsigned l) 266 : start(s) 267 , length(l) 268 { } 269 270 bool isNull() const { return !start && !length; } 271 }; 272 273 protected: 274 AXObject(); 275 276 public: 277 virtual ~AXObject(); 278 279 // After constructing an AXObject, it must be given a 280 // unique ID, then added to AXObjectCache, and finally init() must 281 // be called last. 282 void setAXObjectID(AXID axObjectID) { m_id = axObjectID; } 283 virtual void init() { } 284 285 // When the corresponding WebCore object that this AXObject 286 // wraps is deleted, it must be detached. 287 virtual void detach(); 288 virtual bool isDetached() const; 289 290 // The AXObjectCache that owns this object, and its unique ID within this cache. 291 AXObjectCache* axObjectCache() const; 292 AXID axObjectID() const { return m_id; } 293 294 // Lays out the page so that the accessibility tree is based on up-to-date information. 295 void updateBackingStore(); 296 297 // Determine subclass type. 298 virtual bool isAXNodeObject() const { return false; } 299 virtual bool isAXRenderObject() const { return false; } 300 virtual bool isAXScrollbar() const { return false; } 301 virtual bool isAXScrollView() const { return false; } 302 virtual bool isAXSVGRoot() const { return false; } 303 304 // Check object role or purpose. 305 virtual AccessibilityRole roleValue() const { return m_role; } 306 bool isARIATextControl() const; 307 virtual bool isARIATreeGridRow() const { return false; } 308 virtual bool isAXTable() const { return false; } 309 virtual bool isAnchor() const { return false; } 310 virtual bool isAttachment() const { return false; } 311 bool isButton() const; 312 bool isCanvas() const { return roleValue() == CanvasRole; } 313 bool isCheckbox() const { return roleValue() == CheckBoxRole; } 314 bool isCheckboxOrRadio() const { return isCheckbox() || isRadioButton(); } 315 bool isColorWell() const { return roleValue() == ColorWellRole; } 316 bool isComboBox() const { return roleValue() == ComboBoxRole; } 317 virtual bool isControl() const { return false; } 318 virtual bool isDataTable() const { return false; } 319 virtual bool isFieldset() const { return false; } 320 virtual bool isFileUploadButton() const { return false; } 321 virtual bool isHeading() const { return false; } 322 virtual bool isImage() const { return false; } 323 virtual bool isImageMapLink() const { return false; } 324 virtual bool isInputImage() const { return false; } 325 virtual bool isLink() const { return false; } 326 virtual bool isList() const { return false; } 327 bool isListItem() const { return roleValue() == ListItemRole; } 328 virtual bool isListBoxOption() const { return false; } 329 virtual bool isMenu() const { return false; } 330 virtual bool isMenuButton() const { return false; } 331 virtual bool isMenuList() const { return false; } 332 virtual bool isMenuListOption() const { return false; } 333 virtual bool isMenuListPopup() const { return false; } 334 bool isMenuRelated() const; 335 virtual bool isMockObject() const { return false; } 336 virtual bool isNativeSpinButton() const { return false; } 337 virtual bool isNativeTextControl() const { return false; } // input or textarea 338 virtual bool isNonNativeTextControl() const { return false; } // contenteditable or role=textbox 339 virtual bool isPasswordField() const { return false; } 340 virtual bool isProgressIndicator() const { return false; } 341 bool isRadioButton() const { return roleValue() == RadioButtonRole; } 342 bool isScrollbar() const { return roleValue() == ScrollBarRole; } 343 bool isSeamlessWebArea() const { return roleValue() == SeamlessWebAreaRole; } 344 virtual bool isSlider() const { return false; } 345 virtual bool isSpinButton() const { return roleValue() == SpinButtonRole; } 346 virtual bool isSpinButtonPart() const { return false; } 347 bool isTabItem() const { return roleValue() == TabRole; } 348 virtual bool isTableCell() const { return false; } 349 virtual bool isTableRow() const { return false; } 350 virtual bool isTableCol() const { return false; } 351 bool isTextControl() const; 352 bool isTree() const { return roleValue() == TreeRole; } 353 bool isTreeItem() const { return roleValue() == TreeItemRole; } 354 bool isWebArea() const { return roleValue() == WebAreaRole; } 355 356 // Check object state. 357 virtual bool isChecked() const { return false; } 358 virtual bool isClickable() const; 359 virtual bool isCollapsed() const { return false; } 360 virtual bool isEnabled() const { return false; } 361 bool isExpanded() const; 362 virtual bool isFocused() const { return false; } 363 virtual bool isHovered() const { return false; } 364 virtual bool isIndeterminate() const { return false; } 365 virtual bool isLinked() const { return false; } 366 virtual bool isLoaded() const { return false; } 367 virtual bool isMultiSelectable() const { return false; } 368 virtual bool isOffScreen() const { return false; } 369 virtual bool isPressed() const { return false; } 370 virtual bool isReadOnly() const { return false; } 371 virtual bool isRequired() const { return false; } 372 virtual bool isSelected() const { return false; } 373 virtual bool isSelectedOptionActive() const { return false; } 374 virtual bool isVisible() const { return true; } 375 virtual bool isVisited() const { return false; } 376 377 // Check whether certain properties can be modified. 378 virtual bool canSetFocusAttribute() const { return false; } 379 virtual bool canSetValueAttribute() const { return false; } 380 virtual bool canSetSelectedAttribute() const { return false; } 381 virtual bool canSetSelectedChildrenAttribute() const { return false; } 382 383 // Whether objects are ignored, i.e. not included in the tree. 384 bool accessibilityIsIgnored() const; 385 bool accessibilityIsIgnoredByDefault() const; 386 AXObjectInclusion accessibilityPlatformIncludesObject() const; 387 virtual AXObjectInclusion defaultObjectInclusion() const; 388 bool isInertOrAriaHidden() const; 389 bool lastKnownIsIgnoredValue(); 390 void setLastKnownIsIgnoredValue(bool); 391 392 // Properties of static elements. 393 virtual const AtomicString& accessKey() const { return nullAtom; } 394 virtual bool canvasHasFallbackContent() const { return false; } 395 virtual bool exposesTitleUIElement() const { return true; } 396 virtual int headingLevel() const { return 0; } 397 // 1-based, to match the aria-level spec. 398 virtual unsigned hierarchicalLevel() const { return 0; } 399 virtual AccessibilityOrientation orientation() const; 400 virtual int tableLevel() const { return 0; } 401 virtual String text() const { return String(); } 402 virtual int textLength() const { return 0; } 403 virtual AXObject* titleUIElement() const { return 0; } 404 virtual KURL url() const { return KURL(); } 405 406 // For an inline text box. 407 virtual AccessibilityTextDirection textDirection() const { return AccessibilityTextDirectionLeftToRight; } 408 // The integer horizontal pixel offset of each character in the string; negative values for RTL. 409 virtual void textCharacterOffsets(Vector<int>&) const { } 410 // The start and end character offset of each word in the inline text box. 411 virtual void wordBoundaries(Vector<PlainTextRange>& words) const { } 412 413 // Properties of interactive elements. 414 virtual String actionVerb() const; 415 virtual AccessibilityButtonState checkboxOrRadioValue() const; 416 virtual void colorValue(int& r, int& g, int& b) const { r = 0; g = 0; b = 0; } 417 virtual String valueDescription() const { return String(); } 418 virtual float valueForRange() const { return 0.0f; } 419 virtual float maxValueForRange() const { return 0.0f; } 420 virtual float minValueForRange() const { return 0.0f; } 421 const AtomicString& placeholderValue() const; 422 virtual void selectedChildren(AccessibilityChildrenVector&) { } 423 virtual String stringValue() const { return String(); } 424 425 // ARIA attributes. 426 virtual AXObject* activeDescendant() const { return 0; } 427 virtual String ariaDescribedByAttribute() const { return String(); } 428 virtual void ariaFlowToElements(AccessibilityChildrenVector&) const { } 429 virtual bool ariaHasPopup() const { return false; } 430 bool ariaIsMultiline() const; 431 virtual String ariaLabeledByAttribute() const { return String(); } 432 bool ariaPressedIsPresent() const; 433 virtual AccessibilityRole ariaRoleAttribute() const { return UnknownRole; } 434 virtual bool ariaRoleHasPresentationalChildren() const { return false; } 435 const AtomicString& invalidStatus() const; 436 virtual bool isARIAGrabbed() { return false; } 437 virtual bool isPresentationalChildOfAriaRole() const { return false; } 438 virtual bool shouldFocusActiveDescendant() const { return false; } 439 bool supportsARIAAttributes() const; 440 virtual bool supportsARIADragging() const { return false; } 441 virtual bool supportsARIADropping() const { return false; } 442 virtual bool supportsARIAFlowTo() const { return false; } 443 virtual bool supportsARIAOwns() const { return false; } 444 bool supportsRangeValue() const; 445 446 // ARIA trees. 447 // Used by an ARIA tree to get all its rows. 448 void ariaTreeRows(AccessibilityChildrenVector&); 449 450 // ARIA live-region features. 451 bool supportsARIALiveRegion() const; 452 virtual const AtomicString& ariaLiveRegionStatus() const { return nullAtom; } 453 virtual const AtomicString& ariaLiveRegionRelevant() const { return nullAtom; } 454 virtual bool ariaLiveRegionAtomic() const { return false; } 455 virtual bool ariaLiveRegionBusy() const { return false; } 456 457 // Accessibility Text. 458 virtual void accessibilityText(Vector<AccessibilityText>&) { }; 459 virtual String textUnderElement() const { return String(); } 460 461 // Accessibility Text - (To be deprecated). 462 virtual String accessibilityDescription() const { return String(); } 463 virtual String title() const { return String(); } 464 virtual String helpText() const { return String(); } 465 466 // Location and click point in frame-relative coordinates. 467 virtual LayoutRect elementRect() const { return m_explicitElementRect; } 468 void setElementRect(LayoutRect r) { m_explicitElementRect = r; } 469 virtual void markCachedElementRectDirty() const; 470 virtual IntPoint clickPoint(); 471 472 // Hit testing. 473 // Called on the root AX object to return the deepest available element. 474 virtual AXObject* accessibilityHitTest(const IntPoint&) const { return 0; } 475 // Called on the AX object after the render tree determines which is the right AXRenderObject. 476 virtual AXObject* elementAccessibilityHitTest(const IntPoint&) const; 477 478 // High-level accessibility tree access. Other modules should only use these functions. 479 const AccessibilityChildrenVector& children(); 480 virtual AXObject* parentObject() const = 0; 481 AXObject* parentObjectUnignored() const; 482 virtual AXObject* parentObjectIfExists() const { return 0; } 483 484 // Low-level accessibility tree exploration, only for use within the accessibility module. 485 virtual AXObject* firstChild() const { return 0; } 486 virtual AXObject* nextSibling() const { return 0; } 487 static AXObject* firstAccessibleObjectFromNode(const Node*); 488 virtual void addChildren() { } 489 virtual bool canHaveChildren() const { return true; } 490 bool hasChildren() const { return m_haveChildren; } 491 virtual void updateChildrenIfNecessary(); 492 virtual void setNeedsToUpdateChildren() { } 493 virtual void clearChildren(); 494 virtual void detachFromParent() { } 495 virtual AXObject* observableObject() const { return 0; } 496 virtual AXObject* scrollBar(AccessibilityOrientation) { return 0; } 497 498 // Properties of the object's owning document or page. 499 virtual double estimatedLoadingProgress() const { return 0; } 500 AXObject* focusedUIElement() const; 501 502 // DOM and Render tree access. 503 virtual Node* node() const { return 0; } 504 virtual RenderObject* renderer() const { return 0; } 505 virtual Document* document() const; 506 virtual FrameView* documentFrameView() const; 507 virtual Element* anchorElement() const { return 0; } 508 virtual Element* actionElement() const { return 0; } 509 virtual Widget* widgetForAttachmentView() const { return 0; } 510 String language() const; 511 bool hasAttribute(const QualifiedName&) const; 512 const AtomicString& getAttribute(const QualifiedName&) const; 513 514 // Selected text. 515 virtual PlainTextRange selectedTextRange() const { return PlainTextRange(); } 516 virtual String selectedText() const { return String(); } 517 518 // Modify or take an action on an object. 519 virtual void increment() { } 520 virtual void decrement() { } 521 bool performDefaultAction() const { return press(); } 522 virtual bool press() const; 523 // Make this object visible by scrolling as many nested scrollable views as needed. 524 void scrollToMakeVisible() const; 525 // Same, but if the whole object can't be made visible, try for this subrect, in local coordinates. 526 void scrollToMakeVisibleWithSubFocus(const IntRect&) const; 527 // Scroll this object to a given point in global coordinates of the top-level window. 528 void scrollToGlobalPoint(const IntPoint&) const; 529 virtual void setFocused(bool) { } 530 virtual void setSelected(bool) { } 531 void setSelectedText(const String&) { } 532 virtual void setSelectedTextRange(const PlainTextRange&) { } 533 virtual void setValue(const String&) { } 534 virtual void setValue(float) { } 535 536 // Notifications that this object may have changed. 537 virtual void childrenChanged() { } 538 virtual void handleActiveDescendantChanged() { } 539 virtual void handleAriaExpandedChanged() { } 540 void notifyIfIgnoredValueChanged(); 541 virtual void selectionChanged(); 542 virtual void textChanged() { } 543 virtual void updateAccessibilityRole() { } 544 545 // Text metrics. Most of these should be deprecated, needs major cleanup. 546 virtual VisiblePosition visiblePositionForIndex(int) const { return VisiblePosition(); } 547 int lineForPosition(const VisiblePosition&) const; 548 virtual int index(const VisiblePosition&) const { return -1; } 549 virtual void lineBreaks(Vector<int>&) const { } 550 551 // Static helper functions. 552 static bool isARIAControl(AccessibilityRole); 553 static bool isARIAInput(AccessibilityRole); 554 static AccessibilityRole ariaRoleToWebCoreRole(const String&); 555 static IntRect boundingBoxForQuads(RenderObject*, const Vector<FloatQuad>&); 556 557 protected: 558 AXID m_id; 559 AccessibilityChildrenVector m_children; 560 mutable bool m_haveChildren; 561 AccessibilityRole m_role; 562 AXObjectInclusion m_lastKnownIsIgnoredValue; 563 LayoutRect m_explicitElementRect; 564 565 virtual bool computeAccessibilityIsIgnored() const { return true; } 566 567 // If this object itself scrolls, return its ScrollableArea. 568 virtual ScrollableArea* getScrollableAreaIfScrollable() const { return 0; } 569 virtual void scrollTo(const IntPoint&) const { } 570 571 AccessibilityRole buttonRoleType() const; 572 573 bool allowsTextRanges() const { return isTextControl(); } 574 unsigned getLengthForTextRange() const { return text().length(); } 575 576 bool m_detached; 577 }; 578 579 #define DEFINE_AX_OBJECT_TYPE_CASTS(thisType, predicate) \ 580 DEFINE_TYPE_CASTS(thisType, AXObject, object, object->predicate, object.predicate) 581 582 } // namespace WebCore 583 584 #endif // AXObject_h 585