2 * Copyright (C) 2010 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 "WebEventConversion.h"
33 class WebKit2PlatformMouseEvent : public WebCore::PlatformMouseEvent {
35 WebKit2PlatformMouseEvent(const WebMouseEvent& webEvent)
38 switch (webEvent.type()) {
39 case WebEvent::MouseDown:
40 m_type = WebCore::PlatformEvent::MousePressed;
42 case WebEvent::MouseUp:
43 m_type = WebCore::PlatformEvent::MouseReleased;
45 case WebEvent::MouseMove:
46 m_type = WebCore::PlatformEvent::MouseMoved;
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;
62 m_timestamp = webEvent.timestamp();
65 switch (webEvent.button()) {
66 case WebMouseEvent::NoButton:
67 m_button = WebCore::NoButton;
69 case WebMouseEvent::LeftButton:
70 m_button = WebCore::LeftButton;
72 case WebMouseEvent::MiddleButton:
73 m_button = WebCore::MiddleButton;
75 case WebMouseEvent::RightButton:
76 m_button = WebCore::RightButton;
82 m_position = webEvent.position();
83 m_globalPosition = webEvent.globalPosition();
84 m_clickCount = webEvent.clickCount();
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;
97 m_didActivateWebView = webEvent.didActivateWebView();
102 WebCore::PlatformMouseEvent platform(const WebMouseEvent& webEvent)
104 return WebKit2PlatformMouseEvent(webEvent);
107 class WebKit2PlatformWheelEvent : public WebCore::PlatformWheelEvent {
109 WebKit2PlatformWheelEvent(const WebWheelEvent& webEvent)
112 m_type = PlatformEvent::Wheel;
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;
124 m_timestamp = webEvent.timestamp();
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();
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();
146 WebCore::PlatformWheelEvent platform(const WebWheelEvent& webEvent)
148 return WebKit2PlatformWheelEvent(webEvent);
151 class WebKit2PlatformKeyboardEvent : public WebCore::PlatformKeyboardEvent {
153 WebKit2PlatformKeyboardEvent(const WebKeyboardEvent& webEvent)
156 switch (webEvent.type()) {
157 case WebEvent::KeyDown:
158 m_type = WebCore::PlatformEvent::KeyDown;
160 case WebEvent::KeyUp:
161 m_type = WebCore::PlatformEvent::KeyUp;
163 case WebEvent::RawKeyDown:
164 m_type = WebCore::PlatformEvent::RawKeyDown;
167 m_type = WebCore::PlatformEvent::Char;
170 ASSERT_NOT_REACHED();
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;
183 m_timestamp = webEvent.timestamp();
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();
198 WebCore::PlatformKeyboardEvent platform(const WebKeyboardEvent& webEvent)
200 return WebKit2PlatformKeyboardEvent(webEvent);
203 #if ENABLE(GESTURE_EVENTS)
204 class WebKit2PlatformGestureEvent : public WebCore::PlatformGestureEvent {
206 WebKit2PlatformGestureEvent(const WebGestureEvent& webEvent)
209 switch (webEvent.type()) {
210 case WebEvent::GestureScrollBegin:
211 m_type = WebCore::PlatformEvent::GestureScrollBegin;
213 case WebEvent::GestureScrollEnd:
214 m_type = WebCore::PlatformEvent::GestureScrollEnd;
216 case WebEvent::GestureSingleTap:
217 m_type = WebCore::PlatformEvent::GestureTap;
220 ASSERT_NOT_REACHED();
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;
233 m_timestamp = webEvent.timestamp();
235 // PlatformGestureEvent
236 m_position = webEvent.position();
237 m_globalPosition = webEvent.globalPosition();
239 m_area = webEvent.area();
240 m_deltaX = webEvent.delta().x();
241 m_deltaY = webEvent.delta().y();
245 WebCore::PlatformGestureEvent platform(const WebGestureEvent& webEvent)
247 return WebKit2PlatformGestureEvent(webEvent);
251 #if ENABLE(TOUCH_EVENTS)
252 class WebKit2PlatformTouchPoint : public WebCore::PlatformTouchPoint {
254 WebKit2PlatformTouchPoint(const WebPlatformTouchPoint& webTouchPoint)
256 m_id = webTouchPoint.id();
258 switch (webTouchPoint.state()) {
259 case WebPlatformTouchPoint::TouchReleased:
260 m_state = PlatformTouchPoint::TouchReleased;
262 case WebPlatformTouchPoint::TouchPressed:
263 m_state = PlatformTouchPoint::TouchPressed;
265 case WebPlatformTouchPoint::TouchMoved:
266 m_state = PlatformTouchPoint::TouchMoved;
268 case WebPlatformTouchPoint::TouchStationary:
269 m_state = PlatformTouchPoint::TouchStationary;
271 case WebPlatformTouchPoint::TouchCancelled:
272 m_state = PlatformTouchPoint::TouchCancelled;
275 ASSERT_NOT_REACHED();
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();
287 class WebKit2PlatformTouchEvent : public WebCore::PlatformTouchEvent {
289 WebKit2PlatformTouchEvent(const WebTouchEvent& webEvent)
292 switch (webEvent.type()) {
293 case WebEvent::TouchStart:
294 m_type = WebCore::PlatformEvent::TouchStart;
296 case WebEvent::TouchMove:
297 m_type = WebCore::PlatformEvent::TouchMove;
299 case WebEvent::TouchEnd:
300 m_type = WebCore::PlatformEvent::TouchEnd;
302 case WebEvent::TouchCancel:
303 m_type = WebCore::PlatformEvent::TouchCancel;
306 ASSERT_NOT_REACHED();
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;
319 m_timestamp = webEvent.timestamp();
321 // PlatformTouchEvent
322 for (size_t i = 0; i < webEvent.touchPoints().size(); ++i)
323 m_touchPoints.append(WebKit2PlatformTouchPoint(webEvent.touchPoints().at(i)));
327 WebCore::PlatformTouchEvent platform(const WebTouchEvent& webEvent)
329 return WebKit2PlatformTouchEvent(webEvent);
333 } // namespace WebKit