OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/gesture_detection/gesture_event_data_packet.h" | 5 #include "ui/events/gesture_detection/gesture_event_data_packet.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/events/gesture_detection/motion_event.h" | 8 #include "ui/events/gesture_detection/motion_event.h" |
9 | 9 |
10 namespace ui { | 10 namespace ui { |
(...skipping 15 matching lines...) Expand all Loading... |
26 case ui::MotionEvent::ACTION_POINTER_UP: | 26 case ui::MotionEvent::ACTION_POINTER_UP: |
27 return GestureEventDataPacket::TOUCH_END; | 27 return GestureEventDataPacket::TOUCH_END; |
28 }; | 28 }; |
29 NOTREACHED() << "Invalid ui::MotionEvent action: " << event.GetAction(); | 29 NOTREACHED() << "Invalid ui::MotionEvent action: " << event.GetAction(); |
30 return GestureEventDataPacket::INVALID; | 30 return GestureEventDataPacket::INVALID; |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 GestureEventDataPacket::GestureEventDataPacket() | 35 GestureEventDataPacket::GestureEventDataPacket() |
36 : gesture_source_(UNDEFINED) { | 36 : gesture_source_(UNDEFINED), ack_state_(AckState::PENDING) { |
37 } | 37 } |
38 | 38 |
39 GestureEventDataPacket::GestureEventDataPacket( | 39 GestureEventDataPacket::GestureEventDataPacket( |
40 base::TimeTicks timestamp, | 40 base::TimeTicks timestamp, |
41 GestureSource source, | 41 GestureSource source, |
42 const gfx::PointF& touch_location, | 42 const gfx::PointF& touch_location, |
43 const gfx::PointF& raw_touch_location) | 43 const gfx::PointF& raw_touch_location) |
44 : timestamp_(timestamp), | 44 : timestamp_(timestamp), |
45 touch_location_(touch_location), | 45 touch_location_(touch_location), |
46 raw_touch_location_(raw_touch_location), | 46 raw_touch_location_(raw_touch_location), |
47 gesture_source_(source) { | 47 gesture_source_(source), |
| 48 ack_state_(AckState::PENDING) { |
48 DCHECK_NE(gesture_source_, UNDEFINED); | 49 DCHECK_NE(gesture_source_, UNDEFINED); |
49 } | 50 } |
50 | 51 |
51 GestureEventDataPacket::GestureEventDataPacket( | 52 GestureEventDataPacket::GestureEventDataPacket( |
52 const GestureEventDataPacket& other) | 53 const GestureEventDataPacket& other) |
53 : timestamp_(other.timestamp_), | 54 : timestamp_(other.timestamp_), |
54 gestures_(other.gestures_), | 55 gestures_(other.gestures_), |
55 touch_location_(other.touch_location_), | 56 touch_location_(other.touch_location_), |
56 raw_touch_location_(other.raw_touch_location_), | 57 raw_touch_location_(other.raw_touch_location_), |
57 gesture_source_(other.gesture_source_) { | 58 gesture_source_(other.gesture_source_), |
| 59 ack_state_(AckState::PENDING) { |
58 } | 60 } |
59 | 61 |
60 GestureEventDataPacket::~GestureEventDataPacket() { | 62 GestureEventDataPacket::~GestureEventDataPacket() { |
61 } | 63 } |
62 | 64 |
63 GestureEventDataPacket& GestureEventDataPacket::operator=( | 65 GestureEventDataPacket& GestureEventDataPacket::operator=( |
64 const GestureEventDataPacket& other) { | 66 const GestureEventDataPacket& other) { |
65 timestamp_ = other.timestamp_; | 67 timestamp_ = other.timestamp_; |
66 gesture_source_ = other.gesture_source_; | 68 gesture_source_ = other.gesture_source_; |
67 touch_location_ = other.touch_location_; | 69 touch_location_ = other.touch_location_; |
68 raw_touch_location_ = other.raw_touch_location_; | 70 raw_touch_location_ = other.raw_touch_location_; |
69 gestures_ = other.gestures_; | 71 gestures_ = other.gestures_; |
| 72 ack_state_ = other.ack_state_; |
70 return *this; | 73 return *this; |
71 } | 74 } |
72 | 75 |
73 void GestureEventDataPacket::Push(const GestureEventData& gesture) { | 76 void GestureEventDataPacket::Push(const GestureEventData& gesture) { |
74 DCHECK_NE(ET_UNKNOWN, gesture.type()); | 77 DCHECK_NE(ET_UNKNOWN, gesture.type()); |
75 gestures_->push_back(gesture); | 78 gestures_->push_back(gesture); |
76 } | 79 } |
77 | 80 |
78 GestureEventDataPacket GestureEventDataPacket::FromTouch( | 81 GestureEventDataPacket GestureEventDataPacket::FromTouch( |
79 const ui::MotionEvent& touch) { | 82 const ui::MotionEvent& touch) { |
80 return GestureEventDataPacket(touch.GetEventTime(), | 83 return GestureEventDataPacket(touch.GetEventTime(), |
81 ToGestureSource(touch), | 84 ToGestureSource(touch), |
82 gfx::PointF(touch.GetX(), touch.GetY()), | 85 gfx::PointF(touch.GetX(), touch.GetY()), |
83 gfx::PointF(touch.GetRawX(), touch.GetRawY())); | 86 gfx::PointF(touch.GetRawX(), touch.GetRawY())); |
84 } | 87 } |
85 | 88 |
86 GestureEventDataPacket GestureEventDataPacket::FromTouchTimeout( | 89 GestureEventDataPacket GestureEventDataPacket::FromTouchTimeout( |
87 const GestureEventData& gesture) { | 90 const GestureEventData& gesture) { |
88 GestureEventDataPacket packet(gesture.time, | 91 GestureEventDataPacket packet(gesture.time, |
89 TOUCH_TIMEOUT, | 92 TOUCH_TIMEOUT, |
90 gfx::PointF(gesture.x, gesture.y), | 93 gfx::PointF(gesture.x, gesture.y), |
91 gfx::PointF(gesture.raw_x, gesture.raw_y)); | 94 gfx::PointF(gesture.raw_x, gesture.raw_y)); |
92 packet.Push(gesture); | 95 packet.Push(gesture); |
93 return packet; | 96 return packet; |
94 } | 97 } |
95 | 98 |
| 99 void GestureEventDataPacket::Ack(bool event_consumed) { |
| 100 DCHECK_EQ(static_cast<int>(ack_state_), static_cast<int>(AckState::PENDING)); |
| 101 ack_state_ = event_consumed ? AckState::CONSUMED : AckState::UNCONSUMED; |
| 102 } |
| 103 |
96 } // namespace ui | 104 } // namespace ui |
OLD | NEW |