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