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