Rename isSystemLocationEnabled to isLocationEnabled, as per internal review (185995).
[chromium-blink-merge.git] / mojo / services / html_viewer / ax_provider_impl.cc
blob19f8912d68e1932617ed2b655f581567ec20061d
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/services/html_viewer/ax_provider_impl.h"
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"
13 using blink::WebAXObject;
14 using blink::WebURL;
15 using blink::WebView;
17 namespace mojo {
19 AxProviderImpl::AxProviderImpl(WebView* web_view) : web_view_(web_view) {
22 void AxProviderImpl::GetTree(
23 const Callback<void(Array<AxNodePtr> nodes)>& callback) {
24 web_view_->settings()->setAccessibilityEnabled(true);
25 web_view_->settings()->setInlineTextBoxAccessibilityEnabled(true);
27 Array<AxNodePtr> result;
28 Populate(web_view_->accessibilityObject(), 0, 0, &result);
29 callback.Run(result.Pass());
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;
41 result->push_back(ax_node.Pass());
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;
54 return ax_node_id;
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();
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());
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());
79 return result.Pass();
82 } // namespace mojo