WebKitTools/DumpRenderTree/chromium/AccessibilityController.cpp
changeset 2 303757a437d3
parent 0 4f2f89ce4247
equal deleted inserted replaced
0:4f2f89ce4247 2:303757a437d3
     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 "public/WebAccessibilityCache.h"
       
    36 #include "public/WebAccessibilityObject.h"
       
    37 #include "public/WebFrame.h"
       
    38 #include "public/WebString.h"
       
    39 #include "public/WebView.h"
       
    40 
       
    41 using namespace WebKit;
       
    42 
       
    43 AccessibilityController::AccessibilityController(TestShell* shell)
       
    44     : m_shell(shell)
       
    45 {
       
    46 
       
    47     bindMethod("logFocusEvents",
       
    48         &AccessibilityController::logFocusEventsCallback);
       
    49     bindMethod("logScrollingStartEvents",
       
    50         &AccessibilityController::logScrollingStartEventsCallback);
       
    51 
       
    52     bindProperty("focusedElement",
       
    53         &AccessibilityController::focusedElementGetterCallback);
       
    54     bindProperty("rootElement",
       
    55         &AccessibilityController::rootElementGetterCallback);
       
    56 
       
    57     bindFallbackMethod(&AccessibilityController::fallbackCallback);
       
    58 }
       
    59 
       
    60 void AccessibilityController::bindToJavascript(WebFrame* frame, const WebString& classname)
       
    61 {
       
    62     WebAccessibilityCache::enableAccessibility();
       
    63     CppBoundClass::bindToJavascript(frame, classname);
       
    64 }
       
    65 
       
    66 void AccessibilityController::reset()
       
    67 {
       
    68     m_rootElement = WebAccessibilityObject();
       
    69     m_focusedElement = WebAccessibilityObject();
       
    70     m_elements.clear();
       
    71 }
       
    72 
       
    73 void AccessibilityController::setFocusedElement(const WebAccessibilityObject& focusedElement)
       
    74 {
       
    75     m_focusedElement = focusedElement;
       
    76 }
       
    77 
       
    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 
       
    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 
       
    92 void AccessibilityController::logFocusEventsCallback(const CppArgumentList&, CppVariant* result)
       
    93 {
       
    94     // As of r49031, this is not being used upstream.
       
    95     result->setNull();
       
    96 }
       
    97 
       
    98 void AccessibilityController::logScrollingStartEventsCallback(const CppArgumentList&, CppVariant* result)
       
    99 {
       
   100     // As of r49031, this is not being used upstream.
       
   101     result->setNull();
       
   102 }
       
   103 
       
   104 void AccessibilityController::focusedElementGetterCallback(CppVariant* result)
       
   105 {
       
   106     result->set(*(getFocusedElement()->getAsCppVariant()));
       
   107 }
       
   108 
       
   109 void AccessibilityController::rootElementGetterCallback(CppVariant* result)
       
   110 {
       
   111     result->set(*(getRootElement()->getAsCppVariant()));
       
   112 }
       
   113 
       
   114 void AccessibilityController::fallbackCallback(const CppArgumentList&, CppVariant* result)
       
   115 {
       
   116     printf("CONSOLE MESSAGE: JavaScript ERROR: unknown method called on "
       
   117            "AccessibilityController\n");
       
   118     result->setNull();
       
   119 }