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 "content/shell/test_runner/accessibility_controller.h" | 5 #include "content/shell/test_runner/accessibility_controller.h" |
6 | 6 |
| 7 #include <string> |
| 8 |
7 #include "base/macros.h" | 9 #include "base/macros.h" |
8 #include "content/shell/test_runner/web_view_test_proxy.h" | 10 #include "content/shell/test_runner/web_view_test_proxy.h" |
9 #include "gin/handle.h" | 11 #include "gin/handle.h" |
10 #include "gin/object_template_builder.h" | 12 #include "gin/object_template_builder.h" |
11 #include "gin/wrappable.h" | 13 #include "gin/wrappable.h" |
12 #include "third_party/WebKit/public/web/WebDocument.h" | 14 #include "third_party/WebKit/public/web/WebDocument.h" |
13 #include "third_party/WebKit/public/web/WebElement.h" | 15 #include "third_party/WebKit/public/web/WebElement.h" |
14 #include "third_party/WebKit/public/web/WebFrame.h" | 16 #include "third_party/WebKit/public/web/WebFrame.h" |
15 #include "third_party/WebKit/public/web/WebKit.h" | 17 #include "third_party/WebKit/public/web/WebKit.h" |
16 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 18 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 211 |
210 void AccessibilityController::UnsetNotificationListener() { | 212 void AccessibilityController::UnsetNotificationListener() { |
211 notification_callback_.Reset(); | 213 notification_callback_.Reset(); |
212 } | 214 } |
213 | 215 |
214 v8::Local<v8::Object> AccessibilityController::FocusedElement() { | 216 v8::Local<v8::Object> AccessibilityController::FocusedElement() { |
215 blink::WebFrame* frame = web_view()->MainFrame(); | 217 blink::WebFrame* frame = web_view()->MainFrame(); |
216 if (!frame) | 218 if (!frame) |
217 return v8::Local<v8::Object>(); | 219 return v8::Local<v8::Object>(); |
218 | 220 |
| 221 // TODO(lukasza): Finish adding OOPIF support to the layout tests harness. |
| 222 CHECK(frame->IsWebLocalFrame()) |
| 223 << "This function cannot be called if the main frame is not a " |
| 224 "local frame."; |
219 blink::WebAXObject focused_element = | 225 blink::WebAXObject focused_element = |
220 blink::WebAXObject::FromWebDocumentFocused(frame->GetDocument()); | 226 blink::WebAXObject::FromWebDocumentFocused( |
| 227 frame->ToWebLocalFrame()->GetDocument()); |
221 if (focused_element.IsNull()) | 228 if (focused_element.IsNull()) |
222 focused_element = blink::WebAXObject::FromWebView(*web_view()); | 229 focused_element = GetAccessibilityObjectForMainFrame(); |
223 return elements_.GetOrCreate(focused_element); | 230 return elements_.GetOrCreate(focused_element); |
224 } | 231 } |
225 | 232 |
226 v8::Local<v8::Object> AccessibilityController::RootElement() { | 233 v8::Local<v8::Object> AccessibilityController::RootElement() { |
227 blink::WebAXObject root_element = | 234 return elements_.GetOrCreate(GetAccessibilityObjectForMainFrame()); |
228 blink::WebAXObject::FromWebView(*web_view()); | |
229 return elements_.GetOrCreate(root_element); | |
230 } | 235 } |
231 | 236 |
232 v8::Local<v8::Object> AccessibilityController::AccessibleElementById( | 237 v8::Local<v8::Object> AccessibilityController::AccessibleElementById( |
233 const std::string& id) { | 238 const std::string& id) { |
234 blink::WebAXObject root_element = | 239 blink::WebAXObject root_element = GetAccessibilityObjectForMainFrame(); |
235 blink::WebAXObject::FromWebView(*web_view()); | |
236 | 240 |
237 if (!root_element.UpdateLayoutAndCheckValidity()) | 241 if (!root_element.UpdateLayoutAndCheckValidity()) |
238 return v8::Local<v8::Object>(); | 242 return v8::Local<v8::Object>(); |
239 | 243 |
240 return FindAccessibleElementByIdRecursive( | 244 return FindAccessibleElementByIdRecursive( |
241 root_element, blink::WebString::FromUTF8(id.c_str())); | 245 root_element, blink::WebString::FromUTF8(id.c_str())); |
242 } | 246 } |
243 | 247 |
244 v8::Local<v8::Object> | 248 v8::Local<v8::Object> |
245 AccessibilityController::FindAccessibleElementByIdRecursive( | 249 AccessibilityController::FindAccessibleElementByIdRecursive( |
(...skipping 18 matching lines...) Expand all Loading... |
264 return result; | 268 return result; |
265 } | 269 } |
266 | 270 |
267 return v8::Local<v8::Object>(); | 271 return v8::Local<v8::Object>(); |
268 } | 272 } |
269 | 273 |
270 blink::WebView* AccessibilityController::web_view() { | 274 blink::WebView* AccessibilityController::web_view() { |
271 return web_view_test_proxy_base_->web_view(); | 275 return web_view_test_proxy_base_->web_view(); |
272 } | 276 } |
273 | 277 |
| 278 blink::WebAXObject |
| 279 AccessibilityController::GetAccessibilityObjectForMainFrame() { |
| 280 blink::WebFrame* frame = web_view()->MainFrame(); |
| 281 |
| 282 // TODO(lukasza): Finish adding OOPIF support to the layout tests harness. |
| 283 CHECK(frame && frame->IsWebLocalFrame()) |
| 284 << "This function cannot be called if the main frame is not a " |
| 285 "local frame."; |
| 286 return blink::WebAXObject::FromWebDocument( |
| 287 web_view()->MainFrame()->ToWebLocalFrame()->GetDocument()); |
| 288 } |
| 289 |
274 } // namespace test_runner | 290 } // namespace test_runner |
OLD | NEW |