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/gestures/blink/web_gesture_curve_impl.h" | 5 #include "ui/events/gestures/blink/web_gesture_curve_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "third_party/WebKit/public/platform/WebFloatSize.h" | 9 #include "third_party/WebKit/public/platform/WebFloatSize.h" |
| 10 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" | 10 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 INT_MIN, | 35 INT_MIN, |
| 36 INT_MAX, | 36 INT_MAX, |
| 37 base::TimeTicks()); | 37 base::TimeTicks()); |
| 38 return scroller.Pass(); | 38 return scroller.Pass(); |
| 39 #else | 39 #else |
| 40 return make_scoped_ptr( | 40 return make_scoped_ptr( |
| 41 new FlingCurve(initial_velocity, base::TimeTicks())); | 41 new FlingCurve(initial_velocity, base::TimeTicks())); |
| 42 #endif | 42 #endif |
| 43 } | 43 } |
| 44 | 44 |
| 45 scoped_ptr<GestureCurve> CreateSmoothScrollingCurve(float start_x, | |
| 46 float start_y, | |
| 47 float dx, | |
| 48 float dy, | |
| 49 base::TimeDelta duration) { | |
| 50 DCHECK(duration > base::TimeDelta()); | |
| 51 #if defined(OS_ANDROID) | |
| 52 auto scroller = make_scoped_ptr(new Scroller(Scroller::Config())); | |
| 53 base::TimeTicks start_time = base::TimeTicks(); | |
| 54 | |
| 55 scroller->StartScroll(start_x, start_y, dx, dy, start_time, duration); | |
| 56 return scroller.Pass(); | |
| 57 #else | |
| 58 float vx = dx / duration.InSecondsF(); | |
|
jdduke (slow)
2015/07/23 15:32:50
I'd almost rather we NOTREACHED() here and return
| |
| 59 float vy = dy / duration.InSecondsF(); | |
| 60 return make_scoped_ptr( | |
| 61 new FlingCurve(gfx::Vector2dF(vx, vy), base::TimeTicks())); | |
| 62 #endif | |
| 63 } | |
| 64 | |
| 45 } // namespace | 65 } // namespace |
| 46 | 66 |
| 47 // static | 67 // static |
| 48 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromDefaultPlatformCurve( | 68 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromDefaultPlatformCurve( |
| 49 const gfx::Vector2dF& initial_velocity, | 69 const gfx::Vector2dF& initial_velocity, |
| 50 const gfx::Vector2dF& initial_offset, | 70 const gfx::Vector2dF& initial_offset, |
| 51 bool on_main_thread) { | 71 bool on_main_thread) { |
| 52 return scoped_ptr<WebGestureCurve>(new WebGestureCurveImpl( | 72 return scoped_ptr<WebGestureCurve>(new WebGestureCurveImpl( |
| 53 CreateDefaultPlatformCurve(initial_velocity), initial_offset, | 73 CreateDefaultPlatformCurve(initial_velocity), initial_offset, |
| 54 on_main_thread ? ThreadType::MAIN : ThreadType::IMPL)); | 74 on_main_thread ? ThreadType::MAIN : ThreadType::IMPL)); |
| 55 } | 75 } |
| 56 | 76 |
| 57 // static | 77 // static |
| 78 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromSmoothScrollingCurve( | |
| 79 float start_x, | |
| 80 float start_y, | |
| 81 float dx, | |
| 82 float dy, | |
| 83 base::TimeDelta duration, | |
| 84 bool on_main_thread) { | |
| 85 const gfx::Vector2dF initial_offset(start_x, start_y); | |
| 86 return scoped_ptr<WebGestureCurve>(new WebGestureCurveImpl( | |
| 87 CreateSmoothScrollingCurve(start_x, start_y, dx, dy, duration), | |
| 88 initial_offset, on_main_thread ? ThreadType::MAIN : ThreadType::IMPL)); | |
| 89 } | |
| 90 | |
| 91 // static | |
| 58 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromUICurveForTesting( | 92 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromUICurveForTesting( |
| 59 scoped_ptr<GestureCurve> curve, | 93 scoped_ptr<GestureCurve> curve, |
| 60 const gfx::Vector2dF& initial_offset) { | 94 const gfx::Vector2dF& initial_offset) { |
| 61 return scoped_ptr<WebGestureCurve>( | 95 return scoped_ptr<WebGestureCurve>( |
| 62 new WebGestureCurveImpl(curve.Pass(), initial_offset, ThreadType::TEST)); | 96 new WebGestureCurveImpl(curve.Pass(), initial_offset, ThreadType::TEST)); |
| 63 } | 97 } |
| 64 | 98 |
| 65 WebGestureCurveImpl::WebGestureCurveImpl(scoped_ptr<GestureCurve> curve, | 99 WebGestureCurveImpl::WebGestureCurveImpl(scoped_ptr<GestureCurve> curve, |
| 66 const gfx::Vector2dF& initial_offset, | 100 const gfx::Vector2dF& initial_offset, |
| 67 ThreadType animating_thread_type) | 101 ThreadType animating_thread_type) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 return still_active; | 166 return still_active; |
| 133 | 167 |
| 134 // scrollBy() could delete this curve if the animation is over, so don't touch | 168 // scrollBy() could delete this curve if the animation is over, so don't touch |
| 135 // any member variables after making that call. | 169 // any member variables after making that call. |
| 136 bool did_scroll = target->scrollBy(blink::WebFloatSize(delta), | 170 bool did_scroll = target->scrollBy(blink::WebFloatSize(delta), |
| 137 blink::WebFloatSize(velocity)); | 171 blink::WebFloatSize(velocity)); |
| 138 return did_scroll && still_active; | 172 return did_scroll && still_active; |
| 139 } | 173 } |
| 140 | 174 |
| 141 } // namespace ui | 175 } // namespace ui |
| OLD | NEW |