Add a Notification Settings Button to all web notifications behind the web platform...
[chromium-blink-merge.git] / ui / events / event_utils.h
blob74884392a5e40acbbb6d4b7f60cc8a502c131d49
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/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/keycodes/keyboard_codes.h"
14 #include "ui/gfx/display.h"
15 #include "ui/gfx/native_widget_types.h"
16 #include "ui/events/events_export.h"
18 #if defined(OS_WIN)
19 #include <windows.h>
20 #endif
22 namespace gfx {
23 class Point;
24 class Vector2d;
27 namespace base {
28 class TimeDelta;
31 // Common functions to be used for all platforms except Android.
32 namespace ui {
34 class Event;
35 class MouseEvent;
36 enum class DomCode;
38 // Updates the list of devices for cached properties.
39 EVENTS_EXPORT void UpdateDeviceList();
41 // Returns a ui::Event wrapping a native event. Ownership of the returned value
42 // is transferred to the caller.
43 EVENTS_EXPORT scoped_ptr<Event> EventFromNative(
44 const base::NativeEvent& native_event);
46 // Get the EventType from a native event.
47 EVENTS_EXPORT EventType EventTypeFromNative(
48 const base::NativeEvent& native_event);
50 // Get the EventFlags from a native event.
51 EVENTS_EXPORT int EventFlagsFromNative(const base::NativeEvent& native_event);
53 // Get the timestamp from a native event.
54 EVENTS_EXPORT base::TimeDelta EventTimeFromNative(
55 const base::NativeEvent& native_event);
57 // Create a timestamp based on the current time.
58 EVENTS_EXPORT base::TimeDelta EventTimeForNow();
60 // Get the location from a native event. The coordinate system of the resultant
61 // |Point| has the origin at top-left of the "root window". The nature of
62 // this "root window" and how it maps to platform-specific drawing surfaces is
63 // defined in ui/aura/root_window.* and ui/aura/window_tree_host*.
64 // TODO(tdresser): Return gfx::PointF here. See crbug.com/337827.
65 EVENTS_EXPORT gfx::Point EventLocationFromNative(
66 const base::NativeEvent& native_event);
68 // Gets the location in native system coordinate space.
69 EVENTS_EXPORT gfx::Point EventSystemLocationFromNative(
70 const base::NativeEvent& native_event);
72 #if defined(USE_X11)
73 // Returns the 'real' button for an event. The button reported in slave events
74 // does not take into account any remapping (e.g. using xmodmap), while the
75 // button reported in master events do. This is a utility function to always
76 // return the mapped button.
77 EVENTS_EXPORT int EventButtonFromNative(const base::NativeEvent& native_event);
78 #endif
80 // Returns the KeyboardCode from a native event.
81 EVENTS_EXPORT KeyboardCode KeyboardCodeFromNative(
82 const base::NativeEvent& native_event);
84 // Returns the DOM KeyboardEvent code (physical location in the
85 // keyboard) from a native event.
86 EVENTS_EXPORT DomCode CodeFromNative(const base::NativeEvent& native_event);
88 // Returns true if the keyboard event is a character event rather than
89 // a keystroke event.
90 EVENTS_EXPORT bool IsCharFromNative(const base::NativeEvent& native_event);
92 // Returns the flags of the button that changed during a press/release.
93 EVENTS_EXPORT int GetChangedMouseButtonFlagsFromNative(
94 const base::NativeEvent& native_event);
96 // Gets the mouse wheel offsets from a native event.
97 EVENTS_EXPORT gfx::Vector2d GetMouseWheelOffset(
98 const base::NativeEvent& native_event);
100 // Returns a copy of |native_event|. Depending on the platform, this copy may
101 // need to be deleted with ReleaseCopiedNativeEvent().
102 base::NativeEvent CopyNativeEvent(
103 const base::NativeEvent& native_event);
105 // Delete a |native_event| previously created by CopyNativeEvent().
106 void ReleaseCopiedNativeEvent(
107 const base::NativeEvent& native_event);
109 // Gets the touch id from a native event.
110 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event);
112 // Clear the touch id from bookkeeping if it is a release/cancel event.
113 EVENTS_EXPORT void ClearTouchIdIfReleased(
114 const base::NativeEvent& native_event);
116 // Gets the radius along the X/Y axis from a native event. Default is 1.0.
117 EVENTS_EXPORT float GetTouchRadiusX(const base::NativeEvent& native_event);
118 EVENTS_EXPORT float GetTouchRadiusY(const base::NativeEvent& native_event);
120 // Gets the angle of the major axis away from the X axis. Default is 0.0.
121 EVENTS_EXPORT float GetTouchAngle(const base::NativeEvent& native_event);
123 // Gets the force from a native_event. Normalized to be [0, 1]. Default is 0.0.
124 EVENTS_EXPORT float GetTouchForce(const base::NativeEvent& native_event);
126 // Gets the fling velocity from a native event. is_cancel is set to true if
127 // this was a tap down, intended to stop an ongoing fling.
128 EVENTS_EXPORT bool GetFlingData(const base::NativeEvent& native_event,
129 float* vx,
130 float* vy,
131 float* vx_ordinal,
132 float* vy_ordinal,
133 bool* is_cancel);
135 // Returns whether this is a scroll event and optionally gets the amount to be
136 // scrolled. |x_offset|, |y_offset| and |finger_count| can be NULL.
137 EVENTS_EXPORT bool GetScrollOffsets(const base::NativeEvent& native_event,
138 float* x_offset,
139 float* y_offset,
140 float* x_offset_ordinal,
141 float* y_offset_ordinal,
142 int* finger_count);
144 // Returns whether natural scrolling should be used for touchpad.
145 EVENTS_EXPORT bool ShouldDefaultToNaturalScroll();
147 // Returns whether or not the internal display produces touch events.
148 EVENTS_EXPORT gfx::Display::TouchSupport GetInternalDisplayTouchSupport();
150 #if defined(OS_WIN)
151 EVENTS_EXPORT int GetModifiersFromACCEL(const ACCEL& accel);
152 EVENTS_EXPORT int GetModifiersFromKeyState();
154 // Returns true if |message| identifies a mouse event that was generated as the
155 // result of a touch event.
156 EVENTS_EXPORT bool IsMouseEventFromTouch(UINT message);
158 // Converts scan code and lParam each other. The scan code
159 // representing an extended key contains 0xE000 bits.
160 EVENTS_EXPORT uint16 GetScanCodeFromLParam(LPARAM lParam);
161 EVENTS_EXPORT LPARAM GetLParamFromScanCode(uint16 scan_code);
163 #endif
165 #if defined(USE_X11)
166 // Update the native X11 event to correspond to the new flags.
167 EVENTS_EXPORT void UpdateX11EventForFlags(Event* event);
168 // Update the native X11 event to correspond to the new button flags.
169 EVENTS_EXPORT void UpdateX11EventForChangedButtonFlags(MouseEvent* event);
170 #endif
172 // Registers a custom event type.
173 EVENTS_EXPORT int RegisterCustomEventType();
175 } // namespace ui
177 #endif // UI_EVENTS_EVENT_UTILS_H_