Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Unified Diff: mojo/services/html_viewer/ax_provider_impl.cc

Issue 710803002: Beginning of an accessibility implementation for html_viewer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup, rebase Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/services/html_viewer/ax_provider_impl.cc
diff --git a/mojo/services/html_viewer/ax_provider_impl.cc b/mojo/services/html_viewer/ax_provider_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ed6ca1f936b0375f95375df23fbf8acd9811a2c1
--- /dev/null
+++ b/mojo/services/html_viewer/ax_provider_impl.cc
@@ -0,0 +1,97 @@
+// 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 "mojo/services/html_viewer/ax_provider_impl.h"
+
+#include "mojo/public/cpp/bindings/type_converter.h"
+#include "mojo/services/public/interfaces/geometry/geometry.mojom.h"
+#include "third_party/WebKit/public/platform/WebRect.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::WebRect;
+using blink::WebURL;
+using blink::WebView;
+
+namespace mojo {
+
+template <>
+struct TypeConverter<RectPtr, WebRect> {
+ static RectPtr Convert(const WebRect& input) {
+ RectPtr result(Rect::New());
+ result->x = input.x;
+ result->y = input.y;
+ result->width = input.width;
+ result->height = input.height;
+ return result.Pass();
+ }
+};
abarth-chromium 2014/11/10 00:33:04 Should this go in a more general location for a co
Aaron Boodman 2014/11/10 07:05:53 Whoops, did not see that there. Done.
+
+AxProviderImpl::AxProviderImpl(WebView* web_view) : web_view_(web_view) {
+}
+
+void AxProviderImpl::GetTree(
+ const 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 = AxNode::New();
+ result->id = static_cast<int>(ax_object.axID());
+ result->parent_id = parent_id;
+ result->next_sibling_id = next_sibling_id;
+ result->bounds = Rect::From(ax_object.boundingBoxRect());
+
+ if (ax_object.isAnchor()) {
+ result->link = AxLink::New();
+ result->link->url = ax_object.url().string().utf8();
+ } else if (ax_object.childCount() == 0 &&
+ !ax_object.stringValue().isEmpty()) {
+ result->text = AxText::New();
+ result->text->content = ax_object.stringValue().utf8();
+ }
+
+ return result.Pass();
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698