~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit/chromium/public/WebInputEvent.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Google 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 are
 
6
 * met:
 
7
 *
 
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
 
13
 * distribution.
 
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.
 
17
 *
 
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.
 
29
 */
 
30
 
 
31
#ifndef WebInputEvent_h
 
32
#define WebInputEvent_h
 
33
 
 
34
#include "WebTouchPoint.h"
 
35
#include "platform/WebCommon.h"
 
36
#include "platform/WebRect.h"
 
37
 
 
38
#include <string.h>
 
39
 
 
40
namespace WebKit {
 
41
 
 
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.
 
45
//
 
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!
 
49
//
 
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.
 
54
 
 
55
#pragma pack(push, 4)
 
56
 
 
57
// WebInputEvent --------------------------------------------------------------
 
58
 
 
59
class WebInputEvent {
 
60
public:
 
61
    WebInputEvent(unsigned sizeParam = sizeof(WebInputEvent))
 
62
        : timeStampSeconds(0.0)
 
63
        , size(sizeParam)
 
64
        , type(Undefined)
 
65
        , modifiers(0) { }
 
66
 
 
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
 
72
    // keyboards.)
 
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
 
83
    // process.
 
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.
 
90
 
 
91
    enum Type {
 
92
        Undefined = -1,
 
93
 
 
94
        // WebMouseEvent
 
95
        MouseDown,
 
96
        MouseUp,
 
97
        MouseMove,
 
98
        MouseEnter,
 
99
        MouseLeave,
 
100
        ContextMenu,
 
101
 
 
102
        // WebMouseWheelEvent
 
103
        MouseWheel,
 
104
 
 
105
        // WebKeyboardEvent
 
106
        RawKeyDown,
 
107
        KeyDown,
 
108
        KeyUp,
 
109
        Char,
 
110
 
 
111
        // WebGestureEvent
 
112
        GestureScrollBegin,
 
113
        GestureScrollEnd,
 
114
        GestureScrollUpdate,
 
115
        GestureFlingStart,
 
116
        GestureFlingCancel,
 
117
        GestureTap,
 
118
        GestureTapDown,
 
119
        GestureTapCancel,
 
120
        GestureDoubleTap,
 
121
        GestureTwoFingerTap,
 
122
        GestureLongPress,
 
123
        GestureLongTap,
 
124
        GesturePinchBegin,
 
125
        GesturePinchEnd,
 
126
        GesturePinchUpdate,
 
127
 
 
128
        // WebTouchEvent
 
129
        TouchStart,
 
130
        TouchMove,
 
131
        TouchEnd,
 
132
        TouchCancel,
 
133
    };
 
134
 
 
135
    enum Modifiers {
 
136
        // modifiers for all events:
 
137
        ShiftKey         = 1 << 0,
 
138
        ControlKey       = 1 << 1,
 
139
        AltKey           = 1 << 2,
 
140
        MetaKey          = 1 << 3,
 
141
 
 
142
        // modifiers for keyboard events:
 
143
        IsKeyPad         = 1 << 4,
 
144
        IsAutoRepeat     = 1 << 5,
 
145
 
 
146
        // modifiers for mouse events:
 
147
        LeftButtonDown   = 1 << 6,
 
148
        MiddleButtonDown = 1 << 7,
 
149
        RightButtonDown  = 1 << 8,
 
150
 
 
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.
 
154
        CapsLockOn       = 1 << 9,
 
155
        NumLockOn        = 1 << 10,
 
156
 
 
157
        // Left/right modifiers for keyboard events.
 
158
        IsLeft           = 1 << 11,
 
159
        IsRight          = 1 << 12,
 
160
    };
 
161
 
 
162
    static const int InputModifiers = ShiftKey | ControlKey | AltKey | MetaKey;
 
163
 
 
164
    double timeStampSeconds; // Seconds since epoch.
 
165
    unsigned size; // The size of this structure, for serialization.
 
166
    Type type;
 
167
    int modifiers;
 
168
 
 
169
    // Returns true if the WebInputEvent |type| is a mouse event.
 
170
    static bool isMouseEventType(int type)
 
171
    {
 
172
        return type == MouseDown
 
173
            || type == MouseUp
 
174
            || type == MouseMove
 
175
            || type == MouseEnter
 
176
            || type == MouseLeave
 
177
            || type == ContextMenu;
 
178
    }
 
179
 
 
180
    // Returns true if the WebInputEvent |type| is a keyboard event.
 
181
    static bool isKeyboardEventType(int type)
 
182
    {
 
183
        return type == RawKeyDown
 
184
            || type == KeyDown
 
185
            || type == KeyUp
 
186
            || type == Char;
 
187
    }
 
188
 
 
189
    // Returns true if the WebInputEvent |type| is a touch event.
 
190
    static bool isTouchEventType(int type)
 
191
    {
 
192
        return type == TouchStart
 
193
            || type == TouchMove
 
194
            || type == TouchEnd
 
195
            || type == TouchCancel;
 
196
    }
 
197
 
 
198
    // Returns true if the WebInputEvent is a gesture event.
 
199
    static bool isGestureEventType(int type)
 
200
    {
 
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;
 
219
    }
 
220
};
 
221
 
 
222
// WebKeyboardEvent -----------------------------------------------------------
 
223
 
 
224
class WebKeyboardEvent : public WebInputEvent {
 
225
public:
 
226
    // Caps on string lengths so we can make them static arrays and keep
 
227
    // them PODs.
 
228
    static const size_t textLengthCap = 4;
 
229
 
 
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;
 
234
 
 
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|.
 
243
    int windowsKeyCode;
 
244
 
 
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.
 
248
    int nativeKeyCode;
 
249
 
 
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.
 
256
    bool isSystemKey;
 
257
 
 
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
 
263
    // longer.
 
264
    WebUChar text[textLengthCap];
 
265
    WebUChar unmodifiedText[textLengthCap];
 
266
 
 
267
    // This is a string identifying the key pressed.
 
268
    char keyIdentifier[keyIdentifierLengthCap];
 
269
 
 
270
    WebKeyboardEvent(unsigned sizeParam = sizeof(WebKeyboardEvent))
 
271
        : WebInputEvent(sizeParam)
 
272
        , windowsKeyCode(0)
 
273
        , nativeKeyCode(0)
 
274
        , isSystemKey(false)
 
275
    {
 
276
        memset(&text, 0, sizeof(text));
 
277
        memset(&unmodifiedText, 0, sizeof(unmodifiedText));
 
278
        memset(&keyIdentifier, 0, sizeof(keyIdentifier));
 
279
    }
 
280
 
 
281
    // Sets keyIdentifier based on the value of windowsKeyCode.  This is
 
282
    // handy for generating synthetic keyboard events.
 
283
    WEBKIT_EXPORT void setKeyIdentifierFromWindowsKeyCode();
 
284
 
 
285
    static int windowsKeyCodeWithoutLocation(int keycode);
 
286
    static int locationModifiersFromWindowsKeyCode(int keycode);
 
287
};
 
288
 
 
289
// WebMouseEvent --------------------------------------------------------------
 
290
 
 
291
class WebMouseEvent : public WebInputEvent {
 
292
public:
 
293
    // These values defined for WebCore::MouseButton
 
294
    enum Button {
 
295
        ButtonNone = -1,
 
296
        ButtonLeft,
 
297
        ButtonMiddle,
 
298
        ButtonRight
 
299
    };
 
300
 
 
301
    Button button;
 
302
    int x;
 
303
    int y;
 
304
    int windowX;
 
305
    int windowY;
 
306
    int globalX;
 
307
    int globalY;
 
308
    int movementX;
 
309
    int movementY;
 
310
    int clickCount;
 
311
 
 
312
    WebMouseEvent(unsigned sizeParam = sizeof(WebMouseEvent))
 
313
        : WebInputEvent(sizeParam)
 
314
        , button(ButtonNone)
 
315
        , x(0)
 
316
        , y(0)
 
317
        , windowX(0)
 
318
        , windowY(0)
 
319
        , globalX(0)
 
320
        , globalY(0)
 
321
        , movementX(0)
 
322
        , movementY(0)
 
323
        , clickCount(0)
 
324
    {
 
325
    }
 
326
};
 
327
 
 
328
// WebMouseWheelEvent ---------------------------------------------------------
 
329
 
 
330
class WebMouseWheelEvent : public WebMouseEvent {
 
331
public:
 
332
    enum Phase {
 
333
        PhaseNone        = 0,
 
334
        PhaseBegan       = 1 << 0,
 
335
        PhaseStationary  = 1 << 1,
 
336
        PhaseChanged     = 1 << 2,
 
337
        PhaseEnded       = 1 << 3,
 
338
        PhaseCancelled   = 1 << 4,
 
339
        PhaseMayBegin    = 1 << 5,
 
340
    };
 
341
 
 
342
    float deltaX;
 
343
    float deltaY;
 
344
    float wheelTicksX;
 
345
    float wheelTicksY;
 
346
 
 
347
    // See comment at the top of the file for why an int is used here.
 
348
    int scrollByPage;
 
349
 
 
350
    // See comment at the top of the file for why an int is used here.
 
351
    int hasPreciseScrollingDeltas;
 
352
    Phase phase;
 
353
    Phase momentumPhase;
 
354
 
 
355
    WebMouseWheelEvent(unsigned sizeParam = sizeof(WebMouseWheelEvent))
 
356
        : WebMouseEvent(sizeParam)
 
357
        , deltaX(0.0f)
 
358
        , deltaY(0.0f)
 
359
        , wheelTicksX(0.0f)
 
360
        , wheelTicksY(0.0f)
 
361
        , scrollByPage(false)
 
362
        , hasPreciseScrollingDeltas(false)
 
363
        , phase(PhaseNone)
 
364
        , momentumPhase(PhaseNone)
 
365
    {
 
366
    }
 
367
};
 
368
 
 
369
// WebGestureEvent --------------------------------------------------------------
 
370
 
 
371
class WebGestureEvent : public WebInputEvent {
 
372
public:
 
373
    enum SourceDevice {
 
374
        Touchpad,
 
375
        Touchscreen,
 
376
    };
 
377
 
 
378
    int x;
 
379
    int y;
 
380
    int globalX;
 
381
    int globalY;
 
382
 
 
383
    union {
 
384
        struct {
 
385
            int tapCount;
 
386
            int width;
 
387
            int height;
 
388
        } tap;
 
389
 
 
390
        struct {
 
391
            int width;
 
392
            int height;
 
393
        } tapDown;
 
394
 
 
395
        struct {
 
396
            int width;
 
397
            int height;
 
398
        } longPress;
 
399
 
 
400
        struct {
 
401
            int firstFingerWidth;
 
402
            int firstFingerHeight;
 
403
        } twoFingerTap;
 
404
 
 
405
        struct {
 
406
            float deltaX;
 
407
            float deltaY;
 
408
            float velocityX;
 
409
            float velocityY;
 
410
        } scrollUpdate;
 
411
 
 
412
        struct {
 
413
            float velocityX;
 
414
            float velocityY;
 
415
            SourceDevice sourceDevice;
 
416
        } flingStart;
 
417
 
 
418
        struct {
 
419
            float scale;
 
420
        } pinchUpdate;
 
421
    } data; 
 
422
 
 
423
    WebGestureEvent(unsigned sizeParam = sizeof(WebGestureEvent))
 
424
        : WebInputEvent(sizeParam)
 
425
        , x(0)
 
426
        , y(0)
 
427
        , globalX(0)
 
428
        , globalY(0)
 
429
    {
 
430
      memset(&data, 0, sizeof(data)); 
 
431
    }
 
432
};
 
433
 
 
434
// WebTouchEvent --------------------------------------------------------------
 
435
 
 
436
class WebTouchEvent : public WebInputEvent {
 
437
public:
 
438
    // Maximum number of simultaneous touches supported on
 
439
    // Ash/Aura.
 
440
    enum { touchesLengthCap = 12 };
 
441
 
 
442
    unsigned touchesLength;
 
443
    // List of all touches which are currently down.
 
444
    WebTouchPoint touches[touchesLengthCap];
 
445
 
 
446
    unsigned changedTouchesLength;
 
447
    // List of all touches whose state has changed since the last WebTouchEvent
 
448
    WebTouchPoint changedTouches[touchesLengthCap];
 
449
 
 
450
    unsigned targetTouchesLength;
 
451
    // List of all touches which are currently down and are targeting the event recipient.
 
452
    WebTouchPoint targetTouches[touchesLengthCap];
 
453
 
 
454
    WebTouchEvent(unsigned sizeParam = sizeof(WebTouchEvent))
 
455
        : WebInputEvent(sizeParam)
 
456
        , touchesLength(0)
 
457
        , changedTouchesLength(0)
 
458
        , targetTouchesLength(0)
 
459
    {
 
460
    }
 
461
};
 
462
 
 
463
#pragma pack(pop)
 
464
 
 
465
} // namespace WebKit
 
466
 
 
467
#endif