Home | History | Annotate | Download | only in test
      1 // Copyright 2014 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 #include <vector>
      6 
      7 #include "base/basictypes.h"
      8 #include "base/time/time.h"
      9 #include "ui/events/gesture_detection/motion_event.h"
     10 #include "ui/gfx/geometry/point_f.h"
     11 
     12 namespace ui {
     13 namespace test {
     14 
     15 struct MockMotionEvent : public MotionEvent {
     16   enum { MAX_POINTERS = 3 };
     17   enum { TOUCH_MAJOR = 10 };
     18 
     19   MockMotionEvent();
     20   explicit MockMotionEvent(Action action);
     21   MockMotionEvent(Action action, base::TimeTicks time, float x, float y);
     22   MockMotionEvent(Action action,
     23                   base::TimeTicks time,
     24                   float x0,
     25                   float y0,
     26                   float x1,
     27                   float y1);
     28   MockMotionEvent(Action action,
     29                   base::TimeTicks time,
     30                   float x0,
     31                   float y0,
     32                   float x1,
     33                   float y1,
     34                   float x2,
     35                   float y2);
     36   MockMotionEvent(Action action,
     37                   base::TimeTicks time,
     38                   const std::vector<gfx::PointF>& positions);
     39   MockMotionEvent(const MockMotionEvent& other);
     40 
     41   virtual ~MockMotionEvent();
     42 
     43   // MotionEvent methods.
     44   virtual Action GetAction() const OVERRIDE;
     45   virtual int GetActionIndex() const OVERRIDE;
     46   virtual size_t GetPointerCount() const OVERRIDE;
     47   virtual int GetId() const OVERRIDE;
     48   virtual int GetPointerId(size_t pointer_index) const OVERRIDE;
     49   virtual float GetX(size_t pointer_index) const OVERRIDE;
     50   virtual float GetY(size_t pointer_index) const OVERRIDE;
     51   virtual float GetRawX(size_t pointer_index) const OVERRIDE;
     52   virtual float GetRawY(size_t pointer_index) const OVERRIDE;
     53   virtual float GetTouchMajor(size_t pointer_index) const OVERRIDE;
     54   virtual float GetPressure(size_t pointer_index) const OVERRIDE;
     55   virtual base::TimeTicks GetEventTime() const OVERRIDE;
     56   virtual size_t GetHistorySize() const OVERRIDE;
     57   virtual base::TimeTicks GetHistoricalEventTime(size_t historical_index) const
     58       OVERRIDE;
     59   virtual float GetHistoricalTouchMajor(size_t pointer_index,
     60                                         size_t historical_index) const OVERRIDE;
     61   virtual float GetHistoricalX(size_t pointer_index,
     62                                size_t historical_index) const OVERRIDE;
     63   virtual float GetHistoricalY(size_t pointer_index,
     64                                size_t historical_index) const OVERRIDE;
     65   virtual ToolType GetToolType(size_t pointer_index) const OVERRIDE;
     66   virtual int GetButtonState() const OVERRIDE;
     67 
     68   virtual scoped_ptr<MotionEvent> Clone() const OVERRIDE;
     69   virtual scoped_ptr<MotionEvent> Cancel() const OVERRIDE;
     70 
     71   // Utility methods.
     72   void SetId(int new_id);
     73   void SetTime(base::TimeTicks new_time);
     74   void PressPoint(float x, float y);
     75   void MovePoint(size_t index, float x, float y);
     76   void ReleasePoint();
     77   void CancelPoint();
     78   void SetTouchMajor(float new_touch_major);
     79   void SetRawOffset(float raw_offset_x, float raw_offset_y);
     80   void SetToolType(size_t index, ToolType tool_type);
     81   void SetButtonState(int button_state);
     82 
     83   MotionEvent::Action action;
     84   size_t pointer_count;
     85   gfx::PointF points[MAX_POINTERS];
     86   ToolType tool_types[MAX_POINTERS];
     87   gfx::Vector2dF raw_offset;
     88   base::TimeTicks time;
     89   float touch_major;
     90   int id;
     91   int button_state;
     92 };
     93 
     94 }  // namespace test
     95 }  // namespace ui
     96