| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/events/gesture_detection/motion_event_generic.h" | 5 #include "ui/events/gesture_detection/motion_event_generic.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/events/base_event_utils.h" |
| 8 | 9 |
| 9 namespace ui { | 10 namespace ui { |
| 10 | 11 |
| 11 PointerProperties::PointerProperties() | 12 PointerProperties::PointerProperties() |
| 12 : PointerProperties(0, 0, 0) { | 13 : PointerProperties(0, 0, 0) { |
| 13 } | 14 } |
| 14 | 15 |
| 15 PointerProperties::PointerProperties(float x, float y, float touch_major) | 16 PointerProperties::PointerProperties(float x, float y, float touch_major) |
| 16 : id(0), | 17 : id(0), |
| 17 tool_type(MotionEvent::TOOL_TYPE_UNKNOWN), | 18 tool_type(MotionEvent::TOOL_TYPE_UNKNOWN), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 39 touch_minor(event.GetTouchMinor(pointer_index)), | 40 touch_minor(event.GetTouchMinor(pointer_index)), |
| 40 orientation(event.GetOrientation(pointer_index)), | 41 orientation(event.GetOrientation(pointer_index)), |
| 41 source_device_id(0) { | 42 source_device_id(0) { |
| 42 } | 43 } |
| 43 | 44 |
| 44 MotionEventGeneric::MotionEventGeneric(Action action, | 45 MotionEventGeneric::MotionEventGeneric(Action action, |
| 45 base::TimeTicks event_time, | 46 base::TimeTicks event_time, |
| 46 const PointerProperties& pointer) | 47 const PointerProperties& pointer) |
| 47 : action_(action), | 48 : action_(action), |
| 48 event_time_(event_time), | 49 event_time_(event_time), |
| 49 id_(0), | 50 unique_event_id_(ui::GetNextTouchEventId()), |
| 50 action_index_(0), | 51 action_index_(0), |
| 51 button_state_(0), | 52 button_state_(0), |
| 52 flags_(0) { | 53 flags_(0) { |
| 53 PushPointer(pointer); | 54 PushPointer(pointer); |
| 54 } | 55 } |
| 55 | 56 |
| 56 MotionEventGeneric::MotionEventGeneric(const MotionEventGeneric& other) | 57 MotionEventGeneric::MotionEventGeneric(const MotionEventGeneric& other) |
| 57 : action_(other.action_), | 58 : action_(other.action_), |
| 58 event_time_(other.event_time_), | 59 event_time_(other.event_time_), |
| 59 id_(other.id_), | 60 unique_event_id_(other.unique_event_id_), |
| 60 action_index_(other.action_index_), | 61 action_index_(other.action_index_), |
| 61 button_state_(other.button_state_), | 62 button_state_(other.button_state_), |
| 62 flags_(other.flags_), | 63 flags_(other.flags_), |
| 63 pointers_(other.pointers_) { | 64 pointers_(other.pointers_) { |
| 64 const size_t history_size = other.GetHistorySize(); | 65 const size_t history_size = other.GetHistorySize(); |
| 65 for (size_t h = 0; h < history_size; ++h) | 66 for (size_t h = 0; h < history_size; ++h) |
| 66 PushHistoricalEvent(other.historical_events_[h]->Clone()); | 67 PushHistoricalEvent(other.historical_events_[h]->Clone()); |
| 67 } | 68 } |
| 68 | 69 |
| 69 MotionEventGeneric::~MotionEventGeneric() { | 70 MotionEventGeneric::~MotionEventGeneric() { |
| 70 } | 71 } |
| 71 | 72 |
| 72 int MotionEventGeneric::GetId() const { | 73 uint32 MotionEventGeneric::GetUniqueEventId() const { |
| 73 return id_; | 74 return unique_event_id_; |
| 74 } | 75 } |
| 75 | 76 |
| 76 MotionEvent::Action MotionEventGeneric::GetAction() const { | 77 MotionEvent::Action MotionEventGeneric::GetAction() const { |
| 77 return action_; | 78 return action_; |
| 78 } | 79 } |
| 79 | 80 |
| 80 int MotionEventGeneric::GetActionIndex() const { | 81 int MotionEventGeneric::GetActionIndex() const { |
| 81 DCHECK(action_ == ACTION_POINTER_DOWN || action_ == ACTION_POINTER_UP); | 82 DCHECK(action_ == ACTION_POINTER_DOWN || action_ == ACTION_POINTER_UP); |
| 82 DCHECK_GE(action_index_, 0); | 83 DCHECK_GE(action_index_, 0); |
| 83 DCHECK_LT(action_index_, static_cast<int>(pointers_->size())); | 84 DCHECK_LT(action_index_, static_cast<int>(pointers_->size())); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 return make_scoped_ptr(new MotionEventGeneric(event, with_history)); | 188 return make_scoped_ptr(new MotionEventGeneric(event, with_history)); |
| 188 } | 189 } |
| 189 | 190 |
| 190 // static | 191 // static |
| 191 scoped_ptr<MotionEventGeneric> MotionEventGeneric::CancelEvent( | 192 scoped_ptr<MotionEventGeneric> MotionEventGeneric::CancelEvent( |
| 192 const MotionEvent& event) { | 193 const MotionEvent& event) { |
| 193 bool with_history = false; | 194 bool with_history = false; |
| 194 scoped_ptr<MotionEventGeneric> cancel_event( | 195 scoped_ptr<MotionEventGeneric> cancel_event( |
| 195 new MotionEventGeneric(event, with_history)); | 196 new MotionEventGeneric(event, with_history)); |
| 196 cancel_event->set_action(ACTION_CANCEL); | 197 cancel_event->set_action(ACTION_CANCEL); |
| 198 cancel_event->set_unique_event_id(ui::GetNextTouchEventId()); |
| 197 return cancel_event.Pass(); | 199 return cancel_event.Pass(); |
| 198 } | 200 } |
| 199 | 201 |
| 200 size_t MotionEventGeneric::PushPointer(const PointerProperties& pointer) { | 202 size_t MotionEventGeneric::PushPointer(const PointerProperties& pointer) { |
| 201 DCHECK_EQ(0U, GetHistorySize()); | 203 DCHECK_EQ(0U, GetHistorySize()); |
| 202 pointers_->push_back(pointer); | 204 pointers_->push_back(pointer); |
| 203 return pointers_->size() - 1; | 205 return pointers_->size() - 1; |
| 204 } | 206 } |
| 205 | 207 |
| 206 void MotionEventGeneric::RemovePointerAt(size_t index) { | 208 void MotionEventGeneric::RemovePointerAt(size_t index) { |
| 207 DCHECK_LT(index, pointers_->size()); | 209 DCHECK_LT(index, pointers_->size()); |
| 208 pointers_->erase(pointers_->begin() + index); | 210 pointers_->erase(pointers_->begin() + index); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void MotionEventGeneric::PushHistoricalEvent(scoped_ptr<MotionEvent> event) { | 213 void MotionEventGeneric::PushHistoricalEvent(scoped_ptr<MotionEvent> event) { |
| 212 DCHECK(event); | 214 DCHECK(event); |
| 213 DCHECK_EQ(event->GetAction(), ACTION_MOVE); | 215 DCHECK_EQ(event->GetAction(), ACTION_MOVE); |
| 214 DCHECK_EQ(event->GetPointerCount(), GetPointerCount()); | 216 DCHECK_EQ(event->GetPointerCount(), GetPointerCount()); |
| 215 DCHECK_EQ(event->GetAction(), GetAction()); | 217 DCHECK_EQ(event->GetAction(), GetAction()); |
| 216 DCHECK_LE(event->GetEventTime().ToInternalValue(), | 218 DCHECK_LE(event->GetEventTime().ToInternalValue(), |
| 217 GetEventTime().ToInternalValue()); | 219 GetEventTime().ToInternalValue()); |
| 218 historical_events_.push_back(event.release()); | 220 historical_events_.push_back(event.release()); |
| 219 } | 221 } |
| 220 | 222 |
| 221 MotionEventGeneric::MotionEventGeneric() | 223 MotionEventGeneric::MotionEventGeneric() |
| 222 : action_(ACTION_CANCEL), id_(0), action_index_(0), button_state_(0) { | 224 : action_(ACTION_CANCEL), |
| 225 unique_event_id_(ui::GetNextTouchEventId()), |
| 226 action_index_(0), |
| 227 button_state_(0) { |
| 223 } | 228 } |
| 224 | 229 |
| 225 MotionEventGeneric::MotionEventGeneric(const MotionEvent& event, | 230 MotionEventGeneric::MotionEventGeneric(const MotionEvent& event, |
| 226 bool with_history) | 231 bool with_history) |
| 227 : action_(event.GetAction()), | 232 : action_(event.GetAction()), |
| 228 event_time_(event.GetEventTime()), | 233 event_time_(event.GetEventTime()), |
| 229 id_(event.GetId()), | 234 unique_event_id_(event.GetUniqueEventId()), |
| 230 action_index_( | 235 action_index_( |
| 231 (action_ == ACTION_POINTER_UP || action_ == ACTION_POINTER_DOWN) | 236 (action_ == ACTION_POINTER_UP || action_ == ACTION_POINTER_DOWN) |
| 232 ? event.GetActionIndex() | 237 ? event.GetActionIndex() |
| 233 : 0), | 238 : 0), |
| 234 button_state_(event.GetButtonState()), | 239 button_state_(event.GetButtonState()), |
| 235 flags_(event.GetFlags()) { | 240 flags_(event.GetFlags()) { |
| 236 const size_t pointer_count = event.GetPointerCount(); | 241 const size_t pointer_count = event.GetPointerCount(); |
| 237 for (size_t i = 0; i < pointer_count; ++i) | 242 for (size_t i = 0; i < pointer_count; ++i) |
| 238 PushPointer(PointerProperties(event, i)); | 243 PushPointer(PointerProperties(event, i)); |
| 239 | 244 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 252 event.GetHistoricalTouchMajor(i, h))); | 257 event.GetHistoricalTouchMajor(i, h))); |
| 253 } | 258 } |
| 254 PushHistoricalEvent(historical_event.Pass()); | 259 PushHistoricalEvent(historical_event.Pass()); |
| 255 } | 260 } |
| 256 } | 261 } |
| 257 | 262 |
| 258 MotionEventGeneric& MotionEventGeneric::operator=( | 263 MotionEventGeneric& MotionEventGeneric::operator=( |
| 259 const MotionEventGeneric& other) { | 264 const MotionEventGeneric& other) { |
| 260 action_ = other.action_; | 265 action_ = other.action_; |
| 261 event_time_ = other.event_time_; | 266 event_time_ = other.event_time_; |
| 262 id_ = other.id_; | 267 unique_event_id_ = other.unique_event_id_; |
| 263 action_index_ = other.action_index_; | 268 action_index_ = other.action_index_; |
| 264 button_state_ = other.button_state_; | 269 button_state_ = other.button_state_; |
| 265 flags_ = other.flags_; | 270 flags_ = other.flags_; |
| 266 pointers_ = other.pointers_; | 271 pointers_ = other.pointers_; |
| 267 const size_t history_size = other.GetHistorySize(); | 272 const size_t history_size = other.GetHistorySize(); |
| 268 for (size_t h = 0; h < history_size; ++h) | 273 for (size_t h = 0; h < history_size; ++h) |
| 269 PushHistoricalEvent(other.historical_events_[h]->Clone()); | 274 PushHistoricalEvent(other.historical_events_[h]->Clone()); |
| 270 return *this; | 275 return *this; |
| 271 } | 276 } |
| 272 | 277 |
| 273 void MotionEventGeneric::PopPointer() { | 278 void MotionEventGeneric::PopPointer() { |
| 274 DCHECK_GT(pointers_->size(), 0U); | 279 DCHECK_GT(pointers_->size(), 0U); |
| 275 pointers_->pop_back(); | 280 pointers_->pop_back(); |
| 276 } | 281 } |
| 277 | 282 |
| 278 } // namespace ui | 283 } // namespace ui |
| OLD | NEW |