2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "EventSendingController.h"
29 #include "InjectedBundle.h"
30 #include "InjectedBundlePage.h"
31 #include "JSEventSendingController.h"
32 #include "StringFunctions.h"
33 #include <WebKit2/WKBundle.h>
34 #include <WebKit2/WKBundleFrame.h>
35 #include <WebKit2/WKBundlePagePrivate.h>
36 #include <WebKit2/WKBundlePrivate.h>
37 #include <WebKit2/WKMutableDictionary.h>
38 #include <WebKit2/WKNumber.h>
42 static const float ZoomMultiplierRatio = 1.2f;
44 static WKEventModifiers parseModifier(JSStringRef modifier)
46 if (JSStringIsEqualToUTF8CString(modifier, "ctrlKey"))
47 return kWKEventModifiersControlKey;
48 if (JSStringIsEqualToUTF8CString(modifier, "shiftKey") || JSStringIsEqualToUTF8CString(modifier, "rangeSelectionKey"))
49 return kWKEventModifiersShiftKey;
50 if (JSStringIsEqualToUTF8CString(modifier, "altKey"))
51 return kWKEventModifiersAltKey;
52 if (JSStringIsEqualToUTF8CString(modifier, "metaKey") || JSStringIsEqualToUTF8CString(modifier, "addSelectionKey"))
53 return kWKEventModifiersMetaKey;
57 static unsigned arrayLength(JSContextRef context, JSObjectRef array)
59 JSRetainPtr<JSStringRef> lengthString(Adopt, JSStringCreateWithUTF8CString("length"));
60 JSValueRef lengthValue = JSObjectGetProperty(context, array, lengthString.get(), 0);
63 return static_cast<unsigned>(JSValueToNumber(context, lengthValue, 0));
66 static WKEventModifiers parseModifierArray(JSContextRef context, JSValueRef arrayValue)
70 if (!JSValueIsObject(context, arrayValue))
72 JSObjectRef array = const_cast<JSObjectRef>(arrayValue);
73 unsigned length = arrayLength(context, array);
74 WKEventModifiers modifiers = 0;
75 for (unsigned i = 0; i < length; i++) {
76 JSValueRef exception = 0;
77 JSValueRef value = JSObjectGetPropertyAtIndex(context, array, i, &exception);
80 JSRetainPtr<JSStringRef> string(Adopt, JSValueToStringCopy(context, value, &exception));
83 modifiers |= parseModifier(string.get());
88 PassRefPtr<EventSendingController> EventSendingController::create()
90 return adoptRef(new EventSendingController);
93 EventSendingController::EventSendingController()
94 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
100 , m_clickButton(kWKEventMouseButtonNoButton)
105 EventSendingController::~EventSendingController()
109 JSClassRef EventSendingController::wrapperClass()
111 return JSEventSendingController::eventSendingControllerClass();
114 void EventSendingController::mouseDown(int button, JSValueRef modifierArray)
116 WKBundlePageRef page = InjectedBundle::shared().page()->page();
117 WKBundleFrameRef frame = WKBundlePageGetMainFrame(page);
118 JSContextRef context = WKBundleFrameGetJavaScriptContext(frame);
119 WKEventModifiers modifiers = parseModifierArray(context, modifierArray);
121 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
122 updateClickCount(button);
123 WKBundlePageSimulateMouseDown(page, button, m_position, m_clickCount, modifiers, m_time);
125 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
126 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
128 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
129 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseDown"));
130 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
132 WKRetainPtr<WKStringRef> buttonKey = adoptWK(WKStringCreateWithUTF8CString("Button"));
133 WKRetainPtr<WKUInt64Ref> buttonRef = adoptWK(WKUInt64Create(button));
134 WKDictionaryAddItem(EventSenderMessageBody.get(), buttonKey.get(), buttonRef.get());
136 WKRetainPtr<WKStringRef> modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers"));
137 WKRetainPtr<WKUInt64Ref> modifiersRef = adoptWK(WKUInt64Create(modifiers));
138 WKDictionaryAddItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get());
140 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
144 void EventSendingController::mouseUp(int button, JSValueRef modifierArray)
146 WKBundlePageRef page = InjectedBundle::shared().page()->page();
147 WKBundleFrameRef frame = WKBundlePageGetMainFrame(page);
148 JSContextRef context = WKBundleFrameGetJavaScriptContext(frame);
149 WKEventModifiers modifiers = parseModifierArray(context, modifierArray);
151 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
152 updateClickCount(button);
153 WKBundlePageSimulateMouseUp(page, button, m_position, m_clickCount, modifiers, m_time);
155 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
156 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
158 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
159 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseUp"));
160 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
162 WKRetainPtr<WKStringRef> buttonKey(AdoptWK, WKStringCreateWithUTF8CString("Button"));
163 WKRetainPtr<WKUInt64Ref> buttonRef(AdoptWK, WKUInt64Create(button));
164 WKDictionaryAddItem(EventSenderMessageBody.get(), buttonKey.get(), buttonRef.get());
166 WKRetainPtr<WKStringRef> modifiersKey(AdoptWK, WKStringCreateWithUTF8CString("Modifiers"));
167 WKRetainPtr<WKUInt64Ref> modifiersRef(AdoptWK, WKUInt64Create(modifiers));
168 WKDictionaryAddItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get());
170 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
174 void EventSendingController::mouseMoveTo(int x, int y)
176 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
179 WKBundlePageSimulateMouseMotion(InjectedBundle::shared().page()->page(), m_position, m_time);
181 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
182 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
184 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
185 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseMoveTo"));
186 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
188 WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("X"));
189 WKRetainPtr<WKDoubleRef> xRef(AdoptWK, WKDoubleCreate(x));
190 WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
192 WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("Y"));
193 WKRetainPtr<WKDoubleRef> yRef(AdoptWK, WKDoubleCreate(y));
194 WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
196 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
200 void EventSendingController::leapForward(int milliseconds)
202 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
203 m_time += milliseconds / 1000.0;
205 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
206 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
208 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
209 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("LeapForward"));
210 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
212 WKRetainPtr<WKStringRef> timeKey(AdoptWK, WKStringCreateWithUTF8CString("TimeInMilliseconds"));
213 WKRetainPtr<WKUInt64Ref> timeRef(AdoptWK, WKUInt64Create(milliseconds));
214 WKDictionaryAddItem(EventSenderMessageBody.get(), timeKey.get(), timeRef.get());
216 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
220 void EventSendingController::keyDown(JSStringRef key, JSValueRef modifierArray, int location)
222 WKBundlePageRef page = InjectedBundle::shared().page()->page();
223 WKBundleFrameRef frame = WKBundlePageGetMainFrame(page);
224 JSContextRef context = WKBundleFrameGetJavaScriptContext(frame);
225 WKEventModifiers modifiers = parseModifierArray(context, modifierArray);
227 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
228 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
230 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
231 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("KeyDown"));
232 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
234 WKRetainPtr<WKStringRef> keyKey(AdoptWK, WKStringCreateWithUTF8CString("Key"));
235 WKDictionaryAddItem(EventSenderMessageBody.get(), keyKey.get(), toWK(key).get());
237 WKRetainPtr<WKStringRef> modifiersKey(AdoptWK, WKStringCreateWithUTF8CString("Modifiers"));
238 WKRetainPtr<WKUInt64Ref> modifiersRef(AdoptWK, WKUInt64Create(modifiers));
239 WKDictionaryAddItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get());
241 WKRetainPtr<WKStringRef> locationKey(AdoptWK, WKStringCreateWithUTF8CString("Location"));
242 WKRetainPtr<WKUInt64Ref> locationRef(AdoptWK, WKUInt64Create(location));
243 WKDictionaryAddItem(EventSenderMessageBody.get(), locationKey.get(), locationRef.get());
245 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
248 void EventSendingController::mouseScrollBy(int x, int y)
250 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
251 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
253 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
254 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseScrollBy"));
255 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
257 WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("X"));
258 WKRetainPtr<WKDoubleRef> xRef(AdoptWK, WKDoubleCreate(x));
259 WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
261 WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("Y"));
262 WKRetainPtr<WKDoubleRef> yRef(AdoptWK, WKDoubleCreate(y));
263 WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
265 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
268 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
269 void EventSendingController::updateClickCount(WKEventMouseButton button)
271 if (m_time - m_clickTime < 1 && m_position == m_clickPosition && button == m_clickButton) {
273 m_clickTime = m_time;
278 m_clickTime = m_time;
279 m_clickPosition = m_position;
280 m_clickButton = button;
284 void EventSendingController::textZoomIn()
286 // Ensure page zoom is reset.
287 WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), 1);
289 double zoomFactor = WKBundlePageGetTextZoomFactor(InjectedBundle::shared().page()->page());
290 WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor * ZoomMultiplierRatio);
293 void EventSendingController::textZoomOut()
295 // Ensure page zoom is reset.
296 WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), 1);
298 double zoomFactor = WKBundlePageGetTextZoomFactor(InjectedBundle::shared().page()->page());
299 WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor / ZoomMultiplierRatio);
302 void EventSendingController::zoomPageIn()
304 // Ensure text zoom is reset.
305 WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), 1);
307 double zoomFactor = WKBundlePageGetPageZoomFactor(InjectedBundle::shared().page()->page());
308 WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor * ZoomMultiplierRatio);
311 void EventSendingController::zoomPageOut()
313 // Ensure text zoom is reset.
314 WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), 1);
316 double zoomFactor = WKBundlePageGetPageZoomFactor(InjectedBundle::shared().page()->page());
317 WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor / ZoomMultiplierRatio);
320 void EventSendingController::scalePageBy(double scale, double x, double y)
322 WKPoint origin = { x, y };
323 WKBundlePageSetScaleAtOrigin(InjectedBundle::shared().page()->page(), scale, origin);
326 #if ENABLE(TOUCH_EVENTS)
327 void EventSendingController::addTouchPoint(int x, int y)
329 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
330 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
332 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
333 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("AddTouchPoint"));
334 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
336 WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("X"));
337 WKRetainPtr<WKUInt64Ref> xRef(AdoptWK, WKUInt64Create(x));
338 WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
340 WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("Y"));
341 WKRetainPtr<WKUInt64Ref> yRef(AdoptWK, WKUInt64Create(y));
342 WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
344 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
347 void EventSendingController::updateTouchPoint(int index, int x, int y)
349 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
350 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
352 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
353 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("UpdateTouchPoint"));
354 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
356 WKRetainPtr<WKStringRef> indexKey(AdoptWK, WKStringCreateWithUTF8CString("Index"));
357 WKRetainPtr<WKUInt64Ref> indexRef(AdoptWK, WKUInt64Create(index));
358 WKDictionaryAddItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get());
360 WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("X"));
361 WKRetainPtr<WKUInt64Ref> xRef(AdoptWK, WKUInt64Create(x));
362 WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
364 WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("Y"));
365 WKRetainPtr<WKUInt64Ref> yRef(AdoptWK, WKUInt64Create(y));
366 WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
368 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
371 void EventSendingController::setTouchModifier(const JSStringRef &modifier, bool enable)
373 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
374 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
376 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
377 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("SetTouchModifier"));
378 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
380 WKEventModifiers mod = 0;
381 if (JSStringIsEqualToUTF8CString(modifier, "ctrl"))
382 mod = kWKEventModifiersControlKey;
383 if (JSStringIsEqualToUTF8CString(modifier, "shift"))
384 mod = kWKEventModifiersShiftKey;
385 if (JSStringIsEqualToUTF8CString(modifier, "alt"))
386 mod = kWKEventModifiersAltKey;
387 if (JSStringIsEqualToUTF8CString(modifier, "meta"))
388 mod = kWKEventModifiersMetaKey;
390 WKRetainPtr<WKStringRef> modifierKey(AdoptWK, WKStringCreateWithUTF8CString("Modifier"));
391 WKRetainPtr<WKUInt64Ref> modifierRef(AdoptWK, WKUInt64Create(mod));
392 WKDictionaryAddItem(EventSenderMessageBody.get(), modifierKey.get(), modifierRef.get());
394 WKRetainPtr<WKStringRef> enableKey(AdoptWK, WKStringCreateWithUTF8CString("Enable"));
395 WKRetainPtr<WKUInt64Ref> enableRef(AdoptWK, WKUInt64Create(enable));
396 WKDictionaryAddItem(EventSenderMessageBody.get(), enableKey.get(), enableRef.get());
398 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
401 void EventSendingController::touchStart()
403 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
404 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
406 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
407 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("TouchStart"));
408 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
410 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
413 void EventSendingController::touchMove()
415 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
416 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
418 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
419 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("TouchMove"));
420 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
422 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
425 void EventSendingController::touchEnd()
427 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
428 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
430 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
431 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("TouchEnd"));
432 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
434 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
437 void EventSendingController::touchCancel()
439 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
440 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
442 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
443 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("TouchCancel"));
444 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
446 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
449 void EventSendingController::clearTouchPoints()
451 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
452 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
454 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
455 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("ClearTouchPoints"));
456 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
458 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
461 void EventSendingController::releaseTouchPoint(int index)
463 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
464 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
466 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
467 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("ReleaseTouchPoint"));
468 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
470 WKRetainPtr<WKStringRef> indexKey(AdoptWK, WKStringCreateWithUTF8CString("Index"));
471 WKRetainPtr<WKUInt64Ref> indexRef(AdoptWK, WKUInt64Create(index));
472 WKDictionaryAddItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get());
474 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
477 void EventSendingController::cancelTouchPoint(int index)
479 WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
480 WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
482 WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
483 WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("CancelTouchPoint"));
484 WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
486 WKRetainPtr<WKStringRef> indexKey(AdoptWK, WKStringCreateWithUTF8CString("Index"));
487 WKRetainPtr<WKUInt64Ref> indexRef(AdoptWK, WKUInt64Create(index));
488 WKDictionaryAddItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get());
490 WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
496 void EventSendingController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
498 setProperty(context, windowObject, "eventSender", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);