Add default implementations for AppWindowRegistry::Observer notifications.
[chromium-blink-merge.git] / ui / events / event_utils.h
blob08bbfbc2e556d9a0f9c840ecccf0956af16de965
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 // Returns a copy of |native_event|. Depending on the platform, this copy may
88 // need to be deleted with ReleaseCopiedNativeEvent().
89 base::NativeEvent CopyNativeEvent(
90 const base::NativeEvent& native_event);
92 // Delete a |native_event| previously created by CopyNativeEvent().
93 void ReleaseCopiedNativeEvent(
94 const base::NativeEvent& native_event);
96 // Gets the touch id from a native event.
97 EVENTS_EXPORT int GetTouchId(const base::NativeEvent& native_event);
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);
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);
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);
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);
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);
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);
131 EVENTS_EXPORT bool GetGestureTimes(const base::NativeEvent& native_event,
132 double* start_time,
133 double* end_time);
135 // Returns whether natural scrolling should be used for touchpad.
136 EVENTS_EXPORT bool ShouldDefaultToNaturalScroll();
138 // Returns whether or not the internal display produces touch events.
139 EVENTS_EXPORT gfx::Display::TouchSupport GetInternalDisplayTouchSupport();
141 // Was this event generated by a touchpad device?
142 // The caller is responsible for ensuring that this is a mouse/touchpad event
143 // before calling this function.
144 EVENTS_EXPORT bool IsTouchpadEvent(const base::NativeEvent& event);
146 #if defined(OS_WIN)
147 EVENTS_EXPORT int GetModifiersFromACCEL(const ACCEL& accel);
148 EVENTS_EXPORT int GetModifiersFromKeyState();
150 // Returns true if |message| identifies a mouse event that was generated as the
151 // result of a touch event.
152 EVENTS_EXPORT bool IsMouseEventFromTouch(UINT message);
154 // Converts scan code and lParam each other. The scan code
155 // representing an extended key contains 0xE000 bits.
156 EVENTS_EXPORT uint16 GetScanCodeFromLParam(LPARAM lParam);
157 EVENTS_EXPORT LPARAM GetLParamFromScanCode(uint16 scan_code);
158 #endif
160 // Registers a custom event type.
161 EVENTS_EXPORT int RegisterCustomEventType();
163 } // namespace ui
165 #endif // UI_EVENTS_EVENT_UTILS_H_