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

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwScrollOffsetManager.java

Issue 15029006: Make it possible for the scroll offset delegate to intercept fling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reactivate the patch! Created 7 years, 5 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
Index: android_webview/java/src/org/chromium/android_webview/AwScrollOffsetManager.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwScrollOffsetManager.java b/android_webview/java/src/org/chromium/android_webview/AwScrollOffsetManager.java
index 4564b42ff04c4f76e2bf45c42611cd21bae64bb0..ead226c1adf9e134e7ff8496c40c143d1d3de669 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwScrollOffsetManager.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwScrollOffsetManager.java
@@ -4,6 +4,8 @@
package org.chromium.android_webview;
+import android.widget.OverScroller;
+
import org.chromium.base.CalledByNative;
/**
@@ -24,8 +26,11 @@ public class AwScrollOffsetManager {
// operation, the native side shouldn't synchronously alter the scroll offset from within
// this call.
void scrollNativeTo(int x, int y);
+
int getContainerViewScrollX();
int getContainerViewScrollY();
+
+ void invalidate();
}
private final Delegate mDelegate;
@@ -42,14 +47,24 @@ public class AwScrollOffsetManager {
private int mContainerViewWidth;
private int mContainerViewHeight;
+ // Whether we're in the middle of processing a touch event.
private boolean mProcessingTouchEvent;
+ // Whether (and to what value) to update the native side scroll offset after we've finished
+ // provessing a touch event.
private boolean mApplyDeferredNativeScroll;
private int mDeferredNativeScrollX;
private int mDeferredNativeScrollY;
- public AwScrollOffsetManager(Delegate delegate) {
+ // The velocity of the last recorded fling,
+ private int mLastFlingVx;
+ private int mLastFlingVy;
+
+ private OverScroller mScroller;
+
+ public AwScrollOffsetManager(Delegate delegate, OverScroller overScroller) {
mDelegate = delegate;
+ mScroller = overScroller;
}
//----- Scroll range and extent calculation methods -------------------------------------------
@@ -133,7 +148,9 @@ public class AwScrollOffsetManager {
}
// Called by the native side to over-scroll the container view.
- public void overscrollBy(int deltaX, int deltaY) {
+ public void overScrollBy(int deltaX, int deltaY) {
+ if (deltaX == 0 && deltaY == 0) return;
+
final int scrollX = mDelegate.getContainerViewScrollX();
final int scrollY = mDelegate.getContainerViewScrollY();
final int scrollRangeX = computeMaximumHorizontalScrollOffset();
@@ -201,4 +218,59 @@ public class AwScrollOffsetManager {
mDelegate.scrollNativeTo(x, y);
}
+
+ /**
+ * Called at the beginning of every fling gesture.
+ */
+ public void onFlingStartGestureStart(int vx, int vy) {
+ mLastFlingVx = vx;
+ mLastFlingVy = vy;
+ }
+
+ /**
+ * Called when a fling gesture is not handled by the renderer.
+ * We explicitly ask the renderer not to handle fling gestures targeted at the root
+ * scroll layer.
+ */
+ public void onUnhandledFlingStartEvent() {
+ final int scrollX = mDelegate.getContainerViewScrollX();
+ final int scrollY = mDelegate.getContainerViewScrollY();
+ final int rangeX = computeMaximumHorizontalScrollOffset();
+ final int rangeY = computeMaximumVerticalScrollOffset();
+
+ mScroller.fling(scrollX, scrollY, -mLastFlingVx, -mLastFlingVy, 0, rangeX, 0, rangeY);
+ mDelegate.invalidate();
+ }
+
+ /**
+ * Called immediately before the draw to update the scroll offset.
+ */
+ public void computeScrollAndAbsorbGlow(OverScrollGlow overScrollGlow) {
+ if (!mScroller.computeScrollOffset()) {
+ return;
+ }
+
+ final int oldX = mDelegate.getContainerViewScrollX();
+ final int oldY = mDelegate.getContainerViewScrollY();
+ int x = mScroller.getCurrX();
+ int y = mScroller.getCurrY();
+
+ int rangeX = computeMaximumHorizontalScrollOffset();
+ int rangeY = computeMaximumVerticalScrollOffset();
+
+ if (overScrollGlow != null) {
+ overScrollGlow.absorbGlow(x, y, oldX, oldY, rangeX, rangeY,
+ mScroller.getCurrVelocity());
+ }
+
+ overScrollBy(x - oldX, y - oldY);
+
+ mDelegate.invalidate();
+ }
+
+ public void onTouchDown() {
+ // TODO(mkosiba): Support speeding up a fling by flinging again.
+ // http://crbug.com/265841
+ mScroller.forceFinished(true);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698