OLD | NEW |
(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 // static |
| 464 gin::WrapperInfo WebAXObjectProxy::kWrapperInfo = { |
| 465 gin::kEmbedderNativeGin, |
| 466 }; |
| 467 |
| 468 WebAXObjectProxy::WebAXObjectProxy(const blink::WebAXObject& object, |
| 469 WebAXObjectProxy::Factory* factory) |
| 470 : accessibility_object_(object), |
| 471 factory_(factory) { |
| 472 } |
| 473 |
| 474 WebAXObjectProxy::~WebAXObjectProxy() { |
| 475 ClearNotificationCallbacks(); |
| 476 } |
| 477 |
| 478 gin::ObjectTemplateBuilder |
| 479 WebAXObjectProxy::GetObjectTemplateBuilder(v8::Isolate* isolate) { |
| 480 return gin::Wrappable<WebAXObjectProxy>::GetObjectTemplateBuilder(isolate) |
| 481 .SetProperty("role", &WebAXObjectProxy::Role) |
| 482 .SetProperty("title", &WebAXObjectProxy::Title) |
| 483 .SetProperty("description", &WebAXObjectProxy::Description) |
| 484 .SetProperty("helpText", &WebAXObjectProxy::HelpText) |
| 485 .SetProperty("stringValue", &WebAXObjectProxy::StringValue) |
| 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("insertionPointLineNumber", |
| 496 &WebAXObjectProxy::InsertionPointLineNumber) |
| 497 .SetProperty("selectedTextRange", &WebAXObjectProxy::SelectedTextRange) |
| 498 .SetProperty("isEnabled", &WebAXObjectProxy::IsEnabled) |
| 499 .SetProperty("isRequired", &WebAXObjectProxy::IsRequired) |
| 500 .SetProperty("isFocused", &WebAXObjectProxy::IsFocused) |
| 501 .SetProperty("isFocusable", &WebAXObjectProxy::IsFocusable) |
| 502 .SetProperty("isSelected", &WebAXObjectProxy::IsSelected) |
| 503 .SetProperty("isSelectable", &WebAXObjectProxy::IsSelectable) |
| 504 .SetProperty("isMultiSelectable", &WebAXObjectProxy::IsMultiSelectable) |
| 505 .SetProperty("isSelectedOptionActive", |
| 506 &WebAXObjectProxy::IsSelectedOptionActive) |
| 507 .SetProperty("isExpanded", &WebAXObjectProxy::IsExpanded) |
| 508 .SetProperty("isChecked", &WebAXObjectProxy::IsChecked) |
| 509 .SetProperty("isVisible", &WebAXObjectProxy::IsVisible) |
| 510 .SetProperty("isOffScreen", &WebAXObjectProxy::IsOffScreen) |
| 511 .SetProperty("isCollapsed", &WebAXObjectProxy::IsCollapsed) |
| 512 .SetProperty("hasPopup", &WebAXObjectProxy::HasPopup) |
| 513 .SetProperty("isValid", &WebAXObjectProxy::IsValid) |
| 514 .SetProperty("isReadOnly", &WebAXObjectProxy::IsReadOnly) |
| 515 .SetProperty("orientation", &WebAXObjectProxy::Orientation) |
| 516 .SetProperty("clickPointX", &WebAXObjectProxy::ClickPointX) |
| 517 .SetProperty("clickPointY", &WebAXObjectProxy::ClickPointY) |
| 518 .SetProperty("rowCount", &WebAXObjectProxy::RowCount) |
| 519 .SetProperty("columnCount", &WebAXObjectProxy::ColumnCount) |
| 520 .SetProperty("isClickable", &WebAXObjectProxy::IsClickable) |
| 521 .SetMethod("allAttributes", &WebAXObjectProxy::AllAttributes) |
| 522 .SetMethod("attributesOfChildren", |
| 523 &WebAXObjectProxy::AttributesOfChildren) |
| 524 .SetMethod("lineForIndex", &WebAXObjectProxy::LineForIndex) |
| 525 .SetMethod("boundsForRange", &WebAXObjectProxy::BoundsForRange) |
| 526 .SetMethod("childAtIndex", &WebAXObjectProxy::ChildAtIndex) |
| 527 .SetMethod("elementAtPoint", &WebAXObjectProxy::ElementAtPoint) |
| 528 .SetMethod("tableHeader", &WebAXObjectProxy::TableHeader) |
| 529 .SetMethod("rowIndexRange", &WebAXObjectProxy::RowIndexRange) |
| 530 .SetMethod("columnIndexRange", &WebAXObjectProxy::ColumnIndexRange) |
| 531 .SetMethod("cellForColumnAndRow", &WebAXObjectProxy::CellForColumnAndRow) |
| 532 .SetMethod("titleUIElement", &WebAXObjectProxy::TitleUIElement) |
| 533 .SetMethod("setSelectedTextRange", |
| 534 &WebAXObjectProxy::SetSelectedTextRange) |
| 535 .SetMethod("isAttributeSettable", &WebAXObjectProxy::IsAttributeSettable) |
| 536 .SetMethod("isPressActionSupported", |
| 537 &WebAXObjectProxy::IsPressActionSupported) |
| 538 .SetMethod("isIncrementActionSupported", |
| 539 &WebAXObjectProxy::IsIncrementActionSupported) |
| 540 .SetMethod("isDecrementActionSupported", |
| 541 &WebAXObjectProxy::IsDecrementActionSupported) |
| 542 .SetMethod("parentElement", &WebAXObjectProxy::ParentElement) |
| 543 .SetMethod("increment", &WebAXObjectProxy::Increment) |
| 544 .SetMethod("decrement", &WebAXObjectProxy::Decrement) |
| 545 .SetMethod("showMenu", &WebAXObjectProxy::ShowMenu) |
| 546 .SetMethod("press", &WebAXObjectProxy::Press) |
| 547 .SetMethod("isEqual", &WebAXObjectProxy::IsEqual) |
| 548 .SetMethod("addNotificationListener", |
| 549 &WebAXObjectProxy::AddNotificationListener) |
| 550 .SetMethod("removeNotificationListener", |
| 551 &WebAXObjectProxy::RemoveNotificationListener) |
| 552 .SetMethod("takeFocus", &WebAXObjectProxy::TakeFocus) |
| 553 .SetMethod("scrollToMakeVisible", &WebAXObjectProxy::ScrollToMakeVisible) |
| 554 .SetMethod("scrollToMakeVisibleWithSubFocus", |
| 555 &WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus) |
| 556 .SetMethod("scrollToGlobalPoint", &WebAXObjectProxy::ScrollToGlobalPoint) |
| 557 .SetMethod("wordStart", &WebAXObjectProxy::WordStart) |
| 558 .SetMethod("wordEnd", &WebAXObjectProxy::WordEnd); |
| 559 } |
| 560 |
| 561 v8::Handle<v8::Object> WebAXObjectProxy::GetChildAtIndex(unsigned index) { |
| 562 return factory_->GetOrCreate(accessibility_object().childAt(index)); |
| 563 } |
| 564 |
| 565 bool WebAXObjectProxy::IsRoot() const { |
| 566 return false; |
| 567 } |
| 568 |
| 569 bool WebAXObjectProxy::IsEqualToObject(const blink::WebAXObject& other) { |
| 570 return accessibility_object().equals(other); |
| 571 } |
| 572 |
| 573 void WebAXObjectProxy::NotificationReceived( |
| 574 v8::Handle<v8::Context> context, const std::string& notification_name) { |
| 575 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 576 |
| 577 v8::Handle<v8::Value> argv[] = { |
| 578 v8::String::NewFromUtf8(isolate, notification_name.data(), |
| 579 v8::String::kNormalString, |
| 580 notification_name.size()), |
| 581 }; |
| 582 for (CallbackList::iterator it = notification_callbacks_.begin(); |
| 583 it != notification_callbacks_.end(); ++it) { |
| 584 (*it)->Call(context->Global(), arraysize(argv), argv); |
| 585 } |
| 586 } |
| 587 |
| 588 std::string WebAXObjectProxy::Role() { |
| 589 return GetRole(accessibility_object()); |
| 590 } |
| 591 |
| 592 std::string WebAXObjectProxy::Title() { |
| 593 return GetTitle(accessibility_object()); |
| 594 } |
| 595 |
| 596 std::string WebAXObjectProxy::Description() { |
| 597 return GetDescription(accessibility_object()); |
| 598 } |
| 599 |
| 600 std::string WebAXObjectProxy::HelpText() { |
| 601 return GetHelpText(accessibility_object()); |
| 602 } |
| 603 |
| 604 std::string WebAXObjectProxy::StringValue() { |
| 605 return GetStringValue(accessibility_object()); |
| 606 } |
| 607 |
| 608 int WebAXObjectProxy::X() { |
| 609 return accessibility_object().boundingBoxRect().x; |
| 610 } |
| 611 |
| 612 int WebAXObjectProxy::Y() { |
| 613 return accessibility_object().boundingBoxRect().y; |
| 614 } |
| 615 |
| 616 int WebAXObjectProxy::Width() { |
| 617 return accessibility_object().boundingBoxRect().width; |
| 618 } |
| 619 |
| 620 int WebAXObjectProxy::Height() { |
| 621 return accessibility_object().boundingBoxRect().height; |
| 622 } |
| 623 |
| 624 int WebAXObjectProxy::IntValue() { |
| 625 if (accessibility_object().supportsRangeValue()) |
| 626 return accessibility_object().valueForRange(); |
| 627 else if (accessibility_object().role() == blink::WebAXRoleHeading) |
| 628 return accessibility_object().headingLevel(); |
| 629 else |
| 630 return atoi(accessibility_object().stringValue().utf8().data()); |
| 631 } |
| 632 |
| 633 int WebAXObjectProxy::MinValue() { |
| 634 return accessibility_object().minValueForRange(); |
| 635 } |
| 636 |
| 637 int WebAXObjectProxy::MaxValue() { |
| 638 return accessibility_object().maxValueForRange(); |
| 639 } |
| 640 |
| 641 std::string WebAXObjectProxy::ValueDescription() { |
| 642 return GetValueDescription(accessibility_object()); |
| 643 } |
| 644 |
| 645 int WebAXObjectProxy::ChildrenCount() { |
| 646 int count = 1; // Root object always has only one child, the WebView. |
| 647 if (!IsRoot()) |
| 648 count = accessibility_object().childCount(); |
| 649 return count; |
| 650 } |
| 651 |
| 652 int WebAXObjectProxy::InsertionPointLineNumber() { |
| 653 if (!accessibility_object().isFocused()) |
| 654 return -1; |
| 655 return accessibility_object().selectionEndLineNumber(); |
| 656 } |
| 657 |
| 658 std::string WebAXObjectProxy::SelectedTextRange() { |
| 659 unsigned selection_start = accessibility_object().selectionStart(); |
| 660 unsigned selection_end = accessibility_object().selectionEnd(); |
| 661 char buffer[100]; |
| 662 snprintf(buffer, sizeof(buffer), "{%d, %d}", |
| 663 selection_start, selection_end - selection_start); |
| 664 return std::string(buffer); |
| 665 } |
| 666 |
| 667 bool WebAXObjectProxy::IsEnabled() { |
| 668 return accessibility_object().isEnabled(); |
| 669 } |
| 670 |
| 671 bool WebAXObjectProxy::IsRequired() { |
| 672 return accessibility_object().isRequired(); |
| 673 } |
| 674 |
| 675 bool WebAXObjectProxy::IsFocused() { |
| 676 return accessibility_object().isFocused(); |
| 677 } |
| 678 |
| 679 bool WebAXObjectProxy::IsFocusable() { |
| 680 return accessibility_object().canSetFocusAttribute(); |
| 681 } |
| 682 |
| 683 bool WebAXObjectProxy::IsSelected() { |
| 684 return accessibility_object().isSelected(); |
| 685 } |
| 686 |
| 687 bool WebAXObjectProxy::IsSelectable() { |
| 688 return accessibility_object().canSetSelectedAttribute(); |
| 689 } |
| 690 |
| 691 bool WebAXObjectProxy::IsMultiSelectable() { |
| 692 return accessibility_object().isMultiSelectable(); |
| 693 } |
| 694 |
| 695 bool WebAXObjectProxy::IsSelectedOptionActive() { |
| 696 return accessibility_object().isSelectedOptionActive(); |
| 697 } |
| 698 |
| 699 bool WebAXObjectProxy::IsExpanded() { |
| 700 return !accessibility_object().isCollapsed(); |
| 701 } |
| 702 |
| 703 bool WebAXObjectProxy::IsChecked() { |
| 704 return accessibility_object().isChecked(); |
| 705 } |
| 706 |
| 707 bool WebAXObjectProxy::IsVisible() { |
| 708 return accessibility_object().isVisible(); |
| 709 } |
| 710 |
| 711 bool WebAXObjectProxy::IsOffScreen() { |
| 712 return accessibility_object().isOffScreen(); |
| 713 } |
| 714 |
| 715 bool WebAXObjectProxy::IsCollapsed() { |
| 716 return accessibility_object().isCollapsed(); |
| 717 } |
| 718 |
| 719 bool WebAXObjectProxy::HasPopup() { |
| 720 return accessibility_object().ariaHasPopup(); |
| 721 } |
| 722 |
| 723 bool WebAXObjectProxy::IsValid() { |
| 724 return !accessibility_object().isDetached(); |
| 725 } |
| 726 |
| 727 bool WebAXObjectProxy::IsReadOnly() { |
| 728 return accessibility_object().isReadOnly(); |
| 729 } |
| 730 |
| 731 std::string WebAXObjectProxy::Orientation() { |
| 732 return GetOrientation(accessibility_object()); |
| 733 } |
| 734 |
| 735 int WebAXObjectProxy::ClickPointX() { |
| 736 return accessibility_object().clickPoint().x; |
| 737 } |
| 738 |
| 739 int WebAXObjectProxy::ClickPointY() { |
| 740 return accessibility_object().clickPoint().y; |
| 741 } |
| 742 |
| 743 int32_t WebAXObjectProxy::RowCount() { |
| 744 return static_cast<int32_t>(accessibility_object().rowCount()); |
| 745 } |
| 746 |
| 747 int32_t WebAXObjectProxy::ColumnCount() { |
| 748 return static_cast<int32_t>(accessibility_object().columnCount()); |
| 749 } |
| 750 |
| 751 bool WebAXObjectProxy::IsClickable() { |
| 752 return accessibility_object().isClickable(); |
| 753 } |
| 754 |
| 755 std::string WebAXObjectProxy::AllAttributes() { |
| 756 return GetAttributes(accessibility_object()); |
| 757 } |
| 758 |
| 759 std::string WebAXObjectProxy::AttributesOfChildren() { |
| 760 AttributesCollector collector; |
| 761 unsigned size = accessibility_object().childCount(); |
| 762 for (unsigned i = 0; i < size; ++i) |
| 763 collector.CollectAttributes(accessibility_object().childAt(i)); |
| 764 return collector.attributes(); |
| 765 } |
| 766 |
| 767 int WebAXObjectProxy::LineForIndex(int index) { |
| 768 blink::WebVector<int> line_breaks; |
| 769 accessibility_object().lineBreaks(line_breaks); |
| 770 int line = 0; |
| 771 int vector_size = static_cast<int>(line_breaks.size()); |
| 772 while (line < vector_size && line_breaks[line] <= index) |
| 773 line++; |
| 774 return line; |
| 775 } |
| 776 |
| 777 std::string WebAXObjectProxy::BoundsForRange(int start, int end) { |
| 778 if (accessibility_object().role() != blink::WebAXRoleStaticText) |
| 779 return std::string(); |
| 780 |
| 781 int len = end - start; |
| 782 |
| 783 // Get the bounds for each character and union them into one large rectangle. |
| 784 // This is just for testing so it doesn't need to be efficient. |
| 785 blink::WebRect bounds = BoundsForCharacter(accessibility_object(), start); |
| 786 for (int i = 1; i < len; i++) { |
| 787 blink::WebRect next = BoundsForCharacter(accessibility_object(), start + i); |
| 788 int right = std::max(bounds.x + bounds.width, next.x + next.width); |
| 789 int bottom = std::max(bounds.y + bounds.height, next.y + next.height); |
| 790 bounds.x = std::min(bounds.x, next.x); |
| 791 bounds.y = std::min(bounds.y, next.y); |
| 792 bounds.width = right - bounds.x; |
| 793 bounds.height = bottom - bounds.y; |
| 794 } |
| 795 |
| 796 char buffer[100]; |
| 797 snprintf(buffer, sizeof(buffer), "{x: %d, y: %d, width: %d, height: %d}", |
| 798 bounds.x, bounds.y, bounds.width, bounds.height); |
| 799 return std::string(buffer); |
| 800 } |
| 801 |
| 802 v8::Handle<v8::Object> WebAXObjectProxy::ChildAtIndex(int index) { |
| 803 return GetChildAtIndex(index); |
| 804 } |
| 805 |
| 806 v8::Handle<v8::Object> WebAXObjectProxy::ElementAtPoint(int x, int y) { |
| 807 blink::WebPoint point(x, y); |
| 808 blink::WebAXObject obj = accessibility_object().hitTest(point); |
| 809 if (obj.isNull()) |
| 810 return v8::Handle<v8::Object>(); |
| 811 |
| 812 return factory_->GetOrCreate(obj); |
| 813 } |
| 814 |
| 815 v8::Handle<v8::Object> WebAXObjectProxy::TableHeader() { |
| 816 blink::WebAXObject obj = accessibility_object().headerContainerObject(); |
| 817 if (obj.isNull()) |
| 818 return v8::Handle<v8::Object>(); |
| 819 |
| 820 return factory_->GetOrCreate(obj); |
| 821 } |
| 822 |
| 823 std::string WebAXObjectProxy::RowIndexRange() { |
| 824 unsigned row_index = accessibility_object().cellRowIndex(); |
| 825 unsigned row_span = accessibility_object().cellRowSpan(); |
| 826 char buffer[100]; |
| 827 snprintf(buffer, sizeof(buffer), "{%d, %d}", row_index, row_span); |
| 828 return std::string(buffer); |
| 829 } |
| 830 |
| 831 std::string WebAXObjectProxy::ColumnIndexRange() { |
| 832 unsigned column_index = accessibility_object().cellColumnIndex(); |
| 833 unsigned column_span = accessibility_object().cellColumnSpan(); |
| 834 char buffer[100]; |
| 835 snprintf(buffer, sizeof(buffer), "{%d, %d}", column_index, column_span); |
| 836 return std::string(buffer); |
| 837 } |
| 838 |
| 839 v8::Handle<v8::Object> WebAXObjectProxy::CellForColumnAndRow( |
| 840 int column, int row) { |
| 841 blink::WebAXObject obj = |
| 842 accessibility_object().cellForColumnAndRow(column, row); |
| 843 if (obj.isNull()) |
| 844 return v8::Handle<v8::Object>(); |
| 845 |
| 846 return factory_->GetOrCreate(obj); |
| 847 } |
| 848 |
| 849 v8::Handle<v8::Object> WebAXObjectProxy::TitleUIElement() { |
| 850 blink::WebAXObject obj = accessibility_object().titleUIElement(); |
| 851 if (obj.isNull()) |
| 852 return v8::Handle<v8::Object>(); |
| 853 |
| 854 return factory_->GetOrCreate(obj); |
| 855 } |
| 856 |
| 857 void WebAXObjectProxy::SetSelectedTextRange(int selection_start, |
| 858 int length) { |
| 859 accessibility_object().setSelectedTextRange(selection_start, |
| 860 selection_start + length); |
| 861 } |
| 862 |
| 863 bool WebAXObjectProxy::IsAttributeSettable(const std::string& attribute) { |
| 864 bool settable = false; |
| 865 if (attribute == "AXValue") |
| 866 settable = accessibility_object().canSetValueAttribute(); |
| 867 return settable; |
| 868 } |
| 869 |
| 870 bool WebAXObjectProxy::IsPressActionSupported() { |
| 871 return accessibility_object().canPress(); |
| 872 } |
| 873 |
| 874 bool WebAXObjectProxy::IsIncrementActionSupported() { |
| 875 return accessibility_object().canIncrement(); |
| 876 } |
| 877 |
| 878 bool WebAXObjectProxy::IsDecrementActionSupported() { |
| 879 return accessibility_object().canDecrement(); |
| 880 } |
| 881 |
| 882 v8::Handle<v8::Object> WebAXObjectProxy::ParentElement() { |
| 883 blink::WebAXObject parent_object = accessibility_object().parentObject(); |
| 884 while (parent_object.accessibilityIsIgnored()) |
| 885 parent_object = parent_object.parentObject(); |
| 886 return factory_->GetOrCreate(parent_object); |
| 887 } |
| 888 |
| 889 void WebAXObjectProxy::Increment() { |
| 890 accessibility_object().increment(); |
| 891 } |
| 892 |
| 893 void WebAXObjectProxy::Decrement() { |
| 894 accessibility_object().decrement(); |
| 895 } |
| 896 |
| 897 void WebAXObjectProxy::ShowMenu() { |
| 898 } |
| 899 |
| 900 void WebAXObjectProxy::Press() { |
| 901 accessibility_object().press(); |
| 902 } |
| 903 |
| 904 bool WebAXObjectProxy::IsEqual(v8::Handle<v8::Object> proxy) { |
| 905 WebAXObjectProxy* unwrapped_proxy = NULL; |
| 906 if (!gin::ConvertFromV8(blink::mainThreadIsolate(), proxy, &unwrapped_proxy)) |
| 907 return false; |
| 908 return unwrapped_proxy->IsEqualToObject(accessibility_object_); |
| 909 } |
| 910 |
| 911 void WebAXObjectProxy::AddNotificationListener( |
| 912 v8::Handle<v8::Function> callback) { |
| 913 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 914 notification_callbacks_.push_back( |
| 915 gin::UnsafePersistent<v8::Function>(isolate, callback)); |
| 916 } |
| 917 |
| 918 void WebAXObjectProxy::RemoveNotificationListener() { |
| 919 // FIXME: Implement this. |
| 920 } |
| 921 |
| 922 void WebAXObjectProxy::TakeFocus() { |
| 923 accessibility_object().setFocused(true); |
| 924 } |
| 925 |
| 926 void WebAXObjectProxy::ScrollToMakeVisible() { |
| 927 accessibility_object().scrollToMakeVisible(); |
| 928 } |
| 929 |
| 930 void WebAXObjectProxy::ScrollToMakeVisibleWithSubFocus(int x, int y, |
| 931 int width, int height) { |
| 932 accessibility_object().scrollToMakeVisibleWithSubFocus( |
| 933 blink::WebRect(x, y, width, height)); |
| 934 } |
| 935 |
| 936 void WebAXObjectProxy::ScrollToGlobalPoint(int x, int y) { |
| 937 accessibility_object().scrollToGlobalPoint(blink::WebPoint(x, y)); |
| 938 } |
| 939 |
| 940 int WebAXObjectProxy::WordStart(int character_index) { |
| 941 if (accessibility_object().role() != blink::WebAXRoleStaticText) |
| 942 return -1; |
| 943 |
| 944 int word_start, word_end; |
| 945 GetBoundariesForOneWord(accessibility_object(), character_index, |
| 946 word_start, word_end); |
| 947 return word_start; |
| 948 } |
| 949 |
| 950 int WebAXObjectProxy::WordEnd(int character_index) { |
| 951 if (accessibility_object().role() != blink::WebAXRoleStaticText) |
| 952 return -1; |
| 953 |
| 954 int word_start, word_end; |
| 955 GetBoundariesForOneWord(accessibility_object(), character_index, |
| 956 word_start, word_end); |
| 957 return word_end; |
| 958 } |
| 959 |
| 960 void WebAXObjectProxy::ClearNotificationCallbacks() { |
| 961 for (CallbackList::iterator it = notification_callbacks_.begin(); |
| 962 it != notification_callbacks_.end(); ++it) { |
| 963 it->Dispose(); |
| 964 } |
| 965 notification_callbacks_.clear(); |
| 966 } |
| 967 |
| 968 RootWebAXObjectProxy::RootWebAXObjectProxy( |
| 969 const blink::WebAXObject &object, Factory *factory) |
| 970 : WebAXObjectProxy(object, factory) { |
| 971 } |
| 972 |
| 973 v8::Handle<v8::Object> RootWebAXObjectProxy::GetChildAtIndex(unsigned index) { |
| 974 if (index) |
| 975 return v8::Handle<v8::Object>(); |
| 976 |
| 977 return factory()->GetOrCreate(accessibility_object()); |
| 978 } |
| 979 |
| 980 bool RootWebAXObjectProxy::IsRoot() const { |
| 981 return true; |
| 982 } |
| 983 |
| 984 WebAXObjectProxyList::WebAXObjectProxyList() { |
| 985 } |
| 986 |
| 987 WebAXObjectProxyList::~WebAXObjectProxyList() { |
| 988 Clear(); |
| 989 } |
| 990 |
| 991 void WebAXObjectProxyList::Clear() { |
| 992 for (ElementList::iterator i = elements_.begin(); i != elements_.end(); ++i) |
| 993 i->Dispose(); |
| 994 elements_.clear(); |
| 995 } |
| 996 |
| 997 v8::Handle<v8::Object> WebAXObjectProxyList::GetOrCreate( |
| 998 const blink::WebAXObject& object) { |
| 999 if (object.isNull()) |
| 1000 return v8::Handle<v8::Object>(); |
| 1001 |
| 1002 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 1003 |
| 1004 size_t elementCount = elements_.size(); |
| 1005 for (size_t i = 0; i < elementCount; i++) { |
| 1006 WebAXObjectProxy* unwrapped_object = NULL; |
| 1007 bool result = gin::ConvertFromV8(isolate, elements_[i].NewLocal(isolate), |
| 1008 &unwrapped_object); |
| 1009 DCHECK(result); |
| 1010 DCHECK(unwrapped_object); |
| 1011 if (unwrapped_object->IsEqualToObject(object)) |
| 1012 return elements_[i].NewLocal(isolate); |
| 1013 } |
| 1014 |
| 1015 v8::Handle<v8::Object> handle = gin::CreateHandle( |
| 1016 isolate, new WebAXObjectProxy(object, this)).ToV8()->ToObject(); |
| 1017 gin::UnsafePersistent<v8::Object> unsafe_handle(isolate, handle); |
| 1018 elements_.push_back(unsafe_handle); |
| 1019 return unsafe_handle.NewLocal(isolate); |
| 1020 } |
| 1021 |
| 1022 v8::Handle<v8::Object> WebAXObjectProxyList::CreateRoot( |
| 1023 const blink::WebAXObject& object) { |
| 1024 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 1025 v8::Handle<v8::Object> handle = gin::CreateHandle( |
| 1026 isolate, new RootWebAXObjectProxy(object, this)).ToV8()->ToObject(); |
| 1027 gin::UnsafePersistent<v8::Object> unsafe_handle(isolate, handle); |
| 1028 elements_.push_back(unsafe_handle); |
| 1029 return unsafe_handle.NewLocal(isolate); |
| 1030 } |
| 1031 |
| 1032 } // namespace content |
OLD | NEW |