| 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/event_types.h" | 8 #include "base/event_types.h" |
| 9 #include "ui/events/event_constants.h" | 9 #include "ui/events/event_constants.h" |
| 10 #include "ui/events/keycodes/keyboard_codes.h" | 10 #include "ui/events/keycodes/keyboard_codes.h" |
| 11 #include "ui/gfx/native_widget_types.h" | 11 #include "ui/gfx/native_widget_types.h" |
| 12 #include "ui/events/events_export.h" |
| 12 | 13 |
| 13 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
| 14 #include <windows.h> | 15 #include <windows.h> |
| 15 #endif | 16 #endif |
| 16 | 17 |
| 17 namespace gfx { | 18 namespace gfx { |
| 18 class Point; | 19 class Point; |
| 19 class Vector2d; | 20 class Vector2d; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class TimeDelta; | 24 class TimeDelta; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace ui { | 27 namespace ui { |
| 27 | 28 |
| 28 class Event; | 29 class Event; |
| 29 | 30 |
| 30 // Updates the list of devices for cached properties. | 31 // Updates the list of devices for cached properties. |
| 31 UI_EXPORT void UpdateDeviceList(); | 32 EVENTS_EXPORT void UpdateDeviceList(); |
| 32 | 33 |
| 33 // Get the EventType from a native event. | 34 // Get the EventType from a native event. |
| 34 UI_EXPORT EventType EventTypeFromNative(const base::NativeEvent& native_event); | 35 EVENTS_EXPORT EventType EventTypeFromNative( |
| 36 const base::NativeEvent& native_event); |
| 35 | 37 |
| 36 // Get the EventFlags from a native event. | 38 // Get the EventFlags from a native event. |
| 37 UI_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event); | 39 EVENTS_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event); |
| 38 | 40 |
| 39 // Get the timestamp from a native event. | 41 // Get the timestamp from a native event. |
| 40 UI_EXPORT base::TimeDelta EventTimeFromNative( | 42 EVENTS_EXPORT base::TimeDelta EventTimeFromNative( |
| 41 const base::NativeEvent& native_event); | 43 const base::NativeEvent& native_event); |
| 42 | 44 |
| 43 // Create a timestamp based on the current time. | 45 // Create a timestamp based on the current time. |
| 44 UI_EXPORT base::TimeDelta EventTimeForNow(); | 46 EVENTS_EXPORT base::TimeDelta EventTimeForNow(); |
| 45 | 47 |
| 46 // Get the location from a native event. The coordinate system of the resultant | 48 // Get the location from a native event. The coordinate system of the resultant |
| 47 // |Point| has the origin at top-left of the "root window". The nature of | 49 // |Point| has the origin at top-left of the "root window". The nature of |
| 48 // this "root window" and how it maps to platform-specific drawing surfaces is | 50 // this "root window" and how it maps to platform-specific drawing surfaces is |
| 49 // defined in ui/aura/root_window.* and ui/aura/root_window_host*. | 51 // defined in ui/aura/root_window.* and ui/aura/root_window_host*. |
| 50 UI_EXPORT gfx::Point EventLocationFromNative( | 52 EVENTS_EXPORT gfx::Point EventLocationFromNative( |
| 51 const base::NativeEvent& native_event); | 53 const base::NativeEvent& native_event); |
| 52 | 54 |
| 53 // Gets the location in native system coordinate space. | 55 // Gets the location in native system coordinate space. |
| 54 UI_EXPORT gfx::Point EventSystemLocationFromNative( | 56 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative( |
| 55 const base::NativeEvent& native_event); | 57 const base::NativeEvent& native_event); |
| 56 | 58 |
| 57 #if defined(USE_X11) | 59 #if defined(USE_X11) |
| 58 // Returns the 'real' button for an event. The button reported in slave events | 60 // Returns the 'real' button for an event. The button reported in slave events |
| 59 // does not take into account any remapping (e.g. using xmodmap), while the | 61 // does not take into account any remapping (e.g. using xmodmap), while the |
| 60 // button reported in master events do. This is a utility function to always | 62 // button reported in master events do. This is a utility function to always |
| 61 // return the mapped button. | 63 // return the mapped button. |
| 62 UI_EXPORT int EventButtonFromNative(const base::NativeEvent& native_event); | 64 EVENTS_EXPORT int EventButtonFromNative(const base::NativeEvent& native_event); |
| 63 #endif | 65 #endif |
| 64 | 66 |
| 65 // Returns the KeyboardCode from a native event. | 67 // Returns the KeyboardCode from a native event. |
| 66 UI_EXPORT KeyboardCode KeyboardCodeFromNative( | 68 EVENTS_EXPORT KeyboardCode KeyboardCodeFromNative( |
| 67 const base::NativeEvent& native_event); | 69 const base::NativeEvent& native_event); |
| 68 | 70 |
| 69 // Returns true if the message is a mouse event. | 71 // Returns true if the message is a mouse event. |
| 70 UI_EXPORT bool IsMouseEvent(const base::NativeEvent& native_event); | 72 EVENTS_EXPORT bool IsMouseEvent(const base::NativeEvent& native_event); |
| 71 | 73 |
| 72 // Returns the flags of the button that changed during a press/release. | 74 // Returns the flags of the button that changed during a press/release. |
| 73 UI_EXPORT int GetChangedMouseButtonFlagsFromNative( | 75 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative( |
| 74 const base::NativeEvent& native_event); | 76 const base::NativeEvent& native_event); |
| 75 | 77 |
| 76 // Gets the mouse wheel offsets from a native event. | 78 // Gets the mouse wheel offsets from a native event. |
| 77 UI_EXPORT gfx::Vector2d GetMouseWheelOffset( | 79 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset( |
| 78 const base::NativeEvent& native_event); | 80 const base::NativeEvent& native_event); |
| 79 | 81 |
| 80 // Gets the touch id from a native event. | 82 // Gets the touch id from a native event. |
| 81 UI_EXPORT int GetTouchId(const base::NativeEvent& native_event); | 83 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event); |
| 82 | 84 |
| 83 // Clear the touch id from bookkeeping if it is a release/cancel event. | 85 // Clear the touch id from bookkeeping if it is a release/cancel event. |
| 84 UI_EXPORT void ClearTouchIdIfReleased(const base::NativeEvent& native_event); | 86 EVENTS_EXPORT void ClearTouchIdIfReleased( |
| 87 const base::NativeEvent& native_event); |
| 85 | 88 |
| 86 // Gets the radius along the X/Y axis from a native event. Default is 1.0. | 89 // Gets the radius along the X/Y axis from a native event. Default is 1.0. |
| 87 UI_EXPORT float GetTouchRadiusX(const base::NativeEvent& native_event); | 90 EVENTS_EXPORT float GetTouchRadiusX(const base::NativeEvent& native_event); |
| 88 UI_EXPORT float GetTouchRadiusY(const base::NativeEvent& native_event); | 91 EVENTS_EXPORT float GetTouchRadiusY(const base::NativeEvent& native_event); |
| 89 | 92 |
| 90 // Gets the angle of the major axis away from the X axis. Default is 0.0. | 93 // Gets the angle of the major axis away from the X axis. Default is 0.0. |
| 91 UI_EXPORT float GetTouchAngle(const base::NativeEvent& native_event); | 94 EVENTS_EXPORT float GetTouchAngle(const base::NativeEvent& native_event); |
| 92 | 95 |
| 93 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0. | 96 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0. |
| 94 UI_EXPORT float GetTouchForce(const base::NativeEvent& native_event); | 97 EVENTS_EXPORT float GetTouchForce(const base::NativeEvent& native_event); |
| 95 | 98 |
| 96 // Gets the fling velocity from a native event. is_cancel is set to true if | 99 // Gets the fling velocity from a native event. is_cancel is set to true if |
| 97 // this was a tap down, intended to stop an ongoing fling. | 100 // this was a tap down, intended to stop an ongoing fling. |
| 98 UI_EXPORT bool GetFlingData(const base::NativeEvent& native_event, | 101 EVENTS_EXPORT bool GetFlingData(const base::NativeEvent& native_event, |
| 99 float* vx, | 102 float* vx, |
| 100 float* vy, | 103 float* vy, |
| 101 float* vx_ordinal, | 104 float* vx_ordinal, |
| 102 float* vy_ordinal, | 105 float* vy_ordinal, |
| 103 bool* is_cancel); | 106 bool* is_cancel); |
| 104 | 107 |
| 105 // Returns whether this is a scroll event and optionally gets the amount to be | 108 // Returns whether this is a scroll event and optionally gets the amount to be |
| 106 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL. | 109 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL. |
| 107 UI_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event, | 110 EVENTS_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event, |
| 108 float* x_offset, | 111 float* x_offset, |
| 109 float* y_offset, | 112 float* y_offset, |
| 110 float* x_offset_ordinal, | 113 float* x_offset_ordinal, |
| 111 float* y_offset_ordinal, | 114 float* y_offset_ordinal, |
| 112 int* finger_count); | 115 int* finger_count); |
| 113 | 116 |
| 114 UI_EXPORT bool GetGestureTimes(const base::NativeEvent& native_event, | 117 EVENTS_EXPORT bool GetGestureTimes(const base::NativeEvent& native_event, |
| 115 double* start_time, | 118 double* start_time, |
| 116 double* end_time); | 119 double* end_time); |
| 117 | 120 |
| 118 // Enable/disable natural scrolling for touchpads. | 121 // Enable/disable natural scrolling for touchpads. |
| 119 UI_EXPORT void SetNaturalScroll(bool enabled); | 122 EVENTS_EXPORT void SetNaturalScroll(bool enabled); |
| 120 | 123 |
| 121 // In natural scrolling enabled for touchpads? | 124 // In natural scrolling enabled for touchpads? |
| 122 UI_EXPORT bool IsNaturalScrollEnabled(); | 125 EVENTS_EXPORT bool IsNaturalScrollEnabled(); |
| 123 | 126 |
| 124 // Was this event generated by a touchpad device? | 127 // Was this event generated by a touchpad device? |
| 125 // The caller is responsible for ensuring that this is a mouse/touchpad event | 128 // The caller is responsible for ensuring that this is a mouse/touchpad event |
| 126 // before calling this function. | 129 // before calling this function. |
| 127 UI_EXPORT bool IsTouchpadEvent(const base::NativeEvent& event); | 130 EVENTS_EXPORT bool IsTouchpadEvent(const base::NativeEvent& event); |
| 128 | 131 |
| 129 // Returns true if event is noop. | 132 // Returns true if event is noop. |
| 130 UI_EXPORT bool IsNoopEvent(const base::NativeEvent& event); | 133 EVENTS_EXPORT bool IsNoopEvent(const base::NativeEvent& event); |
| 131 | 134 |
| 132 // Creates and returns no-op event. | 135 // Creates and returns no-op event. |
| 133 UI_EXPORT base::NativeEvent CreateNoopEvent(); | 136 EVENTS_EXPORT base::NativeEvent CreateNoopEvent(); |
| 134 | 137 |
| 135 #if defined(OS_WIN) | 138 #if defined(OS_WIN) |
| 136 UI_EXPORT int GetModifiersFromACCEL(const ACCEL& accel); | 139 EVENTS_EXPORT int GetModifiersFromACCEL(const ACCEL& accel); |
| 137 UI_EXPORT int GetModifiersFromKeyState(); | 140 EVENTS_EXPORT int GetModifiersFromKeyState(); |
| 138 | 141 |
| 139 // Returns true if |message| identifies a mouse event that was generated as the | 142 // Returns true if |message| identifies a mouse event that was generated as the |
| 140 // result of a touch event. | 143 // result of a touch event. |
| 141 UI_EXPORT bool IsMouseEventFromTouch(UINT message); | 144 EVENTS_EXPORT bool IsMouseEventFromTouch(UINT message); |
| 142 #endif | 145 #endif |
| 143 | 146 |
| 144 // Returns true if default post-target handling was canceled for |event| after | 147 // Returns true if default post-target handling was canceled for |event| after |
| 145 // its dispatch to its target. | 148 // its dispatch to its target. |
| 146 UI_EXPORT bool EventCanceledDefaultHandling(const Event& event); | 149 EVENTS_EXPORT bool EventCanceledDefaultHandling(const Event& event); |
| 147 | 150 |
| 148 // Registers a custom event type. | 151 // Registers a custom event type. |
| 149 UI_EXPORT int RegisterCustomEventType(); | 152 EVENTS_EXPORT int RegisterCustomEventType(); |
| 150 | 153 |
| 151 } // namespace ui | 154 } // namespace ui |
| 152 | 155 |
| 153 #endif // UI_EVENTS_EVENT_UTILS_H_ | 156 #endif // UI_EVENTS_EVENT_UTILS_H_ |
| OLD | NEW |