Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: content/shell/renderer/test_runner/web_ax_object_proxy.cc

Issue 172263002: Move WebAXObjectProxy and AccessibleController from CppBoundClass to gin::Wrappable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: kouhei's review: {add/remove}NotificationCallback -> {set/unset}NotificationCallback Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 // TODO(hajimehoshi): Remove this when UnsafePersistent is removed.
6 #define V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
7
8 #include "content/shell/renderer/test_runner/web_ax_object_proxy.h"
9
10 #include "gin/handle.h"
11 #include "third_party/WebKit/public/platform/WebPoint.h"
12 #include "third_party/WebKit/public/platform/WebRect.h"
13 #include "third_party/WebKit/public/platform/WebString.h"
14 #include "third_party/WebKit/public/web/WebFrame.h"
15 #include "third_party/WebKit/public/web/WebKit.h"
16
17 namespace content {
18
19 namespace {
20
21 // Map role value to string, matching Safari/Mac platform implementation to
22 // avoid rebaselining layout tests.
23 std::string RoleToString(blink::WebAXRole role)
24 {
25 std::string result = "AXRole: AX";
26 switch (role) {
27 case blink::WebAXRoleAlertDialog:
28 return result.append("AlertDialog");
29 case blink::WebAXRoleAlert:
30 return result.append("Alert");
31 case blink::WebAXRoleAnnotation:
32 return result.append("Annotation");
33 case blink::WebAXRoleApplication:
34 return result.append("Application");
35 case blink::WebAXRoleArticle:
36 return result.append("Article");
37 case blink::WebAXRoleBanner:
38 return result.append("Banner");
39 case blink::WebAXRoleBrowser:
40 return result.append("Browser");
41 case blink::WebAXRoleBusyIndicator:
42 return result.append("BusyIndicator");
43 case blink::WebAXRoleButton:
44 return result.append("Button");
45 case blink::WebAXRoleCanvas:
46 return result.append("Canvas");
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::WebAXRoleDefinition:
64 return result.append("Definition");
65 case blink::WebAXRoleDescriptionListDetail:
66 return result.append("DescriptionListDetail");
67 case blink::WebAXRoleDescriptionListTerm:
68 return result.append("DescriptionListTerm");
69 case blink::WebAXRoleDialog:
70 return result.append("Dialog");
71 case blink::WebAXRoleDirectory:
72 return result.append("Directory");
73 case blink::WebAXRoleDisclosureTriangle:
74 return result.append("DisclosureTriangle");
75 case blink::WebAXRoleDiv:
76 return result.append("Div");
77 case blink::WebAXRoleDocument:
78 return result.append("Document");
79 case blink::WebAXRoleDrawer:
80 return result.append("Drawer");
81 case blink::WebAXRoleEditableText:
82 return result.append("EditableText");
83 case blink::WebAXRoleFooter:
84 return result.append("Footer");
85 case blink::WebAXRoleForm:
86 return result.append("Form");
87 case blink::WebAXRoleGrid:
88 return result.append("Grid");
89 case blink::WebAXRoleGroup:
90 return result.append("Group");
91 case blink::WebAXRoleGrowArea:
92 return result.append("GrowArea");
93 case blink::WebAXRoleHeading:
94 return result.append("Heading");
95 case blink::WebAXRoleHelpTag:
96 return result.append("HelpTag");
97 case blink::WebAXRoleHorizontalRule:
98 return result.append("HorizontalRule");
99 case blink::WebAXRoleIgnored:
100 return result.append("Ignored");
101 case blink::WebAXRoleImageMapLink:
102 return result.append("ImageMapLink");
103 case blink::WebAXRoleImageMap:
104 return result.append("ImageMap");
105 case blink::WebAXRoleImage:
106 return result.append("Image");
107 case blink::WebAXRoleIncrementor:
108 return result.append("Incrementor");
109 case blink::WebAXRoleInlineTextBox:
110 return result.append("InlineTextBox");
111 case blink::WebAXRoleLabel:
112 return result.append("Label");
113 case blink::WebAXRoleLegend:
114 return result.append("Legend");
115 case blink::WebAXRoleLink:
116 return result.append("Link");
117 case blink::WebAXRoleListBoxOption:
118 return result.append("ListBoxOption");
119 case blink::WebAXRoleListBox:
120 return result.append("ListBox");
121 case blink::WebAXRoleListItem:
122 return result.append("ListItem");
123 case blink::WebAXRoleListMarker:
124 return result.append("ListMarker");
125 case blink::WebAXRoleList:
126 return result.append("List");
127 case blink::WebAXRoleLog:
128 return result.append("Log");
129 case blink::WebAXRoleMain:
130 return result.append("Main");
131 case blink::WebAXRoleMarquee:
132 return result.append("Marquee");
133 case blink::WebAXRoleMathElement:
134 return result.append("MathElement");
135 case blink::WebAXRoleMath:
136 return result.append("Math");
137 case blink::WebAXRoleMatte:
138 return result.append("Matte");
139 case blink::WebAXRoleMenuBar:
140 return result.append("MenuBar");
141 case blink::WebAXRoleMenuButton:
142 return result.append("MenuButton");
143 case blink::WebAXRoleMenuItem:
144 return result.append("MenuItem");
145 case blink::WebAXRoleMenuListOption:
146 return result.append("MenuListOption");
147 case blink::WebAXRoleMenuListPopup:
148 return result.append("MenuListPopup");
149 case blink::WebAXRoleMenu:
150 return result.append("Menu");
151 case blink::WebAXRoleNavigation:
152 return result.append("Navigation");
153 case blink::WebAXRoleNote:
154 return result.append("Note");
155 case blink::WebAXRoleOutline:
156 return result.append("Outline");
157 case blink::WebAXRoleParagraph:
158 return result.append("Paragraph");
159 case blink::WebAXRolePopUpButton:
160 return result.append("PopUpButton");
161 case blink::WebAXRolePresentational:
162 return result.append("Presentational");
163 case blink::WebAXRoleProgressIndicator:
164 return result.append("ProgressIndicator");
165 case blink::WebAXRoleRadioButton:
166 return result.append("RadioButton");
167 case blink::WebAXRoleRadioGroup:
168 return result.append("RadioGroup");
169 case blink::WebAXRoleRegion:
170 return result.append("Region");
171 case blink::WebAXRoleRootWebArea:
172 return result.append("RootWebArea");
173 case blink::WebAXRoleRowHeader:
174 return result.append("RowHeader");
175 case blink::WebAXRoleRow:
176 return result.append("Row");
177 case blink::WebAXRoleRulerMarker:
178 return result.append("RulerMarker");
179 case blink::WebAXRoleRuler:
180 return result.append("Ruler");
181 case blink::WebAXRoleSVGRoot:
182 return result.append("SVGRoot");
183 case blink::WebAXRoleScrollArea:
184 return result.append("ScrollArea");
185 case blink::WebAXRoleScrollBar:
186 return result.append("ScrollBar");
187 case blink::WebAXRoleSeamlessWebArea:
188 return result.append("SeamlessWebArea");
189 case blink::WebAXRoleSearch:
190 return result.append("Search");
191 case blink::WebAXRoleSheet:
192 return result.append("Sheet");
193 case blink::WebAXRoleSlider:
194 return result.append("Slider");
195 case blink::WebAXRoleSliderThumb:
196 return result.append("SliderThumb");
197 case blink::WebAXRoleSpinButtonPart:
198 return result.append("SpinButtonPart");
199 case blink::WebAXRoleSpinButton:
200 return result.append("SpinButton");
201 case blink::WebAXRoleSplitGroup:
202 return result.append("SplitGroup");
203 case blink::WebAXRoleSplitter:
204 return result.append("Splitter");
205 case blink::WebAXRoleStaticText:
206 return result.append("StaticText");
207 case blink::WebAXRoleStatus:
208 return result.append("Status");
209 case blink::WebAXRoleSystemWide:
210 return result.append("SystemWide");
211 case blink::WebAXRoleTabGroup:
212 return result.append("TabGroup");
213 case blink::WebAXRoleTabList:
214 return result.append("TabList");
215 case blink::WebAXRoleTabPanel:
216 return result.append("TabPanel");
217 case blink::WebAXRoleTab:
218 return result.append("Tab");
219 case blink::WebAXRoleTableHeaderContainer:
220 return result.append("TableHeaderContainer");
221 case blink::WebAXRoleTable:
222 return result.append("Table");
223 case blink::WebAXRoleTextArea:
224 return result.append("TextArea");
225 case blink::WebAXRoleTextField:
226 return result.append("TextField");
227 case blink::WebAXRoleTimer:
228 return result.append("Timer");
229 case blink::WebAXRoleToggleButton:
230 return result.append("ToggleButton");
231 case blink::WebAXRoleToolbar:
232 return result.append("Toolbar");
233 case blink::WebAXRoleTreeGrid:
234 return result.append("TreeGrid");
235 case blink::WebAXRoleTreeItem:
236 return result.append("TreeItem");
237 case blink::WebAXRoleTree:
238 return result.append("Tree");
239 case blink::WebAXRoleUnknown:
240 return result.append("Unknown");
241 case blink::WebAXRoleUserInterfaceTooltip:
242 return result.append("UserInterfaceTooltip");
243 case blink::WebAXRoleValueIndicator:
244 return result.append("ValueIndicator");
245 case blink::WebAXRoleWebArea:
246 return result.append("WebArea");
247 case blink::WebAXRoleWindow:
248 return result.append("Window");
249 default:
250 return result.append("Unknown");
251 }
252 }
253
254 std::string GetDescription(const blink::WebAXObject& object) {
255 std::string description = object.accessibilityDescription().utf8();
256 return description.insert(0, "AXDescription: ");
257 }
258
259 std::string GetHelpText(const blink::WebAXObject& object) {
260 std::string help_text = object.helpText().utf8();
261 return help_text.insert(0, "AXHelp: ");
262 }
263
264 std::string GetStringValue(const blink::WebAXObject& object) {
265 std::string value;
266 if (object.role() == blink::WebAXRoleColorWell) {
267 int r, g, b;
268 char buffer[100];
269 object.colorValue(r, g, b);
270 snprintf(buffer, sizeof(buffer), "rgb %7.5f %7.5f %7.5f 1",
271 r / 255., g / 255., b / 255.);
272 value = buffer;
273 } else {
274 value = object.stringValue().utf8();
275 }
276 return value.insert(0, "AXValue: ");
277 }
278
279 std::string GetRole(const blink::WebAXObject& object) {
280 std::string role_string = RoleToString(object.role());
281
282 // Special-case canvas with fallback content because Chromium wants to treat
283 // this as essentially a separate role that it can map differently depending
284 // on the platform.
285 if (object.role() == blink::WebAXRoleCanvas &&
286 object.canvasHasFallbackContent()) {
287 role_string += "WithFallbackContent";
288 }
289
290 return role_string;
291 }
292
293 std::string GetTitle(const blink::WebAXObject& object) {
294 std::string title = object.title().utf8();
295 return title.insert(0, "AXTitle: ");
296 }
297
298 std::string GetOrientation(const blink::WebAXObject& object) {
299 if (object.isVertical())
300 return "AXOrientation: AXVerticalOrientation";
301
302 return "AXOrientation: AXHorizontalOrientation";
303 }
304
305 std::string GetValueDescription(const blink::WebAXObject& object) {
306 std::string value_description = object.valueDescription().utf8();
307 return value_description.insert(0, "AXValueDescription: ");
308 }
309
310 std::string GetAttributes(const blink::WebAXObject& object) {
311 // FIXME: Concatenate all attributes of the AXObject.
312 std::string attributes(GetTitle(object));
313 attributes.append("\n");
314 attributes.append(GetRole(object));
315 attributes.append("\n");
316 attributes.append(GetDescription(object));
317 return attributes;
318 }
319
320 blink::WebRect BoundsForCharacter(const blink::WebAXObject& object,
321 int characterIndex) {
322 DCHECK_EQ(object.role(), blink::WebAXRoleStaticText);
323 int end = 0;
324 for (unsigned i = 0; i < object.childCount(); i++) {
325 blink::WebAXObject inline_text_box = object.childAt(i);
326 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox);
327 int start = end;
328 end += inline_text_box.stringValue().length();
329 if (end <= characterIndex)
330 continue;
331 blink::WebRect inline_text_box_rect = inline_text_box.boundingBoxRect();
332 int localIndex = characterIndex - start;
333 blink::WebVector<int> character_offsets;
334 inline_text_box.characterOffsets(character_offsets);
335 DCHECK(character_offsets.size() > 0 &&
336 character_offsets.size() == inline_text_box.stringValue().length());
337 switch (inline_text_box.textDirection()) {
338 case blink::WebAXTextDirectionLR: {
339 if (localIndex) {
340 int left = inline_text_box_rect.x + character_offsets[localIndex - 1];
341 int width = character_offsets[localIndex] -
342 character_offsets[localIndex - 1];
343 return blink::WebRect(left, inline_text_box_rect.y,
344 width, inline_text_box_rect.height);
345 }
346 return blink::WebRect(
347 inline_text_box_rect.x, inline_text_box_rect.y,
348 character_offsets[0], inline_text_box_rect.height);
349 }
350 case blink::WebAXTextDirectionRL: {
351 int right = inline_text_box_rect.x + inline_text_box_rect.width;
352
353 if (localIndex) {
354 int left = right - character_offsets[localIndex];
355 int width = character_offsets[localIndex] -
356 character_offsets[localIndex - 1];
357 return blink::WebRect(left, inline_text_box_rect.y,
358 width, inline_text_box_rect.height);
359 }
360 int left = right - character_offsets[0];
361 return blink::WebRect(
362 left, inline_text_box_rect.y,
363 character_offsets[0], inline_text_box_rect.height);
364 }
365 case blink::WebAXTextDirectionTB: {
366 if (localIndex) {
367 int top = inline_text_box_rect.y + character_offsets[localIndex - 1];
368 int height = character_offsets[localIndex] -
369 character_offsets[localIndex - 1];
370 return blink::WebRect(inline_text_box_rect.x, top,
371 inline_text_box_rect.width, height);
372 }
373 return blink::WebRect(inline_text_box_rect.x, inline_text_box_rect.y,
374 inline_text_box_rect.width, character_offsets[0]);
375 }
376 case blink::WebAXTextDirectionBT: {
377 int bottom = inline_text_box_rect.y + inline_text_box_rect.height;
378
379 if (localIndex) {
380 int top = bottom - character_offsets[localIndex];
381 int height = character_offsets[localIndex] -
382 character_offsets[localIndex - 1];
383 return blink::WebRect(inline_text_box_rect.x, top,
384 inline_text_box_rect.width, height);
385 }
386 int top = bottom - character_offsets[0];
387 return blink::WebRect(inline_text_box_rect.x, top,
388 inline_text_box_rect.width, character_offsets[0]);
389 }
390 }
391 }
392
393 DCHECK(false);
394 return blink::WebRect();
395 }
396
397 void GetBoundariesForOneWord(const blink::WebAXObject& object,
398 int character_index,
399 int& word_start,
400 int& word_end) {
401 int end = 0;
402 for (unsigned i = 0; i < object.childCount(); i++) {
403 blink::WebAXObject inline_text_box = object.childAt(i);
404 DCHECK_EQ(inline_text_box.role(), blink::WebAXRoleInlineTextBox);
405 int start = end;
406 end += inline_text_box.stringValue().length();
407 if (end <= character_index)
408 continue;
409 int localIndex = character_index - start;
410
411 blink::WebVector<int> starts;
412 blink::WebVector<int> ends;
413 inline_text_box.wordBoundaries(starts, ends);
414 size_t word_count = starts.size();
415 DCHECK_EQ(ends.size(), word_count);
416
417 // If there are no words, use the InlineTextBox boundaries.
418 if (!word_count) {
419 word_start = start;
420 word_end = end;
421 return;
422 }
423
424 // Look for a character within any word other than the last.
425 for (size_t j = 0; j < word_count - 1; j++) {
426 if (localIndex <= ends[j]) {
427 word_start = start + starts[j];
428 word_end = start + ends[j];
429 return;
430 }
431 }
432
433 // Return the last word by default.
434 word_start = start + starts[word_count - 1];
435 word_end = start + ends[word_count - 1];
436 return;
437 }
438 }
439
440 // Collects attributes into a string, delimited by dashes. Used by all methods
441 // that output lists of attributes: attributesOfLinkedUIElementsCallback,
442 // AttributesOfChildrenCallback, etc.
443 class AttributesCollector {
444 public:
445 AttributesCollector() {}
446 ~AttributesCollector() {}
447
448 void CollectAttributes(const blink::WebAXObject& object) {
449 attributes_.append("\n------------\n");
450 attributes_.append(GetAttributes(object));
451 }
452
453 std::string attributes() const { return attributes_; }
454
455 private:
456 std::string attributes_;
457
458 DISALLOW_COPY_AND_ASSIGN(AttributesCollector);
459 };
460
461 } // namespace
462
463 gin::WrapperInfo WebAXObjectProxy::kWrapperInfo = {
464 gin::kEmbedderNativeGin};
465
466 WebAXObjectProxy::WebAXObjectProxy(const blink::WebAXObject& object,
467 WebAXObjectProxy::Factory* factory)
468 : accessibility_object_(object),
469 factory_(factory) {
470 }
471
472 WebAXObjectProxy::~WebAXObjectProxy() {}
473
474 gin::ObjectTemplateBuilder
475 WebAXObjectProxy::GetObjectTemplateBuilder(v8::Isolate* isolate) {
476 return gin::Wrappable<WebAXObjectProxy>::GetObjectTemplateBuilder(isolate)
477 .SetProperty("role", &WebAXObjectProxy::Role)
478 .SetProperty("title", &WebAXObjectProxy::Title)
479 .SetProperty("description", &WebAXObjectProxy::Description)
480 .SetProperty("helpText", &WebAXObjectProxy::HelpText)
481 .SetProperty("stringValue", &WebAXObjectProxy::StringValue)
482 .SetProperty("x", &WebAXObjectProxy::X)
483 .SetProperty("y", &WebAXObjectProxy::Y)
484 .SetProperty("width", &WebAXObjectProxy::Width)
485 .SetProperty("height", &WebAXObjectProxy::Height)
486 .SetProperty("intValue", &WebAXObjectProxy::IntValue)
487 .SetProperty("minValue", &WebAXObjectProxy::MinValue)
488 .SetProperty("maxValue", &WebAXObjectProxy::MaxValue)
489 .SetProperty("valueDescription", &WebAXObjectProxy::ValueDescription)
490 .SetProperty("childrenCount", &WebAXObjectProxy::ChildrenCount)
491 .SetProperty("insertionPointLineNumber",
492 &WebAXObjectProxy::InsertionPointLineNumber)
493 .SetProperty("selectedTextRange", &WebAXObjectProxy::SelectedTextRange)
494 .SetProperty("isEnabled", &WebAXObjectProxy::IsEnabled)
495 .SetProperty("isRequired", &WebAXObjectProxy::IsRequired)
496 .SetProperty("isFocused", &WebAXObjectProxy::IsFocused)
497 .SetProperty("isFocusable", &WebAXObjectProxy::IsFocusable)
498 .SetProperty("isSelected", &WebAXObjectProxy::IsSelected)
499 .SetProperty("isSelectable", &WebAXObjectProxy::IsSelectable)
500 .SetProperty("isMultiSelectable", &WebAXObjectProxy::IsMultiSelectable)
501 .SetProperty("isSelectedOptionActive",
502 &WebAXObjectProxy::IsSelectedOptionActive)
503 .SetProperty("isExpanded", &WebAXObjectProxy::IsExpanded)
504 .SetProperty("isChecked", &WebAXObjectProxy::IsChecked)
505 .SetProperty("isVisible", &WebAXObjectProxy::IsVisible)
506 .SetProperty("isOffScreen", &WebAXObjectProxy::IsOffScreen)
507 .SetProperty("isCollapsed", &WebAXObjectProxy::IsCollapsed)
508 .SetProperty("hasPopup", &WebAXObjectProxy::HasPopup)
509 .SetProperty("isValid", &WebAXObjectProxy::IsValid)
510 .SetProperty("isReadOnly", &WebAXObjectProxy::IsReadOnly)
511 .SetProperty("orientation", &WebAXObjectProxy::Orientation)
512 .SetProperty("clickPointX", &WebAXObjectProxy::ClickPointX)
513 .SetProperty("clickPointY", &WebAXObjectProxy::ClickPointY)
514 .SetProperty("rowCount", &WebAXObjectProxy::RowCount)
515 .SetProperty("columnCount", &WebAXObjectProxy::ColumnCount)
516 .SetProperty("isClickable", &WebAXObjectProxy::IsClickable)
517 .SetMethod("allAttributes", &WebAXObjectProxy::AllAttributes)
518 .SetMethod("attributesOfChildren",
519 &WebAXObjectProxy::AttributesOfChildren)
520 .SetMethod("lineForIndex", &WebAXObjectProxy::LineForIndex)
521 .SetMethod("boundsForRange", &WebAXObjectProxy::BoundsForRange)
522 .SetMethod("childAtIndex", &WebAXObjectProxy::ChildAtIndex)
523 .SetMethod("elementAtPoint", &WebAXObjectProxy::ElementAtPoint)
524 .SetMethod("tableHeader", &WebAXObjectProxy::TableHeader)
525 .SetMethod("rowIndexRange", &WebAXObjectProxy::RowIndexRange)
526 .SetMethod("columnIndexRange", &WebAXObjectProxy::ColumnIndexRange)
527 .SetMethod("cellForColumnAndRow", &WebAXObjectProxy::CellForColumnAndRow)
528 .SetMethod("titleUIElement", &WebAXObjectProxy::TitleUIElement)
529 .SetMethod("setSelectedTextRange",
530 &WebAXObjectProxy::SetSelectedTextRange)
531 .SetMethod("isAttributeSettable", &WebAXObjectProxy::IsAttributeSettable)
532 .SetMethod("isPressActionSupported",
533 &WebAXObjectProxy::IsPressActionSupported)
534 .SetMethod("isIncrementActionSupported",
535 &WebAXObjectProxy::IsIncrementActionSupported)
536 .SetMethod("isDecrementActionSupported",
537 &WebAXObjectProxy::IsDecrementActionSupported)
538 .SetMethod("parentElement", &WebAXObjectProxy::ParentElement)
539 .SetMethod("increment", &WebAXObjectProxy::Increment)
540 .SetMethod("decrement", &WebAXObjectProxy::Decrement)
541 .SetMethod("showMenu", &WebAXObjectProxy::ShowMenu)
542 .SetMethod("press", &WebAXObjectProxy::Press)
543 .SetMethod("isEqual", &WebAXObjectProxy::IsEqual)
544 .SetMethod("setNotificationListener",
545 &WebAXObjectProxy::SetNotificationListener)
546 .SetMethod("unsetNotificationListener",
547 &WebAXObjectProxy::UnsetNotificationListener)
548 .SetMethod("takeFocus", &WebAXObjectProxy::TakeFocus)
549 .SetMethod("scrollToMakeVisible", &WebAXObjectProxy::ScrollToMakeVisible)
550 .SetMethod("scrollToMakeVisibleWithSubFocus",
551 &WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus)
552 .SetMethod("scrollToGlobalPoint", &WebAXObjectProxy::ScrollToGlobalPoint)
553 .SetMethod("wordStart", &WebAXObjectProxy::WordStart)
554 .SetMethod("wordEnd", &WebAXObjectProxy::WordEnd)
555 // TODO(hajimehoshi): This is for backward compatibility. Remove them.
556 .SetMethod("addNotificationListener",
557 &WebAXObjectProxy::SetNotificationListener)
558 .SetMethod("removeNotificationListener",
559 &WebAXObjectProxy::UnsetNotificationListener);
560 }
561
562 v8::Handle<v8::Object> WebAXObjectProxy::GetChildAtIndex(unsigned index) {
563 return factory_->GetOrCreate(accessibility_object().childAt(index));
564 }
565
566 bool WebAXObjectProxy::IsRoot() const {
567 return false;
568 }
569
570 bool WebAXObjectProxy::IsEqualToObject(const blink::WebAXObject& other) {
571 return accessibility_object().equals(other);
572 }
573
574 void WebAXObjectProxy::NotificationReceived(
575 blink::WebFrame* frame,
576 const std::string& notification_name) {
577 if (notification_callback_.IsEmpty())
578 return;
579
580 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
581 if (context.IsEmpty())
582 return;
583
584 v8::Isolate* isolate = blink::mainThreadIsolate();
585
586 v8::Handle<v8::Value> argv[] = {
587 v8::String::NewFromUtf8(isolate, notification_name.data(),
588 v8::String::kNormalString,
589 notification_name.size()),
590 };
591 frame->callFunctionEvenIfScriptDisabled(
592 v8::Local<v8::Function>::New(isolate, notification_callback_),
593 context->Global(),
594 arraysize(argv),
595 argv);
596 }
597
598 std::string WebAXObjectProxy::Role() {
599 return GetRole(accessibility_object());
600 }
601
602 std::string WebAXObjectProxy::Title() {
603 return GetTitle(accessibility_object());
604 }
605
606 std::string WebAXObjectProxy::Description() {
607 return GetDescription(accessibility_object());
608 }
609
610 std::string WebAXObjectProxy::HelpText() {
611 return GetHelpText(accessibility_object());
612 }
613
614 std::string WebAXObjectProxy::StringValue() {
615 return GetStringValue(accessibility_object());
616 }
617
618 int WebAXObjectProxy::X() {
619 return accessibility_object().boundingBoxRect().x;
620 }
621
622 int WebAXObjectProxy::Y() {
623 return accessibility_object().boundingBoxRect().y;
624 }
625
626 int WebAXObjectProxy::Width() {
627 return accessibility_object().boundingBoxRect().width;
628 }
629
630 int WebAXObjectProxy::Height() {
631 return accessibility_object().boundingBoxRect().height;
632 }
633
634 int WebAXObjectProxy::IntValue() {
635 if (accessibility_object().supportsRangeValue())
636 return accessibility_object().valueForRange();
637 else if (accessibility_object().role() == blink::WebAXRoleHeading)
638 return accessibility_object().headingLevel();
639 else
640 return atoi(accessibility_object().stringValue().utf8().data());
641 }
642
643 int WebAXObjectProxy::MinValue() {
644 return accessibility_object().minValueForRange();
645 }
646
647 int WebAXObjectProxy::MaxValue() {
648 return accessibility_object().maxValueForRange();
649 }
650
651 std::string WebAXObjectProxy::ValueDescription() {
652 return GetValueDescription(accessibility_object());
653 }
654
655 int WebAXObjectProxy::ChildrenCount() {
656 int count = 1; // Root object always has only one child, the WebView.
657 if (!IsRoot())
658 count = accessibility_object().childCount();
659 return count;
660 }
661
662 int WebAXObjectProxy::InsertionPointLineNumber() {
663 if (!accessibility_object().isFocused())
664 return -1;
665 return accessibility_object().selectionEndLineNumber();
666 }
667
668 std::string WebAXObjectProxy::SelectedTextRange() {
669 unsigned selection_start = accessibility_object().selectionStart();
670 unsigned selection_end = accessibility_object().selectionEnd();
671 char buffer[100];
672 snprintf(buffer, sizeof(buffer), "{%d, %d}",
673 selection_start, selection_end - selection_start);
674 return std::string(buffer);
675 }
676
677 bool WebAXObjectProxy::IsEnabled() {
678 return accessibility_object().isEnabled();
679 }
680
681 bool WebAXObjectProxy::IsRequired() {
682 return accessibility_object().isRequired();
683 }
684
685 bool WebAXObjectProxy::IsFocused() {
686 return accessibility_object().isFocused();
687 }
688
689 bool WebAXObjectProxy::IsFocusable() {
690 return accessibility_object().canSetFocusAttribute();
691 }
692
693 bool WebAXObjectProxy::IsSelected() {
694 return accessibility_object().isSelected();
695 }
696
697 bool WebAXObjectProxy::IsSelectable() {
698 return accessibility_object().canSetSelectedAttribute();
699 }
700
701 bool WebAXObjectProxy::IsMultiSelectable() {
702 return accessibility_object().isMultiSelectable();
703 }
704
705 bool WebAXObjectProxy::IsSelectedOptionActive() {
706 return accessibility_object().isSelectedOptionActive();
707 }
708
709 bool WebAXObjectProxy::IsExpanded() {
710 return !accessibility_object().isCollapsed();
711 }
712
713 bool WebAXObjectProxy::IsChecked() {
714 return accessibility_object().isChecked();
715 }
716
717 bool WebAXObjectProxy::IsVisible() {
718 return accessibility_object().isVisible();
719 }
720
721 bool WebAXObjectProxy::IsOffScreen() {
722 return accessibility_object().isOffScreen();
723 }
724
725 bool WebAXObjectProxy::IsCollapsed() {
726 return accessibility_object().isCollapsed();
727 }
728
729 bool WebAXObjectProxy::HasPopup() {
730 return accessibility_object().ariaHasPopup();
731 }
732
733 bool WebAXObjectProxy::IsValid() {
734 return !accessibility_object().isDetached();
735 }
736
737 bool WebAXObjectProxy::IsReadOnly() {
738 return accessibility_object().isReadOnly();
739 }
740
741 std::string WebAXObjectProxy::Orientation() {
742 return GetOrientation(accessibility_object());
743 }
744
745 int WebAXObjectProxy::ClickPointX() {
746 return accessibility_object().clickPoint().x;
747 }
748
749 int WebAXObjectProxy::ClickPointY() {
750 return accessibility_object().clickPoint().y;
751 }
752
753 int32_t WebAXObjectProxy::RowCount() {
754 return static_cast<int32_t>(accessibility_object().rowCount());
755 }
756
757 int32_t WebAXObjectProxy::ColumnCount() {
758 return static_cast<int32_t>(accessibility_object().columnCount());
759 }
760
761 bool WebAXObjectProxy::IsClickable() {
762 return accessibility_object().isClickable();
763 }
764
765 std::string WebAXObjectProxy::AllAttributes() {
766 return GetAttributes(accessibility_object());
767 }
768
769 std::string WebAXObjectProxy::AttributesOfChildren() {
770 AttributesCollector collector;
771 unsigned size = accessibility_object().childCount();
772 for (unsigned i = 0; i < size; ++i)
773 collector.CollectAttributes(accessibility_object().childAt(i));
774 return collector.attributes();
775 }
776
777 int WebAXObjectProxy::LineForIndex(int index) {
778 blink::WebVector<int> line_breaks;
779 accessibility_object().lineBreaks(line_breaks);
780 int line = 0;
781 int vector_size = static_cast<int>(line_breaks.size());
782 while (line < vector_size && line_breaks[line] <= index)
783 line++;
784 return line;
785 }
786
787 std::string WebAXObjectProxy::BoundsForRange(int start, int end) {
788 if (accessibility_object().role() != blink::WebAXRoleStaticText)
789 return std::string();
790
791 int len = end - start;
792
793 // Get the bounds for each character and union them into one large rectangle.
794 // This is just for testing so it doesn't need to be efficient.
795 blink::WebRect bounds = BoundsForCharacter(accessibility_object(), start);
796 for (int i = 1; i < len; i++) {
797 blink::WebRect next = BoundsForCharacter(accessibility_object(), start + i);
798 int right = std::max(bounds.x + bounds.width, next.x + next.width);
799 int bottom = std::max(bounds.y + bounds.height, next.y + next.height);
800 bounds.x = std::min(bounds.x, next.x);
801 bounds.y = std::min(bounds.y, next.y);
802 bounds.width = right - bounds.x;
803 bounds.height = bottom - bounds.y;
804 }
805
806 char buffer[100];
807 snprintf(buffer, sizeof(buffer), "{x: %d, y: %d, width: %d, height: %d}",
808 bounds.x, bounds.y, bounds.width, bounds.height);
809 return std::string(buffer);
810 }
811
812 v8::Handle<v8::Object> WebAXObjectProxy::ChildAtIndex(int index) {
813 return GetChildAtIndex(index);
814 }
815
816 v8::Handle<v8::Object> WebAXObjectProxy::ElementAtPoint(int x, int y) {
817 blink::WebPoint point(x, y);
818 blink::WebAXObject obj = accessibility_object().hitTest(point);
819 if (obj.isNull())
820 return v8::Handle<v8::Object>();
821
822 return factory_->GetOrCreate(obj);
823 }
824
825 v8::Handle<v8::Object> WebAXObjectProxy::TableHeader() {
826 blink::WebAXObject obj = accessibility_object().headerContainerObject();
827 if (obj.isNull())
828 return v8::Handle<v8::Object>();
829
830 return factory_->GetOrCreate(obj);
831 }
832
833 std::string WebAXObjectProxy::RowIndexRange() {
834 unsigned row_index = accessibility_object().cellRowIndex();
835 unsigned row_span = accessibility_object().cellRowSpan();
836 char buffer[100];
837 snprintf(buffer, sizeof(buffer), "{%d, %d}", row_index, row_span);
838 return std::string(buffer);
839 }
840
841 std::string WebAXObjectProxy::ColumnIndexRange() {
842 unsigned column_index = accessibility_object().cellColumnIndex();
843 unsigned column_span = accessibility_object().cellColumnSpan();
844 char buffer[100];
845 snprintf(buffer, sizeof(buffer), "{%d, %d}", column_index, column_span);
846 return std::string(buffer);
847 }
848
849 v8::Handle<v8::Object> WebAXObjectProxy::CellForColumnAndRow(
850 int column, int row) {
851 blink::WebAXObject obj =
852 accessibility_object().cellForColumnAndRow(column, row);
853 if (obj.isNull())
854 return v8::Handle<v8::Object>();
855
856 return factory_->GetOrCreate(obj);
857 }
858
859 v8::Handle<v8::Object> WebAXObjectProxy::TitleUIElement() {
860 blink::WebAXObject obj = accessibility_object().titleUIElement();
861 if (obj.isNull())
862 return v8::Handle<v8::Object>();
863
864 return factory_->GetOrCreate(obj);
865 }
866
867 void WebAXObjectProxy::SetSelectedTextRange(int selection_start,
868 int length) {
869 accessibility_object().setSelectedTextRange(selection_start,
870 selection_start + length);
871 }
872
873 bool WebAXObjectProxy::IsAttributeSettable(const std::string& attribute) {
874 bool settable = false;
875 if (attribute == "AXValue")
876 settable = accessibility_object().canSetValueAttribute();
877 return settable;
878 }
879
880 bool WebAXObjectProxy::IsPressActionSupported() {
881 return accessibility_object().canPress();
882 }
883
884 bool WebAXObjectProxy::IsIncrementActionSupported() {
885 return accessibility_object().canIncrement();
886 }
887
888 bool WebAXObjectProxy::IsDecrementActionSupported() {
889 return accessibility_object().canDecrement();
890 }
891
892 v8::Handle<v8::Object> WebAXObjectProxy::ParentElement() {
893 blink::WebAXObject parent_object = accessibility_object().parentObject();
894 while (parent_object.accessibilityIsIgnored())
895 parent_object = parent_object.parentObject();
896 return factory_->GetOrCreate(parent_object);
897 }
898
899 void WebAXObjectProxy::Increment() {
900 accessibility_object().increment();
901 }
902
903 void WebAXObjectProxy::Decrement() {
904 accessibility_object().decrement();
905 }
906
907 void WebAXObjectProxy::ShowMenu() {
908 }
909
910 void WebAXObjectProxy::Press() {
911 accessibility_object().press();
912 }
913
914 bool WebAXObjectProxy::IsEqual(v8::Handle<v8::Object> proxy) {
915 WebAXObjectProxy* unwrapped_proxy = NULL;
916 if (!gin::ConvertFromV8(blink::mainThreadIsolate(), proxy, &unwrapped_proxy))
917 return false;
918 return unwrapped_proxy->IsEqualToObject(accessibility_object_);
919 }
920
921 void WebAXObjectProxy::SetNotificationListener(
922 v8::Handle<v8::Function> callback) {
923 v8::Isolate* isolate = blink::mainThreadIsolate();
924 notification_callback_.Reset(isolate, callback);
925 }
926
927 void WebAXObjectProxy::UnsetNotificationListener() {
928 notification_callback_.Reset();
929 }
930
931 void WebAXObjectProxy::TakeFocus() {
932 accessibility_object().setFocused(true);
933 }
934
935 void WebAXObjectProxy::ScrollToMakeVisible() {
936 accessibility_object().scrollToMakeVisible();
937 }
938
939 void WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus(int x, int y,
940 int width, int height) {
941 accessibility_object().scrollToMakeVisibleWithSubFocus(
942 blink::WebRect(x, y, width, height));
943 }
944
945 void WebAXObjectProxy::ScrollToGlobalPoint(int x, int y) {
946 accessibility_object().scrollToGlobalPoint(blink::WebPoint(x, y));
947 }
948
949 int WebAXObjectProxy::WordStart(int character_index) {
950 if (accessibility_object().role() != blink::WebAXRoleStaticText)
951 return -1;
952
953 int word_start, word_end;
954 GetBoundariesForOneWord(accessibility_object(), character_index,
955 word_start, word_end);
956 return word_start;
957 }
958
959 int WebAXObjectProxy::WordEnd(int character_index) {
960 if (accessibility_object().role() != blink::WebAXRoleStaticText)
961 return -1;
962
963 int word_start, word_end;
964 GetBoundariesForOneWord(accessibility_object(), character_index,
965 word_start, word_end);
966 return word_end;
967 }
968
969 RootWebAXObjectProxy::RootWebAXObjectProxy(
970 const blink::WebAXObject &object, Factory *factory)
971 : WebAXObjectProxy(object, factory) {
972 }
973
974 v8::Handle<v8::Object> RootWebAXObjectProxy::GetChildAtIndex(unsigned index) {
975 if (index)
976 return v8::Handle<v8::Object>();
977
978 return factory()->GetOrCreate(accessibility_object());
979 }
980
981 bool RootWebAXObjectProxy::IsRoot() const {
982 return true;
983 }
984
985 WebAXObjectProxyList::WebAXObjectProxyList() {
986 }
987
988 WebAXObjectProxyList::~WebAXObjectProxyList() {
989 Clear();
990 }
991
992 void WebAXObjectProxyList::Clear() {
993 for (ElementList::iterator i = elements_.begin(); i != elements_.end(); ++i)
994 i->Dispose();
995 elements_.clear();
996 }
997
998 v8::Handle<v8::Object> WebAXObjectProxyList::GetOrCreate(
999 const blink::WebAXObject& object) {
1000 if (object.isNull())
1001 return v8::Handle<v8::Object>();
1002
1003 v8::Isolate* isolate = blink::mainThreadIsolate();
1004
1005 size_t elementCount = elements_.size();
1006 for (size_t i = 0; i < elementCount; i++) {
1007 WebAXObjectProxy* unwrapped_object = NULL;
1008 bool result = gin::ConvertFromV8(isolate, elements_[i].NewLocal(isolate),
1009 &unwrapped_object);
1010 DCHECK(result);
1011 DCHECK(unwrapped_object);
1012 if (unwrapped_object->IsEqualToObject(object))
1013 return elements_[i].NewLocal(isolate);
1014 }
1015
1016 v8::Handle<v8::Object> handle = gin::CreateHandle(
1017 isolate, new WebAXObjectProxy(object, this)).ToV8()->ToObject();
1018 UnsafePersistent<v8::Object> unsafe_handle(isolate, handle);
1019 elements_.push_back(unsafe_handle);
1020 return unsafe_handle.NewLocal(isolate);
1021 }
1022
1023 v8::Handle<v8::Object> WebAXObjectProxyList::CreateRoot(
1024 const blink::WebAXObject& object) {
1025 v8::Isolate* isolate = blink::mainThreadIsolate();
1026 v8::Handle<v8::Object> handle = gin::CreateHandle(
1027 isolate, new RootWebAXObjectProxy(object, this)).ToV8()->ToObject();
1028 UnsafePersistent<v8::Object> unsafe_handle(isolate, handle);
1029 elements_.push_back(unsafe_handle);
1030 return unsafe_handle.NewLocal(isolate);
1031 }
1032
1033 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698