Chromium Code Reviews| 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 | |
| 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. | 30 // Get the EventType from a native event. |
| 45 EVENTS_EXPORT EventType EventTypeFromNative( | 31 EVENTS_EXPORT EventType EventTypeFromNative(const XEvent* native_event); |
|
spang
2014/11/24 18:56:54
I don't think we should have these X overloads in
achaulk
2014/11/24 19:28:39
Well we still need the logic to determine EventTyp
| |
| 46 const base::NativeEvent& native_event); | |
| 47 | 32 |
| 48 // Get the EventFlags from a native event. | 33 // Get the EventFlags from a native event. |
| 49 EVENTS_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event); | 34 EVENTS_EXPORT int EventFlagsFromNative(const XEvent* native_event); |
| 50 | 35 |
| 51 // Get the timestamp from a native event. | 36 // Get the timestamp from a native event. |
| 52 EVENTS_EXPORT base::TimeDelta EventTimeFromNative( | 37 EVENTS_EXPORT base::TimeDelta EventTimeFromNative(const XEvent* native_event); |
| 53 const base::NativeEvent& native_event); | |
| 54 | |
| 55 // Create a timestamp based on the current time. | |
| 56 EVENTS_EXPORT base::TimeDelta EventTimeForNow(); | |
| 57 | 38 |
| 58 // Get the location from a native event. The coordinate system of the resultant | 39 // 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 | 40 // |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 | 41 // 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*. | 42 // defined in ui/aura/root_window.* and ui/aura/window_tree_host*. |
| 62 // TODO(tdresser): Return gfx::PointF here. See crbug.com/337827. | 43 // TODO(tdresser): Return gfx::PointF here. See crbug.com/337827. |
| 63 EVENTS_EXPORT gfx::Point EventLocationFromNative( | 44 EVENTS_EXPORT gfx::Point EventLocationFromNative(const XEvent* native_event); |
| 64 const base::NativeEvent& native_event); | |
| 65 | 45 |
| 66 // Gets the location in native system coordinate space. | 46 // Gets the location in native system coordinate space. |
| 67 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative( | 47 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative( |
| 68 const base::NativeEvent& native_event); | 48 const XEvent* native_event); |
| 69 | 49 |
| 70 #if defined(USE_X11) | |
| 71 // Returns the 'real' button for an event. The button reported in slave events | 50 // 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 | 51 // 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 | 52 // button reported in master events do. This is a utility function to always |
| 74 // return the mapped button. | 53 // return the mapped button. |
| 75 EVENTS_EXPORT int EventButtonFromNative(const base::NativeEvent& native_event); | 54 EVENTS_EXPORT int EventButtonFromNative(const XEvent* native_event); |
| 76 #endif | |
| 77 | 55 |
| 78 // Returns the KeyboardCode from a native event. | 56 // Returns the KeyboardCode from a native event. |
| 79 EVENTS_EXPORT KeyboardCode KeyboardCodeFromNative( | 57 EVENTS_EXPORT KeyboardCode KeyboardCodeFromNative(const XEvent* native_event); |
| 80 const base::NativeEvent& native_event); | |
| 81 | 58 |
| 82 // Returns the DOM KeyboardEvent code (physical location in the | 59 // Returns the DOM KeyboardEvent code (physical location in the |
| 83 // keyboard) from a native event. The ownership of the return value | 60 // keyboard) from a native event. The ownership of the return value |
| 84 // is NOT trasferred to the caller. | 61 // is NOT trasferred to the caller. |
| 85 EVENTS_EXPORT const char* CodeFromNative( | 62 EVENTS_EXPORT const char* CodeFromNative(const XEvent* native_event); |
| 86 const base::NativeEvent& native_event); | |
| 87 | 63 |
| 88 // Returns the platform related key code. For X11, it is xksym value. | 64 // Returns the platform related key code. For X11, it is xksym value. |
| 89 EVENTS_EXPORT uint32 PlatformKeycodeFromNative( | 65 EVENTS_EXPORT uint32 PlatformKeycodeFromNative(const XEvent* native_event); |
| 90 const base::NativeEvent& native_event); | |
| 91 | 66 |
| 92 // Returns a control character sequences from a |windows_key_code|. | 67 // Returns a control character sequences from a |windows_key_code|. |
| 93 EVENTS_EXPORT base::char16 GetControlCharacterForKeycode(int windows_key_code, | 68 EVENTS_EXPORT base::char16 GetControlCharacterForKeycode(int windows_key_code, |
| 94 bool shift); | 69 bool shift); |
| 95 | 70 |
| 96 // Returns true if the keyboard event is a character event rather than | 71 // Returns true if the keyboard event is a character event rather than |
| 97 // a keystroke event. | 72 // a keystroke event. |
| 98 EVENTS_EXPORT bool IsCharFromNative(const base::NativeEvent& native_event); | 73 EVENTS_EXPORT bool IsCharFromNative(const XEvent* native_event); |
| 99 | 74 |
| 100 // Returns the flags of the button that changed during a press/release. | 75 // Returns the flags of the button that changed during a press/release. |
| 101 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative( | 76 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative( |
| 102 const base::NativeEvent& native_event); | 77 const XEvent* native_event); |
| 103 | 78 |
| 104 // Gets the mouse wheel offsets from a native event. | 79 // Gets the mouse wheel offsets from a native event. |
| 105 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset( | 80 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset(const XEvent* native_event); |
| 106 const base::NativeEvent& native_event); | |
| 107 | 81 |
| 108 // Returns a copy of |native_event|. Depending on the platform, this copy may | 82 // Returns a copy of |native_event|. Depending on the platform, this copy may |
| 109 // need to be deleted with ReleaseCopiedNativeEvent(). | 83 // need to be deleted with ReleaseCopiedNativeEvent(). |
| 110 base::NativeEvent CopyNativeEvent( | 84 XEvent* CopyNativeEvent(const XEvent* native_event); |
| 111 const base::NativeEvent& native_event); | |
| 112 | 85 |
| 113 // Delete a |native_event| previously created by CopyNativeEvent(). | 86 // Delete a |native_event| previously created by CopyNativeEvent(). |
| 114 void ReleaseCopiedNativeEvent( | 87 void ReleaseCopiedNativeEvent(const XEvent* native_event); |
| 115 const base::NativeEvent& native_event); | |
| 116 | 88 |
| 117 // Gets the touch id from a native event. | 89 // Gets the touch id from a native event. |
| 118 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event); | 90 EVENTS_EXPORT int GetTouchId(const XEvent* native_event); |
| 119 | 91 |
| 120 // Increases the number of times |ClearTouchIdIfReleased| needs to be called on | 92 // 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. | 93 // an event with a given touch id before it will actually be cleared. |
| 122 EVENTS_EXPORT void IncrementTouchIdRefCount( | 94 EVENTS_EXPORT void IncrementTouchIdRefCount(const XEvent* native_event); |
| 123 const base::NativeEvent& native_event); | |
| 124 | 95 |
| 125 // Clear the touch id from bookkeeping if it is a release/cancel event. | 96 // Clear the touch id from bookkeeping if it is a release/cancel event. |
| 126 EVENTS_EXPORT void ClearTouchIdIfReleased( | 97 EVENTS_EXPORT void ClearTouchIdIfReleased(const XEvent* native_event); |
| 127 const base::NativeEvent& native_event); | |
| 128 | 98 |
| 129 // Gets the radius along the X/Y axis from a native event. Default is 1.0. | 99 // 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); | 100 EVENTS_EXPORT float GetTouchRadiusX(const XEvent* native_event); |
| 131 EVENTS_EXPORT float GetTouchRadiusY(const base::NativeEvent& native_event); | 101 EVENTS_EXPORT float GetTouchRadiusY(const XEvent* native_event); |
| 132 | 102 |
| 133 // Gets the angle of the major axis away from the X axis. Default is 0.0. | 103 // 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); | 104 EVENTS_EXPORT float GetTouchAngle(const XEvent* native_event); |
| 135 | 105 |
| 136 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0. | 106 // 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); | 107 EVENTS_EXPORT float GetTouchForce(const XEvent* native_event); |
| 138 | 108 |
| 139 // Gets the fling velocity from a native event. is_cancel is set to true if | 109 // 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. | 110 // this was a tap down, intended to stop an ongoing fling. |
| 141 EVENTS_EXPORT bool GetFlingData(const base::NativeEvent& native_event, | 111 EVENTS_EXPORT bool GetFlingData(const XEvent* native_event, |
| 142 float* vx, | 112 float* vx, |
| 143 float* vy, | 113 float* vy, |
| 144 float* vx_ordinal, | 114 float* vx_ordinal, |
| 145 float* vy_ordinal, | 115 float* vy_ordinal, |
| 146 bool* is_cancel); | 116 bool* is_cancel); |
| 147 | 117 |
| 148 // Returns whether this is a scroll event and optionally gets the amount to be | 118 // 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. | 119 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL. |
| 150 EVENTS_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event, | 120 EVENTS_EXPORT bool GetScrollOffsets(const XEvent* native_event, |
| 151 float* x_offset, | 121 float* x_offset, |
| 152 float* y_offset, | 122 float* y_offset, |
| 153 float* x_offset_ordinal, | 123 float* x_offset_ordinal, |
| 154 float* y_offset_ordinal, | 124 float* y_offset_ordinal, |
| 155 int* finger_count); | 125 int* finger_count); |
| 156 | 126 |
| 157 // Returns whether natural scrolling should be used for touchpad. | 127 #if defined(USE_OZONE) && !defined(USE_X11) |
| 158 EVENTS_EXPORT bool ShouldDefaultToNaturalScroll(); | 128 EVENTS_EXPORT base::NativeEvent TranslateXEventToNativeEvent(XEvent* xevent); |
| 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 | 129 #endif |
| 177 | 130 |
| 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 | 131 } // namespace ui |
| 189 | 132 |
| 190 #endif // UI_EVENTS_EVENT_UTILS_H_ | 133 #endif // UI_EVENTS_EVENT_UTILS_H_ |
| OLD | NEW |