Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/accessibility/blink_ax_tree_source.h" | 5 #include "content/renderer/accessibility/blink_ax_tree_source.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "content/renderer/accessibility/blink_ax_enum_conversion.h" | 12 #include "content/renderer/accessibility/blink_ax_enum_conversion.h" |
| 13 #include "content/renderer/browser_plugin/browser_plugin.h" | |
| 13 #include "content/renderer/render_frame_impl.h" | 14 #include "content/renderer/render_frame_impl.h" |
| 14 #include "content/renderer/render_frame_proxy.h" | 15 #include "content/renderer/render_frame_proxy.h" |
| 15 #include "content/renderer/render_view_impl.h" | 16 #include "content/renderer/render_view_impl.h" |
| 16 #include "third_party/WebKit/public/platform/WebRect.h" | 17 #include "third_party/WebKit/public/platform/WebRect.h" |
| 17 #include "third_party/WebKit/public/platform/WebSize.h" | 18 #include "third_party/WebKit/public/platform/WebSize.h" |
| 18 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
| 20 #include "third_party/WebKit/public/web/WebAXEnums.h" | 21 #include "third_party/WebKit/public/web/WebAXEnums.h" |
| 21 #include "third_party/WebKit/public/web/WebAXObject.h" | 22 #include "third_party/WebKit/public/web/WebAXObject.h" |
| 22 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
| 23 #include "third_party/WebKit/public/web/WebDocumentType.h" | 24 #include "third_party/WebKit/public/web/WebDocumentType.h" |
| 24 #include "third_party/WebKit/public/web/WebElement.h" | 25 #include "third_party/WebKit/public/web/WebElement.h" |
| 25 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 26 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| 26 #include "third_party/WebKit/public/web/WebFrame.h" | 27 #include "third_party/WebKit/public/web/WebFrame.h" |
| 27 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 28 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 28 #include "third_party/WebKit/public/web/WebInputElement.h" | |
| 29 #include "third_party/WebKit/public/web/WebNode.h" | 29 #include "third_party/WebKit/public/web/WebNode.h" |
| 30 #include "third_party/WebKit/public/web/WebPlugin.h" | |
| 31 #include "third_party/WebKit/public/web/WebPluginContainer.h" | |
| 30 #include "third_party/WebKit/public/web/WebView.h" | 32 #include "third_party/WebKit/public/web/WebView.h" |
| 31 | 33 |
| 32 using base::ASCIIToUTF16; | 34 using base::ASCIIToUTF16; |
| 33 using base::UTF16ToUTF8; | 35 using base::UTF16ToUTF8; |
| 34 using blink::WebAXObject; | 36 using blink::WebAXObject; |
| 35 using blink::WebDocument; | 37 using blink::WebDocument; |
| 36 using blink::WebDocumentType; | 38 using blink::WebDocumentType; |
| 37 using blink::WebElement; | 39 using blink::WebElement; |
| 38 using blink::WebLocalFrame; | 40 using blink::WebLocalFrame; |
| 39 using blink::WebNode; | 41 using blink::WebNode; |
| 42 using blink::WebPlugin; | |
| 43 using blink::WebPluginContainer; | |
| 40 using blink::WebVector; | 44 using blink::WebVector; |
| 41 using blink::WebView; | 45 using blink::WebView; |
| 42 | 46 |
| 43 namespace content { | 47 namespace content { |
| 44 | 48 |
| 45 namespace { | 49 namespace { |
| 46 | 50 |
| 47 // Returns true if |ancestor| is the first unignored parent of |child|, | 51 // Returns true if |ancestor| is the first unignored parent of |child|, |
| 48 // which means that when walking up the parent chain from |child|, | 52 // which means that when walking up the parent chain from |child|, |
| 49 // |ancestor| is the *first* ancestor that isn't marked as | 53 // |ancestor| is the *first* ancestor that isn't marked as |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 std::vector<int32> ids; | 94 std::vector<int32> ids; |
| 91 for(size_t i = 0; i < objects.size(); i++) | 95 for(size_t i = 0; i < objects.size(); i++) |
| 92 ids.push_back(objects[i].axID()); | 96 ids.push_back(objects[i].axID()); |
| 93 if (ids.size() > 0) | 97 if (ids.size() > 0) |
| 94 dst->AddIntListAttribute(attr, ids); | 98 dst->AddIntListAttribute(attr, ids); |
| 95 } | 99 } |
| 96 | 100 |
| 97 } // Anonymous namespace | 101 } // Anonymous namespace |
| 98 | 102 |
| 99 BlinkAXTreeSource::BlinkAXTreeSource(RenderFrameImpl* render_frame) | 103 BlinkAXTreeSource::BlinkAXTreeSource(RenderFrameImpl* render_frame) |
| 100 : render_frame_(render_frame) { | 104 : render_frame_(render_frame), |
| 105 node_to_frame_routing_id_map_(NULL), | |
| 106 node_to_browser_plugin_instance_id_map_(NULL) { | |
| 101 } | 107 } |
| 102 | 108 |
| 103 BlinkAXTreeSource::~BlinkAXTreeSource() { | 109 BlinkAXTreeSource::~BlinkAXTreeSource() { |
| 104 } | 110 } |
| 105 | 111 |
| 106 bool BlinkAXTreeSource::IsInTree(blink::WebAXObject node) const { | 112 bool BlinkAXTreeSource::IsInTree(blink::WebAXObject node) const { |
| 107 const blink::WebAXObject& root = GetRoot(); | 113 const blink::WebAXObject& root = GetRoot(); |
| 108 while (IsValid(node)) { | 114 while (IsValid(node)) { |
| 109 if (node.equals(root)) | 115 if (node.equals(root)) |
| 110 return true; | 116 return true; |
| 111 node = GetParent(node); | 117 node = GetParent(node); |
| 112 } | 118 } |
| 113 return false; | 119 return false; |
| 114 } | 120 } |
| 115 | 121 |
| 116 void BlinkAXTreeSource::CollectChildFrameIdMapping( | 122 void BlinkAXTreeSource::CollectChildFrameIdMapping( |
| 117 std::map<int32, int>* node_to_frame_routing_id_map) { | 123 std::map<int32, int>* node_to_frame_routing_id_map, |
| 124 std::map<int32, int>* node_to_browser_plugin_instance_id_map) { | |
| 118 node_to_frame_routing_id_map_ = node_to_frame_routing_id_map; | 125 node_to_frame_routing_id_map_ = node_to_frame_routing_id_map; |
| 126 node_to_browser_plugin_instance_id_map_ = | |
| 127 node_to_browser_plugin_instance_id_map; | |
| 119 } | 128 } |
| 120 | 129 |
| 121 blink::WebAXObject BlinkAXTreeSource::GetRoot() const { | 130 blink::WebAXObject BlinkAXTreeSource::GetRoot() const { |
| 122 return GetMainDocument().accessibilityObject(); | 131 return GetMainDocument().accessibilityObject(); |
| 123 } | 132 } |
| 124 | 133 |
| 125 blink::WebAXObject BlinkAXTreeSource::GetFromId(int32 id) const { | 134 blink::WebAXObject BlinkAXTreeSource::GetFromId(int32 id) const { |
| 126 return GetMainDocument().accessibilityObjectFromID(id); | 135 return GetMainDocument().accessibilityObjectFromID(id); |
| 127 } | 136 } |
| 128 | 137 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 std::string role = GetEquivalentAriaRoleString(dst->role); | 352 std::string role = GetEquivalentAriaRoleString(dst->role); |
| 344 if (!role.empty()) | 353 if (!role.empty()) |
| 345 dst->AddStringAttribute(ui::AX_ATTR_ROLE, role); | 354 dst->AddStringAttribute(ui::AX_ATTR_ROLE, role); |
| 346 } | 355 } |
| 347 | 356 |
| 348 // Live region attributes | 357 // Live region attributes |
| 349 live_atomic = UTF16ToUTF8(element.getAttribute("aria-atomic")); | 358 live_atomic = UTF16ToUTF8(element.getAttribute("aria-atomic")); |
| 350 live_busy = UTF16ToUTF8(element.getAttribute("aria-busy")); | 359 live_busy = UTF16ToUTF8(element.getAttribute("aria-busy")); |
| 351 live_status = UTF16ToUTF8(element.getAttribute("aria-live")); | 360 live_status = UTF16ToUTF8(element.getAttribute("aria-live")); |
| 352 live_relevant = UTF16ToUTF8(element.getAttribute("aria-relevant")); | 361 live_relevant = UTF16ToUTF8(element.getAttribute("aria-relevant")); |
| 362 | |
| 363 // Browser plugin (used in a <webview>). | |
| 364 | |
| 365 if (node_to_browser_plugin_instance_id_map_ && | |
| 366 element.tagName() == base::ASCIIToUTF16("OBJECT") && | |
| 367 element.getAttribute("type") == | |
| 368 base::ASCIIToUTF16("application/browser-plugin")) { | |
|
Fady Samuel
2014/09/11 17:50:19
I'm a little bit sad that we need to hard code the
dmazzoni
2014/09/12 07:34:35
Sure. I went ahead and put it in BrowserPlugin lik
Fady Samuel
2014/09/12 15:47:44
Yup, thanks! :-)
| |
| 369 WebPluginContainer* plugin_container = element.pluginContainer(); | |
| 370 if (plugin_container) { | |
| 371 WebPlugin* plugin = plugin_container->plugin(); | |
| 372 if (plugin) { | |
| 373 BrowserPlugin* browser_plugin = static_cast<BrowserPlugin*>(plugin); | |
| 374 node_to_browser_plugin_instance_id_map_->insert( | |
| 375 std::pair<int32, int>( | |
|
Fady Samuel
2014/09/11 17:50:19
Is it possible to make this a struct instead for r
dmazzoni
2014/09/12 07:34:35
I'm not sure how much more clear I can get than ca
Fady Samuel
2014/09/12 15:47:44
Ohh sorry, I missed that this is a map and not a v
| |
| 376 dst->id, browser_plugin->browser_plugin_instance_id())); | |
| 377 dst->AddBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST, true); | |
| 378 } | |
| 379 } | |
| 380 } | |
| 353 } | 381 } |
| 354 | 382 |
| 355 // Walk up the parent chain to set live region attributes of containers | 383 // Walk up the parent chain to set live region attributes of containers |
| 356 std::string container_live_atomic; | 384 std::string container_live_atomic; |
| 357 std::string container_live_busy; | 385 std::string container_live_busy; |
| 358 std::string container_live_status; | 386 std::string container_live_status; |
| 359 std::string container_live_relevant; | 387 std::string container_live_relevant; |
| 360 WebAXObject container_accessible = src; | 388 WebAXObject container_accessible = src; |
| 361 while (!container_accessible.isDetached()) { | 389 while (!container_accessible.isDetached()) { |
| 362 WebNode container_node = container_accessible.node(); | 390 WebNode container_node = container_accessible.node(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 const gfx::Size& max_offset = document.maximumScrollOffset(); | 484 const gfx::Size& max_offset = document.maximumScrollOffset(); |
| 457 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MAX, max_offset.width()); | 485 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_X_MAX, max_offset.width()); |
| 458 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MAX, max_offset.height()); | 486 dst->AddIntAttribute(ui::AX_ATTR_SCROLL_Y_MAX, max_offset.height()); |
| 459 | 487 |
| 460 if (node_to_frame_routing_id_map_ && !src.equals(GetRoot())) { | 488 if (node_to_frame_routing_id_map_ && !src.equals(GetRoot())) { |
| 461 WebLocalFrame* frame = document.frame(); | 489 WebLocalFrame* frame = document.frame(); |
| 462 RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(frame); | 490 RenderFrameImpl* render_frame = RenderFrameImpl::FromWebFrame(frame); |
| 463 if (render_frame) { | 491 if (render_frame) { |
| 464 node_to_frame_routing_id_map_->insert(std::pair<int32, int>( | 492 node_to_frame_routing_id_map_->insert(std::pair<int32, int>( |
| 465 dst->id, render_frame->GetRoutingID())); | 493 dst->id, render_frame->GetRoutingID())); |
| 494 dst->AddBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST, true); | |
| 466 } else { | 495 } else { |
| 467 RenderFrameProxy* render_frame_proxy = | 496 RenderFrameProxy* render_frame_proxy = |
| 468 RenderFrameProxy::FromWebFrame(frame); | 497 RenderFrameProxy::FromWebFrame(frame); |
| 469 if (render_frame_proxy) { | 498 if (render_frame_proxy) { |
| 470 node_to_frame_routing_id_map_->insert(std::pair<int32, int>( | 499 node_to_frame_routing_id_map_->insert(std::pair<int32, int>( |
| 471 dst->id, render_frame_proxy->routing_id())); | 500 dst->id, render_frame_proxy->routing_id())); |
| 501 dst->AddBoolAttribute(ui::AX_ATTR_IS_AX_TREE_HOST, true); | |
| 472 } | 502 } |
| 473 } | 503 } |
| 474 } | 504 } |
| 475 } | 505 } |
| 476 | 506 |
| 477 if (dst->role == ui::AX_ROLE_TABLE) { | 507 if (dst->role == ui::AX_ROLE_TABLE) { |
| 478 int column_count = src.columnCount(); | 508 int column_count = src.columnCount(); |
| 479 int row_count = src.rowCount(); | 509 int row_count = src.rowCount(); |
| 480 if (column_count > 0 && row_count > 0) { | 510 if (column_count > 0 && row_count > 0) { |
| 481 std::set<int32> unique_cell_id_set; | 511 std::set<int32> unique_cell_id_set; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 AddIntListAttributeFromWebObjects(ui::AX_ATTR_OWNS_IDS, owns, dst); | 603 AddIntListAttributeFromWebObjects(ui::AX_ATTR_OWNS_IDS, owns, dst); |
| 574 } | 604 } |
| 575 | 605 |
| 576 blink::WebDocument BlinkAXTreeSource::GetMainDocument() const { | 606 blink::WebDocument BlinkAXTreeSource::GetMainDocument() const { |
| 577 if (render_frame_ && render_frame_->GetWebFrame()) | 607 if (render_frame_ && render_frame_->GetWebFrame()) |
| 578 return render_frame_->GetWebFrame()->document(); | 608 return render_frame_->GetWebFrame()->document(); |
| 579 return WebDocument(); | 609 return WebDocument(); |
| 580 } | 610 } |
| 581 | 611 |
| 582 } // namespace content | 612 } // namespace content |
| OLD | NEW |