Chromium Code Reviews| 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_provider.h" | 5 #include "ui/events/gesture_detection/gesture_provider.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "ui/events/event_constants.h" | 11 #include "ui/events/event_constants.h" |
| 12 #include "ui/events/gesture_detection/gesture_detection_switches.h" | |
| 12 #include "ui/events/gesture_detection/gesture_event_data.h" | 13 #include "ui/events/gesture_detection/gesture_event_data.h" |
| 13 #include "ui/events/gesture_detection/gesture_listeners.h" | 14 #include "ui/events/gesture_detection/gesture_listeners.h" |
| 14 #include "ui/events/gesture_detection/motion_event.h" | 15 #include "ui/events/gesture_detection/motion_event.h" |
| 15 #include "ui/events/gesture_detection/motion_event_generic.h" | 16 #include "ui/events/gesture_detection/motion_event_generic.h" |
| 16 #include "ui/events/gesture_detection/scale_gesture_listeners.h" | 17 #include "ui/events/gesture_detection/scale_gesture_listeners.h" |
| 17 #include "ui/gfx/geometry/point_f.h" | 18 #include "ui/gfx/geometry/point_f.h" |
| 18 | 19 |
| 19 namespace ui { | 20 namespace ui { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 e1.GetY(), | 312 e1.GetY(), |
| 312 e1.GetRawX(), | 313 e1.GetRawX(), |
| 313 e1.GetRawY(), | 314 e1.GetRawY(), |
| 314 e2.GetPointerCount(), | 315 e2.GetPointerCount(), |
| 315 GetBoundingBox(e2, scroll_details.type()), | 316 GetBoundingBox(e2, scroll_details.type()), |
| 316 e2.GetFlags())); | 317 e2.GetFlags())); |
| 317 DCHECK(scroll_event_sent_); | 318 DCHECK(scroll_event_sent_); |
| 318 } | 319 } |
| 319 | 320 |
| 320 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); | 321 snap_scroll_controller_.UpdateSnapScrollMode(distance_x, distance_y); |
| 321 if (snap_scroll_controller_.IsSnappingScrolls()) { | 322 |
| 323 if (!PostponeRailApplication() && | |
|
jdduke (slow)
2015/04/01 17:40:49
We've worked hard to keep globals out of the gestu
| |
| 324 snap_scroll_controller_.IsSnappingScrolls()) { | |
| 322 if (snap_scroll_controller_.IsSnapHorizontal()) | 325 if (snap_scroll_controller_.IsSnapHorizontal()) |
| 323 distance_y = 0; | 326 distance_y = 0; |
| 324 else | 327 else |
| 325 distance_x = 0; | 328 distance_x = 0; |
| 326 } | 329 } |
| 327 | 330 |
| 328 if (distance_x || distance_y) { | 331 if (distance_x || distance_y) { |
| 329 GestureEventDetails scroll_details( | 332 GestureEventDetails scroll_details( |
| 330 ET_GESTURE_SCROLL_UPDATE, -distance_x, -distance_y); | 333 ET_GESTURE_SCROLL_UPDATE, -distance_x, -distance_y, |
| 334 snap_scroll_controller_.ScrollRailState()); | |
| 335 | |
| 331 const gfx::RectF bounding_box = GetBoundingBox(e2, scroll_details.type()); | 336 const gfx::RectF bounding_box = GetBoundingBox(e2, scroll_details.type()); |
| 332 const gfx::PointF center = bounding_box.CenterPoint(); | 337 const gfx::PointF center = bounding_box.CenterPoint(); |
| 333 const gfx::PointF raw_center = | 338 const gfx::PointF raw_center = |
| 334 center + gfx::Vector2dF(e2.GetRawOffsetX(), e2.GetRawOffsetY()); | 339 center + gfx::Vector2dF(e2.GetRawOffsetX(), e2.GetRawOffsetY()); |
| 335 Send(CreateGesture(scroll_details, | 340 Send(CreateGesture(scroll_details, |
| 336 e2.GetId(), | 341 e2.GetId(), |
| 337 e2.GetToolType(), | 342 e2.GetToolType(), |
| 338 e2.GetEventTime(), | 343 e2.GetEventTime(), |
| 339 center.x(), | 344 center.x(), |
| 340 center.y(), | 345 center.y(), |
| 341 raw_center.x(), | 346 raw_center.x(), |
| 342 raw_center.y(), | 347 raw_center.y(), |
| 343 e2.GetPointerCount(), | 348 e2.GetPointerCount(), |
| 344 bounding_box, | 349 bounding_box, |
| 345 e2.GetFlags())); | 350 e2.GetFlags())); |
| 346 } | 351 } |
| 347 | 352 |
| 348 return true; | 353 return true; |
| 349 } | 354 } |
| 350 | 355 |
| 351 bool OnFling(const MotionEvent& e1, | 356 bool OnFling(const MotionEvent& e1, |
| 352 const MotionEvent& e2, | 357 const MotionEvent& e2, |
| 353 float velocity_x, | 358 float velocity_x, |
| 354 float velocity_y) override { | 359 float velocity_y) override { |
| 355 if (snap_scroll_controller_.IsSnappingScrolls()) { | |
| 356 if (snap_scroll_controller_.IsSnapHorizontal()) { | |
| 357 velocity_y = 0; | |
| 358 } else { | |
| 359 velocity_x = 0; | |
| 360 } | |
| 361 } | |
| 362 | |
| 363 if (!velocity_x && !velocity_y) | 360 if (!velocity_x && !velocity_y) |
| 364 return true; | 361 return true; |
| 365 | 362 |
| 366 if (!scroll_event_sent_) { | 363 if (!scroll_event_sent_) { |
| 367 // The native side needs a ET_GESTURE_SCROLL_BEGIN before | 364 // The native side needs a ET_GESTURE_SCROLL_BEGIN before |
| 368 // ET_SCROLL_FLING_START to send the fling to the correct target. | 365 // ET_SCROLL_FLING_START to send the fling to the correct target. |
| 369 // The distance traveled in one second is a reasonable scroll start hint. | 366 // The distance traveled in one second is a reasonable scroll start hint. |
| 370 GestureEventDetails scroll_details( | 367 GestureEventDetails scroll_details( |
| 371 ET_GESTURE_SCROLL_BEGIN, velocity_x, velocity_y); | 368 ET_GESTURE_SCROLL_BEGIN, velocity_x, velocity_y); |
| 372 Send(CreateGesture(scroll_details, e2)); | 369 Send(CreateGesture(scroll_details, e2)); |
| 373 } | 370 } |
| 374 | 371 |
| 372 if (!PostponeRailApplication() && | |
| 373 snap_scroll_controller_.IsSnappingScrolls()) { | |
| 374 if (snap_scroll_controller_.IsSnapHorizontal()) | |
| 375 velocity_y = 0; | |
| 376 else | |
| 377 velocity_x = 0; | |
| 378 } | |
| 379 | |
| 375 GestureEventDetails fling_details( | 380 GestureEventDetails fling_details( |
| 376 ET_SCROLL_FLING_START, velocity_x, velocity_y); | 381 ET_SCROLL_FLING_START, velocity_x, velocity_y, |
| 382 snap_scroll_controller_.ScrollRailState()); | |
| 377 Send(CreateGesture(fling_details, e2)); | 383 Send(CreateGesture(fling_details, e2)); |
| 378 return true; | 384 return true; |
| 379 } | 385 } |
| 380 | 386 |
| 381 bool OnSwipe(const MotionEvent& e1, | 387 bool OnSwipe(const MotionEvent& e1, |
| 382 const MotionEvent& e2, | 388 const MotionEvent& e2, |
| 383 float velocity_x, | 389 float velocity_x, |
| 384 float velocity_y) override { | 390 float velocity_y) override { |
| 385 GestureEventDetails swipe_details(ET_GESTURE_SWIPE, velocity_x, velocity_y); | 391 GestureEventDetails swipe_details(ET_GESTURE_SWIPE, velocity_x, velocity_y); |
| 386 Send(CreateGesture(swipe_details, e2)); | 392 Send(CreateGesture(swipe_details, e2)); |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 823 // null'ing of the listener until the sequence has ended. | 829 // null'ing of the listener until the sequence has ended. |
| 824 if (current_down_event_) | 830 if (current_down_event_) |
| 825 return; | 831 return; |
| 826 | 832 |
| 827 const bool double_tap_enabled = | 833 const bool double_tap_enabled = |
| 828 double_tap_support_for_page_ && double_tap_support_for_platform_; | 834 double_tap_support_for_page_ && double_tap_support_for_platform_; |
| 829 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); | 835 gesture_listener_->SetDoubleTapEnabled(double_tap_enabled); |
| 830 } | 836 } |
| 831 | 837 |
| 832 } // namespace ui | 838 } // namespace ui |
| OLD | NEW |