| 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/gesture_detector.h" | 5 #include "ui/events/gesture_detection/gesture_detector.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "ui/events/gesture_detection/motion_event.h" | 10 #include "ui/events/gesture_detection/motion_event.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 257 |
| 258 case MotionEvent::ACTION_MOVE: | 258 case MotionEvent::ACTION_MOVE: |
| 259 if (in_longpress_) | 259 if (in_longpress_) |
| 260 break; | 260 break; |
| 261 | 261 |
| 262 { | 262 { |
| 263 const float scroll_x = last_focus_x_ - focus_x; | 263 const float scroll_x = last_focus_x_ - focus_x; |
| 264 const float scroll_y = last_focus_y_ - focus_y; | 264 const float scroll_y = last_focus_y_ - focus_y; |
| 265 if (is_double_tapping_) { | 265 if (is_double_tapping_) { |
| 266 // Give the move events of the double-tap. | 266 // Give the move events of the double-tap. |
| 267 DCHECK(double_tap_listener_); |
| 267 handled |= double_tap_listener_->OnDoubleTapEvent(ev); | 268 handled |= double_tap_listener_->OnDoubleTapEvent(ev); |
| 268 } else if (always_in_tap_region_) { | 269 } else if (always_in_tap_region_) { |
| 269 const int delta_x = static_cast<int>(focus_x - down_focus_x_); | 270 const int delta_x = static_cast<int>(focus_x - down_focus_x_); |
| 270 const int delta_y = static_cast<int>(focus_y - down_focus_y_); | 271 const int delta_y = static_cast<int>(focus_y - down_focus_y_); |
| 271 int distance = (delta_x * delta_x) + (delta_y * delta_y); | 272 int distance = (delta_x * delta_x) + (delta_y * delta_y); |
| 272 if (distance > touch_slop_square_) { | 273 if (distance > touch_slop_square_) { |
| 273 handled = listener_->OnScroll( | 274 handled = listener_->OnScroll( |
| 274 *current_down_event_, ev, scroll_x, scroll_y); | 275 *current_down_event_, ev, scroll_x, scroll_y); |
| 275 last_focus_x_ = focus_x; | 276 last_focus_x_ = focus_x; |
| 276 last_focus_y_ = focus_y; | 277 last_focus_y_ = focus_y; |
| 277 always_in_tap_region_ = false; | 278 always_in_tap_region_ = false; |
| 278 timeout_handler_->Stop(); | 279 timeout_handler_->Stop(); |
| 279 } | 280 } |
| 280 if (distance > double_tap_touch_slop_square_) | 281 if (distance > double_tap_touch_slop_square_) |
| 281 always_in_bigger_tap_region_ = false; | 282 always_in_bigger_tap_region_ = false; |
| 282 } else if ((std::abs(scroll_x) >= 1) || (std::abs(scroll_y) >= 1)) { | 283 } else if ((std::abs(scroll_x) >= 1) || (std::abs(scroll_y) >= 1)) { |
| 283 handled = | 284 handled = |
| 284 listener_->OnScroll(*current_down_event_, ev, scroll_x, scroll_y); | 285 listener_->OnScroll(*current_down_event_, ev, scroll_x, scroll_y); |
| 285 last_focus_x_ = focus_x; | 286 last_focus_x_ = focus_x; |
| 286 last_focus_y_ = focus_y; | 287 last_focus_y_ = focus_y; |
| 287 } | 288 } |
| 288 } | 289 } |
| 289 break; | 290 break; |
| 290 | 291 |
| 291 case MotionEvent::ACTION_UP: | 292 case MotionEvent::ACTION_UP: |
| 292 still_down_ = false; | 293 still_down_ = false; |
| 293 { | 294 { |
| 294 if (is_double_tapping_) { | 295 if (is_double_tapping_) { |
| 295 // Finally, give the up event of the double-tap. | 296 // Finally, give the up event of the double-tap. |
| 297 DCHECK(double_tap_listener_); |
| 296 handled |= double_tap_listener_->OnDoubleTapEvent(ev); | 298 handled |= double_tap_listener_->OnDoubleTapEvent(ev); |
| 297 } else if (in_longpress_) { | 299 } else if (in_longpress_) { |
| 298 timeout_handler_->StopTimeout(TAP); | 300 timeout_handler_->StopTimeout(TAP); |
| 299 in_longpress_ = false; | 301 in_longpress_ = false; |
| 300 } else if (always_in_tap_region_) { | 302 } else if (always_in_tap_region_) { |
| 301 handled = listener_->OnSingleTapUp(ev); | 303 handled = listener_->OnSingleTapUp(ev); |
| 302 if (defer_confirm_single_tap_ && double_tap_listener_ != NULL) { | 304 if (defer_confirm_single_tap_ && double_tap_listener_ != NULL) { |
| 303 double_tap_listener_->OnSingleTapConfirmed(ev); | 305 double_tap_listener_->OnSingleTapConfirmed(ev); |
| 304 } | 306 } |
| 305 } else { | 307 } else { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 if (second_down.GetEventTime() - first_up.GetEventTime() > | 400 if (second_down.GetEventTime() - first_up.GetEventTime() > |
| 399 double_tap_timeout_) | 401 double_tap_timeout_) |
| 400 return false; | 402 return false; |
| 401 | 403 |
| 402 int delta_x = static_cast<int>(first_down.GetX() - second_down.GetX()); | 404 int delta_x = static_cast<int>(first_down.GetX() - second_down.GetX()); |
| 403 int delta_y = static_cast<int>(first_down.GetY() - second_down.GetY()); | 405 int delta_y = static_cast<int>(first_down.GetY() - second_down.GetY()); |
| 404 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square_); | 406 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square_); |
| 405 } | 407 } |
| 406 | 408 |
| 407 } // namespace ui | 409 } // namespace ui |
| OLD | NEW |