[Qt][WK2] Convert touch-point area
[WebKit-https.git] / Tools / WebKitTestRunner / InjectedBundle / EventSendingController.cpp
1 /*
2  * Copyright (C) 2010, 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. 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
26 #include "config.h"
27 #include "EventSendingController.h"
28
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>
39
40 namespace WTR {
41
42 static const float ZoomMultiplierRatio = 1.2f;
43
44 static WKEventModifiers parseModifier(JSStringRef modifier)
45 {
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;
54     return 0;
55 }
56
57 static unsigned arrayLength(JSContextRef context, JSObjectRef array)
58 {
59     JSRetainPtr<JSStringRef> lengthString(Adopt, JSStringCreateWithUTF8CString("length"));
60     JSValueRef lengthValue = JSObjectGetProperty(context, array, lengthString.get(), 0);
61     if (!lengthValue)
62         return 0;
63     return static_cast<unsigned>(JSValueToNumber(context, lengthValue, 0));
64 }
65
66 static WKEventModifiers parseModifierArray(JSContextRef context, JSValueRef arrayValue)
67 {
68     if (!arrayValue)
69         return 0;
70     if (!JSValueIsObject(context, arrayValue))
71         return 0;
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);
78         if (exception)
79             continue;
80         JSRetainPtr<JSStringRef> string(Adopt, JSValueToStringCopy(context, value, &exception));
81         if (exception)
82             continue;
83         modifiers |= parseModifier(string.get());
84     }
85     return modifiers;
86 }
87
88 PassRefPtr<EventSendingController> EventSendingController::create()
89 {
90     return adoptRef(new EventSendingController);
91 }
92
93 EventSendingController::EventSendingController()
94 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
95     : m_time(0)
96     , m_position()
97     , m_clickCount(0)
98     , m_clickTime(0)
99     , m_clickPosition()
100     , m_clickButton(kWKEventMouseButtonNoButton)
101 #endif
102 {
103 }
104
105 EventSendingController::~EventSendingController()
106 {
107 }
108
109 JSClassRef EventSendingController::wrapperClass()
110 {
111     return JSEventSendingController::eventSendingControllerClass();
112 }
113
114 void EventSendingController::mouseDown(int button, JSValueRef modifierArray) 
115 {
116     WKBundlePageRef page = InjectedBundle::shared().page()->page();
117     WKBundleFrameRef frame = WKBundlePageGetMainFrame(page);
118     JSContextRef context = WKBundleFrameGetJavaScriptContext(frame);
119     WKEventModifiers modifiers = parseModifierArray(context, modifierArray);
120
121 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
122     updateClickCount(button);
123     WKBundlePageSimulateMouseDown(page, button, m_position, m_clickCount, modifiers, m_time);
124 #else
125     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
126     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
127
128     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
129     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseDown"));
130     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
131
132     WKRetainPtr<WKStringRef> buttonKey = adoptWK(WKStringCreateWithUTF8CString("Button"));
133     WKRetainPtr<WKUInt64Ref> buttonRef = adoptWK(WKUInt64Create(button));
134     WKDictionaryAddItem(EventSenderMessageBody.get(), buttonKey.get(), buttonRef.get());
135
136     WKRetainPtr<WKStringRef> modifiersKey = adoptWK(WKStringCreateWithUTF8CString("Modifiers"));
137     WKRetainPtr<WKUInt64Ref> modifiersRef = adoptWK(WKUInt64Create(modifiers));
138     WKDictionaryAddItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get());
139
140     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
141 #endif
142 }
143
144 void EventSendingController::mouseUp(int button, JSValueRef modifierArray)
145 {
146     WKBundlePageRef page = InjectedBundle::shared().page()->page();
147     WKBundleFrameRef frame = WKBundlePageGetMainFrame(page);
148     JSContextRef context = WKBundleFrameGetJavaScriptContext(frame);
149     WKEventModifiers modifiers = parseModifierArray(context, modifierArray);
150
151 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
152     updateClickCount(button);
153     WKBundlePageSimulateMouseUp(page, button, m_position, m_clickCount, modifiers, m_time);
154 #else
155     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
156     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
157
158     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
159     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseUp"));
160     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
161
162     WKRetainPtr<WKStringRef> buttonKey(AdoptWK, WKStringCreateWithUTF8CString("Button"));
163     WKRetainPtr<WKUInt64Ref> buttonRef(AdoptWK, WKUInt64Create(button));
164     WKDictionaryAddItem(EventSenderMessageBody.get(), buttonKey.get(), buttonRef.get());
165
166     WKRetainPtr<WKStringRef> modifiersKey(AdoptWK, WKStringCreateWithUTF8CString("Modifiers"));
167     WKRetainPtr<WKUInt64Ref> modifiersRef(AdoptWK, WKUInt64Create(modifiers));
168     WKDictionaryAddItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get());
169
170     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
171 #endif
172 }
173
174 void EventSendingController::mouseMoveTo(int x, int y)
175 {
176 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
177     m_position.x = x;
178     m_position.y = y;
179     WKBundlePageSimulateMouseMotion(InjectedBundle::shared().page()->page(), m_position, m_time);
180 #else
181     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
182     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
183
184     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
185     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseMoveTo"));
186     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
187
188     WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("X"));
189     WKRetainPtr<WKDoubleRef> xRef(AdoptWK, WKDoubleCreate(x));
190     WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
191
192     WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("Y"));
193     WKRetainPtr<WKDoubleRef> yRef(AdoptWK, WKDoubleCreate(y));
194     WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
195
196     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
197 #endif
198 }
199
200 void EventSendingController::leapForward(int milliseconds)
201 {
202 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
203     m_time += milliseconds / 1000.0;
204 #else
205     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
206     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
207
208     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
209     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("LeapForward"));
210     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
211
212     WKRetainPtr<WKStringRef> timeKey(AdoptWK, WKStringCreateWithUTF8CString("TimeInMilliseconds"));
213     WKRetainPtr<WKUInt64Ref> timeRef(AdoptWK, WKUInt64Create(milliseconds));
214     WKDictionaryAddItem(EventSenderMessageBody.get(), timeKey.get(), timeRef.get());
215
216     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
217 #endif
218 }
219
220 void EventSendingController::keyDown(JSStringRef key, JSValueRef modifierArray, int location)
221 {
222     WKBundlePageRef page = InjectedBundle::shared().page()->page();
223     WKBundleFrameRef frame = WKBundlePageGetMainFrame(page);
224     JSContextRef context = WKBundleFrameGetJavaScriptContext(frame);
225     WKEventModifiers modifiers = parseModifierArray(context, modifierArray);
226
227     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
228     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
229
230     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
231     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("KeyDown"));
232     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
233
234     WKRetainPtr<WKStringRef> keyKey(AdoptWK, WKStringCreateWithUTF8CString("Key"));
235     WKDictionaryAddItem(EventSenderMessageBody.get(), keyKey.get(), toWK(key).get());
236
237     WKRetainPtr<WKStringRef> modifiersKey(AdoptWK, WKStringCreateWithUTF8CString("Modifiers"));
238     WKRetainPtr<WKUInt64Ref> modifiersRef(AdoptWK, WKUInt64Create(modifiers));
239     WKDictionaryAddItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get());
240
241     WKRetainPtr<WKStringRef> locationKey(AdoptWK, WKStringCreateWithUTF8CString("Location"));
242     WKRetainPtr<WKUInt64Ref> locationRef(AdoptWK, WKUInt64Create(location));
243     WKDictionaryAddItem(EventSenderMessageBody.get(), locationKey.get(), locationRef.get());
244
245     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
246 }
247
248 void EventSendingController::mouseScrollBy(int x, int y)
249 {
250     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
251     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
252
253     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
254     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseScrollBy"));
255     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
256
257     WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("X"));
258     WKRetainPtr<WKDoubleRef> xRef(AdoptWK, WKDoubleCreate(x));
259     WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
260
261     WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("Y"));
262     WKRetainPtr<WKDoubleRef> yRef(AdoptWK, WKDoubleCreate(y));
263     WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
264
265     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
266 }
267
268 #ifdef USE_WEBPROCESS_EVENT_SIMULATION
269 void EventSendingController::updateClickCount(WKEventMouseButton button)
270 {
271     if (m_time - m_clickTime < 1 && m_position == m_clickPosition && button == m_clickButton) {
272         ++m_clickCount;
273         m_clickTime = m_time;
274         return;
275     }
276
277     m_clickCount = 1;
278     m_clickTime = m_time;
279     m_clickPosition = m_position;
280     m_clickButton = button;
281 }
282 #endif
283
284 void EventSendingController::textZoomIn()
285 {
286     // Ensure page zoom is reset.
287     WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), 1);
288
289     double zoomFactor = WKBundlePageGetTextZoomFactor(InjectedBundle::shared().page()->page());
290     WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor * ZoomMultiplierRatio);
291 }
292
293 void EventSendingController::textZoomOut()
294 {
295     // Ensure page zoom is reset.
296     WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), 1);
297
298     double zoomFactor = WKBundlePageGetTextZoomFactor(InjectedBundle::shared().page()->page());
299     WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor / ZoomMultiplierRatio);
300 }
301
302 void EventSendingController::zoomPageIn()
303 {
304     // Ensure text zoom is reset.
305     WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), 1);
306
307     double zoomFactor = WKBundlePageGetPageZoomFactor(InjectedBundle::shared().page()->page());
308     WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor * ZoomMultiplierRatio);
309 }
310
311 void EventSendingController::zoomPageOut()
312 {
313     // Ensure text zoom is reset.
314     WKBundlePageSetTextZoomFactor(InjectedBundle::shared().page()->page(), 1);
315
316     double zoomFactor = WKBundlePageGetPageZoomFactor(InjectedBundle::shared().page()->page());
317     WKBundlePageSetPageZoomFactor(InjectedBundle::shared().page()->page(), zoomFactor / ZoomMultiplierRatio);
318 }
319
320 void EventSendingController::scalePageBy(double scale, double x, double y)
321 {
322     WKPoint origin = { x, y };
323     WKBundlePageSetScaleAtOrigin(InjectedBundle::shared().page()->page(), scale, origin);
324 }
325
326 #if ENABLE(TOUCH_EVENTS)
327 void EventSendingController::addTouchPoint(int x, int y)
328 {
329     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
330     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
331
332     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
333     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("AddTouchPoint"));
334     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
335
336     WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("X"));
337     WKRetainPtr<WKUInt64Ref> xRef(AdoptWK, WKUInt64Create(x));
338     WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
339
340     WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("Y"));
341     WKRetainPtr<WKUInt64Ref> yRef(AdoptWK, WKUInt64Create(y));
342     WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
343
344     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
345 }
346
347 void EventSendingController::updateTouchPoint(int index, int x, int y)
348 {
349     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
350     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
351
352     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
353     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("UpdateTouchPoint"));
354     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
355
356     WKRetainPtr<WKStringRef> indexKey(AdoptWK, WKStringCreateWithUTF8CString("Index"));
357     WKRetainPtr<WKUInt64Ref> indexRef(AdoptWK, WKUInt64Create(index));
358     WKDictionaryAddItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get());
359
360     WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("X"));
361     WKRetainPtr<WKUInt64Ref> xRef(AdoptWK, WKUInt64Create(x));
362     WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
363
364     WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("Y"));
365     WKRetainPtr<WKUInt64Ref> yRef(AdoptWK, WKUInt64Create(y));
366     WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
367
368     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
369 }
370
371 void EventSendingController::setTouchModifier(const JSStringRef &modifier, bool enable)
372 {
373     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
374     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
375
376     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
377     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("SetTouchModifier"));
378     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
379
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;
389
390     WKRetainPtr<WKStringRef> modifierKey(AdoptWK, WKStringCreateWithUTF8CString("Modifier"));
391     WKRetainPtr<WKUInt64Ref> modifierRef(AdoptWK, WKUInt64Create(mod));
392     WKDictionaryAddItem(EventSenderMessageBody.get(), modifierKey.get(), modifierRef.get());
393
394     WKRetainPtr<WKStringRef> enableKey(AdoptWK, WKStringCreateWithUTF8CString("Enable"));
395     WKRetainPtr<WKUInt64Ref> enableRef(AdoptWK, WKUInt64Create(enable));
396     WKDictionaryAddItem(EventSenderMessageBody.get(), enableKey.get(), enableRef.get());
397
398     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
399 }
400
401
402 void EventSendingController::setTouchPointRadius(int radiusX, int radiusY)
403 {
404     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
405     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
406
407     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
408     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("SetTouchPointRadius"));
409     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
410
411     WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("RadiusX"));
412     WKRetainPtr<WKUInt64Ref> xRef(AdoptWK, WKUInt64Create(radiusX));
413     WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());
414
415     WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("RadiusY"));
416     WKRetainPtr<WKUInt64Ref> yRef(AdoptWK, WKUInt64Create(radiusY));
417     WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());
418
419     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
420 }
421
422 void EventSendingController::touchStart()
423 {
424     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
425     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
426
427     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
428     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("TouchStart"));
429     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
430
431     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
432 }
433
434 void EventSendingController::touchMove()
435 {
436     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
437     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
438
439     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
440     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("TouchMove"));
441     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
442
443     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
444 }
445
446 void EventSendingController::touchEnd()
447 {
448     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
449     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
450
451     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
452     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("TouchEnd"));
453     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
454
455     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
456 }
457
458 void EventSendingController::touchCancel()
459 {
460     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
461     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
462
463     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
464     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("TouchCancel"));
465     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
466
467     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
468 }
469
470 void EventSendingController::clearTouchPoints()
471 {
472     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
473     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
474
475     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
476     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("ClearTouchPoints"));
477     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
478
479     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
480 }
481
482 void EventSendingController::releaseTouchPoint(int index)
483 {
484     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
485     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
486
487     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
488     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("ReleaseTouchPoint"));
489     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
490
491     WKRetainPtr<WKStringRef> indexKey(AdoptWK, WKStringCreateWithUTF8CString("Index"));
492     WKRetainPtr<WKUInt64Ref> indexRef(AdoptWK, WKUInt64Create(index));
493     WKDictionaryAddItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get());
494
495     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
496 }
497
498 void EventSendingController::cancelTouchPoint(int index)
499 {
500     WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
501     WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());
502
503     WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
504     WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("CancelTouchPoint"));
505     WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());
506
507     WKRetainPtr<WKStringRef> indexKey(AdoptWK, WKStringCreateWithUTF8CString("Index"));
508     WKRetainPtr<WKUInt64Ref> indexRef(AdoptWK, WKUInt64Create(index));
509     WKDictionaryAddItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get());
510
511     WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
512 }
513 #endif
514
515 // Object Creation
516
517 void EventSendingController::makeWindowObject(JSContextRef context, JSObjectRef windowObject, JSValueRef* exception)
518 {
519     setProperty(context, windowObject, "eventSender", this, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, exception);
520 }
521
522 } // namespace WTR