1 // Copyright 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. 4 5 #ifndef UI_EVENTS_TEST_EVENTS_TEST_UTILS_X11_H_ 6 #define UI_EVENTS_TEST_EVENTS_TEST_UTILS_X11_H_ 7 8 #include "base/memory/scoped_ptr.h" 9 #include "ui/events/event_constants.h" 10 #include "ui/events/keycodes/keyboard_codes.h" 11 #include "ui/events/x/device_data_manager.h" 12 #include "ui/gfx/point.h" 13 #include "ui/gfx/x/x11_types.h" 14 15 typedef union _XEvent XEvent; 16 17 namespace ui { 18 19 struct Valuator { ValuatorValuator20 Valuator(DeviceDataManager::DataType type, double v) 21 : data_type(type), value(v) {} 22 23 DeviceDataManager::DataType data_type; 24 double value; 25 }; 26 27 class ScopedXI2Event { 28 public: 29 ScopedXI2Event(); 30 ~ScopedXI2Event(); 31 32 operator XEvent*() { return event_.get(); } 33 34 // Initializes a XEvent with for the appropriate type with the specified data. 35 // Note that ui::EF_ flags should be passed as |flags|, not the native ones in 36 // <X11/X.h>. 37 void InitKeyEvent(EventType type, 38 KeyboardCode key_code, 39 int flags); 40 41 void InitButtonEvent(EventType type, 42 int flags); 43 44 void InitMouseWheelEvent(int wheel_delta, 45 int flags); 46 47 void InitScrollEvent(int deviceid, 48 int x_offset, 49 int y_offset, 50 int x_offset_ordinal, 51 int y_offset_ordinal, 52 int finger_count); 53 54 void InitFlingScrollEvent(int deviceid, 55 int x_velocity, 56 int y_velocity, 57 int x_velocity_ordinal, 58 int y_velocity_ordinal, 59 bool is_cancel); 60 61 void InitTouchEvent(int deviceid, 62 int evtype, 63 int tracking_id, 64 const gfx::Point& location, 65 const std::vector<Valuator>& valuators); 66 67 private: 68 void Cleanup(); 69 70 void SetUpValuators(const std::vector<Valuator>& valuators); 71 72 scoped_ptr<XEvent> event_; 73 74 DISALLOW_COPY_AND_ASSIGN(ScopedXI2Event); 75 }; 76 77 // Initializes a test touchpad device for scroll events. 78 void SetUpScrollDeviceForTest(unsigned int deviceid); 79 80 // Initializes a list of touchscreen devices for touch events. 81 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices); 82 83 } // namespace ui 84 85 #endif // UI_EVENTS_TEST_EVENTS_TEST_UTILS_X11_H_ 86