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("selectionStart", &WebAXObjectProxy::SelectionStart
)
496 .SetProperty("selectionEnd", &WebAXObjectProxy::SelectionEnd
)
497 .SetProperty("selectionStartLineNumber",
498 &WebAXObjectProxy::SelectionStartLineNumber
)
499 .SetProperty("selectionEndLineNumber",
500 &WebAXObjectProxy::SelectionEndLineNumber
)
501 .SetProperty("isEnabled", &WebAXObjectProxy::IsEnabled
)
502 .SetProperty("isRequired", &WebAXObjectProxy::IsRequired
)
503 .SetProperty("isRichlyEditable", &WebAXObjectProxy::IsRichlyEditable
)
504 .SetProperty("isFocused", &WebAXObjectProxy::IsFocused
)
505 .SetProperty("isFocusable", &WebAXObjectProxy::IsFocusable
)
506 .SetProperty("isSelected", &WebAXObjectProxy::IsSelected
)
507 .SetProperty("isSelectable", &WebAXObjectProxy::IsSelectable
)
508 .SetProperty("isMultiSelectable", &WebAXObjectProxy::IsMultiSelectable
)
509 .SetProperty("isSelectedOptionActive",
510 &WebAXObjectProxy::IsSelectedOptionActive
)
511 .SetProperty("isExpanded", &WebAXObjectProxy::IsExpanded
)
512 .SetProperty("isChecked", &WebAXObjectProxy::IsChecked
)
513 .SetProperty("isVisible", &WebAXObjectProxy::IsVisible
)
514 .SetProperty("isOffScreen", &WebAXObjectProxy::IsOffScreen
)
515 .SetProperty("isCollapsed", &WebAXObjectProxy::IsCollapsed
)
516 .SetProperty("hasPopup", &WebAXObjectProxy::HasPopup
)
517 .SetProperty("isValid", &WebAXObjectProxy::IsValid
)
518 .SetProperty("isReadOnly", &WebAXObjectProxy::IsReadOnly
)
519 .SetProperty("backgroundColor", &WebAXObjectProxy::BackgroundColor
)
520 .SetProperty("color", &WebAXObjectProxy::Color
)
521 .SetProperty("colorValue", &WebAXObjectProxy::ColorValue
)
522 .SetProperty("fontSize", &WebAXObjectProxy::FontSize
)
523 .SetProperty("orientation", &WebAXObjectProxy::Orientation
)
524 .SetProperty("posInSet", &WebAXObjectProxy::PosInSet
)
525 .SetProperty("setSize", &WebAXObjectProxy::SetSize
)
526 .SetProperty("clickPointX", &WebAXObjectProxy::ClickPointX
)
527 .SetProperty("clickPointY", &WebAXObjectProxy::ClickPointY
)
528 .SetProperty("rowCount", &WebAXObjectProxy::RowCount
)
529 .SetProperty("rowHeadersCount", &WebAXObjectProxy::RowHeadersCount
)
530 .SetProperty("columnCount", &WebAXObjectProxy::ColumnCount
)
531 .SetProperty("columnHeadersCount", &WebAXObjectProxy::ColumnHeadersCount
)
532 .SetProperty("isClickable", &WebAXObjectProxy::IsClickable
)
533 .SetProperty("isButtonStateMixed", &WebAXObjectProxy::IsButtonStateMixed
)
534 .SetMethod("allAttributes", &WebAXObjectProxy::AllAttributes
)
535 .SetMethod("attributesOfChildren",
536 &WebAXObjectProxy::AttributesOfChildren
)
537 .SetMethod("ariaControlsElementAtIndex",
538 &WebAXObjectProxy::AriaControlsElementAtIndex
)
539 .SetMethod("ariaFlowToElementAtIndex",
540 &WebAXObjectProxy::AriaFlowToElementAtIndex
)
541 .SetMethod("ariaOwnsElementAtIndex",
542 &WebAXObjectProxy::AriaOwnsElementAtIndex
)
543 .SetMethod("lineForIndex", &WebAXObjectProxy::LineForIndex
)
544 .SetMethod("boundsForRange", &WebAXObjectProxy::BoundsForRange
)
545 .SetMethod("childAtIndex", &WebAXObjectProxy::ChildAtIndex
)
546 .SetMethod("elementAtPoint", &WebAXObjectProxy::ElementAtPoint
)
547 .SetMethod("tableHeader", &WebAXObjectProxy::TableHeader
)
548 .SetMethod("rowHeaderAtIndex", &WebAXObjectProxy::RowHeaderAtIndex
)
549 .SetMethod("columnHeaderAtIndex", &WebAXObjectProxy::ColumnHeaderAtIndex
)
550 .SetMethod("rowIndexRange", &WebAXObjectProxy::RowIndexRange
)
551 .SetMethod("columnIndexRange", &WebAXObjectProxy::ColumnIndexRange
)
552 .SetMethod("cellForColumnAndRow", &WebAXObjectProxy::CellForColumnAndRow
)
553 .SetMethod("setSelectedTextRange",
554 &WebAXObjectProxy::SetSelectedTextRange
)
555 .SetMethod("isAttributeSettable", &WebAXObjectProxy::IsAttributeSettable
)
556 .SetMethod("isPressActionSupported",
557 &WebAXObjectProxy::IsPressActionSupported
)
558 .SetMethod("isIncrementActionSupported",
559 &WebAXObjectProxy::IsIncrementActionSupported
)
560 .SetMethod("isDecrementActionSupported",
561 &WebAXObjectProxy::IsDecrementActionSupported
)
562 .SetMethod("parentElement", &WebAXObjectProxy::ParentElement
)
563 .SetMethod("increment", &WebAXObjectProxy::Increment
)
564 .SetMethod("decrement", &WebAXObjectProxy::Decrement
)
565 .SetMethod("showMenu", &WebAXObjectProxy::ShowMenu
)
566 .SetMethod("press", &WebAXObjectProxy::Press
)
567 .SetMethod("isEqual", &WebAXObjectProxy::IsEqual
)
568 .SetMethod("setNotificationListener",
569 &WebAXObjectProxy::SetNotificationListener
)
570 .SetMethod("unsetNotificationListener",
571 &WebAXObjectProxy::UnsetNotificationListener
)
572 .SetMethod("takeFocus", &WebAXObjectProxy::TakeFocus
)
573 .SetMethod("scrollToMakeVisible", &WebAXObjectProxy::ScrollToMakeVisible
)
574 .SetMethod("scrollToMakeVisibleWithSubFocus",
575 &WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus
)
576 .SetMethod("scrollToGlobalPoint", &WebAXObjectProxy::ScrollToGlobalPoint
)
577 .SetMethod("wordStart", &WebAXObjectProxy::WordStart
)
578 .SetMethod("wordEnd", &WebAXObjectProxy::WordEnd
)
579 .SetMethod("nextOnLine", &WebAXObjectProxy::NextOnLine
)
580 .SetMethod("previousOnLine", &WebAXObjectProxy::PreviousOnLine
)
581 // TODO(hajimehoshi): This is for backward compatibility. Remove them.
582 .SetMethod("addNotificationListener",
583 &WebAXObjectProxy::SetNotificationListener
)
584 .SetMethod("removeNotificationListener",
585 &WebAXObjectProxy::UnsetNotificationListener
)
587 // DEPRECATED accessible name and description accessors
589 .SetProperty("title", &WebAXObjectProxy::DeprecatedTitle
)
590 .SetProperty("description", &WebAXObjectProxy::DeprecatedDescription
)
591 .SetProperty("helpText", &WebAXObjectProxy::DeprecatedHelpText
)
592 .SetMethod("titleUIElement", &WebAXObjectProxy::DeprecatedTitleUIElement
)
593 .SetProperty("deprecatedTitle",
594 &WebAXObjectProxy::DeprecatedTitle
)
595 .SetProperty("deprecatedDescription",
596 &WebAXObjectProxy::DeprecatedDescription
)
597 .SetProperty("deprecatedHelpText",
598 &WebAXObjectProxy::DeprecatedHelpText
)
599 .SetMethod("deprecatedTitleUIElement",
600 &WebAXObjectProxy::DeprecatedTitleUIElement
)
602 // NEW accessible name and description accessors
604 .SetProperty("name", &WebAXObjectProxy::Name
)
605 .SetProperty("nameFrom", &WebAXObjectProxy::NameFrom
)
606 .SetMethod("nameElementCount", &WebAXObjectProxy::NameElementCount
)
607 .SetMethod("nameElementAtIndex", &WebAXObjectProxy::NameElementAtIndex
);
608 // TODO(dmazzoni): add "description", etc. once LayoutTests have
609 // been updated to call deprecatedDescription instead.
613 v8::Local
<v8::Object
> WebAXObjectProxy::GetChildAtIndex(unsigned index
) {
614 return factory_
->GetOrCreate(accessibility_object_
.childAt(index
));
617 bool WebAXObjectProxy::IsRoot() const {
621 bool WebAXObjectProxy::IsEqualToObject(const blink::WebAXObject
& other
) {
622 return accessibility_object_
.equals(other
);
625 void WebAXObjectProxy::NotificationReceived(
626 blink::WebFrame
* frame
,
627 const std::string
& notification_name
) {
628 if (notification_callback_
.IsEmpty())
631 v8::Local
<v8::Context
> context
= frame
->mainWorldScriptContext();
632 if (context
.IsEmpty())
635 v8::Isolate
* isolate
= blink::mainThreadIsolate();
637 v8::Local
<v8::Value
> argv
[] = {
638 v8::String::NewFromUtf8(isolate
, notification_name
.data(),
639 v8::String::kNormalString
,
640 notification_name
.size()),
642 frame
->callFunctionEvenIfScriptDisabled(
643 v8::Local
<v8::Function
>::New(isolate
, notification_callback_
),
649 void WebAXObjectProxy::Reset() {
650 notification_callback_
.Reset();
653 std::string
WebAXObjectProxy::Role() {
654 accessibility_object_
.updateLayoutAndCheckValidity();
655 return GetRole(accessibility_object_
);
658 std::string
WebAXObjectProxy::DeprecatedTitle() {
659 accessibility_object_
.updateLayoutAndCheckValidity();
660 return DeprecatedGetTitle(accessibility_object_
);
663 std::string
WebAXObjectProxy::DeprecatedDescription() {
664 accessibility_object_
.updateLayoutAndCheckValidity();
665 return DeprecatedGetDescription(accessibility_object_
);
668 std::string
WebAXObjectProxy::DeprecatedHelpText() {
669 accessibility_object_
.updateLayoutAndCheckValidity();
670 return DeprecatedGetHelpText(accessibility_object_
);
673 std::string
WebAXObjectProxy::StringValue() {
674 accessibility_object_
.updateLayoutAndCheckValidity();
675 return GetStringValue(accessibility_object_
);
678 std::string
WebAXObjectProxy::Language() {
679 accessibility_object_
.updateLayoutAndCheckValidity();
680 return GetLanguage(accessibility_object_
);
683 int WebAXObjectProxy::X() {
684 accessibility_object_
.updateLayoutAndCheckValidity();
685 return accessibility_object_
.boundingBoxRect().x
;
688 int WebAXObjectProxy::Y() {
689 accessibility_object_
.updateLayoutAndCheckValidity();
690 return accessibility_object_
.boundingBoxRect().y
;
693 int WebAXObjectProxy::Width() {
694 accessibility_object_
.updateLayoutAndCheckValidity();
695 return accessibility_object_
.boundingBoxRect().width
;
698 int WebAXObjectProxy::Height() {
699 accessibility_object_
.updateLayoutAndCheckValidity();
700 return accessibility_object_
.boundingBoxRect().height
;
703 int WebAXObjectProxy::IntValue() {
704 accessibility_object_
.updateLayoutAndCheckValidity();
705 if (accessibility_object_
.supportsRangeValue())
706 return accessibility_object_
.valueForRange();
707 else if (accessibility_object_
.role() == blink::WebAXRoleHeading
)
708 return accessibility_object_
.headingLevel();
710 return atoi(accessibility_object_
.stringValue().utf8().data());
713 int WebAXObjectProxy::MinValue() {
714 accessibility_object_
.updateLayoutAndCheckValidity();
715 return accessibility_object_
.minValueForRange();
718 int WebAXObjectProxy::MaxValue() {
719 accessibility_object_
.updateLayoutAndCheckValidity();
720 return accessibility_object_
.maxValueForRange();
723 std::string
WebAXObjectProxy::ValueDescription() {
724 accessibility_object_
.updateLayoutAndCheckValidity();
725 return GetValueDescription(accessibility_object_
);
728 int WebAXObjectProxy::ChildrenCount() {
729 accessibility_object_
.updateLayoutAndCheckValidity();
730 int count
= 1; // Root object always has only one child, the WebView.
732 count
= accessibility_object_
.childCount();
736 int WebAXObjectProxy::SelectionStart() {
737 accessibility_object_
.updateLayoutAndCheckValidity();
738 return accessibility_object_
.selectionStart();
741 int WebAXObjectProxy::SelectionEnd() {
742 accessibility_object_
.updateLayoutAndCheckValidity();
743 return accessibility_object_
.selectionEnd();
746 int WebAXObjectProxy::SelectionStartLineNumber() {
747 accessibility_object_
.updateLayoutAndCheckValidity();
748 return accessibility_object_
.selectionStartLineNumber();
751 int WebAXObjectProxy::SelectionEndLineNumber() {
752 accessibility_object_
.updateLayoutAndCheckValidity();
753 return accessibility_object_
.selectionEndLineNumber();
756 bool WebAXObjectProxy::IsEnabled() {
757 accessibility_object_
.updateLayoutAndCheckValidity();
758 return accessibility_object_
.isEnabled();
761 bool WebAXObjectProxy::IsRequired() {
762 accessibility_object_
.updateLayoutAndCheckValidity();
763 return accessibility_object_
.isRequired();
766 bool WebAXObjectProxy::IsRichlyEditable() {
767 accessibility_object_
.updateLayoutAndCheckValidity();
768 return accessibility_object_
.isRichlyEditable();
771 bool WebAXObjectProxy::IsFocused() {
772 accessibility_object_
.updateLayoutAndCheckValidity();
773 return accessibility_object_
.isFocused();
776 bool WebAXObjectProxy::IsFocusable() {
777 accessibility_object_
.updateLayoutAndCheckValidity();
778 return accessibility_object_
.canSetFocusAttribute();
781 bool WebAXObjectProxy::IsSelected() {
782 accessibility_object_
.updateLayoutAndCheckValidity();
783 return accessibility_object_
.isSelected();
786 bool WebAXObjectProxy::IsSelectable() {
787 accessibility_object_
.updateLayoutAndCheckValidity();
788 return accessibility_object_
.canSetSelectedAttribute();
791 bool WebAXObjectProxy::IsMultiSelectable() {
792 accessibility_object_
.updateLayoutAndCheckValidity();
793 return accessibility_object_
.isMultiSelectable();
796 bool WebAXObjectProxy::IsSelectedOptionActive() {
797 accessibility_object_
.updateLayoutAndCheckValidity();
798 return accessibility_object_
.isSelectedOptionActive();
801 bool WebAXObjectProxy::IsExpanded() {
802 accessibility_object_
.updateLayoutAndCheckValidity();
803 return accessibility_object_
.isExpanded() == blink::WebAXExpandedExpanded
;
806 bool WebAXObjectProxy::IsChecked() {
807 accessibility_object_
.updateLayoutAndCheckValidity();
808 return accessibility_object_
.isChecked();
811 bool WebAXObjectProxy::IsCollapsed() {
812 accessibility_object_
.updateLayoutAndCheckValidity();
813 return accessibility_object_
.isExpanded() == blink::WebAXExpandedCollapsed
;
816 bool WebAXObjectProxy::IsVisible() {
817 accessibility_object_
.updateLayoutAndCheckValidity();
818 return accessibility_object_
.isVisible();
821 bool WebAXObjectProxy::IsOffScreen() {
822 accessibility_object_
.updateLayoutAndCheckValidity();
823 return accessibility_object_
.isOffScreen();
826 bool WebAXObjectProxy::HasPopup() {
827 accessibility_object_
.updateLayoutAndCheckValidity();
828 return accessibility_object_
.ariaHasPopup();
831 bool WebAXObjectProxy::IsValid() {
832 accessibility_object_
.updateLayoutAndCheckValidity();
833 return !accessibility_object_
.isDetached();
836 bool WebAXObjectProxy::IsReadOnly() {
837 accessibility_object_
.updateLayoutAndCheckValidity();
838 return accessibility_object_
.isReadOnly();
841 unsigned int WebAXObjectProxy::BackgroundColor() {
842 accessibility_object_
.updateLayoutAndCheckValidity();
843 return accessibility_object_
.backgroundColor();
846 unsigned int WebAXObjectProxy::Color() {
847 accessibility_object_
.updateLayoutAndCheckValidity();
848 unsigned int color
= accessibility_object_
.color();
849 // Remove the alpha because it's always 1 and thus not informative.
850 return color
& 0xFFFFFF;
853 // For input elements of type color.
854 unsigned int WebAXObjectProxy::ColorValue() {
855 accessibility_object_
.updateLayoutAndCheckValidity();
856 return accessibility_object_
.colorValue();
859 float WebAXObjectProxy::FontSize() {
860 accessibility_object_
.updateLayoutAndCheckValidity();
861 return accessibility_object_
.fontSize();
864 std::string
WebAXObjectProxy::Orientation() {
865 accessibility_object_
.updateLayoutAndCheckValidity();
866 if (accessibility_object_
.orientation() == blink::WebAXOrientationVertical
)
867 return "AXOrientation: AXVerticalOrientation";
868 else if (accessibility_object_
.orientation()
869 == blink::WebAXOrientationHorizontal
)
870 return "AXOrientation: AXHorizontalOrientation";
872 return std::string();
875 int WebAXObjectProxy::PosInSet() {
876 accessibility_object_
.updateLayoutAndCheckValidity();
877 return accessibility_object_
.posInSet();
880 int WebAXObjectProxy::SetSize() {
881 accessibility_object_
.updateLayoutAndCheckValidity();
882 return accessibility_object_
.setSize();
885 int WebAXObjectProxy::ClickPointX() {
886 accessibility_object_
.updateLayoutAndCheckValidity();
887 return accessibility_object_
.clickPoint().x
;
890 int WebAXObjectProxy::ClickPointY() {
891 accessibility_object_
.updateLayoutAndCheckValidity();
892 return accessibility_object_
.clickPoint().y
;
895 int32_t WebAXObjectProxy::RowCount() {
896 accessibility_object_
.updateLayoutAndCheckValidity();
897 return static_cast<int32_t>(accessibility_object_
.rowCount());
900 int32_t WebAXObjectProxy::RowHeadersCount() {
901 accessibility_object_
.updateLayoutAndCheckValidity();
902 blink::WebVector
<blink::WebAXObject
> headers
;
903 accessibility_object_
.rowHeaders(headers
);
904 return static_cast<int32_t>(headers
.size());
907 int32_t WebAXObjectProxy::ColumnCount() {
908 accessibility_object_
.updateLayoutAndCheckValidity();
909 return static_cast<int32_t>(accessibility_object_
.columnCount());
912 int32_t WebAXObjectProxy::ColumnHeadersCount()
914 accessibility_object_
.updateLayoutAndCheckValidity();
915 blink::WebVector
<blink::WebAXObject
> headers
;
916 accessibility_object_
.columnHeaders(headers
);
917 return static_cast<int32_t>(headers
.size());
920 bool WebAXObjectProxy::IsClickable() {
921 accessibility_object_
.updateLayoutAndCheckValidity();
922 return accessibility_object_
.isClickable();
925 bool WebAXObjectProxy::IsButtonStateMixed() {
926 accessibility_object_
.updateLayoutAndCheckValidity();
927 return accessibility_object_
.isButtonStateMixed();
930 v8::Local
<v8::Object
> WebAXObjectProxy::AriaControlsElementAtIndex(
933 accessibility_object_
.updateLayoutAndCheckValidity();
934 blink::WebVector
<blink::WebAXObject
> elements
;
935 accessibility_object_
.ariaControls(elements
);
936 size_t elementCount
= elements
.size();
937 if (index
>= elementCount
)
938 return v8::Local
<v8::Object
>();
940 return factory_
->GetOrCreate(elements
[index
]);
943 v8::Local
<v8::Object
> WebAXObjectProxy::AriaFlowToElementAtIndex(
946 accessibility_object_
.updateLayoutAndCheckValidity();
947 blink::WebVector
<blink::WebAXObject
> elements
;
948 accessibility_object_
.ariaFlowTo(elements
);
949 size_t elementCount
= elements
.size();
950 if (index
>= elementCount
)
951 return v8::Local
<v8::Object
>();
953 return factory_
->GetOrCreate(elements
[index
]);
956 v8::Local
<v8::Object
> WebAXObjectProxy::AriaOwnsElementAtIndex(unsigned index
)
958 accessibility_object_
.updateLayoutAndCheckValidity();
959 blink::WebVector
<blink::WebAXObject
> elements
;
960 accessibility_object_
.ariaOwns(elements
);
961 size_t elementCount
= elements
.size();
962 if (index
>= elementCount
)
963 return v8::Local
<v8::Object
>();
965 return factory_
->GetOrCreate(elements
[index
]);
968 std::string
WebAXObjectProxy::AllAttributes() {
969 accessibility_object_
.updateLayoutAndCheckValidity();
970 return GetAttributes(accessibility_object_
);
973 std::string
WebAXObjectProxy::AttributesOfChildren() {
974 accessibility_object_
.updateLayoutAndCheckValidity();
975 AttributesCollector collector
;
976 unsigned size
= accessibility_object_
.childCount();
977 for (unsigned i
= 0; i
< size
; ++i
)
978 collector
.CollectAttributes(accessibility_object_
.childAt(i
));
979 return collector
.attributes();
982 int WebAXObjectProxy::LineForIndex(int index
) {
983 accessibility_object_
.updateLayoutAndCheckValidity();
984 blink::WebVector
<int> line_breaks
;
985 accessibility_object_
.lineBreaks(line_breaks
);
987 int vector_size
= static_cast<int>(line_breaks
.size());
988 while (line
< vector_size
&& line_breaks
[line
] <= index
)
993 std::string
WebAXObjectProxy::BoundsForRange(int start
, int end
) {
994 accessibility_object_
.updateLayoutAndCheckValidity();
995 if (accessibility_object_
.role() != blink::WebAXRoleStaticText
)
996 return std::string();
998 if (!accessibility_object_
.updateLayoutAndCheckValidity())
999 return std::string();
1001 int len
= end
- start
;
1003 // Get the bounds for each character and union them into one large rectangle.
1004 // This is just for testing so it doesn't need to be efficient.
1005 blink::WebRect bounds
= BoundsForCharacter(accessibility_object_
, start
);
1006 for (int i
= 1; i
< len
; i
++) {
1007 blink::WebRect next
= BoundsForCharacter(accessibility_object_
, start
+ i
);
1008 int right
= std::max(bounds
.x
+ bounds
.width
, next
.x
+ next
.width
);
1009 int bottom
= std::max(bounds
.y
+ bounds
.height
, next
.y
+ next
.height
);
1010 bounds
.x
= std::min(bounds
.x
, next
.x
);
1011 bounds
.y
= std::min(bounds
.y
, next
.y
);
1012 bounds
.width
= right
- bounds
.x
;
1013 bounds
.height
= bottom
- bounds
.y
;
1016 return base::StringPrintf("{x: %d, y: %d, width: %d, height: %d}",
1017 bounds
.x
, bounds
.y
, bounds
.width
, bounds
.height
);
1020 v8::Local
<v8::Object
> WebAXObjectProxy::ChildAtIndex(int index
) {
1021 accessibility_object_
.updateLayoutAndCheckValidity();
1022 return GetChildAtIndex(index
);
1025 v8::Local
<v8::Object
> WebAXObjectProxy::ElementAtPoint(int x
, int y
) {
1026 accessibility_object_
.updateLayoutAndCheckValidity();
1027 blink::WebPoint
point(x
, y
);
1028 blink::WebAXObject obj
= accessibility_object_
.hitTest(point
);
1030 return v8::Local
<v8::Object
>();
1032 return factory_
->GetOrCreate(obj
);
1035 v8::Local
<v8::Object
> WebAXObjectProxy::TableHeader() {
1036 accessibility_object_
.updateLayoutAndCheckValidity();
1037 blink::WebAXObject obj
= accessibility_object_
.headerContainerObject();
1039 return v8::Local
<v8::Object
>();
1041 return factory_
->GetOrCreate(obj
);
1044 v8::Local
<v8::Object
> WebAXObjectProxy::RowHeaderAtIndex(unsigned index
) {
1045 accessibility_object_
.updateLayoutAndCheckValidity();
1046 blink::WebVector
<blink::WebAXObject
> headers
;
1047 accessibility_object_
.rowHeaders(headers
);
1048 size_t headerCount
= headers
.size();
1049 if (index
>= headerCount
)
1050 return v8::Local
<v8::Object
>();
1052 return factory_
->GetOrCreate(headers
[index
]);
1055 v8::Local
<v8::Object
> WebAXObjectProxy::ColumnHeaderAtIndex(unsigned index
) {
1056 accessibility_object_
.updateLayoutAndCheckValidity();
1057 blink::WebVector
<blink::WebAXObject
> headers
;
1058 accessibility_object_
.columnHeaders(headers
);
1059 size_t headerCount
= headers
.size();
1060 if (index
>= headerCount
)
1061 return v8::Local
<v8::Object
>();
1063 return factory_
->GetOrCreate(headers
[index
]);
1066 std::string
WebAXObjectProxy::RowIndexRange() {
1067 accessibility_object_
.updateLayoutAndCheckValidity();
1068 unsigned row_index
= accessibility_object_
.cellRowIndex();
1069 unsigned row_span
= accessibility_object_
.cellRowSpan();
1070 return base::StringPrintf("{%d, %d}", row_index
, row_span
);
1073 std::string
WebAXObjectProxy::ColumnIndexRange() {
1074 accessibility_object_
.updateLayoutAndCheckValidity();
1075 unsigned column_index
= accessibility_object_
.cellColumnIndex();
1076 unsigned column_span
= accessibility_object_
.cellColumnSpan();
1077 return base::StringPrintf("{%d, %d}", column_index
, column_span
);
1080 v8::Local
<v8::Object
> WebAXObjectProxy::CellForColumnAndRow(
1081 int column
, int row
) {
1082 accessibility_object_
.updateLayoutAndCheckValidity();
1083 blink::WebAXObject obj
=
1084 accessibility_object_
.cellForColumnAndRow(column
, row
);
1086 return v8::Local
<v8::Object
>();
1088 return factory_
->GetOrCreate(obj
);
1091 v8::Local
<v8::Object
> WebAXObjectProxy::DeprecatedTitleUIElement() {
1092 accessibility_object_
.updateLayoutAndCheckValidity();
1093 blink::WebAXObject obj
= accessibility_object_
.deprecatedTitleUIElement();
1095 return v8::Local
<v8::Object
>();
1097 return factory_
->GetOrCreate(obj
);
1100 void WebAXObjectProxy::SetSelectedTextRange(int selection_start
,
1102 accessibility_object_
.updateLayoutAndCheckValidity();
1103 accessibility_object_
.setSelectedTextRange(selection_start
,
1104 selection_start
+ length
);
1107 bool WebAXObjectProxy::IsAttributeSettable(const std::string
& attribute
) {
1108 accessibility_object_
.updateLayoutAndCheckValidity();
1109 bool settable
= false;
1110 if (attribute
== "AXValue")
1111 settable
= accessibility_object_
.canSetValueAttribute();
1115 bool WebAXObjectProxy::IsPressActionSupported() {
1116 accessibility_object_
.updateLayoutAndCheckValidity();
1117 return accessibility_object_
.canPress();
1120 bool WebAXObjectProxy::IsIncrementActionSupported() {
1121 accessibility_object_
.updateLayoutAndCheckValidity();
1122 return accessibility_object_
.canIncrement();
1125 bool WebAXObjectProxy::IsDecrementActionSupported() {
1126 accessibility_object_
.updateLayoutAndCheckValidity();
1127 return accessibility_object_
.canDecrement();
1130 v8::Local
<v8::Object
> WebAXObjectProxy::ParentElement() {
1131 accessibility_object_
.updateLayoutAndCheckValidity();
1132 blink::WebAXObject parent_object
= accessibility_object_
.parentObject();
1133 while (parent_object
.accessibilityIsIgnored())
1134 parent_object
= parent_object
.parentObject();
1135 return factory_
->GetOrCreate(parent_object
);
1138 void WebAXObjectProxy::Increment() {
1139 accessibility_object_
.updateLayoutAndCheckValidity();
1140 accessibility_object_
.increment();
1143 void WebAXObjectProxy::Decrement() {
1144 accessibility_object_
.updateLayoutAndCheckValidity();
1145 accessibility_object_
.decrement();
1148 void WebAXObjectProxy::ShowMenu() {
1149 accessibility_object_
.showContextMenu();
1152 void WebAXObjectProxy::Press() {
1153 accessibility_object_
.updateLayoutAndCheckValidity();
1154 accessibility_object_
.press();
1157 bool WebAXObjectProxy::IsEqual(v8::Local
<v8::Object
> proxy
) {
1158 WebAXObjectProxy
* unwrapped_proxy
= NULL
;
1159 if (!gin::ConvertFromV8(blink::mainThreadIsolate(), proxy
, &unwrapped_proxy
))
1161 return unwrapped_proxy
->IsEqualToObject(accessibility_object_
);
1164 void WebAXObjectProxy::SetNotificationListener(
1165 v8::Local
<v8::Function
> callback
) {
1166 v8::Isolate
* isolate
= blink::mainThreadIsolate();
1167 notification_callback_
.Reset(isolate
, callback
);
1170 void WebAXObjectProxy::UnsetNotificationListener() {
1171 notification_callback_
.Reset();
1174 void WebAXObjectProxy::TakeFocus() {
1175 accessibility_object_
.updateLayoutAndCheckValidity();
1176 accessibility_object_
.setFocused(true);
1179 void WebAXObjectProxy::ScrollToMakeVisible() {
1180 accessibility_object_
.updateLayoutAndCheckValidity();
1181 accessibility_object_
.scrollToMakeVisible();
1184 void WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus(int x
, int y
,
1185 int width
, int height
) {
1186 accessibility_object_
.updateLayoutAndCheckValidity();
1187 accessibility_object_
.scrollToMakeVisibleWithSubFocus(
1188 blink::WebRect(x
, y
, width
, height
));
1191 void WebAXObjectProxy::ScrollToGlobalPoint(int x
, int y
) {
1192 accessibility_object_
.updateLayoutAndCheckValidity();
1193 accessibility_object_
.scrollToGlobalPoint(blink::WebPoint(x
, y
));
1196 int WebAXObjectProxy::WordStart(int character_index
) {
1197 accessibility_object_
.updateLayoutAndCheckValidity();
1198 if (accessibility_object_
.role() != blink::WebAXRoleStaticText
)
1201 int word_start
= 0, word_end
= 0;
1202 GetBoundariesForOneWord(accessibility_object_
, character_index
,
1203 word_start
, word_end
);
1207 int WebAXObjectProxy::WordEnd(int character_index
) {
1208 accessibility_object_
.updateLayoutAndCheckValidity();
1209 if (accessibility_object_
.role() != blink::WebAXRoleStaticText
)
1212 int word_start
= 0, word_end
= 0;
1213 GetBoundariesForOneWord(accessibility_object_
, character_index
,
1214 word_start
, word_end
);
1218 v8::Local
<v8::Object
> WebAXObjectProxy::NextOnLine() {
1219 accessibility_object_
.updateLayoutAndCheckValidity();
1220 blink::WebAXObject obj
= accessibility_object_
.nextOnLine();
1222 return v8::Local
<v8::Object
>();
1224 return factory_
->GetOrCreate(obj
);
1227 v8::Local
<v8::Object
> WebAXObjectProxy::PreviousOnLine() {
1228 accessibility_object_
.updateLayoutAndCheckValidity();
1229 blink::WebAXObject obj
= accessibility_object_
.previousOnLine();
1231 return v8::Local
<v8::Object
>();
1233 return factory_
->GetOrCreate(obj
);
1236 std::string
WebAXObjectProxy::Name() {
1237 accessibility_object_
.updateLayoutAndCheckValidity();
1238 blink::WebAXNameFrom nameFrom
;
1239 blink::WebVector
<blink::WebAXObject
> nameObjects
;
1240 return accessibility_object_
.name(nameFrom
, nameObjects
).utf8();
1243 std::string
WebAXObjectProxy::NameFrom() {
1244 accessibility_object_
.updateLayoutAndCheckValidity();
1245 blink::WebAXNameFrom nameFrom
= blink::WebAXNameFromContents
;
1246 blink::WebVector
<blink::WebAXObject
> nameObjects
;
1247 accessibility_object_
.name(nameFrom
, nameObjects
);
1249 case blink::WebAXNameFromAttribute
:
1251 case blink::WebAXNameFromContents
:
1253 case blink::WebAXNameFromPlaceholder
:
1254 return "placeholder";
1255 case blink::WebAXNameFromRelatedElement
:
1256 return "relatedElement";
1262 int WebAXObjectProxy::NameElementCount() {
1263 accessibility_object_
.updateLayoutAndCheckValidity();
1264 blink::WebAXNameFrom nameFrom
;
1265 blink::WebVector
<blink::WebAXObject
> nameObjects
;
1266 accessibility_object_
.name(nameFrom
, nameObjects
);
1267 return static_cast<int>(nameObjects
.size());
1270 v8::Local
<v8::Object
> WebAXObjectProxy::NameElementAtIndex(unsigned index
) {
1271 accessibility_object_
.updateLayoutAndCheckValidity();
1272 blink::WebAXNameFrom nameFrom
;
1273 blink::WebVector
<blink::WebAXObject
> nameObjects
;
1274 accessibility_object_
.name(nameFrom
, nameObjects
);
1275 if (index
>= nameObjects
.size())
1276 return v8::Local
<v8::Object
>();
1277 return factory_
->GetOrCreate(nameObjects
[index
]);
1280 RootWebAXObjectProxy::RootWebAXObjectProxy(
1281 const blink::WebAXObject
&object
, Factory
*factory
)
1282 : WebAXObjectProxy(object
, factory
) {
1285 v8::Local
<v8::Object
> RootWebAXObjectProxy::GetChildAtIndex(unsigned index
) {
1287 return v8::Local
<v8::Object
>();
1289 return factory()->GetOrCreate(accessibility_object());
1292 bool RootWebAXObjectProxy::IsRoot() const {
1296 WebAXObjectProxyList::WebAXObjectProxyList()
1297 : elements_(blink::mainThreadIsolate()) {
1300 WebAXObjectProxyList::~WebAXObjectProxyList() {
1304 void WebAXObjectProxyList::Clear() {
1305 v8::Isolate
* isolate
= blink::mainThreadIsolate();
1306 v8::HandleScope
handle_scope(isolate
);
1307 size_t elementCount
= elements_
.Size();
1308 for (size_t i
= 0; i
< elementCount
; i
++) {
1309 WebAXObjectProxy
* unwrapped_object
= NULL
;
1310 bool result
= gin::ConvertFromV8(isolate
, elements_
.Get(i
),
1313 DCHECK(unwrapped_object
);
1314 unwrapped_object
->Reset();
1319 v8::Local
<v8::Object
> WebAXObjectProxyList::GetOrCreate(
1320 const blink::WebAXObject
& object
) {
1321 if (object
.isNull())
1322 return v8::Local
<v8::Object
>();
1324 v8::Isolate
* isolate
= blink::mainThreadIsolate();
1326 size_t elementCount
= elements_
.Size();
1327 for (size_t i
= 0; i
< elementCount
; i
++) {
1328 WebAXObjectProxy
* unwrapped_object
= NULL
;
1329 bool result
= gin::ConvertFromV8(isolate
, elements_
.Get(i
),
1332 DCHECK(unwrapped_object
);
1333 if (unwrapped_object
->IsEqualToObject(object
))
1334 return elements_
.Get(i
);
1337 v8::Local
<v8::Value
> value_handle
= gin::CreateHandle(
1338 isolate
, new WebAXObjectProxy(object
, this)).ToV8();
1339 if (value_handle
.IsEmpty())
1340 return v8::Local
<v8::Object
>();
1341 v8::Local
<v8::Object
> handle
= value_handle
->ToObject(isolate
);
1342 elements_
.Append(handle
);
1346 } // namespace test_runner