• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #include "ui/events/gesture_detection/gesture_event_data_packet.h"
6 
7 #include "base/logging.h"
8 #include "ui/events/gesture_detection/motion_event.h"
9 
10 namespace ui {
11 namespace {
12 
ToGestureSource(const ui::MotionEvent & event)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   };
29   NOTREACHED() << "Invalid ui::MotionEvent action: " << event.GetAction();
30   return GestureEventDataPacket::INVALID;
31 }
32 
33 }  // namespace
34 
GestureEventDataPacket()35 GestureEventDataPacket::GestureEventDataPacket()
36     : gesture_source_(UNDEFINED) {
37 }
38 
GestureEventDataPacket(base::TimeTicks timestamp,GestureSource source,const gfx::PointF & touch_location,const gfx::PointF & raw_touch_location)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);
49 }
50 
GestureEventDataPacket(const GestureEventDataPacket & other)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_) {
58 }
59 
~GestureEventDataPacket()60 GestureEventDataPacket::~GestureEventDataPacket() {
61 }
62 
operator =(const GestureEventDataPacket & other)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;
71 }
72 
Push(const GestureEventData & gesture)73 void GestureEventDataPacket::Push(const GestureEventData& gesture) {
74   DCHECK_NE(ET_UNKNOWN, gesture.type());
75   gestures_.push_back(gesture);
76 }
77 
FromTouch(const ui::MotionEvent & touch)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()));
84 }
85 
FromTouchTimeout(const GestureEventData & gesture)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;
94 }
95 
96 }  // namespace ui
97