Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / events / gesture_detection / motion_event_generic.cc
blobb76a37e05dfbb2fdcd4edd4662fc51a67a0568bf
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/motion_event_generic.h"
7 #include "base/logging.h"
9 namespace ui {
11 PointerProperties::PointerProperties()
12 : id(0),
13 tool_type(MotionEvent::TOOL_TYPE_UNKNOWN),
14 x(0),
15 y(0),
16 raw_x(0),
17 raw_y(0),
18 pressure(0),
19 touch_major(0) {
22 PointerProperties::PointerProperties(float x, float y)
23 : id(0),
24 tool_type(MotionEvent::TOOL_TYPE_UNKNOWN),
25 x(x),
26 y(y),
27 raw_x(x),
28 raw_y(y),
29 pressure(0),
30 touch_major(0) {
33 MotionEventGeneric::MotionEventGeneric()
34 : action_(ACTION_CANCEL), id_(0), action_index_(0), button_state_(0) {
37 MotionEventGeneric::MotionEventGeneric(Action action,
38 base::TimeTicks event_time,
39 const PointerProperties& pointer)
40 : action_(action),
41 event_time_(event_time),
42 id_(0),
43 action_index_(0),
44 button_state_(0) {
45 PushPointer(pointer);
48 MotionEventGeneric::MotionEventGeneric(const MotionEventGeneric& other)
49 : action_(other.action_),
50 event_time_(other.event_time_),
51 id_(other.id_),
52 action_index_(other.action_index_),
53 button_state_(other.button_state_),
54 pointers_(other.pointers_) {
57 MotionEventGeneric::~MotionEventGeneric() {
60 int MotionEventGeneric::GetId() const {
61 return id_;
64 MotionEvent::Action MotionEventGeneric::GetAction() const {
65 return action_;
68 int MotionEventGeneric::GetActionIndex() const {
69 return action_index_;
72 size_t MotionEventGeneric::GetPointerCount() const {
73 return pointers_->size();
76 int MotionEventGeneric::GetPointerId(size_t pointer_index) const {
77 DCHECK_LT(pointer_index, pointers_->size());
78 return pointers_[pointer_index].id;
81 float MotionEventGeneric::GetX(size_t pointer_index) const {
82 DCHECK_LT(pointer_index, pointers_->size());
83 return pointers_[pointer_index].x;
86 float MotionEventGeneric::GetY(size_t pointer_index) const {
87 DCHECK_LT(pointer_index, pointers_->size());
88 return pointers_[pointer_index].y;
91 float MotionEventGeneric::GetRawX(size_t pointer_index) const {
92 DCHECK_LT(pointer_index, pointers_->size());
93 return pointers_[pointer_index].raw_x;
96 float MotionEventGeneric::GetRawY(size_t pointer_index) const {
97 DCHECK_LT(pointer_index, pointers_->size());
98 return pointers_[pointer_index].raw_y;
101 float MotionEventGeneric::GetTouchMajor(size_t pointer_index) const {
102 DCHECK_LT(pointer_index, pointers_->size());
103 return pointers_[pointer_index].touch_major;
106 float MotionEventGeneric::GetPressure(size_t pointer_index) const {
107 DCHECK_LT(pointer_index, pointers_->size());
108 return pointers_[pointer_index].pressure;
111 MotionEvent::ToolType MotionEventGeneric::GetToolType(
112 size_t pointer_index) const {
113 DCHECK_LT(pointer_index, pointers_->size());
114 return pointers_[pointer_index].tool_type;
117 int MotionEventGeneric::GetButtonState() const {
118 return button_state_;
121 base::TimeTicks MotionEventGeneric::GetEventTime() const {
122 return event_time_;
125 scoped_ptr<MotionEvent> MotionEventGeneric::Clone() const {
126 return scoped_ptr<MotionEvent>(new MotionEventGeneric(*this));
129 scoped_ptr<MotionEvent> MotionEventGeneric::Cancel() const {
130 scoped_ptr<MotionEventGeneric> event(new MotionEventGeneric(*this));
131 event->set_action(ACTION_CANCEL);
132 return event.PassAs<MotionEvent>();
135 void MotionEventGeneric::PushPointer(const PointerProperties& pointer) {
136 pointers_->push_back(pointer);
139 void MotionEventGeneric::PopPointer() {
140 DCHECK_GT(pointers_->size(), 0U);
141 pointers_->pop_back();
144 } // namespace ui