| 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/scale_gesture_detector.h" | 5 #include "ui/events/gesture_detection/scale_gesture_detector.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/float_util.h" | |
| 11 #include "base/logging.h" | 10 #include "base/logging.h" |
| 12 #include "ui/events/gesture_detection/motion_event.h" | 11 #include "ui/events/gesture_detection/motion_event.h" |
| 13 #include "ui/events/gesture_detection/scale_gesture_listeners.h" | 12 #include "ui/events/gesture_detection/scale_gesture_listeners.h" |
| 14 | 13 |
| 15 using base::TimeDelta; | 14 using base::TimeDelta; |
| 16 using base::TimeTicks; | 15 using base::TimeTicks; |
| 17 | 16 |
| 18 namespace ui { | 17 namespace ui { |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 void ScaleGestureDetector::AddTouchHistory(const MotionEvent& ev) { | 277 void ScaleGestureDetector::AddTouchHistory(const MotionEvent& ev) { |
| 279 const base::TimeTicks current_time = ev.GetEventTime(); | 278 const base::TimeTicks current_time = ev.GetEventTime(); |
| 280 DCHECK(!current_time.is_null()); | 279 DCHECK(!current_time.is_null()); |
| 281 const int count = static_cast<int>(ev.GetPointerCount()); | 280 const int count = static_cast<int>(ev.GetPointerCount()); |
| 282 bool accept = touch_history_last_accepted_time_.is_null() || | 281 bool accept = touch_history_last_accepted_time_.is_null() || |
| 283 (current_time - touch_history_last_accepted_time_) >= | 282 (current_time - touch_history_last_accepted_time_) >= |
| 284 base::TimeDelta::FromMilliseconds(kTouchStabilizeTimeMs); | 283 base::TimeDelta::FromMilliseconds(kTouchStabilizeTimeMs); |
| 285 float total = 0; | 284 float total = 0; |
| 286 int sample_count = 0; | 285 int sample_count = 0; |
| 287 for (int i = 0; i < count; i++) { | 286 for (int i = 0; i < count; i++) { |
| 288 const bool has_last_accepted = !base::IsNaN(touch_history_last_accepted_); | 287 const bool has_last_accepted = !std::isnan(touch_history_last_accepted_); |
| 289 const int history_size = static_cast<int>(ev.GetHistorySize()); | 288 const int history_size = static_cast<int>(ev.GetHistorySize()); |
| 290 const int pointersample_count = history_size + 1; | 289 const int pointersample_count = history_size + 1; |
| 291 for (int h = 0; h < pointersample_count; h++) { | 290 for (int h = 0; h < pointersample_count; h++) { |
| 292 float major; | 291 float major; |
| 293 if (h < history_size) { | 292 if (h < history_size) { |
| 294 major = ev.GetHistoricalTouchMajor(i, h); | 293 major = ev.GetHistoricalTouchMajor(i, h); |
| 295 } else { | 294 } else { |
| 296 major = ev.GetTouchMajor(i); | 295 major = ev.GetTouchMajor(i); |
| 297 } | 296 } |
| 298 if (major < touch_min_major_) | 297 if (major < touch_min_major_) |
| 299 major = touch_min_major_; | 298 major = touch_min_major_; |
| 300 if (major > touch_max_major_) | 299 if (major > touch_max_major_) |
| 301 major = touch_max_major_; | 300 major = touch_max_major_; |
| 302 total += major; | 301 total += major; |
| 303 | 302 |
| 304 if (base::IsNaN(touch_upper_) || major > touch_upper_) { | 303 if (std::isnan(touch_upper_) || major > touch_upper_) { |
| 305 touch_upper_ = major; | 304 touch_upper_ = major; |
| 306 } | 305 } |
| 307 if (base::IsNaN(touch_lower_) || major < touch_lower_) { | 306 if (std::isnan(touch_lower_) || major < touch_lower_) { |
| 308 touch_lower_ = major; | 307 touch_lower_ = major; |
| 309 } | 308 } |
| 310 | 309 |
| 311 if (has_last_accepted) { | 310 if (has_last_accepted) { |
| 312 const float major_delta = major - touch_history_last_accepted_; | 311 const float major_delta = major - touch_history_last_accepted_; |
| 313 const int direction_sig = | 312 const int direction_sig = |
| 314 major_delta > 0 ? 1 : (major_delta < 0 ? -1 : 0); | 313 major_delta > 0 ? 1 : (major_delta < 0 ? -1 : 0); |
| 315 if (direction_sig != touch_history_direction_ || | 314 if (direction_sig != touch_history_direction_ || |
| 316 (direction_sig == 0 && touch_history_direction_ == 0)) { | 315 (direction_sig == 0 && touch_history_direction_ == 0)) { |
| 317 touch_history_direction_ = direction_sig; | 316 touch_history_direction_ = direction_sig; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 345 touch_history_last_accepted_time_ = base::TimeTicks(); | 344 touch_history_last_accepted_time_ = base::TimeTicks(); |
| 346 } | 345 } |
| 347 | 346 |
| 348 void ScaleGestureDetector::ResetScaleWithSpan(float span) { | 347 void ScaleGestureDetector::ResetScaleWithSpan(float span) { |
| 349 in_progress_ = false; | 348 in_progress_ = false; |
| 350 initial_span_ = span; | 349 initial_span_ = span; |
| 351 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; | 350 double_tap_mode_ = DOUBLE_TAP_MODE_NONE; |
| 352 } | 351 } |
| 353 | 352 |
| 354 } // namespace ui | 353 } // namespace ui |
| OLD | NEW |