summaryrefslogtreecommitdiffstats
path: root/webkit/child
diff options
context:
space:
mode:
authorscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-13 20:02:21 +0000
committerscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-13 20:02:21 +0000
commitb52a42243daf55ec35be02f382e6873aeb9a3992 (patch)
tree18f5937da732ff2b91c9d52b25d632c4ebea13b9 /webkit/child
parent9559f2c9c5a2760fd3ba291eae6f3fd5c7e921a4 (diff)
downloadchromium_src-b52a42243daf55ec35be02f382e6873aeb9a3992.zip
chromium_src-b52a42243daf55ec35be02f382e6873aeb9a3992.tar.gz
chromium_src-b52a42243daf55ec35be02f382e6873aeb9a3992.tar.bz2
move webkit/glue/fling_* to webkit/child
A little bit of rejiggering for Android JNI registration. R=jam@chromium.org, jamesr@chromium.org BUG=237249 Review URL: https://codereview.chromium.org/16424008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206148 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/child')
-rw-r--r--webkit/child/DEPS3
-rw-r--r--webkit/child/fling_animator_impl_android.cc148
-rw-r--r--webkit/child/fling_animator_impl_android.h58
-rw-r--r--webkit/child/fling_curve_configuration.cc55
-rw-r--r--webkit/child/fling_curve_configuration.h58
-rw-r--r--webkit/child/webkitplatformsupport_child_impl.cc34
-rw-r--r--webkit/child/webkitplatformsupport_child_impl.h13
7 files changed, 367 insertions, 2 deletions
diff --git a/webkit/child/DEPS b/webkit/child/DEPS
new file mode 100644
index 0000000..b15a790
--- /dev/null
+++ b/webkit/child/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+jni", # Needed for Android's java-generated bindings.
+]
diff --git a/webkit/child/fling_animator_impl_android.cc b/webkit/child/fling_animator_impl_android.cc
new file mode 100644
index 0000000..d874302
--- /dev/null
+++ b/webkit/child/fling_animator_impl_android.cc
@@ -0,0 +1,148 @@
+// 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/child/fling_animator_impl_android.h"
+
+#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/public/platform/WebFloatSize.h"
+#include "third_party/WebKit/public/platform/WebGestureCurveTarget.h"
+#include "ui/gfx/screen.h"
+#include "ui/gfx/vector2d.h"
+
+namespace webkit_glue {
+
+namespace {
+static const float kEpsilon = 1e-4;
+}
+
+FlingAnimatorImpl::FlingAnimatorImpl()
+ : is_active_(false) {
+ // hold the global reference of the Java objects.
+ 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
+ // Instead, use the largest possible bounds for minX/maxX/minY/maxY. The
+ // compositor will ignore any attempt to scroll beyond the end of the page.
+
+ DCHECK(velocity.x() || velocity.y());
+ if (is_active_)
+ CancelFling();
+
+ is_active_ = true;
+ last_time_ = 0;
+ last_velocity_ = velocity;
+
+ JNIEnv* env = base::android::AttachCurrentThread();
+
+ 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()
+{
+ if (!is_active_)
+ return;
+
+ is_active_ = false;
+ JNIEnv* env = base::android::AttachCurrentThread();
+ JNI_OverScroller::Java_OverScroller_abortAnimation(env, java_scroller_.obj());
+}
+
+bool FlingAnimatorImpl::UpdatePosition()
+{
+ 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 = base::android::AttachCurrentThread();
+ gfx::Point position(
+ JNI_OverScroller::Java_OverScroller_getCurrX(env, java_scroller_.obj()),
+ JNI_OverScroller::Java_OverScroller_getCurrY(env, java_scroller_.obj()));
+ return position;
+}
+
+float FlingAnimatorImpl::GetCurrentVelocity()
+{
+ JNIEnv* env = base::android::AttachCurrentThread();
+ // TODO(jdduke): Add Java-side hooks for getCurrVelocityX/Y, and return
+ // vector velocity.
+ return JNI_OverScroller::Java_OverScroller_getCurrVelocity(
+ env, java_scroller_.obj());
+}
+
+bool FlingAnimatorImpl::apply(double time,
+ WebKit::WebGestureCurveTarget* target) {
+ if (!UpdatePosition())
+ return false;
+
+ gfx::Point current_position = GetCurrentPosition();
+ gfx::Vector2d diff(current_position - last_position_);
+ last_position_ = current_position;
+ float dpi_scale = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay()
+ .device_scale_factor();
+ WebKit::WebFloatSize scroll_amount(diff.x() / dpi_scale,
+ diff.y() / dpi_scale);
+
+ float delta_time = time - last_time_;
+ last_time_ = time;
+
+ // Currently, the OverScroller only provides the velocity magnitude; use the
+ // angle of the scroll delta to yield approximate x and y velocity components.
+ // TODO(jdduke): Remove this when we can properly poll OverScroller velocity.
+ gfx::PointF current_velocity = last_velocity_;
+ if (delta_time > kEpsilon) {
+ float diff_length = diff.Length();
+ if (diff_length > kEpsilon) {
+ float velocity = GetCurrentVelocity();
+ float scroll_to_velocity = velocity / diff_length;
+ current_velocity = gfx::PointF(diff.x() * scroll_to_velocity,
+ diff.y() * scroll_to_velocity);
+ }
+ }
+ last_velocity_ = current_velocity;
+ WebKit::WebFloatSize fling_velocity(current_velocity.x() / dpi_scale,
+ current_velocity.y() / dpi_scale);
+ target->notifyCurrentFlingVelocity(fling_velocity);
+
+ // scrollBy() could delete this curve if the animation is over, so don't touch
+ // any member variables after making that call.
+ target->scrollBy(scroll_amount);
+ return true;
+}
+
+FlingAnimatorImpl* FlingAnimatorImpl::CreateAndroidGestureCurve(
+ const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebSize&) {
+ FlingAnimatorImpl* gesture_curve = new FlingAnimatorImpl();
+ gesture_curve->StartFling(velocity);
+ return gesture_curve;
+}
+
+} // namespace webkit_glue
diff --git a/webkit/child/fling_animator_impl_android.h b/webkit/child/fling_animator_impl_android.h
new file mode 100644
index 0000000..1148caf
--- /dev/null
+++ b/webkit/child/fling_animator_impl_android.h
@@ -0,0 +1,58 @@
+// 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_CHILD_FLING_ANIMATOR_IMPL_ANDROID_H_
+#define WEBKIT_CHILD_FLING_ANIMATOR_IMPL_ANDROID_H_
+
+#include "base/android/scoped_java_ref.h"
+#include "third_party/WebKit/public/platform/WebFloatPoint.h"
+#include "third_party/WebKit/public/platform/WebGestureCurve.h"
+#include "third_party/WebKit/public/platform/WebSize.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/point_f.h"
+#include "webkit/child/webkit_child_export.h"
+
+namespace WebKit {
+class WebGestureCurveTarget;
+}
+
+namespace webkit_glue {
+
+class WEBKIT_CHILD_EXPORT FlingAnimatorImpl : public WebKit::WebGestureCurve {
+ public:
+ FlingAnimatorImpl();
+ virtual ~FlingAnimatorImpl();
+
+ static FlingAnimatorImpl* CreateAndroidGestureCurve(
+ const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebSize&);
+
+ 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.
+ bool UpdatePosition();
+ gfx::Point GetCurrentPosition();
+ float GetCurrentVelocity();
+ virtual void CancelFling();
+
+ bool is_active_;
+
+ // Java OverScroller instance and methods.
+ base::android::ScopedJavaGlobalRef<jobject> java_scroller_;
+
+ gfx::Point last_position_;
+ gfx::PointF last_velocity_;
+ double last_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(FlingAnimatorImpl);
+};
+
+} // namespace webkit_glue
+
+#endif // WEBKIT_CHILD_FLING_ANIMATOR_IMPL_ANDROID_H_
diff --git a/webkit/child/fling_curve_configuration.cc b/webkit/child/fling_curve_configuration.cc
new file mode 100644
index 0000000..6095ca9
--- /dev/null
+++ b/webkit/child/fling_curve_configuration.cc
@@ -0,0 +1,55 @@
+// Copyright (c) 2013 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/child/fling_curve_configuration.h"
+
+#include "base/logging.h"
+#include "third_party/WebKit/public/platform/WebGestureCurve.h"
+#include "webkit/glue/touch_fling_gesture_curve.h"
+
+namespace webkit_glue {
+
+FlingCurveConfiguration::FlingCurveConfiguration() { }
+
+FlingCurveConfiguration::~FlingCurveConfiguration() { }
+
+void FlingCurveConfiguration::SetCurveParameters(
+ const std::vector<float>& new_touchpad,
+ const std::vector<float>& new_touchscreen) {
+ DCHECK(new_touchpad.size() >= 3);
+ DCHECK(new_touchscreen.size() >= 3);
+ base::AutoLock scoped_lock(lock_);
+ touchpad_coefs_ = new_touchpad;
+ touchscreen_coefs_ = new_touchscreen;
+}
+
+WebKit::WebGestureCurve* FlingCurveConfiguration::CreateCore(
+ const std::vector<float>& coefs,
+ const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebSize& cumulativeScroll) {
+ float p0, p1, p2;
+
+ {
+ base::AutoLock scoped_lock(lock_);
+ p0 = coefs[0];
+ p1 = coefs[1];
+ p2 = coefs[2];
+ }
+
+ return TouchFlingGestureCurve::Create(velocity, p0, p1, p2, cumulativeScroll);
+}
+
+WebKit::WebGestureCurve* FlingCurveConfiguration::CreateForTouchPad(
+ const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebSize& cumulativeScroll) {
+ return CreateCore(touchpad_coefs_, velocity, cumulativeScroll);
+}
+
+WebKit::WebGestureCurve* FlingCurveConfiguration::CreateForTouchScreen(
+ const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebSize& cumulativeScroll) {
+ return CreateCore(touchscreen_coefs_, velocity, cumulativeScroll);
+}
+
+} // namespace webkit_glue
diff --git a/webkit/child/fling_curve_configuration.h b/webkit/child/fling_curve_configuration.h
new file mode 100644
index 0000000..2ce5ba1
--- /dev/null
+++ b/webkit/child/fling_curve_configuration.h
@@ -0,0 +1,58 @@
+// Copyright (c) 2013 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_CHILD_FLING_CURVE_CONFIGURATION_H_
+#define WEBKIT_CHILD_FLING_CURVE_CONFIGURATION_H_
+
+#include <vector>
+
+#include "base/synchronization/lock.h"
+#include "third_party/WebKit/public/platform/WebFloatPoint.h"
+#include "third_party/WebKit/public/platform/WebSize.h"
+
+namespace WebKit {
+class WebGestureCurve;
+}
+
+namespace webkit_glue {
+
+// A class to manage dynamically adjustable parameters controlling the
+// shape of the fling deacceleration function.
+class FlingCurveConfiguration {
+ public:
+ FlingCurveConfiguration();
+ virtual ~FlingCurveConfiguration();
+
+ // Create a touchpad fling curve using the current parameters.
+ WebKit::WebGestureCurve* CreateForTouchPad(
+ const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebSize& cumulativeScroll);
+
+ // Create a touchscreen fling curve using the current parameters.
+ WebKit::WebGestureCurve* CreateForTouchScreen(
+ const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebSize& cumulativeScroll);
+
+ // Set the curve parameters.
+ void SetCurveParameters(
+ const std::vector<float>& new_touchpad,
+ const std::vector<float>& new_touchscreen);
+
+ private:
+ WebKit::WebGestureCurve* CreateCore(
+ const std::vector<float>& coefs,
+ const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebSize& cumulativeScroll);
+
+ // Protect access to touchpad_coefs_ and touchscreen_coefs_.
+ base::Lock lock_;
+ std::vector<float> touchpad_coefs_;
+ std::vector<float> touchscreen_coefs_;
+
+ DISALLOW_COPY_AND_ASSIGN(FlingCurveConfiguration);
+};
+
+} // namespace webkit_glue
+
+#endif // WEBKIT_CHILD_FLING_CURVE_CONFIGURATION_H_
diff --git a/webkit/child/webkitplatformsupport_child_impl.cc b/webkit/child/webkitplatformsupport_child_impl.cc
index b9a0662..456a5c9 100644
--- a/webkit/child/webkitplatformsupport_child_impl.cc
+++ b/webkit/child/webkitplatformsupport_child_impl.cc
@@ -4,12 +4,42 @@
#include "webkit/child/webkitplatformsupport_child_impl.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
+#include "webkit/child/fling_curve_configuration.h"
+
+#if defined(OS_ANDROID)
+#include "webkit/child/fling_animator_impl_android.h"
+#endif
+
namespace webkit_glue {
-WebKitPlatformSupportChildImpl::WebKitPlatformSupportChildImpl() {
+WebKitPlatformSupportChildImpl::WebKitPlatformSupportChildImpl()
+ : fling_curve_configuration_(new FlingCurveConfiguration) {}
+
+WebKitPlatformSupportChildImpl::~WebKitPlatformSupportChildImpl() {}
+
+void WebKitPlatformSupportChildImpl::SetFlingCurveParameters(
+ const std::vector<float>& new_touchpad,
+ const std::vector<float>& new_touchscreen) {
+ fling_curve_configuration_->SetCurveParameters(new_touchpad, new_touchscreen);
}
-WebKitPlatformSupportChildImpl::~WebKitPlatformSupportChildImpl() {
+WebKit::WebGestureCurve*
+WebKitPlatformSupportChildImpl::createFlingAnimationCurve(
+ int device_source,
+ const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebSize& cumulative_scroll) {
+#if defined(OS_ANDROID)
+ return FlingAnimatorImpl::CreateAndroidGestureCurve(velocity,
+ cumulative_scroll);
+#endif
+
+ if (device_source == WebKit::WebGestureEvent::Touchscreen)
+ return fling_curve_configuration_->CreateForTouchScreen(velocity,
+ cumulative_scroll);
+
+ return fling_curve_configuration_->CreateForTouchPad(velocity,
+ cumulative_scroll);
}
} // namespace webkit_glue
diff --git a/webkit/child/webkitplatformsupport_child_impl.h b/webkit/child/webkitplatformsupport_child_impl.h
index 4589906..8e23ead 100644
--- a/webkit/child/webkitplatformsupport_child_impl.h
+++ b/webkit/child/webkitplatformsupport_child_impl.h
@@ -10,11 +10,24 @@
namespace webkit_glue {
+class FlingCurveConfiguration;
+
class WEBKIT_CHILD_EXPORT WebKitPlatformSupportChildImpl :
public WebKitPlatformSupportImpl {
public:
WebKitPlatformSupportChildImpl();
virtual ~WebKitPlatformSupportChildImpl();
+
+ void SetFlingCurveParameters(
+ const std::vector<float>& new_touchpad,
+ const std::vector<float>& new_touchscreen);
+
+ virtual WebKit::WebGestureCurve* createFlingAnimationCurve(
+ int device_source,
+ const WebKit::WebFloatPoint& velocity,
+ const WebKit::WebSize& cumulative_scroll) OVERRIDE;
+
+ scoped_ptr<FlingCurveConfiguration> fling_curve_configuration_;
};
} // namespace webkit_glue