1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_EVENTS_EVENT_H_
6 #define UI_EVENTS_EVENT_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/event_types.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
15 #include "ui/events/event_constants.h"
16 #include "ui/events/gesture_event_details.h"
17 #include "ui/events/gestures/gesture_types.h"
18 #include "ui/events/keycodes/keyboard_codes.h"
19 #include "ui/events/latency_info.h"
20 #include "ui/gfx/point.h"
21 #include "ui/gfx/point_conversions.h"
30 class EVENTS_EXPORT Event
{
36 explicit DispatcherApi(Event
* event
) : event_(event
) {}
38 void set_target(EventTarget
* target
) {
39 event_
->target_
= target
;
42 void set_phase(EventPhase phase
) { event_
->phase_
= phase
; }
43 void set_result(int result
) {
44 event_
->result_
= static_cast<EventResult
>(result
);
51 DISALLOW_COPY_AND_ASSIGN(DispatcherApi
);
54 const base::NativeEvent
& native_event() const { return native_event_
; }
55 EventType
type() const { return type_
; }
56 const std::string
& name() const { return name_
; }
57 // time_stamp represents time since machine was booted.
58 const base::TimeDelta
& time_stamp() const { return time_stamp_
; }
59 int flags() const { return flags_
; }
61 // This is only intended to be used externally by classes that are modifying
62 // events in an EventRewriter.
63 void set_flags(int flags
) { flags_
= flags
; }
65 EventTarget
* target() const { return target_
; }
66 EventPhase
phase() const { return phase_
; }
67 EventResult
result() const { return result_
; }
69 LatencyInfo
* latency() { return &latency_
; }
70 const LatencyInfo
* latency() const { return &latency_
; }
71 void set_latency(const LatencyInfo
& latency
) { latency_
= latency
; }
73 int source_device_id() const { return source_device_id_
; }
75 // By default, events are "cancelable", this means any default processing that
76 // the containing abstraction layer may perform can be prevented by calling
77 // SetHandled(). SetHandled() or StopPropagation() must not be called for
78 // events that are not cancelable.
79 bool cancelable() const { return cancelable_
; }
81 // The following methods return true if the respective keys were pressed at
82 // the time the event was created.
83 bool IsShiftDown() const { return (flags_
& EF_SHIFT_DOWN
) != 0; }
84 bool IsControlDown() const { return (flags_
& EF_CONTROL_DOWN
) != 0; }
85 bool IsCapsLockDown() const { return (flags_
& EF_CAPS_LOCK_DOWN
) != 0; }
86 bool IsAltDown() const { return (flags_
& EF_ALT_DOWN
) != 0; }
87 bool IsAltGrDown() const { return (flags_
& EF_ALTGR_DOWN
) != 0; }
88 bool IsCommandDown() const { return (flags_
& EF_COMMAND_DOWN
) != 0; }
89 bool IsRepeat() const { return (flags_
& EF_IS_REPEAT
) != 0; }
91 bool IsKeyEvent() const {
92 return type_
== ET_KEY_PRESSED
||
93 type_
== ET_KEY_RELEASED
||
94 type_
== ET_TRANSLATED_KEY_PRESS
||
95 type_
== ET_TRANSLATED_KEY_RELEASE
;
98 bool IsMouseEvent() const {
99 return type_
== ET_MOUSE_PRESSED
||
100 type_
== ET_MOUSE_DRAGGED
||
101 type_
== ET_MOUSE_RELEASED
||
102 type_
== ET_MOUSE_MOVED
||
103 type_
== ET_MOUSE_ENTERED
||
104 type_
== ET_MOUSE_EXITED
||
105 type_
== ET_MOUSEWHEEL
||
106 type_
== ET_MOUSE_CAPTURE_CHANGED
;
109 bool IsTouchEvent() const {
110 return type_
== ET_TOUCH_RELEASED
||
111 type_
== ET_TOUCH_PRESSED
||
112 type_
== ET_TOUCH_MOVED
||
113 type_
== ET_TOUCH_CANCELLED
;
116 bool IsGestureEvent() const {
118 case ET_GESTURE_SCROLL_BEGIN
:
119 case ET_GESTURE_SCROLL_END
:
120 case ET_GESTURE_SCROLL_UPDATE
:
122 case ET_GESTURE_TAP_CANCEL
:
123 case ET_GESTURE_TAP_DOWN
:
124 case ET_GESTURE_BEGIN
:
126 case ET_GESTURE_TWO_FINGER_TAP
:
127 case ET_GESTURE_PINCH_BEGIN
:
128 case ET_GESTURE_PINCH_END
:
129 case ET_GESTURE_PINCH_UPDATE
:
130 case ET_GESTURE_LONG_PRESS
:
131 case ET_GESTURE_LONG_TAP
:
132 case ET_GESTURE_SWIPE
:
133 case ET_GESTURE_SHOW_PRESS
:
134 case ET_GESTURE_WIN8_EDGE_SWIPE
:
135 // When adding a gesture event which is paired with an event which
136 // occurs earlier, add the event to |IsEndingEvent|.
139 case ET_SCROLL_FLING_CANCEL
:
140 case ET_SCROLL_FLING_START
:
141 // These can be ScrollEvents too. EF_FROM_TOUCH determines if they're
142 // Gesture or Scroll events.
143 return (flags_
& EF_FROM_TOUCH
) == EF_FROM_TOUCH
;
151 // An ending event is paired with the event which started it. Setting capture
152 // should not prevent ending events from getting to their initial target.
153 bool IsEndingEvent() const {
155 case ui::ET_TOUCH_CANCELLED
:
156 case ui::ET_GESTURE_TAP_CANCEL
:
157 case ui::ET_GESTURE_END
:
158 case ui::ET_GESTURE_SCROLL_END
:
159 case ui::ET_GESTURE_PINCH_END
:
166 bool IsScrollEvent() const {
167 // Flings can be GestureEvents too. EF_FROM_TOUCH determins if they're
168 // Gesture or Scroll events.
169 return type_
== ET_SCROLL
||
170 ((type_
== ET_SCROLL_FLING_START
||
171 type_
== ET_SCROLL_FLING_CANCEL
) &&
172 !(flags() & EF_FROM_TOUCH
));
175 bool IsScrollGestureEvent() const {
176 return type_
== ET_GESTURE_SCROLL_BEGIN
||
177 type_
== ET_GESTURE_SCROLL_UPDATE
||
178 type_
== ET_GESTURE_SCROLL_END
;
181 bool IsFlingScrollEvent() const {
182 return type_
== ET_SCROLL_FLING_CANCEL
||
183 type_
== ET_SCROLL_FLING_START
;
186 bool IsMouseWheelEvent() const {
187 return type_
== ET_MOUSEWHEEL
;
190 // Convenience methods to cast |this| to a GestureEvent. IsGestureEvent()
191 // must be true as a precondition to calling these methods.
192 GestureEvent
* AsGestureEvent();
193 const GestureEvent
* AsGestureEvent() const;
195 // Returns true if the event has a valid |native_event_|.
196 bool HasNativeEvent() const;
198 // Immediately stops the propagation of the event. This must be called only
199 // from an EventHandler during an event-dispatch. Any event handler that may
200 // be in the list will not receive the event after this is called.
201 // Note that StopPropagation() can be called only for cancelable events.
202 void StopPropagation();
203 bool stopped_propagation() const { return !!(result_
& ER_CONSUMED
); }
205 // Marks the event as having been handled. A handled event does not reach the
206 // next event phase. For example, if an event is handled during the pre-target
207 // phase, then the event is dispatched to all pre-target handlers, but not to
208 // the target or post-target handlers.
209 // Note that SetHandled() can be called only for cancelable events.
211 bool handled() const { return result_
!= ER_UNHANDLED
; }
214 Event(EventType type
, base::TimeDelta time_stamp
, int flags
);
215 Event(const base::NativeEvent
& native_event
, EventType type
, int flags
);
216 Event(const Event
& copy
);
217 void SetType(EventType type
);
218 void set_delete_native_event(bool delete_native_event
) {
219 delete_native_event_
= delete_native_event
;
221 void set_cancelable(bool cancelable
) { cancelable_
= cancelable
; }
223 void set_time_stamp(const base::TimeDelta
& time_stamp
) {
224 time_stamp_
= time_stamp
;
227 void set_name(const std::string
& name
) { name_
= name
; }
230 friend class EventTestApi
;
234 base::TimeDelta time_stamp_
;
235 LatencyInfo latency_
;
237 base::NativeEvent native_event_
;
238 bool delete_native_event_
;
240 EventTarget
* target_
;
244 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information
246 int source_device_id_
;
249 class EVENTS_EXPORT CancelModeEvent
: public Event
{
252 virtual ~CancelModeEvent();
255 class EVENTS_EXPORT LocatedEvent
: public Event
{
257 virtual ~LocatedEvent();
259 float x() const { return location_
.x(); }
260 float y() const { return location_
.y(); }
261 void set_location(const gfx::PointF
& location
) { location_
= location
; }
262 // TODO(tdresser): Always return floating point location. See
264 gfx::Point
location() const { return gfx::ToFlooredPoint(location_
); }
265 const gfx::PointF
& location_f() const { return location_
; }
266 void set_root_location(const gfx::PointF
& root_location
) {
267 root_location_
= root_location
;
269 gfx::Point
root_location() const {
270 return gfx::ToFlooredPoint(root_location_
);
272 const gfx::PointF
& root_location_f() const {
273 return root_location_
;
276 // Transform the locations using |inverted_root_transform|.
277 // This is applied to both |location_| and |root_location_|.
278 virtual void UpdateForRootTransform(
279 const gfx::Transform
& inverted_root_transform
);
281 template <class T
> void ConvertLocationToTarget(T
* source
, T
* target
) {
282 if (!target
|| target
== source
)
284 // TODO(tdresser): Rewrite ConvertPointToTarget to use PointF. See
286 gfx::Point offset
= gfx::ToFlooredPoint(location_
);
287 T::ConvertPointToTarget(source
, target
, &offset
);
288 gfx::Vector2d diff
= gfx::ToFlooredPoint(location_
) - offset
;
289 location_
= location_
- diff
;
293 friend class LocatedEventTestApi
;
294 explicit LocatedEvent(const base::NativeEvent
& native_event
);
296 // Create a new LocatedEvent which is identical to the provided model.
297 // If source / target windows are provided, the model location will be
298 // converted from |source| coordinate system to |target| coordinate system.
300 LocatedEvent(const LocatedEvent
& model
, T
* source
, T
* target
)
302 location_(model
.location_
),
303 root_location_(model
.root_location_
) {
304 ConvertLocationToTarget(source
, target
);
307 // Used for synthetic events in testing.
308 LocatedEvent(EventType type
,
309 const gfx::PointF
& location
,
310 const gfx::PointF
& root_location
,
311 base::TimeDelta time_stamp
,
314 gfx::PointF location_
;
316 // |location_| multiplied by an optional transformation matrix for
317 // rotations, animations and skews.
318 gfx::PointF root_location_
;
321 class EVENTS_EXPORT MouseEvent
: public LocatedEvent
{
323 explicit MouseEvent(const base::NativeEvent
& native_event
);
325 // Create a new MouseEvent based on the provided model.
326 // Uses the provided |type| and |flags| for the new event.
327 // If source / target windows are provided, the model location will be
328 // converted from |source| coordinate system to |target| coordinate system.
330 MouseEvent(const MouseEvent
& model
, T
* source
, T
* target
)
331 : LocatedEvent(model
, source
, target
),
332 changed_button_flags_(model
.changed_button_flags_
) {
336 MouseEvent(const MouseEvent
& model
,
341 : LocatedEvent(model
, source
, target
),
342 changed_button_flags_(model
.changed_button_flags_
) {
347 // Used for synthetic events in testing and by the gesture recognizer.
348 MouseEvent(EventType type
,
349 const gfx::PointF
& location
,
350 const gfx::PointF
& root_location
,
352 int changed_button_flags
);
354 // Conveniences to quickly test what button is down
355 bool IsOnlyLeftMouseButton() const {
356 return (flags() & EF_LEFT_MOUSE_BUTTON
) &&
357 !(flags() & (EF_MIDDLE_MOUSE_BUTTON
| EF_RIGHT_MOUSE_BUTTON
));
360 bool IsLeftMouseButton() const {
361 return (flags() & EF_LEFT_MOUSE_BUTTON
) != 0;
364 bool IsOnlyMiddleMouseButton() const {
365 return (flags() & EF_MIDDLE_MOUSE_BUTTON
) &&
366 !(flags() & (EF_LEFT_MOUSE_BUTTON
| EF_RIGHT_MOUSE_BUTTON
));
369 bool IsMiddleMouseButton() const {
370 return (flags() & EF_MIDDLE_MOUSE_BUTTON
) != 0;
373 bool IsOnlyRightMouseButton() const {
374 return (flags() & EF_RIGHT_MOUSE_BUTTON
) &&
375 !(flags() & (EF_LEFT_MOUSE_BUTTON
| EF_MIDDLE_MOUSE_BUTTON
));
378 bool IsRightMouseButton() const {
379 return (flags() & EF_RIGHT_MOUSE_BUTTON
) != 0;
382 bool IsAnyButton() const {
383 return (flags() & (EF_LEFT_MOUSE_BUTTON
| EF_MIDDLE_MOUSE_BUTTON
|
384 EF_RIGHT_MOUSE_BUTTON
)) != 0;
387 // Compares two mouse down events and returns true if the second one should
388 // be considered a repeat of the first.
389 static bool IsRepeatedClickEvent(
390 const MouseEvent
& event1
,
391 const MouseEvent
& event2
);
393 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise.
394 int GetClickCount() const;
396 // Set the click count for a mousedown message. Can be 1, 2 or 3.
397 void SetClickCount(int click_count
);
399 // Identifies the button that changed. During a press this corresponds to the
400 // button that was pressed and during a release this corresponds to the button
401 // that was released.
402 // NOTE: during a press and release flags() contains the complete set of
403 // flags. Use this to determine the button that was pressed or released.
404 int changed_button_flags() const { return changed_button_flags_
; }
406 // Updates the button that changed.
407 void set_changed_button_flags(int flags
) { changed_button_flags_
= flags
; }
410 FRIEND_TEST_ALL_PREFIXES(EventTest
, DoubleClickRequiresRelease
);
411 FRIEND_TEST_ALL_PREFIXES(EventTest
, SingleClickRightLeft
);
413 // Returns the repeat count based on the previous mouse click, if it is
414 // recent enough and within a small enough distance.
415 static int GetRepeatCount(const MouseEvent
& click_event
);
417 // Resets the last_click_event_ for unit tests.
418 static void ResetLastClickForTest();
420 // See description above getter for details.
421 int changed_button_flags_
;
423 static MouseEvent
* last_click_event_
;
425 // We can create a MouseEvent for a native event more than once. We set this
426 // to true when the next event either has a different timestamp or we see a
427 // release signalling that the press (click) event was completed.
428 static bool last_click_complete_
;
433 class EVENTS_EXPORT MouseWheelEvent
: public MouseEvent
{
435 // See |offset| for details.
436 static const int kWheelDelta
;
438 explicit MouseWheelEvent(const base::NativeEvent
& native_event
);
439 explicit MouseWheelEvent(const ScrollEvent
& scroll_event
);
440 MouseWheelEvent(const MouseEvent
& mouse_event
, int x_offset
, int y_offset
);
441 MouseWheelEvent(const MouseWheelEvent
& mouse_wheel_event
);
444 MouseWheelEvent(const MouseWheelEvent
& model
,
447 : MouseEvent(model
, source
, target
, model
.type(), model
.flags()),
448 offset_(model
.x_offset(), model
.y_offset()) {
451 // Used for synthetic events in testing and by the gesture recognizer.
452 MouseWheelEvent(const gfx::Vector2d
& offset
,
453 const gfx::PointF
& location
,
454 const gfx::PointF
& root_location
,
456 int changed_button_flags
);
458 // The amount to scroll. This is in multiples of kWheelDelta.
459 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up.
460 int x_offset() const { return offset_
.x(); }
461 int y_offset() const { return offset_
.y(); }
462 const gfx::Vector2d
& offset() const { return offset_
; }
464 // Overridden from LocatedEvent.
465 virtual void UpdateForRootTransform(
466 const gfx::Transform
& inverted_root_transform
) OVERRIDE
;
469 gfx::Vector2d offset_
;
472 class EVENTS_EXPORT TouchEvent
: public LocatedEvent
{
474 explicit TouchEvent(const base::NativeEvent
& native_event
);
476 // Create a new TouchEvent which is identical to the provided model.
477 // If source / target windows are provided, the model location will be
478 // converted from |source| coordinate system to |target| coordinate system.
480 TouchEvent(const TouchEvent
& model
, T
* source
, T
* target
)
481 : LocatedEvent(model
, source
, target
),
482 touch_id_(model
.touch_id_
),
483 radius_x_(model
.radius_x_
),
484 radius_y_(model
.radius_y_
),
485 rotation_angle_(model
.rotation_angle_
),
486 force_(model
.force_
) {
489 TouchEvent(EventType type
,
490 const gfx::PointF
& location
,
492 base::TimeDelta time_stamp
);
494 TouchEvent(EventType type
,
495 const gfx::PointF
& location
,
498 base::TimeDelta timestamp
,
504 virtual ~TouchEvent();
506 int touch_id() const { return touch_id_
; }
507 float radius_x() const { return radius_x_
; }
508 float radius_y() const { return radius_y_
; }
509 float rotation_angle() const { return rotation_angle_
; }
510 float force() const { return force_
; }
512 // Used for unit tests.
513 void set_radius_x(const float r
) { radius_x_
= r
; }
514 void set_radius_y(const float r
) { radius_y_
= r
; }
516 // Overridden from LocatedEvent.
517 virtual void UpdateForRootTransform(
518 const gfx::Transform
& inverted_root_transform
) OVERRIDE
;
521 void set_radius(float radius_x
, float radius_y
) {
522 radius_x_
= radius_x
;
523 radius_y_
= radius_y
;
526 void set_rotation_angle(float rotation_angle
) {
527 rotation_angle_
= rotation_angle
;
530 void set_force(float force
) { force_
= force
; }
533 // The identity (typically finger) of the touch starting at 0 and incrementing
534 // for each separable additional touch that the hardware can detect.
537 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown.
540 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown.
543 // Angle of the major axis away from the X axis. Default 0.0.
544 float rotation_angle_
;
546 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
550 // An interface that individual platforms can use to store additional data on
553 // Currently only used in mojo.
554 class EVENTS_EXPORT ExtendedKeyEventData
{
556 virtual ~ExtendedKeyEventData() {}
558 virtual ExtendedKeyEventData
* Clone() const = 0;
561 // A KeyEvent is really two distinct classes, melded together due to the
562 // DOM legacy of Windows key events: a keystroke event (is_char_ == false),
563 // or a character event (is_char_ == true).
565 // For a keystroke event,
566 // -- is_char_ is false.
567 // -- type() can be any one of ET_KEY_PRESSED, ET_KEY_RELEASED,
568 // ET_TRANSLATED_KEY_PRESS, or ET_TRANSLATED_KEY_RELEASE.
569 // -- character_ functions as a bypass or cache for GetCharacter().
570 // -- key_code_ is a VKEY_ value associated with the key. For printable
571 // characters, this may or may not be a mapped value, imitating MS Windows:
572 // if the mapped key generates a character that has an associated VKEY_
573 // code, then key_code_ is that code; if not, then key_code_ is the unmapped
574 // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use
575 // VKEY_Q for the key beside Tab, while French uses VKEY_A.
576 // -- code_ is in one-to-one correspondence with a physical keyboard
577 // location, and does not vary depending on key layout.
579 // For a character event,
580 // -- is_char_ is true.
581 // -- type() is ET_KEY_PRESSED.
582 // -- character_ is a UTF-16 character value.
583 // -- key_code_ is conflated with character_ by some code, because both
584 // arrive in the wParam field of a Windows event.
587 class EVENTS_EXPORT KeyEvent
: public Event
{
589 // Create a KeyEvent from a NativeEvent. For Windows this native event can
590 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message
591 // (WM_CHAR). Other systems have only keystroke events.
592 explicit KeyEvent(const base::NativeEvent
& native_event
);
594 // Create a keystroke event.
595 KeyEvent(EventType type
, KeyboardCode key_code
, int flags
);
597 // Create a character event.
598 KeyEvent(base::char16 character
, KeyboardCode key_code
, int flags
);
600 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA')
601 // See also: ui/events/keycodes/dom4/keycode_converter_data.h
602 KeyEvent(EventType type
,
603 KeyboardCode key_code
,
604 const std::string
& code
,
607 KeyEvent(const KeyEvent
& rhs
);
609 KeyEvent
& operator=(const KeyEvent
& rhs
);
613 // TODO(erg): While we transition to mojo, we have to hack around a mismatch
614 // in our event types. Our ui::Events don't really have all the data we need
615 // to process key events, and we instead do per-platform conversions with
616 // native HWNDs or XEvents. And we can't reliably send those native data
617 // types across mojo types in a cross-platform way. So instead, we set the
618 // resulting data when read across IPC boundaries.
619 void SetExtendedKeyEventData(scoped_ptr
<ExtendedKeyEventData
> data
);
620 const ExtendedKeyEventData
* extended_key_event_data() const {
621 return extended_key_event_data_
.get();
624 // This bypasses the normal mapping from keystroke events to characters,
625 // which allows an I18N virtual keyboard to fabricate a keyboard event that
626 // does not have a corresponding KeyboardCode (example: U+00E1 Latin small
627 // letter A with acute, U+0410 Cyrillic capital letter A).
628 void set_character(base::char16 character
) { character_
= character
; }
630 // Gets the character generated by this key event. It only supports Unicode
632 base::char16
GetCharacter() const;
634 // Gets the platform key code. For XKB, this is the xksym value.
635 void set_platform_keycode(uint32 keycode
) { platform_keycode_
= keycode
; }
636 uint32
platform_keycode() const { return platform_keycode_
; }
637 KeyboardCode
key_code() const { return key_code_
; }
639 // True if this is a character event, false if this is a keystroke event.
640 bool is_char() const { return is_char_
; }
642 // This is only intended to be used externally by classes that are modifying
643 // events in an EventRewriter.
644 void set_key_code(KeyboardCode key_code
) { key_code_
= key_code
; }
646 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win.
647 // TODO(msw): Additional work may be needed for analogues on other platforms.
648 bool IsUnicodeKeyCode() const;
650 std::string
code() const { return code_
; }
652 // Normalizes flags_ so that it describes the state after the event.
653 // (Native X11 event flags describe the state before the event.)
654 void NormalizeFlags();
656 // Returns true if the key event has already been processed by an input method
657 // and there is no need to pass the key event to the input method again.
658 bool IsTranslated() const;
659 // Marks this key event as translated or not translated.
660 void SetTranslated(bool translated
);
663 friend class KeyEventTestApi
;
665 // This allows a subclass TranslatedKeyEvent to be a non character event.
666 void set_is_char(bool is_char
) { is_char_
= is_char
; }
669 KeyboardCode key_code_
;
671 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space')
672 // http://www.w3.org/TR/uievents/#keyboard-key-codes.
674 // This value represents the physical position in the keyboard and can be
675 // converted from / to keyboard scan code like XKB.
678 // True if this is a character event, false if this is a keystroke event.
681 // The platform related keycode value. For XKB, it's keysym value.
682 // For now, this is used for CharacterComposer in ChromeOS.
683 uint32 platform_keycode_
;
685 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'รข')
686 // http://www.w3.org/TR/uievents/#keyboard-key-codes.
688 // This value represents the text that the key event will insert to input
689 // field. For key with modifier key, it may have specifial text.
690 // e.g. CTRL+A has '\x01'.
691 base::char16 character_
;
693 // Parts of our event handling require raw native events (see both the
694 // windows and linux implementations of web_input_event in content/). Because
695 // mojo instead serializes and deserializes events in potentially different
696 // processes, we need to have a mechanism to keep track of this data.
697 scoped_ptr
<ExtendedKeyEventData
> extended_key_event_data_
;
699 static bool IsRepeated(const KeyEvent
& event
);
701 static KeyEvent
* last_key_event_
;
704 class EVENTS_EXPORT ScrollEvent
: public MouseEvent
{
706 explicit ScrollEvent(const base::NativeEvent
& native_event
);
708 ScrollEvent(const ScrollEvent
& model
,
711 : MouseEvent(model
, source
, target
),
712 x_offset_(model
.x_offset_
),
713 y_offset_(model
.y_offset_
),
714 x_offset_ordinal_(model
.x_offset_ordinal_
),
715 y_offset_ordinal_(model
.y_offset_ordinal_
),
716 finger_count_(model
.finger_count_
){
720 ScrollEvent(EventType type
,
721 const gfx::PointF
& location
,
722 base::TimeDelta time_stamp
,
726 float x_offset_ordinal
,
727 float y_offset_ordinal
,
730 // Scale the scroll event's offset value.
731 // This is useful in the multi-monitor setup where it needs to be scaled
732 // to provide a consistent user experience.
733 void Scale(const float factor
);
735 float x_offset() const { return x_offset_
; }
736 float y_offset() const { return y_offset_
; }
737 float x_offset_ordinal() const { return x_offset_ordinal_
; }
738 float y_offset_ordinal() const { return y_offset_ordinal_
; }
739 int finger_count() const { return finger_count_
; }
742 // Potential accelerated offsets.
745 // Unaccelerated offsets.
746 float x_offset_ordinal_
;
747 float y_offset_ordinal_
;
748 // Number of fingers on the pad.
752 class EVENTS_EXPORT GestureEvent
: public LocatedEvent
{
754 GestureEvent(float x
,
757 base::TimeDelta time_stamp
,
758 const GestureEventDetails
& details
);
760 // Create a new GestureEvent which is identical to the provided model.
761 // If source / target windows are provided, the model location will be
762 // converted from |source| coordinate system to |target| coordinate system.
763 template <typename T
>
764 GestureEvent(const GestureEvent
& model
, T
* source
, T
* target
)
765 : LocatedEvent(model
, source
, target
),
766 details_(model
.details_
) {
769 virtual ~GestureEvent();
771 const GestureEventDetails
& details() const { return details_
; }
774 GestureEventDetails details_
;
779 #endif // UI_EVENTS_EVENT_H_