Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / events / event_utils.h
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 "ui/events/event_constants.h"
10 #include "ui/events/keycodes/keyboard_codes.h"
11 #include "ui/gfx/display.h"
12 #include "ui/gfx/native_widget_types.h"
13 #include "ui/events/events_export.h"
14
15 #if defined(OS_WIN)
16 #include <windows.h>
17 #endif
18
19 namespace gfx {
20 class Point;
21 class Vector2d;
22 }
23
24 namespace base {
25 class TimeDelta;
26 }
27
28 namespace ui {
29
30 class Event;
31
32 // Updates the list of devices for cached properties.
33 EVENTS_EXPORT void UpdateDeviceList();
34
35 // Get the EventType from a native event.
36 EVENTS_EXPORT EventType EventTypeFromNative(
37     const base::NativeEvent& native_event);
38
39 // Get the EventFlags from a native event.
40 EVENTS_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event);
41
42 // Get the timestamp from a native event.
43 EVENTS_EXPORT base::TimeDelta EventTimeFromNative(
44     const base::NativeEvent& native_event);
45
46 // Create a timestamp based on the current time.
47 EVENTS_EXPORT base::TimeDelta EventTimeForNow();
48
49 // Get the location from a native event.  The coordinate system of the resultant
50 // |Point| has the origin at top-left of the "root window".  The nature of
51 // this "root window" and how it maps to platform-specific drawing surfaces is
52 // defined in ui/aura/root_window.* and ui/aura/window_tree_host*.
53 // TODO(tdresser): Return gfx::PointF here. See crbug.com/337827.
54 EVENTS_EXPORT gfx::Point EventLocationFromNative(
55     const base::NativeEvent& native_event);
56
57 // Gets the location in native system coordinate space.
58 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative(
59     const base::NativeEvent& native_event);
60
61 #if defined(USE_X11)
62 // Returns the 'real' button for an event. The button reported in slave events
63 // does not take into account any remapping (e.g. using xmodmap), while the
64 // button reported in master events do. This is a utility function to always
65 // return the mapped button.
66 EVENTS_EXPORT int EventButtonFromNative(const base::NativeEvent& native_event);
67 #endif
68
69 // Returns the KeyboardCode from a native event.
70 EVENTS_EXPORT KeyboardCode KeyboardCodeFromNative(
71     const base::NativeEvent& native_event);
72
73 // Returns the DOM KeyboardEvent code (physical location in the
74 // keyboard) from a native event.  The ownership of the return value
75 // is NOT trasferred to the caller.
76 EVENTS_EXPORT const char* CodeFromNative(
77     const base::NativeEvent& native_event);
78
79 // Returns the flags of the button that changed during a press/release.
80 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative(
81     const base::NativeEvent& native_event);
82
83 // Gets the mouse wheel offsets from a native event.
84 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset(
85     const base::NativeEvent& native_event);
86
87 // Returns a copy of |native_event|. Depending on the platform, this copy may
88 // need to be deleted with ReleaseCopiedNativeEvent().
89 base::NativeEvent CopyNativeEvent(
90     const base::NativeEvent& native_event);
91
92 // Delete a |native_event| previously created by CopyNativeEvent().
93 void ReleaseCopiedNativeEvent(
94     const base::NativeEvent& native_event);
95
96 // Gets the touch id from a native event.
97 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event);
98
99 // Clear the touch id from bookkeeping if it is a release/cancel event.
100 EVENTS_EXPORT void ClearTouchIdIfReleased(
101     const base::NativeEvent& native_event);
102
103 // Gets the radius along the X/Y axis from a native event. Default is 1.0.
104 EVENTS_EXPORT float GetTouchRadiusX(const base::NativeEvent& native_event);
105 EVENTS_EXPORT float GetTouchRadiusY(const base::NativeEvent& native_event);
106
107 // Gets the angle of the major axis away from the X axis. Default is 0.0.
108 EVENTS_EXPORT float GetTouchAngle(const base::NativeEvent& native_event);
109
110 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0.
111 EVENTS_EXPORT float GetTouchForce(const base::NativeEvent& native_event);
112
113 // Gets the fling velocity from a native event. is_cancel is set to true if
114 // this was a tap down, intended to stop an ongoing fling.
115 EVENTS_EXPORT bool GetFlingData(const base::NativeEvent& native_event,
116                             float* vx,
117                             float* vy,
118                             float* vx_ordinal,
119                             float* vy_ordinal,
120                             bool* is_cancel);
121
122 // Returns whether this is a scroll event and optionally gets the amount to be
123 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL.
124 EVENTS_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event,
125                                 float* x_offset,
126                                 float* y_offset,
127                                 float* x_offset_ordinal,
128                                 float* y_offset_ordinal,
129                                 int* finger_count);
130
131 EVENTS_EXPORT bool GetGestureTimes(const base::NativeEvent& native_event,
132                                double* start_time,
133                                double* end_time);
134
135 // Returns whether natural scrolling should be used for touchpad.
136 EVENTS_EXPORT bool ShouldDefaultToNaturalScroll();
137
138 // Returns whether or not the internal display produces touch events.
139 EVENTS_EXPORT gfx::Display::TouchSupport GetInternalDisplayTouchSupport();
140
141 // Was this event generated by a touchpad device?
142 // The caller is responsible for ensuring that this is a mouse/touchpad event
143 // before calling this function.
144 EVENTS_EXPORT bool IsTouchpadEvent(const base::NativeEvent& event);
145
146 #if defined(OS_WIN)
147 EVENTS_EXPORT int GetModifiersFromACCEL(const ACCEL& accel);
148 EVENTS_EXPORT int GetModifiersFromKeyState();
149
150 // Returns true if |message| identifies a mouse event that was generated as the
151 // result of a touch event.
152 EVENTS_EXPORT bool IsMouseEventFromTouch(UINT message);
153
154 // Converts scan code and lParam each other.  The scan code
155 // representing an extended key contains 0xE000 bits.
156 EVENTS_EXPORT uint16 GetScanCodeFromLParam(LPARAM lParam);
157 EVENTS_EXPORT LPARAM GetLParamFromScanCode(uint16 scan_code);
158 #endif
159
160 // Registers a custom event type.
161 EVENTS_EXPORT int RegisterCustomEventType();
162
163 }  // namespace ui
164
165 #endif  // UI_EVENTS_EVENT_UTILS_H_