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 #include "mojo/services/html_viewer/ax_provider_impl.h" |
| 6 |
| 7 #include "mojo/services/html_viewer/blink_basic_type_converters.h" |
| 8 #include "third_party/WebKit/public/platform/WebURL.h" |
| 9 #include "third_party/WebKit/public/web/WebAXObject.h" |
| 10 #include "third_party/WebKit/public/web/WebSettings.h" |
| 11 #include "third_party/WebKit/public/web/WebView.h" |
| 12 |
| 13 using blink::WebAXObject; |
| 14 using blink::WebURL; |
| 15 using blink::WebView; |
| 16 |
| 17 namespace mojo { |
| 18 |
| 19 AxProviderImpl::AxProviderImpl(WebView* web_view) : web_view_(web_view) { |
| 20 } |
| 21 |
| 22 void AxProviderImpl::GetTree( |
| 23 const Callback<void(Array<AxNodePtr> nodes)>& callback) { |
| 24 web_view_->settings()->setAccessibilityEnabled(true); |
| 25 web_view_->settings()->setInlineTextBoxAccessibilityEnabled(true); |
| 26 |
| 27 Array<AxNodePtr> result; |
| 28 Populate(web_view_->accessibilityObject(), 0, 0, &result); |
| 29 callback.Run(result.Pass()); |
| 30 } |
| 31 |
| 32 int AxProviderImpl::Populate(const WebAXObject& ax_object, |
| 33 int parent_id, |
| 34 int next_sibling_id, |
| 35 Array<AxNodePtr>* result) { |
| 36 AxNodePtr ax_node(ConvertAxNode(ax_object, parent_id, next_sibling_id)); |
| 37 int ax_node_id = ax_node->id; |
| 38 if (ax_node.is_null()) |
| 39 return 0; |
| 40 |
| 41 result->push_back(ax_node.Pass()); |
| 42 |
| 43 unsigned num_children = ax_object.childCount(); |
| 44 next_sibling_id = 0; |
| 45 for (unsigned i = 0; i < num_children; ++i) { |
| 46 int new_id = Populate(ax_object.childAt(num_children - i - 1), |
| 47 ax_node_id, |
| 48 next_sibling_id, |
| 49 result); |
| 50 if (new_id != 0) |
| 51 next_sibling_id = new_id; |
| 52 } |
| 53 |
| 54 return ax_node_id; |
| 55 } |
| 56 |
| 57 AxNodePtr AxProviderImpl::ConvertAxNode(const WebAXObject& ax_object, |
| 58 int parent_id, |
| 59 int next_sibling_id) { |
| 60 AxNodePtr result; |
| 61 if (!const_cast<WebAXObject&>(ax_object).updateLayoutAndCheckValidity()) |
| 62 return result.Pass(); |
| 63 |
| 64 result = AxNode::New(); |
| 65 result->id = static_cast<int>(ax_object.axID()); |
| 66 result->parent_id = parent_id; |
| 67 result->next_sibling_id = next_sibling_id; |
| 68 result->bounds = Rect::From(ax_object.boundingBoxRect()); |
| 69 |
| 70 if (ax_object.isAnchor()) { |
| 71 result->link = AxLink::New(); |
| 72 result->link->url = String::From(ax_object.url().string()); |
| 73 } else if (ax_object.childCount() == 0 && |
| 74 !ax_object.stringValue().isEmpty()) { |
| 75 result->text = AxText::New(); |
| 76 result->text->content = String::From(ax_object.stringValue()); |
| 77 } |
| 78 |
| 79 return result.Pass(); |
| 80 } |
| 81 |
| 82 } // namespace mojo |
OLD | NEW |