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
{
32 static scoped_ptr
<Event
> Clone(const Event
& event
);
38 explicit DispatcherApi(Event
* event
) : event_(event
) {}
40 void set_target(EventTarget
* target
) {
41 event_
->target_
= target
;
44 void set_phase(EventPhase phase
) { event_
->phase_
= phase
; }
45 void set_result(int result
) {
46 event_
->result_
= static_cast<EventResult
>(result
);
53 DISALLOW_COPY_AND_ASSIGN(DispatcherApi
);
56 const base::NativeEvent
& native_event() const { return native_event_
; }
57 EventType
type() const { return type_
; }
58 const std::string
& name() const { return name_
; }
59 // time_stamp represents time since machine was booted.
60 const base::TimeDelta
& time_stamp() const { return time_stamp_
; }
61 int flags() const { return flags_
; }
63 // This is only intended to be used externally by classes that are modifying
64 // events in an EventRewriter.
65 void set_flags(int flags
) { flags_
= flags
; }
67 EventTarget
* target() const { return target_
; }
68 EventPhase
phase() const { return phase_
; }
69 EventResult
result() const { return result_
; }
71 LatencyInfo
* latency() { return &latency_
; }
72 const LatencyInfo
* latency() const { return &latency_
; }
73 void set_latency(const LatencyInfo
& latency
) { latency_
= latency
; }
75 int source_device_id() const { return source_device_id_
; }
76 void set_source_device_id(int id
) { source_device_id_
= id
; }
78 // By default, events are "cancelable", this means any default processing that
79 // the containing abstraction layer may perform can be prevented by calling
80 // SetHandled(). SetHandled() or StopPropagation() must not be called for
81 // events that are not cancelable.
82 bool cancelable() const { return cancelable_
; }
84 // The following methods return true if the respective keys were pressed at
85 // the time the event was created.
86 bool IsShiftDown() const { return (flags_
& EF_SHIFT_DOWN
) != 0; }
87 bool IsControlDown() const { return (flags_
& EF_CONTROL_DOWN
) != 0; }
88 bool IsCapsLockDown() const { return (flags_
& EF_CAPS_LOCK_DOWN
) != 0; }
89 bool IsAltDown() const { return (flags_
& EF_ALT_DOWN
) != 0; }
90 bool IsAltGrDown() const { return (flags_
& EF_ALTGR_DOWN
) != 0; }
91 bool IsCommandDown() const { return (flags_
& EF_COMMAND_DOWN
) != 0; }
92 bool IsRepeat() const { return (flags_
& EF_IS_REPEAT
) != 0; }
94 bool IsKeyEvent() const {
95 return type_
== ET_KEY_PRESSED
||
96 type_
== ET_KEY_RELEASED
||
97 type_
== ET_TRANSLATED_KEY_PRESS
||
98 type_
== ET_TRANSLATED_KEY_RELEASE
;
101 bool IsMouseEvent() const {
102 return type_
== ET_MOUSE_PRESSED
||
103 type_
== ET_MOUSE_DRAGGED
||
104 type_
== ET_MOUSE_RELEASED
||
105 type_
== ET_MOUSE_MOVED
||
106 type_
== ET_MOUSE_ENTERED
||
107 type_
== ET_MOUSE_EXITED
||
108 type_
== ET_MOUSEWHEEL
||
109 type_
== ET_MOUSE_CAPTURE_CHANGED
;
112 bool IsTouchEvent() const {
113 return type_
== ET_TOUCH_RELEASED
||
114 type_
== ET_TOUCH_PRESSED
||
115 type_
== ET_TOUCH_MOVED
||
116 type_
== ET_TOUCH_CANCELLED
;
119 bool IsGestureEvent() const {
121 case ET_GESTURE_SCROLL_BEGIN
:
122 case ET_GESTURE_SCROLL_END
:
123 case ET_GESTURE_SCROLL_UPDATE
:
125 case ET_GESTURE_TAP_CANCEL
:
126 case ET_GESTURE_TAP_DOWN
:
127 case ET_GESTURE_BEGIN
:
129 case ET_GESTURE_TWO_FINGER_TAP
:
130 case ET_GESTURE_PINCH_BEGIN
:
131 case ET_GESTURE_PINCH_END
:
132 case ET_GESTURE_PINCH_UPDATE
:
133 case ET_GESTURE_LONG_PRESS
:
134 case ET_GESTURE_LONG_TAP
:
135 case ET_GESTURE_SWIPE
:
136 case ET_GESTURE_SHOW_PRESS
:
137 case ET_GESTURE_WIN8_EDGE_SWIPE
:
138 // When adding a gesture event which is paired with an event which
139 // occurs earlier, add the event to |IsEndingEvent|.
142 case ET_SCROLL_FLING_CANCEL
:
143 case ET_SCROLL_FLING_START
:
144 // These can be ScrollEvents too. EF_FROM_TOUCH determines if they're
145 // Gesture or Scroll events.
146 return (flags_
& EF_FROM_TOUCH
) == EF_FROM_TOUCH
;
154 // An ending event is paired with the event which started it. Setting capture
155 // should not prevent ending events from getting to their initial target.
156 bool IsEndingEvent() const {
158 case ui::ET_TOUCH_CANCELLED
:
159 case ui::ET_GESTURE_TAP_CANCEL
:
160 case ui::ET_GESTURE_END
:
161 case ui::ET_GESTURE_SCROLL_END
:
162 case ui::ET_GESTURE_PINCH_END
:
169 bool IsScrollEvent() const {
170 // Flings can be GestureEvents too. EF_FROM_TOUCH determins if they're
171 // Gesture or Scroll events.
172 return type_
== ET_SCROLL
||
173 ((type_
== ET_SCROLL_FLING_START
||
174 type_
== ET_SCROLL_FLING_CANCEL
) &&
175 !(flags() & EF_FROM_TOUCH
));
178 bool IsScrollGestureEvent() const {
179 return type_
== ET_GESTURE_SCROLL_BEGIN
||
180 type_
== ET_GESTURE_SCROLL_UPDATE
||
181 type_
== ET_GESTURE_SCROLL_END
;
184 bool IsFlingScrollEvent() const {
185 return type_
== ET_SCROLL_FLING_CANCEL
||
186 type_
== ET_SCROLL_FLING_START
;
189 bool IsMouseWheelEvent() const {
190 return type_
== ET_MOUSEWHEEL
;
193 bool IsLocatedEvent() const {
194 return IsMouseEvent() || IsScrollEvent() || IsTouchEvent() ||
198 // Convenience methods to cast |this| to a GestureEvent. IsGestureEvent()
199 // must be true as a precondition to calling these methods.
200 GestureEvent
* AsGestureEvent();
201 const GestureEvent
* AsGestureEvent() const;
203 // Returns true if the event has a valid |native_event_|.
204 bool HasNativeEvent() const;
206 // Immediately stops the propagation of the event. This must be called only
207 // from an EventHandler during an event-dispatch. Any event handler that may
208 // be in the list will not receive the event after this is called.
209 // Note that StopPropagation() can be called only for cancelable events.
210 void StopPropagation();
211 bool stopped_propagation() const { return !!(result_
& ER_CONSUMED
); }
213 // Marks the event as having been handled. A handled event does not reach the
214 // next event phase. For example, if an event is handled during the pre-target
215 // phase, then the event is dispatched to all pre-target handlers, but not to
216 // the target or post-target handlers.
217 // Note that SetHandled() can be called only for cancelable events.
219 bool handled() const { return result_
!= ER_UNHANDLED
; }
222 Event(EventType type
, base::TimeDelta time_stamp
, int flags
);
223 Event(const base::NativeEvent
& native_event
, EventType type
, int flags
);
224 Event(const Event
& copy
);
225 void SetType(EventType type
);
226 void set_delete_native_event(bool delete_native_event
) {
227 delete_native_event_
= delete_native_event
;
229 void set_cancelable(bool cancelable
) { cancelable_
= cancelable
; }
231 void set_time_stamp(const base::TimeDelta
& time_stamp
) {
232 time_stamp_
= time_stamp
;
235 void set_name(const std::string
& name
) { name_
= name
; }
238 friend class EventTestApi
;
242 base::TimeDelta time_stamp_
;
243 LatencyInfo latency_
;
245 base::NativeEvent native_event_
;
246 bool delete_native_event_
;
248 EventTarget
* target_
;
252 // The device id the event came from, or ED_UNKNOWN_DEVICE if the information
254 int source_device_id_
;
257 class EVENTS_EXPORT CancelModeEvent
: public Event
{
260 ~CancelModeEvent() override
;
263 class EVENTS_EXPORT LocatedEvent
: public Event
{
265 ~LocatedEvent() override
;
267 float x() const { return location_
.x(); }
268 float y() const { return location_
.y(); }
269 void set_location(const gfx::PointF
& location
) { location_
= location
; }
270 // TODO(tdresser): Always return floating point location. See
272 gfx::Point
location() const { return gfx::ToFlooredPoint(location_
); }
273 const gfx::PointF
& location_f() const { return location_
; }
274 void set_root_location(const gfx::PointF
& root_location
) {
275 root_location_
= root_location
;
277 gfx::Point
root_location() const {
278 return gfx::ToFlooredPoint(root_location_
);
280 const gfx::PointF
& root_location_f() const {
281 return root_location_
;
284 // Transform the locations using |inverted_root_transform|.
285 // This is applied to both |location_| and |root_location_|.
286 virtual void UpdateForRootTransform(
287 const gfx::Transform
& inverted_root_transform
);
289 template <class T
> void ConvertLocationToTarget(T
* source
, T
* target
) {
290 if (!target
|| target
== source
)
292 // TODO(tdresser): Rewrite ConvertPointToTarget to use PointF. See
294 gfx::Point offset
= gfx::ToFlooredPoint(location_
);
295 T::ConvertPointToTarget(source
, target
, &offset
);
296 gfx::Vector2d diff
= gfx::ToFlooredPoint(location_
) - offset
;
297 location_
= location_
- diff
;
301 friend class LocatedEventTestApi
;
302 explicit LocatedEvent(const base::NativeEvent
& native_event
);
304 // Create a new LocatedEvent which is identical to the provided model.
305 // If source / target windows are provided, the model location will be
306 // converted from |source| coordinate system to |target| coordinate system.
308 LocatedEvent(const LocatedEvent
& model
, T
* source
, T
* target
)
310 location_(model
.location_
),
311 root_location_(model
.root_location_
) {
312 ConvertLocationToTarget(source
, target
);
315 // Used for synthetic events in testing.
316 LocatedEvent(EventType type
,
317 const gfx::PointF
& location
,
318 const gfx::PointF
& root_location
,
319 base::TimeDelta time_stamp
,
322 gfx::PointF location_
;
324 // |location_| multiplied by an optional transformation matrix for
325 // rotations, animations and skews.
326 gfx::PointF root_location_
;
329 class EVENTS_EXPORT MouseEvent
: public LocatedEvent
{
331 explicit MouseEvent(const base::NativeEvent
& native_event
);
333 // Create a new MouseEvent based on the provided model.
334 // Uses the provided |type| and |flags| for the new event.
335 // If source / target windows are provided, the model location will be
336 // converted from |source| coordinate system to |target| coordinate system.
338 MouseEvent(const MouseEvent
& model
, T
* source
, T
* target
)
339 : LocatedEvent(model
, source
, target
),
340 changed_button_flags_(model
.changed_button_flags_
) {
344 MouseEvent(const MouseEvent
& model
,
349 : LocatedEvent(model
, source
, target
),
350 changed_button_flags_(model
.changed_button_flags_
) {
355 // Used for synthetic events in testing and by the gesture recognizer.
356 MouseEvent(EventType type
,
357 const gfx::PointF
& location
,
358 const gfx::PointF
& root_location
,
360 int changed_button_flags
);
362 // Conveniences to quickly test what button is down
363 bool IsOnlyLeftMouseButton() const {
364 return (flags() & EF_LEFT_MOUSE_BUTTON
) &&
365 !(flags() & (EF_MIDDLE_MOUSE_BUTTON
| EF_RIGHT_MOUSE_BUTTON
));
368 bool IsLeftMouseButton() const {
369 return (flags() & EF_LEFT_MOUSE_BUTTON
) != 0;
372 bool IsOnlyMiddleMouseButton() const {
373 return (flags() & EF_MIDDLE_MOUSE_BUTTON
) &&
374 !(flags() & (EF_LEFT_MOUSE_BUTTON
| EF_RIGHT_MOUSE_BUTTON
));
377 bool IsMiddleMouseButton() const {
378 return (flags() & EF_MIDDLE_MOUSE_BUTTON
) != 0;
381 bool IsOnlyRightMouseButton() const {
382 return (flags() & EF_RIGHT_MOUSE_BUTTON
) &&
383 !(flags() & (EF_LEFT_MOUSE_BUTTON
| EF_MIDDLE_MOUSE_BUTTON
));
386 bool IsRightMouseButton() const {
387 return (flags() & EF_RIGHT_MOUSE_BUTTON
) != 0;
390 bool IsAnyButton() const {
391 return (flags() & (EF_LEFT_MOUSE_BUTTON
| EF_MIDDLE_MOUSE_BUTTON
|
392 EF_RIGHT_MOUSE_BUTTON
)) != 0;
395 // Compares two mouse down events and returns true if the second one should
396 // be considered a repeat of the first.
397 static bool IsRepeatedClickEvent(
398 const MouseEvent
& event1
,
399 const MouseEvent
& event2
);
401 // Get the click count. Can be 1, 2 or 3 for mousedown messages, 0 otherwise.
402 int GetClickCount() const;
404 // Set the click count for a mousedown message. Can be 1, 2 or 3.
405 void SetClickCount(int click_count
);
407 // Identifies the button that changed. During a press this corresponds to the
408 // button that was pressed and during a release this corresponds to the button
409 // that was released.
410 // NOTE: during a press and release flags() contains the complete set of
411 // flags. Use this to determine the button that was pressed or released.
412 int changed_button_flags() const { return changed_button_flags_
; }
414 // Updates the button that changed.
415 void set_changed_button_flags(int flags
) { changed_button_flags_
= flags
; }
418 FRIEND_TEST_ALL_PREFIXES(EventTest
, DoubleClickRequiresRelease
);
419 FRIEND_TEST_ALL_PREFIXES(EventTest
, SingleClickRightLeft
);
421 // Returns the repeat count based on the previous mouse click, if it is
422 // recent enough and within a small enough distance.
423 static int GetRepeatCount(const MouseEvent
& click_event
);
425 // Resets the last_click_event_ for unit tests.
426 static void ResetLastClickForTest();
428 // See description above getter for details.
429 int changed_button_flags_
;
431 static MouseEvent
* last_click_event_
;
433 // We can create a MouseEvent for a native event more than once. We set this
434 // to true when the next event either has a different timestamp or we see a
435 // release signalling that the press (click) event was completed.
436 static bool last_click_complete_
;
441 class EVENTS_EXPORT MouseWheelEvent
: public MouseEvent
{
443 // See |offset| for details.
444 static const int kWheelDelta
;
446 explicit MouseWheelEvent(const base::NativeEvent
& native_event
);
447 explicit MouseWheelEvent(const ScrollEvent
& scroll_event
);
448 MouseWheelEvent(const MouseEvent
& mouse_event
, int x_offset
, int y_offset
);
449 MouseWheelEvent(const MouseWheelEvent
& mouse_wheel_event
);
452 MouseWheelEvent(const MouseWheelEvent
& model
,
455 : MouseEvent(model
, source
, target
, model
.type(), model
.flags()),
456 offset_(model
.x_offset(), model
.y_offset()) {
459 // Used for synthetic events in testing and by the gesture recognizer.
460 MouseWheelEvent(const gfx::Vector2d
& offset
,
461 const gfx::PointF
& location
,
462 const gfx::PointF
& root_location
,
464 int changed_button_flags
);
466 // The amount to scroll. This is in multiples of kWheelDelta.
467 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up.
468 int x_offset() const { return offset_
.x(); }
469 int y_offset() const { return offset_
.y(); }
470 const gfx::Vector2d
& offset() const { return offset_
; }
472 // Overridden from LocatedEvent.
473 void UpdateForRootTransform(
474 const gfx::Transform
& inverted_root_transform
) override
;
477 gfx::Vector2d offset_
;
480 class EVENTS_EXPORT TouchEvent
: public LocatedEvent
{
482 explicit TouchEvent(const base::NativeEvent
& native_event
);
484 // Create a new TouchEvent which is identical to the provided model.
485 // If source / target windows are provided, the model location will be
486 // converted from |source| coordinate system to |target| coordinate system.
488 TouchEvent(const TouchEvent
& model
, T
* source
, T
* target
)
489 : LocatedEvent(model
, source
, target
),
490 touch_id_(model
.touch_id_
),
491 radius_x_(model
.radius_x_
),
492 radius_y_(model
.radius_y_
),
493 rotation_angle_(model
.rotation_angle_
),
494 force_(model
.force_
) {
497 TouchEvent(EventType type
,
498 const gfx::PointF
& location
,
500 base::TimeDelta time_stamp
);
502 TouchEvent(EventType type
,
503 const gfx::PointF
& location
,
506 base::TimeDelta timestamp
,
512 ~TouchEvent() override
;
514 int touch_id() const { return touch_id_
; }
515 float radius_x() const { return radius_x_
; }
516 float radius_y() const { return radius_y_
; }
517 float rotation_angle() const { return rotation_angle_
; }
518 float force() const { return force_
; }
520 // Used for unit tests.
521 void set_radius_x(const float r
) { radius_x_
= r
; }
522 void set_radius_y(const float r
) { radius_y_
= r
; }
524 // Overridden from LocatedEvent.
525 void UpdateForRootTransform(
526 const gfx::Transform
& inverted_root_transform
) override
;
529 void set_radius(float radius_x
, float radius_y
) {
530 radius_x_
= radius_x
;
531 radius_y_
= radius_y
;
534 void set_rotation_angle(float rotation_angle
) {
535 rotation_angle_
= rotation_angle
;
538 void set_force(float force
) { force_
= force
; }
541 // The identity (typically finger) of the touch starting at 0 and incrementing
542 // for each separable additional touch that the hardware can detect.
545 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown.
548 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown.
551 // Angle of the major axis away from the X axis. Default 0.0.
552 float rotation_angle_
;
554 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
558 // An interface that individual platforms can use to store additional data on
561 // Currently only used in mojo.
562 class EVENTS_EXPORT ExtendedKeyEventData
{
564 virtual ~ExtendedKeyEventData() {}
566 virtual ExtendedKeyEventData
* Clone() const = 0;
569 // A KeyEvent is really two distinct classes, melded together due to the
570 // DOM legacy of Windows key events: a keystroke event (is_char_ == false),
571 // or a character event (is_char_ == true).
573 // For a keystroke event,
574 // -- is_char_ is false.
575 // -- type() can be any one of ET_KEY_PRESSED, ET_KEY_RELEASED,
576 // ET_TRANSLATED_KEY_PRESS, or ET_TRANSLATED_KEY_RELEASE.
577 // -- character_ functions as a bypass or cache for GetCharacter().
578 // -- key_code_ is a VKEY_ value associated with the key. For printable
579 // characters, this may or may not be a mapped value, imitating MS Windows:
580 // if the mapped key generates a character that has an associated VKEY_
581 // code, then key_code_ is that code; if not, then key_code_ is the unmapped
582 // VKEY_ code. For example, US, Greek, Cyrillic, Japanese, etc. all use
583 // VKEY_Q for the key beside Tab, while French uses VKEY_A.
584 // -- code_ is in one-to-one correspondence with a physical keyboard
585 // location, and does not vary depending on key layout.
587 // For a character event,
588 // -- is_char_ is true.
589 // -- type() is ET_KEY_PRESSED.
590 // -- character_ is a UTF-16 character value.
591 // -- key_code_ is conflated with character_ by some code, because both
592 // arrive in the wParam field of a Windows event.
593 // -- code_ is the empty string.
595 class EVENTS_EXPORT KeyEvent
: public Event
{
597 // Create a KeyEvent from a NativeEvent. For Windows this native event can
598 // be either a keystroke message (WM_KEYUP/WM_KEYDOWN) or a character message
599 // (WM_CHAR). Other systems have only keystroke events.
600 explicit KeyEvent(const base::NativeEvent
& native_event
);
602 // Create a keystroke event.
603 KeyEvent(EventType type
, KeyboardCode key_code
, int flags
);
605 // Create a character event.
606 KeyEvent(base::char16 character
, KeyboardCode key_code
, int flags
);
608 // Used for synthetic events with code of DOM KeyboardEvent (e.g. 'KeyA')
609 // See also: ui/events/keycodes/dom4/keycode_converter_data.h
610 KeyEvent(EventType type
,
611 KeyboardCode key_code
,
612 const std::string
& code
,
615 KeyEvent(const KeyEvent
& rhs
);
617 KeyEvent
& operator=(const KeyEvent
& rhs
);
619 ~KeyEvent() override
;
621 // TODO(erg): While we transition to mojo, we have to hack around a mismatch
622 // in our event types. Our ui::Events don't really have all the data we need
623 // to process key events, and we instead do per-platform conversions with
624 // native HWNDs or XEvents. And we can't reliably send those native data
625 // types across mojo types in a cross-platform way. So instead, we set the
626 // resulting data when read across IPC boundaries.
627 void SetExtendedKeyEventData(scoped_ptr
<ExtendedKeyEventData
> data
);
628 const ExtendedKeyEventData
* extended_key_event_data() const {
629 return extended_key_event_data_
.get();
632 // This bypasses the normal mapping from keystroke events to characters,
633 // which allows an I18N virtual keyboard to fabricate a keyboard event that
634 // does not have a corresponding KeyboardCode (example: U+00E1 Latin small
635 // letter A with acute, U+0410 Cyrillic capital letter A).
636 void set_character(base::char16 character
) { character_
= character
; }
638 // Gets the character generated by this key event. It only supports Unicode
640 base::char16
GetCharacter() const;
642 // If this is a keystroke event with key_code_ VKEY_RETURN, returns '\r';
643 // otherwise returns the same as GetCharacter().
644 base::char16
GetUnmodifiedText() const;
646 // If the Control key is down in the event, returns a layout-independent
647 // character (corresponding to US layout); otherwise returns the same
648 // as GetUnmodifiedText().
649 base::char16
GetText() const;
651 // Gets the platform key code. For XKB, this is the xksym value.
652 void set_platform_keycode(uint32 keycode
) { platform_keycode_
= keycode
; }
653 uint32
platform_keycode() const { return platform_keycode_
; }
655 // Gets the associated (Windows-based) KeyboardCode for this key event.
656 // Historically, this has also been used to obtain the character associated
657 // with a character event, because both use the Window message 'wParam' field.
658 // This should be avoided; if necessary for backwards compatibility, use
659 // GetConflatedWindowsKeyCode().
660 KeyboardCode
key_code() const { return key_code_
; }
662 // True if this is a character event, false if this is a keystroke event.
663 bool is_char() const { return is_char_
; }
665 // This is only intended to be used externally by classes that are modifying
666 // events in an EventRewriter.
667 void set_key_code(KeyboardCode key_code
) { key_code_
= key_code
; }
669 // Returns the same value as key_code(), except that located codes are
670 // returned in place of non-located ones (e.g. VKEY_LSHIFT or VKEY_RSHIFT
671 // instead of VKEY_SHIFT). This is a hybrid of semantic and physical
672 // for legacy DOM reasons.
673 KeyboardCode
GetLocatedWindowsKeyboardCode() const;
675 // For a keystroke event, returns the same value as key_code().
676 // For a character event, returns the same value as GetCharacter().
677 // This exists for backwards compatibility with Windows key events.
678 uint16
GetConflatedWindowsKeyCode() const;
680 // Returns true for [Alt]+<num-pad digit> Unicode alt key codes used by Win.
681 // TODO(msw): Additional work may be needed for analogues on other platforms.
682 bool IsUnicodeKeyCode() const;
684 std::string
code() const { return code_
; }
686 // Normalizes flags_ so that it describes the state after the event.
687 // (Native X11 event flags describe the state before the event.)
688 void NormalizeFlags();
690 // Returns true if the key event has already been processed by an input method
691 // and there is no need to pass the key event to the input method again.
692 bool IsTranslated() const;
693 // Marks this key event as translated or not translated.
694 void SetTranslated(bool translated
);
697 friend class KeyEventTestApi
;
699 // This allows a subclass TranslatedKeyEvent to be a non character event.
700 void set_is_char(bool is_char
) { is_char_
= is_char
; }
703 // True if the key press originated from a 'right' key (VKEY_RSHIFT, etc.).
704 bool IsRightSideKey() const;
706 KeyboardCode key_code_
;
708 // String of 'code' defined in DOM KeyboardEvent (e.g. 'KeyA', 'Space')
709 // http://www.w3.org/TR/uievents/#keyboard-key-codes.
711 // This value represents the physical position in the keyboard and can be
712 // converted from / to keyboard scan code like XKB.
715 // True if this is a character event, false if this is a keystroke event.
718 // The platform related keycode value. For XKB, it's keysym value.
719 // For now, this is used for CharacterComposer in ChromeOS.
720 uint32 platform_keycode_
;
722 // String of 'key' defined in DOM KeyboardEvent (e.g. 'a', 'รข')
723 // http://www.w3.org/TR/uievents/#keyboard-key-codes.
725 // This value represents the text that the key event will insert to input
726 // field. For key with modifier key, it may have specifial text.
727 // e.g. CTRL+A has '\x01'.
728 mutable base::char16 character_
;
730 // Parts of our event handling require raw native events (see both the
731 // windows and linux implementations of web_input_event in content/). Because
732 // mojo instead serializes and deserializes events in potentially different
733 // processes, we need to have a mechanism to keep track of this data.
734 scoped_ptr
<ExtendedKeyEventData
> extended_key_event_data_
;
736 static bool IsRepeated(const KeyEvent
& event
);
738 static KeyEvent
* last_key_event_
;
741 class EVENTS_EXPORT ScrollEvent
: public MouseEvent
{
743 explicit ScrollEvent(const base::NativeEvent
& native_event
);
745 ScrollEvent(const ScrollEvent
& model
,
748 : MouseEvent(model
, source
, target
),
749 x_offset_(model
.x_offset_
),
750 y_offset_(model
.y_offset_
),
751 x_offset_ordinal_(model
.x_offset_ordinal_
),
752 y_offset_ordinal_(model
.y_offset_ordinal_
),
753 finger_count_(model
.finger_count_
){
757 ScrollEvent(EventType type
,
758 const gfx::PointF
& location
,
759 base::TimeDelta time_stamp
,
763 float x_offset_ordinal
,
764 float y_offset_ordinal
,
767 // Scale the scroll event's offset value.
768 // This is useful in the multi-monitor setup where it needs to be scaled
769 // to provide a consistent user experience.
770 void Scale(const float factor
);
772 float x_offset() const { return x_offset_
; }
773 float y_offset() const { return y_offset_
; }
774 float x_offset_ordinal() const { return x_offset_ordinal_
; }
775 float y_offset_ordinal() const { return y_offset_ordinal_
; }
776 int finger_count() const { return finger_count_
; }
779 // Potential accelerated offsets.
782 // Unaccelerated offsets.
783 float x_offset_ordinal_
;
784 float y_offset_ordinal_
;
785 // Number of fingers on the pad.
789 class EVENTS_EXPORT GestureEvent
: public LocatedEvent
{
791 GestureEvent(float x
,
794 base::TimeDelta time_stamp
,
795 const GestureEventDetails
& details
);
797 // Create a new GestureEvent which is identical to the provided model.
798 // If source / target windows are provided, the model location will be
799 // converted from |source| coordinate system to |target| coordinate system.
800 template <typename T
>
801 GestureEvent(const GestureEvent
& model
, T
* source
, T
* target
)
802 : LocatedEvent(model
, source
, target
),
803 details_(model
.details_
) {
806 ~GestureEvent() override
;
808 const GestureEventDetails
& details() const { return details_
; }
811 GestureEventDetails details_
;
816 #endif // UI_EVENTS_EVENT_H_