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 "../platform/WebCommon.h"
35 #include "../platform/WebGestureDevice.h"
36 #include "../platform/WebPointerProperties.h"
37 #include "../platform/WebRect.h"
38 #include "WebTouchPoint.h"
44 // The classes defined in this file are intended to be used with
45 // WebWidget's handleInputEvent method. These event types are cross-
46 // platform and correspond closely to WebCore's Platform*Event classes.
48 // WARNING! These classes must remain PODs (plain old data). They are
49 // intended to be "serializable" by copying their raw bytes, so they must
50 // not contain any non-bit-copyable member variables!
52 // Furthermore, the class members need to be packed so they are aligned
53 // properly and don't have paddings/gaps, otherwise memory check tools
54 // like Valgrind will complain about uninitialized memory usage when
55 // transferring these classes over the wire.
59 // WebInputEvent --------------------------------------------------------------
63 // When we use an input method (or an input method editor), we receive
64 // two events for a keypress. The former event is a keydown, which
65 // provides a keycode, and the latter is a textinput, which provides
66 // a character processed by an input method. (The mapping from a
67 // keycode to a character code is not trivial for non-English
69 // To support input methods, Safari sends keydown events to WebKit for
70 // filtering. WebKit sends filtered keydown events back to Safari,
71 // which sends them to input methods.
72 // Unfortunately, it is hard to apply this design to Chrome because of
73 // our multiprocess architecture. An input method is running in a
74 // browser process. On the other hand, WebKit is running in a renderer
75 // process. So, this design results in increasing IPC messages.
76 // To support input methods without increasing IPC messages, Chrome
77 // handles keyboard events in a browser process and send asynchronous
78 // input events (to be translated to DOM events) to a renderer
80 // This design is mostly the same as the one of Windows and Mac Carbon.
81 // So, for what it's worth, our Linux and Mac front-ends emulate our
82 // Windows front-end. To emulate our Windows front-end, we can share
83 // our back-end code among Windows, Linux, and Mac.
84 // TODO(hbono): Issue 18064: remove the KeyDown type since it isn't
85 // used in Chrome any longer.
87 // A Java counterpart will be generated for this enum.
88 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.blink_public.web
89 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: WebInputEventType
92 TypeFirst
= Undefined
,
96 MouseTypeFirst
= MouseDown
,
102 MouseTypeLast
= ContextMenu
,
104 // WebMouseWheelEvent
109 KeyboardTypeFirst
= RawKeyDown
,
113 KeyboardTypeLast
= Char
,
117 GestureTypeFirst
= GestureScrollBegin
,
124 GestureTapUnconfirmed
,
134 GestureTypeLast
= GesturePinchUpdate
,
138 TouchTypeFirst
= TouchStart
,
142 TouchTypeLast
= TouchCancel
,
144 TypeLast
= TouchTypeLast
147 // A Java counterpart will be generated for this enum.
148 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.blink_public.web
149 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: WebInputEventModifier
151 // modifiers for all events:
157 // modifiers for keyboard events:
159 IsAutoRepeat
= 1 << 5,
161 // modifiers for mouse events:
162 LeftButtonDown
= 1 << 6,
163 MiddleButtonDown
= 1 << 7,
164 RightButtonDown
= 1 << 8,
166 // Toggle modifiers for all events. Danger: these are not reflected
167 // into WebCore, so round-tripping from WebInputEvent to a WebCore
168 // event and back will not preserve these flags.
172 // Left/right modifiers for keyboard events.
177 // The rail mode for a wheel event specifies the axis on which scrolling is
178 // expected to stick. If this axis is set to Free, then scrolling is not
179 // stuck to any axis.
182 RailsModeHorizontal
= 1,
183 RailsModeVertical
= 2,
186 static const int InputModifiers
= ShiftKey
| ControlKey
| AltKey
| MetaKey
;
188 double timeStampSeconds
; // Seconds since platform start with microsecond resolution.
189 unsigned size
; // The size of this structure, for serialization.
193 // Returns true if the WebInputEvent |type| is a mouse event.
194 static bool isMouseEventType(int type
)
196 return MouseTypeFirst
<= type
&& type
<= MouseTypeLast
;
199 // Returns true if the WebInputEvent |type| is a keyboard event.
200 static bool isKeyboardEventType(int type
)
202 return KeyboardTypeFirst
<= type
&& type
<= KeyboardTypeLast
;
205 // Returns true if the WebInputEvent |type| is a touch event.
206 static bool isTouchEventType(int type
)
208 return TouchTypeFirst
<= type
&& type
<= TouchTypeLast
;
211 // Returns true if the WebInputEvent is a gesture event.
212 static bool isGestureEventType(int type
)
214 return GestureTypeFirst
<= type
&& type
<= GestureTypeLast
;
218 explicit WebInputEvent(unsigned sizeParam
)
220 memset(this, 0, sizeParam
);
221 timeStampSeconds
= 0.0;
228 // WebKeyboardEvent -----------------------------------------------------------
230 class WebKeyboardEvent
: public WebInputEvent
{
232 // Caps on string lengths so we can make them static arrays and keep
234 static const size_t textLengthCap
= 4;
236 // http://www.w3.org/TR/DOM-Level-3-Events/keyset.html lists the
237 // identifiers. The longest is 18 characters, so we round up to the
238 // next multiple of 4.
239 static const size_t keyIdentifierLengthCap
= 20;
241 // |windowsKeyCode| is the Windows key code associated with this key
242 // event. Sometimes it's direct from the event (i.e. on Windows),
243 // sometimes it's via a mapping function. If you want a list, see
244 // WebCore/platform/chromium/KeyboardCodes* . Note that this should
245 // ALWAYS store the non-locational version of a keycode as this is
246 // what is returned by the Windows API. For example, it should
247 // store VK_SHIFT instead of VK_RSHIFT. The location information
248 // should be stored in |modifiers|.
251 // The actual key code genenerated by the platform. The DOM spec runs
252 // on Windows-equivalent codes (thus |windowsKeyCode| above) but it
253 // doesn't hurt to have this one around.
256 // The DOM code enum of the key pressed as passed by the embedder. DOM
257 // code enum are defined in ui/events/keycodes/dom4/keycode_converter_data.h.
260 // The DOM key enum of the key pressed as passed by the embedder. DOM
261 // key enum are defined in ui/events/keycodes/dom3/dom_key_data.h
264 // This identifies whether this event was tagged by the system as being
265 // a "system key" event (see
266 // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx for
267 // details). Other platforms don't have this concept, but it's just
268 // easier to leave it always false than ifdef.
271 // |text| is the text generated by this keystroke. |unmodifiedText| is
272 // |text|, but unmodified by an concurrently-held modifiers (except
273 // shift). This is useful for working out shortcut keys. Linux and
274 // Windows guarantee one character per event. The Mac does not, but in
275 // reality that's all it ever gives. We're generous, and cap it a bit
277 WebUChar text
[textLengthCap
];
278 WebUChar unmodifiedText
[textLengthCap
];
280 // This is a string identifying the key pressed.
281 char keyIdentifier
[keyIdentifierLengthCap
];
284 : WebInputEvent(sizeof(WebKeyboardEvent
))
289 memset(&text
, 0, sizeof(text
));
290 memset(&unmodifiedText
, 0, sizeof(unmodifiedText
));
291 memset(&keyIdentifier
, 0, sizeof(keyIdentifier
));
294 // Sets keyIdentifier based on the value of windowsKeyCode. This is
295 // handy for generating synthetic keyboard events.
296 BLINK_EXPORT
void setKeyIdentifierFromWindowsKeyCode();
299 // WebMouseEvent --------------------------------------------------------------
301 class WebMouseEvent
: public WebInputEvent
, public WebPointerProperties
{
307 // DEPRECATED (crbug.com/507787)
320 : WebInputEvent(sizeof(WebMouseEvent
))
321 , WebPointerProperties()
335 explicit WebMouseEvent(unsigned sizeParam
)
336 : WebInputEvent(sizeParam
)
337 , WebPointerProperties()
351 // WebMouseWheelEvent ---------------------------------------------------------
353 class WebMouseWheelEvent
: public WebMouseEvent
{
358 PhaseStationary
= 1 << 1,
359 PhaseChanged
= 1 << 2,
361 PhaseCancelled
= 1 << 4,
362 PhaseMayBegin
= 1 << 5,
370 float accelerationRatioX
;
371 float accelerationRatioY
;
373 // This field exists to allow BrowserPlugin to mark MouseWheel events as
374 // 'resent' to handle the case where an event is not consumed when first
375 // encountered; it should be handled differently by the plugin when it is
376 // sent for thesecond time. No code within Blink touches this, other than to
377 // plumb it through event conversions.
378 int resendingPluginId
;
383 // Rubberbanding is an OSX visual effect. When a user scrolls the content
384 // area with a track pad, and the content area is already at its limit in
385 // the direction being scrolled, the entire content area is allowed to
386 // scroll slightly off screen, revealing a grey background. When the user
387 // lets go, the content area snaps back into place. Blink is responsible
388 // for this rubberbanding effect, but the embedder may wish to disable
389 // rubber banding in the left or right direction, if the scroll should have
390 // an alternate effect. The common case is that a scroll in the left or
391 // right directions causes a back or forwards navigation, respectively.
393 // These flags prevent rubber banding from starting in a given direction,
394 // but have no effect on an ongoing rubber banding. A rubber banding that
395 // started in the vertical direction is allowed to continue in the right
396 // direction, even if canRubberbandRight is 0.
397 bool canRubberbandLeft
;
398 bool canRubberbandRight
;
401 bool hasPreciseScrollingDeltas
;
403 // When false, this wheel event should not trigger scrolling (or any other default
404 // action) if the event goes unhandled by JavaScript. This is used, for example,
405 // when the browser decides the default behavior for Ctrl+Wheel should be to zoom
406 // instead of scroll.
412 : WebMouseEvent(sizeof(WebMouseWheelEvent
))
417 , accelerationRatioX(1.0f
)
418 , accelerationRatioY(1.0f
)
419 , resendingPluginId(-1)
421 , momentumPhase(PhaseNone
)
422 , canRubberbandLeft(true)
423 , canRubberbandRight(true)
424 , scrollByPage(false)
425 , hasPreciseScrollingDeltas(false)
427 , railsMode(RailsModeFree
)
432 // WebGestureEvent --------------------------------------------------------------
434 class WebGestureEvent
: public WebInputEvent
{
440 WebGestureDevice sourceDevice
;
441 // This field exists to allow BrowserPlugin to mark GestureScroll events as
442 // 'resent' to handle the case where an event is not consumed when first
443 // encountered; it should be handled differently by the plugin when it is
444 // sent for thesecond time. No code within Blink touches this, other than to
445 // plumb it through event conversions.
446 int resendingPluginId
;
449 // Tap information must be set for GestureTap, GestureTapUnconfirmed,
450 // and GestureDoubleTap events.
473 float firstFingerWidth
;
474 float firstFingerHeight
;
478 // Initial motion that triggered the scroll.
479 // May be redundant with deltaX/deltaY in the first scrollUpdate.
482 // If true, this event will skip hit testing to find a scroll
483 // target and instead just scroll the viewport.
492 // Whether any previous GestureScrollUpdate in the current scroll
493 // sequence was suppressed (e.g., the causal touchmove was
494 // preventDefault'ed). This bit is particularly useful for
495 // determining whether the observed scroll update sequence captures
496 // the entirety of the generative motion.
497 bool previousUpdateInSequencePrevented
;
498 bool preventPropagation
;
505 // If true, this event will skip hit testing to find a scroll
506 // target and instead just scroll the viewport.
511 // If set to true, don't treat flingCancel
512 // as a part of fling boost events sequence.
513 bool preventBoosting
;
523 : WebInputEvent(sizeof(WebGestureEvent
))
528 , resendingPluginId(-1)
530 memset(&data
, 0, sizeof(data
));
534 // WebTouchEvent --------------------------------------------------------------
536 // TODO(e_hakkinen): Replace with WebPointerEvent. crbug.com/508283
537 class WebTouchEvent
: public WebInputEvent
{
539 // Maximum number of simultaneous touches supported on
541 enum { touchesLengthCap
= 16 };
543 unsigned touchesLength
;
544 // List of all touches, regardless of state.
545 WebTouchPoint touches
[touchesLengthCap
];
547 // Whether the event can be canceled (with preventDefault). If true then the browser
548 // must wait for an ACK for this event. If false then no ACK IPC is expected.
551 // Whether the event will produce scroll-inducing events if uncanceled. This
552 // will be true for touchmove events after the platform slop region has been
553 // exceeded and fling-generating touchend events. Note that this doesn't
554 // necessarily mean content will scroll, only that scroll events will be
556 bool causesScrollingIfUncanceled
;
558 // A unique identifier for the touch event.
559 uint32_t uniqueTouchEventId
;
562 : WebInputEvent(sizeof(WebTouchEvent
))
565 , causesScrollingIfUncanceled(false)
566 , uniqueTouchEventId(0)