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