Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / events / event_utils.h
blobe9c9093a95bd6cbe3f6b4ba9964be7a2cc9887ab
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/basictypes.h"
9 #include "base/event_types.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string16.h"
12 #include "ui/events/event_constants.h"
13 #include "ui/events/keycodes/keyboard_codes.h"
14 #include "ui/gfx/display.h"
15 #include "ui/gfx/native_widget_types.h"
16 #include "ui/events/events_export.h"
18 #if defined(OS_WIN)
19 #include <windows.h>
20 #endif
22 namespace gfx {
23 class Point;
24 class Vector2d;
27 namespace base {
28 class TimeDelta;
31 namespace ui {
33 class Event;
34 class MouseEvent;
35 enum class DomCode;
37 // Updates the list of devices for cached properties.
38 EVENTS_EXPORT void UpdateDeviceList();
40 // Returns a ui::Event wrapping a native event. Ownership of the returned value
41 // is transferred to the caller.
42 EVENTS_EXPORT scoped_ptr<Event> EventFromNative(
43 const base::NativeEvent& native_event);
45 // Get the EventType from a native event.
46 EVENTS_EXPORT EventType EventTypeFromNative(
47 const base::NativeEvent& native_event);
49 // Get the EventFlags from a native event.
50 EVENTS_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event);
52 // Get the timestamp from a native event.
53 EVENTS_EXPORT base::TimeDelta EventTimeFromNative(
54 const base::NativeEvent& native_event);
56 // Create a timestamp based on the current time.
57 EVENTS_EXPORT base::TimeDelta EventTimeForNow();
59 // Get the location from a native event. The coordinate system of the resultant
60 // |Point| has the origin at top-left of the "root window". The nature of
61 // this "root window" and how it maps to platform-specific drawing surfaces is
62 // defined in ui/aura/root_window.* and ui/aura/window_tree_host*.
63 // TODO(tdresser): Return gfx::PointF here. See crbug.com/337827.
64 EVENTS_EXPORT gfx::Point EventLocationFromNative(
65 const base::NativeEvent& native_event);
67 // Gets the location in native system coordinate space.
68 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative(
69 const base::NativeEvent& native_event);
71 #if defined(USE_X11)
72 // Returns the 'real' button for an event. The button reported in slave events
73 // does not take into account any remapping (e.g. using xmodmap), while the
74 // button reported in master events do. This is a utility function to always
75 // return the mapped button.
76 EVENTS_EXPORT int EventButtonFromNative(const base::NativeEvent& native_event);
77 #endif
79 // Returns the KeyboardCode from a native event.
80 EVENTS_EXPORT KeyboardCode KeyboardCodeFromNative(
81 const base::NativeEvent& native_event);
83 // Returns the DOM KeyboardEvent code (physical location in the
84 // keyboard) from a native event.
85 EVENTS_EXPORT DomCode CodeFromNative(const base::NativeEvent& native_event);
87 // Returns the platform related key code (interpretation, not scan code).
88 // For X11 and xkbcommon, this is the KeySym value.
89 EVENTS_EXPORT uint32 PlatformKeycodeFromNative(
90 const base::NativeEvent& native_event);
92 // Returns true if the keyboard event is a character event rather than
93 // a keystroke event.
94 EVENTS_EXPORT bool IsCharFromNative(const base::NativeEvent& native_event);
96 // Returns the flags of the button that changed during a press/release.
97 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative(
98 const base::NativeEvent& native_event);
100 // Gets the mouse wheel offsets from a native event.
101 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset(
102 const base::NativeEvent& native_event);
104 // Returns a copy of |native_event|. Depending on the platform, this copy may
105 // need to be deleted with ReleaseCopiedNativeEvent().
106 base::NativeEvent CopyNativeEvent(
107 const base::NativeEvent& native_event);
109 // Delete a |native_event| previously created by CopyNativeEvent().
110 void ReleaseCopiedNativeEvent(
111 const base::NativeEvent& native_event);
113 // Gets the touch id from a native event.
114 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event);
116 // Clear the touch id from bookkeeping if it is a release/cancel event.
117 EVENTS_EXPORT void ClearTouchIdIfReleased(
118 const base::NativeEvent& native_event);
120 // Gets the radius along the X/Y axis from a native event. Default is 1.0.
121 EVENTS_EXPORT float GetTouchRadiusX(const base::NativeEvent& native_event);
122 EVENTS_EXPORT float GetTouchRadiusY(const base::NativeEvent& native_event);
124 // Gets the angle of the major axis away from the X axis. Default is 0.0.
125 EVENTS_EXPORT float GetTouchAngle(const base::NativeEvent& native_event);
127 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0.
128 EVENTS_EXPORT float GetTouchForce(const base::NativeEvent& native_event);
130 // Gets the fling velocity from a native event. is_cancel is set to true if
131 // this was a tap down, intended to stop an ongoing fling.
132 EVENTS_EXPORT bool GetFlingData(const base::NativeEvent& native_event,
133 float* vx,
134 float* vy,
135 float* vx_ordinal,
136 float* vy_ordinal,
137 bool* is_cancel);
139 // Returns whether this is a scroll event and optionally gets the amount to be
140 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL.
141 EVENTS_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event,
142 float* x_offset,
143 float* y_offset,
144 float* x_offset_ordinal,
145 float* y_offset_ordinal,
146 int* finger_count);
148 // Returns whether natural scrolling should be used for touchpad.
149 EVENTS_EXPORT bool ShouldDefaultToNaturalScroll();
151 // Returns whether or not the internal display produces touch events.
152 EVENTS_EXPORT gfx::Display::TouchSupport GetInternalDisplayTouchSupport();
154 #if defined(OS_WIN)
155 EVENTS_EXPORT int GetModifiersFromACCEL(const ACCEL& accel);
156 EVENTS_EXPORT int GetModifiersFromKeyState();
158 // Returns true if |message| identifies a mouse event that was generated as the
159 // result of a touch event.
160 EVENTS_EXPORT bool IsMouseEventFromTouch(UINT message);
162 // Converts scan code and lParam each other. The scan code
163 // representing an extended key contains 0xE000 bits.
164 EVENTS_EXPORT uint16 GetScanCodeFromLParam(LPARAM lParam);
165 EVENTS_EXPORT LPARAM GetLParamFromScanCode(uint16 scan_code);
167 #endif
169 #if defined(USE_X11)
170 // Update the native X11 event to correspond to the new flags.
171 EVENTS_EXPORT void UpdateX11EventForFlags(Event* event);
172 // Update the native X11 event to correspond to the new button flags.
173 EVENTS_EXPORT void UpdateX11EventForChangedButtonFlags(MouseEvent* event);
174 #endif
176 // Registers a custom event type.
177 EVENTS_EXPORT int RegisterCustomEventType();
179 } // namespace ui
181 #endif // UI_EVENTS_EVENT_UTILS_H_