Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / events / gesture_detection / gesture_event_data_packet.cc
blob7ad711313dda61479f9add61bc442d6fcb390d7f
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.
5 #include "ui/events/gesture_detection/gesture_event_data_packet.h"
7 #include "base/logging.h"
8 #include "ui/events/gesture_detection/motion_event.h"
10 namespace ui {
11 namespace {
13 GestureEventDataPacket::GestureSource ToGestureSource(
14 const ui::MotionEvent& event) {
15 switch (event.GetAction()) {
16 case ui::MotionEvent::ACTION_DOWN:
17 return GestureEventDataPacket::TOUCH_SEQUENCE_START;
18 case ui::MotionEvent::ACTION_UP:
19 return GestureEventDataPacket::TOUCH_SEQUENCE_END;
20 case ui::MotionEvent::ACTION_MOVE:
21 return GestureEventDataPacket::TOUCH_MOVE;
22 case ui::MotionEvent::ACTION_CANCEL:
23 return GestureEventDataPacket::TOUCH_SEQUENCE_CANCEL;
24 case ui::MotionEvent::ACTION_POINTER_DOWN:
25 return GestureEventDataPacket::TOUCH_START;
26 case ui::MotionEvent::ACTION_POINTER_UP:
27 return GestureEventDataPacket::TOUCH_END;
28 case ui::MotionEvent::ACTION_NONE:
29 NOTREACHED();
30 return GestureEventDataPacket::INVALID;
32 NOTREACHED();
33 return GestureEventDataPacket::INVALID;
36 } // namespace
38 GestureEventDataPacket::GestureEventDataPacket()
39 : gesture_source_(UNDEFINED),
40 ack_state_(AckState::PENDING),
41 unique_touch_event_id_(0) {
44 GestureEventDataPacket::GestureEventDataPacket(
45 base::TimeTicks timestamp,
46 GestureSource source,
47 const gfx::PointF& touch_location,
48 const gfx::PointF& raw_touch_location,
49 uint32 unique_touch_event_id)
50 : timestamp_(timestamp),
51 touch_location_(touch_location),
52 raw_touch_location_(raw_touch_location),
53 gesture_source_(source),
54 ack_state_(AckState::PENDING),
55 unique_touch_event_id_(unique_touch_event_id) {
56 DCHECK_NE(gesture_source_, UNDEFINED);
59 GestureEventDataPacket::GestureEventDataPacket(
60 const GestureEventDataPacket& other)
61 : timestamp_(other.timestamp_),
62 gestures_(other.gestures_),
63 touch_location_(other.touch_location_),
64 raw_touch_location_(other.raw_touch_location_),
65 gesture_source_(other.gesture_source_),
66 ack_state_(AckState::PENDING),
67 unique_touch_event_id_(other.unique_touch_event_id_) {
70 GestureEventDataPacket::~GestureEventDataPacket() {
73 GestureEventDataPacket& GestureEventDataPacket::operator=(
74 const GestureEventDataPacket& other) {
75 timestamp_ = other.timestamp_;
76 gesture_source_ = other.gesture_source_;
77 touch_location_ = other.touch_location_;
78 raw_touch_location_ = other.raw_touch_location_;
79 gestures_ = other.gestures_;
80 ack_state_ = other.ack_state_;
81 unique_touch_event_id_ = other.unique_touch_event_id_;
82 return *this;
85 void GestureEventDataPacket::Push(const GestureEventData& gesture) {
86 DCHECK_NE(ET_UNKNOWN, gesture.type());
87 gestures_->push_back(gesture);
90 GestureEventDataPacket GestureEventDataPacket::FromTouch(
91 const ui::MotionEvent& touch) {
92 return GestureEventDataPacket(touch.GetEventTime(), ToGestureSource(touch),
93 gfx::PointF(touch.GetX(), touch.GetY()),
94 gfx::PointF(touch.GetRawX(), touch.GetRawY()),
95 touch.GetUniqueEventId());
98 GestureEventDataPacket GestureEventDataPacket::FromTouchTimeout(
99 const GestureEventData& gesture) {
100 GestureEventDataPacket packet(gesture.time, TOUCH_TIMEOUT,
101 gfx::PointF(gesture.x, gesture.y),
102 gfx::PointF(gesture.raw_x, gesture.raw_y), 0);
103 packet.Push(gesture);
104 return packet;
107 void GestureEventDataPacket::Ack(bool event_consumed) {
108 DCHECK_EQ(static_cast<int>(ack_state_), static_cast<int>(AckState::PENDING));
109 ack_state_ = event_consumed ? AckState::CONSUMED : AckState::UNCONSUMED;
112 } // namespace ui