• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "config.h"
32 #include "AccessibilityController.h"
33 
34 #include "TestShell.h"
35 #include "WebAccessibilityCache.h"
36 #include "WebAccessibilityObject.h"
37 #include "WebFrame.h"
38 #include "WebString.h"
39 #include "WebView.h"
40 
41 using namespace WebKit;
42 
AccessibilityController(TestShell * shell)43 AccessibilityController::AccessibilityController(TestShell* shell)
44     : m_dumpAccessibilityNotifications(false)
45     , m_shell(shell)
46 {
47 
48     bindMethod("dumpAccessibilityNotifications", &AccessibilityController::dumpAccessibilityNotifications);
49     bindMethod("logFocusEvents", &AccessibilityController::logFocusEventsCallback);
50     bindMethod("logScrollingStartEvents", &AccessibilityController::logScrollingStartEventsCallback);
51 
52     bindProperty("focusedElement", &AccessibilityController::focusedElementGetterCallback);
53     bindProperty("rootElement", &AccessibilityController::rootElementGetterCallback);
54 
55     bindFallbackMethod(&AccessibilityController::fallbackCallback);
56 }
57 
bindToJavascript(WebFrame * frame,const WebString & classname)58 void AccessibilityController::bindToJavascript(WebFrame* frame, const WebString& classname)
59 {
60     WebAccessibilityCache::enableAccessibility();
61     CppBoundClass::bindToJavascript(frame, classname);
62 }
63 
reset()64 void AccessibilityController::reset()
65 {
66     m_rootElement = WebAccessibilityObject();
67     m_focusedElement = WebAccessibilityObject();
68     m_elements.clear();
69 
70     m_dumpAccessibilityNotifications = false;
71 }
72 
setFocusedElement(const WebAccessibilityObject & focusedElement)73 void AccessibilityController::setFocusedElement(const WebAccessibilityObject& focusedElement)
74 {
75     m_focusedElement = focusedElement;
76 }
77 
getFocusedElement()78 AccessibilityUIElement* AccessibilityController::getFocusedElement()
79 {
80     if (m_focusedElement.isNull())
81         m_focusedElement = m_shell->webView()->accessibilityObject();
82     return m_elements.create(m_focusedElement);
83 }
84 
getRootElement()85 AccessibilityUIElement* AccessibilityController::getRootElement()
86 {
87     if (m_rootElement.isNull())
88         m_rootElement = m_shell->webView()->accessibilityObject();
89     return m_elements.createRoot(m_rootElement);
90 }
91 
dumpAccessibilityNotifications(const CppArgumentList &,CppVariant * result)92 void AccessibilityController::dumpAccessibilityNotifications(const CppArgumentList&, CppVariant* result)
93 {
94     m_dumpAccessibilityNotifications = true;
95     result->setNull();
96 }
97 
logFocusEventsCallback(const CppArgumentList &,CppVariant * result)98 void AccessibilityController::logFocusEventsCallback(const CppArgumentList&, CppVariant* result)
99 {
100     // As of r49031, this is not being used upstream.
101     result->setNull();
102 }
103 
logScrollingStartEventsCallback(const CppArgumentList &,CppVariant * result)104 void AccessibilityController::logScrollingStartEventsCallback(const CppArgumentList&, CppVariant* result)
105 {
106     // As of r49031, this is not being used upstream.
107     result->setNull();
108 }
109 
focusedElementGetterCallback(CppVariant * result)110 void AccessibilityController::focusedElementGetterCallback(CppVariant* result)
111 {
112     result->set(*(getFocusedElement()->getAsCppVariant()));
113 }
114 
rootElementGetterCallback(CppVariant * result)115 void AccessibilityController::rootElementGetterCallback(CppVariant* result)
116 {
117     result->set(*(getRootElement()->getAsCppVariant()));
118 }
119 
fallbackCallback(const CppArgumentList &,CppVariant * result)120 void AccessibilityController::fallbackCallback(const CppArgumentList&, CppVariant* result)
121 {
122     printf("CONSOLE MESSAGE: JavaScript ERROR: unknown method called on "
123            "AccessibilityController\n");
124     result->setNull();
125 }
126