Home | History | Annotate | Download | only in test
      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_x11.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 {
     20   Valuator(DeviceDataManagerX11::DataType type, double v)
     21       : data_type(type), value(v) {}
     22 
     23   DeviceDataManagerX11::DataType data_type;
     24   double value;
     25 };
     26 
     27 struct XEventDeleter {
     28   void operator()(XEvent* event);
     29 };
     30 
     31 class ScopedXI2Event {
     32  public:
     33   ScopedXI2Event();
     34   ~ScopedXI2Event();
     35 
     36   operator XEvent*() { return event_.get(); }
     37 
     38   // Initializes a XEvent with for the appropriate type with the specified data.
     39   // Note that ui::EF_ flags should be passed as |flags|, not the native ones in
     40   // <X11/X.h>.
     41   void InitKeyEvent(EventType type,
     42                     KeyboardCode key_code,
     43                     int flags);
     44 
     45   // Initializes an Xinput2 key event.
     46   // |deviceid| is the master, and |sourceid| is the slave device.
     47   void InitGenericKeyEvent(int deviceid,
     48                            int sourceid,
     49                            EventType type,
     50                            KeyboardCode key_code,
     51                            int flags);
     52 
     53   void InitGenericButtonEvent(int deviceid,
     54                               EventType type,
     55                               const gfx::Point& location,
     56                               int flags);
     57 
     58   void InitGenericMouseWheelEvent(int deviceid,
     59                                   int wheel_delta,
     60                                   int flags);
     61 
     62   void InitScrollEvent(int deviceid,
     63                        int x_offset,
     64                        int y_offset,
     65                        int x_offset_ordinal,
     66                        int y_offset_ordinal,
     67                        int finger_count);
     68 
     69   void InitFlingScrollEvent(int deviceid,
     70                             int x_velocity,
     71                             int y_velocity,
     72                             int x_velocity_ordinal,
     73                             int y_velocity_ordinal,
     74                             bool is_cancel);
     75 
     76   void InitTouchEvent(int deviceid,
     77                       int evtype,
     78                       int tracking_id,
     79                       const gfx::Point& location,
     80                       const std::vector<Valuator>& valuators);
     81 
     82  private:
     83   void Cleanup();
     84 
     85   void SetUpValuators(const std::vector<Valuator>& valuators);
     86 
     87   scoped_ptr<XEvent, XEventDeleter> event_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(ScopedXI2Event);
     90 };
     91 
     92 // Initializes a test touchpad device for scroll events.
     93 void SetUpTouchPadForTest(unsigned int deviceid);
     94 
     95 // Initializes a list of touchscreen devices for touch events.
     96 void SetUpTouchDevicesForTest(const std::vector<unsigned int>& devices);
     97 
     98 }  // namespace ui
     99 
    100 #endif  // UI_EVENTS_TEST_EVENTS_TEST_UTILS_X11_H_
    101