2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
30 // FIXME: We should probably move to makeing the WebCore/PlatformFooEvents trivial classes so that
31 // we can use them as the event type.
33 #include <WebCore/FloatPoint.h>
34 #include <WebCore/FloatSize.h>
35 #include <WebCore/IntPoint.h>
36 #include <WebCore/IntSize.h>
37 #include <wtf/text/WTFString.h>
40 class ArgumentDecoder;
41 class ArgumentEncoder;
65 #if ENABLE(GESTURE_EVENTS)
72 #if ENABLE(TOUCH_EVENTS)
89 Type type() const { return static_cast<Type>(m_type); }
91 bool shiftKey() const { return m_modifiers & ShiftKey; }
92 bool controlKey() const { return m_modifiers & ControlKey; }
93 bool altKey() const { return m_modifiers & AltKey; }
94 bool metaKey() const { return m_modifiers & MetaKey; }
95 bool capsLockKey() const { return m_modifiers & CapsLockKey; }
97 Modifiers modifiers() const { return static_cast<Modifiers>(m_modifiers); }
99 double timestamp() const { return m_timestamp; }
104 WebEvent(Type, Modifiers, double timestamp);
106 void encode(CoreIPC::ArgumentEncoder*) const;
107 static bool decode(CoreIPC::ArgumentDecoder*, WebEvent&);
110 uint32_t m_type; // Type
111 uint32_t m_modifiers; // Modifiers
115 // FIXME: Move this class to its own header file.
116 class WebMouseEvent : public WebEvent {
127 WebMouseEvent(Type, Button, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, Modifiers, double timestamp);
129 WebMouseEvent(Type, Button, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, Modifiers, double timestamp, bool didActivateWebView);
132 Button button() const { return static_cast<Button>(m_button); }
133 const WebCore::IntPoint& position() const { return m_position; }
134 const WebCore::IntPoint& globalPosition() const { return m_globalPosition; }
135 float deltaX() const { return m_deltaX; }
136 float deltaY() const { return m_deltaY; }
137 float deltaZ() const { return m_deltaZ; }
138 int32_t clickCount() const { return m_clickCount; }
140 bool didActivateWebView() const { return m_didActivateWebView; }
143 void encode(CoreIPC::ArgumentEncoder*) const;
144 static bool decode(CoreIPC::ArgumentDecoder*, WebMouseEvent&);
147 static bool isMouseEventType(Type);
150 WebCore::IntPoint m_position;
151 WebCore::IntPoint m_globalPosition;
155 int32_t m_clickCount;
157 bool m_didActivateWebView;
161 // FIXME: Move this class to its own header file.
162 class WebWheelEvent : public WebEvent {
165 ScrollByPageWheelEvent,
166 ScrollByPixelWheelEvent
173 PhaseStationary = 1 << 1,
174 PhaseChanged = 1 << 2,
176 PhaseCancelled = 1 << 4,
177 PhaseMayBegin = 1 << 5,
183 WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Granularity, Modifiers, double timestamp);
185 WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Granularity, bool directionInvertedFromDevice, Phase, Phase momentumPhase, bool hasPreciseScrollingDeltas, uint32_t scrollCount, const WebCore::FloatSize& unacceleratedScrollingDelta, Modifiers, double timestamp);
188 const WebCore::IntPoint position() const { return m_position; }
189 const WebCore::IntPoint globalPosition() const { return m_globalPosition; }
190 const WebCore::FloatSize delta() const { return m_delta; }
191 const WebCore::FloatSize wheelTicks() const { return m_wheelTicks; }
192 Granularity granularity() const { return static_cast<Granularity>(m_granularity); }
193 bool directionInvertedFromDevice() const { return m_directionInvertedFromDevice; }
195 Phase phase() const { return static_cast<Phase>(m_phase); }
196 Phase momentumPhase() const { return static_cast<Phase>(m_momentumPhase); }
197 bool hasPreciseScrollingDeltas() const { return m_hasPreciseScrollingDeltas; }
198 uint32_t scrollCount() const { return m_scrollCount; }
199 const WebCore::FloatSize& unacceleratedScrollingDelta() const { return m_unacceleratedScrollingDelta; }
202 void encode(CoreIPC::ArgumentEncoder*) const;
203 static bool decode(CoreIPC::ArgumentDecoder*, WebWheelEvent&);
206 static bool isWheelEventType(Type);
208 WebCore::IntPoint m_position;
209 WebCore::IntPoint m_globalPosition;
210 WebCore::FloatSize m_delta;
211 WebCore::FloatSize m_wheelTicks;
212 uint32_t m_granularity; // Granularity
213 bool m_directionInvertedFromDevice;
215 uint32_t m_phase; // Phase
216 uint32_t m_momentumPhase; // Phase
217 bool m_hasPreciseScrollingDeltas;
218 uint32_t m_scrollCount;
219 WebCore::FloatSize m_unacceleratedScrollingDelta;
223 // FIXME: Move this class to its own header file.
224 class WebKeyboardEvent : public WebEvent {
226 WebKeyboardEvent() { }
228 WebKeyboardEvent(Type, const String& text, const String& unmodifiedText, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers, double timestamp);
230 const String& text() const { return m_text; }
231 const String& unmodifiedText() const { return m_unmodifiedText; }
232 const String& keyIdentifier() const { return m_keyIdentifier; }
233 int32_t windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; }
234 int32_t nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; }
235 int32_t macCharCode() const { return m_macCharCode; }
236 bool isAutoRepeat() const { return m_isAutoRepeat; }
237 bool isKeypad() const { return m_isKeypad; }
238 bool isSystemKey() const { return m_isSystemKey; }
240 void encode(CoreIPC::ArgumentEncoder*) const;
241 static bool decode(CoreIPC::ArgumentDecoder*, WebKeyboardEvent&);
243 static bool isKeyboardEventType(Type);
247 String m_unmodifiedText;
248 String m_keyIdentifier;
249 int32_t m_windowsVirtualKeyCode;
250 int32_t m_nativeVirtualKeyCode;
251 int32_t m_macCharCode;
258 #if ENABLE(GESTURE_EVENTS)
259 // FIXME: Move this class to its own header file.
260 class WebGestureEvent : public WebEvent {
262 WebGestureEvent() { }
263 WebGestureEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, Modifiers, double timestamp);
264 WebGestureEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, Modifiers, double timestamp, const WebCore::IntSize& area, const WebCore::FloatPoint& delta);
266 const WebCore::IntPoint position() const { return m_position; }
267 const WebCore::IntPoint globalPosition() const { return m_globalPosition; }
268 const WebCore::IntSize area() const { return m_area; }
269 const WebCore::FloatPoint delta() const { return m_delta; }
271 void encode(CoreIPC::ArgumentEncoder*) const;
272 static bool decode(CoreIPC::ArgumentDecoder*, WebGestureEvent&);
275 static bool isGestureEventType(Type);
277 WebCore::IntPoint m_position;
278 WebCore::IntPoint m_globalPosition;
279 WebCore::IntSize m_area;
280 WebCore::FloatPoint m_delta;
282 #endif // ENABLE(GESTURE_EVENTS)
285 #if ENABLE(TOUCH_EVENTS)
286 // FIXME: Move this class to its own header file.
287 // FIXME: Having "Platform" in the name makes it sound like this event is platform-specific or low-
288 // level in some way. That doesn't seem to be the case.
289 class WebPlatformTouchPoint {
291 enum TouchPointState {
299 WebPlatformTouchPoint() : m_rotationAngle(0.0), m_force(0.0) { }
301 WebPlatformTouchPoint(uint32_t id, TouchPointState, const WebCore::IntPoint& screenPosition, const WebCore::IntPoint& position);
303 WebPlatformTouchPoint(uint32_t id, TouchPointState, const WebCore::IntPoint& screenPosition, const WebCore::IntPoint& position, const WebCore::IntSize& radius, float rotationAngle = 0.0, float force = 0.0);
305 uint32_t id() const { return m_id; }
306 TouchPointState state() const { return static_cast<TouchPointState>(m_state); }
308 const WebCore::IntPoint& screenPosition() const { return m_screenPosition; }
309 const WebCore::IntPoint& position() const { return m_position; }
310 const WebCore::IntSize& radius() const { return m_radius; }
311 float rotationAngle() const { return m_rotationAngle; }
312 float force() const { return m_force; }
314 void setState(TouchPointState state) { m_state = state; }
316 void encode(CoreIPC::ArgumentEncoder*) const;
317 static bool decode(CoreIPC::ArgumentDecoder*, WebPlatformTouchPoint&);
322 WebCore::IntPoint m_screenPosition;
323 WebCore::IntPoint m_position;
324 WebCore::IntSize m_radius;
325 float m_rotationAngle;
329 // FIXME: Move this class to its own header file.
330 class WebTouchEvent : public WebEvent {
334 // FIXME: It would be nice not to have to copy the Vector here.
335 WebTouchEvent(Type, Vector<WebPlatformTouchPoint>, Modifiers, double timestamp);
337 const Vector<WebPlatformTouchPoint>& touchPoints() const { return m_touchPoints; }
339 void encode(CoreIPC::ArgumentEncoder*) const;
340 static bool decode(CoreIPC::ArgumentDecoder*, WebTouchEvent&);
343 static bool isTouchEventType(Type);
345 Vector<WebPlatformTouchPoint> m_touchPoints;
348 #endif // ENABLE(TOUCH_EVENTS)
350 } // namespace WebKit