OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/test_runner/accessibility_controller.h" | 5 #include "components/test_runner/accessibility_controller.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "gin/handle.h" | 8 #include "gin/handle.h" |
9 #include "gin/object_template_builder.h" | 9 #include "gin/object_template_builder.h" |
10 #include "gin/wrappable.h" | 10 #include "gin/wrappable.h" |
| 11 #include "third_party/WebKit/public/web/WebDocument.h" |
11 #include "third_party/WebKit/public/web/WebElement.h" | 12 #include "third_party/WebKit/public/web/WebElement.h" |
12 #include "third_party/WebKit/public/web/WebFrame.h" | 13 #include "third_party/WebKit/public/web/WebFrame.h" |
13 #include "third_party/WebKit/public/web/WebKit.h" | 14 #include "third_party/WebKit/public/web/WebKit.h" |
14 #include "third_party/WebKit/public/web/WebSettings.h" | 15 #include "third_party/WebKit/public/web/WebSettings.h" |
15 #include "third_party/WebKit/public/web/WebView.h" | 16 #include "third_party/WebKit/public/web/WebView.h" |
16 | 17 |
17 namespace test_runner { | 18 namespace test_runner { |
18 | 19 |
19 class AccessibilityControllerBindings | 20 class AccessibilityControllerBindings |
20 : public gin::Wrappable<AccessibilityControllerBindings> { | 21 : public gin::Wrappable<AccessibilityControllerBindings> { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 134 } |
134 | 135 |
135 AccessibilityController::AccessibilityController() | 136 AccessibilityController::AccessibilityController() |
136 : log_accessibility_events_(false), | 137 : log_accessibility_events_(false), |
137 weak_factory_(this) { | 138 weak_factory_(this) { |
138 } | 139 } |
139 | 140 |
140 AccessibilityController::~AccessibilityController() {} | 141 AccessibilityController::~AccessibilityController() {} |
141 | 142 |
142 void AccessibilityController::Reset() { | 143 void AccessibilityController::Reset() { |
143 root_element_ = blink::WebAXObject(); | |
144 focused_element_ = blink::WebAXObject(); | |
145 elements_.Clear(); | 144 elements_.Clear(); |
146 notification_callback_.Reset(); | 145 notification_callback_.Reset(); |
147 log_accessibility_events_ = false; | 146 log_accessibility_events_ = false; |
148 } | 147 } |
149 | 148 |
150 void AccessibilityController::Install(blink::WebFrame* frame) { | 149 void AccessibilityController::Install(blink::WebFrame* frame) { |
151 frame->view()->settings()->setAccessibilityEnabled(true); | 150 frame->view()->settings()->setAccessibilityEnabled(true); |
152 frame->view()->settings()->setInlineTextBoxAccessibilityEnabled(true); | 151 frame->view()->settings()->setInlineTextBoxAccessibilityEnabled(true); |
153 | 152 |
154 AccessibilityControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); | 153 AccessibilityControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); |
155 } | 154 } |
156 | 155 |
157 void AccessibilityController::SetFocusedElement( | |
158 const blink::WebAXObject& focused_element) { | |
159 focused_element_ = focused_element; | |
160 } | |
161 | |
162 bool AccessibilityController::ShouldLogAccessibilityEvents() { | 156 bool AccessibilityController::ShouldLogAccessibilityEvents() { |
163 return log_accessibility_events_; | 157 return log_accessibility_events_; |
164 } | 158 } |
165 | 159 |
166 void AccessibilityController::NotificationReceived( | 160 void AccessibilityController::NotificationReceived( |
167 const blink::WebAXObject& target, const std::string& notification_name) { | 161 const blink::WebAXObject& target, const std::string& notification_name) { |
168 v8::Isolate* isolate = blink::mainThreadIsolate(); | 162 v8::Isolate* isolate = blink::mainThreadIsolate(); |
169 v8::HandleScope handle_scope(isolate); | 163 v8::HandleScope handle_scope(isolate); |
170 | 164 |
171 blink::WebFrame* frame = web_view_->mainFrame(); | 165 blink::WebFrame* frame = web_view_->mainFrame(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 v8::Local<v8::Function> callback) { | 215 v8::Local<v8::Function> callback) { |
222 v8::Isolate* isolate = blink::mainThreadIsolate(); | 216 v8::Isolate* isolate = blink::mainThreadIsolate(); |
223 notification_callback_.Reset(isolate, callback); | 217 notification_callback_.Reset(isolate, callback); |
224 } | 218 } |
225 | 219 |
226 void AccessibilityController::UnsetNotificationListener() { | 220 void AccessibilityController::UnsetNotificationListener() { |
227 notification_callback_.Reset(); | 221 notification_callback_.Reset(); |
228 } | 222 } |
229 | 223 |
230 v8::Local<v8::Object> AccessibilityController::FocusedElement() { | 224 v8::Local<v8::Object> AccessibilityController::FocusedElement() { |
231 if (focused_element_.isNull()) | 225 blink::WebFrame* frame = web_view_->mainFrame(); |
232 focused_element_ = web_view_->accessibilityObject(); | 226 if (!frame) |
233 return elements_.GetOrCreate(focused_element_); | 227 return v8::Local<v8::Object>(); |
| 228 |
| 229 blink::WebAXObject focused_element = |
| 230 frame->document().focusedAccessibilityObject(); |
| 231 if (focused_element.isNull()) |
| 232 focused_element = web_view_->accessibilityObject(); |
| 233 return elements_.GetOrCreate(focused_element); |
234 } | 234 } |
235 | 235 |
236 v8::Local<v8::Object> AccessibilityController::RootElement() { | 236 v8::Local<v8::Object> AccessibilityController::RootElement() { |
237 if (root_element_.isNull()) | 237 blink::WebAXObject root_element = web_view_->accessibilityObject(); |
238 root_element_ = web_view_->accessibilityObject(); | 238 return elements_.GetOrCreate(root_element); |
239 return elements_.GetOrCreate(root_element_); | |
240 } | 239 } |
241 | 240 |
242 v8::Local<v8::Object> | 241 v8::Local<v8::Object> |
243 AccessibilityController::AccessibleElementById(const std::string& id) { | 242 AccessibilityController::AccessibleElementById(const std::string& id) { |
244 if (root_element_.isNull()) | 243 blink::WebAXObject root_element = web_view_->accessibilityObject(); |
245 root_element_ = web_view_->accessibilityObject(); | |
246 | 244 |
247 if (!root_element_.updateLayoutAndCheckValidity()) | 245 if (!root_element.updateLayoutAndCheckValidity()) |
248 return v8::Local<v8::Object>(); | 246 return v8::Local<v8::Object>(); |
249 | 247 |
250 return FindAccessibleElementByIdRecursive( | 248 return FindAccessibleElementByIdRecursive( |
251 root_element_, blink::WebString::fromUTF8(id.c_str())); | 249 root_element, blink::WebString::fromUTF8(id.c_str())); |
252 } | 250 } |
253 | 251 |
254 v8::Local<v8::Object> | 252 v8::Local<v8::Object> |
255 AccessibilityController::FindAccessibleElementByIdRecursive( | 253 AccessibilityController::FindAccessibleElementByIdRecursive( |
256 const blink::WebAXObject& obj, const blink::WebString& id) { | 254 const blink::WebAXObject& obj, const blink::WebString& id) { |
257 if (obj.isNull() || obj.isDetached()) | 255 if (obj.isNull() || obj.isDetached()) |
258 return v8::Local<v8::Object>(); | 256 return v8::Local<v8::Object>(); |
259 | 257 |
260 blink::WebNode node = obj.node(); | 258 blink::WebNode node = obj.node(); |
261 if (!node.isNull() && node.isElementNode()) { | 259 if (!node.isNull() && node.isElementNode()) { |
262 blink::WebElement element = node.to<blink::WebElement>(); | 260 blink::WebElement element = node.to<blink::WebElement>(); |
263 element.getAttribute("id"); | 261 element.getAttribute("id"); |
264 if (element.getAttribute("id") == id) | 262 if (element.getAttribute("id") == id) |
265 return elements_.GetOrCreate(obj); | 263 return elements_.GetOrCreate(obj); |
266 } | 264 } |
267 | 265 |
268 unsigned childCount = obj.childCount(); | 266 unsigned childCount = obj.childCount(); |
269 for (unsigned i = 0; i < childCount; i++) { | 267 for (unsigned i = 0; i < childCount; i++) { |
270 v8::Local<v8::Object> result = | 268 v8::Local<v8::Object> result = |
271 FindAccessibleElementByIdRecursive(obj.childAt(i), id); | 269 FindAccessibleElementByIdRecursive(obj.childAt(i), id); |
272 if (*result) | 270 if (*result) |
273 return result; | 271 return result; |
274 } | 272 } |
275 | 273 |
276 return v8::Local<v8::Object>(); | 274 return v8::Local<v8::Object>(); |
277 } | 275 } |
278 | 276 |
279 } // namespace test_runner | 277 } // namespace test_runner |
OLD | NEW |