| 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 CHECK(frame->IsWebLocalFrame()) |
| 222 << "This function cannot be called if the main frame is not a " |
| 223 "local frame."; |
| 219 blink::WebAXObject focused_element = | 224 blink::WebAXObject focused_element = |
| 220 blink::WebAXObject::FromWebDocumentFocused(frame->GetDocument()); | 225 blink::WebAXObject::FromWebDocumentFocused( |
| 226 frame->ToWebLocalFrame()->GetDocument()); |
| 221 if (focused_element.IsNull()) | 227 if (focused_element.IsNull()) |
| 222 focused_element = blink::WebAXObject::FromWebView(*web_view()); | 228 focused_element = GetAccessibilityObjectForMainFrame(); |
| 223 return elements_.GetOrCreate(focused_element); | 229 return elements_.GetOrCreate(focused_element); |
| 224 } | 230 } |
| 225 | 231 |
| 226 v8::Local<v8::Object> AccessibilityController::RootElement() { | 232 v8::Local<v8::Object> AccessibilityController::RootElement() { |
| 227 blink::WebAXObject root_element = | 233 return elements_.GetOrCreate(GetAccessibilityObjectForMainFrame()); |
| 228 blink::WebAXObject::FromWebView(*web_view()); | |
| 229 return elements_.GetOrCreate(root_element); | |
| 230 } | 234 } |
| 231 | 235 |
| 232 v8::Local<v8::Object> AccessibilityController::AccessibleElementById( | 236 v8::Local<v8::Object> AccessibilityController::AccessibleElementById( |
| 233 const std::string& id) { | 237 const std::string& id) { |
| 234 blink::WebAXObject root_element = | 238 blink::WebAXObject root_element = GetAccessibilityObjectForMainFrame(); |
| 235 blink::WebAXObject::FromWebView(*web_view()); | |
| 236 | 239 |
| 237 if (!root_element.UpdateLayoutAndCheckValidity()) | 240 if (!root_element.UpdateLayoutAndCheckValidity()) |
| 238 return v8::Local<v8::Object>(); | 241 return v8::Local<v8::Object>(); |
| 239 | 242 |
| 240 return FindAccessibleElementByIdRecursive( | 243 return FindAccessibleElementByIdRecursive( |
| 241 root_element, blink::WebString::FromUTF8(id.c_str())); | 244 root_element, blink::WebString::FromUTF8(id.c_str())); |
| 242 } | 245 } |
| 243 | 246 |
| 244 v8::Local<v8::Object> | 247 v8::Local<v8::Object> |
| 245 AccessibilityController::FindAccessibleElementByIdRecursive( | 248 AccessibilityController::FindAccessibleElementByIdRecursive( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 264 return result; | 267 return result; |
| 265 } | 268 } |
| 266 | 269 |
| 267 return v8::Local<v8::Object>(); | 270 return v8::Local<v8::Object>(); |
| 268 } | 271 } |
| 269 | 272 |
| 270 blink::WebView* AccessibilityController::web_view() { | 273 blink::WebView* AccessibilityController::web_view() { |
| 271 return web_view_test_proxy_base_->web_view(); | 274 return web_view_test_proxy_base_->web_view(); |
| 272 } | 275 } |
| 273 | 276 |
| 277 blink::WebAXObject |
| 278 AccessibilityController::GetAccessibilityObjectForMainFrame() { |
| 279 blink::WebFrame* frame = web_view()->MainFrame(); |
| 280 CHECK(frame && frame->IsWebLocalFrame()) |
| 281 << "This function cannot be called if the main frame is not a " |
| 282 "local frame."; |
| 283 return blink::WebAXObject::FromWebDocument( |
| 284 web_view()->MainFrame()->ToWebLocalFrame()->GetDocument()); |
| 285 } |
| 286 |
| 274 } // namespace test_runner | 287 } // namespace test_runner |
| OLD | NEW |