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

Side by Side 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 unified diff | Download patch
OLDNEW
(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/public/cpp/bindings/type_converter.h"
8 #include "mojo/services/public/interfaces/geometry/geometry.mojom.h"
9 #include "third_party/WebKit/public/platform/WebRect.h"
10 #include "third_party/WebKit/public/platform/WebURL.h"
11 #include "third_party/WebKit/public/web/WebAXObject.h"
12 #include "third_party/WebKit/public/web/WebSettings.h"
13 #include "third_party/WebKit/public/web/WebView.h"
14
15 using blink::WebAXObject;
16 using blink::WebRect;
17 using blink::WebURL;
18 using blink::WebView;
19
20 namespace mojo {
21
22 template <>
23 struct TypeConverter<RectPtr, WebRect> {
24 static RectPtr Convert(const WebRect& input) {
25 RectPtr result(Rect::New());
26 result->x = input.x;
27 result->y = input.y;
28 result->width = input.width;
29 result->height = input.height;
30 return result.Pass();
31 }
32 };
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.
33
34 AxProviderImpl::AxProviderImpl(WebView* web_view) : web_view_(web_view) {
35 }
36
37 void AxProviderImpl::GetTree(
38 const Callback<void(Array<AxNodePtr> nodes)>& callback) {
39 web_view_->settings()->setAccessibilityEnabled(true);
40 web_view_->settings()->setInlineTextBoxAccessibilityEnabled(true);
41
42 Array<AxNodePtr> result;
43 Populate(web_view_->accessibilityObject(), 0, 0, &result);
44 callback.Run(result.Pass());
45 }
46
47 int AxProviderImpl::Populate(const WebAXObject& ax_object,
48 int parent_id,
49 int next_sibling_id,
50 Array<AxNodePtr>* result) {
51 AxNodePtr ax_node(ConvertAxNode(ax_object, parent_id, next_sibling_id));
52 int ax_node_id = ax_node->id;
53 if (ax_node.is_null())
54 return 0;
55
56 result->push_back(ax_node.Pass());
57
58 unsigned num_children = ax_object.childCount();
59 next_sibling_id = 0;
60 for (unsigned i = 0; i < num_children; ++i) {
61 int new_id = Populate(ax_object.childAt(num_children - i - 1),
62 ax_node_id,
63 next_sibling_id,
64 result);
65 if (new_id != 0)
66 next_sibling_id = new_id;
67 }
68
69 return ax_node_id;
70 }
71
72 AxNodePtr AxProviderImpl::ConvertAxNode(const WebAXObject& ax_object,
73 int parent_id,
74 int next_sibling_id) {
75 AxNodePtr result;
76 if (!const_cast<WebAXObject&>(ax_object).updateLayoutAndCheckValidity())
77 return result.Pass();
78
79 result = AxNode::New();
80 result->id = static_cast<int>(ax_object.axID());
81 result->parent_id = parent_id;
82 result->next_sibling_id = next_sibling_id;
83 result->bounds = Rect::From(ax_object.boundingBoxRect());
84
85 if (ax_object.isAnchor()) {
86 result->link = AxLink::New();
87 result->link->url = ax_object.url().string().utf8();
88 } else if (ax_object.childCount() == 0 &&
89 !ax_object.stringValue().isEmpty()) {
90 result->text = AxText::New();
91 result->text->content = ax_object.stringValue().utf8();
92 }
93
94 return result.Pass();
95 }
96
97 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698