2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "../platform/WebCommon.h"
35 #include "../platform/WebPoint.h"
36 #include "../platform/WebPrivateOwnPtr.h"
37 #include "../platform/WebPrivatePtr.h"
38 #include "../platform/WebVector.h"
39 #include "WebAXEnums.h"
41 #if BLINK_IMPLEMENTATION
42 namespace WTF
{ template <typename T
> class PassRefPtr
; }
48 class ScopedAXObjectCache
;
57 // An instance of this class, while kept alive, indicates that accessibility
58 // should be temporarily enabled. If accessibility was enabled globally
59 // (WebSettings::setAccessibilityEnabled), this will have no effect.
60 class WebScopedAXContext
{
62 BLINK_EXPORT
WebScopedAXContext(WebDocument
& rootDocument
);
63 BLINK_EXPORT
~WebScopedAXContext();
65 BLINK_EXPORT WebAXObject
root() const;
68 WebPrivateOwnPtr
<ScopedAXObjectCache
> m_private
;
71 // A container for passing around a reference to AXObject.
74 ~WebAXObject() { reset(); }
77 WebAXObject(const WebAXObject
& o
) { assign(o
); }
78 WebAXObject
& operator=(const WebAXObject
& o
)
84 BLINK_EXPORT
void reset();
85 BLINK_EXPORT
void assign(const WebAXObject
&);
86 BLINK_EXPORT
bool equals(const WebAXObject
&) const;
88 bool isNull() const { return m_private
.isNull(); }
89 // isDetached also checks for null, so it's safe to just call isDetached.
90 BLINK_EXPORT
bool isDetached() const;
92 BLINK_EXPORT
int axID() const;
94 // Update layout on the underlying tree, and return true if this object is
95 // still valid (not detached). Note that calling this method
96 // can cause other WebAXObjects to become invalid, too,
97 // so always call isDetached if any other WebCore code has run.
98 BLINK_EXPORT
bool updateLayoutAndCheckValidity();
100 BLINK_EXPORT
unsigned childCount() const;
102 BLINK_EXPORT WebAXObject
childAt(unsigned) const;
103 BLINK_EXPORT WebAXObject
parentObject() const;
105 BLINK_EXPORT
bool isAnchor() const;
106 BLINK_EXPORT
bool isAriaReadOnly() const;
107 BLINK_EXPORT
bool isButtonStateMixed() const;
108 BLINK_EXPORT
bool isChecked() const;
109 BLINK_EXPORT
bool isClickable() const;
110 BLINK_EXPORT
bool isCollapsed() const;
111 BLINK_EXPORT
bool isControl() const;
112 BLINK_EXPORT
bool isEnabled() const;
113 BLINK_EXPORT WebAXExpanded
isExpanded() const;
114 BLINK_EXPORT
bool isFocused() const;
115 BLINK_EXPORT
bool isHovered() const;
116 BLINK_EXPORT
bool isIndeterminate() const;
117 BLINK_EXPORT
bool isLinked() const;
118 BLINK_EXPORT
bool isLoaded() const;
119 BLINK_EXPORT
bool isMultiSelectable() const;
120 BLINK_EXPORT
bool isOffScreen() const;
121 BLINK_EXPORT
bool isPasswordField() const;
122 BLINK_EXPORT
bool isPressed() const;
123 BLINK_EXPORT
bool isReadOnly() const;
124 BLINK_EXPORT
bool isRequired() const;
125 BLINK_EXPORT
bool isSelected() const;
126 BLINK_EXPORT
bool isSelectedOptionActive() const;
127 BLINK_EXPORT
bool isVisible() const;
128 BLINK_EXPORT
bool isVisited() const;
130 BLINK_EXPORT WebString
accessKey() const;
131 BLINK_EXPORT
unsigned backgroundColor() const;
132 BLINK_EXPORT
unsigned color() const;
134 BLINK_EXPORT
void colorValue(int& r
, int& g
, int& b
) const;
135 BLINK_EXPORT
unsigned colorValue() const;
136 BLINK_EXPORT WebAXObject
ariaActiveDescendant() const;
137 BLINK_EXPORT WebString
ariaAutoComplete() const;
138 BLINK_EXPORT
bool ariaControls(WebVector
<WebAXObject
>& controlsElements
) const;
139 BLINK_EXPORT
bool ariaFlowTo(WebVector
<WebAXObject
>& flowToElements
) const;
140 BLINK_EXPORT
bool ariaHasPopup() const;
141 BLINK_EXPORT
bool isEditable() const;
142 BLINK_EXPORT
bool isMultiline() const;
143 BLINK_EXPORT
bool isRichlyEditable() const;
144 BLINK_EXPORT
bool ariaOwns(WebVector
<WebAXObject
>& ownsElements
) const;
145 BLINK_EXPORT WebRect
boundingBoxRect() const;
146 BLINK_EXPORT
float fontSize() const;
147 BLINK_EXPORT
bool canvasHasFallbackContent() const;
148 BLINK_EXPORT WebPoint
clickPoint() const;
149 BLINK_EXPORT WebAXInvalidState
invalidState() const;
150 // Only used when invalidState() returns WebAXInvalidStateOther.
151 BLINK_EXPORT WebString
ariaInvalidValue() const;
152 BLINK_EXPORT
double estimatedLoadingProgress() const;
153 BLINK_EXPORT
int headingLevel() const;
154 BLINK_EXPORT
int hierarchicalLevel() const;
155 BLINK_EXPORT WebAXObject
hitTest(const WebPoint
&) const;
156 BLINK_EXPORT WebString
keyboardShortcut() const;
157 BLINK_EXPORT WebString
language() const;
158 BLINK_EXPORT WebAXOrientation
orientation() const;
159 BLINK_EXPORT WebAXRole
role() const;
160 BLINK_EXPORT WebString
stringValue() const;
161 BLINK_EXPORT WebAXTextDirection
textDirection() const;
162 BLINK_EXPORT WebAXTextStyle
textStyle() const;
163 BLINK_EXPORT WebURL
url() const;
165 // Deprecated text alternative calculation API. All of these will be replaced
166 // with the new API, below (under "New text alternative calculation API".
167 BLINK_EXPORT WebString
deprecatedAccessibilityDescription() const;
168 BLINK_EXPORT
bool deprecatedAriaDescribedby(WebVector
<WebAXObject
>& describedbyElements
) const;
169 BLINK_EXPORT
bool deprecatedAriaLabelledby(WebVector
<WebAXObject
>& labelledbyElements
) const;
170 BLINK_EXPORT WebString
deprecatedHelpText() const;
171 BLINK_EXPORT WebString
deprecatedPlaceholder() const;
172 BLINK_EXPORT WebString
deprecatedTitle() const;
173 BLINK_EXPORT WebAXObject
deprecatedTitleUIElement() const;
175 // FIXME(dmazzoni): remove these ASAP once Chromium only calls either explicitly-deprecated
176 // functions, above, or the new APIs, below.
177 BLINK_EXPORT WebString
accessibilityDescription() const;
178 BLINK_EXPORT
bool ariaDescribedby(WebVector
<WebAXObject
>& describedbyElements
) const;
179 BLINK_EXPORT
bool ariaLabelledby(WebVector
<WebAXObject
>& labelledbyElements
) const;
180 BLINK_EXPORT WebString
helpText() const;
181 BLINK_EXPORT WebString
placeholder() const;
182 BLINK_EXPORT WebString
title() const;
183 BLINK_EXPORT WebAXObject
titleUIElement() const;
185 // New text alternative calculation API (under development).
187 // Retrieves the accessible name of the object, an enum indicating where the name
188 // was derived from, and a list of related objects that were used to derive the name, if any.
189 BLINK_EXPORT WebString
name(WebAXNameFrom
&, WebVector
<WebAXObject
>& nameObjects
) const;
190 // Takes the result of nameFrom from calling |name|, above, and retrieves the
191 // accessible description of the object, which is secondary to |name|, an enum indicating
192 // where the description was derived from, and a list of objects that were used to
193 // derive the description, if any.
194 BLINK_EXPORT WebString
description(WebAXNameFrom
, WebAXDescriptionFrom
&, WebVector
<WebAXObject
>& descriptionObjects
) const;
195 // Takes the result of nameFrom and descriptionFrom from calling |name| and |description|,
196 // above, and retrieves the placeholder of the object, if present and if it wasn't already
197 // exposed by one of the two functions above.
198 BLINK_EXPORT WebString
placeholder(WebAXNameFrom
, WebAXDescriptionFrom
) const;
200 // The following selection functions get or set the global document
201 // selection and can be called on any object in the tree.
202 BLINK_EXPORT
void selection(WebAXObject
& anchorObject
, int& anchorOffset
,
203 WebAXObject
& focusObject
, int& focusOffset
) const;
204 BLINK_EXPORT
void setSelection(const WebAXObject
& anchorObject
, int anchorOffset
,
205 const WebAXObject
& focusObject
, int focusOffset
) const;
207 // The following selection functions return text offsets calculated starting
208 // the current object. They only report on a selection that is placed on
209 // the current object or on any of its descendants.
210 BLINK_EXPORT
unsigned selectionEnd() const;
211 BLINK_EXPORT
unsigned selectionEndLineNumber() const;
212 BLINK_EXPORT
unsigned selectionStart() const;
213 BLINK_EXPORT
unsigned selectionStartLineNumber() const;
215 // 1-based position in set & Size of set.
216 BLINK_EXPORT
int posInSet() const;
217 BLINK_EXPORT
int setSize() const;
220 BLINK_EXPORT
bool isInLiveRegion() const;
221 BLINK_EXPORT
bool liveRegionAtomic() const;
222 BLINK_EXPORT
bool liveRegionBusy() const;
223 BLINK_EXPORT WebString
liveRegionRelevant() const;
224 BLINK_EXPORT WebString
liveRegionStatus() const;
225 BLINK_EXPORT
bool containerLiveRegionAtomic() const;
226 BLINK_EXPORT
bool containerLiveRegionBusy() const;
227 BLINK_EXPORT WebString
containerLiveRegionRelevant() const;
228 BLINK_EXPORT WebString
containerLiveRegionStatus() const;
230 BLINK_EXPORT
bool supportsRangeValue() const;
231 BLINK_EXPORT WebString
valueDescription() const;
232 BLINK_EXPORT
float valueForRange() const;
233 BLINK_EXPORT
float maxValueForRange() const;
234 BLINK_EXPORT
float minValueForRange() const;
236 BLINK_EXPORT WebNode
node() const;
237 BLINK_EXPORT WebDocument
document() const;
238 BLINK_EXPORT
bool hasComputedStyle() const;
239 BLINK_EXPORT WebString
computedStyleDisplay() const;
240 BLINK_EXPORT
bool accessibilityIsIgnored() const;
241 BLINK_EXPORT
bool lineBreaks(WebVector
<int>&) const;
244 BLINK_EXPORT WebString
actionVerb() const; // The verb corresponding to performDefaultAction.
245 BLINK_EXPORT
bool canDecrement() const;
246 BLINK_EXPORT
bool canIncrement() const;
247 BLINK_EXPORT
bool canPress() const;
248 BLINK_EXPORT
bool canSetFocusAttribute() const;
249 BLINK_EXPORT
bool canSetSelectedAttribute() const;
250 BLINK_EXPORT
bool canSetValueAttribute() const;
251 BLINK_EXPORT
bool performDefaultAction() const;
252 BLINK_EXPORT
bool press() const;
253 BLINK_EXPORT
bool increment() const;
254 BLINK_EXPORT
bool decrement() const;
255 BLINK_EXPORT
void setFocused(bool) const;
256 BLINK_EXPORT
void setSelectedTextRange(int selectionStart
, int selectionEnd
) const;
257 BLINK_EXPORT
void setValue(WebString
) const;
258 BLINK_EXPORT
void showContextMenu() const;
261 BLINK_EXPORT
unsigned columnCount() const;
262 BLINK_EXPORT
unsigned rowCount() const;
263 BLINK_EXPORT WebAXObject
cellForColumnAndRow(unsigned column
, unsigned row
) const;
264 BLINK_EXPORT WebAXObject
headerContainerObject() const;
265 BLINK_EXPORT WebAXObject
rowAtIndex(unsigned rowIndex
) const;
266 BLINK_EXPORT WebAXObject
columnAtIndex(unsigned columnIndex
) const;
267 BLINK_EXPORT
void rowHeaders(WebVector
<WebAXObject
>&) const;
268 BLINK_EXPORT
void columnHeaders(WebVector
<WebAXObject
>&) const;
271 BLINK_EXPORT
unsigned rowIndex() const;
272 BLINK_EXPORT WebAXObject
rowHeader() const;
274 // For a table column
275 BLINK_EXPORT
unsigned columnIndex() const;
276 BLINK_EXPORT WebAXObject
columnHeader() const;
279 BLINK_EXPORT
unsigned cellColumnIndex() const;
280 BLINK_EXPORT
unsigned cellColumnSpan() const;
281 BLINK_EXPORT
unsigned cellRowIndex() const;
282 BLINK_EXPORT
unsigned cellRowSpan() const;
283 BLINK_EXPORT WebAXSortDirection
sortDirection() const;
285 // Load inline text boxes for just this subtree, even if
286 // settings->inlineTextBoxAccessibilityEnabled() is false.
287 BLINK_EXPORT
void loadInlineTextBoxes() const;
289 // Walk the WebAXObjects on the same line. This is supported on any
290 // object type but primarily intended to be used for inline text boxes.
291 BLINK_EXPORT WebAXObject
nextOnLine() const;
292 BLINK_EXPORT WebAXObject
previousOnLine() const;
294 // For an inline text box.
295 BLINK_EXPORT
void characterOffsets(WebVector
<int>&) const;
296 BLINK_EXPORT
void wordBoundaries(WebVector
<int>& starts
, WebVector
<int>& ends
) const;
298 // Scrollable containers.
299 BLINK_EXPORT
bool isScrollableContainer() const;
300 BLINK_EXPORT WebPoint
scrollOffset() const;
301 BLINK_EXPORT WebPoint
minimumScrollOffset() const;
302 BLINK_EXPORT WebPoint
maximumScrollOffset() const;
303 BLINK_EXPORT
void setScrollOffset(const WebPoint
&) const;
305 // Make this object visible by scrolling as many nested scrollable views as needed.
306 BLINK_EXPORT
void scrollToMakeVisible() const;
307 // Same, but if the whole object can't be made visible, try for this subrect, in local coordinates.
308 BLINK_EXPORT
void scrollToMakeVisibleWithSubFocus(const WebRect
&) const;
309 // Scroll this object to a given point in global coordinates of the top-level window.
310 BLINK_EXPORT
void scrollToGlobalPoint(const WebPoint
&) const;
312 #if BLINK_IMPLEMENTATION
313 WebAXObject(AXObject
*);
314 WebAXObject
& operator=(AXObject
*);
315 operator AXObject
*() const;
319 WebPrivatePtr
<AXObject
> m_private
;