Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: sky/engine/public/web/WebInputEvent.h

Issue 860593003: Move WebInputEvent from public/web to public/platform (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Build fix Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 SKY_ENGINE_PUBLIC_WEB_WEBINPUTEVENT_H_
32 #define SKY_ENGINE_PUBLIC_WEB_WEBINPUTEVENT_H_
33
34 #include "../platform/WebCommon.h"
35 #include "../platform/WebGestureDevice.h"
36 #include "../platform/WebRect.h"
37 #include "sky/engine/public/web/WebTouchPoint.h"
38
39 #include <string.h>
40
41 namespace blink {
42
43 // The classes defined in this file are intended to be used with
44 // WebWidget's handleInputEvent method. These event types are cross-
45 // platform and correspond closely to WebCore's Platform*Event classes.
46 //
47 // WARNING! These classes must remain PODs (plain old data). They are
48 // intended to be "serializable" by copying their raw bytes, so they must
49 // not contain any non-bit-copyable member variables!
50 //
51 // Furthermore, the class members need to be packed so they are aligned
52 // properly and don't have paddings/gaps, otherwise memory check tools
53 // like Valgrind will complain about uninitialized memory usage when
54 // transferring these classes over the wire.
55
56 #pragma pack(push, 4)
57
58 // WebInputEvent --------------------------------------------------------------
59
60 class WebInputEvent {
61 public:
62 // When we use an input method (or an input method editor), we receive
63 // two events for a keypress. The former event is a keydown, which
64 // provides a keycode, and the latter is a textinput, which provides
65 // a character processed by an input method. (The mapping from a
66 // keycode to a character code is not trivial for non-English
67 // keyboards.)
68 // To support input methods, Safari sends keydown events to WebKit for
69 // filtering. WebKit sends filtered keydown events back to Safari,
70 // which sends them to input methods.
71 // Unfortunately, it is hard to apply this design to Chrome because of
72 // our multiprocess architecture. An input method is running in a
73 // browser process. On the other hand, WebKit is running in a renderer
74 // process. So, this design results in increasing IPC messages.
75 // To support input methods without increasing IPC messages, Chrome
76 // handles keyboard events in a browser process and send asynchronous
77 // input events (to be translated to DOM events) to a renderer
78 // process.
79 // This design is mostly the same as the one of Windows and Mac Carbon.
80 // So, for what it's worth, our Linux and Mac front-ends emulate our
81 // Windows front-end. To emulate our Windows front-end, we can share
82 // our back-end code among Windows, Linux, and Mac.
83 // TODO(hbono): Issue 18064: remove the KeyDown type since it isn't
84 // used in Chrome any longer.
85
86 enum Type {
87 Undefined = -1,
88 TypeFirst = Undefined,
89
90 // WebMouseEvent
91 MouseDown,
92 MouseTypeFirst = MouseDown,
93 MouseUp,
94 MouseMove,
95 MouseEnter,
96 MouseLeave,
97 MouseTypeLast = MouseLeave,
98
99 // WebMouseWheelEvent
100 MouseWheel,
101
102 // WebKeyboardEvent
103 RawKeyDown,
104 KeyboardTypeFirst = RawKeyDown,
105 KeyDown,
106 KeyUp,
107 Char,
108 KeyboardTypeLast = Char,
109
110 // WebGestureEvent
111 GestureScrollBegin,
112 GestureTypeFirst = GestureScrollBegin,
113 GestureScrollEnd,
114 GestureScrollUpdate,
115 GestureScrollUpdateWithoutPropagation,
116 GestureFlingStart,
117 GestureFlingCancel,
118 GestureShowPress,
119 GestureTap,
120 GestureTapUnconfirmed,
121 GestureTapDown,
122 GestureTapCancel,
123 GestureDoubleTap,
124 GestureTwoFingerTap,
125 GestureLongPress,
126 GestureLongTap,
127 GesturePinchBegin,
128 GesturePinchEnd,
129 GesturePinchUpdate,
130 GestureTypeLast = GesturePinchUpdate,
131
132 // WebTouchEvent
133 TouchStart,
134 TouchTypeFirst = TouchStart,
135 TouchMove,
136 TouchEnd,
137 TouchCancel,
138 TouchTypeLast = TouchCancel,
139
140 TypeLast = TouchTypeLast
141 };
142
143 enum Modifiers {
144 // modifiers for all events:
145 ShiftKey = 1 << 0,
146 ControlKey = 1 << 1,
147 AltKey = 1 << 2,
148 MetaKey = 1 << 3,
149
150 // modifiers for keyboard events:
151 IsKeyPad = 1 << 4,
152 IsAutoRepeat = 1 << 5,
153
154 // modifiers for mouse events:
155 LeftButtonDown = 1 << 6,
156 MiddleButtonDown = 1 << 7,
157 RightButtonDown = 1 << 8,
158
159 // Toggle modifiers for all events. Danger: these are not reflected
160 // into WebCore, so round-tripping from WebInputEvent to a WebCore
161 // event and back will not preserve these flags.
162 CapsLockOn = 1 << 9,
163 NumLockOn = 1 << 10,
164
165 // Left/right modifiers for keyboard events.
166 IsLeft = 1 << 11,
167 IsRight = 1 << 12,
168
169 // Last input event to be sent for the current vsync interval. If this
170 // flag is set, the sender guarantees that no more input events will be
171 // delivered until the next vsync and the receiver can schedule
172 // rendering accordingly. If it isn't set, the receiver should not make
173 // any assumptions about the delivery times of future input events
174 // w.r.t. vsync.
175 IsLastInputEventForCurrentVSync = 1 << 13,
176 };
177
178 static const int InputModifiers = ShiftKey | ControlKey | AltKey | MetaKey;
179
180 double timeStampSeconds; // Seconds since epoch.
181 unsigned size; // The size of this structure, for serialization.
182 Type type;
183 int modifiers;
184
185 // Returns true if the WebInputEvent |type| is a mouse event.
186 static bool isMouseEventType(int type)
187 {
188 return MouseTypeFirst <= type && type <= MouseTypeLast;
189 }
190
191 // Returns true if the WebInputEvent |type| is a keyboard event.
192 static bool isKeyboardEventType(int type)
193 {
194 return KeyboardTypeFirst <= type && type <= KeyboardTypeLast;
195 }
196
197 // Returns true if the WebInputEvent |type| is a touch event.
198 static bool isTouchEventType(int type)
199 {
200 return TouchTypeFirst <= type && type <= TouchTypeLast;
201 }
202
203 // Returns true if the WebInputEvent is a gesture event.
204 static bool isGestureEventType(int type)
205 {
206 return GestureTypeFirst <= type && type <= GestureTypeLast;
207 }
208
209 protected:
210 explicit WebInputEvent(unsigned sizeParam)
211 {
212 memset(this, 0, sizeParam);
213 timeStampSeconds = 0.0;
214 size = sizeParam;
215 type = Undefined;
216 modifiers = 0;
217 }
218 };
219
220 // WebKeyboardEvent -----------------------------------------------------------
221
222 class WebKeyboardEvent : public WebInputEvent {
223 public:
224 // Caps on string lengths so we can make them static arrays and keep
225 // them PODs.
226 static const size_t textLengthCap = 4;
227
228 // http://www.w3.org/TR/DOM-Level-3-Events/keyset.html lists the
229 // identifiers. The longest is 18 characters, so we round up to the
230 // next multiple of 4.
231 static const size_t keyIdentifierLengthCap = 20;
232
233 // |windowsKeyCode| is the Windows key code associated with this key
234 // event. Sometimes it's direct from the event (i.e. on Windows),
235 // sometimes it's via a mapping function. If you want a list, see
236 // WebCore/platform/chromium/KeyboardCodes* . Note that this should
237 // ALWAYS store the non-locational version of a keycode as this is
238 // what is returned by the Windows API. For example, it should
239 // store VK_SHIFT instead of VK_RSHIFT. The location information
240 // should be stored in |modifiers|.
241 int windowsKeyCode;
242
243 // The actual key code genenerated by the platform. The DOM spec runs
244 // on Windows-equivalent codes (thus |windowsKeyCode| above) but it
245 // doesn't hurt to have this one around.
246 int nativeKeyCode;
247
248 // This identifies whether this event was tagged by the system as being
249 // a "system key" event (see
250 // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for
251 // details). Other platforms don't have this concept, but it's just
252 // easier to leave it always false than ifdef.
253 // See comment at the top of the file for why an int is used here.
254 bool isSystemKey;
255
256 // |text| is the text generated by this keystroke. |unmodifiedText| is
257 // |text|, but unmodified by an concurrently-held modifiers (except
258 // shift). This is useful for working out shortcut keys. Linux and
259 // Windows guarantee one character per event. The Mac does not, but in
260 // reality that's all it ever gives. We're generous, and cap it a bit
261 // longer.
262 WebUChar text[textLengthCap];
263 WebUChar unmodifiedText[textLengthCap];
264
265 // This is a string identifying the key pressed.
266 char keyIdentifier[keyIdentifierLengthCap];
267
268 WebKeyboardEvent()
269 : WebInputEvent(sizeof(WebKeyboardEvent))
270 , windowsKeyCode(0)
271 , nativeKeyCode(0)
272 , isSystemKey(false)
273 {
274 memset(&text, 0, sizeof(text));
275 memset(&unmodifiedText, 0, sizeof(unmodifiedText));
276 memset(&keyIdentifier, 0, sizeof(keyIdentifier));
277 }
278
279 // Sets keyIdentifier based on the value of windowsKeyCode. This is
280 // handy for generating synthetic keyboard events.
281 BLINK_EXPORT void setKeyIdentifierFromWindowsKeyCode();
282
283 static int windowsKeyCodeWithoutLocation(int keycode);
284 static int locationModifiersFromWindowsKeyCode(int keycode);
285 };
286
287 // WebMouseEvent --------------------------------------------------------------
288
289 class WebMouseEvent : public WebInputEvent {
290 public:
291 enum Button {
292 ButtonNone = -1,
293 ButtonLeft,
294 ButtonMiddle,
295 ButtonRight
296 };
297
298 Button button;
299 int x;
300 int y;
301 int windowX;
302 int windowY;
303 int globalX;
304 int globalY;
305 int movementX;
306 int movementY;
307 int clickCount;
308
309 WebMouseEvent()
310 : WebInputEvent(sizeof(WebMouseEvent))
311 , button(ButtonNone)
312 , x(0)
313 , y(0)
314 , windowX(0)
315 , windowY(0)
316 , globalX(0)
317 , globalY(0)
318 , movementX(0)
319 , movementY(0)
320 , clickCount(0)
321 {
322 }
323
324 protected:
325 explicit WebMouseEvent(unsigned sizeParam)
326 : WebInputEvent(sizeParam)
327 , button(ButtonNone)
328 , x(0)
329 , y(0)
330 , windowX(0)
331 , windowY(0)
332 , globalX(0)
333 , globalY(0)
334 , movementX(0)
335 , movementY(0)
336 , clickCount(0)
337 {
338 }
339 };
340
341 // WebMouseWheelEvent ---------------------------------------------------------
342
343 class WebMouseWheelEvent : public WebMouseEvent {
344 public:
345 enum Phase {
346 PhaseNone = 0,
347 PhaseBegan = 1 << 0,
348 PhaseStationary = 1 << 1,
349 PhaseChanged = 1 << 2,
350 PhaseEnded = 1 << 3,
351 PhaseCancelled = 1 << 4,
352 PhaseMayBegin = 1 << 5,
353 };
354
355 float deltaX;
356 float deltaY;
357 float wheelTicksX;
358 float wheelTicksY;
359
360 float accelerationRatioX;
361 float accelerationRatioY;
362
363 // See comment at the top of the file for why an int is used here.
364 int scrollByPage;
365
366 // See comment at the top of the file for why an int is used here.
367 int hasPreciseScrollingDeltas;
368 Phase phase;
369 Phase momentumPhase;
370
371 // See comment at the top of the file for why an int is used here.
372 // Rubberbanding is an OSX visual effect. When a user scrolls the content
373 // area with a track pad, and the content area is already at its limit in
374 // the direction being scrolled, the entire content area is allowed to
375 // scroll slightly off screen, revealing a grey background. When the user
376 // lets go, the content area snaps back into place. Blink is responsible
377 // for this rubberbanding effect, but the embedder may wish to disable
378 // rubber banding in the left or right direction, if the scroll should have
379 // an alternate effect. The common case is that a scroll in the left or
380 // right directions causes a back or forwards navigation, respectively.
381 //
382 // These flags prevent rubber banding from starting in a given direction,
383 // but have no effect on an ongoing rubber banding. A rubber banding that
384 // started in the vertical direction is allowed to continue in the right
385 // direction, even if canRubberbandRight is 0.
386 int canRubberbandLeft;
387 int canRubberbandRight;
388
389 WebMouseWheelEvent()
390 : WebMouseEvent(sizeof(WebMouseWheelEvent))
391 , deltaX(0.0f)
392 , deltaY(0.0f)
393 , wheelTicksX(0.0f)
394 , wheelTicksY(0.0f)
395 , accelerationRatioX(1.0f)
396 , accelerationRatioY(1.0f)
397 , scrollByPage(false)
398 , hasPreciseScrollingDeltas(false)
399 , phase(PhaseNone)
400 , momentumPhase(PhaseNone)
401 , canRubberbandLeft(true)
402 , canRubberbandRight(true)
403 {
404 }
405 };
406
407 // WebGestureEvent ------------------------------------------------------------- -
408
409 class WebGestureEvent : public WebInputEvent {
410 public:
411 int x;
412 int y;
413 int globalX;
414 int globalY;
415 WebGestureDevice sourceDevice;
416
417 union {
418 // Tap information must be set for GestureTap, GestureTapUnconfirmed,
419 // and GestureDoubleTap events.
420 struct {
421 int tapCount;
422 float width;
423 float height;
424 } tap;
425
426 struct {
427 float width;
428 float height;
429 } tapDown;
430
431 struct {
432 float width;
433 float height;
434 } showPress;
435
436 struct {
437 float width;
438 float height;
439 } longPress;
440
441 struct {
442 float firstFingerWidth;
443 float firstFingerHeight;
444 } twoFingerTap;
445
446 struct {
447 // Initial motion that triggered the scroll.
448 // May be redundant with deltaX/deltaY in the first scrollUpdate.
449 float deltaXHint;
450 float deltaYHint;
451 } scrollBegin;
452
453 struct {
454 float deltaX;
455 float deltaY;
456 float velocityX;
457 float velocityY;
458 } scrollUpdate;
459
460 struct {
461 float velocityX;
462 float velocityY;
463 } flingStart;
464
465 struct {
466 float scale;
467 } pinchUpdate;
468 } data;
469
470 WebGestureEvent()
471 : WebInputEvent(sizeof(WebGestureEvent))
472 , x(0)
473 , y(0)
474 , globalX(0)
475 , globalY(0)
476 {
477 memset(&data, 0, sizeof(data));
478 }
479 };
480
481 // WebTouchEvent --------------------------------------------------------------
482
483 class WebTouchEvent : public WebInputEvent {
484 public:
485 // Maximum number of simultaneous touches supported on
486 // Ash/Aura.
487 enum { touchesLengthCap = 12 };
488
489 unsigned touchesLength;
490 // List of all touches which are currently down.
491 WebTouchPoint touches[touchesLengthCap];
492
493 unsigned changedTouchesLength;
494 // List of all touches whose state has changed since the last WebTouchEvent
495 WebTouchPoint changedTouches[touchesLengthCap];
496
497 unsigned targetTouchesLength;
498 // List of all touches which are currently down and are targeting the event recipient.
499 WebTouchPoint targetTouches[touchesLengthCap];
500
501 // Whether the event can be canceled (with preventDefault). If true then the browser
502 // must wait for an ACK for this event. If false then no ACK IPC is expected .
503 // See comment at the top for why an int is used here instead of a bool.
504 int cancelable;
505
506 WebTouchEvent()
507 : WebInputEvent(sizeof(WebTouchEvent))
508 , touchesLength(0)
509 , changedTouchesLength(0)
510 , targetTouchesLength(0)
511 , cancelable(true)
512 {
513 }
514 };
515
516 #pragma pack(pop)
517
518 } // namespace blink
519
520 #endif // SKY_ENGINE_PUBLIC_WEB_WEBINPUTEVENT_H_
OLDNEW
« no previous file with comments | « sky/engine/public/web/WebActiveWheelFlingParameters.h ('k') | sky/engine/public/web/WebTouchPoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698