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"
34 // Updates the list of devices for cached properties.
35 EVENTS_EXPORT void UpdateDeviceList();
37 // Returns a ui::Event wrapping a native event. Ownership of the returned value
38 // is transferred to the caller.
39 EVENTS_EXPORT scoped_ptr<Event> EventFromNative(
40 const base::NativeEvent& native_event);
42 // Get the EventType from a native event.
43 EVENTS_EXPORT EventType EventTypeFromNative(
44 const base::NativeEvent& native_event);
46 // Get the EventFlags from a native event.
47 EVENTS_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event);
49 // Get the timestamp from a native event.
50 EVENTS_EXPORT base::TimeDelta EventTimeFromNative(
51 const base::NativeEvent& native_event);
53 // Create a timestamp based on the current time.
54 EVENTS_EXPORT base::TimeDelta EventTimeForNow();
56 // Get the location from a native event. The coordinate system of the resultant
57 // |Point| has the origin at top-left of the "root window". The nature of
58 // this "root window" and how it maps to platform-specific drawing surfaces is
59 // defined in ui/aura/root_window.* and ui/aura/window_tree_host*.
60 // TODO(tdresser): Return gfx::PointF here. See crbug.com/337827.
61 EVENTS_EXPORT gfx::Point EventLocationFromNative(
62 const base::NativeEvent& native_event);
64 // Gets the location in native system coordinate space.
65 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative(
66 const base::NativeEvent& native_event);
69 // Returns the 'real' button for an event. The button reported in slave events
70 // does not take into account any remapping (e.g. using xmodmap), while the
71 // button reported in master events do. This is a utility function to always
72 // return the mapped button.
73 EVENTS_EXPORT int EventButtonFromNative(const base::NativeEvent& native_event);
76 // Returns the KeyboardCode from a native event.
77 EVENTS_EXPORT KeyboardCode KeyboardCodeFromNative(
78 const base::NativeEvent& native_event);
80 // Returns the DOM KeyboardEvent code (physical location in the
81 // keyboard) from a native event. The ownership of the return value
82 // is NOT trasferred to the caller.
83 EVENTS_EXPORT const char* CodeFromNative(
84 const base::NativeEvent& native_event);
86 // Returns the platform related key code. For X11, it is xksym value.
87 EVENTS_EXPORT uint32 PlatformKeycodeFromNative(
88 const base::NativeEvent& native_event);
90 // Returns true if the keyboard event is a character event rather than
92 EVENTS_EXPORT bool IsCharFromNative(const base::NativeEvent& native_event);
94 // Returns the flags of the button that changed during a press/release.
95 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative(
96 const base::NativeEvent& native_event);
98 // Gets the mouse wheel offsets from a native event.
99 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset(
100 const base::NativeEvent& native_event);
102 // Returns a copy of |native_event|. Depending on the platform, this copy may
103 // need to be deleted with ReleaseCopiedNativeEvent().
104 base::NativeEvent CopyNativeEvent(
105 const base::NativeEvent& native_event);
107 // Delete a |native_event| previously created by CopyNativeEvent().
108 void ReleaseCopiedNativeEvent(
109 const base::NativeEvent& native_event);
111 // Gets the touch id from a native event.
112 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event);
114 // Increases the number of times |ClearTouchIdIfReleased| needs to be called on
115 // an event with a given touch id before it will actually be cleared.
116 EVENTS_EXPORT void IncrementTouchIdRefCount(
117 const base::NativeEvent& native_event);
119 // Clear the touch id from bookkeeping if it is a release/cancel event.
120 EVENTS_EXPORT void ClearTouchIdIfReleased(
121 const base::NativeEvent& native_event);
123 // Gets the radius along the X/Y axis from a native event. Default is 1.0.
124 EVENTS_EXPORT float GetTouchRadiusX(const base::NativeEvent& native_event);
125 EVENTS_EXPORT float GetTouchRadiusY(const base::NativeEvent& native_event);
127 // Gets the angle of the major axis away from the X axis. Default is 0.0.
128 EVENTS_EXPORT float GetTouchAngle(const base::NativeEvent& native_event);
130 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0.
131 EVENTS_EXPORT float GetTouchForce(const base::NativeEvent& native_event);
133 // Gets the fling velocity from a native event. is_cancel is set to true if
134 // this was a tap down, intended to stop an ongoing fling.
135 EVENTS_EXPORT bool GetFlingData(const base::NativeEvent& native_event,
142 // Returns whether this is a scroll event and optionally gets the amount to be
143 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL.
144 EVENTS_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event,
147 float* x_offset_ordinal,
148 float* y_offset_ordinal,
151 // Returns whether natural scrolling should be used for touchpad.
152 EVENTS_EXPORT bool ShouldDefaultToNaturalScroll();
154 // Returns whether or not the internal display produces touch events.
155 EVENTS_EXPORT gfx::Display::TouchSupport GetInternalDisplayTouchSupport();
158 EVENTS_EXPORT int GetModifiersFromACCEL(const ACCEL& accel);
159 EVENTS_EXPORT int GetModifiersFromKeyState();
161 // Returns true if |message| identifies a mouse event that was generated as the
162 // result of a touch event.
163 EVENTS_EXPORT bool IsMouseEventFromTouch(UINT message);
165 // Converts scan code and lParam each other. The scan code
166 // representing an extended key contains 0xE000 bits.
167 EVENTS_EXPORT uint16 GetScanCodeFromLParam(LPARAM lParam);
168 EVENTS_EXPORT LPARAM GetLParamFromScanCode(uint16 scan_code);
173 // Update the native X11 event to correspond to the new flags.
174 EVENTS_EXPORT void UpdateX11EventForFlags(Event* event);
175 // Update the native X11 event to correspond to the new button flags.
176 EVENTS_EXPORT void UpdateX11EventForChangedButtonFlags(MouseEvent* event);
179 // Registers a custom event type.
180 EVENTS_EXPORT int RegisterCustomEventType();
184 #endif // UI_EVENTS_EVENT_UTILS_H_