Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / events / gesture_detection / gesture_event_data_packet.cc
blob04cec5ca34ce1f320427c68c597a5f571496f91e
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;
29 NOTREACHED() << "Invalid ui::MotionEvent action: " << event.GetAction();
30 return GestureEventDataPacket::INVALID;
33 } // namespace
35 GestureEventDataPacket::GestureEventDataPacket()
36 : gesture_source_(UNDEFINED),
37 ack_state_(AckState::PENDING),
38 unique_touch_event_id_(0) {
41 GestureEventDataPacket::GestureEventDataPacket(
42 base::TimeTicks timestamp,
43 GestureSource source,
44 const gfx::PointF& touch_location,
45 const gfx::PointF& raw_touch_location,
46 uint32 unique_touch_event_id)
47 : timestamp_(timestamp),
48 touch_location_(touch_location),
49 raw_touch_location_(raw_touch_location),
50 gesture_source_(source),
51 ack_state_(AckState::PENDING),
52 unique_touch_event_id_(unique_touch_event_id) {
53 DCHECK_NE(gesture_source_, UNDEFINED);
56 GestureEventDataPacket::GestureEventDataPacket(
57 const GestureEventDataPacket& other)
58 : timestamp_(other.timestamp_),
59 gestures_(other.gestures_),
60 touch_location_(other.touch_location_),
61 raw_touch_location_(other.raw_touch_location_),
62 gesture_source_(other.gesture_source_),
63 ack_state_(AckState::PENDING),
64 unique_touch_event_id_(other.unique_touch_event_id_) {
67 GestureEventDataPacket::~GestureEventDataPacket() {
70 GestureEventDataPacket& GestureEventDataPacket::operator=(
71 const GestureEventDataPacket& other) {
72 timestamp_ = other.timestamp_;
73 gesture_source_ = other.gesture_source_;
74 touch_location_ = other.touch_location_;
75 raw_touch_location_ = other.raw_touch_location_;
76 gestures_ = other.gestures_;
77 ack_state_ = other.ack_state_;
78 unique_touch_event_id_ = other.unique_touch_event_id_;
79 return *this;
82 void GestureEventDataPacket::Push(const GestureEventData& gesture) {
83 DCHECK_NE(ET_UNKNOWN, gesture.type());
84 gestures_->push_back(gesture);
87 GestureEventDataPacket GestureEventDataPacket::FromTouch(
88 const ui::MotionEvent& touch) {
89 return GestureEventDataPacket(touch.GetEventTime(), ToGestureSource(touch),
90 gfx::PointF(touch.GetX(), touch.GetY()),
91 gfx::PointF(touch.GetRawX(), touch.GetRawY()),
92 touch.GetUniqueEventId());
95 GestureEventDataPacket GestureEventDataPacket::FromTouchTimeout(
96 const GestureEventData& gesture) {
97 GestureEventDataPacket packet(gesture.time, TOUCH_TIMEOUT,
98 gfx::PointF(gesture.x, gesture.y),
99 gfx::PointF(gesture.raw_x, gesture.raw_y), 0);
100 packet.Push(gesture);
101 return packet;
104 void GestureEventDataPacket::Ack(bool event_consumed) {
105 DCHECK_EQ(static_cast<int>(ack_state_), static_cast<int>(AckState::PENDING));
106 ack_state_ = event_consumed ? AckState::CONSUMED : AckState::UNCONSUMED;
109 } // namespace ui