gesture_event_data_packet.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DATA_PACKET_H_
  5. #define UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DATA_PACKET_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include "base/containers/stack_container.h"
  9. #include "base/time/time.h"
  10. #include "ui/events/gesture_detection/gesture_detection_export.h"
  11. #include "ui/events/gesture_detection/gesture_event_data.h"
  12. namespace ui {
  13. class MotionEvent;
  14. // Acts as a transport container for gestures created (directly or indirectly)
  15. // by a touch event.
  16. class GESTURE_DETECTION_EXPORT GestureEventDataPacket {
  17. public:
  18. enum GestureSource {
  19. UNDEFINED = -1, // Used only for a default-constructed packet.
  20. INVALID, // The source of the gesture was invalid.
  21. TOUCH_SEQUENCE_START, // The start of a new gesture sequence.
  22. TOUCH_SEQUENCE_END, // The end of a gesture sequence.
  23. TOUCH_SEQUENCE_CANCEL, // The gesture sequence was cancelled.
  24. TOUCH_START, // A touch down occured during a gesture sequence.
  25. TOUCH_MOVE, // A touch move occured during a gesture sequence.
  26. TOUCH_END, // A touch up occured during a gesture sequence.
  27. TOUCH_TIMEOUT, // Timeout from an existing gesture sequence.
  28. };
  29. enum class AckState {
  30. PENDING,
  31. CONSUMED,
  32. UNCONSUMED,
  33. };
  34. GestureEventDataPacket();
  35. GestureEventDataPacket(const GestureEventDataPacket& other);
  36. ~GestureEventDataPacket();
  37. GestureEventDataPacket& operator=(const GestureEventDataPacket& other);
  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. // Pushes into the GestureEventDataPacket a copy of |gesture| that has the
  43. // same unique_touch_event_id as the data packet.
  44. void Push(const GestureEventData& gesture);
  45. const base::TimeTicks& timestamp() const { return timestamp_; }
  46. const GestureEventData& gesture(size_t i) const { return gestures_[i]; }
  47. size_t gesture_count() const { return gestures_->size(); }
  48. GestureSource gesture_source() const { return gesture_source_; }
  49. const gfx::PointF& touch_location() const { return touch_location_; }
  50. const gfx::PointF& raw_touch_location() const { return raw_touch_location_; }
  51. // We store the ack with the packet until the packet reaches the
  52. // head of the queue, and then we handle the ack.
  53. void Ack(bool event_consumed, bool is_source_touch_event_set_blocking);
  54. AckState ack_state() { return ack_state_; }
  55. uint32_t unique_touch_event_id() const { return unique_touch_event_id_; }
  56. private:
  57. GestureEventDataPacket(base::TimeTicks timestamp,
  58. GestureSource source,
  59. const gfx::PointF& touch_location,
  60. const gfx::PointF& raw_touch_location,
  61. uint32_t unique_touch_event_id);
  62. enum { kTypicalMaxGesturesPerTouch = 5 };
  63. base::TimeTicks timestamp_;
  64. base::StackVector<GestureEventData, kTypicalMaxGesturesPerTouch> gestures_;
  65. gfx::PointF touch_location_;
  66. gfx::PointF raw_touch_location_;
  67. GestureSource gesture_source_;
  68. AckState ack_state_;
  69. uint32_t unique_touch_event_id_;
  70. };
  71. } // namespace ui
  72. #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DATA_PACKET_H_