OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/input/input_handler_proxy.h" | 5 #include "content/renderer/input/input_handler_proxy.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 bool ShouldSuppressScrollForFlingBoosting( | 65 bool ShouldSuppressScrollForFlingBoosting( |
66 const gfx::Vector2dF& current_fling_velocity, | 66 const gfx::Vector2dF& current_fling_velocity, |
67 const WebGestureEvent& scroll_update_event, | 67 const WebGestureEvent& scroll_update_event, |
68 double time_since_last_boost_event) { | 68 double time_since_last_boost_event) { |
69 DCHECK_EQ(WebInputEvent::GestureScrollUpdate, scroll_update_event.type); | 69 DCHECK_EQ(WebInputEvent::GestureScrollUpdate, scroll_update_event.type); |
70 | 70 |
71 gfx::Vector2dF dx(scroll_update_event.data.scrollUpdate.deltaX, | 71 gfx::Vector2dF dx(scroll_update_event.data.scrollUpdate.deltaX, |
72 scroll_update_event.data.scrollUpdate.deltaY); | 72 scroll_update_event.data.scrollUpdate.deltaY); |
73 if (gfx::DotProduct(current_fling_velocity, dx) < 0) | 73 if (gfx::DotProduct(current_fling_velocity, dx) <= 0) |
74 return false; | 74 return false; |
75 | 75 |
76 if (time_since_last_boost_event < 0.001) | 76 if (time_since_last_boost_event < 0.001) |
77 return true; | 77 return true; |
78 | 78 |
79 // TODO(jdduke): Use |scroll_update_event.data.scrollUpdate.velocity{X,Y}|. | 79 // TODO(jdduke): Use |scroll_update_event.data.scrollUpdate.velocity{X,Y}|. |
80 // The scroll must be of sufficient velocity to maintain the active fling. | 80 // The scroll must be of sufficient velocity to maintain the active fling. |
81 const gfx::Vector2dF scroll_velocity = | 81 const gfx::Vector2dF scroll_velocity = |
82 gfx::ScaleVector2d(dx, 1. / time_since_last_boost_event); | 82 gfx::ScaleVector2d(dx, 1. / time_since_last_boost_event); |
83 if (scroll_velocity.LengthSquared() < kMinBoostTouchScrollSpeedSquare) | 83 if (scroll_velocity.LengthSquared() < kMinBoostTouchScrollSpeedSquare) |
84 return false; | 84 return false; |
85 | 85 |
86 return true; | 86 return true; |
87 } | 87 } |
88 | 88 |
89 bool ShouldBoostFling(const gfx::Vector2dF& current_fling_velocity, | 89 bool ShouldBoostFling(const gfx::Vector2dF& current_fling_velocity, |
90 const WebGestureEvent& fling_start_event) { | 90 const WebGestureEvent& fling_start_event) { |
91 DCHECK_EQ(WebInputEvent::GestureFlingStart, fling_start_event.type); | 91 DCHECK_EQ(WebInputEvent::GestureFlingStart, fling_start_event.type); |
92 | 92 |
93 gfx::Vector2dF new_fling_velocity( | 93 gfx::Vector2dF new_fling_velocity( |
94 fling_start_event.data.flingStart.velocityX, | 94 fling_start_event.data.flingStart.velocityX, |
95 fling_start_event.data.flingStart.velocityY); | 95 fling_start_event.data.flingStart.velocityY); |
96 | 96 |
97 if (gfx::DotProduct(current_fling_velocity, new_fling_velocity) < 0) | 97 if (gfx::DotProduct(current_fling_velocity, new_fling_velocity) <= 0) |
98 return false; | 98 return false; |
99 | 99 |
100 if (current_fling_velocity.LengthSquared() < kMinBoostFlingSpeedSquare) | 100 if (current_fling_velocity.LengthSquared() < kMinBoostFlingSpeedSquare) |
101 return false; | 101 return false; |
102 | 102 |
103 if (new_fling_velocity.LengthSquared() < kMinBoostFlingSpeedSquare) | 103 if (new_fling_velocity.LengthSquared() < kMinBoostFlingSpeedSquare) |
104 return false; | 104 return false; |
105 | 105 |
106 return true; | 106 return true; |
107 } | 107 } |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 gesture_event.data.flingStart.velocityY); | 543 gesture_event.data.flingStart.velocityY); |
544 | 544 |
545 if (fling_boosted) | 545 if (fling_boosted) |
546 current_fling_velocity_ += new_fling_velocity; | 546 current_fling_velocity_ += new_fling_velocity; |
547 else | 547 else |
548 current_fling_velocity_ = new_fling_velocity; | 548 current_fling_velocity_ = new_fling_velocity; |
549 | 549 |
550 WebFloatPoint velocity(current_fling_velocity_.x(), | 550 WebFloatPoint velocity(current_fling_velocity_.x(), |
551 current_fling_velocity_.y()); | 551 current_fling_velocity_.y()); |
552 deferred_fling_cancel_time_seconds_ = 0; | 552 deferred_fling_cancel_time_seconds_ = 0; |
| 553 disallow_horizontal_fling_scroll_ = !velocity.x; |
| 554 disallow_vertical_fling_scroll_ = !velocity.y; |
553 last_fling_boost_event_ = WebGestureEvent(); | 555 last_fling_boost_event_ = WebGestureEvent(); |
554 fling_curve_.reset(client_->CreateFlingAnimationCurve( | 556 fling_curve_.reset(client_->CreateFlingAnimationCurve( |
555 gesture_event.sourceDevice, | 557 gesture_event.sourceDevice, |
556 velocity, | 558 velocity, |
557 blink::WebSize())); | 559 blink::WebSize())); |
558 fling_parameters_.startTime = gesture_event.timeStampSeconds; | 560 fling_parameters_.startTime = gesture_event.timeStampSeconds; |
559 fling_parameters_.delta = velocity; | 561 fling_parameters_.delta = velocity; |
560 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); | 562 fling_parameters_.point = WebPoint(gesture_event.x, gesture_event.y); |
561 fling_parameters_.globalPoint = | 563 fling_parameters_.globalPoint = |
562 WebPoint(gesture_event.globalX, gesture_event.globalY); | 564 WebPoint(gesture_event.globalX, gesture_event.globalY); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 // trigger a scroll, e.g., with a trivial time delta between fling updates. | 811 // trigger a scroll, e.g., with a trivial time delta between fling updates. |
810 // Return true in this case to prevent early fling termination. | 812 // Return true in this case to prevent early fling termination. |
811 if (std::abs(clipped_increment.width) < kScrollEpsilon && | 813 if (std::abs(clipped_increment.width) < kScrollEpsilon && |
812 std::abs(clipped_increment.height) < kScrollEpsilon) | 814 std::abs(clipped_increment.height) < kScrollEpsilon) |
813 return true; | 815 return true; |
814 | 816 |
815 return did_scroll; | 817 return did_scroll; |
816 } | 818 } |
817 | 819 |
818 } // namespace content | 820 } // namespace content |
OLD | NEW |