Change to let media_stream_devices_controller.cc decide if a gUM request fail if...
[chromium-blink-merge.git] / ui / events / event_utils.h
blobe0775225f8245d6e810c4fb0283920fc9abed3bc
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.
5 #ifndef UI_EVENTS_EVENT_UTILS_H_
6 #define UI_EVENTS_EVENT_UTILS_H_
8 #include "base/event_types.h"
9 #include "ui/events/event_constants.h"
10 #include "ui/events/keycodes/keyboard_codes.h"
11 #include "ui/gfx/display.h"
12 #include "ui/gfx/native_widget_types.h"
13 #include "ui/events/events_export.h"
15 #if defined(OS_WIN)
16 #include <windows.h>
17 #endif
19 namespace gfx {
20 class Point;
21 class Vector2d;
24 namespace base {
25 class TimeDelta;
28 namespace ui {
30 class Event;
32 // Updates the list of devices for cached properties.
33 EVENTS_EXPORT void UpdateDeviceList();
35 // Get the EventType from a native event.
36 EVENTS_EXPORT EventType EventTypeFromNative(
37 const base::NativeEvent& native_event);
39 // Get the EventFlags from a native event.
40 EVENTS_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event);
42 // Get the timestamp from a native event.
43 EVENTS_EXPORT base::TimeDelta EventTimeFromNative(
44 const base::NativeEvent& native_event);
46 // Create a timestamp based on the current time.
47 EVENTS_EXPORT base::TimeDelta EventTimeForNow();
49 // Get the location from a native event. The coordinate system of the resultant
50 // |Point| has the origin at top-left of the "root window". The nature of
51 // this "root window" and how it maps to platform-specific drawing surfaces is
52 // defined in ui/aura/root_window.* and ui/aura/window_tree_host*.
53 // TODO(tdresser): Return gfx::PointF here. See crbug.com/337827.
54 EVENTS_EXPORT gfx::Point EventLocationFromNative(
55 const base::NativeEvent& native_event);
57 // Gets the location in native system coordinate space.
58 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative(
59 const base::NativeEvent& native_event);
61 #if defined(USE_X11)
62 // Returns the 'real' button for an event. The button reported in slave events
63 // does not take into account any remapping (e.g. using xmodmap), while the
64 // button reported in master events do. This is a utility function to always
65 // return the mapped button.
66 EVENTS_EXPORT int EventButtonFromNative(const base::NativeEvent& native_event);
67 #endif
69 // Returns the KeyboardCode from a native event.
70 EVENTS_EXPORT KeyboardCode KeyboardCodeFromNative(
71 const base::NativeEvent& native_event);
73 // Returns the DOM KeyboardEvent code (physical location in the
74 // keyboard) from a native event. The ownership of the return value
75 // is NOT trasferred to the caller.
76 EVENTS_EXPORT const char* CodeFromNative(
77 const base::NativeEvent& native_event);
79 // Returns the flags of the button that changed during a press/release.
80 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative(
81 const base::NativeEvent& native_event);
83 // Gets the mouse wheel offsets from a native event.
84 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset(
85 const base::NativeEvent& native_event);
87 // Gets the touch id from a native event.
88 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event);
90 // Clear the touch id from bookkeeping if it is a release/cancel event.
91 EVENTS_EXPORT void ClearTouchIdIfReleased(
92 const base::NativeEvent& native_event);
94 // Gets the radius along the X/Y axis from a native event. Default is 1.0.
95 EVENTS_EXPORT float GetTouchRadiusX(const base::NativeEvent& native_event);
96 EVENTS_EXPORT float GetTouchRadiusY(const base::NativeEvent& native_event);
98 // Gets the angle of the major axis away from the X axis. Default is 0.0.
99 EVENTS_EXPORT float GetTouchAngle(const base::NativeEvent& native_event);
101 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0.
102 EVENTS_EXPORT float GetTouchForce(const base::NativeEvent& native_event);
104 // Gets the fling velocity from a native event. is_cancel is set to true if
105 // this was a tap down, intended to stop an ongoing fling.
106 EVENTS_EXPORT bool GetFlingData(const base::NativeEvent& native_event,
107 float* vx,
108 float* vy,
109 float* vx_ordinal,
110 float* vy_ordinal,
111 bool* is_cancel);
113 // Returns whether this is a scroll event and optionally gets the amount to be
114 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL.
115 EVENTS_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event,
116 float* x_offset,
117 float* y_offset,
118 float* x_offset_ordinal,
119 float* y_offset_ordinal,
120 int* finger_count);
122 EVENTS_EXPORT bool GetGestureTimes(const base::NativeEvent& native_event,
123 double* start_time,
124 double* end_time);
126 // Enable/disable natural scrolling for touchpads.
127 EVENTS_EXPORT void SetNaturalScroll(bool enabled);
129 // In natural scrolling enabled for touchpads?
130 EVENTS_EXPORT bool IsNaturalScrollEnabled();
132 // Returns whether natural scrolling should be used for touchpad.
133 EVENTS_EXPORT bool ShouldDefaultToNaturalScroll();
135 // Returns whether or not the internal display produces touch events.
136 EVENTS_EXPORT gfx::Display::TouchSupport GetInternalDisplayTouchSupport();
138 // Was this event generated by a touchpad device?
139 // The caller is responsible for ensuring that this is a mouse/touchpad event
140 // before calling this function.
141 EVENTS_EXPORT bool IsTouchpadEvent(const base::NativeEvent& event);
143 #if defined(OS_WIN)
144 EVENTS_EXPORT int GetModifiersFromACCEL(const ACCEL& accel);
145 EVENTS_EXPORT int GetModifiersFromKeyState();
147 // Returns true if |message| identifies a mouse event that was generated as the
148 // result of a touch event.
149 EVENTS_EXPORT bool IsMouseEventFromTouch(UINT message);
151 // Converts scan code and lParam each other. The scan code
152 // representing an extended key contains 0xE000 bits.
153 EVENTS_EXPORT uint16 GetScanCodeFromLParam(LPARAM lParam);
154 EVENTS_EXPORT LPARAM GetLParamFromScanCode(uint16 scan_code);
155 #endif
157 // Registers a custom event type.
158 EVENTS_EXPORT int RegisterCustomEventType();
160 } // namespace ui
162 #endif // UI_EVENTS_EVENT_UTILS_H_