Get foreground tab on Android
[chromium-blink-merge.git] / ui / events / x / events_x_utils.h
blob1d316a726d795785719446f65e69930eb4c4c98d
1 // Copyright (c) 2013 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 #include "base/memory/scoped_ptr.h"
6 #include "ui/events/event_constants.h"
7 #include "ui/events/events_export.h"
8 #include "ui/events/keycodes/keyboard_codes.h"
9 #include "ui/events/x/device_data_manager.h"
10 #include "ui/gfx/point.h"
11 #include "ui/gfx/x/x11_types.h"
13 typedef union _XEvent XEvent;
15 namespace ui {
17 struct Valuator {
18 Valuator(DeviceDataManager::DataType type, double v)
19 : data_type(type), value(v) {}
21 DeviceDataManager::DataType data_type;
22 double value;
25 class EVENTS_EXPORT ScopedXI2Event {
26 public:
27 explicit ScopedXI2Event(XEvent* event);
28 ~ScopedXI2Event();
30 operator XEvent*() { return event_.get(); }
32 private:
33 scoped_ptr<XEvent> event_;
35 DISALLOW_COPY_AND_ASSIGN(ScopedXI2Event);
38 // Initializes a XEvent that holds XKeyEvent for testing. Note that ui::EF_
39 // flags should be passed as |flags|, not the native ones in <X11/X.h>.
40 EVENTS_EXPORT void InitXKeyEventForTesting(EventType type,
41 KeyboardCode key_code,
42 int flags,
43 XEvent* event);
45 // Initializes a XEvent that holds XButtonEvent for testing. Note that ui::EF_
46 // flags should be passed as |flags|, not the native ones in <X11/X.h>.
47 EVENTS_EXPORT void InitXButtonEventForTesting(EventType type,
48 int flags,
49 XEvent* event);
51 // Initializes an XEvent for an Aura MouseWheelEvent. The underlying native
52 // event is an XButtonEvent.
53 EVENTS_EXPORT void InitXMouseWheelEventForTesting(int wheel_delta,
54 int flags,
55 XEvent* event);
57 // Creates a native scroll event, based on a XInput2Event. The caller is
58 // responsible for the ownership of the returned XEvent. Consider wrapping
59 // the XEvent in a ScopedXI2Event, as XEvent is purely a struct and simply
60 // deleting it will result in dangling pointers.
61 EVENTS_EXPORT XEvent* CreateScrollEventForTest(
62 int deviceid,
63 int x_offset,
64 int y_offset,
65 int x_offset_ordinal,
66 int y_offset_ordinal,
67 int finger_count);
69 // Initializes a test touchpad device for scroll events.
70 EVENTS_EXPORT void SetUpScrollDeviceForTest(unsigned int deviceid);
72 #if defined(USE_XI2_MT)
74 EVENTS_EXPORT XEvent* CreateTouchEventForTest(
75 int deviceid,
76 int evtype,
77 int tracking_id,
78 const gfx::Point& location,
79 const std::vector<Valuator>& valuators);
81 EVENTS_EXPORT void SetupTouchDevicesForTest(
82 const std::vector<unsigned int>& devices);
84 #endif
86 } // namespace ui