Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Unified Diff: webkit/glue/fling_animator_impl_android.cc

Issue 12638003: Replace hand-written JNI in fling_animator with generated bindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/glue/fling_animator_impl_android.h ('k') | webkit/glue/webkit_glue.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/fling_animator_impl_android.cc
diff --git a/webkit/glue/fling_animator_impl_android.cc b/webkit/glue/fling_animator_impl_android.cc
index 94f5f764a166373a21cf653ec4ded80f9590d83d..f15caf73c9a28f3b24debf17c7c87d5a41f7c5ef 100644
--- a/webkit/glue/fling_animator_impl_android.cc
+++ b/webkit/glue/fling_animator_impl_android.cc
@@ -7,49 +7,32 @@
#include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#include "base/logging.h"
+#include "jni/OverScroller_jni.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebFloatSize.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebGestureCurveTarget.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/vector2d.h"
-using base::android::AttachCurrentThread;
-using base::android::CheckException;
-using base::android::GetApplicationContext;
-using base::android::GetClass;
-using base::android::MethodID;
-using base::android::ScopedJavaLocalRef;
-
namespace webkit_glue {
FlingAnimatorImpl::FlingAnimatorImpl()
: is_active_(false) {
// hold the global reference of the Java objects.
- JNIEnv* env = AttachCurrentThread();
- DCHECK(env);
- ScopedJavaLocalRef<jclass> cls(GetClass(env, "android/widget/OverScroller"));
- jmethodID constructor = MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, cls.obj(), "<init>", "(Landroid/content/Context;)V");
- ScopedJavaLocalRef<jobject> tmp(env, env->NewObject(cls.obj(), constructor,
- GetApplicationContext()));
- DCHECK(tmp.obj());
- java_scroller_.Reset(tmp);
-
- fling_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, cls.obj(), "fling", "(IIIIIIII)V");
- abort_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, cls.obj(), "abortAnimation", "()V");
- compute_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, cls.obj(), "computeScrollOffset", "()Z");
- getX_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, cls.obj(), "getCurrX", "()I");
- getY_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, cls.obj(), "getCurrY", "()I");
+ JNIEnv* env = base::android::AttachCurrentThread();
+ java_scroller_.Reset(JNI_OverScroller::Java_OverScroller_ConstructorAWOS_ACC(
+ env,
+ base::android::GetApplicationContext()));
}
FlingAnimatorImpl::~FlingAnimatorImpl()
{
}
+//static
+bool FlingAnimatorImpl::RegisterJni(JNIEnv* env) {
+ return JNI_OverScroller::RegisterNativesImpl(env);
+}
+
void FlingAnimatorImpl::StartFling(const gfx::PointF& velocity)
{
// No bounds on the fling. See http://webkit.org/b/96403
@@ -62,13 +45,13 @@ void FlingAnimatorImpl::StartFling(const gfx::PointF& velocity)
is_active_ = true;
- JNIEnv* env = AttachCurrentThread();
+ JNIEnv* env = base::android::AttachCurrentThread();
- env->CallVoidMethod(java_scroller_.obj(), fling_method_id_, 0, 0,
- static_cast<int>(velocity.x()),
- static_cast<int>(velocity.y()),
- INT_MIN, INT_MAX, INT_MIN, INT_MAX);
- CheckException(env);
+ JNI_OverScroller::Java_OverScroller_flingV_I_I_I_I_I_I_I_I(
+ env, java_scroller_.obj(), 0, 0,
+ static_cast<int>(velocity.x()),
+ static_cast<int>(velocity.y()),
+ INT_MIN, INT_MAX, INT_MIN, INT_MAX);
}
void FlingAnimatorImpl::CancelFling()
@@ -77,27 +60,25 @@ void FlingAnimatorImpl::CancelFling()
return;
is_active_ = false;
- JNIEnv* env = AttachCurrentThread();
- env->CallVoidMethod(java_scroller_.obj(), abort_method_id_);
- CheckException(env);
+ JNIEnv* env = base::android::AttachCurrentThread();
+ JNI_OverScroller::Java_OverScroller_abortAnimation(env, java_scroller_.obj());
}
bool FlingAnimatorImpl::UpdatePosition()
{
- JNIEnv* env = AttachCurrentThread();
- bool result = env->CallBooleanMethod(java_scroller_.obj(),
- compute_method_id_);
- CheckException(env);
+ JNIEnv* env = base::android::AttachCurrentThread();
+ bool result = JNI_OverScroller::Java_OverScroller_computeScrollOffset(
+ env,
+ java_scroller_.obj());
return is_active_ = result;
}
gfx::Point FlingAnimatorImpl::GetCurrentPosition()
{
- JNIEnv* env = AttachCurrentThread();
+ JNIEnv* env = base::android::AttachCurrentThread();
gfx::Point position(
- env->CallIntMethod(java_scroller_.obj(), getX_method_id_),
- env->CallIntMethod(java_scroller_.obj(), getY_method_id_));
- CheckException(env);
+ JNI_OverScroller::Java_OverScroller_getCurrX(env, java_scroller_.obj()),
+ JNI_OverScroller::Java_OverScroller_getCurrY(env, java_scroller_.obj()));
return position;
}
« no previous file with comments | « webkit/glue/fling_animator_impl_android.h ('k') | webkit/glue/webkit_glue.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698