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 #ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DATA_PACKET_H_ 6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DATA_PACKET_H_ 7 8 #include <vector> 9 10 #include "ui/events/gesture_detection/gesture_detection_export.h" 11 #include "ui/events/gesture_detection/gesture_event_data.h" 12 13 namespace ui { 14 15 class MotionEvent; 16 17 // Acts as a transport container for gestures created (directly or indirectly) 18 // by a touch event. 19 class GESTURE_DETECTION_EXPORT GestureEventDataPacket { 20 public: 21 enum GestureSource { 22 UNDEFINED = -1, // Used only for a default-constructed packet. 23 INVALID, // The source of the gesture was invalid. 24 TOUCH_SEQUENCE_START, // The start of a new gesture sequence. 25 TOUCH_SEQUENCE_END, // The end of a gesture sequence. 26 TOUCH_SEQUENCE_CANCEL, // The gesture sequence was cancelled. 27 TOUCH_START, // A touch down occured during a gesture sequence. 28 TOUCH_MOVE, // A touch move occured during a gesture sequence. 29 TOUCH_END, // A touch up occured during a gesture sequence. 30 TOUCH_TIMEOUT, // Timeout from an existing gesture sequence. 31 }; 32 33 GestureEventDataPacket(); 34 GestureEventDataPacket(const GestureEventDataPacket& other); 35 ~GestureEventDataPacket(); 36 GestureEventDataPacket& operator=(const GestureEventDataPacket& other); 37 38 // Factory methods for creating a packet from a particular event. 39 static GestureEventDataPacket FromTouch(const ui::MotionEvent& touch); 40 static GestureEventDataPacket FromTouchTimeout( 41 const GestureEventData& gesture); 42 43 void Push(const GestureEventData& gesture); 44 timestamp()45 const base::TimeTicks& timestamp() const { return timestamp_; } gesture(size_t i)46 const GestureEventData& gesture(size_t i) const { return gestures_[i]; } gesture_count()47 size_t gesture_count() const { return gestures_.size(); } gesture_source()48 GestureSource gesture_source() const { return gesture_source_; } touch_location()49 const gfx::PointF& touch_location() const { return touch_location_; } raw_touch_location()50 const gfx::PointF& raw_touch_location() const { return raw_touch_location_; } 51 52 private: 53 GestureEventDataPacket(base::TimeTicks timestamp, 54 GestureSource source, 55 const gfx::PointF& touch_location, 56 const gfx::PointF& raw_touch_location); 57 58 base::TimeTicks timestamp_; 59 // TODO(jdduke): This vector is in general very short. Optimize? 60 std::vector<GestureEventData> gestures_; 61 gfx::PointF touch_location_; 62 gfx::PointF raw_touch_location_; 63 GestureSource gesture_source_; 64 }; 65 66 } // namespace ui 67 68 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DATA_PACKET_H_ 69