Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / events / gesture_detection / gesture_event_data_packet.cc
blob265300cc1fcdfb7bf0c137ce0e2d09b7790b464c
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) {
39 GestureEventDataPacket::GestureEventDataPacket(
40 base::TimeTicks timestamp,
41 GestureSource source,
42 const gfx::PointF& touch_location,
43 const gfx::PointF& raw_touch_location)
44 : timestamp_(timestamp),
45 touch_location_(touch_location),
46 raw_touch_location_(raw_touch_location),
47 gesture_source_(source) {
48 DCHECK_NE(gesture_source_, UNDEFINED);
51 GestureEventDataPacket::GestureEventDataPacket(
52 const GestureEventDataPacket& other)
53 : timestamp_(other.timestamp_),
54 gestures_(other.gestures_),
55 touch_location_(other.touch_location_),
56 raw_touch_location_(other.raw_touch_location_),
57 gesture_source_(other.gesture_source_) {
60 GestureEventDataPacket::~GestureEventDataPacket() {
63 GestureEventDataPacket& GestureEventDataPacket::operator=(
64 const GestureEventDataPacket& other) {
65 timestamp_ = other.timestamp_;
66 gesture_source_ = other.gesture_source_;
67 touch_location_ = other.touch_location_;
68 raw_touch_location_ = other.raw_touch_location_;
69 gestures_ = other.gestures_;
70 return *this;
73 void GestureEventDataPacket::Push(const GestureEventData& gesture) {
74 DCHECK_NE(ET_UNKNOWN, gesture.type());
75 gestures_->push_back(gesture);
78 GestureEventDataPacket GestureEventDataPacket::FromTouch(
79 const ui::MotionEvent& touch) {
80 return GestureEventDataPacket(touch.GetEventTime(),
81 ToGestureSource(touch),
82 gfx::PointF(touch.GetX(), touch.GetY()),
83 gfx::PointF(touch.GetRawX(), touch.GetRawY()));
86 GestureEventDataPacket GestureEventDataPacket::FromTouchTimeout(
87 const GestureEventData& gesture) {
88 GestureEventDataPacket packet(gesture.time,
89 TOUCH_TIMEOUT,
90 gfx::PointF(gesture.x, gesture.y),
91 gfx::PointF(gesture.raw_x, gesture.raw_y));
92 packet.Push(gesture);
93 return packet;
96 } // namespace ui