AccessibilityController.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2011 Apple 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
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "AccessibilityController.h"
  27. #include "AccessibilityUIElement.h"
  28. #include "InjectedBundle.h"
  29. #include "InjectedBundlePage.h"
  30. #include "JSAccessibilityController.h"
  31. #include <JavaScriptCore/JSRetainPtr.h>
  32. #include <WebKit2/WKBundle.h>
  33. #include <WebKit2/WKBundlePage.h>
  34. #include <WebKit2/WKBundlePagePrivate.h>
  35. namespace WTR {
  36. PassRefPtr<AccessibilityController> AccessibilityController::create()
  37. {
  38. return adoptRef(new AccessibilityController);
  39. }
  40. AccessibilityController::AccessibilityController()
  41. #if PLATFORM(GTK) || PLATFORM(EFL)
  42. : m_stateChangeListenerId(0)
  43. , m_focusEventListenerId(0)
  44. , m_activeDescendantChangedListenerId(0)
  45. , m_childrenChangedListenerId(0)
  46. , m_propertyChangedListenerId(0)
  47. , m_visibleDataChangedListenerId(0)
  48. #endif
  49. {
  50. }
  51. AccessibilityController::~AccessibilityController()
  52. {
  53. }
  54. void AccessibilityController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
  55. {
  56. setProperty(context, windowObject, "accessibilityController", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
  57. }
  58. JSClassRef AccessibilityController::wrapperClass()
  59. {
  60. return JSAccessibilityController::accessibilityControllerClass();
  61. }
  62. #if !PLATFORM(GTK) && !PLATFORM(EFL)
  63. PassRefPtr<AccessibilityUIElement> AccessibilityController::rootElement()
  64. {
  65. // FIXME: Make this work on Windows.
  66. #if PLATFORM(WIN)
  67. return 0;
  68. #else
  69. WKBundlePageRef page = InjectedBundle::shared().page()->page();
  70. void* root = WKAccessibilityRootObject(page);
  71. return AccessibilityUIElement::create(static_cast<PlatformUIElement>(root));
  72. #endif
  73. }
  74. PassRefPtr<AccessibilityUIElement> AccessibilityController::focusedElement()
  75. {
  76. // FIXME: Make this work on Windows.
  77. #if PLATFORM(WIN)
  78. return 0;
  79. #else
  80. WKBundlePageRef page = InjectedBundle::shared().page()->page();
  81. void* root = WKAccessibilityFocusedObject(page);
  82. return AccessibilityUIElement::create(static_cast<PlatformUIElement>(root));
  83. #endif
  84. }
  85. #endif
  86. PassRefPtr<AccessibilityUIElement> AccessibilityController::elementAtPoint(int x, int y)
  87. {
  88. RefPtr<AccessibilityUIElement> uiElement = rootElement();
  89. return uiElement->elementAtPoint(x, y);
  90. }
  91. // Unsupported methods on various platforms.
  92. // As they're implemented on other platforms this list should be modified.
  93. #if !PLATFORM(MAC)
  94. bool AccessibilityController::addNotificationListener(JSValueRef) { return false; }
  95. bool AccessibilityController::removeNotificationListener() { return false; }
  96. #endif
  97. #if !PLATFORM(MAC) && !PLATFORM(GTK) && !PLATFORM(EFL)
  98. PassRefPtr<AccessibilityUIElement> AccessibilityController::accessibleElementById(JSStringRef attribute) { return 0; }
  99. #endif
  100. #if !PLATFORM(GTK) && !PLATFORM(EFL) && !PLATFORM(MAC)
  101. void AccessibilityController::logAccessibilityEvents() { }
  102. void AccessibilityController::resetToConsistentState() { }
  103. #endif
  104. } // namespace WTR