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