• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef UI_EVENTS_EVENT_UTILS_H_
6 #define UI_EVENTS_EVENT_UTILS_H_
7 
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"
15 
16 #if defined(OS_WIN)
17 #include <windows.h>
18 #endif
19 
20 namespace gfx {
21 class Point;
22 class Vector2d;
23 }
24 
25 namespace base {
26 class TimeDelta;
27 }
28 
29 namespace ui {
30 
31 class Event;
32 
33 // Updates the list of devices for cached properties.
34 EVENTS_EXPORT void UpdateDeviceList();
35 
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);
40 
41 // Get the EventType from a native event.
42 EVENTS_EXPORT EventType EventTypeFromNative(
43     const base::NativeEvent& native_event);
44 
45 // Get the EventFlags from a native event.
46 EVENTS_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event);
47 
48 // Get the timestamp from a native event.
49 EVENTS_EXPORT base::TimeDelta EventTimeFromNative(
50     const base::NativeEvent& native_event);
51 
52 // Create a timestamp based on the current time.
53 EVENTS_EXPORT base::TimeDelta EventTimeForNow();
54 
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);
62 
63 // Gets the location in native system coordinate space.
64 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative(
65     const base::NativeEvent& native_event);
66 
67 #if defined(USE_X11)
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);
73 #endif
74 
75 // Returns the KeyboardCode from a native event.
76 EVENTS_EXPORT KeyboardCode KeyboardCodeFromNative(
77     const base::NativeEvent& native_event);
78 
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);
84 
85 // Returns the platform related key code. For X11, it is xksym value.
86 EVENTS_EXPORT uint32 PlatformKeycodeFromNative(
87     const base::NativeEvent& native_event);
88 
89 // Returns the flags of the button that changed during a press/release.
90 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative(
91     const base::NativeEvent& native_event);
92 
93 // Gets the mouse wheel offsets from a native event.
94 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset(
95     const base::NativeEvent& native_event);
96 
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);
101 
102 // Delete a |native_event| previously created by CopyNativeEvent().
103 void ReleaseCopiedNativeEvent(
104     const base::NativeEvent& native_event);
105 
106 // Gets the touch id from a native event.
107 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event);
108 
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);
112 
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);
116 
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);
119 
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);
122 
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,
126                             float* vx,
127                             float* vy,
128                             float* vx_ordinal,
129                             float* vy_ordinal,
130                             bool* is_cancel);
131 
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,
135                                 float* x_offset,
136                                 float* y_offset,
137                                 float* x_offset_ordinal,
138                                 float* y_offset_ordinal,
139                                 int* finger_count);
140 
141 EVENTS_EXPORT bool GetGestureTimes(const base::NativeEvent& native_event,
142                                double* start_time,
143                                double* end_time);
144 
145 // Returns whether natural scrolling should be used for touchpad.
146 EVENTS_EXPORT bool ShouldDefaultToNaturalScroll();
147 
148 // Returns whether or not the internal display produces touch events.
149 EVENTS_EXPORT gfx::Display::TouchSupport GetInternalDisplayTouchSupport();
150 
151 // Was this event generated by a touchpad device?
152 // The caller is responsible for ensuring that this is a mouse/touchpad event
153 // before calling this function.
154 EVENTS_EXPORT bool IsTouchpadEvent(const base::NativeEvent& event);
155 
156 #if defined(OS_WIN)
157 EVENTS_EXPORT int GetModifiersFromACCEL(const ACCEL& accel);
158 EVENTS_EXPORT int GetModifiersFromKeyState();
159 
160 // Returns true if |message| identifies a mouse event that was generated as the
161 // result of a touch event.
162 EVENTS_EXPORT bool IsMouseEventFromTouch(UINT message);
163 
164 // Converts scan code and lParam each other.  The scan code
165 // representing an extended key contains 0xE000 bits.
166 EVENTS_EXPORT uint16 GetScanCodeFromLParam(LPARAM lParam);
167 EVENTS_EXPORT LPARAM GetLParamFromScanCode(uint16 scan_code);
168 
169 #endif
170 
171 // Registers a custom event type.
172 EVENTS_EXPORT int RegisterCustomEventType();
173 
174 }  // namespace ui
175 
176 #endif  // UI_EVENTS_EVENT_UTILS_H_
177