Ignore contiguous composition event.
[framework/web/webkit-efl.git] / Source / WebKit2 / Shared / WebEvent.h
1 /*
2  * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
3  * Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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.
25  */
26
27 #ifndef WebEvent_h
28 #define WebEvent_h
29
30 // FIXME: We should probably move to makeing the WebCore/PlatformFooEvents trivial classes so that
31 // we can use them as the event type.
32
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>
38
39 namespace CoreIPC {
40     class ArgumentDecoder;
41     class ArgumentEncoder;
42 }
43
44 namespace WebKit {
45
46 class WebEvent {
47 public:
48     enum Type {
49         NoType = -1,
50         
51         // WebMouseEvent
52         MouseDown,
53         MouseUp,
54         MouseMove,
55
56         // WebWheelEvent
57         Wheel,
58
59         // WebKeyboardEvent
60         KeyDown,
61         KeyUp,
62         RawKeyDown,
63         Char,
64
65 #if ENABLE(GESTURE_EVENTS)
66         // WebGestureEvent
67         GestureScrollBegin,
68         GestureScrollEnd,
69         GestureSingleTap,
70 #endif
71
72 #if ENABLE(TOUCH_EVENTS)
73         // WebTouchEvent
74         TouchStart,
75         TouchMove,
76         TouchEnd,
77         TouchCancel,
78 #endif
79     };
80
81     enum Modifiers {
82         ShiftKey    = 1 << 0,
83         ControlKey  = 1 << 1,
84         AltKey      = 1 << 2,
85         MetaKey     = 1 << 3,
86         CapsLockKey = 1 << 4,
87     };
88
89     Type type() const { return static_cast<Type>(m_type); }
90
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; }
96
97     Modifiers modifiers() const { return static_cast<Modifiers>(m_modifiers); }
98
99     double timestamp() const { return m_timestamp; }
100
101 protected:
102     WebEvent();
103
104     WebEvent(Type, Modifiers, double timestamp);
105
106     void encode(CoreIPC::ArgumentEncoder*) const;
107     static bool decode(CoreIPC::ArgumentDecoder*, WebEvent&);
108
109 private:
110     uint32_t m_type; // Type
111     uint32_t m_modifiers; // Modifiers
112     double m_timestamp;
113 };
114
115 // FIXME: Move this class to its own header file.
116 class WebMouseEvent : public WebEvent {
117 public:
118     enum Button {
119         NoButton = -1,
120         LeftButton,
121         MiddleButton,
122         RightButton
123     };
124
125     WebMouseEvent();
126
127     WebMouseEvent(Type, Button, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, float deltaX, float deltaY, float deltaZ, int clickCount, Modifiers, double timestamp);
128 #if PLATFORM(WIN)
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);
130 #endif
131
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; }
139 #if PLATFORM(WIN)
140     bool didActivateWebView() const { return m_didActivateWebView; }
141 #endif
142
143     void encode(CoreIPC::ArgumentEncoder*) const;
144     static bool decode(CoreIPC::ArgumentDecoder*, WebMouseEvent&);
145
146 private:
147     static bool isMouseEventType(Type);
148
149     uint32_t m_button;
150     WebCore::IntPoint m_position;
151     WebCore::IntPoint m_globalPosition;
152     float m_deltaX;
153     float m_deltaY;
154     float m_deltaZ;
155     int32_t m_clickCount;
156 #if PLATFORM(WIN)
157     bool m_didActivateWebView;
158 #endif
159 };
160
161 // FIXME: Move this class to its own header file.
162 class WebWheelEvent : public WebEvent {
163 public:
164     enum Granularity {
165         ScrollByPageWheelEvent,
166         ScrollByPixelWheelEvent
167     };
168
169 #if PLATFORM(MAC)
170     enum Phase {
171         PhaseNone        = 0,
172         PhaseBegan       = 1 << 0,
173         PhaseStationary  = 1 << 1,
174         PhaseChanged     = 1 << 2,
175         PhaseEnded       = 1 << 3,
176         PhaseCancelled   = 1 << 4,
177         PhaseMayBegin    = 1 << 5,
178     };
179 #endif
180
181     WebWheelEvent() { }
182
183     WebWheelEvent(Type, const WebCore::IntPoint& position, const WebCore::IntPoint& globalPosition, const WebCore::FloatSize& delta, const WebCore::FloatSize& wheelTicks, Granularity, Modifiers, double timestamp);
184 #if PLATFORM(MAC)
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);
186 #endif
187
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; }
194 #if PLATFORM(MAC)
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; }
200 #endif
201
202     void encode(CoreIPC::ArgumentEncoder*) const;
203     static bool decode(CoreIPC::ArgumentDecoder*, WebWheelEvent&);
204
205 private:
206     static bool isWheelEventType(Type);
207
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;
214 #if PLATFORM(MAC)
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;
220 #endif
221 };
222
223 // FIXME: Move this class to its own header file.
224 class WebKeyboardEvent : public WebEvent {
225 public:
226     WebKeyboardEvent() { }
227
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);
229
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; }
239
240     void encode(CoreIPC::ArgumentEncoder*) const;
241     static bool decode(CoreIPC::ArgumentDecoder*, WebKeyboardEvent&);
242
243     static bool isKeyboardEventType(Type);
244
245 private:
246     String m_text;
247     String m_unmodifiedText;
248     String m_keyIdentifier;
249     int32_t m_windowsVirtualKeyCode;
250     int32_t m_nativeVirtualKeyCode;
251     int32_t m_macCharCode;
252     bool m_isAutoRepeat;
253     bool m_isKeypad;
254     bool m_isSystemKey;
255 };
256
257
258 #if ENABLE(GESTURE_EVENTS)
259 // FIXME: Move this class to its own header file.
260 class WebGestureEvent : public WebEvent {
261 public:
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);
265
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; }
270
271     void encode(CoreIPC::ArgumentEncoder*) const;
272     static bool decode(CoreIPC::ArgumentDecoder*, WebGestureEvent&);
273
274 private:
275     static bool isGestureEventType(Type);
276
277     WebCore::IntPoint m_position;
278     WebCore::IntPoint m_globalPosition;
279     WebCore::IntSize m_area;
280     WebCore::FloatPoint m_delta;
281 };
282 #endif // ENABLE(GESTURE_EVENTS)
283
284
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 {
290 public:
291     enum TouchPointState {
292         TouchReleased,
293         TouchPressed,
294         TouchMoved,
295         TouchStationary,
296         TouchCancelled
297     };
298
299     WebPlatformTouchPoint() : m_rotationAngle(0.0), m_force(0.0) { }
300
301     WebPlatformTouchPoint(uint32_t id, TouchPointState, const WebCore::IntPoint& screenPosition, const WebCore::IntPoint& position);
302
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);
304     
305     uint32_t id() const { return m_id; }
306     TouchPointState state() const { return static_cast<TouchPointState>(m_state); }
307
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; }
313
314     void setState(TouchPointState state) { m_state = state; }
315
316     void encode(CoreIPC::ArgumentEncoder*) const;
317     static bool decode(CoreIPC::ArgumentDecoder*, WebPlatformTouchPoint&);
318
319 private:
320     uint32_t m_id;
321     uint32_t m_state;
322     WebCore::IntPoint m_screenPosition;
323     WebCore::IntPoint m_position;
324     WebCore::IntSize m_radius;
325     float m_rotationAngle;
326     float m_force;
327 };
328
329 // FIXME: Move this class to its own header file.
330 class WebTouchEvent : public WebEvent {
331 public:
332     WebTouchEvent() { }
333  
334     // FIXME: It would be nice not to have to copy the Vector here.
335     WebTouchEvent(Type, Vector<WebPlatformTouchPoint>, Modifiers, double timestamp);
336
337     const Vector<WebPlatformTouchPoint>& touchPoints() const { return m_touchPoints; }
338
339     void encode(CoreIPC::ArgumentEncoder*) const;
340     static bool decode(CoreIPC::ArgumentDecoder*, WebTouchEvent&);
341   
342 private:
343     static bool isTouchEventType(Type);
344
345     Vector<WebPlatformTouchPoint> m_touchPoints;
346 };
347
348 #endif // ENABLE(TOUCH_EVENTS)
349
350 } // namespace WebKit
351
352 #endif // WebEvent_h