1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/test_runner/web_ax_object_proxy.h"
7 #include "base/strings/stringprintf.h"
8 #include "gin/handle.h"
9 #include "third_party/WebKit/public/platform/WebPoint.h"
10 #include "third_party/WebKit/public/platform/WebRect.h"
11 #include "third_party/WebKit/public/platform/WebString.h"
12 #include "third_party/WebKit/public/web/WebFrame.h"
13 #include "third_party/WebKit/public/web/WebKit.h"
15 namespace test_runner
{
19 // Map role value to string, matching Safari/Mac platform implementation to
20 // avoid rebaselining layout tests.
21 std::string
RoleToString(blink::WebAXRole role
)
23 std::string result
= "AXRole: AX";
25 case blink::WebAXRoleAlertDialog
:
26 return result
.append("AlertDialog");
27 case blink::WebAXRoleAlert
:
28 return result
.append("Alert");
29 case blink::WebAXRoleAnnotation
:
30 return result
.append("Annotation");
31 case blink::WebAXRoleApplication
:
32 return result
.append("Application");
33 case blink::WebAXRoleArticle
:
34 return result
.append("Article");
35 case blink::WebAXRoleBanner
:
36 return result
.append("Banner");
37 case blink::WebAXRoleBlockquote
:
38 return result
.append("Blockquote");
39 case blink::WebAXRoleBusyIndicator
:
40 return result
.append("BusyIndicator");
41 case blink::WebAXRoleButton
:
42 return result
.append("Button");
43 case blink::WebAXRoleCanvas
:
44 return result
.append("Canvas");
45 case blink::WebAXRoleCaption
:
46 return result
.append("Caption");
47 case blink::WebAXRoleCell
:
48 return result
.append("Cell");
49 case blink::WebAXRoleCheckBox
:
50 return result
.append("CheckBox");
51 case blink::WebAXRoleColorWell
:
52 return result
.append("ColorWell");
53 case blink::WebAXRoleColumnHeader
:
54 return result
.append("ColumnHeader");
55 case blink::WebAXRoleColumn
:
56 return result
.append("Column");
57 case blink::WebAXRoleComboBox
:
58 return result
.append("ComboBox");
59 case blink::WebAXRoleComplementary
:
60 return result
.append("Complementary");
61 case blink::WebAXRoleContentInfo
:
62 return result
.append("ContentInfo");
63 case blink::WebAXRoleDate
:
64 return result
.append("DateField");
65 case blink::WebAXRoleDateTime
:
66 return result
.append("DateTimeField");
67 case blink::WebAXRoleDefinition
:
68 return result
.append("Definition");
69 case blink::WebAXRoleDescriptionListDetail
:
70 return result
.append("DescriptionListDetail");
71 case blink::WebAXRoleDescriptionList
:
72 return result
.append("DescriptionList");
73 case blink::WebAXRoleDescriptionListTerm
:
74 return result
.append("DescriptionListTerm");
75 case blink::WebAXRoleDetails
:
76 return result
.append("Details");
77 case blink::WebAXRoleDialog
:
78 return result
.append("Dialog");
79 case blink::WebAXRoleDirectory
:
80 return result
.append("Directory");
81 case blink::WebAXRoleDisclosureTriangle
:
82 return result
.append("DisclosureTriangle");
83 case blink::WebAXRoleDiv
:
84 return result
.append("Div");
85 case blink::WebAXRoleDocument
:
86 return result
.append("Document");
87 case blink::WebAXRoleEmbeddedObject
:
88 return result
.append("EmbeddedObject");
89 case blink::WebAXRoleFigcaption
:
90 return result
.append("Figcaption");
91 case blink::WebAXRoleFigure
:
92 return result
.append("Figure");
93 case blink::WebAXRoleFooter
:
94 return result
.append("Footer");
95 case blink::WebAXRoleForm
:
96 return result
.append("Form");
97 case blink::WebAXRoleGrid
:
98 return result
.append("Grid");
99 case blink::WebAXRoleGroup
:
100 return result
.append("Group");
101 case blink::WebAXRoleHeading
:
102 return result
.append("Heading");
103 case blink::WebAXRoleIgnored
:
104 return result
.append("Ignored");
105 case blink::WebAXRoleImageMapLink
:
106 return result
.append("ImageMapLink");
107 case blink::WebAXRoleImageMap
:
108 return result
.append("ImageMap");
109 case blink::WebAXRoleImage
:
110 return result
.append("Image");
111 case blink::WebAXRoleInlineTextBox
:
112 return result
.append("InlineTextBox");
113 case blink::WebAXRoleInputTime
:
114 return result
.append("InputTime");
115 case blink::WebAXRoleLabel
:
116 return result
.append("Label");
117 case blink::WebAXRoleLegend
:
118 return result
.append("Legend");
119 case blink::WebAXRoleLink
:
120 return result
.append("Link");
121 case blink::WebAXRoleListBoxOption
:
122 return result
.append("ListBoxOption");
123 case blink::WebAXRoleListBox
:
124 return result
.append("ListBox");
125 case blink::WebAXRoleListItem
:
126 return result
.append("ListItem");
127 case blink::WebAXRoleListMarker
:
128 return result
.append("ListMarker");
129 case blink::WebAXRoleList
:
130 return result
.append("List");
131 case blink::WebAXRoleLog
:
132 return result
.append("Log");
133 case blink::WebAXRoleMain
:
134 return result
.append("Main");
135 case blink::WebAXRoleMark
:
136 return result
.append("Mark");
137 case blink::WebAXRoleMarquee
:
138 return result
.append("Marquee");
139 case blink::WebAXRoleMath
:
140 return result
.append("Math");
141 case blink::WebAXRoleMenuBar
:
142 return result
.append("MenuBar");
143 case blink::WebAXRoleMenuButton
:
144 return result
.append("MenuButton");
145 case blink::WebAXRoleMenuItem
:
146 return result
.append("MenuItem");
147 case blink::WebAXRoleMenuItemCheckBox
:
148 return result
.append("MenuItemCheckBox");
149 case blink::WebAXRoleMenuItemRadio
:
150 return result
.append("MenuItemRadio");
151 case blink::WebAXRoleMenuListOption
:
152 return result
.append("MenuListOption");
153 case blink::WebAXRoleMenuListPopup
:
154 return result
.append("MenuListPopup");
155 case blink::WebAXRoleMenu
:
156 return result
.append("Menu");
157 case blink::WebAXRoleMeter
:
158 return result
.append("Meter");
159 case blink::WebAXRoleNavigation
:
160 return result
.append("Navigation");
161 case blink::WebAXRoleNone
:
162 return result
.append("None");
163 case blink::WebAXRoleNote
:
164 return result
.append("Note");
165 case blink::WebAXRoleOutline
:
166 return result
.append("Outline");
167 case blink::WebAXRoleParagraph
:
168 return result
.append("Paragraph");
169 case blink::WebAXRolePopUpButton
:
170 return result
.append("PopUpButton");
171 case blink::WebAXRolePre
:
172 return result
.append("Pre");
173 case blink::WebAXRolePresentational
:
174 return result
.append("Presentational");
175 case blink::WebAXRoleProgressIndicator
:
176 return result
.append("ProgressIndicator");
177 case blink::WebAXRoleRadioButton
:
178 return result
.append("RadioButton");
179 case blink::WebAXRoleRadioGroup
:
180 return result
.append("RadioGroup");
181 case blink::WebAXRoleRegion
:
182 return result
.append("Region");
183 case blink::WebAXRoleRootWebArea
:
184 return result
.append("RootWebArea");
185 case blink::WebAXRoleRowHeader
:
186 return result
.append("RowHeader");
187 case blink::WebAXRoleRow
:
188 return result
.append("Row");
189 case blink::WebAXRoleRuby
:
190 return result
.append("Ruby");
191 case blink::WebAXRoleRuler
:
192 return result
.append("Ruler");
193 case blink::WebAXRoleSVGRoot
:
194 return result
.append("SVGRoot");
195 case blink::WebAXRoleScrollArea
:
196 return result
.append("ScrollArea");
197 case blink::WebAXRoleScrollBar
:
198 return result
.append("ScrollBar");
199 case blink::WebAXRoleSeamlessWebArea
:
200 return result
.append("SeamlessWebArea");
201 case blink::WebAXRoleSearch
:
202 return result
.append("Search");
203 case blink::WebAXRoleSearchBox
:
204 return result
.append("SearchBox");
205 case blink::WebAXRoleSlider
:
206 return result
.append("Slider");
207 case blink::WebAXRoleSliderThumb
:
208 return result
.append("SliderThumb");
209 case blink::WebAXRoleSpinButtonPart
:
210 return result
.append("SpinButtonPart");
211 case blink::WebAXRoleSpinButton
:
212 return result
.append("SpinButton");
213 case blink::WebAXRoleSplitter
:
214 return result
.append("Splitter");
215 case blink::WebAXRoleStaticText
:
216 return result
.append("StaticText");
217 case blink::WebAXRoleStatus
:
218 return result
.append("Status");
219 case blink::WebAXRoleSwitch
:
220 return result
.append("Switch");
221 case blink::WebAXRoleTabGroup
:
222 return result
.append("TabGroup");
223 case blink::WebAXRoleTabList
:
224 return result
.append("TabList");
225 case blink::WebAXRoleTabPanel
:
226 return result
.append("TabPanel");
227 case blink::WebAXRoleTab
:
228 return result
.append("Tab");
229 case blink::WebAXRoleTableHeaderContainer
:
230 return result
.append("TableHeaderContainer");
231 case blink::WebAXRoleTable
:
232 return result
.append("Table");
233 case blink::WebAXRoleTextField
:
234 return result
.append("TextField");
235 case blink::WebAXRoleTime
:
236 return result
.append("Time");
237 case blink::WebAXRoleTimer
:
238 return result
.append("Timer");
239 case blink::WebAXRoleToggleButton
:
240 return result
.append("ToggleButton");
241 case blink::WebAXRoleToolbar
:
242 return result
.append("Toolbar");
243 case blink::WebAXRoleTreeGrid
:
244 return result
.append("TreeGrid");
245 case blink::WebAXRoleTreeItem
:
246 return result
.append("TreeItem");
247 case blink::WebAXRoleTree
:
248 return result
.append("Tree");
249 case blink::WebAXRoleUnknown
:
250 return result
.append("Unknown");
251 case blink::WebAXRoleUserInterfaceTooltip
:
252 return result
.append("UserInterfaceTooltip");
253 case blink::WebAXRoleWebArea
:
254 return result
.append("WebArea");
255 case blink::WebAXRoleWindow
:
256 return result
.append("Window");
258 return result
.append("Unknown");
262 std::string
DeprecatedGetDescription(const blink::WebAXObject
& object
) {
263 std::string description
= object
.deprecatedAccessibilityDescription().utf8();
264 return description
.insert(0, "AXDescription: ");
267 std::string
DeprecatedGetHelpText(const blink::WebAXObject
& object
) {
268 std::string help_text
= object
.deprecatedHelpText().utf8();
269 return help_text
.insert(0, "AXHelp: ");
272 std::string
GetStringValue(const blink::WebAXObject
& object
) {
274 if (object
.role() == blink::WebAXRoleColorWell
) {
275 unsigned int color
= object
.colorValue();
276 unsigned int red
= (color
>> 16) & 0xFF;
277 unsigned int green
= (color
>> 8) & 0xFF;
278 unsigned int blue
= color
& 0xFF;
279 value
= base::StringPrintf("rgba(%d, %d, %d, 1)",
282 value
= object
.stringValue().utf8();
284 return value
.insert(0, "AXValue: ");
287 std::string
GetRole(const blink::WebAXObject
& object
) {
288 std::string role_string
= RoleToString(object
.role());
290 // Special-case canvas with fallback content because Chromium wants to treat
291 // this as essentially a separate role that it can map differently depending
293 if (object
.role() == blink::WebAXRoleCanvas
&&
294 object
.canvasHasFallbackContent()) {
295 role_string
+= "WithFallbackContent";
301 std::string
DeprecatedGetTitle(const blink::WebAXObject
& object
) {
302 std::string title
= object
.deprecatedTitle().utf8();
303 return title
.insert(0, "AXTitle: ");
306 std::string
GetValueDescription(const blink::WebAXObject
& object
) {
307 std::string value_description
= object
.valueDescription().utf8();
308 return value_description
.insert(0, "AXValueDescription: ");
311 std::string
GetLanguage(const blink::WebAXObject
& object
) {
312 std::string language
= object
.language().utf8();
313 return language
.insert(0, "AXLanguage: ");
316 std::string
GetAttributes(const blink::WebAXObject
& object
) {
317 // FIXME: Concatenate all attributes of the AXObject.
318 std::string
attributes(DeprecatedGetTitle(object
));
319 attributes
.append("\n");
320 attributes
.append(GetRole(object
));
321 attributes
.append("\n");
322 attributes
.append(DeprecatedGetDescription(object
));
326 blink::WebRect
BoundsForCharacter(const blink::WebAXObject
& object
,
327 int characterIndex
) {
328 DCHECK_EQ(object
.role(), blink::WebAXRoleStaticText
);
330 for (unsigned i
= 0; i
< object
.childCount(); i
++) {
331 blink::WebAXObject inline_text_box
= object
.childAt(i
);
332 DCHECK_EQ(inline_text_box
.role(), blink::WebAXRoleInlineTextBox
);
334 end
+= inline_text_box
.stringValue().length();
335 if (characterIndex
< start
|| characterIndex
>= end
)
337 blink::WebRect inline_text_box_rect
= inline_text_box
.boundingBoxRect();
338 int localIndex
= characterIndex
- start
;
339 blink::WebVector
<int> character_offsets
;
340 inline_text_box
.characterOffsets(character_offsets
);
341 DCHECK(character_offsets
.size() > 0 &&
342 character_offsets
.size() == inline_text_box
.stringValue().length());
343 switch (inline_text_box
.textDirection()) {
344 case blink::WebAXTextDirectionLR
: {
346 int left
= inline_text_box_rect
.x
+ character_offsets
[localIndex
- 1];
347 int width
= character_offsets
[localIndex
] -
348 character_offsets
[localIndex
- 1];
349 return blink::WebRect(left
, inline_text_box_rect
.y
,
350 width
, inline_text_box_rect
.height
);
352 return blink::WebRect(
353 inline_text_box_rect
.x
, inline_text_box_rect
.y
,
354 character_offsets
[0], inline_text_box_rect
.height
);
356 case blink::WebAXTextDirectionRL
: {
357 int right
= inline_text_box_rect
.x
+ inline_text_box_rect
.width
;
360 int left
= right
- character_offsets
[localIndex
];
361 int width
= character_offsets
[localIndex
] -
362 character_offsets
[localIndex
- 1];
363 return blink::WebRect(left
, inline_text_box_rect
.y
,
364 width
, inline_text_box_rect
.height
);
366 int left
= right
- character_offsets
[0];
367 return blink::WebRect(
368 left
, inline_text_box_rect
.y
,
369 character_offsets
[0], inline_text_box_rect
.height
);
371 case blink::WebAXTextDirectionTB
: {
373 int top
= inline_text_box_rect
.y
+ character_offsets
[localIndex
- 1];
374 int height
= character_offsets
[localIndex
] -
375 character_offsets
[localIndex
- 1];
376 return blink::WebRect(inline_text_box_rect
.x
, top
,
377 inline_text_box_rect
.width
, height
);
379 return blink::WebRect(inline_text_box_rect
.x
, inline_text_box_rect
.y
,
380 inline_text_box_rect
.width
, character_offsets
[0]);
382 case blink::WebAXTextDirectionBT
: {
383 int bottom
= inline_text_box_rect
.y
+ inline_text_box_rect
.height
;
386 int top
= bottom
- character_offsets
[localIndex
];
387 int height
= character_offsets
[localIndex
] -
388 character_offsets
[localIndex
- 1];
389 return blink::WebRect(inline_text_box_rect
.x
, top
,
390 inline_text_box_rect
.width
, height
);
392 int top
= bottom
- character_offsets
[0];
393 return blink::WebRect(inline_text_box_rect
.x
, top
,
394 inline_text_box_rect
.width
, character_offsets
[0]);
400 return blink::WebRect();
403 void GetBoundariesForOneWord(const blink::WebAXObject
& object
,
408 for (unsigned i
= 0; i
< object
.childCount(); i
++) {
409 blink::WebAXObject inline_text_box
= object
.childAt(i
);
410 DCHECK_EQ(inline_text_box
.role(), blink::WebAXRoleInlineTextBox
);
412 end
+= inline_text_box
.stringValue().length();
413 if (end
<= character_index
)
415 int localIndex
= character_index
- start
;
417 blink::WebVector
<int> starts
;
418 blink::WebVector
<int> ends
;
419 inline_text_box
.wordBoundaries(starts
, ends
);
420 size_t word_count
= starts
.size();
421 DCHECK_EQ(ends
.size(), word_count
);
423 // If there are no words, use the InlineTextBox boundaries.
430 // Look for a character within any word other than the last.
431 for (size_t j
= 0; j
< word_count
- 1; j
++) {
432 if (localIndex
<= ends
[j
]) {
433 word_start
= start
+ starts
[j
];
434 word_end
= start
+ ends
[j
];
439 // Return the last word by default.
440 word_start
= start
+ starts
[word_count
- 1];
441 word_end
= start
+ ends
[word_count
- 1];
446 // Collects attributes into a string, delimited by dashes. Used by all methods
447 // that output lists of attributes: attributesOfLinkedUIElementsCallback,
448 // AttributesOfChildrenCallback, etc.
449 class AttributesCollector
{
451 AttributesCollector() {}
452 ~AttributesCollector() {}
454 void CollectAttributes(const blink::WebAXObject
& object
) {
455 attributes_
.append("\n------------\n");
456 attributes_
.append(GetAttributes(object
));
459 std::string
attributes() const { return attributes_
; }
462 std::string attributes_
;
464 DISALLOW_COPY_AND_ASSIGN(AttributesCollector
);
469 gin::WrapperInfo
WebAXObjectProxy::kWrapperInfo
= {
470 gin::kEmbedderNativeGin
};
472 WebAXObjectProxy::WebAXObjectProxy(const blink::WebAXObject
& object
,
473 WebAXObjectProxy::Factory
* factory
)
474 : accessibility_object_(object
),
478 WebAXObjectProxy::~WebAXObjectProxy() {}
480 gin::ObjectTemplateBuilder
481 WebAXObjectProxy::GetObjectTemplateBuilder(v8::Isolate
* isolate
) {
482 return gin::Wrappable
<WebAXObjectProxy
>::GetObjectTemplateBuilder(isolate
)
483 .SetProperty("role", &WebAXObjectProxy::Role
)
484 .SetProperty("stringValue", &WebAXObjectProxy::StringValue
)
485 .SetProperty("language", &WebAXObjectProxy::Language
)
486 .SetProperty("x", &WebAXObjectProxy::X
)
487 .SetProperty("y", &WebAXObjectProxy::Y
)
488 .SetProperty("width", &WebAXObjectProxy::Width
)
489 .SetProperty("height", &WebAXObjectProxy::Height
)
490 .SetProperty("intValue", &WebAXObjectProxy::IntValue
)
491 .SetProperty("minValue", &WebAXObjectProxy::MinValue
)
492 .SetProperty("maxValue", &WebAXObjectProxy::MaxValue
)
493 .SetProperty("valueDescription", &WebAXObjectProxy::ValueDescription
)
494 .SetProperty("childrenCount", &WebAXObjectProxy::ChildrenCount
)
495 .SetProperty("selectionAnchorObject",
496 &WebAXObjectProxy::SelectionAnchorObject
)
497 .SetProperty("selectionAnchorOffset",
498 &WebAXObjectProxy::SelectionAnchorOffset
)
499 .SetProperty("selectionFocusObject",
500 &WebAXObjectProxy::SelectionFocusObject
)
501 .SetProperty("selectionFocusOffset",
502 &WebAXObjectProxy::SelectionFocusOffset
)
503 .SetProperty("selectionStart", &WebAXObjectProxy::SelectionStart
)
504 .SetProperty("selectionEnd", &WebAXObjectProxy::SelectionEnd
)
505 .SetProperty("selectionStartLineNumber",
506 &WebAXObjectProxy::SelectionStartLineNumber
)
507 .SetProperty("selectionEndLineNumber",
508 &WebAXObjectProxy::SelectionEndLineNumber
)
509 .SetProperty("isEnabled", &WebAXObjectProxy::IsEnabled
)
510 .SetProperty("isRequired", &WebAXObjectProxy::IsRequired
)
511 .SetProperty("isRichlyEditable", &WebAXObjectProxy::IsRichlyEditable
)
512 .SetProperty("isFocused", &WebAXObjectProxy::IsFocused
)
513 .SetProperty("isFocusable", &WebAXObjectProxy::IsFocusable
)
514 .SetProperty("isSelected", &WebAXObjectProxy::IsSelected
)
515 .SetProperty("isSelectable", &WebAXObjectProxy::IsSelectable
)
516 .SetProperty("isMultiSelectable", &WebAXObjectProxy::IsMultiSelectable
)
517 .SetProperty("isSelectedOptionActive",
518 &WebAXObjectProxy::IsSelectedOptionActive
)
519 .SetProperty("isExpanded", &WebAXObjectProxy::IsExpanded
)
520 .SetProperty("isChecked", &WebAXObjectProxy::IsChecked
)
521 .SetProperty("isVisible", &WebAXObjectProxy::IsVisible
)
522 .SetProperty("isOffScreen", &WebAXObjectProxy::IsOffScreen
)
523 .SetProperty("isCollapsed", &WebAXObjectProxy::IsCollapsed
)
524 .SetProperty("hasPopup", &WebAXObjectProxy::HasPopup
)
525 .SetProperty("isValid", &WebAXObjectProxy::IsValid
)
526 .SetProperty("isReadOnly", &WebAXObjectProxy::IsReadOnly
)
527 .SetProperty("backgroundColor", &WebAXObjectProxy::BackgroundColor
)
528 .SetProperty("color", &WebAXObjectProxy::Color
)
529 .SetProperty("colorValue", &WebAXObjectProxy::ColorValue
)
530 .SetProperty("fontSize", &WebAXObjectProxy::FontSize
)
531 .SetProperty("orientation", &WebAXObjectProxy::Orientation
)
532 .SetProperty("posInSet", &WebAXObjectProxy::PosInSet
)
533 .SetProperty("setSize", &WebAXObjectProxy::SetSize
)
534 .SetProperty("clickPointX", &WebAXObjectProxy::ClickPointX
)
535 .SetProperty("clickPointY", &WebAXObjectProxy::ClickPointY
)
536 .SetProperty("rowCount", &WebAXObjectProxy::RowCount
)
537 .SetProperty("rowHeadersCount", &WebAXObjectProxy::RowHeadersCount
)
538 .SetProperty("columnCount", &WebAXObjectProxy::ColumnCount
)
539 .SetProperty("columnHeadersCount", &WebAXObjectProxy::ColumnHeadersCount
)
540 .SetProperty("isClickable", &WebAXObjectProxy::IsClickable
)
541 .SetProperty("isButtonStateMixed", &WebAXObjectProxy::IsButtonStateMixed
)
542 .SetMethod("allAttributes", &WebAXObjectProxy::AllAttributes
)
543 .SetMethod("attributesOfChildren",
544 &WebAXObjectProxy::AttributesOfChildren
)
545 .SetMethod("ariaControlsElementAtIndex",
546 &WebAXObjectProxy::AriaControlsElementAtIndex
)
547 .SetMethod("ariaFlowToElementAtIndex",
548 &WebAXObjectProxy::AriaFlowToElementAtIndex
)
549 .SetMethod("ariaOwnsElementAtIndex",
550 &WebAXObjectProxy::AriaOwnsElementAtIndex
)
551 .SetMethod("lineForIndex", &WebAXObjectProxy::LineForIndex
)
552 .SetMethod("boundsForRange", &WebAXObjectProxy::BoundsForRange
)
553 .SetMethod("childAtIndex", &WebAXObjectProxy::ChildAtIndex
)
554 .SetMethod("elementAtPoint", &WebAXObjectProxy::ElementAtPoint
)
555 .SetMethod("tableHeader", &WebAXObjectProxy::TableHeader
)
556 .SetMethod("rowHeaderAtIndex", &WebAXObjectProxy::RowHeaderAtIndex
)
557 .SetMethod("columnHeaderAtIndex", &WebAXObjectProxy::ColumnHeaderAtIndex
)
558 .SetMethod("rowIndexRange", &WebAXObjectProxy::RowIndexRange
)
559 .SetMethod("columnIndexRange", &WebAXObjectProxy::ColumnIndexRange
)
560 .SetMethod("cellForColumnAndRow", &WebAXObjectProxy::CellForColumnAndRow
)
561 .SetMethod("setSelectedTextRange",
562 &WebAXObjectProxy::SetSelectedTextRange
)
563 .SetMethod("setSelection",
564 &WebAXObjectProxy::SetSelection
)
565 .SetMethod("isAttributeSettable", &WebAXObjectProxy::IsAttributeSettable
)
566 .SetMethod("isPressActionSupported",
567 &WebAXObjectProxy::IsPressActionSupported
)
568 .SetMethod("isIncrementActionSupported",
569 &WebAXObjectProxy::IsIncrementActionSupported
)
570 .SetMethod("isDecrementActionSupported",
571 &WebAXObjectProxy::IsDecrementActionSupported
)
572 .SetMethod("parentElement", &WebAXObjectProxy::ParentElement
)
573 .SetMethod("increment", &WebAXObjectProxy::Increment
)
574 .SetMethod("decrement", &WebAXObjectProxy::Decrement
)
575 .SetMethod("showMenu", &WebAXObjectProxy::ShowMenu
)
576 .SetMethod("press", &WebAXObjectProxy::Press
)
577 .SetMethod("isEqual", &WebAXObjectProxy::IsEqual
)
578 .SetMethod("setNotificationListener",
579 &WebAXObjectProxy::SetNotificationListener
)
580 .SetMethod("unsetNotificationListener",
581 &WebAXObjectProxy::UnsetNotificationListener
)
582 .SetMethod("takeFocus", &WebAXObjectProxy::TakeFocus
)
583 .SetMethod("scrollToMakeVisible", &WebAXObjectProxy::ScrollToMakeVisible
)
584 .SetMethod("scrollToMakeVisibleWithSubFocus",
585 &WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus
)
586 .SetMethod("scrollToGlobalPoint", &WebAXObjectProxy::ScrollToGlobalPoint
)
587 .SetMethod("wordStart", &WebAXObjectProxy::WordStart
)
588 .SetMethod("wordEnd", &WebAXObjectProxy::WordEnd
)
589 .SetMethod("nextOnLine", &WebAXObjectProxy::NextOnLine
)
590 .SetMethod("previousOnLine", &WebAXObjectProxy::PreviousOnLine
)
591 // TODO(hajimehoshi): This is for backward compatibility. Remove them.
592 .SetMethod("addNotificationListener",
593 &WebAXObjectProxy::SetNotificationListener
)
594 .SetMethod("removeNotificationListener",
595 &WebAXObjectProxy::UnsetNotificationListener
)
597 // DEPRECATED accessible name and description accessors
599 .SetProperty("title", &WebAXObjectProxy::DeprecatedTitle
)
600 .SetProperty("description", &WebAXObjectProxy::DeprecatedDescription
)
601 .SetProperty("helpText", &WebAXObjectProxy::DeprecatedHelpText
)
602 .SetMethod("titleUIElement", &WebAXObjectProxy::DeprecatedTitleUIElement
)
603 .SetProperty("deprecatedTitle",
604 &WebAXObjectProxy::DeprecatedTitle
)
605 .SetProperty("deprecatedDescription",
606 &WebAXObjectProxy::DeprecatedDescription
)
607 .SetProperty("deprecatedHelpText",
608 &WebAXObjectProxy::DeprecatedHelpText
)
609 .SetMethod("deprecatedTitleUIElement",
610 &WebAXObjectProxy::DeprecatedTitleUIElement
)
612 // NEW accessible name and description accessors
614 .SetProperty("name", &WebAXObjectProxy::Name
)
615 .SetProperty("nameFrom", &WebAXObjectProxy::NameFrom
)
616 .SetMethod("nameElementCount", &WebAXObjectProxy::NameElementCount
)
617 .SetMethod("nameElementAtIndex", &WebAXObjectProxy::NameElementAtIndex
);
618 // TODO(dmazzoni): add "description", etc. once LayoutTests have
619 // been updated to call deprecatedDescription instead.
623 v8::Local
<v8::Object
> WebAXObjectProxy::GetChildAtIndex(unsigned index
) {
624 return factory_
->GetOrCreate(accessibility_object_
.childAt(index
));
627 bool WebAXObjectProxy::IsRoot() const {
631 bool WebAXObjectProxy::IsEqualToObject(const blink::WebAXObject
& other
) {
632 return accessibility_object_
.equals(other
);
635 void WebAXObjectProxy::NotificationReceived(
636 blink::WebFrame
* frame
,
637 const std::string
& notification_name
) {
638 if (notification_callback_
.IsEmpty())
641 v8::Local
<v8::Context
> context
= frame
->mainWorldScriptContext();
642 if (context
.IsEmpty())
645 v8::Isolate
* isolate
= blink::mainThreadIsolate();
647 v8::Local
<v8::Value
> argv
[] = {
648 v8::String::NewFromUtf8(isolate
, notification_name
.data(),
649 v8::String::kNormalString
,
650 notification_name
.size()),
652 frame
->callFunctionEvenIfScriptDisabled(
653 v8::Local
<v8::Function
>::New(isolate
, notification_callback_
),
659 void WebAXObjectProxy::Reset() {
660 notification_callback_
.Reset();
663 std::string
WebAXObjectProxy::Role() {
664 accessibility_object_
.updateLayoutAndCheckValidity();
665 return GetRole(accessibility_object_
);
668 std::string
WebAXObjectProxy::DeprecatedTitle() {
669 accessibility_object_
.updateLayoutAndCheckValidity();
670 return DeprecatedGetTitle(accessibility_object_
);
673 std::string
WebAXObjectProxy::DeprecatedDescription() {
674 accessibility_object_
.updateLayoutAndCheckValidity();
675 return DeprecatedGetDescription(accessibility_object_
);
678 std::string
WebAXObjectProxy::DeprecatedHelpText() {
679 accessibility_object_
.updateLayoutAndCheckValidity();
680 return DeprecatedGetHelpText(accessibility_object_
);
683 std::string
WebAXObjectProxy::StringValue() {
684 accessibility_object_
.updateLayoutAndCheckValidity();
685 return GetStringValue(accessibility_object_
);
688 std::string
WebAXObjectProxy::Language() {
689 accessibility_object_
.updateLayoutAndCheckValidity();
690 return GetLanguage(accessibility_object_
);
693 int WebAXObjectProxy::X() {
694 accessibility_object_
.updateLayoutAndCheckValidity();
695 return accessibility_object_
.boundingBoxRect().x
;
698 int WebAXObjectProxy::Y() {
699 accessibility_object_
.updateLayoutAndCheckValidity();
700 return accessibility_object_
.boundingBoxRect().y
;
703 int WebAXObjectProxy::Width() {
704 accessibility_object_
.updateLayoutAndCheckValidity();
705 return accessibility_object_
.boundingBoxRect().width
;
708 int WebAXObjectProxy::Height() {
709 accessibility_object_
.updateLayoutAndCheckValidity();
710 return accessibility_object_
.boundingBoxRect().height
;
713 int WebAXObjectProxy::IntValue() {
714 accessibility_object_
.updateLayoutAndCheckValidity();
715 if (accessibility_object_
.supportsRangeValue())
716 return accessibility_object_
.valueForRange();
717 else if (accessibility_object_
.role() == blink::WebAXRoleHeading
)
718 return accessibility_object_
.headingLevel();
720 return atoi(accessibility_object_
.stringValue().utf8().data());
723 int WebAXObjectProxy::MinValue() {
724 accessibility_object_
.updateLayoutAndCheckValidity();
725 return accessibility_object_
.minValueForRange();
728 int WebAXObjectProxy::MaxValue() {
729 accessibility_object_
.updateLayoutAndCheckValidity();
730 return accessibility_object_
.maxValueForRange();
733 std::string
WebAXObjectProxy::ValueDescription() {
734 accessibility_object_
.updateLayoutAndCheckValidity();
735 return GetValueDescription(accessibility_object_
);
738 int WebAXObjectProxy::ChildrenCount() {
739 accessibility_object_
.updateLayoutAndCheckValidity();
740 int count
= 1; // Root object always has only one child, the WebView.
742 count
= accessibility_object_
.childCount();
746 v8::Local
<v8::Value
> WebAXObjectProxy::SelectionAnchorObject() {
747 accessibility_object_
.updateLayoutAndCheckValidity();
749 blink::WebAXObject anchorObject
;
750 int anchorOffset
= -1;
751 blink::WebAXObject focusObject
;
752 int focusOffset
= -1;
753 accessibility_object_
.selection(anchorObject
, anchorOffset
,
754 focusObject
, focusOffset
);
755 if (anchorObject
.isNull())
756 return v8::Null(blink::mainThreadIsolate());
758 return factory_
->GetOrCreate(anchorObject
);
761 int WebAXObjectProxy::SelectionAnchorOffset() {
762 accessibility_object_
.updateLayoutAndCheckValidity();
764 blink::WebAXObject anchorObject
;
765 int anchorOffset
= -1;
766 blink::WebAXObject focusObject
;
767 int focusOffset
= -1;
768 accessibility_object_
.selection(anchorObject
, anchorOffset
,
769 focusObject
, focusOffset
);
770 if (anchorOffset
< 0)
776 v8::Local
<v8::Value
> WebAXObjectProxy::SelectionFocusObject() {
777 accessibility_object_
.updateLayoutAndCheckValidity();
779 blink::WebAXObject anchorObject
;
780 int anchorOffset
= -1;
781 blink::WebAXObject focusObject
;
782 int focusOffset
= -1;
783 accessibility_object_
.selection(anchorObject
, anchorOffset
,
784 focusObject
, focusOffset
);
785 if (focusObject
.isNull())
786 return v8::Null(blink::mainThreadIsolate());
788 return factory_
->GetOrCreate(focusObject
);
791 int WebAXObjectProxy::SelectionFocusOffset() {
792 accessibility_object_
.updateLayoutAndCheckValidity();
794 blink::WebAXObject anchorObject
;
795 int anchorOffset
= -1;
796 blink::WebAXObject focusObject
;
797 int focusOffset
= -1;
798 accessibility_object_
.selection(anchorObject
, anchorOffset
,
799 focusObject
, focusOffset
);
806 int WebAXObjectProxy::SelectionStart() {
807 accessibility_object_
.updateLayoutAndCheckValidity();
808 return accessibility_object_
.selectionStart();
811 int WebAXObjectProxy::SelectionEnd() {
812 accessibility_object_
.updateLayoutAndCheckValidity();
813 return accessibility_object_
.selectionEnd();
816 int WebAXObjectProxy::SelectionStartLineNumber() {
817 accessibility_object_
.updateLayoutAndCheckValidity();
818 return accessibility_object_
.selectionStartLineNumber();
821 int WebAXObjectProxy::SelectionEndLineNumber() {
822 accessibility_object_
.updateLayoutAndCheckValidity();
823 return accessibility_object_
.selectionEndLineNumber();
826 bool WebAXObjectProxy::IsEnabled() {
827 accessibility_object_
.updateLayoutAndCheckValidity();
828 return accessibility_object_
.isEnabled();
831 bool WebAXObjectProxy::IsRequired() {
832 accessibility_object_
.updateLayoutAndCheckValidity();
833 return accessibility_object_
.isRequired();
836 bool WebAXObjectProxy::IsRichlyEditable() {
837 accessibility_object_
.updateLayoutAndCheckValidity();
838 return accessibility_object_
.isRichlyEditable();
841 bool WebAXObjectProxy::IsFocused() {
842 accessibility_object_
.updateLayoutAndCheckValidity();
843 return accessibility_object_
.isFocused();
846 bool WebAXObjectProxy::IsFocusable() {
847 accessibility_object_
.updateLayoutAndCheckValidity();
848 return accessibility_object_
.canSetFocusAttribute();
851 bool WebAXObjectProxy::IsSelected() {
852 accessibility_object_
.updateLayoutAndCheckValidity();
853 return accessibility_object_
.isSelected();
856 bool WebAXObjectProxy::IsSelectable() {
857 accessibility_object_
.updateLayoutAndCheckValidity();
858 return accessibility_object_
.canSetSelectedAttribute();
861 bool WebAXObjectProxy::IsMultiSelectable() {
862 accessibility_object_
.updateLayoutAndCheckValidity();
863 return accessibility_object_
.isMultiSelectable();
866 bool WebAXObjectProxy::IsSelectedOptionActive() {
867 accessibility_object_
.updateLayoutAndCheckValidity();
868 return accessibility_object_
.isSelectedOptionActive();
871 bool WebAXObjectProxy::IsExpanded() {
872 accessibility_object_
.updateLayoutAndCheckValidity();
873 return accessibility_object_
.isExpanded() == blink::WebAXExpandedExpanded
;
876 bool WebAXObjectProxy::IsChecked() {
877 accessibility_object_
.updateLayoutAndCheckValidity();
878 return accessibility_object_
.isChecked();
881 bool WebAXObjectProxy::IsCollapsed() {
882 accessibility_object_
.updateLayoutAndCheckValidity();
883 return accessibility_object_
.isExpanded() == blink::WebAXExpandedCollapsed
;
886 bool WebAXObjectProxy::IsVisible() {
887 accessibility_object_
.updateLayoutAndCheckValidity();
888 return accessibility_object_
.isVisible();
891 bool WebAXObjectProxy::IsOffScreen() {
892 accessibility_object_
.updateLayoutAndCheckValidity();
893 return accessibility_object_
.isOffScreen();
896 bool WebAXObjectProxy::HasPopup() {
897 accessibility_object_
.updateLayoutAndCheckValidity();
898 return accessibility_object_
.ariaHasPopup();
901 bool WebAXObjectProxy::IsValid() {
902 accessibility_object_
.updateLayoutAndCheckValidity();
903 return !accessibility_object_
.isDetached();
906 bool WebAXObjectProxy::IsReadOnly() {
907 accessibility_object_
.updateLayoutAndCheckValidity();
908 return accessibility_object_
.isReadOnly();
911 unsigned int WebAXObjectProxy::BackgroundColor() {
912 accessibility_object_
.updateLayoutAndCheckValidity();
913 return accessibility_object_
.backgroundColor();
916 unsigned int WebAXObjectProxy::Color() {
917 accessibility_object_
.updateLayoutAndCheckValidity();
918 unsigned int color
= accessibility_object_
.color();
919 // Remove the alpha because it's always 1 and thus not informative.
920 return color
& 0xFFFFFF;
923 // For input elements of type color.
924 unsigned int WebAXObjectProxy::ColorValue() {
925 accessibility_object_
.updateLayoutAndCheckValidity();
926 return accessibility_object_
.colorValue();
929 float WebAXObjectProxy::FontSize() {
930 accessibility_object_
.updateLayoutAndCheckValidity();
931 return accessibility_object_
.fontSize();
934 std::string
WebAXObjectProxy::Orientation() {
935 accessibility_object_
.updateLayoutAndCheckValidity();
936 if (accessibility_object_
.orientation() == blink::WebAXOrientationVertical
)
937 return "AXOrientation: AXVerticalOrientation";
938 else if (accessibility_object_
.orientation()
939 == blink::WebAXOrientationHorizontal
)
940 return "AXOrientation: AXHorizontalOrientation";
942 return std::string();
945 int WebAXObjectProxy::PosInSet() {
946 accessibility_object_
.updateLayoutAndCheckValidity();
947 return accessibility_object_
.posInSet();
950 int WebAXObjectProxy::SetSize() {
951 accessibility_object_
.updateLayoutAndCheckValidity();
952 return accessibility_object_
.setSize();
955 int WebAXObjectProxy::ClickPointX() {
956 accessibility_object_
.updateLayoutAndCheckValidity();
957 return accessibility_object_
.clickPoint().x
;
960 int WebAXObjectProxy::ClickPointY() {
961 accessibility_object_
.updateLayoutAndCheckValidity();
962 return accessibility_object_
.clickPoint().y
;
965 int32_t WebAXObjectProxy::RowCount() {
966 accessibility_object_
.updateLayoutAndCheckValidity();
967 return static_cast<int32_t>(accessibility_object_
.rowCount());
970 int32_t WebAXObjectProxy::RowHeadersCount() {
971 accessibility_object_
.updateLayoutAndCheckValidity();
972 blink::WebVector
<blink::WebAXObject
> headers
;
973 accessibility_object_
.rowHeaders(headers
);
974 return static_cast<int32_t>(headers
.size());
977 int32_t WebAXObjectProxy::ColumnCount() {
978 accessibility_object_
.updateLayoutAndCheckValidity();
979 return static_cast<int32_t>(accessibility_object_
.columnCount());
982 int32_t WebAXObjectProxy::ColumnHeadersCount()
984 accessibility_object_
.updateLayoutAndCheckValidity();
985 blink::WebVector
<blink::WebAXObject
> headers
;
986 accessibility_object_
.columnHeaders(headers
);
987 return static_cast<int32_t>(headers
.size());
990 bool WebAXObjectProxy::IsClickable() {
991 accessibility_object_
.updateLayoutAndCheckValidity();
992 return accessibility_object_
.isClickable();
995 bool WebAXObjectProxy::IsButtonStateMixed() {
996 accessibility_object_
.updateLayoutAndCheckValidity();
997 return accessibility_object_
.isButtonStateMixed();
1000 v8::Local
<v8::Object
> WebAXObjectProxy::AriaControlsElementAtIndex(
1003 accessibility_object_
.updateLayoutAndCheckValidity();
1004 blink::WebVector
<blink::WebAXObject
> elements
;
1005 accessibility_object_
.ariaControls(elements
);
1006 size_t elementCount
= elements
.size();
1007 if (index
>= elementCount
)
1008 return v8::Local
<v8::Object
>();
1010 return factory_
->GetOrCreate(elements
[index
]);
1013 v8::Local
<v8::Object
> WebAXObjectProxy::AriaFlowToElementAtIndex(
1016 accessibility_object_
.updateLayoutAndCheckValidity();
1017 blink::WebVector
<blink::WebAXObject
> elements
;
1018 accessibility_object_
.ariaFlowTo(elements
);
1019 size_t elementCount
= elements
.size();
1020 if (index
>= elementCount
)
1021 return v8::Local
<v8::Object
>();
1023 return factory_
->GetOrCreate(elements
[index
]);
1026 v8::Local
<v8::Object
> WebAXObjectProxy::AriaOwnsElementAtIndex(unsigned index
)
1028 accessibility_object_
.updateLayoutAndCheckValidity();
1029 blink::WebVector
<blink::WebAXObject
> elements
;
1030 accessibility_object_
.ariaOwns(elements
);
1031 size_t elementCount
= elements
.size();
1032 if (index
>= elementCount
)
1033 return v8::Local
<v8::Object
>();
1035 return factory_
->GetOrCreate(elements
[index
]);
1038 std::string
WebAXObjectProxy::AllAttributes() {
1039 accessibility_object_
.updateLayoutAndCheckValidity();
1040 return GetAttributes(accessibility_object_
);
1043 std::string
WebAXObjectProxy::AttributesOfChildren() {
1044 accessibility_object_
.updateLayoutAndCheckValidity();
1045 AttributesCollector collector
;
1046 unsigned size
= accessibility_object_
.childCount();
1047 for (unsigned i
= 0; i
< size
; ++i
)
1048 collector
.CollectAttributes(accessibility_object_
.childAt(i
));
1049 return collector
.attributes();
1052 int WebAXObjectProxy::LineForIndex(int index
) {
1053 accessibility_object_
.updateLayoutAndCheckValidity();
1054 blink::WebVector
<int> line_breaks
;
1055 accessibility_object_
.lineBreaks(line_breaks
);
1057 int vector_size
= static_cast<int>(line_breaks
.size());
1058 while (line
< vector_size
&& line_breaks
[line
] <= index
)
1063 std::string
WebAXObjectProxy::BoundsForRange(int start
, int end
) {
1064 accessibility_object_
.updateLayoutAndCheckValidity();
1065 if (accessibility_object_
.role() != blink::WebAXRoleStaticText
)
1066 return std::string();
1068 if (!accessibility_object_
.updateLayoutAndCheckValidity())
1069 return std::string();
1071 int len
= end
- start
;
1073 // Get the bounds for each character and union them into one large rectangle.
1074 // This is just for testing so it doesn't need to be efficient.
1075 blink::WebRect bounds
= BoundsForCharacter(accessibility_object_
, start
);
1076 for (int i
= 1; i
< len
; i
++) {
1077 blink::WebRect next
= BoundsForCharacter(accessibility_object_
, start
+ i
);
1078 int right
= std::max(bounds
.x
+ bounds
.width
, next
.x
+ next
.width
);
1079 int bottom
= std::max(bounds
.y
+ bounds
.height
, next
.y
+ next
.height
);
1080 bounds
.x
= std::min(bounds
.x
, next
.x
);
1081 bounds
.y
= std::min(bounds
.y
, next
.y
);
1082 bounds
.width
= right
- bounds
.x
;
1083 bounds
.height
= bottom
- bounds
.y
;
1086 return base::StringPrintf("{x: %d, y: %d, width: %d, height: %d}",
1087 bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
1090 v8::Local
<v8::Object
> WebAXObjectProxy::ChildAtIndex(int index
) {
1091 accessibility_object_
.updateLayoutAndCheckValidity();
1092 return GetChildAtIndex(index
);
1095 v8::Local
<v8::Object
> WebAXObjectProxy::ElementAtPoint(int x
, int y
) {
1096 accessibility_object_
.updateLayoutAndCheckValidity();
1097 blink::WebPoint
point(x
, y
);
1098 blink::WebAXObject obj
= accessibility_object_
.hitTest(point
);
1100 return v8::Local
<v8::Object
>();
1102 return factory_
->GetOrCreate(obj
);
1105 v8::Local
<v8::Object
> WebAXObjectProxy::TableHeader() {
1106 accessibility_object_
.updateLayoutAndCheckValidity();
1107 blink::WebAXObject obj
= accessibility_object_
.headerContainerObject();
1109 return v8::Local
<v8::Object
>();
1111 return factory_
->GetOrCreate(obj
);
1114 v8::Local
<v8::Object
> WebAXObjectProxy::RowHeaderAtIndex(unsigned index
) {
1115 accessibility_object_
.updateLayoutAndCheckValidity();
1116 blink::WebVector
<blink::WebAXObject
> headers
;
1117 accessibility_object_
.rowHeaders(headers
);
1118 size_t headerCount
= headers
.size();
1119 if (index
>= headerCount
)
1120 return v8::Local
<v8::Object
>();
1122 return factory_
->GetOrCreate(headers
[index
]);
1125 v8::Local
<v8::Object
> WebAXObjectProxy::ColumnHeaderAtIndex(unsigned index
) {
1126 accessibility_object_
.updateLayoutAndCheckValidity();
1127 blink::WebVector
<blink::WebAXObject
> headers
;
1128 accessibility_object_
.columnHeaders(headers
);
1129 size_t headerCount
= headers
.size();
1130 if (index
>= headerCount
)
1131 return v8::Local
<v8::Object
>();
1133 return factory_
->GetOrCreate(headers
[index
]);
1136 std::string
WebAXObjectProxy::RowIndexRange() {
1137 accessibility_object_
.updateLayoutAndCheckValidity();
1138 unsigned row_index
= accessibility_object_
.cellRowIndex();
1139 unsigned row_span
= accessibility_object_
.cellRowSpan();
1140 return base::StringPrintf("{%d, %d}", row_index
, row_span
);
1143 std::string
WebAXObjectProxy::ColumnIndexRange() {
1144 accessibility_object_
.updateLayoutAndCheckValidity();
1145 unsigned column_index
= accessibility_object_
.cellColumnIndex();
1146 unsigned column_span
= accessibility_object_
.cellColumnSpan();
1147 return base::StringPrintf("{%d, %d}", column_index
, column_span
);
1150 v8::Local
<v8::Object
> WebAXObjectProxy::CellForColumnAndRow(
1151 int column
, int row
) {
1152 accessibility_object_
.updateLayoutAndCheckValidity();
1153 blink::WebAXObject obj
=
1154 accessibility_object_
.cellForColumnAndRow(column
, row
);
1156 return v8::Local
<v8::Object
>();
1158 return factory_
->GetOrCreate(obj
);
1161 v8::Local
<v8::Object
> WebAXObjectProxy::DeprecatedTitleUIElement() {
1162 accessibility_object_
.updateLayoutAndCheckValidity();
1163 blink::WebAXObject obj
= accessibility_object_
.deprecatedTitleUIElement();
1165 return v8::Local
<v8::Object
>();
1167 return factory_
->GetOrCreate(obj
);
1170 void WebAXObjectProxy::SetSelectedTextRange(int selection_start
,
1172 accessibility_object_
.updateLayoutAndCheckValidity();
1173 accessibility_object_
.setSelectedTextRange(selection_start
,
1174 selection_start
+ length
);
1177 void WebAXObjectProxy::SetSelection(
1178 v8::Local
<v8::Value
> anchor_object
, int anchor_offset
,
1179 v8::Local
<v8::Value
> focus_object
, int focus_offset
) {
1180 if (anchor_object
.IsEmpty() || focus_object
.IsEmpty() ||
1181 !anchor_object
->IsObject() || !focus_object
->IsObject() ||
1182 anchor_offset
< 0 || focus_offset
< 0) {
1186 WebAXObjectProxy
* web_ax_anchor
= nullptr;
1187 if (!gin::ConvertFromV8(
1188 blink::mainThreadIsolate(), anchor_object
, &web_ax_anchor
)) {
1191 DCHECK(web_ax_anchor
);
1193 WebAXObjectProxy
* web_ax_focus
= nullptr;
1194 if (!gin::ConvertFromV8(
1195 blink::mainThreadIsolate(), focus_object
, &web_ax_focus
)) {
1198 DCHECK(web_ax_focus
);
1200 accessibility_object_
.updateLayoutAndCheckValidity();
1201 accessibility_object_
.setSelection(
1202 web_ax_anchor
->accessibility_object_
, anchor_offset
,
1203 web_ax_focus
->accessibility_object_
, focus_offset
);
1206 bool WebAXObjectProxy::IsAttributeSettable(const std::string
& attribute
) {
1207 accessibility_object_
.updateLayoutAndCheckValidity();
1208 bool settable
= false;
1209 if (attribute
== "AXValue")
1210 settable
= accessibility_object_
.canSetValueAttribute();
1214 bool WebAXObjectProxy::IsPressActionSupported() {
1215 accessibility_object_
.updateLayoutAndCheckValidity();
1216 return accessibility_object_
.canPress();
1219 bool WebAXObjectProxy::IsIncrementActionSupported() {
1220 accessibility_object_
.updateLayoutAndCheckValidity();
1221 return accessibility_object_
.canIncrement();
1224 bool WebAXObjectProxy::IsDecrementActionSupported() {
1225 accessibility_object_
.updateLayoutAndCheckValidity();
1226 return accessibility_object_
.canDecrement();
1229 v8::Local
<v8::Object
> WebAXObjectProxy::ParentElement() {
1230 accessibility_object_
.updateLayoutAndCheckValidity();
1231 blink::WebAXObject parent_object
= accessibility_object_
.parentObject();
1232 while (parent_object
.accessibilityIsIgnored())
1233 parent_object
= parent_object
.parentObject();
1234 return factory_
->GetOrCreate(parent_object
);
1237 void WebAXObjectProxy::Increment() {
1238 accessibility_object_
.updateLayoutAndCheckValidity();
1239 accessibility_object_
.increment();
1242 void WebAXObjectProxy::Decrement() {
1243 accessibility_object_
.updateLayoutAndCheckValidity();
1244 accessibility_object_
.decrement();
1247 void WebAXObjectProxy::ShowMenu() {
1248 accessibility_object_
.showContextMenu();
1251 void WebAXObjectProxy::Press() {
1252 accessibility_object_
.updateLayoutAndCheckValidity();
1253 accessibility_object_
.press();
1256 bool WebAXObjectProxy::IsEqual(v8::Local
<v8::Object
> proxy
) {
1257 WebAXObjectProxy
* unwrapped_proxy
= NULL
;
1258 if (!gin::ConvertFromV8(blink::mainThreadIsolate(), proxy
, &unwrapped_proxy
))
1260 return unwrapped_proxy
->IsEqualToObject(accessibility_object_
);
1263 void WebAXObjectProxy::SetNotificationListener(
1264 v8::Local
<v8::Function
> callback
) {
1265 v8::Isolate
* isolate
= blink::mainThreadIsolate();
1266 notification_callback_
.Reset(isolate
, callback
);
1269 void WebAXObjectProxy::UnsetNotificationListener() {
1270 notification_callback_
.Reset();
1273 void WebAXObjectProxy::TakeFocus() {
1274 accessibility_object_
.updateLayoutAndCheckValidity();
1275 accessibility_object_
.setFocused(true);
1278 void WebAXObjectProxy::ScrollToMakeVisible() {
1279 accessibility_object_
.updateLayoutAndCheckValidity();
1280 accessibility_object_
.scrollToMakeVisible();
1283 void WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus(int x
, int y
,
1284 int width
, int height
) {
1285 accessibility_object_
.updateLayoutAndCheckValidity();
1286 accessibility_object_
.scrollToMakeVisibleWithSubFocus(
1287 blink::WebRect(x
, y
, width
, height
));
1290 void WebAXObjectProxy::ScrollToGlobalPoint(int x
, int y
) {
1291 accessibility_object_
.updateLayoutAndCheckValidity();
1292 accessibility_object_
.scrollToGlobalPoint(blink::WebPoint(x
, y
));
1295 int WebAXObjectProxy::WordStart(int character_index
) {
1296 accessibility_object_
.updateLayoutAndCheckValidity();
1297 if (accessibility_object_
.role() != blink::WebAXRoleStaticText
)
1300 int word_start
= 0, word_end
= 0;
1301 GetBoundariesForOneWord(accessibility_object_
, character_index
,
1302 word_start
, word_end
);
1306 int WebAXObjectProxy::WordEnd(int character_index
) {
1307 accessibility_object_
.updateLayoutAndCheckValidity();
1308 if (accessibility_object_
.role() != blink::WebAXRoleStaticText
)
1311 int word_start
= 0, word_end
= 0;
1312 GetBoundariesForOneWord(accessibility_object_
, character_index
,
1313 word_start
, word_end
);
1317 v8::Local
<v8::Object
> WebAXObjectProxy::NextOnLine() {
1318 accessibility_object_
.updateLayoutAndCheckValidity();
1319 blink::WebAXObject obj
= accessibility_object_
.nextOnLine();
1321 return v8::Local
<v8::Object
>();
1323 return factory_
->GetOrCreate(obj
);
1326 v8::Local
<v8::Object
> WebAXObjectProxy::PreviousOnLine() {
1327 accessibility_object_
.updateLayoutAndCheckValidity();
1328 blink::WebAXObject obj
= accessibility_object_
.previousOnLine();
1330 return v8::Local
<v8::Object
>();
1332 return factory_
->GetOrCreate(obj
);
1335 std::string
WebAXObjectProxy::Name() {
1336 accessibility_object_
.updateLayoutAndCheckValidity();
1337 blink::WebAXNameFrom nameFrom
;
1338 blink::WebVector
<blink::WebAXObject
> nameObjects
;
1339 return accessibility_object_
.name(nameFrom
, nameObjects
).utf8();
1342 std::string
WebAXObjectProxy::NameFrom() {
1343 accessibility_object_
.updateLayoutAndCheckValidity();
1344 blink::WebAXNameFrom nameFrom
= blink::WebAXNameFromContents
;
1345 blink::WebVector
<blink::WebAXObject
> nameObjects
;
1346 accessibility_object_
.name(nameFrom
, nameObjects
);
1348 case blink::WebAXNameFromAttribute
:
1350 case blink::WebAXNameFromContents
:
1352 case blink::WebAXNameFromPlaceholder
:
1353 return "placeholder";
1354 case blink::WebAXNameFromRelatedElement
:
1355 return "relatedElement";
1361 int WebAXObjectProxy::NameElementCount() {
1362 accessibility_object_
.updateLayoutAndCheckValidity();
1363 blink::WebAXNameFrom nameFrom
;
1364 blink::WebVector
<blink::WebAXObject
> nameObjects
;
1365 accessibility_object_
.name(nameFrom
, nameObjects
);
1366 return static_cast<int>(nameObjects
.size());
1369 v8::Local
<v8::Object
> WebAXObjectProxy::NameElementAtIndex(unsigned index
) {
1370 accessibility_object_
.updateLayoutAndCheckValidity();
1371 blink::WebAXNameFrom nameFrom
;
1372 blink::WebVector
<blink::WebAXObject
> nameObjects
;
1373 accessibility_object_
.name(nameFrom
, nameObjects
);
1374 if (index
>= nameObjects
.size())
1375 return v8::Local
<v8::Object
>();
1376 return factory_
->GetOrCreate(nameObjects
[index
]);
1379 RootWebAXObjectProxy::RootWebAXObjectProxy(
1380 const blink::WebAXObject
&object
, Factory
*factory
)
1381 : WebAXObjectProxy(object
, factory
) {
1384 v8::Local
<v8::Object
> RootWebAXObjectProxy::GetChildAtIndex(unsigned index
) {
1386 return v8::Local
<v8::Object
>();
1388 return factory()->GetOrCreate(accessibility_object());
1391 bool RootWebAXObjectProxy::IsRoot() const {
1395 WebAXObjectProxyList::WebAXObjectProxyList()
1396 : elements_(blink::mainThreadIsolate()) {
1399 WebAXObjectProxyList::~WebAXObjectProxyList() {
1403 void WebAXObjectProxyList::Clear() {
1404 v8::Isolate
* isolate
= blink::mainThreadIsolate();
1405 v8::HandleScope
handle_scope(isolate
);
1406 size_t elementCount
= elements_
.Size();
1407 for (size_t i
= 0; i
< elementCount
; i
++) {
1408 WebAXObjectProxy
* unwrapped_object
= NULL
;
1409 bool result
= gin::ConvertFromV8(isolate
, elements_
.Get(i
),
1412 DCHECK(unwrapped_object
);
1413 unwrapped_object
->Reset();
1418 v8::Local
<v8::Object
> WebAXObjectProxyList::GetOrCreate(
1419 const blink::WebAXObject
& object
) {
1420 if (object
.isNull())
1421 return v8::Local
<v8::Object
>();
1423 v8::Isolate
* isolate
= blink::mainThreadIsolate();
1425 size_t elementCount
= elements_
.Size();
1426 for (size_t i
= 0; i
< elementCount
; i
++) {
1427 WebAXObjectProxy
* unwrapped_object
= NULL
;
1428 bool result
= gin::ConvertFromV8(isolate
, elements_
.Get(i
),
1431 DCHECK(unwrapped_object
);
1432 if (unwrapped_object
->IsEqualToObject(object
))
1433 return elements_
.Get(i
);
1436 v8::Local
<v8::Value
> value_handle
= gin::CreateHandle(
1437 isolate
, new WebAXObjectProxy(object
, this)).ToV8();
1438 if (value_handle
.IsEmpty())
1439 return v8::Local
<v8::Object
>();
1440 v8::Local
<v8::Object
> handle
= value_handle
->ToObject(isolate
);
1441 elements_
.Append(handle
);
1445 } // namespace test_runner