| 1 | /* |
| 2 | * Copyright (C) 2010, 2011, 2014-2015 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. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | #include "config.h" |
| 26 | #include "EventSendingController.h" |
| 27 | #include "JSEventSendingController.h" |
| 28 | #include <JavaScriptCore/JSRetainPtr.h> |
| 29 | #include <wtf/GetPtr.h> |
| 30 | |
| 31 | namespace WTR { |
| 32 | |
| 33 | EventSendingController* toEventSendingController(JSContextRef context, JSValueRef value) |
| 34 | { |
| 35 | if (!context || !value || !JSEventSendingController::eventSendingControllerClass() || !JSValueIsObjectOfClass(context, value, JSEventSendingController::eventSendingControllerClass())) |
| 36 | return 0; |
| 37 | return static_cast<EventSendingController*>(JSWrapper::unwrap(context, value)); |
| 38 | } |
| 39 | |
| 40 | JSClassRef JSEventSendingController::eventSendingControllerClass() |
| 41 | { |
| 42 | static JSClassRef jsClass; |
| 43 | if (!jsClass) { |
| 44 | JSClassDefinition definition = kJSClassDefinitionEmpty; |
| 45 | definition.className = "EventSendingController" ; |
| 46 | definition.parentClass = 0; |
| 47 | definition.staticValues = staticValues(); |
| 48 | definition.staticFunctions = staticFunctions(); |
| 49 | definition.initialize = initialize; |
| 50 | definition.finalize = finalize; |
| 51 | jsClass = JSClassCreate(&definition); |
| 52 | } |
| 53 | return jsClass; |
| 54 | } |
| 55 | |
| 56 | const JSStaticFunction* JSEventSendingController::staticFunctions() |
| 57 | { |
| 58 | static const JSStaticFunction functions[] = { |
| 59 | { "mouseDown" , mouseDown, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 60 | { "mouseUp" , mouseUp, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 61 | { "mouseMoveTo" , mouseMoveTo, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 62 | { "mouseForceClick" , mouseForceClick, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 63 | { "startAndCancelMouseForceClick" , startAndCancelMouseForceClick, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 64 | { "mouseForceDown" , mouseForceDown, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 65 | { "mouseForceUp" , mouseForceUp, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 66 | { "mouseForceChanged" , mouseForceChanged, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 67 | { "mouseScrollBy" , mouseScrollBy, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 68 | { "mouseScrollByWithWheelAndMomentumPhases" , mouseScrollByWithWheelAndMomentumPhases, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 69 | { "continuousMouseScrollBy" , continuousMouseScrollBy, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 70 | { "contextClick" , contextClick, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 71 | { "scheduleAsynchronousClick" , scheduleAsynchronousClick, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 72 | { "leapForward" , leapForward, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 73 | { "keyDown" , keyDown, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 74 | { "scheduleAsynchronousKeyDown" , scheduleAsynchronousKeyDown, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 75 | { "textZoomIn" , textZoomIn, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 76 | { "textZoomOut" , textZoomOut, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 77 | { "zoomPageIn" , zoomPageIn, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 78 | { "zoomPageOut" , zoomPageOut, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 79 | { "scalePageBy" , scalePageBy, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 80 | { "monitorWheelEvents" , monitorWheelEvents, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 81 | { "callAfterScrollingCompletes" , callAfterScrollingCompletes, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 82 | { "addTouchPoint" , addTouchPoint, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 83 | { "updateTouchPoint" , updateTouchPoint, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 84 | { "setTouchModifier" , setTouchModifier, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 85 | { "setTouchPointRadius" , setTouchPointRadius, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 86 | { "touchStart" , touchStart, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 87 | { "touchMove" , touchMove, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 88 | { "touchEnd" , touchEnd, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 89 | { "touchCancel" , touchCancel, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 90 | { "clearTouchPoints" , clearTouchPoints, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 91 | { "releaseTouchPoint" , releaseTouchPoint, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 92 | { "cancelTouchPoint" , cancelTouchPoint, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, |
| 93 | { 0, 0, 0 } |
| 94 | }; |
| 95 | return functions; |
| 96 | } |
| 97 | |
| 98 | const JSStaticValue* JSEventSendingController::staticValues() |
| 99 | { |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | // Functions |
| 104 | |
| 105 | JSValueRef JSEventSendingController::mouseDown(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 106 | { |
| 107 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 108 | if (!impl) |
| 109 | return JSValueMakeUndefined(context); |
| 110 | |
| 111 | double buttonNumber = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 112 | JSValueRef modifierArray = argumentCount > 1 ? arguments[1] : JSValueMakeUndefined(context); |
| 113 | impl->mouseDown(buttonNumber, modifierArray); |
| 114 | |
| 115 | return JSValueMakeUndefined(context); |
| 116 | } |
| 117 | |
| 118 | JSValueRef JSEventSendingController::mouseUp(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 119 | { |
| 120 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 121 | if (!impl) |
| 122 | return JSValueMakeUndefined(context); |
| 123 | |
| 124 | double buttonNumber = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 125 | JSValueRef modifierArray = argumentCount > 1 ? arguments[1] : JSValueMakeUndefined(context); |
| 126 | impl->mouseUp(buttonNumber, modifierArray); |
| 127 | |
| 128 | return JSValueMakeUndefined(context); |
| 129 | } |
| 130 | |
| 131 | JSValueRef JSEventSendingController::mouseMoveTo(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 132 | { |
| 133 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 134 | if (!impl) |
| 135 | return JSValueMakeUndefined(context); |
| 136 | |
| 137 | double x = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 138 | double y = argumentCount > 1 ? JSValueToNumber(context, arguments[1], nullptr) : 0; |
| 139 | impl->mouseMoveTo(x, y); |
| 140 | |
| 141 | return JSValueMakeUndefined(context); |
| 142 | } |
| 143 | |
| 144 | JSValueRef JSEventSendingController::mouseForceClick(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 145 | { |
| 146 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 147 | if (!impl) |
| 148 | return JSValueMakeUndefined(context); |
| 149 | |
| 150 | impl->mouseForceClick(); |
| 151 | |
| 152 | return JSValueMakeUndefined(context); |
| 153 | } |
| 154 | |
| 155 | JSValueRef JSEventSendingController::startAndCancelMouseForceClick(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 156 | { |
| 157 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 158 | if (!impl) |
| 159 | return JSValueMakeUndefined(context); |
| 160 | |
| 161 | impl->startAndCancelMouseForceClick(); |
| 162 | |
| 163 | return JSValueMakeUndefined(context); |
| 164 | } |
| 165 | |
| 166 | JSValueRef JSEventSendingController::mouseForceDown(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 167 | { |
| 168 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 169 | if (!impl) |
| 170 | return JSValueMakeUndefined(context); |
| 171 | |
| 172 | impl->mouseForceDown(); |
| 173 | |
| 174 | return JSValueMakeUndefined(context); |
| 175 | } |
| 176 | |
| 177 | JSValueRef JSEventSendingController::mouseForceUp(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 178 | { |
| 179 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 180 | if (!impl) |
| 181 | return JSValueMakeUndefined(context); |
| 182 | |
| 183 | impl->mouseForceUp(); |
| 184 | |
| 185 | return JSValueMakeUndefined(context); |
| 186 | } |
| 187 | |
| 188 | JSValueRef JSEventSendingController::mouseForceChanged(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 189 | { |
| 190 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 191 | if (!impl) |
| 192 | return JSValueMakeUndefined(context); |
| 193 | |
| 194 | double force = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 195 | impl->mouseForceChanged(force); |
| 196 | |
| 197 | return JSValueMakeUndefined(context); |
| 198 | } |
| 199 | |
| 200 | JSValueRef JSEventSendingController::mouseScrollBy(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 201 | { |
| 202 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 203 | if (!impl) |
| 204 | return JSValueMakeUndefined(context); |
| 205 | |
| 206 | double x = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 207 | double y = argumentCount > 1 ? JSValueToNumber(context, arguments[1], nullptr) : 0; |
| 208 | impl->mouseScrollBy(x, y); |
| 209 | |
| 210 | return JSValueMakeUndefined(context); |
| 211 | } |
| 212 | |
| 213 | JSValueRef JSEventSendingController::mouseScrollByWithWheelAndMomentumPhases(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 214 | { |
| 215 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 216 | if (!impl) |
| 217 | return JSValueMakeUndefined(context); |
| 218 | |
| 219 | double x = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 220 | double y = argumentCount > 1 ? JSValueToNumber(context, arguments[1], nullptr) : 0; |
| 221 | JSRetainPtr<JSStringRef> phase = argumentCount > 2 ? adopt(JSValueToStringCopy(context, arguments[2], nullptr)) : JSRetainPtr<JSStringRef>(); |
| 222 | JSRetainPtr<JSStringRef> momentum = argumentCount > 3 ? adopt(JSValueToStringCopy(context, arguments[3], nullptr)) : JSRetainPtr<JSStringRef>(); |
| 223 | impl->mouseScrollByWithWheelAndMomentumPhases(x, y, phase.get(), momentum.get()); |
| 224 | |
| 225 | return JSValueMakeUndefined(context); |
| 226 | } |
| 227 | |
| 228 | JSValueRef JSEventSendingController::continuousMouseScrollBy(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 229 | { |
| 230 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 231 | if (!impl) |
| 232 | return JSValueMakeUndefined(context); |
| 233 | |
| 234 | double x = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 235 | double y = argumentCount > 1 ? JSValueToNumber(context, arguments[1], nullptr) : 0; |
| 236 | bool paged = argumentCount > 2 && JSValueToBoolean(context, arguments[2]); |
| 237 | impl->continuousMouseScrollBy(x, y, paged); |
| 238 | |
| 239 | return JSValueMakeUndefined(context); |
| 240 | } |
| 241 | |
| 242 | JSValueRef JSEventSendingController::contextClick(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 243 | { |
| 244 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 245 | if (!impl) |
| 246 | return JSValueMakeUndefined(context); |
| 247 | |
| 248 | return impl->contextClick(); |
| 249 | } |
| 250 | |
| 251 | JSValueRef JSEventSendingController::scheduleAsynchronousClick(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 252 | { |
| 253 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 254 | if (!impl) |
| 255 | return JSValueMakeUndefined(context); |
| 256 | |
| 257 | impl->scheduleAsynchronousClick(); |
| 258 | |
| 259 | return JSValueMakeUndefined(context); |
| 260 | } |
| 261 | |
| 262 | JSValueRef JSEventSendingController::leapForward(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 263 | { |
| 264 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 265 | if (!impl) |
| 266 | return JSValueMakeUndefined(context); |
| 267 | |
| 268 | double milliseconds = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 269 | impl->leapForward(milliseconds); |
| 270 | |
| 271 | return JSValueMakeUndefined(context); |
| 272 | } |
| 273 | |
| 274 | JSValueRef JSEventSendingController::keyDown(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 275 | { |
| 276 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 277 | if (!impl) |
| 278 | return JSValueMakeUndefined(context); |
| 279 | |
| 280 | JSRetainPtr<JSStringRef> key = argumentCount > 0 ? adopt(JSValueToStringCopy(context, arguments[0], nullptr)) : JSRetainPtr<JSStringRef>(); |
| 281 | JSValueRef modifierArray = argumentCount > 1 ? arguments[1] : JSValueMakeUndefined(context); |
| 282 | double location = argumentCount > 2 ? JSValueToNumber(context, arguments[2], nullptr) : 0; |
| 283 | impl->keyDown(key.get(), modifierArray, location); |
| 284 | |
| 285 | return JSValueMakeUndefined(context); |
| 286 | } |
| 287 | |
| 288 | JSValueRef JSEventSendingController::scheduleAsynchronousKeyDown(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 289 | { |
| 290 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 291 | if (!impl) |
| 292 | return JSValueMakeUndefined(context); |
| 293 | |
| 294 | JSRetainPtr<JSStringRef> key = argumentCount > 0 ? adopt(JSValueToStringCopy(context, arguments[0], nullptr)) : JSRetainPtr<JSStringRef>(); |
| 295 | impl->scheduleAsynchronousKeyDown(key.get()); |
| 296 | |
| 297 | return JSValueMakeUndefined(context); |
| 298 | } |
| 299 | |
| 300 | JSValueRef JSEventSendingController::textZoomIn(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 301 | { |
| 302 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 303 | if (!impl) |
| 304 | return JSValueMakeUndefined(context); |
| 305 | |
| 306 | impl->textZoomIn(); |
| 307 | |
| 308 | return JSValueMakeUndefined(context); |
| 309 | } |
| 310 | |
| 311 | JSValueRef JSEventSendingController::textZoomOut(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 312 | { |
| 313 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 314 | if (!impl) |
| 315 | return JSValueMakeUndefined(context); |
| 316 | |
| 317 | impl->textZoomOut(); |
| 318 | |
| 319 | return JSValueMakeUndefined(context); |
| 320 | } |
| 321 | |
| 322 | JSValueRef JSEventSendingController::zoomPageIn(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 323 | { |
| 324 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 325 | if (!impl) |
| 326 | return JSValueMakeUndefined(context); |
| 327 | |
| 328 | impl->zoomPageIn(); |
| 329 | |
| 330 | return JSValueMakeUndefined(context); |
| 331 | } |
| 332 | |
| 333 | JSValueRef JSEventSendingController::zoomPageOut(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 334 | { |
| 335 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 336 | if (!impl) |
| 337 | return JSValueMakeUndefined(context); |
| 338 | |
| 339 | impl->zoomPageOut(); |
| 340 | |
| 341 | return JSValueMakeUndefined(context); |
| 342 | } |
| 343 | |
| 344 | JSValueRef JSEventSendingController::scalePageBy(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 345 | { |
| 346 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 347 | if (!impl) |
| 348 | return JSValueMakeUndefined(context); |
| 349 | |
| 350 | double scale = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 351 | double x = argumentCount > 1 ? JSValueToNumber(context, arguments[1], nullptr) : 0; |
| 352 | double y = argumentCount > 2 ? JSValueToNumber(context, arguments[2], nullptr) : 0; |
| 353 | impl->scalePageBy(scale, x, y); |
| 354 | |
| 355 | return JSValueMakeUndefined(context); |
| 356 | } |
| 357 | |
| 358 | JSValueRef JSEventSendingController::monitorWheelEvents(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 359 | { |
| 360 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 361 | if (!impl) |
| 362 | return JSValueMakeUndefined(context); |
| 363 | |
| 364 | impl->monitorWheelEvents(); |
| 365 | |
| 366 | return JSValueMakeUndefined(context); |
| 367 | } |
| 368 | |
| 369 | JSValueRef JSEventSendingController::callAfterScrollingCompletes(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 370 | { |
| 371 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 372 | if (!impl) |
| 373 | return JSValueMakeUndefined(context); |
| 374 | |
| 375 | JSValueRef functionCallback = argumentCount > 0 ? arguments[0] : JSValueMakeUndefined(context); |
| 376 | impl->callAfterScrollingCompletes(functionCallback); |
| 377 | |
| 378 | return JSValueMakeUndefined(context); |
| 379 | } |
| 380 | |
| 381 | JSValueRef JSEventSendingController::addTouchPoint(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 382 | { |
| 383 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 384 | if (!impl) |
| 385 | return JSValueMakeUndefined(context); |
| 386 | |
| 387 | double x = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 388 | double y = argumentCount > 1 ? JSValueToNumber(context, arguments[1], nullptr) : 0; |
| 389 | impl->addTouchPoint(x, y); |
| 390 | |
| 391 | return JSValueMakeUndefined(context); |
| 392 | } |
| 393 | |
| 394 | JSValueRef JSEventSendingController::updateTouchPoint(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 395 | { |
| 396 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 397 | if (!impl) |
| 398 | return JSValueMakeUndefined(context); |
| 399 | |
| 400 | double index = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 401 | double x = argumentCount > 1 ? JSValueToNumber(context, arguments[1], nullptr) : 0; |
| 402 | double y = argumentCount > 2 ? JSValueToNumber(context, arguments[2], nullptr) : 0; |
| 403 | impl->updateTouchPoint(index, x, y); |
| 404 | |
| 405 | return JSValueMakeUndefined(context); |
| 406 | } |
| 407 | |
| 408 | JSValueRef JSEventSendingController::setTouchModifier(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 409 | { |
| 410 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 411 | if (!impl) |
| 412 | return JSValueMakeUndefined(context); |
| 413 | |
| 414 | JSRetainPtr<JSStringRef> modifier = argumentCount > 0 ? adopt(JSValueToStringCopy(context, arguments[0], nullptr)) : JSRetainPtr<JSStringRef>(); |
| 415 | bool enable = argumentCount > 1 && JSValueToBoolean(context, arguments[1]); |
| 416 | impl->setTouchModifier(modifier.get(), enable); |
| 417 | |
| 418 | return JSValueMakeUndefined(context); |
| 419 | } |
| 420 | |
| 421 | JSValueRef JSEventSendingController::setTouchPointRadius(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 422 | { |
| 423 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 424 | if (!impl) |
| 425 | return JSValueMakeUndefined(context); |
| 426 | |
| 427 | double radiusX = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 428 | double radiusY = argumentCount > 1 ? JSValueToNumber(context, arguments[1], nullptr) : 0; |
| 429 | impl->setTouchPointRadius(radiusX, radiusY); |
| 430 | |
| 431 | return JSValueMakeUndefined(context); |
| 432 | } |
| 433 | |
| 434 | JSValueRef JSEventSendingController::touchStart(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 435 | { |
| 436 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 437 | if (!impl) |
| 438 | return JSValueMakeUndefined(context); |
| 439 | |
| 440 | impl->touchStart(); |
| 441 | |
| 442 | return JSValueMakeUndefined(context); |
| 443 | } |
| 444 | |
| 445 | JSValueRef JSEventSendingController::touchMove(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 446 | { |
| 447 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 448 | if (!impl) |
| 449 | return JSValueMakeUndefined(context); |
| 450 | |
| 451 | impl->touchMove(); |
| 452 | |
| 453 | return JSValueMakeUndefined(context); |
| 454 | } |
| 455 | |
| 456 | JSValueRef JSEventSendingController::touchEnd(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 457 | { |
| 458 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 459 | if (!impl) |
| 460 | return JSValueMakeUndefined(context); |
| 461 | |
| 462 | impl->touchEnd(); |
| 463 | |
| 464 | return JSValueMakeUndefined(context); |
| 465 | } |
| 466 | |
| 467 | JSValueRef JSEventSendingController::touchCancel(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 468 | { |
| 469 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 470 | if (!impl) |
| 471 | return JSValueMakeUndefined(context); |
| 472 | |
| 473 | impl->touchCancel(); |
| 474 | |
| 475 | return JSValueMakeUndefined(context); |
| 476 | } |
| 477 | |
| 478 | JSValueRef JSEventSendingController::clearTouchPoints(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 479 | { |
| 480 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 481 | if (!impl) |
| 482 | return JSValueMakeUndefined(context); |
| 483 | |
| 484 | impl->clearTouchPoints(); |
| 485 | |
| 486 | return JSValueMakeUndefined(context); |
| 487 | } |
| 488 | |
| 489 | JSValueRef JSEventSendingController::releaseTouchPoint(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 490 | { |
| 491 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 492 | if (!impl) |
| 493 | return JSValueMakeUndefined(context); |
| 494 | |
| 495 | double index = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 496 | impl->releaseTouchPoint(index); |
| 497 | |
| 498 | return JSValueMakeUndefined(context); |
| 499 | } |
| 500 | |
| 501 | JSValueRef JSEventSendingController::cancelTouchPoint(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) |
| 502 | { |
| 503 | EventSendingController* impl = toEventSendingController(context, thisObject); |
| 504 | if (!impl) |
| 505 | return JSValueMakeUndefined(context); |
| 506 | |
| 507 | double index = argumentCount > 0 ? JSValueToNumber(context, arguments[0], nullptr) : 0; |
| 508 | impl->cancelTouchPoint(index); |
| 509 | |
| 510 | return JSValueMakeUndefined(context); |
| 511 | } |
| 512 | |
| 513 | } // namespace WTR |
| 514 | |
| 515 | |