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