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_UTILS_H_
6 #define UI_EVENTS_EVENT_UTILS_H_
8 #include "base/event_types.h"
9 #include "ui/events/event_constants.h"
10 #include "ui/events/keycodes/keyboard_codes.h"
11 #include "ui/gfx/native_widget_types.h"
12 #include "ui/events/events_export.h"
31 // Updates the list of devices for cached properties.
32 EVENTS_EXPORT
void UpdateDeviceList();
34 // Get the EventType from a native event.
35 EVENTS_EXPORT EventType
EventTypeFromNative(
36 const base::NativeEvent
& native_event
);
38 // Get the EventFlags from a native event.
39 EVENTS_EXPORT
int EventFlagsFromNative(const base::NativeEvent
& native_event
);
41 // Get the timestamp from a native event.
42 EVENTS_EXPORT
base::TimeDelta
EventTimeFromNative(
43 const base::NativeEvent
& native_event
);
45 // Create a timestamp based on the current time.
46 EVENTS_EXPORT
base::TimeDelta
EventTimeForNow();
48 // Get the location from a native event. The coordinate system of the resultant
49 // |Point| has the origin at top-left of the "root window". The nature of
50 // this "root window" and how it maps to platform-specific drawing surfaces is
51 // defined in ui/aura/root_window.* and ui/aura/root_window_host*.
52 EVENTS_EXPORT
gfx::Point
EventLocationFromNative(
53 const base::NativeEvent
& native_event
);
55 // Gets the location in native system coordinate space.
56 EVENTS_EXPORT
gfx::Point
EventSystemLocationFromNative(
57 const base::NativeEvent
& native_event
);
60 // Returns the 'real' button for an event. The button reported in slave events
61 // does not take into account any remapping (e.g. using xmodmap), while the
62 // button reported in master events do. This is a utility function to always
63 // return the mapped button.
64 EVENTS_EXPORT
int EventButtonFromNative(const base::NativeEvent
& native_event
);
67 // Returns the KeyboardCode from a native event.
68 EVENTS_EXPORT KeyboardCode
KeyboardCodeFromNative(
69 const base::NativeEvent
& native_event
);
71 // Returns true if the message is a mouse event.
72 EVENTS_EXPORT
bool IsMouseEvent(const base::NativeEvent
& native_event
);
74 // Returns the flags of the button that changed during a press/release.
75 EVENTS_EXPORT
int GetChangedMouseButtonFlagsFromNative(
76 const base::NativeEvent
& native_event
);
78 // Gets the mouse wheel offsets from a native event.
79 EVENTS_EXPORT
gfx::Vector2d
GetMouseWheelOffset(
80 const base::NativeEvent
& native_event
);
82 // Gets the touch id from a native event.
83 EVENTS_EXPORT
int GetTouchId(const base::NativeEvent
& native_event
);
85 // Clear the touch id from bookkeeping if it is a release/cancel event.
86 EVENTS_EXPORT
void ClearTouchIdIfReleased(
87 const base::NativeEvent
& native_event
);
89 // Gets the radius along the X/Y axis from a native event. Default is 1.0.
90 EVENTS_EXPORT
float GetTouchRadiusX(const base::NativeEvent
& native_event
);
91 EVENTS_EXPORT
float GetTouchRadiusY(const base::NativeEvent
& native_event
);
93 // Gets the angle of the major axis away from the X axis. Default is 0.0.
94 EVENTS_EXPORT
float GetTouchAngle(const base::NativeEvent
& native_event
);
96 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0.
97 EVENTS_EXPORT
float GetTouchForce(const base::NativeEvent
& native_event
);
99 // Gets the fling velocity from a native event. is_cancel is set to true if
100 // this was a tap down, intended to stop an ongoing fling.
101 EVENTS_EXPORT
bool GetFlingData(const base::NativeEvent
& native_event
,
108 // Returns whether this is a scroll event and optionally gets the amount to be
109 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL.
110 EVENTS_EXPORT
bool GetScrollOffsets(const base::NativeEvent
& native_event
,
113 float* x_offset_ordinal
,
114 float* y_offset_ordinal
,
117 EVENTS_EXPORT
bool GetGestureTimes(const base::NativeEvent
& native_event
,
121 // Enable/disable natural scrolling for touchpads.
122 EVENTS_EXPORT
void SetNaturalScroll(bool enabled
);
124 // In natural scrolling enabled for touchpads?
125 EVENTS_EXPORT
bool IsNaturalScrollEnabled();
127 // Returns whether natural scrolling should be used for touchpad.
128 EVENTS_EXPORT
bool ShouldDefaultToNaturalScroll();
130 // Was this event generated by a touchpad device?
131 // The caller is responsible for ensuring that this is a mouse/touchpad event
132 // before calling this function.
133 EVENTS_EXPORT
bool IsTouchpadEvent(const base::NativeEvent
& event
);
135 // Returns true if event is noop.
136 EVENTS_EXPORT
bool IsNoopEvent(const base::NativeEvent
& event
);
138 // Creates and returns no-op event.
139 EVENTS_EXPORT
base::NativeEvent
CreateNoopEvent();
142 EVENTS_EXPORT
int GetModifiersFromACCEL(const ACCEL
& accel
);
143 EVENTS_EXPORT
int GetModifiersFromKeyState();
145 // Returns true if |message| identifies a mouse event that was generated as the
146 // result of a touch event.
147 EVENTS_EXPORT
bool IsMouseEventFromTouch(UINT message
);
150 // Returns true if default post-target handling was canceled for |event| after
151 // its dispatch to its target.
152 EVENTS_EXPORT
bool EventCanceledDefaultHandling(const Event
& event
);
154 // Registers a custom event type.
155 EVENTS_EXPORT
int RegisterCustomEventType();
159 #endif // UI_EVENTS_EVENT_UTILS_H_