| 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 <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "third_party/WebKit/public/platform/WebFloatSize.h" | 15 #include "third_party/WebKit/public/platform/WebFloatSize.h" |
| 15 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" | 16 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" |
| 16 #include "ui/events/gestures/fling_curve.h" | 17 #include "ui/events/gestures/fling_curve.h" |
| 17 #include "ui/gfx/geometry/safe_integer_conversions.h" | 18 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 18 #include "ui/gfx/geometry/vector2d.h" | 19 #include "ui/gfx/geometry/vector2d.h" |
| 19 | 20 |
| 20 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
| 21 #include "ui/events/android/scroller.h" | 22 #include "ui/events/android/scroller.h" |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 using blink::WebGestureCurve; | 25 using blink::WebGestureCurve; |
| 25 | 26 |
| 26 namespace ui { | 27 namespace ui { |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 scoped_ptr<GestureCurve> CreateDefaultPlatformCurve( | 30 std::unique_ptr<GestureCurve> CreateDefaultPlatformCurve( |
| 30 const gfx::Vector2dF& initial_velocity) { | 31 const gfx::Vector2dF& initial_velocity) { |
| 31 DCHECK(!initial_velocity.IsZero()); | 32 DCHECK(!initial_velocity.IsZero()); |
| 32 #if defined(OS_ANDROID) | 33 #if defined(OS_ANDROID) |
| 33 auto scroller = make_scoped_ptr(new Scroller(Scroller::Config())); | 34 auto scroller = base::WrapUnique(new Scroller(Scroller::Config())); |
| 34 scroller->Fling(0, | 35 scroller->Fling(0, |
| 35 0, | 36 0, |
| 36 initial_velocity.x(), | 37 initial_velocity.x(), |
| 37 initial_velocity.y(), | 38 initial_velocity.y(), |
| 38 INT_MIN, | 39 INT_MIN, |
| 39 INT_MAX, | 40 INT_MAX, |
| 40 INT_MIN, | 41 INT_MIN, |
| 41 INT_MAX, | 42 INT_MAX, |
| 42 base::TimeTicks()); | 43 base::TimeTicks()); |
| 43 return std::move(scroller); | 44 return std::move(scroller); |
| 44 #else | 45 #else |
| 45 return make_scoped_ptr( | 46 return base::WrapUnique(new FlingCurve(initial_velocity, base::TimeTicks())); |
| 46 new FlingCurve(initial_velocity, base::TimeTicks())); | |
| 47 #endif | 47 #endif |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 // static | 52 // static |
| 53 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromDefaultPlatformCurve( | 53 std::unique_ptr<WebGestureCurve> |
| 54 WebGestureCurveImpl::CreateFromDefaultPlatformCurve( |
| 54 const gfx::Vector2dF& initial_velocity, | 55 const gfx::Vector2dF& initial_velocity, |
| 55 const gfx::Vector2dF& initial_offset, | 56 const gfx::Vector2dF& initial_offset, |
| 56 bool on_main_thread) { | 57 bool on_main_thread) { |
| 57 return scoped_ptr<WebGestureCurve>(new WebGestureCurveImpl( | 58 return std::unique_ptr<WebGestureCurve>(new WebGestureCurveImpl( |
| 58 CreateDefaultPlatformCurve(initial_velocity), initial_offset, | 59 CreateDefaultPlatformCurve(initial_velocity), initial_offset, |
| 59 on_main_thread ? ThreadType::MAIN : ThreadType::IMPL)); | 60 on_main_thread ? ThreadType::MAIN : ThreadType::IMPL)); |
| 60 } | 61 } |
| 61 | 62 |
| 62 // static | 63 // static |
| 63 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromUICurveForTesting( | 64 std::unique_ptr<WebGestureCurve> |
| 64 scoped_ptr<GestureCurve> curve, | 65 WebGestureCurveImpl::CreateFromUICurveForTesting( |
| 66 std::unique_ptr<GestureCurve> curve, |
| 65 const gfx::Vector2dF& initial_offset) { | 67 const gfx::Vector2dF& initial_offset) { |
| 66 return scoped_ptr<WebGestureCurve>(new WebGestureCurveImpl( | 68 return std::unique_ptr<WebGestureCurve>(new WebGestureCurveImpl( |
| 67 std::move(curve), initial_offset, ThreadType::TEST)); | 69 std::move(curve), initial_offset, ThreadType::TEST)); |
| 68 } | 70 } |
| 69 | 71 |
| 70 WebGestureCurveImpl::WebGestureCurveImpl(scoped_ptr<GestureCurve> curve, | 72 WebGestureCurveImpl::WebGestureCurveImpl(std::unique_ptr<GestureCurve> curve, |
| 71 const gfx::Vector2dF& initial_offset, | 73 const gfx::Vector2dF& initial_offset, |
| 72 ThreadType animating_thread_type) | 74 ThreadType animating_thread_type) |
| 73 : curve_(std::move(curve)), | 75 : curve_(std::move(curve)), |
| 74 last_offset_(initial_offset), | 76 last_offset_(initial_offset), |
| 75 animating_thread_type_(animating_thread_type), | 77 animating_thread_type_(animating_thread_type), |
| 76 ticks_since_first_animate_(0), | 78 ticks_since_first_animate_(0), |
| 77 first_animate_time_(0), | 79 first_animate_time_(0), |
| 78 last_animate_time_(0) {} | 80 last_animate_time_(0) {} |
| 79 | 81 |
| 80 WebGestureCurveImpl::~WebGestureCurveImpl() { | 82 WebGestureCurveImpl::~WebGestureCurveImpl() { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return still_active; | 138 return still_active; |
| 137 | 139 |
| 138 // scrollBy() could delete this curve if the animation is over, so don't touch | 140 // scrollBy() could delete this curve if the animation is over, so don't touch |
| 139 // any member variables after making that call. | 141 // any member variables after making that call. |
| 140 bool did_scroll = target->scrollBy(blink::WebFloatSize(delta), | 142 bool did_scroll = target->scrollBy(blink::WebFloatSize(delta), |
| 141 blink::WebFloatSize(velocity)); | 143 blink::WebFloatSize(velocity)); |
| 142 return did_scroll && still_active; | 144 return did_scroll && still_active; |
| 143 } | 145 } |
| 144 | 146 |
| 145 } // namespace ui | 147 } // namespace ui |
| OLD | NEW |