platformKeys: Add per-extension sign permissions.
[chromium-blink-merge.git] / ui / events / gesture_detection / gesture_event_data_packet.cc
blobaac1d4edc1923be229ed8adb41e6765b5aa31fc2
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), ack_state_(AckState::PENDING) {
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 ack_state_(AckState::PENDING) {
49 DCHECK_NE(gesture_source_, UNDEFINED);
52 GestureEventDataPacket::GestureEventDataPacket(
53 const GestureEventDataPacket& other)
54 : timestamp_(other.timestamp_),
55 gestures_(other.gestures_),
56 touch_location_(other.touch_location_),
57 raw_touch_location_(other.raw_touch_location_),
58 gesture_source_(other.gesture_source_),
59 ack_state_(AckState::PENDING) {
62 GestureEventDataPacket::~GestureEventDataPacket() {
65 GestureEventDataPacket& GestureEventDataPacket::operator=(
66 const GestureEventDataPacket& other) {
67 timestamp_ = other.timestamp_;
68 gesture_source_ = other.gesture_source_;
69 touch_location_ = other.touch_location_;
70 raw_touch_location_ = other.raw_touch_location_;
71 gestures_ = other.gestures_;
72 ack_state_ = other.ack_state_;
73 return *this;
76 void GestureEventDataPacket::Push(const GestureEventData& gesture) {
77 DCHECK_NE(ET_UNKNOWN, gesture.type());
78 gestures_->push_back(gesture);
81 GestureEventDataPacket GestureEventDataPacket::FromTouch(
82 const ui::MotionEvent& touch) {
83 return GestureEventDataPacket(touch.GetEventTime(),
84 ToGestureSource(touch),
85 gfx::PointF(touch.GetX(), touch.GetY()),
86 gfx::PointF(touch.GetRawX(), touch.GetRawY()));
89 GestureEventDataPacket GestureEventDataPacket::FromTouchTimeout(
90 const GestureEventData& gesture) {
91 GestureEventDataPacket packet(gesture.time,
92 TOUCH_TIMEOUT,
93 gfx::PointF(gesture.x, gesture.y),
94 gfx::PointF(gesture.raw_x, gesture.raw_y));
95 packet.Push(gesture);
96 return packet;
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;
104 } // namespace ui