| OLD | NEW |
| (Empty) |
| 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_PLATFORM_PLATFORM_EVENT_UTILS_H_ | |
| 6 #define UI_EVENTS_PLATFORM_PLATFORM_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/events_export.h" | |
| 14 #include "ui/events/keycodes/keyboard_codes.h" | |
| 15 #include "ui/gfx/display.h" | |
| 16 #include "ui/gfx/native_widget_types.h" | |
| 17 | |
| 18 namespace gfx { | |
| 19 class Point; | |
| 20 class Vector2d; | |
| 21 } | |
| 22 | |
| 23 namespace base { | |
| 24 class TimeDelta; | |
| 25 } | |
| 26 | |
| 27 namespace ui { | |
| 28 | |
| 29 class Event; | |
| 30 class MouseEvent; | |
| 31 | |
| 32 // Updates the list of devices for cached properties. | |
| 33 EVENTS_EXPORT void UpdateDeviceList(); | |
| 34 | |
| 35 // Get the EventType from a native event. | |
| 36 EVENTS_EXPORT EventType | |
| 37 EventTypeFromNative(const base::NativeEvent& native_event); | |
| 38 | |
| 39 // Get the EventFlags from a native event. | |
| 40 EVENTS_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event); | |
| 41 | |
| 42 // Get the timestamp from a native event. | |
| 43 EVENTS_EXPORT base::TimeDelta EventTimeFromNative( | |
| 44 const base::NativeEvent& native_event); | |
| 45 | |
| 46 // 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 | |
| 48 // this "root window" and how it maps to platform-specific drawing surfaces is | |
| 49 // defined in ui/aura/root_window.* and ui/aura/window_tree_host*. | |
| 50 // TODO(tdresser): Return gfx::PointF here. See crbug.com/337827. | |
| 51 EVENTS_EXPORT gfx::Point EventLocationFromNative( | |
| 52 const base::NativeEvent& native_event); | |
| 53 | |
| 54 // Gets the location in native system coordinate space. | |
| 55 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative( | |
| 56 const base::NativeEvent& native_event); | |
| 57 | |
| 58 #if defined(USE_X11) | |
| 59 // Returns the 'real' button for an event. The button reported in slave events | |
| 60 // does not take into account any remapping (e.g. using xmodmap), while the | |
| 61 // button reported in master events do. This is a utility function to always | |
| 62 // return the mapped button. | |
| 63 EVENTS_EXPORT int EventButtonFromNative(const base::NativeEvent& native_event); | |
| 64 #endif | |
| 65 | |
| 66 // Returns the KeyboardCode from a native event. | |
| 67 EVENTS_EXPORT KeyboardCode | |
| 68 KeyboardCodeFromNative(const base::NativeEvent& native_event); | |
| 69 | |
| 70 // Returns the DOM KeyboardEvent code (physical location in the | |
| 71 // keyboard) from a native event. The ownership of the return value | |
| 72 // is NOT trasferred to the caller. | |
| 73 EVENTS_EXPORT const char* CodeFromNative(const base::NativeEvent& native_event); | |
| 74 | |
| 75 // Returns the platform related key code. For X11, it is xksym value. | |
| 76 EVENTS_EXPORT uint32 | |
| 77 PlatformKeycodeFromNative(const base::NativeEvent& native_event); | |
| 78 | |
| 79 // Returns true if the keyboard event is a character event rather than | |
| 80 // a keystroke event. | |
| 81 EVENTS_EXPORT bool IsCharFromNative(const base::NativeEvent& native_event); | |
| 82 | |
| 83 // Returns the flags of the button that changed during a press/release. | |
| 84 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative( | |
| 85 const base::NativeEvent& native_event); | |
| 86 | |
| 87 // Gets the mouse wheel offsets from a native event. | |
| 88 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset( | |
| 89 const base::NativeEvent& native_event); | |
| 90 | |
| 91 // Gets the touch id from a native event. | |
| 92 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event); | |
| 93 | |
| 94 // Increases the number of times |ClearTouchIdIfReleased| needs to be called on | |
| 95 // an event with a given touch id before it will actually be cleared. | |
| 96 EVENTS_EXPORT void IncrementTouchIdRefCount( | |
| 97 const base::NativeEvent& native_event); | |
| 98 | |
| 99 // Clear the touch id from bookkeeping if it is a release/cancel event. | |
| 100 EVENTS_EXPORT void ClearTouchIdIfReleased( | |
| 101 const base::NativeEvent& native_event); | |
| 102 | |
| 103 // Gets the radius along the X/Y axis from a native event. Default is 1.0. | |
| 104 EVENTS_EXPORT float GetTouchRadiusX(const base::NativeEvent& native_event); | |
| 105 EVENTS_EXPORT float GetTouchRadiusY(const base::NativeEvent& native_event); | |
| 106 | |
| 107 // Gets the angle of the major axis away from the X axis. Default is 0.0. | |
| 108 EVENTS_EXPORT float GetTouchAngle(const base::NativeEvent& native_event); | |
| 109 | |
| 110 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0. | |
| 111 EVENTS_EXPORT float GetTouchForce(const base::NativeEvent& native_event); | |
| 112 | |
| 113 // Gets the fling velocity from a native event. is_cancel is set to true if | |
| 114 // this was a tap down, intended to stop an ongoing fling. | |
| 115 EVENTS_EXPORT bool GetFlingData(const base::NativeEvent& native_event, | |
| 116 float* vx, | |
| 117 float* vy, | |
| 118 float* vx_ordinal, | |
| 119 float* vy_ordinal, | |
| 120 bool* is_cancel); | |
| 121 | |
| 122 // Returns whether this is a scroll event and optionally gets the amount to be | |
| 123 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL. | |
| 124 EVENTS_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event, | |
| 125 float* x_offset, | |
| 126 float* y_offset, | |
| 127 float* x_offset_ordinal, | |
| 128 float* y_offset_ordinal, | |
| 129 int* finger_count); | |
| 130 | |
| 131 } // namespace ui | |
| 132 | |
| 133 #endif // UI_EVENTS_PLATFORM_PLATFORM_EVENT_UTILS_H_ | |
| OLD | NEW |