1 /* 2 * Copyright (C) 2008 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 AccessibilityObject_h 31 #define AccessibilityObject_h 32 33 #include "IntRect.h" 34 #include "Range.h" 35 #include "VisiblePosition.h" 36 #include "VisibleSelection.h" 37 #include <wtf/Platform.h> 38 #include <wtf/RefPtr.h> 39 #include <wtf/Vector.h> 40 41 #if PLATFORM(MAC) 42 #include <wtf/RetainPtr.h> 43 #elif PLATFORM(WIN) && !PLATFORM(WINCE) 44 #include "AccessibilityObjectWrapperWin.h" 45 #include "COMPtr.h" 46 #elif PLATFORM(CHROMIUM) 47 #include "AccessibilityObjectWrapper.h" 48 #endif 49 50 typedef struct _NSRange NSRange; 51 52 #ifdef __OBJC__ 53 @class AccessibilityObjectWrapper; 54 @class NSArray; 55 @class NSAttributedString; 56 @class NSData; 57 @class NSMutableAttributedString; 58 @class NSString; 59 @class NSValue; 60 @class NSView; 61 #else 62 class NSArray; 63 class NSAttributedString; 64 class NSData; 65 class NSMutableAttributedString; 66 class NSString; 67 class NSValue; 68 class NSView; 69 #if PLATFORM(GTK) 70 typedef struct _AtkObject AtkObject; 71 typedef struct _AtkObject AccessibilityObjectWrapper; 72 #else 73 class AccessibilityObjectWrapper; 74 #endif 75 #endif 76 77 namespace WebCore { 78 79 class AXObjectCache; 80 class Element; 81 class Frame; 82 class FrameView; 83 class HTMLAnchorElement; 84 class HTMLAreaElement; 85 class IntPoint; 86 class IntSize; 87 class Node; 88 class RenderObject; 89 class VisibleSelection; 90 class String; 91 class Widget; 92 93 enum AccessibilityRole { 94 UnknownRole = 1, 95 ButtonRole, 96 RadioButtonRole, 97 CheckBoxRole, 98 SliderRole, 99 TabGroupRole, 100 TextFieldRole, 101 StaticTextRole, 102 TextAreaRole, 103 ScrollAreaRole, 104 PopUpButtonRole, 105 MenuButtonRole, 106 TableRole, 107 ApplicationRole, 108 GroupRole, 109 RadioGroupRole, 110 ListRole, 111 ScrollBarRole, 112 ValueIndicatorRole, 113 ImageRole, 114 MenuBarRole, 115 MenuRole, 116 MenuItemRole, 117 ColumnRole, 118 RowRole, 119 ToolbarRole, 120 BusyIndicatorRole, 121 ProgressIndicatorRole, 122 WindowRole, 123 DrawerRole, 124 SystemWideRole, 125 OutlineRole, 126 IncrementorRole, 127 BrowserRole, 128 ComboBoxRole, 129 SplitGroupRole, 130 SplitterRole, 131 ColorWellRole, 132 GrowAreaRole, 133 SheetRole, 134 HelpTagRole, 135 MatteRole, 136 RulerRole, 137 RulerMarkerRole, 138 LinkRole, 139 DisclosureTriangleRole, 140 GridRole, 141 CellRole, 142 ColumnHeaderRole, 143 RowHeaderRole, 144 // AppKit includes SortButtonRole but it is misnamed and really a subrole of ButtonRole so we do not include it here. 145 146 // WebCore-specific roles 147 WebCoreLinkRole, 148 ImageMapLinkRole, 149 ImageMapRole, 150 ListMarkerRole, 151 WebAreaRole, 152 HeadingRole, 153 ListBoxRole, 154 ListBoxOptionRole, 155 TableHeaderContainerRole, 156 DefinitionListTermRole, 157 DefinitionListDefinitionRole, 158 AnnotationRole, 159 SliderThumbRole 160 }; 161 162 enum AccessibilityOrientation { 163 AccessibilityOrientationVertical, 164 AccessibilityOrientationHorizontal, 165 }; 166 167 struct VisiblePositionRange { 168 169 VisiblePosition start; 170 VisiblePosition end; 171 VisiblePositionRangeVisiblePositionRange172 VisiblePositionRange() {} 173 VisiblePositionRangeVisiblePositionRange174 VisiblePositionRange(const VisiblePosition& s, const VisiblePosition& e) 175 : start(s) 176 , end(e) 177 { } 178 isNullVisiblePositionRange179 bool isNull() const { return start.isNull() || end.isNull(); } 180 }; 181 182 struct PlainTextRange { 183 184 unsigned start; 185 unsigned length; 186 PlainTextRangePlainTextRange187 PlainTextRange() 188 : start(0) 189 , length(0) 190 { } 191 PlainTextRangePlainTextRange192 PlainTextRange(unsigned s, unsigned l) 193 : start(s) 194 , length(l) 195 { } 196 isNullPlainTextRange197 bool isNull() const { return start == 0 && length == 0; } 198 }; 199 200 class AccessibilityObject : public RefCounted<AccessibilityObject> { 201 protected: 202 AccessibilityObject(); 203 public: 204 virtual ~AccessibilityObject(); 205 virtual void detach(); 206 207 typedef Vector<RefPtr<AccessibilityObject> > AccessibilityChildrenVector; 208 isAccessibilityRenderObject()209 virtual bool isAccessibilityRenderObject() const { return false; }; isAnchor()210 virtual bool isAnchor() const { return false; }; isAttachment()211 virtual bool isAttachment() const { return false; }; isHeading()212 virtual bool isHeading() const { return false; }; isLink()213 virtual bool isLink() const { return false; }; isImage()214 virtual bool isImage() const { return false; }; isNativeImage()215 virtual bool isNativeImage() const { return false; }; isImageButton()216 virtual bool isImageButton() const { return false; }; isPasswordField()217 virtual bool isPasswordField() const { return false; }; isTextControl()218 virtual bool isTextControl() const { return false; }; isNativeTextControl()219 virtual bool isNativeTextControl() const { return false; }; isWebArea()220 virtual bool isWebArea() const { return false; }; isCheckboxOrRadio()221 virtual bool isCheckboxOrRadio() const { return false; }; isListBox()222 virtual bool isListBox() const { return roleValue() == ListBoxRole; }; isMenuRelated()223 virtual bool isMenuRelated() const { return false; } isMenu()224 virtual bool isMenu() const { return false; } isMenuBar()225 virtual bool isMenuBar() const { return false; } isMenuButton()226 virtual bool isMenuButton() const { return false; } isMenuItem()227 virtual bool isMenuItem() const { return false; } isFileUploadButton()228 virtual bool isFileUploadButton() const { return false; }; isInputImage()229 virtual bool isInputImage() const { return false; } isProgressIndicator()230 virtual bool isProgressIndicator() const { return false; }; isSlider()231 virtual bool isSlider() const { return false; }; isControl()232 virtual bool isControl() const { return false; }; isList()233 virtual bool isList() const { return false; }; isDataTable()234 virtual bool isDataTable() const { return false; }; isTableRow()235 virtual bool isTableRow() const { return false; }; isTableColumn()236 virtual bool isTableColumn() const { return false; }; isTableCell()237 virtual bool isTableCell() const { return false; }; isFieldset()238 virtual bool isFieldset() const { return false; }; isGroup()239 virtual bool isGroup() const { return false; }; isRadioGroup()240 bool isRadioGroup() const { return roleValue() == RadioGroupRole; } 241 isChecked()242 virtual bool isChecked() const { return false; }; isEnabled()243 virtual bool isEnabled() const { return false; }; isSelected()244 virtual bool isSelected() const { return false; }; isFocused()245 virtual bool isFocused() const { return false; }; isHovered()246 virtual bool isHovered() const { return false; }; isIndeterminate()247 virtual bool isIndeterminate() const { return false; }; isLoaded()248 virtual bool isLoaded() const { return false; }; isMultiSelect()249 virtual bool isMultiSelect() const { return false; }; isOffScreen()250 virtual bool isOffScreen() const { return false; }; isPressed()251 virtual bool isPressed() const { return false; }; isReadOnly()252 virtual bool isReadOnly() const { return false; }; isVisited()253 virtual bool isVisited() const { return false; }; isRequired()254 virtual bool isRequired() const { return false; }; 255 canSetFocusAttribute()256 virtual bool canSetFocusAttribute() const { return false; }; canSetTextRangeAttributes()257 virtual bool canSetTextRangeAttributes() const { return false; }; canSetValueAttribute()258 virtual bool canSetValueAttribute() const { return false; }; canSetSelectedAttribute()259 virtual bool canSetSelectedAttribute() const { return false; } canSetSelectedChildrenAttribute()260 virtual bool canSetSelectedChildrenAttribute() const { return false; } 261 hasIntValue()262 virtual bool hasIntValue() const { return false; }; 263 accessibilityShouldUseUniqueId()264 bool accessibilityShouldUseUniqueId() const { return true; }; accessibilityIsIgnored()265 virtual bool accessibilityIsIgnored() const { return true; }; 266 headingLevel()267 virtual int headingLevel() const { return 0; } intValue()268 virtual int intValue() const { return 0; } valueDescription()269 virtual String valueDescription() const { return String(); } valueForRange()270 virtual float valueForRange() const { return 0.0f; } maxValueForRange()271 virtual float maxValueForRange() const { return 0.0f; } minValueForRange()272 virtual float minValueForRange() const { return 0.0f; } selectedRadioButton()273 virtual AccessibilityObject* selectedRadioButton() { return 0; } layoutCount()274 virtual int layoutCount() const { return 0; } 275 static bool isARIAControl(AccessibilityRole); 276 static bool isARIAInput(AccessibilityRole); 277 doAccessibilityHitTest(const IntPoint &)278 virtual AccessibilityObject* doAccessibilityHitTest(const IntPoint&) const { return 0; } focusedUIElement()279 virtual AccessibilityObject* focusedUIElement() const { return 0; } 280 firstChild()281 virtual AccessibilityObject* firstChild() const { return 0; } lastChild()282 virtual AccessibilityObject* lastChild() const { return 0; } previousSibling()283 virtual AccessibilityObject* previousSibling() const { return 0; } nextSibling()284 virtual AccessibilityObject* nextSibling() const { return 0; } 285 virtual AccessibilityObject* parentObject() const = 0; 286 virtual AccessibilityObject* parentObjectUnignored() const; parentObjectIfExists()287 virtual AccessibilityObject* parentObjectIfExists() const { return 0; } 288 observableObject()289 virtual AccessibilityObject* observableObject() const { return 0; } linkedUIElements(AccessibilityChildrenVector &)290 virtual void linkedUIElements(AccessibilityChildrenVector&) const { } titleUIElement()291 virtual AccessibilityObject* titleUIElement() const { return 0; } exposesTitleUIElement()292 virtual bool exposesTitleUIElement() const { return true; } 293 ariaRoleAttribute()294 virtual AccessibilityRole ariaRoleAttribute() const { return UnknownRole; } isPresentationalChildOfAriaRole()295 virtual bool isPresentationalChildOfAriaRole() const { return false; } ariaRoleHasPresentationalChildren()296 virtual bool ariaRoleHasPresentationalChildren() const { return false; } 297 setRoleValue(AccessibilityRole role)298 void setRoleValue(AccessibilityRole role) { m_role = role; } roleValue()299 virtual AccessibilityRole roleValue() const { return m_role; } ariaAccessibilityName(const String &)300 virtual String ariaAccessibilityName(const String&) const { return String(); } ariaLabeledByAttribute()301 virtual String ariaLabeledByAttribute() const { return String(); } ariaDescribedByAttribute()302 virtual String ariaDescribedByAttribute() const { return String(); } accessibilityDescription()303 virtual String accessibilityDescription() const { return String(); } ariaSelectedTextDOMRange()304 virtual PassRefPtr<Range> ariaSelectedTextDOMRange() const { return 0; } 305 axObjectCache()306 virtual AXObjectCache* axObjectCache() const { return 0; } axObjectID()307 unsigned axObjectID() const { return m_id; } setAXObjectID(unsigned axObjectID)308 void setAXObjectID(unsigned axObjectID) { m_id = axObjectID; } 309 310 static AccessibilityObject* anchorElementForNode(Node*); anchorElement()311 virtual Element* anchorElement() const { return 0; } actionElement()312 virtual Element* actionElement() const { return 0; } boundingBoxRect()313 virtual IntRect boundingBoxRect() const { return IntRect(); } 314 virtual IntRect elementRect() const = 0; 315 virtual IntSize size() const = 0; 316 virtual IntPoint clickPoint() const; 317 selectedTextRange()318 virtual PlainTextRange selectedTextRange() const { return PlainTextRange(); } selectionStart()319 unsigned selectionStart() const { return selectedTextRange().start; } selectionEnd()320 unsigned selectionEnd() const { return selectedTextRange().length; } 321 url()322 virtual KURL url() const { return KURL(); } selection()323 virtual VisibleSelection selection() const { return VisibleSelection(); } stringValue()324 virtual String stringValue() const { return String(); } title()325 virtual String title() const { return String(); } helpText()326 virtual String helpText() const { return String(); } textUnderElement()327 virtual String textUnderElement() const { return String(); } text()328 virtual String text() const { return String(); } textLength()329 virtual int textLength() const { return 0; } selectedText()330 virtual String selectedText() const { return String(); } accessKey()331 virtual const AtomicString& accessKey() const { return nullAtom; } 332 const String& actionVerb() const; widget()333 virtual Widget* widget() const { return 0; } widgetForAttachmentView()334 virtual Widget* widgetForAttachmentView() const { return 0; } document()335 virtual Document* document() const { return 0; } topDocumentFrameView()336 virtual FrameView* topDocumentFrameView() const { return 0; } 337 virtual FrameView* documentFrameView() const; 338 virtual String language() const; 339 setFocused(bool)340 virtual void setFocused(bool) { } setSelectedText(const String &)341 virtual void setSelectedText(const String&) { } setSelectedTextRange(const PlainTextRange &)342 virtual void setSelectedTextRange(const PlainTextRange&) { } setValue(const String &)343 virtual void setValue(const String&) { } setSelected(bool)344 virtual void setSelected(bool) { } 345 makeRangeVisible(const PlainTextRange &)346 virtual void makeRangeVisible(const PlainTextRange&) { } 347 virtual bool press() const; performDefaultAction()348 bool performDefaultAction() const { return press(); } 349 350 virtual AccessibilityOrientation orientation() const; increment()351 virtual void increment() { }; decrement()352 virtual void decrement() { }; 353 childrenChanged()354 virtual void childrenChanged() { } children()355 virtual const AccessibilityChildrenVector& children() { return m_children; } addChildren()356 virtual void addChildren() { } canHaveChildren()357 virtual bool canHaveChildren() const { return true; } hasChildren()358 virtual bool hasChildren() const { return m_haveChildren; } selectedChildren(AccessibilityChildrenVector &)359 virtual void selectedChildren(AccessibilityChildrenVector&) { } visibleChildren(AccessibilityChildrenVector &)360 virtual void visibleChildren(AccessibilityChildrenVector&) { } shouldFocusActiveDescendant()361 virtual bool shouldFocusActiveDescendant() const { return false; } activeDescendant()362 virtual AccessibilityObject* activeDescendant() const { return 0; } handleActiveDescendantChanged()363 virtual void handleActiveDescendantChanged() { } 364 visiblePositionRange()365 virtual VisiblePositionRange visiblePositionRange() const { return VisiblePositionRange(); } visiblePositionRangeForLine(unsigned)366 virtual VisiblePositionRange visiblePositionRangeForLine(unsigned) const { return VisiblePositionRange(); } 367 368 VisiblePositionRange visiblePositionRangeForUnorderedPositions(const VisiblePosition&, const VisiblePosition&) const; 369 VisiblePositionRange positionOfLeftWord(const VisiblePosition&) const; 370 VisiblePositionRange positionOfRightWord(const VisiblePosition&) const; 371 VisiblePositionRange leftLineVisiblePositionRange(const VisiblePosition&) const; 372 VisiblePositionRange rightLineVisiblePositionRange(const VisiblePosition&) const; 373 VisiblePositionRange sentenceForPosition(const VisiblePosition&) const; 374 VisiblePositionRange paragraphForPosition(const VisiblePosition&) const; 375 VisiblePositionRange styleRangeForPosition(const VisiblePosition&) const; 376 VisiblePositionRange visiblePositionRangeForRange(const PlainTextRange&) const; 377 378 String stringForVisiblePositionRange(const VisiblePositionRange&) const; boundsForVisiblePositionRange(const VisiblePositionRange &)379 virtual IntRect boundsForVisiblePositionRange(const VisiblePositionRange&) const { return IntRect(); } 380 int lengthForVisiblePositionRange(const VisiblePositionRange&) const; setSelectedVisiblePositionRange(const VisiblePositionRange &)381 virtual void setSelectedVisiblePositionRange(const VisiblePositionRange&) const { } 382 visiblePositionForPoint(const IntPoint &)383 virtual VisiblePosition visiblePositionForPoint(const IntPoint&) const { return VisiblePosition(); } nextVisiblePosition(const VisiblePosition & visiblePos)384 VisiblePosition nextVisiblePosition(const VisiblePosition& visiblePos) const { return visiblePos.next(); } previousVisiblePosition(const VisiblePosition & visiblePos)385 VisiblePosition previousVisiblePosition(const VisiblePosition& visiblePos) const { return visiblePos.previous(); } 386 VisiblePosition nextWordEnd(const VisiblePosition&) const; 387 VisiblePosition previousWordStart(const VisiblePosition&) const; 388 VisiblePosition nextLineEndPosition(const VisiblePosition&) const; 389 VisiblePosition previousLineStartPosition(const VisiblePosition&) const; 390 VisiblePosition nextSentenceEndPosition(const VisiblePosition&) const; 391 VisiblePosition previousSentenceStartPosition(const VisiblePosition&) const; 392 VisiblePosition nextParagraphEndPosition(const VisiblePosition&) const; 393 VisiblePosition previousParagraphStartPosition(const VisiblePosition&) const; visiblePositionForIndex(unsigned,bool)394 virtual VisiblePosition visiblePositionForIndex(unsigned, bool /*lastIndexOK */) const { return VisiblePosition(); } 395 visiblePositionForIndex(int)396 virtual VisiblePosition visiblePositionForIndex(int) const { return VisiblePosition(); } indexForVisiblePosition(const VisiblePosition &)397 virtual int indexForVisiblePosition(const VisiblePosition&) const { return 0; } 398 399 AccessibilityObject* accessibilityObjectForPosition(const VisiblePosition&) const; 400 int lineForPosition(const VisiblePosition&) const; 401 PlainTextRange plainTextRangeForVisiblePositionRange(const VisiblePositionRange&) const; index(const VisiblePosition &)402 virtual int index(const VisiblePosition&) const { return -1; } 403 doAXRangeForLine(unsigned)404 virtual PlainTextRange doAXRangeForLine(unsigned) const { return PlainTextRange(); } 405 PlainTextRange doAXRangeForPosition(const IntPoint&) const; doAXRangeForIndex(unsigned)406 virtual PlainTextRange doAXRangeForIndex(unsigned) const { return PlainTextRange(); } 407 PlainTextRange doAXStyleRangeForIndex(unsigned) const; 408 doAXStringForRange(const PlainTextRange &)409 virtual String doAXStringForRange(const PlainTextRange&) const { return String(); } doAXBoundsForRange(const PlainTextRange &)410 virtual IntRect doAXBoundsForRange(const PlainTextRange&) const { return IntRect(); } 411 412 unsigned doAXLineForIndex(unsigned); 413 414 #if HAVE(ACCESSIBILITY) 415 #if PLATFORM(GTK) 416 AccessibilityObjectWrapper* wrapper() const; 417 void setWrapper(AccessibilityObjectWrapper*); 418 #else wrapper()419 AccessibilityObjectWrapper* wrapper() const { return m_wrapper.get(); } setWrapper(AccessibilityObjectWrapper * wrapper)420 void setWrapper(AccessibilityObjectWrapper* wrapper) 421 { 422 m_wrapper = wrapper; 423 } 424 #endif 425 #endif 426 427 // a platform-specific method for determining if an attachment is ignored 428 #if HAVE(ACCESSIBILITY) 429 bool accessibilityIgnoreAttachment() const; 430 #else accessibilityIgnoreAttachment()431 bool accessibilityIgnoreAttachment() const { return true; } 432 #endif 433 434 // allows for an AccessibilityObject to update its render tree or perform 435 // other operations update type operations updateBackingStore()436 virtual void updateBackingStore() { } 437 438 protected: 439 unsigned m_id; 440 AccessibilityChildrenVector m_children; 441 mutable bool m_haveChildren; 442 AccessibilityRole m_role; 443 444 virtual void clearChildren(); isDetached()445 virtual bool isDetached() const { return true; } 446 447 #if PLATFORM(MAC) 448 RetainPtr<AccessibilityObjectWrapper> m_wrapper; 449 #elif PLATFORM(WIN) && !PLATFORM(WINCE) 450 COMPtr<AccessibilityObjectWrapper> m_wrapper; 451 #elif PLATFORM(GTK) 452 AtkObject* m_wrapper; 453 #elif PLATFORM(CHROMIUM) 454 RefPtr<AccessibilityObjectWrapper> m_wrapper; 455 #endif 456 }; 457 458 } // namespace WebCore 459 460 #endif // AccessibilityObject_h 461