OLD | NEW |
(Empty) | |
| 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/motion_event_generic.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace ui { |
| 10 |
| 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) { |
| 20 } |
| 21 |
| 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) { |
| 31 } |
| 32 |
| 33 MotionEventGeneric::MotionEventGeneric() |
| 34 : action_(ACTION_CANCEL), id_(0), action_index_(0), button_state_(0) { |
| 35 } |
| 36 |
| 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 pointers_(1, pointer) { |
| 46 } |
| 47 |
| 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_) { |
| 55 } |
| 56 |
| 57 MotionEventGeneric::~MotionEventGeneric() { |
| 58 } |
| 59 |
| 60 int MotionEventGeneric::GetId() const { |
| 61 return id_; |
| 62 } |
| 63 |
| 64 MotionEvent::Action MotionEventGeneric::GetAction() const { |
| 65 return action_; |
| 66 } |
| 67 |
| 68 int MotionEventGeneric::GetActionIndex() const { |
| 69 return action_index_; |
| 70 } |
| 71 |
| 72 size_t MotionEventGeneric::GetPointerCount() const { |
| 73 return pointers_.size(); |
| 74 } |
| 75 |
| 76 int MotionEventGeneric::GetPointerId(size_t pointer_index) const { |
| 77 DCHECK_LT(pointer_index, pointers_.size()); |
| 78 return pointers_[pointer_index].id; |
| 79 } |
| 80 |
| 81 float MotionEventGeneric::GetX(size_t pointer_index) const { |
| 82 DCHECK_LT(pointer_index, pointers_.size()); |
| 83 return pointers_[pointer_index].x; |
| 84 } |
| 85 |
| 86 float MotionEventGeneric::GetY(size_t pointer_index) const { |
| 87 DCHECK_LT(pointer_index, pointers_.size()); |
| 88 return pointers_[pointer_index].y; |
| 89 } |
| 90 |
| 91 float MotionEventGeneric::GetRawX(size_t pointer_index) const { |
| 92 DCHECK_LT(pointer_index, pointers_.size()); |
| 93 return pointers_[pointer_index].raw_x; |
| 94 } |
| 95 |
| 96 float MotionEventGeneric::GetRawY(size_t pointer_index) const { |
| 97 DCHECK_LT(pointer_index, pointers_.size()); |
| 98 return pointers_[pointer_index].raw_y; |
| 99 } |
| 100 |
| 101 float MotionEventGeneric::GetTouchMajor(size_t pointer_index) const { |
| 102 DCHECK_LT(pointer_index, pointers_.size()); |
| 103 return pointers_[pointer_index].touch_major; |
| 104 } |
| 105 |
| 106 float MotionEventGeneric::GetPressure(size_t pointer_index) const { |
| 107 DCHECK_LT(pointer_index, pointers_.size()); |
| 108 return pointers_[pointer_index].pressure; |
| 109 } |
| 110 |
| 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; |
| 115 } |
| 116 |
| 117 int MotionEventGeneric::GetButtonState() const { |
| 118 return button_state_; |
| 119 } |
| 120 |
| 121 base::TimeTicks MotionEventGeneric::GetEventTime() const { |
| 122 return event_time_; |
| 123 } |
| 124 |
| 125 scoped_ptr<MotionEvent> MotionEventGeneric::Clone() const { |
| 126 return scoped_ptr<MotionEvent>(new MotionEventGeneric(*this)); |
| 127 } |
| 128 |
| 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>(); |
| 133 } |
| 134 |
| 135 void MotionEventGeneric::PushPointer(const PointerProperties& pointer) { |
| 136 pointers_.push_back(pointer); |
| 137 } |
| 138 |
| 139 void MotionEventGeneric::PopPointer() { |
| 140 DCHECK_GT(pointers_.size(), 0U); |
| 141 pointers_.pop_back(); |
| 142 } |
| 143 |
| 144 } // namespace ui |
OLD | NEW |