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 | 10 |
11 using namespace base::android; | 11 using namespace base::android; |
12 | 12 |
13 namespace webkit_glue { | 13 namespace webkit_glue { |
14 | 14 |
15 FlingAnimatorImpl::FlingAnimatorImpl() | 15 FlingAnimatorImpl::FlingAnimatorImpl() |
16 : is_active_(false) { | 16 : is_active_(false) { |
17 // hold the global reference of the Java objects. | 17 // hold the global reference of the Java objects. |
18 JNIEnv* env = AttachCurrentThread(); | 18 JNIEnv* env = AttachCurrentThread(); |
19 DCHECK(env); | 19 DCHECK(env); |
20 ScopedJavaLocalRef<jclass> cls(GetClass(env, "android/widget/OverScroller")); | 20 ScopedJavaLocalRef<jclass> cls(GetClass(env, "android/widget/OverScroller")); |
21 jmethodID constructor = GetMethodID(env, cls, "<init>", | 21 jmethodID constructor = GetMethodID(env, cls, "<init>", |
22 "(Landroid/content/Context;)V"); | 22 "(Landroid/content/Context;)V"); |
23 ScopedJavaLocalRef<jobject> tmp(env, env->NewObject(cls.obj(), constructor, | 23 ScopedJavaLocalRef<jobject> tmp(env, env->NewObject(cls.obj(), constructor, |
24 GetApplicationContext())); | 24 GetApplicationContext())); |
25 DCHECK(tmp.obj()); | 25 DCHECK(tmp.obj()); |
26 java_scroller_.Reset(tmp); | 26 java_scroller_.Reset(tmp); |
27 | 27 |
28 fling_method_id_ = GetMethodID(env, cls, "fling", "(IIIIIIIIII)V"); | 28 fling_method_id_ = GetMethodID(env, cls, "fling", "(IIIIIIII)V"); |
29 abort_method_id_ = GetMethodID(env, cls, "abortAnimation", "()V"); | 29 abort_method_id_ = GetMethodID(env, cls, "abortAnimation", "()V"); |
30 compute_method_id_ = GetMethodID(env, cls, "computeScrollOffset", "()Z"); | 30 compute_method_id_ = GetMethodID(env, cls, "computeScrollOffset", "()Z"); |
31 getX_method_id_ = GetMethodID(env, cls, "getCurrX", "()I"); | 31 getX_method_id_ = GetMethodID(env, cls, "getCurrX", "()I"); |
32 getY_method_id_ = GetMethodID(env, cls, "getCurrY", "()I"); | 32 getY_method_id_ = GetMethodID(env, cls, "getCurrY", "()I"); |
33 } | 33 } |
34 | 34 |
35 FlingAnimatorImpl::~FlingAnimatorImpl() | 35 FlingAnimatorImpl::~FlingAnimatorImpl() |
36 { | 36 { |
37 } | 37 } |
38 | 38 |
39 void FlingAnimatorImpl::startFling(const WebKit::WebFloatPoint& velocity, | 39 void FlingAnimatorImpl::startFling(const WebKit::WebFloatPoint& velocity, |
40 const WebKit::WebRect& range) | 40 const WebKit::WebRect& /* range */) |
41 { | 41 { |
| 42 // Ignore "range" as it's always empty -- see http://webkit.org/b/96403 |
| 43 // Instead, use the largest possible bounds for minX/maxX/minY/maxY. The |
| 44 // compositor will ignore any attempt to scroll beyond the end of the page. |
| 45 |
42 DCHECK(velocity.x || velocity.y); | 46 DCHECK(velocity.x || velocity.y); |
43 if (is_active_) | 47 if (is_active_) |
44 cancelFling(); | 48 cancelFling(); |
45 | 49 |
46 is_active_ = true; | 50 is_active_ = true; |
47 | 51 |
48 JNIEnv* env = AttachCurrentThread(); | 52 JNIEnv* env = AttachCurrentThread(); |
| 53 |
49 env->CallVoidMethod(java_scroller_.obj(), fling_method_id_, 0, 0, | 54 env->CallVoidMethod(java_scroller_.obj(), fling_method_id_, 0, 0, |
50 static_cast<int>(velocity.x), | 55 static_cast<int>(velocity.x), |
51 static_cast<int>(velocity.y), | 56 static_cast<int>(velocity.y), |
52 range.x, range.x + range.width, | 57 INT_MIN, INT_MAX, INT_MIN, INT_MAX); |
53 range.y, range.y + range.height, 0, 0); | |
54 CheckException(env); | 58 CheckException(env); |
55 } | 59 } |
56 | 60 |
57 void FlingAnimatorImpl::cancelFling() | 61 void FlingAnimatorImpl::cancelFling() |
58 { | 62 { |
59 if (!is_active_) | 63 if (!is_active_) |
60 return; | 64 return; |
61 | 65 |
62 is_active_ = false; | 66 is_active_ = false; |
63 JNIEnv* env = AttachCurrentThread(); | 67 JNIEnv* env = AttachCurrentThread(); |
(...skipping 14 matching lines...) Expand all Loading... |
78 { | 82 { |
79 JNIEnv* env = AttachCurrentThread(); | 83 JNIEnv* env = AttachCurrentThread(); |
80 WebKit::WebPoint position( | 84 WebKit::WebPoint position( |
81 env->CallIntMethod(java_scroller_.obj(), getX_method_id_), | 85 env->CallIntMethod(java_scroller_.obj(), getX_method_id_), |
82 env->CallIntMethod(java_scroller_.obj(), getY_method_id_)); | 86 env->CallIntMethod(java_scroller_.obj(), getY_method_id_)); |
83 CheckException(env); | 87 CheckException(env); |
84 return position; | 88 return position; |
85 } | 89 } |
86 | 90 |
87 } // namespace webkit_glue | 91 } // namespace webkit_glue |
OLD | NEW |