bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 1 | /* |
jhoneycutt@apple.com | cd3d45c | 2010-01-05 01:12:13 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008, 2009, 2010 Apple Inc. All Rights Reserved. |
bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 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 | |
darin@apple.com | a6bd509 | 2008-10-14 18:43:24 +0000 | [diff] [blame] | 26 | #include "config.h" |
commit-queue@webkit.org | d036cc8 | 2013-04-07 16:42:28 +0000 | [diff] [blame] | 27 | |
| 28 | #if HAVE(ACCESSIBILITY) |
| 29 | |
bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 30 | #include "AccessibilityController.h" |
| 31 | |
weinig@apple.com | e876c60 | 2008-07-16 04:53:29 +0000 | [diff] [blame] | 32 | #include "AccessibilityUIElement.h" |
| 33 | #include <JavaScriptCore/JSRetainPtr.h> |
bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 34 | |
weinig@apple.com | e876c60 | 2008-07-16 04:53:29 +0000 | [diff] [blame] | 35 | // Static Value Getters |
bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 36 | |
weinig@apple.com | e876c60 | 2008-07-16 04:53:29 +0000 | [diff] [blame] | 37 | static JSValueRef getFocusedElementCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) |
bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 38 | { |
darin@apple.com | 2c43008 | 2009-03-27 23:55:04 +0000 | [diff] [blame] | 39 | AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); |
weinig@apple.com | e876c60 | 2008-07-16 04:53:29 +0000 | [diff] [blame] | 40 | return AccessibilityUIElement::makeJSAccessibilityUIElement(context, controller->focusedElement()); |
bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 41 | } |
| 42 | |
weinig@apple.com | e876c60 | 2008-07-16 04:53:29 +0000 | [diff] [blame] | 43 | static JSValueRef getRootElementCallback(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception) |
bdakin@apple.com | b8ae4a5 | 2008-06-26 00:22:59 +0000 | [diff] [blame] | 44 | { |
darin@apple.com | 2c43008 | 2009-03-27 23:55:04 +0000 | [diff] [blame] | 45 | AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); |
weinig@apple.com | e876c60 | 2008-07-16 04:53:29 +0000 | [diff] [blame] | 46 | return AccessibilityUIElement::makeJSAccessibilityUIElement(context, controller->rootElement()); |
bdakin@apple.com | fe260cb | 2008-07-07 23:26:05 +0000 | [diff] [blame] | 47 | } |
| 48 | |
bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 49 | // Object Creation |
| 50 | |
| 51 | void AccessibilityController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception) |
| 52 | { |
| 53 | JSRetainPtr<JSStringRef> accessibilityControllerStr(Adopt, JSStringCreateWithUTF8CString("accessibilityController")); |
weinig@apple.com | 22c5a16 | 2009-12-03 21:25:24 +0000 | [diff] [blame] | 54 | |
| 55 | JSClassRef classRef = getJSClass(); |
| 56 | JSValueRef accessibilityControllerObject = JSObjectMake(context, classRef, this); |
| 57 | JSClassRelease(classRef); |
| 58 | |
bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 59 | JSObjectSetProperty(context, windowObject, accessibilityControllerStr.get(), accessibilityControllerObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception); |
| 60 | } |
| 61 | |
jhoneycutt@apple.com | fa9b19d | 2009-08-15 06:15:05 +0000 | [diff] [blame] | 62 | static JSValueRef logFocusEventsCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*) |
| 63 | { |
| 64 | AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); |
jhoneycutt@apple.com | 739aa7b | 2009-08-15 11:25:19 +0000 | [diff] [blame] | 65 | controller->setLogFocusEvents(true); |
jhoneycutt@apple.com | fa9b19d | 2009-08-15 06:15:05 +0000 | [diff] [blame] | 66 | return JSValueMakeUndefined(ctx); |
| 67 | } |
| 68 | |
jhoneycutt@apple.com | cd3d45c | 2010-01-05 01:12:13 +0000 | [diff] [blame] | 69 | static JSValueRef logValueChangeEventsCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*) |
| 70 | { |
| 71 | AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); |
| 72 | controller->setLogValueChangeEvents(true); |
| 73 | return JSValueMakeUndefined(ctx); |
| 74 | } |
| 75 | |
jhoneycutt@apple.com | f1115ef5 | 2009-09-14 21:25:24 +0000 | [diff] [blame] | 76 | static JSValueRef logScrollingStartEventsCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*) |
| 77 | { |
| 78 | AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); |
| 79 | controller->setLogScrollingStartEvents(true); |
| 80 | return JSValueMakeUndefined(ctx); |
| 81 | } |
| 82 | |
mario@webkit.org | 19d3474 | 2011-02-10 09:03:30 +0000 | [diff] [blame] | 83 | static JSValueRef logAccessibilityEventsCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t, const JSValueRef[], JSValueRef*) |
| 84 | { |
| 85 | AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); |
| 86 | controller->setLogAccessibilityEvents(true); |
| 87 | return JSValueMakeUndefined(ctx); |
| 88 | } |
| 89 | |
cfleizach@apple.com | 0c8875a | 2010-03-09 17:42:29 +0000 | [diff] [blame] | 90 | static JSValueRef getElementAtPointCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 91 | { |
| 92 | int x = 0; |
| 93 | int y = 0; |
| 94 | if (argumentCount == 2) { |
| 95 | x = JSValueToNumber(context, arguments[0], exception); |
| 96 | y = JSValueToNumber(context, arguments[1], exception); |
| 97 | } |
| 98 | |
| 99 | AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); |
| 100 | return AccessibilityUIElement::makeJSAccessibilityUIElement(context, controller->elementAtPoint(x, y)); |
| 101 | } |
| 102 | |
dmazzoni@google.com | 8dea0ad0 | 2012-09-22 16:17:57 +0000 | [diff] [blame] | 103 | static JSValueRef getAccessibleElementByIdCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 104 | { |
| 105 | JSStringRef idAttribute = 0; |
| 106 | if (argumentCount == 1) |
| 107 | idAttribute = JSValueToStringCopy(context, arguments[0], exception); |
| 108 | AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); |
| 109 | JSValueRef result = AccessibilityUIElement::makeJSAccessibilityUIElement(context, controller->accessibleElementById(idAttribute)); |
| 110 | if (idAttribute) |
| 111 | JSStringRelease(idAttribute); |
| 112 | return result; |
| 113 | } |
| 114 | |
dmazzoni@google.com | 1851ba0 | 2011-12-08 21:27:16 +0000 | [diff] [blame] | 115 | static JSValueRef addNotificationListenerCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 116 | { |
| 117 | if (argumentCount != 1) |
| 118 | return JSValueMakeBoolean(context, false); |
| 119 | |
| 120 | AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); |
| 121 | JSObjectRef callback = JSValueToObject(context, arguments[0], exception); |
| 122 | bool succeeded = controller->addNotificationListener(callback); |
| 123 | return JSValueMakeBoolean(context, succeeded); |
| 124 | } |
| 125 | |
| 126 | static JSValueRef removeNotificationListenerCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 127 | { |
| 128 | AccessibilityController* controller = static_cast<AccessibilityController*>(JSObjectGetPrivate(thisObject)); |
| 129 | controller->removeNotificationListener(); |
| 130 | return JSValueMakeUndefined(context); |
| 131 | } |
| 132 | |
bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 133 | JSClassRef AccessibilityController::getJSClass() |
| 134 | { |
jhoneycutt@apple.com | fa9b19d | 2009-08-15 06:15:05 +0000 | [diff] [blame] | 135 | static JSStaticFunction staticFunctions[] = { |
| 136 | { "logFocusEvents", logFocusEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, |
jhoneycutt@apple.com | cd3d45c | 2010-01-05 01:12:13 +0000 | [diff] [blame] | 137 | { "logValueChangeEvents", logValueChangeEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, |
jhoneycutt@apple.com | f1115ef5 | 2009-09-14 21:25:24 +0000 | [diff] [blame] | 138 | { "logScrollingStartEvents", logScrollingStartEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, |
mario@webkit.org | 19d3474 | 2011-02-10 09:03:30 +0000 | [diff] [blame] | 139 | { "logAccessibilityEvents", logAccessibilityEventsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, |
cfleizach@apple.com | 0c8875a | 2010-03-09 17:42:29 +0000 | [diff] [blame] | 140 | { "elementAtPoint", getElementAtPointCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, |
dmazzoni@google.com | 8dea0ad0 | 2012-09-22 16:17:57 +0000 | [diff] [blame] | 141 | { "accessibleElementById", getAccessibleElementByIdCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, |
dmazzoni@google.com | 1851ba0 | 2011-12-08 21:27:16 +0000 | [diff] [blame] | 142 | { "addNotificationListener", addNotificationListenerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, |
| 143 | { "removeNotificationListener", removeNotificationListenerCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, |
jhoneycutt@apple.com | fa9b19d | 2009-08-15 06:15:05 +0000 | [diff] [blame] | 144 | { 0, 0, 0 } |
| 145 | }; |
| 146 | |
weinig@apple.com | e876c60 | 2008-07-16 04:53:29 +0000 | [diff] [blame] | 147 | static JSStaticValue staticValues[] = { |
| 148 | { "focusedElement", getFocusedElementCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, |
| 149 | { "rootElement", getRootElementCallback, 0, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, |
| 150 | { 0, 0, 0, 0 } |
bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
weinig@apple.com | e876c60 | 2008-07-16 04:53:29 +0000 | [diff] [blame] | 153 | static JSClassDefinition classDefinition = { |
jhoneycutt@apple.com | fa9b19d | 2009-08-15 06:15:05 +0000 | [diff] [blame] | 154 | 0, kJSClassAttributeNone, "AccessibilityController", 0, staticValues, staticFunctions, |
weinig@apple.com | e876c60 | 2008-07-16 04:53:29 +0000 | [diff] [blame] | 155 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 156 | }; |
| 157 | |
weinig@apple.com | bb56753 | 2009-12-01 01:18:50 +0000 | [diff] [blame] | 158 | return JSClassCreate(&classDefinition); |
bdakin@apple.com | e1d57db | 2008-06-24 21:02:38 +0000 | [diff] [blame] | 159 | } |
jhoneycutt@apple.com | 739aa7b | 2009-08-15 11:25:19 +0000 | [diff] [blame] | 160 | |
| 161 | void AccessibilityController::resetToConsistentState() |
| 162 | { |
| 163 | setLogFocusEvents(false); |
jhoneycutt@apple.com | cd3d45c | 2010-01-05 01:12:13 +0000 | [diff] [blame] | 164 | setLogValueChangeEvents(false); |
jhoneycutt@apple.com | f1115ef5 | 2009-09-14 21:25:24 +0000 | [diff] [blame] | 165 | setLogScrollingStartEvents(false); |
mario@webkit.org | 19d3474 | 2011-02-10 09:03:30 +0000 | [diff] [blame] | 166 | setLogAccessibilityEvents(false); |
jhoneycutt@apple.com | 739aa7b | 2009-08-15 11:25:19 +0000 | [diff] [blame] | 167 | } |
commit-queue@webkit.org | d036cc8 | 2013-04-07 16:42:28 +0000 | [diff] [blame] | 168 | #endif // HAVE(ACCESSIBILITY) |