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 uint64 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 DCHECK(event); | 213 DCHECK(event); |
213 DCHECK_EQ(event->GetAction(), ACTION_MOVE); | 214 DCHECK_EQ(event->GetAction(), ACTION_MOVE); |
214 DCHECK_EQ(event->GetPointerCount(), GetPointerCount()); | 215 DCHECK_EQ(event->GetPointerCount(), GetPointerCount()); |
215 DCHECK_EQ(event->GetAction(), GetAction()); | 216 DCHECK_EQ(event->GetAction(), GetAction()); |
216 DCHECK_LE(event->GetEventTime().ToInternalValue(), | 217 DCHECK_LE(event->GetEventTime().ToInternalValue(), |
217 GetEventTime().ToInternalValue()); | 218 GetEventTime().ToInternalValue()); |
218 historical_events_.push_back(event.release()); | 219 historical_events_.push_back(event.release()); |
219 } | 220 } |
220 | 221 |
221 MotionEventGeneric::MotionEventGeneric() | 222 MotionEventGeneric::MotionEventGeneric() |
222 : action_(ACTION_CANCEL), id_(0), action_index_(0), button_state_(0) { | 223 : action_(ACTION_CANCEL), |
224 unique_event_id_(ui::GetNextTouchEventId()), | |
jdduke (slow)
2015/04/21 22:40:16
I can't say I love using globals, but this is prob
tdresser
2015/04/22 12:59:00
I agree, but I think that ensuring that these ids
lanwei
2015/04/22 20:51:31
I also agree, in many cases such as for different
| |
225 action_index_(0), | |
226 button_state_(0) { | |
223 } | 227 } |
224 | 228 |
225 MotionEventGeneric::MotionEventGeneric(const MotionEvent& event, | 229 MotionEventGeneric::MotionEventGeneric(const MotionEvent& event, |
226 bool with_history) | 230 bool with_history) |
227 : action_(event.GetAction()), | 231 : action_(event.GetAction()), |
228 event_time_(event.GetEventTime()), | 232 event_time_(event.GetEventTime()), |
229 id_(event.GetId()), | 233 unique_event_id_(event.GetUniqueEventId()), |
230 action_index_( | 234 action_index_( |
231 (action_ == ACTION_POINTER_UP || action_ == ACTION_POINTER_DOWN) | 235 (action_ == ACTION_POINTER_UP || action_ == ACTION_POINTER_DOWN) |
232 ? event.GetActionIndex() | 236 ? event.GetActionIndex() |
233 : 0), | 237 : 0), |
234 button_state_(event.GetButtonState()), | 238 button_state_(event.GetButtonState()), |
235 flags_(event.GetFlags()) { | 239 flags_(event.GetFlags()) { |
236 const size_t pointer_count = event.GetPointerCount(); | 240 const size_t pointer_count = event.GetPointerCount(); |
237 for (size_t i = 0; i < pointer_count; ++i) | 241 for (size_t i = 0; i < pointer_count; ++i) |
238 PushPointer(PointerProperties(event, i)); | 242 PushPointer(PointerProperties(event, i)); |
239 | 243 |
(...skipping 12 matching lines...) Expand all Loading... | |
252 event.GetHistoricalTouchMajor(i, h))); | 256 event.GetHistoricalTouchMajor(i, h))); |
253 } | 257 } |
254 PushHistoricalEvent(historical_event.Pass()); | 258 PushHistoricalEvent(historical_event.Pass()); |
255 } | 259 } |
256 } | 260 } |
257 | 261 |
258 MotionEventGeneric& MotionEventGeneric::operator=( | 262 MotionEventGeneric& MotionEventGeneric::operator=( |
259 const MotionEventGeneric& other) { | 263 const MotionEventGeneric& other) { |
260 action_ = other.action_; | 264 action_ = other.action_; |
261 event_time_ = other.event_time_; | 265 event_time_ = other.event_time_; |
262 id_ = other.id_; | 266 unique_event_id_ = other.unique_event_id_; |
263 action_index_ = other.action_index_; | 267 action_index_ = other.action_index_; |
264 button_state_ = other.button_state_; | 268 button_state_ = other.button_state_; |
265 flags_ = other.flags_; | 269 flags_ = other.flags_; |
266 pointers_ = other.pointers_; | 270 pointers_ = other.pointers_; |
267 const size_t history_size = other.GetHistorySize(); | 271 const size_t history_size = other.GetHistorySize(); |
268 for (size_t h = 0; h < history_size; ++h) | 272 for (size_t h = 0; h < history_size; ++h) |
269 PushHistoricalEvent(other.historical_events_[h]->Clone()); | 273 PushHistoricalEvent(other.historical_events_[h]->Clone()); |
270 return *this; | 274 return *this; |
271 } | 275 } |
272 | 276 |
273 void MotionEventGeneric::PopPointer() { | 277 void MotionEventGeneric::PopPointer() { |
274 DCHECK_GT(pointers_->size(), 0U); | 278 DCHECK_GT(pointers_->size(), 0U); |
275 pointers_->pop_back(); | 279 pointers_->pop_back(); |
276 } | 280 } |
277 | 281 |
278 } // namespace ui | 282 } // namespace ui |
OLD | NEW |