|
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 #ifndef WebEvent_h |
|
27 #define WebEvent_h |
|
28 |
|
29 // FIXME: We should probably move to makeing the WebCore/PlatformFooEvents trivial classes so that |
|
30 // we can use them as the event type. |
|
31 |
|
32 #include "ArgumentDecoder.h" |
|
33 #include "ArgumentEncoder.h" |
|
34 #include "WebCoreArgumentCoders.h" |
|
35 #include <WebCore/PlatformString.h> |
|
36 |
|
37 namespace WebKit { |
|
38 |
|
39 class WebEvent { |
|
40 public: |
|
41 enum Type { |
|
42 // WebMouseEvent |
|
43 MouseDown, |
|
44 MouseUp, |
|
45 MouseMove, |
|
46 |
|
47 // WebWheelEvent |
|
48 Wheel, |
|
49 |
|
50 // WebKeyboardEvent |
|
51 KeyDown, |
|
52 KeyUp, |
|
53 RawKeyDown, |
|
54 Char |
|
55 }; |
|
56 |
|
57 enum Modifiers { |
|
58 ShiftKey = 1 << 0, |
|
59 ControlKey = 1 << 1, |
|
60 AltKey = 1 << 2, |
|
61 MetaKey = 1 << 3, |
|
62 }; |
|
63 |
|
64 Type type() const { return (Type)m_type; } |
|
65 |
|
66 bool shiftKey() const { return m_modifiers & ShiftKey; } |
|
67 bool controlKey() const { return m_modifiers & ControlKey; } |
|
68 bool altKey() const { return m_modifiers & AltKey; } |
|
69 bool metaKey() const { return m_modifiers & MetaKey; } |
|
70 |
|
71 double timestamp() const { return m_timestamp; } |
|
72 |
|
73 protected: |
|
74 WebEvent() |
|
75 { |
|
76 } |
|
77 |
|
78 WebEvent(Type type, Modifiers modifiers, double timestamp) |
|
79 : m_type(type) |
|
80 , m_modifiers(modifiers) |
|
81 , m_timestamp(timestamp) |
|
82 { |
|
83 } |
|
84 |
|
85 void encode(CoreIPC::ArgumentEncoder& encoder) const |
|
86 { |
|
87 encoder.encode(m_type); |
|
88 encoder.encode(m_modifiers); |
|
89 encoder.encode(m_timestamp); |
|
90 } |
|
91 |
|
92 static bool decode(CoreIPC::ArgumentDecoder& decoder, WebEvent& t) |
|
93 { |
|
94 if (!decoder.decode(t.m_type)) |
|
95 return false; |
|
96 if (!decoder.decode(t.m_modifiers)) |
|
97 return false; |
|
98 if (!decoder.decode(t.m_timestamp)) |
|
99 return false; |
|
100 |
|
101 return true; |
|
102 } |
|
103 |
|
104 private: |
|
105 uint32_t m_type; // Type |
|
106 uint32_t m_modifiers; // Modifiers |
|
107 double m_timestamp; |
|
108 }; |
|
109 |
|
110 class WebMouseEvent : public WebEvent { |
|
111 public: |
|
112 enum Button { |
|
113 NoButton = -1, |
|
114 LeftButton, |
|
115 MiddleButton, |
|
116 RightButton |
|
117 }; |
|
118 |
|
119 WebMouseEvent() |
|
120 { |
|
121 } |
|
122 |
|
123 WebMouseEvent(Type type, Button button, int x, int y, int globalX, int globalY, int clickCount, Modifiers modifiers, double timestamp) |
|
124 : WebEvent(type, modifiers, timestamp) |
|
125 , m_button(button) |
|
126 , m_positionX(x) |
|
127 , m_positionY(y) |
|
128 , m_globalPositionX(globalX) |
|
129 , m_globalPositionY(globalY) |
|
130 , m_clickCount(clickCount) |
|
131 { |
|
132 ASSERT(isMouseEventType(type)); |
|
133 } |
|
134 |
|
135 Button button() const { return m_button; } |
|
136 int positionX() const { return m_positionX; } |
|
137 int positionY() const { return m_positionY; } |
|
138 int globalPositionX() const { return m_globalPositionX; } |
|
139 int globalPositionY() const { return m_globalPositionY; } |
|
140 int clickCount() const { return m_clickCount; } |
|
141 |
|
142 void encode(CoreIPC::ArgumentEncoder& encoder) const |
|
143 { |
|
144 encoder.encodeBytes(reinterpret_cast<const uint8_t*>(this), sizeof(*this)); |
|
145 } |
|
146 |
|
147 static bool decode(CoreIPC::ArgumentDecoder& decoder, WebMouseEvent& t) |
|
148 { |
|
149 return decoder.decodeBytes(reinterpret_cast<uint8_t*>(&t), sizeof(t)); |
|
150 } |
|
151 |
|
152 private: |
|
153 static bool isMouseEventType(Type type) |
|
154 { |
|
155 return type == MouseDown || type == MouseUp || type == MouseMove; |
|
156 } |
|
157 |
|
158 Button m_button; |
|
159 int m_positionX; |
|
160 int m_positionY; |
|
161 int m_globalPositionX; |
|
162 int m_globalPositionY; |
|
163 int m_clickCount; |
|
164 }; |
|
165 |
|
166 class WebWheelEvent : public WebEvent { |
|
167 public: |
|
168 enum Granularity { |
|
169 ScrollByPageWheelEvent, |
|
170 ScrollByPixelWheelEvent |
|
171 }; |
|
172 |
|
173 WebWheelEvent() |
|
174 { |
|
175 } |
|
176 |
|
177 WebWheelEvent(Type type, int x, int y, int globalX, int globalY, float deltaX, float deltaY, float wheelTicksX, float wheelTicksY, Granularity granularity, Modifiers modifiers, double timestamp) |
|
178 : WebEvent(type, modifiers, timestamp) |
|
179 , m_positionX(x) |
|
180 , m_positionY(y) |
|
181 , m_globalPositionX(globalX) |
|
182 , m_globalPositionY(globalY) |
|
183 , m_deltaX(deltaX) |
|
184 , m_deltaY(deltaY) |
|
185 , m_wheelTicksX(wheelTicksX) |
|
186 , m_wheelTicksY(wheelTicksY) |
|
187 , m_granularity(granularity) |
|
188 { |
|
189 ASSERT(isWheelEventType(type)); |
|
190 } |
|
191 |
|
192 int positionX() const { return m_positionX; } |
|
193 int positionY() const { return m_positionY; } |
|
194 int globalPositionX() const { return m_globalPositionX; } |
|
195 int globalPositionY() const { return m_globalPositionY; } |
|
196 float deltaX() const { return m_deltaX; } |
|
197 float deltaY() const { return m_deltaY; } |
|
198 float wheelTicksX() const { return m_wheelTicksX; } |
|
199 float wheelTicksY() const { return m_wheelTicksY; } |
|
200 Granularity granularity() const { return (Granularity)m_granularity; } |
|
201 |
|
202 void encode(CoreIPC::ArgumentEncoder& encoder) const |
|
203 { |
|
204 encoder.encodeBytes(reinterpret_cast<const uint8_t*>(this), sizeof(*this)); |
|
205 } |
|
206 |
|
207 static bool decode(CoreIPC::ArgumentDecoder& decoder, WebWheelEvent& t) |
|
208 { |
|
209 return decoder.decodeBytes(reinterpret_cast<uint8_t*>(&t), sizeof(t)); |
|
210 } |
|
211 |
|
212 private: |
|
213 static bool isWheelEventType(Type type) |
|
214 { |
|
215 return type == Wheel; |
|
216 } |
|
217 |
|
218 int m_positionX; |
|
219 int m_positionY; |
|
220 int m_globalPositionX; |
|
221 int m_globalPositionY; |
|
222 float m_deltaX; |
|
223 float m_deltaY; |
|
224 float m_wheelTicksX; |
|
225 float m_wheelTicksY; |
|
226 unsigned m_granularity; // Granularity |
|
227 }; |
|
228 |
|
229 class WebKeyboardEvent : public WebEvent { |
|
230 public: |
|
231 WebKeyboardEvent() |
|
232 { |
|
233 } |
|
234 |
|
235 WebKeyboardEvent(Type type, const WebCore::String& text, const WebCore::String& unmodifiedText, const WebCore::String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, Modifiers modifiers, double timestamp) |
|
236 : WebEvent(type, modifiers, timestamp) |
|
237 , m_text(text) |
|
238 , m_unmodifiedText(unmodifiedText) |
|
239 , m_keyIdentifier(keyIdentifier) |
|
240 , m_windowsVirtualKeyCode(windowsVirtualKeyCode) |
|
241 , m_nativeVirtualKeyCode(nativeVirtualKeyCode) |
|
242 , m_isAutoRepeat(isAutoRepeat) |
|
243 , m_isKeypad(isKeypad) |
|
244 , m_isSystemKey(isSystemKey) |
|
245 { |
|
246 ASSERT(isKeyboardEventType(type)); |
|
247 } |
|
248 |
|
249 const WebCore::String& text() const { return m_text; } |
|
250 const WebCore::String& unmodifiedText() const { return m_unmodifiedText; } |
|
251 const WebCore::String& keyIdentifier() const { return m_keyIdentifier; } |
|
252 int32_t windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; } |
|
253 int32_t nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; } |
|
254 bool isAutoRepeat() const { return m_isAutoRepeat; } |
|
255 bool isKeypad() const { return m_isKeypad; } |
|
256 bool isSystemKey() const { return m_isSystemKey; } |
|
257 |
|
258 void encode(CoreIPC::ArgumentEncoder& encoder) const |
|
259 { |
|
260 WebEvent::encode(encoder); |
|
261 |
|
262 encoder.encode(m_text); |
|
263 encoder.encode(m_unmodifiedText); |
|
264 encoder.encode(m_keyIdentifier); |
|
265 encoder.encode(m_windowsVirtualKeyCode); |
|
266 encoder.encode(m_nativeVirtualKeyCode); |
|
267 encoder.encode(m_isAutoRepeat); |
|
268 encoder.encode(m_isKeypad); |
|
269 encoder.encode(m_isSystemKey); |
|
270 } |
|
271 |
|
272 static bool decode(CoreIPC::ArgumentDecoder& decoder, WebKeyboardEvent& t) |
|
273 { |
|
274 if (!WebEvent::decode(decoder, t)) |
|
275 return false; |
|
276 |
|
277 WebCore::String text; |
|
278 if (!decoder.decode(text)) |
|
279 return false; |
|
280 t.m_text = text; |
|
281 |
|
282 WebCore::String unmodifiedText; |
|
283 if (!decoder.decode(unmodifiedText)) |
|
284 return false; |
|
285 t.m_unmodifiedText = unmodifiedText; |
|
286 |
|
287 WebCore::String keyIdentifier; |
|
288 if (!decoder.decode(keyIdentifier)) |
|
289 return false; |
|
290 t.m_keyIdentifier = keyIdentifier; |
|
291 |
|
292 if (!decoder.decode(t.m_windowsVirtualKeyCode)) |
|
293 return false; |
|
294 if (!decoder.decode(t.m_nativeVirtualKeyCode)) |
|
295 return false; |
|
296 if (!decoder.decode(t.m_isAutoRepeat)) |
|
297 return false; |
|
298 if (!decoder.decode(t.m_isKeypad)) |
|
299 return false; |
|
300 if (!decoder.decode(t.m_isSystemKey)) |
|
301 return false; |
|
302 return true; |
|
303 } |
|
304 |
|
305 private: |
|
306 static bool isKeyboardEventType(Type type) |
|
307 { |
|
308 return type == RawKeyDown || type == KeyDown || type == KeyUp || type == Char; |
|
309 } |
|
310 |
|
311 WebCore::String m_text; |
|
312 WebCore::String m_unmodifiedText; |
|
313 WebCore::String m_keyIdentifier; |
|
314 int32_t m_windowsVirtualKeyCode; |
|
315 int32_t m_nativeVirtualKeyCode; |
|
316 bool m_isAutoRepeat; |
|
317 bool m_isKeypad; |
|
318 bool m_isSystemKey; |
|
319 }; |
|
320 |
|
321 } // namespace WebKit |
|
322 |
|
323 #endif // WebEvent_h |