OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/glue/fling_animator_impl_android.h" | 5 #include "webkit/glue/fling_animator_impl_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebGestureCurveTarg
et.h" | 10 #include "third_party/WebKit/Source/Platform/chromium/public/WebGestureCurveTarg
et.h" |
| 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebPoint.h" |
11 #include "ui/gfx/vector2d.h" | 12 #include "ui/gfx/vector2d.h" |
12 | 13 |
13 using base::android::AttachCurrentThread; | 14 using base::android::AttachCurrentThread; |
14 using base::android::CheckException; | 15 using base::android::CheckException; |
15 using base::android::GetApplicationContext; | 16 using base::android::GetApplicationContext; |
16 using base::android::GetClass; | 17 using base::android::GetClass; |
17 using base::android::MethodID; | 18 using base::android::MethodID; |
18 using base::android::ScopedJavaLocalRef; | 19 using base::android::ScopedJavaLocalRef; |
19 | 20 |
20 namespace webkit_glue { | 21 namespace webkit_glue { |
(...skipping 20 matching lines...) Expand all Loading... |
41 getX_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>( | 42 getX_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>( |
42 env, cls.obj(), "getCurrX", "()I"); | 43 env, cls.obj(), "getCurrX", "()I"); |
43 getY_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>( | 44 getY_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>( |
44 env, cls.obj(), "getCurrY", "()I"); | 45 env, cls.obj(), "getCurrY", "()I"); |
45 } | 46 } |
46 | 47 |
47 FlingAnimatorImpl::~FlingAnimatorImpl() | 48 FlingAnimatorImpl::~FlingAnimatorImpl() |
48 { | 49 { |
49 } | 50 } |
50 | 51 |
51 void FlingAnimatorImpl::startFling(const WebKit::WebFloatPoint& velocity, | 52 void FlingAnimatorImpl::StartFling(const gfx::PointF& velocity) |
52 const WebKit::WebRect& /* range */) | |
53 { | 53 { |
54 // Ignore "range" as it's always empty -- see http://webkit.org/b/96403 | 54 // No bounds on the fling. See http://webkit.org/b/96403 |
55 // Instead, use the largest possible bounds for minX/maxX/minY/maxY. The | 55 // Instead, use the largest possible bounds for minX/maxX/minY/maxY. The |
56 // compositor will ignore any attempt to scroll beyond the end of the page. | 56 // compositor will ignore any attempt to scroll beyond the end of the page. |
57 | 57 |
58 DCHECK(velocity.x || velocity.y); | 58 DCHECK(velocity.x() || velocity.y()); |
59 if (is_active_) | 59 if (is_active_) |
60 cancelFling(); | 60 CancelFling(); |
61 | 61 |
62 is_active_ = true; | 62 is_active_ = true; |
63 | 63 |
64 JNIEnv* env = AttachCurrentThread(); | 64 JNIEnv* env = AttachCurrentThread(); |
65 | 65 |
66 env->CallVoidMethod(java_scroller_.obj(), fling_method_id_, 0, 0, | 66 env->CallVoidMethod(java_scroller_.obj(), fling_method_id_, 0, 0, |
67 static_cast<int>(velocity.x), | 67 static_cast<int>(velocity.x()), |
68 static_cast<int>(velocity.y), | 68 static_cast<int>(velocity.y()), |
69 INT_MIN, INT_MAX, INT_MIN, INT_MAX); | 69 INT_MIN, INT_MAX, INT_MIN, INT_MAX); |
70 CheckException(env); | 70 CheckException(env); |
71 } | 71 } |
72 | 72 |
73 void FlingAnimatorImpl::cancelFling() | 73 void FlingAnimatorImpl::CancelFling() |
74 { | 74 { |
75 if (!is_active_) | 75 if (!is_active_) |
76 return; | 76 return; |
77 | 77 |
78 is_active_ = false; | 78 is_active_ = false; |
79 JNIEnv* env = AttachCurrentThread(); | 79 JNIEnv* env = AttachCurrentThread(); |
80 env->CallVoidMethod(java_scroller_.obj(), abort_method_id_); | 80 env->CallVoidMethod(java_scroller_.obj(), abort_method_id_); |
81 CheckException(env); | 81 CheckException(env); |
82 } | 82 } |
83 | 83 |
84 bool FlingAnimatorImpl::updatePosition() | 84 bool FlingAnimatorImpl::UpdatePosition() |
85 { | 85 { |
86 JNIEnv* env = AttachCurrentThread(); | 86 JNIEnv* env = AttachCurrentThread(); |
87 bool result = env->CallBooleanMethod(java_scroller_.obj(), | 87 bool result = env->CallBooleanMethod(java_scroller_.obj(), |
88 compute_method_id_); | 88 compute_method_id_); |
89 CheckException(env); | 89 CheckException(env); |
90 return is_active_ = result; | 90 return is_active_ = result; |
91 } | 91 } |
92 | 92 |
93 WebKit::WebPoint FlingAnimatorImpl::getCurrentPosition() | 93 gfx::Point FlingAnimatorImpl::GetCurrentPosition() |
94 { | 94 { |
95 JNIEnv* env = AttachCurrentThread(); | 95 JNIEnv* env = AttachCurrentThread(); |
96 WebKit::WebPoint position( | 96 gfx::Point position( |
97 env->CallIntMethod(java_scroller_.obj(), getX_method_id_), | 97 env->CallIntMethod(java_scroller_.obj(), getX_method_id_), |
98 env->CallIntMethod(java_scroller_.obj(), getY_method_id_)); | 98 env->CallIntMethod(java_scroller_.obj(), getY_method_id_)); |
99 CheckException(env); | 99 CheckException(env); |
100 return position; | 100 return position; |
101 } | 101 } |
102 | 102 |
103 bool FlingAnimatorImpl::apply(double time, | 103 bool FlingAnimatorImpl::apply(double time, |
104 WebKit::WebGestureCurveTarget* target) { | 104 WebKit::WebGestureCurveTarget* target) { |
105 if (!updatePosition()) | 105 if (!UpdatePosition()) |
106 return false; | 106 return false; |
107 | 107 |
108 gfx::Point current_position = getCurrentPosition(); | 108 gfx::Point current_position = GetCurrentPosition(); |
109 gfx::Vector2d diff(current_position - last_position_); | 109 gfx::Vector2d diff(current_position - last_position_); |
110 WebKit::WebPoint scroll_amount(diff.x(), diff.y()); | 110 WebKit::WebPoint scroll_amount(diff.x(), diff.y()); |
111 target->scrollBy(scroll_amount); | 111 target->scrollBy(scroll_amount); |
112 last_position_ = current_position; | 112 last_position_ = current_position; |
113 return true; | 113 return true; |
114 } | 114 } |
115 | 115 |
116 FlingAnimatorImpl* FlingAnimatorImpl::CreateAndroidGestureCurve( | 116 FlingAnimatorImpl* FlingAnimatorImpl::CreateAndroidGestureCurve( |
117 const WebKit::WebFloatPoint& velocity, | 117 const WebKit::WebFloatPoint& velocity, |
118 const WebKit::WebSize&) { | 118 const WebKit::WebSize&) { |
119 FlingAnimatorImpl* gesture_curve = new FlingAnimatorImpl(); | 119 FlingAnimatorImpl* gesture_curve = new FlingAnimatorImpl(); |
120 gesture_curve->startFling(velocity, WebKit::WebRect()); | 120 gesture_curve->StartFling(velocity); |
121 return gesture_curve; | 121 return gesture_curve; |
122 } | 122 } |
123 | 123 |
124 } // namespace webkit_glue | 124 } // namespace webkit_glue |
OLD | NEW |