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)
37 switch (webEvent.type()) {
38 case WebEvent::MouseDown:
39 m_eventType = WebCore::MouseEventPressed;
41 case WebEvent::MouseUp:
42 m_eventType = WebCore::MouseEventReleased;
44 case WebEvent::MouseMove:
45 m_eventType = WebCore::MouseEventMoved;
51 switch (webEvent.button()) {
52 case WebMouseEvent::NoButton:
53 m_button = WebCore::NoButton;
55 case WebMouseEvent::LeftButton:
56 m_button = WebCore::LeftButton;
58 case WebMouseEvent::MiddleButton:
59 m_button = WebCore::MiddleButton;
61 case WebMouseEvent::RightButton:
62 m_button = WebCore::RightButton;
68 m_position = webEvent.position();
69 m_globalPosition = webEvent.globalPosition();
70 m_clickCount = webEvent.clickCount();
71 m_timestamp = webEvent.timestamp();
72 m_shiftKey = webEvent.shiftKey();
73 m_ctrlKey = webEvent.controlKey();
74 m_altKey = webEvent.altKey();
75 m_metaKey = webEvent.metaKey();
79 m_modifierFlags |= WebEvent::ShiftKey;
81 m_modifierFlags |= WebEvent::ControlKey;
83 m_modifierFlags |= WebEvent::AltKey;
85 m_modifierFlags |= WebEvent::MetaKey;
88 m_didActivateWebView = webEvent.didActivateWebView();
93 WebCore::PlatformMouseEvent platform(const WebMouseEvent& webEvent)
95 return WebKit2PlatformMouseEvent(webEvent);
98 class WebKit2PlatformWheelEvent : public WebCore::PlatformWheelEvent {
100 WebKit2PlatformWheelEvent(const WebWheelEvent& webEvent)
102 m_position = webEvent.position();
103 m_globalPosition = webEvent.globalPosition();
104 m_deltaX = webEvent.delta().width();
105 m_deltaY = webEvent.delta().height();
106 m_wheelTicksX = webEvent.wheelTicks().width();
107 m_wheelTicksY = webEvent.wheelTicks().height();
108 m_granularity = (webEvent.granularity() == WebWheelEvent::ScrollByPageWheelEvent) ? WebCore::ScrollByPageWheelEvent : WebCore::ScrollByPixelWheelEvent;
109 m_shiftKey = webEvent.shiftKey();
110 m_ctrlKey = webEvent.controlKey();
111 m_altKey = webEvent.altKey();
112 m_metaKey = webEvent.metaKey();
114 m_phase = static_cast<WebCore::PlatformWheelEventPhase>(webEvent.phase());
115 m_momentumPhase = static_cast<WebCore::PlatformWheelEventPhase>(webEvent.momentumPhase());
116 m_hasPreciseScrollingDeltas = webEvent.hasPreciseScrollingDeltas();
117 m_timestamp = webEvent.timestamp();
122 WebCore::PlatformWheelEvent platform(const WebWheelEvent& webEvent)
124 return WebKit2PlatformWheelEvent(webEvent);
127 class WebKit2PlatformKeyboardEvent : public WebCore::PlatformKeyboardEvent {
129 WebKit2PlatformKeyboardEvent(const WebKeyboardEvent& webEvent)
131 switch (webEvent.type()) {
132 case WebEvent::KeyDown:
133 m_type = PlatformKeyboardEvent::KeyDown;
135 case WebEvent::KeyUp:
136 m_type = PlatformKeyboardEvent::KeyUp;
138 case WebEvent::RawKeyDown:
139 m_type = PlatformKeyboardEvent::RawKeyDown;
142 m_type = PlatformKeyboardEvent::Char;
145 ASSERT_NOT_REACHED();
147 m_text = webEvent.text();
148 m_unmodifiedText = webEvent.unmodifiedText();
149 m_keyIdentifier = webEvent.keyIdentifier();
150 m_windowsVirtualKeyCode = webEvent.windowsVirtualKeyCode();
151 m_nativeVirtualKeyCode = webEvent.nativeVirtualKeyCode();
152 m_autoRepeat = webEvent.isAutoRepeat();
153 m_isKeypad = webEvent.isKeypad();
154 m_shiftKey = webEvent.shiftKey();
155 m_ctrlKey = webEvent.controlKey();
156 m_altKey = webEvent.altKey();
157 m_metaKey = webEvent.metaKey();
160 // FIXME: We should make m_isSystemKey available (and false) on all platforms
161 // to avoid this #define.
162 m_isSystemKey = webEvent.isSystemKey();
167 WebCore::PlatformKeyboardEvent platform(const WebKeyboardEvent& webEvent)
169 return WebKit2PlatformKeyboardEvent(webEvent);
172 #if ENABLE(GESTURE_EVENTS)
173 class WebKit2PlatformGestureEvent : public WebCore::PlatformGestureEvent {
175 WebKit2PlatformGestureEvent(const WebGestureEvent& webEvent)
177 switch (webEvent.type()) {
178 case WebEvent::GestureScrollBegin:
179 m_type = PlatformGestureEvent::ScrollBeginType;
181 case WebEvent::GestureScrollEnd:
182 m_type = PlatformGestureEvent::ScrollEndType;
185 ASSERT_NOT_REACHED();
188 m_position = webEvent.position();
189 m_globalPosition = webEvent.globalPosition();
190 m_timestamp = webEvent.timestamp();
194 WebCore::PlatformGestureEvent platform(const WebGestureEvent& webEvent)
196 return WebKit2PlatformGestureEvent(webEvent);
200 #if ENABLE(TOUCH_EVENTS)
201 class WebKit2PlatformTouchPoint : public WebCore::PlatformTouchPoint {
203 WebKit2PlatformTouchPoint(const WebPlatformTouchPoint& webTouchPoint)
205 m_id = webTouchPoint.id();
207 switch (webTouchPoint.state()) {
208 case WebPlatformTouchPoint::TouchReleased:
209 m_state = PlatformTouchPoint::TouchReleased;
211 case WebPlatformTouchPoint::TouchPressed:
212 m_state = PlatformTouchPoint::TouchPressed;
214 case WebPlatformTouchPoint::TouchMoved:
215 m_state = PlatformTouchPoint::TouchMoved;
217 case WebPlatformTouchPoint::TouchStationary:
218 m_state = PlatformTouchPoint::TouchStationary;
220 case WebPlatformTouchPoint::TouchCancelled:
221 m_state = PlatformTouchPoint::TouchCancelled;
224 ASSERT_NOT_REACHED();
227 m_screenPos = webTouchPoint.screenPosition();
228 m_pos = webTouchPoint.position();
232 class WebKit2PlatformTouchEvent : public WebCore::PlatformTouchEvent {
234 WebKit2PlatformTouchEvent(const WebTouchEvent& webEvent)
236 switch (webEvent.type()) {
237 case WebEvent::TouchStart:
238 m_type = WebCore::TouchStart;
240 case WebEvent::TouchMove:
241 m_type = WebCore::TouchMove;
243 case WebEvent::TouchEnd:
244 m_type = WebCore::TouchEnd;
246 case WebEvent::TouchCancel:
247 m_type = WebCore::TouchCancel;
250 ASSERT_NOT_REACHED();
253 for (int i = 0; i < webEvent.touchPoints().size(); ++i)
254 m_touchPoints.append(WebKit2PlatformTouchPoint(webEvent.touchPoints().at(i)));
256 m_ctrlKey = webEvent.controlKey();
257 m_altKey = webEvent.altKey();
258 m_shiftKey = webEvent.shiftKey();
259 m_metaKey = webEvent.metaKey();
263 WebCore::PlatformTouchEvent platform(const WebTouchEvent& webEvent)
265 return WebKit2PlatformTouchEvent(webEvent);
269 } // namespace WebKit