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/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" |
11 #include "ui/events/gestures/fling_curve.h" | 11 #include "ui/events/gestures/fling_curve.h" |
12 #include "ui/gfx/geometry/safe_integer_conversions.h" | 12 #include "ui/gfx/geometry/safe_integer_conversions.h" |
13 #include "ui/gfx/geometry/vector2d.h" | 13 #include "ui/gfx/geometry/vector2d.h" |
14 | 14 |
15 #if defined(OS_ANDROID) | 15 #if defined(OS_ANDROID) |
16 #include "ui/events/android/scroller.h" | 16 #include "ui/events/android/scroller.h" |
17 #endif | 17 #endif |
18 | 18 |
19 using blink::WebGestureCurve; | 19 using blink::WebGestureCurve; |
20 | 20 |
21 namespace content { | 21 namespace ui { |
22 namespace { | 22 namespace { |
23 | 23 |
24 scoped_ptr<ui::GestureCurve> CreateDefaultPlatformCurve( | 24 scoped_ptr<GestureCurve> CreateDefaultPlatformCurve( |
25 const gfx::Vector2dF& initial_velocity) { | 25 const gfx::Vector2dF& initial_velocity) { |
26 DCHECK(!initial_velocity.IsZero()); | 26 DCHECK(!initial_velocity.IsZero()); |
27 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
28 auto scroller = make_scoped_ptr(new ui::Scroller(ui::Scroller::Config())); | 28 auto scroller = make_scoped_ptr(new Scroller(Scroller::Config())); |
29 scroller->Fling(0, | 29 scroller->Fling(0, |
30 0, | 30 0, |
31 initial_velocity.x(), | 31 initial_velocity.x(), |
32 initial_velocity.y(), | 32 initial_velocity.y(), |
33 INT_MIN, | 33 INT_MIN, |
34 INT_MAX, | 34 INT_MAX, |
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 ui::FlingCurve(initial_velocity, base::TimeTicks())); | 41 new FlingCurve(initial_velocity, base::TimeTicks())); |
42 #endif | 42 #endif |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 // static | 47 // static |
48 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromDefaultPlatformCurve( | 48 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromDefaultPlatformCurve( |
49 const gfx::Vector2dF& initial_velocity, | 49 const gfx::Vector2dF& initial_velocity, |
50 const gfx::Vector2dF& initial_offset, | 50 const gfx::Vector2dF& initial_offset, |
51 bool on_main_thread) { | 51 bool on_main_thread) { |
52 return scoped_ptr<WebGestureCurve>(new WebGestureCurveImpl( | 52 return scoped_ptr<WebGestureCurve>(new WebGestureCurveImpl( |
53 CreateDefaultPlatformCurve(initial_velocity), initial_offset, | 53 CreateDefaultPlatformCurve(initial_velocity), initial_offset, |
54 on_main_thread ? ThreadType::MAIN : ThreadType::IMPL)); | 54 on_main_thread ? ThreadType::MAIN : ThreadType::IMPL)); |
55 } | 55 } |
56 | 56 |
57 // static | 57 // static |
58 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromUICurveForTesting( | 58 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromUICurveForTesting( |
59 scoped_ptr<ui::GestureCurve> curve, | 59 scoped_ptr<GestureCurve> curve, |
60 const gfx::Vector2dF& initial_offset) { | 60 const gfx::Vector2dF& initial_offset) { |
61 return scoped_ptr<WebGestureCurve>( | 61 return scoped_ptr<WebGestureCurve>( |
62 new WebGestureCurveImpl(curve.Pass(), initial_offset, ThreadType::TEST)); | 62 new WebGestureCurveImpl(curve.Pass(), initial_offset, ThreadType::TEST)); |
63 } | 63 } |
64 | 64 |
65 WebGestureCurveImpl::WebGestureCurveImpl(scoped_ptr<ui::GestureCurve> curve, | 65 WebGestureCurveImpl::WebGestureCurveImpl(scoped_ptr<GestureCurve> curve, |
66 const gfx::Vector2dF& initial_offset, | 66 const gfx::Vector2dF& initial_offset, |
67 ThreadType animating_thread_type) | 67 ThreadType animating_thread_type) |
68 : curve_(curve.Pass()), | 68 : curve_(curve.Pass()), |
69 last_offset_(initial_offset), | 69 last_offset_(initial_offset), |
70 animating_thread_type_(animating_thread_type), | 70 animating_thread_type_(animating_thread_type), |
71 ticks_since_first_animate_(0), | 71 ticks_since_first_animate_(0), |
72 first_animate_time_(0), | 72 first_animate_time_(0), |
73 last_animate_time_(0) { | 73 last_animate_time_(0) { |
74 } | 74 } |
75 | 75 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (delta.IsZero()) | 131 if (delta.IsZero()) |
132 return still_active; | 132 return still_active; |
133 | 133 |
134 // scrollBy() could delete this curve if the animation is over, so don't touch | 134 // scrollBy() could delete this curve if the animation is over, so don't touch |
135 // any member variables after making that call. | 135 // any member variables after making that call. |
136 bool did_scroll = target->scrollBy(blink::WebFloatSize(delta), | 136 bool did_scroll = target->scrollBy(blink::WebFloatSize(delta), |
137 blink::WebFloatSize(velocity)); | 137 blink::WebFloatSize(velocity)); |
138 return did_scroll && still_active; | 138 return did_scroll && still_active; |
139 } | 139 } |
140 | 140 |
141 } // namespace content | 141 } // namespace ui |
OLD | NEW |