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

Side by Side Diff: components/html_viewer/ax_provider_impl.cc

Issue 1677293002: Bye bye Mandoline (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moar Created 4 years, 10 months 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 "components/html_viewer/ax_provider_impl.h"
6
7 #include <utility>
8
9 #include "components/html_viewer/blink_basic_type_converters.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::WebURL;
17 using blink::WebView;
18
19 using mojo::Array;
20 using mojo::AxNodePtr;
21 using mojo::String;
22
23 namespace html_viewer {
24
25 AxProviderImpl::AxProviderImpl(WebView* web_view,
26 mojo::InterfaceRequest<mojo::AxProvider> request)
27 : web_view_(web_view), binding_(this, std::move(request)) {}
28
29 AxProviderImpl::~AxProviderImpl() {
30 }
31
32 void AxProviderImpl::GetTree(
33 const mojo::Callback<void(Array<AxNodePtr> nodes)>& callback) {
34 web_view_->settings()->setAccessibilityEnabled(true);
35 web_view_->settings()->setInlineTextBoxAccessibilityEnabled(true);
36
37 Array<AxNodePtr> result;
38 Populate(web_view_->accessibilityObject(), 0, 0, &result);
39 callback.Run(std::move(result));
40 }
41
42 int AxProviderImpl::Populate(const WebAXObject& ax_object,
43 int parent_id,
44 int next_sibling_id,
45 Array<AxNodePtr>* result) {
46 AxNodePtr ax_node(ConvertAxNode(ax_object, parent_id, next_sibling_id));
47 int ax_node_id = ax_node->id;
48 if (ax_node.is_null())
49 return 0;
50
51 result->push_back(std::move(ax_node));
52
53 unsigned num_children = ax_object.childCount();
54 next_sibling_id = 0;
55 for (unsigned i = 0; i < num_children; ++i) {
56 int new_id = Populate(ax_object.childAt(num_children - i - 1),
57 ax_node_id,
58 next_sibling_id,
59 result);
60 if (new_id != 0)
61 next_sibling_id = new_id;
62 }
63
64 return ax_node_id;
65 }
66
67 AxNodePtr AxProviderImpl::ConvertAxNode(const WebAXObject& ax_object,
68 int parent_id,
69 int next_sibling_id) {
70 AxNodePtr result;
71 if (!const_cast<WebAXObject&>(ax_object).updateLayoutAndCheckValidity())
72 return result;
73
74 result = mojo::AxNode::New();
75 result->id = static_cast<int>(ax_object.axID());
76 result->parent_id = parent_id;
77 result->next_sibling_id = next_sibling_id;
78 result->bounds = mojo::Rect::From(ax_object.boundingBoxRect());
79
80 if (ax_object.isAnchor()) {
81 result->link = mojo::AxLink::New();
82 result->link->url = String::From(ax_object.url().string());
83 } else if (ax_object.childCount() == 0) {
84 blink::WebString name = ax_object.name();
85 if (!name.isEmpty()) {
86 result->text = mojo::AxText::New();
87 result->text->content = String::From(name);
88 }
89 }
90
91 return result;
92 }
93
94 } // namespace html_viewer
OLDNEW
« no previous file with comments | « components/html_viewer/ax_provider_impl.h ('k') | components/html_viewer/ax_provider_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698