summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/common/android/common_jni_registrar.cc2
-rw-r--r--webkit/glue/DEPS2
-rw-r--r--webkit/glue/fling_animator_impl_android.cc69
-rw-r--r--webkit/glue/fling_animator_impl_android.h8
-rw-r--r--webkit/glue/webkit_glue.gypi20
5 files changed, 52 insertions, 49 deletions
diff --git a/content/common/android/common_jni_registrar.cc b/content/common/android/common_jni_registrar.cc
index f854fd96..bf774e6 100644
--- a/content/common/android/common_jni_registrar.cc
+++ b/content/common/android/common_jni_registrar.cc
@@ -11,12 +11,14 @@
#include "content/common/android/hash_set.h"
#include "content/common/android/surface_texture_listener.h"
#include "content/common/android/trace_event_binding.h"
+#include "webkit/glue/fling_animator_impl_android.h"
namespace {
base::android::RegistrationMethod kContentRegisteredMethods[] = {
{ "CommandLine", RegisterCommandLine },
{ "DeviceTelephonyInfo",
content::DeviceTelephonyInfo::RegisterDeviceTelephonyInfo },
+ { "FlingAnimator", webkit_glue::FlingAnimatorImpl::RegisterJni },
{ "HashSet", content::RegisterHashSet },
{ "SurfaceTextureListener",
content::SurfaceTextureListener::RegisterSurfaceTextureListener },
diff --git a/webkit/glue/DEPS b/webkit/glue/DEPS
index ceb17b6..9520156 100644
--- a/webkit/glue/DEPS
+++ b/webkit/glue/DEPS
@@ -5,6 +5,8 @@ include_rules = [
"+ui",
"+webkit/tools/test_shell", # Needed for test shell tests.
+ "+jni", # Needed for Android's java-generated bindings
+
# This is not actually a directory, but npruntime_util.cc includes a file
# from WebKit starting with this path in JSCore mode.
"+bindings/c",
diff --git a/webkit/glue/fling_animator_impl_android.cc b/webkit/glue/fling_animator_impl_android.cc
index 94f5f76..f15caf7 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;
}
diff --git a/webkit/glue/fling_animator_impl_android.h b/webkit/glue/fling_animator_impl_android.h
index 8d3758b..0068c73 100644
--- a/webkit/glue/fling_animator_impl_android.h
+++ b/webkit/glue/fling_animator_impl_android.h
@@ -29,6 +29,9 @@ class FlingAnimatorImpl : public WebKit::WebGestureCurve {
virtual bool apply(double time,
WebKit::WebGestureCurveTarget* target);
+
+ static bool RegisterJni(JNIEnv*);
+
private:
void StartFling(const gfx::PointF& velocity);
// Returns true if the animation is not yet finished.
@@ -40,11 +43,6 @@ class FlingAnimatorImpl : public WebKit::WebGestureCurve {
// Java OverScroller instance and methods.
base::android::ScopedJavaGlobalRef<jobject> java_scroller_;
- jmethodID fling_method_id_;
- jmethodID abort_method_id_;
- jmethodID compute_method_id_;
- jmethodID getX_method_id_;
- jmethodID getY_method_id_;
gfx::Point last_position_;
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 58cb4dd..593d296 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -472,6 +472,12 @@
'<(DEPTH)/webkit/support/setup_third_party.gyp:third_party_headers',
],
}],
+ ['OS=="android"', {
+ 'dependencies': [
+ 'overscroller_jni_headers',
+ ],
+ }],
+
],
},
],
@@ -497,5 +503,19 @@
},
],
}],
+ ['OS=="android"', {
+ 'targets': [
+ {
+ 'target_name': 'overscroller_jni_headers',
+ 'type': 'none',
+ 'variables': {
+ 'jni_gen_package': 'webkit',
+ 'input_java_class': 'android/widget/OverScroller.class',
+ 'input_jar_file': '<(android_sdk)/android.jar',
+ },
+ 'includes': [ '../../build/jar_file_jni_generator.gypi' ],
+ },
+ ],
+ }],
],
}