OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2009 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 <vector> | |
6 | |
7 #include "webkit/tools/test_shell/accessibility_controller.h" | |
8 | |
9 #include "base/logging.h" | |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityCache
.h" | |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObjec
t.h" | |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
14 #include "webkit/tools/test_shell/test_shell.h" | |
15 | |
16 using WebKit::WebAccessibilityCache; | |
17 using WebKit::WebAccessibilityObject; | |
18 using WebKit::WebFrame; | |
19 | |
20 AccessibilityController::AccessibilityController(TestShell* shell) | |
21 : shell_(shell) { | |
22 | |
23 BindMethod("logFocusEvents", | |
24 &AccessibilityController::LogFocusEventsCallback); | |
25 BindMethod("logScrollingStartEvents", | |
26 &AccessibilityController::LogScrollingStartEventsCallback); | |
27 | |
28 BindProperty("focusedElement", | |
29 &AccessibilityController::FocusedElementGetterCallback); | |
30 BindProperty("rootElement", | |
31 &AccessibilityController::RootElementGetterCallback); | |
32 | |
33 BindFallbackMethod(&AccessibilityController::FallbackCallback); | |
34 } | |
35 | |
36 void AccessibilityController::BindToJavascript( | |
37 WebFrame* frame, const std::string& classname) { | |
38 WebAccessibilityCache::enableAccessibility(); | |
39 CppBoundClass::BindToJavascript(frame, classname); | |
40 } | |
41 | |
42 void AccessibilityController::Reset() { | |
43 root_element_ = WebAccessibilityObject(); | |
44 focused_element_ = WebAccessibilityObject(); | |
45 elements_.Clear(); | |
46 } | |
47 | |
48 void AccessibilityController::SetFocusedElement( | |
49 const WebAccessibilityObject& focused_element) { | |
50 focused_element_ = focused_element; | |
51 } | |
52 | |
53 AccessibilityUIElement* AccessibilityController::GetFocusedElement() { | |
54 if (focused_element_.isNull()) | |
55 focused_element_ = shell_->webView()->accessibilityObject(); | |
56 | |
57 return elements_.Create(focused_element_); | |
58 } | |
59 | |
60 AccessibilityUIElement* AccessibilityController::GetRootElement() { | |
61 if (root_element_.isNull()) | |
62 root_element_ = shell_->webView()->accessibilityObject(); | |
63 return elements_.CreateRoot(root_element_); | |
64 } | |
65 | |
66 void AccessibilityController::LogFocusEventsCallback( | |
67 const CppArgumentList &args, | |
68 CppVariant *result) { | |
69 // As of r49031, this is not being used upstream. | |
70 result->SetNull(); | |
71 } | |
72 | |
73 void AccessibilityController::LogScrollingStartEventsCallback( | |
74 const CppArgumentList &args, | |
75 CppVariant *result) { | |
76 // As of r49031, this is not being used upstream. | |
77 result->SetNull(); | |
78 } | |
79 | |
80 void AccessibilityController::FocusedElementGetterCallback(CppVariant* result) { | |
81 result->Set(*(GetFocusedElement()->GetAsCppVariant())); | |
82 } | |
83 | |
84 void AccessibilityController::RootElementGetterCallback(CppVariant *result) { | |
85 result->Set(*(GetRootElement()->GetAsCppVariant())); | |
86 } | |
87 | |
88 void AccessibilityController::FallbackCallback(const CppArgumentList &args, | |
89 CppVariant *result) { | |
90 std::wstring message( | |
91 L"JavaScript ERROR: unknown method called on AccessibilityController"); | |
92 if (!shell_->layout_test_mode()) { | |
93 logging::LogMessage("CONSOLE:", 0).stream() << message; | |
94 } else { | |
95 printf("CONSOLE MESSAGE: %S\n", message.c_str()); | |
96 } | |
97 result->SetNull(); | |
98 } | |
OLD | NEW |