OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_EVENTS_EVENT_UTILS_H_ | 5 #ifndef UI_EVENTS_EVENT_UTILS_H_ |
6 #define UI_EVENTS_EVENT_UTILS_H_ | 6 #define UI_EVENTS_EVENT_UTILS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/event_types.h" | 9 #include "base/event_types.h" |
| 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string16.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" |
11 #include "ui/events/events_export.h" | 16 #include "ui/events/events_export.h" |
12 | 17 |
| 18 #if defined(OS_WIN) |
| 19 #include <windows.h> |
| 20 #endif |
| 21 |
| 22 namespace gfx { |
| 23 class Point; |
| 24 class Vector2d; |
| 25 } |
| 26 |
13 namespace base { | 27 namespace base { |
14 class TimeDelta; | 28 class TimeDelta; |
15 } | 29 } |
16 | 30 |
| 31 // Common functions to be used for all platforms except Android. |
17 namespace ui { | 32 namespace ui { |
18 | 33 |
| 34 class Event; |
| 35 class MouseEvent; |
| 36 enum class DomCode; |
| 37 |
| 38 // Updates the list of devices for cached properties. |
| 39 EVENTS_EXPORT void UpdateDeviceList(); |
| 40 |
| 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); |
| 45 |
| 46 // Get the EventType from a native event. |
| 47 EVENTS_EXPORT EventType EventTypeFromNative( |
| 48 const base::NativeEvent& native_event); |
| 49 |
| 50 // Get the EventFlags from a native event. |
| 51 EVENTS_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event); |
| 52 |
| 53 // Get the timestamp from a native event. |
| 54 EVENTS_EXPORT base::TimeDelta EventTimeFromNative( |
| 55 const base::NativeEvent& native_event); |
| 56 |
19 // Create a timestamp based on the current time. | 57 // Create a timestamp based on the current time. |
20 EVENTS_EXPORT base::TimeDelta EventTimeForNow(); | 58 EVENTS_EXPORT base::TimeDelta EventTimeForNow(); |
21 | 59 |
22 // Returns a control character sequences from a |windows_key_code|. | 60 // Get the location from a native event. The coordinate system of the resultant |
23 EVENTS_EXPORT base::char16 GetControlCharacterForKeycode(int windows_key_code, | 61 // |Point| has the origin at top-left of the "root window". The nature of |
24 bool shift); | 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); |
| 67 |
| 68 // Gets the location in native system coordinate space. |
| 69 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative( |
| 70 const base::NativeEvent& native_event); |
| 71 |
| 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 |
| 79 |
| 80 // Returns the KeyboardCode from a native event. |
| 81 EVENTS_EXPORT KeyboardCode KeyboardCodeFromNative( |
| 82 const base::NativeEvent& native_event); |
| 83 |
| 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); |
| 87 |
| 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); |
| 92 |
| 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); |
| 96 |
| 97 // Returns the flags of the button that changed during a press/release. |
| 98 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative( |
| 99 const base::NativeEvent& native_event); |
| 100 |
| 101 // Gets the mouse wheel offsets from a native event. |
| 102 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset( |
| 103 const base::NativeEvent& native_event); |
| 104 |
| 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); |
| 109 |
| 110 // Delete a |native_event| previously created by CopyNativeEvent(). |
| 111 void ReleaseCopiedNativeEvent( |
| 112 const base::NativeEvent& native_event); |
| 113 |
| 114 // Gets the touch id from a native event. |
| 115 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event); |
| 116 |
| 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); |
| 120 |
| 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); |
| 124 |
| 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); |
| 127 |
| 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); |
| 130 |
| 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); |
| 139 |
| 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); |
| 148 |
| 149 // Returns whether natural scrolling should be used for touchpad. |
| 150 EVENTS_EXPORT bool ShouldDefaultToNaturalScroll(); |
| 151 |
| 152 // Returns whether or not the internal display produces touch events. |
| 153 EVENTS_EXPORT gfx::Display::TouchSupport GetInternalDisplayTouchSupport(); |
| 154 |
| 155 #if defined(OS_WIN) |
| 156 EVENTS_EXPORT int GetModifiersFromACCEL(const ACCEL& accel); |
| 157 EVENTS_EXPORT int GetModifiersFromKeyState(); |
| 158 |
| 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); |
| 162 |
| 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); |
| 167 |
| 168 #endif |
| 169 |
| 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 |
| 176 |
| 177 // Registers a custom event type. |
| 178 EVENTS_EXPORT int RegisterCustomEventType(); |
25 | 179 |
26 } // namespace ui | 180 } // namespace ui |
27 | 181 |
28 #endif // UI_EVENTS_EVENT_UTILS_H_ | 182 #endif // UI_EVENTS_EVENT_UTILS_H_ |
OLD | NEW |