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 base::android::AttachCurrentThread; |
| 12 using base::android::CheckException; |
| 13 using base::android::GetApplicationContext; |
| 14 using base::android::GetClass; |
| 15 using base::android::MethodID; |
| 16 using base::android::ScopedJavaLocalRef; |
12 | 17 |
13 namespace webkit_glue { | 18 namespace webkit_glue { |
14 | 19 |
15 FlingAnimatorImpl::FlingAnimatorImpl() | 20 FlingAnimatorImpl::FlingAnimatorImpl() |
16 : is_active_(false) { | 21 : is_active_(false) { |
17 // hold the global reference of the Java objects. | 22 // hold the global reference of the Java objects. |
18 JNIEnv* env = AttachCurrentThread(); | 23 JNIEnv* env = AttachCurrentThread(); |
19 DCHECK(env); | 24 DCHECK(env); |
20 ScopedJavaLocalRef<jclass> cls(GetClass(env, "android/widget/OverScroller")); | 25 ScopedJavaLocalRef<jclass> cls(GetClass(env, "android/widget/OverScroller")); |
21 jmethodID constructor = GetMethodID(env, cls, "<init>", | 26 jmethodID constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( |
22 "(Landroid/content/Context;)V"); | 27 env, cls.obj(), "<init>", "(Landroid/content/Context;)V"); |
23 ScopedJavaLocalRef<jobject> tmp(env, env->NewObject(cls.obj(), constructor, | 28 ScopedJavaLocalRef<jobject> tmp(env, env->NewObject(cls.obj(), constructor, |
24 GetApplicationContext())); | 29 GetApplicationContext())); |
25 DCHECK(tmp.obj()); | 30 DCHECK(tmp.obj()); |
26 java_scroller_.Reset(tmp); | 31 java_scroller_.Reset(tmp); |
27 | 32 |
28 fling_method_id_ = GetMethodID(env, cls, "fling", "(IIIIIIII)V"); | 33 fling_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>( |
29 abort_method_id_ = GetMethodID(env, cls, "abortAnimation", "()V"); | 34 env, cls.obj(), "fling", "(IIIIIIII)V"); |
30 compute_method_id_ = GetMethodID(env, cls, "computeScrollOffset", "()Z"); | 35 abort_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>( |
31 getX_method_id_ = GetMethodID(env, cls, "getCurrX", "()I"); | 36 env, cls.obj(), "abortAnimation", "()V"); |
32 getY_method_id_ = GetMethodID(env, cls, "getCurrY", "()I"); | 37 compute_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 38 env, cls.obj(), "computeScrollOffset", "()Z"); |
| 39 getX_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 40 env, cls.obj(), "getCurrX", "()I"); |
| 41 getY_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>( |
| 42 env, cls.obj(), "getCurrY", "()I"); |
33 } | 43 } |
34 | 44 |
35 FlingAnimatorImpl::~FlingAnimatorImpl() | 45 FlingAnimatorImpl::~FlingAnimatorImpl() |
36 { | 46 { |
37 } | 47 } |
38 | 48 |
39 void FlingAnimatorImpl::startFling(const WebKit::WebFloatPoint& velocity, | 49 void FlingAnimatorImpl::startFling(const WebKit::WebFloatPoint& velocity, |
40 const WebKit::WebRect& /* range */) | 50 const WebKit::WebRect& /* range */) |
41 { | 51 { |
42 // Ignore "range" as it's always empty -- see http://webkit.org/b/96403 | 52 // Ignore "range" as it's always empty -- see http://webkit.org/b/96403 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 { | 92 { |
83 JNIEnv* env = AttachCurrentThread(); | 93 JNIEnv* env = AttachCurrentThread(); |
84 WebKit::WebPoint position( | 94 WebKit::WebPoint position( |
85 env->CallIntMethod(java_scroller_.obj(), getX_method_id_), | 95 env->CallIntMethod(java_scroller_.obj(), getX_method_id_), |
86 env->CallIntMethod(java_scroller_.obj(), getY_method_id_)); | 96 env->CallIntMethod(java_scroller_.obj(), getY_method_id_)); |
87 CheckException(env); | 97 CheckException(env); |
88 return position; | 98 return position; |
89 } | 99 } |
90 | 100 |
91 } // namespace webkit_glue | 101 } // namespace webkit_glue |
OLD | NEW |