summaryrefslogtreecommitdiffstats
path: root/components/html_viewer/ax_provider_impl.cc
diff options
context:
space:
mode:
authorjam <jam@chromium.org>2015-04-22 13:38:16 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-22 20:39:00 +0000
commit81a5661f60738efa7dbbee0a72f2c1e15f6690f9 (patch)
tree27fe82ed9e8d8b504f6c731365df1fc9e2c3d1f6 /components/html_viewer/ax_provider_impl.cc
parentaa86d5f0d050b3322ed02d81e5f51787726f5511 (diff)
downloadchromium_src-81a5661f60738efa7dbbee0a72f2c1e15f6690f9.zip
chromium_src-81a5661f60738efa7dbbee0a72f2c1e15f6690f9.tar.gz
chromium_src-81a5661f60738efa7dbbee0a72f2c1e15f6690f9.tar.bz2
Move html_viewer from mojo/services to components.
BUG=479353 TBR=jochen for DEPS Review URL: https://codereview.chromium.org/1099303002 Cr-Commit-Position: refs/heads/master@{#326369}
Diffstat (limited to 'components/html_viewer/ax_provider_impl.cc')
-rw-r--r--components/html_viewer/ax_provider_impl.cc86
1 files changed, 86 insertions, 0 deletions
diff --git a/components/html_viewer/ax_provider_impl.cc b/components/html_viewer/ax_provider_impl.cc
new file mode 100644
index 0000000..bc7dc3c
--- /dev/null
+++ b/components/html_viewer/ax_provider_impl.cc
@@ -0,0 +1,86 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/html_viewer/ax_provider_impl.h"
+
+#include "components/html_viewer/blink_basic_type_converters.h"
+#include "third_party/WebKit/public/platform/WebURL.h"
+#include "third_party/WebKit/public/web/WebAXObject.h"
+#include "third_party/WebKit/public/web/WebSettings.h"
+#include "third_party/WebKit/public/web/WebView.h"
+
+using blink::WebAXObject;
+using blink::WebURL;
+using blink::WebView;
+
+using mojo::Array;
+using mojo::AxNodePtr;
+using mojo::String;
+
+namespace html_viewer {
+
+AxProviderImpl::AxProviderImpl(WebView* web_view) : web_view_(web_view) {
+}
+
+void AxProviderImpl::GetTree(
+ const mojo::Callback<void(Array<AxNodePtr> nodes)>& callback) {
+ web_view_->settings()->setAccessibilityEnabled(true);
+ web_view_->settings()->setInlineTextBoxAccessibilityEnabled(true);
+
+ Array<AxNodePtr> result;
+ Populate(web_view_->accessibilityObject(), 0, 0, &result);
+ callback.Run(result.Pass());
+}
+
+int AxProviderImpl::Populate(const WebAXObject& ax_object,
+ int parent_id,
+ int next_sibling_id,
+ Array<AxNodePtr>* result) {
+ AxNodePtr ax_node(ConvertAxNode(ax_object, parent_id, next_sibling_id));
+ int ax_node_id = ax_node->id;
+ if (ax_node.is_null())
+ return 0;
+
+ result->push_back(ax_node.Pass());
+
+ unsigned num_children = ax_object.childCount();
+ next_sibling_id = 0;
+ for (unsigned i = 0; i < num_children; ++i) {
+ int new_id = Populate(ax_object.childAt(num_children - i - 1),
+ ax_node_id,
+ next_sibling_id,
+ result);
+ if (new_id != 0)
+ next_sibling_id = new_id;
+ }
+
+ return ax_node_id;
+}
+
+AxNodePtr AxProviderImpl::ConvertAxNode(const WebAXObject& ax_object,
+ int parent_id,
+ int next_sibling_id) {
+ AxNodePtr result;
+ if (!const_cast<WebAXObject&>(ax_object).updateLayoutAndCheckValidity())
+ return result.Pass();
+
+ result = mojo::AxNode::New();
+ result->id = static_cast<int>(ax_object.axID());
+ result->parent_id = parent_id;
+ result->next_sibling_id = next_sibling_id;
+ result->bounds = mojo::Rect::From(ax_object.boundingBoxRect());
+
+ if (ax_object.isAnchor()) {
+ result->link = mojo::AxLink::New();
+ result->link->url = String::From(ax_object.url().string());
+ } else if (ax_object.childCount() == 0 &&
+ !ax_object.stringValue().isEmpty()) {
+ result->text = mojo::AxText::New();
+ result->text->content = String::From(ax_object.stringValue());
+ }
+
+ return result.Pass();
+}
+
+} // namespace html_viewer