Add ICU message format support
[chromium-blink-merge.git] / ui / events / event_utils.h
blob2913a3140b289bfc8b68de0a49a68fa52c0851ca
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 // Common functions to be used for all platforms except Android.
32 namespace ui {
34 class Event;
35 class MouseEvent;
36 enum class DomCode;
38 // Updates the list of devices for cached properties.
39 EVENTS_EXPORT void UpdateDeviceList();
41 // Returns a ui::Event wrapping a native event. Ownership of the returned value
42 // is transferred to the caller.
43 EVENTS_EXPORT scoped_ptr<Event> EventFromNative(
44 const base::NativeEvent& native_event);
46 // Get the EventType from a native event.
47 EVENTS_EXPORT EventType EventTypeFromNative(
48 const base::NativeEvent& native_event);
50 // Get the EventFlags from a native event.
51 EVENTS_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event);
53 // Get the timestamp from a native event.
54 EVENTS_EXPORT base::TimeDelta EventTimeFromNative(
55 const base::NativeEvent& native_event);
57 // Create a timestamp based on the current time.
58 EVENTS_EXPORT base::TimeDelta EventTimeForNow();
60 // Get the location from a native event. The coordinate system of the resultant
61 // |Point| has the origin at top-left of the "root window". The nature of
62 // this "root window" and how it maps to platform-specific drawing surfaces is
63 // defined in ui/aura/root_window.* and ui/aura/window_tree_host*.
64 // TODO(tdresser): Return gfx::PointF here. See crbug.com/337827.
65 EVENTS_EXPORT gfx::Point EventLocationFromNative(
66 const base::NativeEvent& native_event);
68 // Gets the location in native system coordinate space.
69 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative(
70 const base::NativeEvent& native_event);
72 #if defined(USE_X11)
73 // Returns the 'real' button for an event. The button reported in slave events
74 // does not take into account any remapping (e.g. using xmodmap), while the
75 // button reported in master events do. This is a utility function to always
76 // return the mapped button.
77 EVENTS_EXPORT int EventButtonFromNative(const base::NativeEvent& native_event);
78 #endif
80 // Returns the KeyboardCode from a native event.
81 EVENTS_EXPORT KeyboardCode KeyboardCodeFromNative(
82 const base::NativeEvent& native_event);
84 // Returns the DOM KeyboardEvent code (physical location in the
85 // keyboard) from a native event.
86 EVENTS_EXPORT DomCode CodeFromNative(const base::NativeEvent& native_event);
88 // Returns the platform related key code (interpretation, not scan code).
89 // For X11 and xkbcommon, this is the KeySym value.
90 EVENTS_EXPORT uint32 PlatformKeycodeFromNative(
91 const base::NativeEvent& native_event);
93 // Returns true if the keyboard event is a character event rather than
94 // a keystroke event.
95 EVENTS_EXPORT bool IsCharFromNative(const base::NativeEvent& native_event);
97 // Returns the flags of the button that changed during a press/release.
98 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative(
99 const base::NativeEvent& native_event);
101 // Gets the mouse wheel offsets from a native event.
102 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset(
103 const base::NativeEvent& native_event);
105 // Returns a copy of |native_event|. Depending on the platform, this copy may
106 // need to be deleted with ReleaseCopiedNativeEvent().
107 base::NativeEvent CopyNativeEvent(
108 const base::NativeEvent& native_event);
110 // Delete a |native_event| previously created by CopyNativeEvent().
111 void ReleaseCopiedNativeEvent(
112 const base::NativeEvent& native_event);
114 // Gets the touch id from a native event.
115 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event);
117 // Clear the touch id from bookkeeping if it is a release/cancel event.
118 EVENTS_EXPORT void ClearTouchIdIfReleased(
119 const base::NativeEvent& native_event);
121 // Gets the radius along the X/Y axis from a native event. Default is 1.0.
122 EVENTS_EXPORT float GetTouchRadiusX(const base::NativeEvent& native_event);
123 EVENTS_EXPORT float GetTouchRadiusY(const base::NativeEvent& native_event);
125 // Gets the angle of the major axis away from the X axis. Default is 0.0.
126 EVENTS_EXPORT float GetTouchAngle(const base::NativeEvent& native_event);
128 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0.
129 EVENTS_EXPORT float GetTouchForce(const base::NativeEvent& native_event);
131 // Gets the fling velocity from a native event. is_cancel is set to true if
132 // this was a tap down, intended to stop an ongoing fling.
133 EVENTS_EXPORT bool GetFlingData(const base::NativeEvent& native_event,
134 float* vx,
135 float* vy,
136 float* vx_ordinal,
137 float* vy_ordinal,
138 bool* is_cancel);
140 // Returns whether this is a scroll event and optionally gets the amount to be
141 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL.
142 EVENTS_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event,
143 float* x_offset,
144 float* y_offset,
145 float* x_offset_ordinal,
146 float* y_offset_ordinal,
147 int* finger_count);
149 // Returns whether natural scrolling should be used for touchpad.
150 EVENTS_EXPORT bool ShouldDefaultToNaturalScroll();
152 // Returns whether or not the internal display produces touch events.
153 EVENTS_EXPORT gfx::Display::TouchSupport GetInternalDisplayTouchSupport();
155 #if defined(OS_WIN)
156 EVENTS_EXPORT int GetModifiersFromACCEL(const ACCEL& accel);
157 EVENTS_EXPORT int GetModifiersFromKeyState();
159 // Returns true if |message| identifies a mouse event that was generated as the
160 // result of a touch event.
161 EVENTS_EXPORT bool IsMouseEventFromTouch(UINT message);
163 // Converts scan code and lParam each other. The scan code
164 // representing an extended key contains 0xE000 bits.
165 EVENTS_EXPORT uint16 GetScanCodeFromLParam(LPARAM lParam);
166 EVENTS_EXPORT LPARAM GetLParamFromScanCode(uint16 scan_code);
168 #endif
170 #if defined(USE_X11)
171 // Update the native X11 event to correspond to the new flags.
172 EVENTS_EXPORT void UpdateX11EventForFlags(Event* event);
173 // Update the native X11 event to correspond to the new button flags.
174 EVENTS_EXPORT void UpdateX11EventForChangedButtonFlags(MouseEvent* event);
175 #endif
177 // Registers a custom event type.
178 EVENTS_EXPORT int RegisterCustomEventType();
180 } // namespace ui
182 #endif // UI_EVENTS_EVENT_UTILS_H_