summaryrefslogtreecommitdiffstats
path: root/webkit/glue
diff options
context:
space:
mode:
authorjaphet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-13 19:45:14 +0000
committerjaphet@chromium.org <japhet@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-13 19:45:14 +0000
commitbda19f8e50f4a9c24e03a238dcdc44cad74626c9 (patch)
tree3e2c48c740833444d6de0b3ceb6defc1267cbbd7 /webkit/glue
parent81293f4826efd58d3a2c14ed27a12eec3906f29d (diff)
downloadchromium_src-bda19f8e50f4a9c24e03a238dcdc44cad74626c9.zip
chromium_src-bda19f8e50f4a9c24e03a238dcdc44cad74626c9.tar.gz
chromium_src-bda19f8e50f4a9c24e03a238dcdc44cad74626c9.tar.bz2
Upstream android's fling animator.
BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/10823239 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151327 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r--webkit/glue/fling_animator_impl_android.cc86
-rw-r--r--webkit/glue/fling_animator_impl_android.h44
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/glue/webkitplatformsupport_impl.cc10
-rw-r--r--webkit/glue/webkitplatformsupport_impl.h5
5 files changed, 147 insertions, 0 deletions
diff --git a/webkit/glue/fling_animator_impl_android.cc b/webkit/glue/fling_animator_impl_android.cc
new file mode 100644
index 0000000..b125c41
--- /dev/null
+++ b/webkit/glue/fling_animator_impl_android.cc
@@ -0,0 +1,86 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/glue/fling_animator_impl_android.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/logging.h"
+
+using namespace base::android;
+
+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 = GetMethodID(env, cls, "<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_ = GetMethodID(env, cls, "fling", "(IIIIIIIIII)V");
+ abort_method_id_ = GetMethodID(env, cls, "abortAnimation", "()V");
+ compute_method_id_ = GetMethodID(env, cls, "computeScrollOffset", "()Z");
+ getX_method_id_ = GetMethodID(env, cls, "getCurrX", "()I");
+ getY_method_id_ = GetMethodID(env, cls, "getCurrY", "()I");
+}
+
+FlingAnimatorImpl::~FlingAnimatorImpl()
+{
+}
+
+void FlingAnimatorImpl::startFling(const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebRect& range)
+{
+ DCHECK(velocity.x || velocity.y);
+ if (is_active_)
+ cancelFling();
+
+ is_active_ = true;
+
+ JNIEnv* env = AttachCurrentThread();
+ env->CallVoidMethod(java_scroller_.obj(), fling_method_id_, 0, 0,
+ (int) -velocity.x, (int) -velocity.y,
+ range.x, range.x + range.width,
+ range.y, range.y + range.height, 0, 0);
+ CheckException(env);
+}
+
+void FlingAnimatorImpl::cancelFling()
+{
+ if (!is_active_)
+ return;
+
+ is_active_ = false;
+ JNIEnv* env = AttachCurrentThread();
+ env->CallVoidMethod(java_scroller_.obj(), abort_method_id_);
+ CheckException(env);
+}
+
+bool FlingAnimatorImpl::updatePosition()
+{
+ JNIEnv* env = AttachCurrentThread();
+ bool result = env->CallBooleanMethod(java_scroller_.obj(),
+ compute_method_id_);
+ CheckException(env);
+ return is_active_ = result;
+}
+
+WebKit::WebPoint FlingAnimatorImpl::getCurrentPosition()
+{
+ JNIEnv* env = AttachCurrentThread();
+ WebKit::WebPoint position(
+ env->CallIntMethod(java_scroller_.obj(), getX_method_id_),
+ env->CallIntMethod(java_scroller_.obj(), getY_method_id_));
+ CheckException(env);
+ return position;
+}
+
+} // namespace webkit_glue
diff --git a/webkit/glue/fling_animator_impl_android.h b/webkit/glue/fling_animator_impl_android.h
new file mode 100644
index 0000000..90da93e
--- /dev/null
+++ b/webkit/glue/fling_animator_impl_android.h
@@ -0,0 +1,44 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_GLUE_FLING_ANIMATOR_IMPL_ANDROID_H_
+#define WEBKIT_GLUE_FLING_ANIMATOR_IMPL_ANDROID_H_
+
+#include "base/android/scoped_java_ref.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebFlingAnimator.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebFloatPoint.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebPoint.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
+
+namespace webkit_glue {
+
+class FlingAnimatorImpl : public WebKit::WebFlingAnimator {
+ public:
+ FlingAnimatorImpl();
+ virtual ~FlingAnimatorImpl();
+
+ virtual void startFling(const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebRect& range);
+ // Returns true if the animation is not yet finished.
+ virtual bool updatePosition();
+ virtual WebKit::WebPoint getCurrentPosition();
+ virtual void cancelFling();
+
+ private:
+ bool is_active_;
+
+ // 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_;
+
+ DISALLOW_COPY_AND_ASSIGN(FlingAnimatorImpl);
+};
+
+} // namespace webkit_glue
+
+#endif // WEBKIT_GLUE_FLING_ANIMATOR_IMPL_ANDROID_H_
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index dc388d9..c0e1204 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -353,6 +353,8 @@
'cpp_variant.h',
'dom_operations.cc',
'dom_operations.h',
+ 'fling_animator_impl_android.cc',
+ 'fling_animator_impl_android.h',
'ftp_directory_listing_response_delegate.cc',
'ftp_directory_listing_response_delegate.h',
'gl_bindings_skia_cmd_buffer.cc',
diff --git a/webkit/glue/webkitplatformsupport_impl.cc b/webkit/glue/webkitplatformsupport_impl.cc
index fe80547..07b9e96 100644
--- a/webkit/glue/webkitplatformsupport_impl.cc
+++ b/webkit/glue/webkitplatformsupport_impl.cc
@@ -48,6 +48,10 @@
#include "webkit/plugins/npapi/plugin_instance.h"
#include "webkit/plugins/webplugininfo.h"
+#if defined(OS_ANDROID)
+#include "webkit/glue/fling_animator_impl_android.h"
+#endif
+
#if defined(OS_LINUX)
#include "v8/include/v8.h"
#endif
@@ -789,4 +793,10 @@ void WebKitPlatformSupportImpl::didStopWorkerRunLoop(
worker_task_runner->OnWorkerRunLoopStopped(runLoop);
}
+#if defined(OS_ANDROID)
+WebKit::WebFlingAnimator* WebKitPlatformSupportImpl::createFlingAnimator() {
+ return new FlingAnimatorImpl();
+}
+#endif
+
} // namespace webkit_glue
diff --git a/webkit/glue/webkitplatformsupport_impl.h b/webkit/glue/webkitplatformsupport_impl.h
index 30208a0..59dc97e 100644
--- a/webkit/glue/webkitplatformsupport_impl.h
+++ b/webkit/glue/webkitplatformsupport_impl.h
@@ -32,6 +32,7 @@ struct WebPluginInfo;
}
namespace WebKit {
+class WebFlingAnimator;
class WebSocketStreamHandle;
}
@@ -152,6 +153,10 @@ class WEBKIT_GLUE_EXPORT WebKitPlatformSupportImpl :
virtual void didStopWorkerRunLoop(
const WebKit::WebWorkerRunLoop& runLoop) OVERRIDE;
+#if defined(OS_ANDROID)
+ virtual WebKit::WebFlingAnimator* createFlingAnimator();
+#endif
+
private:
void DoTimeout() {
if (shared_timer_func_ && !shared_timer_suspended_)