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