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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f6fe73cd7ea8ebcfc6493fc06f4d665132af595a |
--- /dev/null |
+++ b/android_webview/java/src/org/chromium/android_webview/AwScrollOffsetManager.java |
@@ -0,0 +1,50 @@ |
+// Copyright 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. |
+ |
+package org.chromium.android_webview; |
+ |
+import org.chromium.base.CalledByNative; |
+ |
+class AwScrollOffsetManager { |
+ public interface Delegate { |
+ // Returns whether the update succeeded |
+ boolean scrollContainerViewTo(int xPix, int yPix); |
+ void scrollNativeTo(int xPix, int yPix); |
+ int getContainerViewScrollXPix(); |
+ int getContainerViewScrollYPix(); |
+ } |
+ |
+ final Delegate mDelegate; |
+ boolean mIgnoreContainerViewScrollChanges; |
+ int mNativeScrollXPix; |
+ int mNativeScrollYPix; |
+ |
+ public AwScrollOffsetManager(Delegate delegate) { |
+ mDelegate = delegate; |
+ } |
+ |
+ public void scrollContainerViewTo(int xPix, int yPix) { |
+ mNativeScrollXPix = xPix; |
+ mNativeScrollYPix = yPix; |
+ |
+ if (!mDelegate.scrollContainerViewTo(xPix, yPix)) { |
+ scrollNativeTo(mDelegate.getContainerViewScrollXPix(), |
+ mDelegate.getContainerViewScrollYPix()); |
+ } |
+ } |
+ |
+ public void onContainerViewScrollChanged(int xPix, int yPix) { |
+ scrollNativeTo(xPix, yPix); |
+ } |
+ |
+ private void scrollNativeTo(int xPix, int yPix) { |
+ if (xPix == mNativeScrollXPix && yPix == mNativeScrollYPix) |
+ return; |
+ |
+ mNativeScrollXPix = xPix; |
+ mNativeScrollYPix = yPix; |
+ |
+ mDelegate.scrollNativeTo(xPix, yPix); |
+ } |
+} |