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 "base/memory/scoped_ptr.h"
10 #include "ui/events/event_constants.h"
11 #include "ui/events/keycodes/keyboard_codes.h"
12 #include "ui/gfx/display.h"
13 #include "ui/gfx/native_widget_types.h"
14 #include "ui/events/events_export.h"
33 // Updates the list of devices for cached properties.
34 EVENTS_EXPORT
void UpdateDeviceList();
36 // Returns a ui::Event wrapping a native event. Ownership of the returned value
37 // is transferred to the caller.
38 EVENTS_EXPORT scoped_ptr
<Event
> EventFromNative(
39 const base::NativeEvent
& native_event
);
41 // Get the EventType from a native event.
42 EVENTS_EXPORT EventType
EventTypeFromNative(
43 const base::NativeEvent
& native_event
);
45 // Get the EventFlags from a native event.
46 EVENTS_EXPORT
int EventFlagsFromNative(const base::NativeEvent
& native_event
);
48 // Get the timestamp from a native event.
49 EVENTS_EXPORT
base::TimeDelta
EventTimeFromNative(
50 const base::NativeEvent
& native_event
);
52 // Create a timestamp based on the current time.
53 EVENTS_EXPORT
base::TimeDelta
EventTimeForNow();
55 // Get the location from a native event. The coordinate system of the resultant
56 // |Point| has the origin at top-left of the "root window". The nature of
57 // this "root window" and how it maps to platform-specific drawing surfaces is
58 // defined in ui/aura/root_window.* and ui/aura/window_tree_host*.
59 // TODO(tdresser): Return gfx::PointF here. See crbug.com/337827.
60 EVENTS_EXPORT
gfx::Point
EventLocationFromNative(
61 const base::NativeEvent
& native_event
);
63 // Gets the location in native system coordinate space.
64 EVENTS_EXPORT
gfx::Point
EventSystemLocationFromNative(
65 const base::NativeEvent
& native_event
);
68 // Returns the 'real' button for an event. The button reported in slave events
69 // does not take into account any remapping (e.g. using xmodmap), while the
70 // button reported in master events do. This is a utility function to always
71 // return the mapped button.
72 EVENTS_EXPORT
int EventButtonFromNative(const base::NativeEvent
& native_event
);
75 // Returns the KeyboardCode from a native event.
76 EVENTS_EXPORT KeyboardCode
KeyboardCodeFromNative(
77 const base::NativeEvent
& native_event
);
79 // Returns the DOM KeyboardEvent code (physical location in the
80 // keyboard) from a native event. The ownership of the return value
81 // is NOT trasferred to the caller.
82 EVENTS_EXPORT
const char* CodeFromNative(
83 const base::NativeEvent
& native_event
);
85 // Returns the platform related key code. For X11, it is xksym value.
86 EVENTS_EXPORT uint32
PlatformKeycodeFromNative(
87 const base::NativeEvent
& native_event
);
89 // Returns the flags of the button that changed during a press/release.
90 EVENTS_EXPORT
int GetChangedMouseButtonFlagsFromNative(
91 const base::NativeEvent
& native_event
);
93 // Gets the mouse wheel offsets from a native event.
94 EVENTS_EXPORT
gfx::Vector2d
GetMouseWheelOffset(
95 const base::NativeEvent
& native_event
);
97 // Returns a copy of |native_event|. Depending on the platform, this copy may
98 // need to be deleted with ReleaseCopiedNativeEvent().
99 base::NativeEvent
CopyNativeEvent(
100 const base::NativeEvent
& native_event
);
102 // Delete a |native_event| previously created by CopyNativeEvent().
103 void ReleaseCopiedNativeEvent(
104 const base::NativeEvent
& native_event
);
106 // Gets the touch id from a native event.
107 EVENTS_EXPORT
int GetTouchId(const base::NativeEvent
& native_event
);
109 // Clear the touch id from bookkeeping if it is a release/cancel event.
110 EVENTS_EXPORT
void ClearTouchIdIfReleased(
111 const base::NativeEvent
& native_event
);
113 // Gets the radius along the X/Y axis from a native event. Default is 1.0.
114 EVENTS_EXPORT
float GetTouchRadiusX(const base::NativeEvent
& native_event
);
115 EVENTS_EXPORT
float GetTouchRadiusY(const base::NativeEvent
& native_event
);
117 // Gets the angle of the major axis away from the X axis. Default is 0.0.
118 EVENTS_EXPORT
float GetTouchAngle(const base::NativeEvent
& native_event
);
120 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0.
121 EVENTS_EXPORT
float GetTouchForce(const base::NativeEvent
& native_event
);
123 // Gets the fling velocity from a native event. is_cancel is set to true if
124 // this was a tap down, intended to stop an ongoing fling.
125 EVENTS_EXPORT
bool GetFlingData(const base::NativeEvent
& native_event
,
132 // Returns whether this is a scroll event and optionally gets the amount to be
133 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL.
134 EVENTS_EXPORT
bool GetScrollOffsets(const base::NativeEvent
& native_event
,
137 float* x_offset_ordinal
,
138 float* y_offset_ordinal
,
141 EVENTS_EXPORT
bool GetGestureTimes(const base::NativeEvent
& native_event
,
145 // Returns whether natural scrolling should be used for touchpad.
146 EVENTS_EXPORT
bool ShouldDefaultToNaturalScroll();
148 // Returns whether or not the internal display produces touch events.
149 EVENTS_EXPORT
gfx::Display::TouchSupport
GetInternalDisplayTouchSupport();
152 EVENTS_EXPORT
int GetModifiersFromACCEL(const ACCEL
& accel
);
153 EVENTS_EXPORT
int GetModifiersFromKeyState();
155 // Returns true if |message| identifies a mouse event that was generated as the
156 // result of a touch event.
157 EVENTS_EXPORT
bool IsMouseEventFromTouch(UINT message
);
159 // Converts scan code and lParam each other. The scan code
160 // representing an extended key contains 0xE000 bits.
161 EVENTS_EXPORT uint16
GetScanCodeFromLParam(LPARAM lParam
);
162 EVENTS_EXPORT LPARAM
GetLParamFromScanCode(uint16 scan_code
);
166 // Registers a custom event type.
167 EVENTS_EXPORT
int RegisterCustomEventType();
171 #endif // UI_EVENTS_EVENT_UTILS_H_