Ignore contiguous composition event.
[framework/web/webkit-efl.git] / Source / WebKit2 / Shared / WebEventConversion.cpp
1 /*
2  * Copyright (C) 2010 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 "WebEventConversion.h"
28
29 #include "WebEvent.h"
30
31 namespace WebKit {
32
33 class WebKit2PlatformMouseEvent : public WebCore::PlatformMouseEvent {
34 public:
35     WebKit2PlatformMouseEvent(const WebMouseEvent& webEvent)
36     {
37         // PlatformEvent
38         switch (webEvent.type()) {
39         case WebEvent::MouseDown:
40             m_type = WebCore::PlatformEvent::MousePressed;
41             break;
42         case WebEvent::MouseUp:
43             m_type = WebCore::PlatformEvent::MouseReleased;
44             break;
45         case WebEvent::MouseMove:
46             m_type = WebCore::PlatformEvent::MouseMoved;
47             break;
48         default:
49             ASSERT_NOT_REACHED();
50         }
51
52         m_modifiers = 0;
53         if (webEvent.shiftKey())
54             m_modifiers |= ShiftKey;
55         if (webEvent.controlKey())
56             m_modifiers |= CtrlKey;
57         if (webEvent.altKey())
58             m_modifiers |= AltKey;
59         if (webEvent.metaKey())
60             m_modifiers |= MetaKey;
61
62         m_timestamp = webEvent.timestamp();
63
64         // PlatformMouseEvent
65         switch (webEvent.button()) {
66         case WebMouseEvent::NoButton:
67             m_button = WebCore::NoButton;
68             break;
69         case WebMouseEvent::LeftButton:
70             m_button = WebCore::LeftButton;
71             break;
72         case WebMouseEvent::MiddleButton:
73             m_button = WebCore::MiddleButton;
74             break;
75         case WebMouseEvent::RightButton:
76             m_button = WebCore::RightButton;
77             break;
78         default:
79             ASSERT_NOT_REACHED();
80         }
81
82         m_position = webEvent.position();
83         m_globalPosition = webEvent.globalPosition();
84         m_clickCount = webEvent.clickCount();
85
86         m_modifierFlags = 0;
87         if (webEvent.shiftKey())
88             m_modifierFlags |= WebEvent::ShiftKey;
89         if (webEvent.controlKey())
90             m_modifierFlags |= WebEvent::ControlKey;
91         if (webEvent.altKey())
92             m_modifierFlags |= WebEvent::AltKey;
93         if (webEvent.metaKey())
94             m_modifierFlags |= WebEvent::MetaKey;
95
96 #if PLATFORM(WIN)
97         m_didActivateWebView = webEvent.didActivateWebView();
98 #endif
99     }
100 };
101
102 WebCore::PlatformMouseEvent platform(const WebMouseEvent& webEvent)
103 {
104     return WebKit2PlatformMouseEvent(webEvent);
105 }
106
107 class WebKit2PlatformWheelEvent : public WebCore::PlatformWheelEvent {
108 public:
109     WebKit2PlatformWheelEvent(const WebWheelEvent& webEvent)
110     {
111         // PlatformEvent
112         m_type = PlatformEvent::Wheel;
113
114         m_modifiers = 0;
115         if (webEvent.shiftKey())
116             m_modifiers |= ShiftKey;
117         if (webEvent.controlKey())
118             m_modifiers |= CtrlKey;
119         if (webEvent.altKey())
120             m_modifiers |= AltKey;
121         if (webEvent.metaKey())
122             m_modifiers |= MetaKey;
123
124         m_timestamp = webEvent.timestamp();
125
126         // PlatformWheelEvent
127         m_position = webEvent.position();
128         m_globalPosition = webEvent.globalPosition();
129         m_deltaX = webEvent.delta().width();
130         m_deltaY = webEvent.delta().height();
131         m_wheelTicksX = webEvent.wheelTicks().width();
132         m_wheelTicksY = webEvent.wheelTicks().height();
133         m_granularity = (webEvent.granularity() == WebWheelEvent::ScrollByPageWheelEvent) ? WebCore::ScrollByPageWheelEvent : WebCore::ScrollByPixelWheelEvent;
134         m_directionInvertedFromDevice = webEvent.directionInvertedFromDevice();
135 #if PLATFORM(MAC)
136         m_phase = static_cast<WebCore::PlatformWheelEventPhase>(webEvent.phase());
137         m_momentumPhase = static_cast<WebCore::PlatformWheelEventPhase>(webEvent.momentumPhase());
138         m_hasPreciseScrollingDeltas = webEvent.hasPreciseScrollingDeltas();
139         m_scrollCount = webEvent.scrollCount();
140         m_unacceleratedScrollingDeltaX = webEvent.unacceleratedScrollingDelta().width();
141         m_unacceleratedScrollingDeltaY = webEvent.unacceleratedScrollingDelta().height();
142 #endif
143     }
144 };
145
146 WebCore::PlatformWheelEvent platform(const WebWheelEvent& webEvent)
147 {
148     return WebKit2PlatformWheelEvent(webEvent);
149 }
150
151 class WebKit2PlatformKeyboardEvent : public WebCore::PlatformKeyboardEvent {
152 public:
153     WebKit2PlatformKeyboardEvent(const WebKeyboardEvent& webEvent)
154     {
155         // PlatformEvent
156         switch (webEvent.type()) {
157         case WebEvent::KeyDown:
158             m_type = WebCore::PlatformEvent::KeyDown;
159             break;
160         case WebEvent::KeyUp:
161             m_type = WebCore::PlatformEvent::KeyUp;
162             break;
163         case WebEvent::RawKeyDown:
164             m_type = WebCore::PlatformEvent::RawKeyDown;
165             break;
166         case WebEvent::Char:
167             m_type = WebCore::PlatformEvent::Char;
168             break;
169         default:
170             ASSERT_NOT_REACHED();
171         }
172
173         m_modifiers = 0;
174         if (webEvent.shiftKey())
175             m_modifiers |= ShiftKey;
176         if (webEvent.controlKey())
177             m_modifiers |= CtrlKey;
178         if (webEvent.altKey())
179             m_modifiers |= AltKey;
180         if (webEvent.metaKey())
181             m_modifiers |= MetaKey;
182
183         m_timestamp = webEvent.timestamp();
184
185         // PlatformKeyboardEvent
186         m_text = webEvent.text();
187         m_unmodifiedText = webEvent.unmodifiedText();
188         m_keyIdentifier = webEvent.keyIdentifier();
189         m_windowsVirtualKeyCode = webEvent.windowsVirtualKeyCode();
190         m_nativeVirtualKeyCode = webEvent.nativeVirtualKeyCode();
191         m_macCharCode = webEvent.macCharCode();
192         m_autoRepeat = webEvent.isAutoRepeat();
193         m_isKeypad = webEvent.isKeypad();
194         m_isSystemKey = webEvent.isSystemKey();
195     }
196 };
197
198 WebCore::PlatformKeyboardEvent platform(const WebKeyboardEvent& webEvent)
199 {
200     return WebKit2PlatformKeyboardEvent(webEvent);
201 }
202
203 #if ENABLE(GESTURE_EVENTS)
204 class WebKit2PlatformGestureEvent : public WebCore::PlatformGestureEvent {
205 public:
206     WebKit2PlatformGestureEvent(const WebGestureEvent& webEvent)
207     {
208         // PlatformEvent
209         switch (webEvent.type()) {
210         case WebEvent::GestureScrollBegin:
211             m_type = WebCore::PlatformEvent::GestureScrollBegin;
212             break;
213         case WebEvent::GestureScrollEnd:
214             m_type = WebCore::PlatformEvent::GestureScrollEnd;
215             break;
216         case WebEvent::GestureSingleTap:
217             m_type = WebCore::PlatformEvent::GestureTap;
218             break;
219         default:
220             ASSERT_NOT_REACHED();
221         }
222
223         m_modifiers = 0;
224         if (webEvent.shiftKey())
225             m_modifiers |= ShiftKey;
226         if (webEvent.controlKey())
227             m_modifiers |= CtrlKey;
228         if (webEvent.altKey())
229             m_modifiers |= AltKey;
230         if (webEvent.metaKey())
231             m_modifiers |= MetaKey;
232
233         m_timestamp = webEvent.timestamp();
234
235         // PlatformGestureEvent
236         m_position = webEvent.position();
237         m_globalPosition = webEvent.globalPosition();
238
239         m_area = webEvent.area();
240         m_deltaX = webEvent.delta().x();
241         m_deltaY = webEvent.delta().y();
242     }
243 };
244
245 WebCore::PlatformGestureEvent platform(const WebGestureEvent& webEvent)
246 {
247     return WebKit2PlatformGestureEvent(webEvent);
248 }
249 #endif
250
251 #if ENABLE(TOUCH_EVENTS)
252 class WebKit2PlatformTouchPoint : public WebCore::PlatformTouchPoint {
253 public:
254     WebKit2PlatformTouchPoint(const WebPlatformTouchPoint& webTouchPoint)
255     {
256         m_id = webTouchPoint.id();
257
258         switch (webTouchPoint.state()) {
259         case WebPlatformTouchPoint::TouchReleased:
260             m_state = PlatformTouchPoint::TouchReleased;
261             break;
262         case WebPlatformTouchPoint::TouchPressed:
263             m_state = PlatformTouchPoint::TouchPressed;
264             break;
265         case WebPlatformTouchPoint::TouchMoved:
266             m_state = PlatformTouchPoint::TouchMoved;
267             break;
268         case WebPlatformTouchPoint::TouchStationary:
269             m_state = PlatformTouchPoint::TouchStationary;
270             break;
271         case WebPlatformTouchPoint::TouchCancelled:
272             m_state = PlatformTouchPoint::TouchCancelled;
273             break;
274         default:
275             ASSERT_NOT_REACHED();
276         }
277
278         m_screenPos = webTouchPoint.screenPosition();
279         m_pos = webTouchPoint.position();
280         m_radiusX = webTouchPoint.radius().width();
281         m_radiusY = webTouchPoint.radius().height();
282         m_force = webTouchPoint.force();
283         m_rotationAngle = webTouchPoint.rotationAngle();
284     }
285 };
286
287 class WebKit2PlatformTouchEvent : public WebCore::PlatformTouchEvent {
288 public:
289     WebKit2PlatformTouchEvent(const WebTouchEvent& webEvent)
290     {
291         // PlatformEvent
292         switch (webEvent.type()) {
293         case WebEvent::TouchStart: 
294             m_type = WebCore::PlatformEvent::TouchStart;
295             break;
296         case WebEvent::TouchMove: 
297             m_type = WebCore::PlatformEvent::TouchMove;
298             break;
299         case WebEvent::TouchEnd: 
300             m_type = WebCore::PlatformEvent::TouchEnd;
301             break;
302         case WebEvent::TouchCancel:
303             m_type = WebCore::PlatformEvent::TouchCancel;
304             break;
305         default:
306             ASSERT_NOT_REACHED();
307         }
308
309         m_modifiers = 0;
310         if (webEvent.shiftKey())
311             m_modifiers |= ShiftKey;
312         if (webEvent.controlKey())
313             m_modifiers |= CtrlKey;
314         if (webEvent.altKey())
315             m_modifiers |= AltKey;
316         if (webEvent.metaKey())
317             m_modifiers |= MetaKey;
318
319         m_timestamp = webEvent.timestamp();
320
321         // PlatformTouchEvent
322         for (size_t i = 0; i < webEvent.touchPoints().size(); ++i)
323             m_touchPoints.append(WebKit2PlatformTouchPoint(webEvent.touchPoints().at(i)));
324     }
325 };
326
327 WebCore::PlatformTouchEvent platform(const WebTouchEvent& webEvent)
328 {
329     return WebKit2PlatformTouchEvent(webEvent);
330 }
331 #endif
332
333 } // namespace WebKit