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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include "ui/events/gesture_detection/motion_event_generic.h" | 8 #include "ui/events/gesture_detection/motion_event_generic.h" |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" |
14 #include "ui/events/base_event_utils.h" | 15 #include "ui/events/base_event_utils.h" |
15 | 16 |
16 namespace ui { | 17 namespace ui { |
17 | 18 |
18 PointerProperties::PointerProperties() | 19 PointerProperties::PointerProperties() |
19 : PointerProperties(0, 0, 0) { | 20 : PointerProperties(0, 0, 0) { |
20 } | 21 } |
21 | 22 |
22 PointerProperties::PointerProperties(float x, float y, float touch_major) | 23 PointerProperties::PointerProperties(float x, float y, float touch_major) |
23 : id(0), | 24 : id(0), |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 return historical_events_[historical_index]->GetX(pointer_index); | 222 return historical_events_[historical_index]->GetX(pointer_index); |
222 } | 223 } |
223 | 224 |
224 float MotionEventGeneric::GetHistoricalY(size_t pointer_index, | 225 float MotionEventGeneric::GetHistoricalY(size_t pointer_index, |
225 size_t historical_index) const { | 226 size_t historical_index) const { |
226 DCHECK_LT(historical_index, historical_events_.size()); | 227 DCHECK_LT(historical_index, historical_events_.size()); |
227 return historical_events_[historical_index]->GetY(pointer_index); | 228 return historical_events_[historical_index]->GetY(pointer_index); |
228 } | 229 } |
229 | 230 |
230 // static | 231 // static |
231 scoped_ptr<MotionEventGeneric> MotionEventGeneric::CloneEvent( | 232 std::unique_ptr<MotionEventGeneric> MotionEventGeneric::CloneEvent( |
232 const MotionEvent& event) { | 233 const MotionEvent& event) { |
233 bool with_history = true; | 234 bool with_history = true; |
234 return make_scoped_ptr(new MotionEventGeneric(event, with_history)); | 235 return base::WrapUnique(new MotionEventGeneric(event, with_history)); |
235 } | 236 } |
236 | 237 |
237 // static | 238 // static |
238 scoped_ptr<MotionEventGeneric> MotionEventGeneric::CancelEvent( | 239 std::unique_ptr<MotionEventGeneric> MotionEventGeneric::CancelEvent( |
239 const MotionEvent& event) { | 240 const MotionEvent& event) { |
240 bool with_history = false; | 241 bool with_history = false; |
241 scoped_ptr<MotionEventGeneric> cancel_event( | 242 std::unique_ptr<MotionEventGeneric> cancel_event( |
242 new MotionEventGeneric(event, with_history)); | 243 new MotionEventGeneric(event, with_history)); |
243 cancel_event->set_action(ACTION_CANCEL); | 244 cancel_event->set_action(ACTION_CANCEL); |
244 cancel_event->set_unique_event_id(ui::GetNextTouchEventId()); | 245 cancel_event->set_unique_event_id(ui::GetNextTouchEventId()); |
245 return cancel_event; | 246 return cancel_event; |
246 } | 247 } |
247 | 248 |
248 size_t MotionEventGeneric::PushPointer(const PointerProperties& pointer) { | 249 size_t MotionEventGeneric::PushPointer(const PointerProperties& pointer) { |
249 DCHECK_EQ(0U, GetHistorySize()); | 250 DCHECK_EQ(0U, GetHistorySize()); |
250 pointers_->push_back(pointer); | 251 pointers_->push_back(pointer); |
251 return pointers_->size() - 1; | 252 return pointers_->size() - 1; |
252 } | 253 } |
253 | 254 |
254 void MotionEventGeneric::RemovePointerAt(size_t index) { | 255 void MotionEventGeneric::RemovePointerAt(size_t index) { |
255 DCHECK_LT(index, pointers_->size()); | 256 DCHECK_LT(index, pointers_->size()); |
256 pointers_->erase(pointers_->begin() + index); | 257 pointers_->erase(pointers_->begin() + index); |
257 } | 258 } |
258 | 259 |
259 void MotionEventGeneric::PushHistoricalEvent(scoped_ptr<MotionEvent> event) { | 260 void MotionEventGeneric::PushHistoricalEvent( |
| 261 std::unique_ptr<MotionEvent> event) { |
260 DCHECK(event); | 262 DCHECK(event); |
261 DCHECK_EQ(event->GetAction(), ACTION_MOVE); | 263 DCHECK_EQ(event->GetAction(), ACTION_MOVE); |
262 DCHECK_EQ(event->GetPointerCount(), GetPointerCount()); | 264 DCHECK_EQ(event->GetPointerCount(), GetPointerCount()); |
263 DCHECK_EQ(event->GetAction(), GetAction()); | 265 DCHECK_EQ(event->GetAction(), GetAction()); |
264 DCHECK_LE(event->GetEventTime().ToInternalValue(), | 266 DCHECK_LE(event->GetEventTime().ToInternalValue(), |
265 GetEventTime().ToInternalValue()); | 267 GetEventTime().ToInternalValue()); |
266 historical_events_.push_back(std::move(event)); | 268 historical_events_.push_back(std::move(event)); |
267 } | 269 } |
268 | 270 |
269 MotionEventGeneric::MotionEventGeneric() | 271 MotionEventGeneric::MotionEventGeneric() |
(...skipping 16 matching lines...) Expand all Loading... |
286 flags_(event.GetFlags()) { | 288 flags_(event.GetFlags()) { |
287 const size_t pointer_count = event.GetPointerCount(); | 289 const size_t pointer_count = event.GetPointerCount(); |
288 for (size_t i = 0; i < pointer_count; ++i) | 290 for (size_t i = 0; i < pointer_count; ++i) |
289 PushPointer(PointerProperties(event, i)); | 291 PushPointer(PointerProperties(event, i)); |
290 | 292 |
291 if (!with_history) | 293 if (!with_history) |
292 return; | 294 return; |
293 | 295 |
294 const size_t history_size = event.GetHistorySize(); | 296 const size_t history_size = event.GetHistorySize(); |
295 for (size_t h = 0; h < history_size; ++h) { | 297 for (size_t h = 0; h < history_size; ++h) { |
296 scoped_ptr<MotionEventGeneric> historical_event(new MotionEventGeneric()); | 298 std::unique_ptr<MotionEventGeneric> historical_event( |
| 299 new MotionEventGeneric()); |
297 historical_event->set_action(ACTION_MOVE); | 300 historical_event->set_action(ACTION_MOVE); |
298 historical_event->set_event_time(event.GetHistoricalEventTime(h)); | 301 historical_event->set_event_time(event.GetHistoricalEventTime(h)); |
299 for (size_t i = 0; i < pointer_count; ++i) { | 302 for (size_t i = 0; i < pointer_count; ++i) { |
300 historical_event->PushPointer( | 303 historical_event->PushPointer( |
301 PointerProperties(event.GetHistoricalX(i, h), | 304 PointerProperties(event.GetHistoricalX(i, h), |
302 event.GetHistoricalY(i, h), | 305 event.GetHistoricalY(i, h), |
303 event.GetHistoricalTouchMajor(i, h))); | 306 event.GetHistoricalTouchMajor(i, h))); |
304 } | 307 } |
305 PushHistoricalEvent(std::move(historical_event)); | 308 PushHistoricalEvent(std::move(historical_event)); |
306 } | 309 } |
(...skipping 13 matching lines...) Expand all Loading... |
320 PushHistoricalEvent(other.historical_events_[h]->Clone()); | 323 PushHistoricalEvent(other.historical_events_[h]->Clone()); |
321 return *this; | 324 return *this; |
322 } | 325 } |
323 | 326 |
324 void MotionEventGeneric::PopPointer() { | 327 void MotionEventGeneric::PopPointer() { |
325 DCHECK_GT(pointers_->size(), 0U); | 328 DCHECK_GT(pointers_->size(), 0U); |
326 pointers_->pop_back(); | 329 pointers_->pop_back(); |
327 } | 330 } |
328 | 331 |
329 } // namespace ui | 332 } // namespace ui |
OLD | NEW |