2
* Copyright (C) 2009 Google 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 are
8
* * Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above
11
* copyright notice, this list of conditions and the following disclaimer
12
* in the documentation and/or other materials provided with the
14
* * Neither the name of Google Inc. nor the names of its
15
* contributors may be used to endorse or promote products derived from
16
* this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
#ifndef WebInputEvent_h
32
#define WebInputEvent_h
34
#include "WebTouchPoint.h"
35
#include "platform/WebCommon.h"
36
#include "platform/WebRect.h"
42
// The classes defined in this file are intended to be used with
43
// WebWidget's handleInputEvent method. These event types are cross-
44
// platform and correspond closely to WebCore's Platform*Event classes.
46
// WARNING! These classes must remain PODs (plain old data). They are
47
// intended to be "serializable" by copying their raw bytes, so they must
48
// not contain any non-bit-copyable member variables!
50
// Furthermore, the class members need to be packed so they are aligned
51
// properly and don't have paddings/gaps, otherwise memory check tools
52
// like Valgrind will complain about uninitialized memory usage when
53
// transferring these classes over the wire.
57
// WebInputEvent --------------------------------------------------------------
61
WebInputEvent(unsigned sizeParam = sizeof(WebInputEvent))
62
: timeStampSeconds(0.0)
67
// When we use an input method (or an input method editor), we receive
68
// two events for a keypress. The former event is a keydown, which
69
// provides a keycode, and the latter is a textinput, which provides
70
// a character processed by an input method. (The mapping from a
71
// keycode to a character code is not trivial for non-English
73
// To support input methods, Safari sends keydown events to WebKit for
74
// filtering. WebKit sends filtered keydown events back to Safari,
75
// which sends them to input methods.
76
// Unfortunately, it is hard to apply this design to Chrome because of
77
// our multiprocess architecture. An input method is running in a
78
// browser process. On the other hand, WebKit is running in a renderer
79
// process. So, this design results in increasing IPC messages.
80
// To support input methods without increasing IPC messages, Chrome
81
// handles keyboard events in a browser process and send asynchronous
82
// input events (to be translated to DOM events) to a renderer
84
// This design is mostly the same as the one of Windows and Mac Carbon.
85
// So, for what it's worth, our Linux and Mac front-ends emulate our
86
// Windows front-end. To emulate our Windows front-end, we can share
87
// our back-end code among Windows, Linux, and Mac.
88
// TODO(hbono): Issue 18064: remove the KeyDown type since it isn't
89
// used in Chrome any longer.
102
// WebMouseWheelEvent
136
// modifiers for all events:
142
// modifiers for keyboard events:
144
IsAutoRepeat = 1 << 5,
146
// modifiers for mouse events:
147
LeftButtonDown = 1 << 6,
148
MiddleButtonDown = 1 << 7,
149
RightButtonDown = 1 << 8,
151
// Toggle modifiers for all events. Danger: these are not reflected
152
// into WebCore, so round-tripping from WebInputEvent to a WebCore
153
// event and back will not preserve these flags.
157
// Left/right modifiers for keyboard events.
162
static const int InputModifiers = ShiftKey | ControlKey | AltKey | MetaKey;
164
double timeStampSeconds; // Seconds since epoch.
165
unsigned size; // The size of this structure, for serialization.
169
// Returns true if the WebInputEvent |type| is a mouse event.
170
static bool isMouseEventType(int type)
172
return type == MouseDown
175
|| type == MouseEnter
176
|| type == MouseLeave
177
|| type == ContextMenu;
180
// Returns true if the WebInputEvent |type| is a keyboard event.
181
static bool isKeyboardEventType(int type)
183
return type == RawKeyDown
189
// Returns true if the WebInputEvent |type| is a touch event.
190
static bool isTouchEventType(int type)
192
return type == TouchStart
195
|| type == TouchCancel;
198
// Returns true if the WebInputEvent is a gesture event.
199
static bool isGestureEventType(int type)
201
return type == GestureScrollBegin
202
|| type == GestureScrollEnd
203
|| type == GestureScrollUpdate
204
|| type == GestureFlingStart
205
|| type == GestureFlingCancel
206
|| type == GesturePinchBegin
207
|| type == GesturePinchEnd
208
|| type == GesturePinchUpdate
209
|| type == GestureTap
210
|| type == GestureTapDown
211
|| type == GestureTapCancel
212
|| type == GestureDoubleTap
213
|| type == GestureTwoFingerTap
214
|| type == GestureLongPress
215
|| type == GestureLongTap
216
|| type == GesturePinchBegin
217
|| type == GesturePinchEnd
218
|| type == GesturePinchUpdate;
222
// WebKeyboardEvent -----------------------------------------------------------
224
class WebKeyboardEvent : public WebInputEvent {
226
// Caps on string lengths so we can make them static arrays and keep
228
static const size_t textLengthCap = 4;
230
// http://www.w3.org/TR/DOM-Level-3-Events/keyset.html lists the
231
// identifiers. The longest is 18 characters, so we round up to the
232
// next multiple of 4.
233
static const size_t keyIdentifierLengthCap = 20;
235
// |windowsKeyCode| is the Windows key code associated with this key
236
// event. Sometimes it's direct from the event (i.e. on Windows),
237
// sometimes it's via a mapping function. If you want a list, see
238
// WebCore/platform/chromium/KeyboardCodes* . Note that this should
239
// ALWAYS store the non-locational version of a keycode as this is
240
// what is returned by the Windows API. For example, it should
241
// store VK_SHIFT instead of VK_RSHIFT. The location information
242
// should be stored in |modifiers|.
245
// The actual key code genenerated by the platform. The DOM spec runs
246
// on Windows-equivalent codes (thus |windowsKeyCode| above) but it
247
// doesn't hurt to have this one around.
250
// This identifies whether this event was tagged by the system as being
251
// a "system key" event (see
252
// http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for
253
// details). Other platforms don't have this concept, but it's just
254
// easier to leave it always false than ifdef.
255
// See comment at the top of the file for why an int is used here.
258
// |text| is the text generated by this keystroke. |unmodifiedText| is
259
// |text|, but unmodified by an concurrently-held modifiers (except
260
// shift). This is useful for working out shortcut keys. Linux and
261
// Windows guarantee one character per event. The Mac does not, but in
262
// reality that's all it ever gives. We're generous, and cap it a bit
264
WebUChar text[textLengthCap];
265
WebUChar unmodifiedText[textLengthCap];
267
// This is a string identifying the key pressed.
268
char keyIdentifier[keyIdentifierLengthCap];
270
WebKeyboardEvent(unsigned sizeParam = sizeof(WebKeyboardEvent))
271
: WebInputEvent(sizeParam)
276
memset(&text, 0, sizeof(text));
277
memset(&unmodifiedText, 0, sizeof(unmodifiedText));
278
memset(&keyIdentifier, 0, sizeof(keyIdentifier));
281
// Sets keyIdentifier based on the value of windowsKeyCode. This is
282
// handy for generating synthetic keyboard events.
283
WEBKIT_EXPORT void setKeyIdentifierFromWindowsKeyCode();
285
static int windowsKeyCodeWithoutLocation(int keycode);
286
static int locationModifiersFromWindowsKeyCode(int keycode);
289
// WebMouseEvent --------------------------------------------------------------
291
class WebMouseEvent : public WebInputEvent {
293
// These values defined for WebCore::MouseButton
312
WebMouseEvent(unsigned sizeParam = sizeof(WebMouseEvent))
313
: WebInputEvent(sizeParam)
328
// WebMouseWheelEvent ---------------------------------------------------------
330
class WebMouseWheelEvent : public WebMouseEvent {
335
PhaseStationary = 1 << 1,
336
PhaseChanged = 1 << 2,
338
PhaseCancelled = 1 << 4,
339
PhaseMayBegin = 1 << 5,
347
// See comment at the top of the file for why an int is used here.
350
// See comment at the top of the file for why an int is used here.
351
int hasPreciseScrollingDeltas;
355
WebMouseWheelEvent(unsigned sizeParam = sizeof(WebMouseWheelEvent))
356
: WebMouseEvent(sizeParam)
361
, scrollByPage(false)
362
, hasPreciseScrollingDeltas(false)
364
, momentumPhase(PhaseNone)
369
// WebGestureEvent --------------------------------------------------------------
371
class WebGestureEvent : public WebInputEvent {
401
int firstFingerWidth;
402
int firstFingerHeight;
415
SourceDevice sourceDevice;
423
WebGestureEvent(unsigned sizeParam = sizeof(WebGestureEvent))
424
: WebInputEvent(sizeParam)
430
memset(&data, 0, sizeof(data));
434
// WebTouchEvent --------------------------------------------------------------
436
class WebTouchEvent : public WebInputEvent {
438
// Maximum number of simultaneous touches supported on
440
enum { touchesLengthCap = 12 };
442
unsigned touchesLength;
443
// List of all touches which are currently down.
444
WebTouchPoint touches[touchesLengthCap];
446
unsigned changedTouchesLength;
447
// List of all touches whose state has changed since the last WebTouchEvent
448
WebTouchPoint changedTouches[touchesLengthCap];
450
unsigned targetTouchesLength;
451
// List of all touches which are currently down and are targeting the event recipient.
452
WebTouchPoint targetTouches[touchesLengthCap];
454
WebTouchEvent(unsigned sizeParam = sizeof(WebTouchEvent))
455
: WebInputEvent(sizeParam)
457
, changedTouchesLength(0)
458
, targetTouchesLength(0)
465
} // namespace WebKit