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 "content/child/fling_animator_impl_android.h" | 5 #include "content/child/fling_animator_impl_android.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "third_party/WebKit/public/platform/WebFloatSize.h" | 9 #include "third_party/WebKit/public/platform/WebFloatSize.h" |
| 9 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" | 10 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" |
| 10 #include "ui/gfx/android/view_configuration.h" | 11 #include "ui/gfx/android/view_configuration.h" |
| 11 #include "ui/gfx/frame_time.h" | 12 #include "ui/gfx/frame_time.h" |
| 12 #include "ui/gfx/vector2d.h" | 13 #include "ui/gfx/vector2d.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 19 const char* kCurveName = "FlingAnimatorImpl"; | |
|
jochen (gone - plz use gerrit)
2014/03/31 09:59:10
why do you declare a variable for this but none of
jdduke (slow)
2014/03/31 15:41:43
I added the trace to mimic what was done in touch_
| |
| 20 | |
| 18 gfx::Scroller::Config GetScrollerConfig() { | 21 gfx::Scroller::Config GetScrollerConfig() { |
| 19 gfx::Scroller::Config config; | 22 gfx::Scroller::Config config; |
| 20 config.flywheel_enabled = false; | 23 config.flywheel_enabled = false; |
| 21 config.fling_friction = gfx::ViewConfiguration::GetScrollFriction(); | 24 config.fling_friction = gfx::ViewConfiguration::GetScrollFriction(); |
| 22 return config; | 25 return config; |
| 23 } | 26 } |
| 24 | 27 |
| 25 } // namespace | 28 } // namespace |
| 26 | 29 |
| 27 FlingAnimatorImpl::FlingAnimatorImpl() | 30 FlingAnimatorImpl::FlingAnimatorImpl() |
| 28 : is_active_(false), | 31 : is_active_(false), |
| 29 scroller_(GetScrollerConfig()) {} | 32 scroller_(GetScrollerConfig()) { |
| 33 TRACE_EVENT_ASYNC_BEGIN1( | |
| 34 "input", "GestureAnimation", this, "curve", kCurveName); | |
| 35 } | |
| 30 | 36 |
| 31 FlingAnimatorImpl::~FlingAnimatorImpl() {} | 37 FlingAnimatorImpl::~FlingAnimatorImpl() { |
| 38 TRACE_EVENT_ASYNC_END0("input", "GestureAnimation", this); | |
| 39 } | |
| 32 | 40 |
| 33 void FlingAnimatorImpl::StartFling(const gfx::PointF& velocity) { | 41 void FlingAnimatorImpl::StartFling(const gfx::PointF& velocity) { |
| 34 // No bounds on the fling. See http://webkit.org/b/96403 | 42 // No bounds on the fling. See http://webkit.org/b/96403 |
| 35 // Instead, use the largest possible bounds for minX/maxX/minY/maxY. The | 43 // Instead, use the largest possible bounds for minX/maxX/minY/maxY. The |
| 36 // compositor will ignore any attempt to scroll beyond the end of the page. | 44 // compositor will ignore any attempt to scroll beyond the end of the page. |
| 37 | 45 |
| 38 DCHECK(velocity.x() || velocity.y()); | 46 DCHECK(velocity.x() || velocity.y()); |
| 39 if (is_active_) | 47 if (is_active_) |
| 40 CancelFling(); | 48 CancelFling(); |
| 41 | 49 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 65 blink::WebGestureCurveTarget* target) { | 73 blink::WebGestureCurveTarget* target) { |
| 66 // Historically, Android's Scroller used |currentAnimationTimeMillis()|, | 74 // Historically, Android's Scroller used |currentAnimationTimeMillis()|, |
| 67 // which is equivalent to gfx::FrameTime::Now(). In practice, this produces | 75 // which is equivalent to gfx::FrameTime::Now(). In practice, this produces |
| 68 // smoother results than using |time|, so continue using FrameTime::Now(). | 76 // smoother results than using |time|, so continue using FrameTime::Now(). |
| 69 // TODO(jdduke): Use |time| upon resolution of crbug.com/345459. | 77 // TODO(jdduke): Use |time| upon resolution of crbug.com/345459. |
| 70 if (!scroller_.ComputeScrollOffset(gfx::FrameTime::Now())) { | 78 if (!scroller_.ComputeScrollOffset(gfx::FrameTime::Now())) { |
| 71 is_active_ = false; | 79 is_active_ = false; |
| 72 return false; | 80 return false; |
| 73 } | 81 } |
| 74 | 82 |
| 75 target->notifyCurrentFlingVelocity(blink::WebFloatSize( | |
| 76 scroller_.GetCurrVelocityX(), scroller_.GetCurrVelocityY())); | |
| 77 | |
| 78 gfx::PointF current_position(scroller_.GetCurrX(), scroller_.GetCurrY()); | 83 gfx::PointF current_position(scroller_.GetCurrX(), scroller_.GetCurrY()); |
| 79 gfx::Vector2dF scroll_amount(current_position - last_position_); | 84 gfx::Vector2dF scroll_amount(current_position - last_position_); |
| 80 last_position_ = current_position; | 85 last_position_ = current_position; |
| 81 | 86 |
| 82 // scrollBy() could delete this curve if the animation is over, so don't touch | 87 // scrollBy() could delete this curve if the animation is over, so don't touch |
| 83 // any member variables after making that call. | 88 // any member variables after making that call. |
| 84 target->scrollBy(blink::WebFloatSize(scroll_amount)); | 89 return target->scrollBy(blink::WebFloatSize(scroll_amount), |
| 85 return true; | 90 blink::WebFloatSize(scroller_.GetCurrVelocityX(), |
| 91 scroller_.GetCurrVelocityY())); | |
| 86 } | 92 } |
| 87 | 93 |
| 88 FlingAnimatorImpl* FlingAnimatorImpl::CreateAndroidGestureCurve( | 94 FlingAnimatorImpl* FlingAnimatorImpl::CreateAndroidGestureCurve( |
| 89 const blink::WebFloatPoint& velocity, | 95 const blink::WebFloatPoint& velocity, |
| 90 const blink::WebSize&) { | 96 const blink::WebSize&) { |
| 91 FlingAnimatorImpl* gesture_curve = new FlingAnimatorImpl(); | 97 FlingAnimatorImpl* gesture_curve = new FlingAnimatorImpl(); |
| 92 gesture_curve->StartFling(velocity); | 98 gesture_curve->StartFling(velocity); |
| 93 return gesture_curve; | 99 return gesture_curve; |
| 94 } | 100 } |
| 95 | 101 |
| 96 } // namespace content | 102 } // namespace content |
| OLD | NEW |