Bug 892246 - Allow subdocument scrolling to reveal margins. r=kats, a=lsblakk
authorChris Lord <chrislord.net@gmail.com>
Mon, 15 Jul 2013 17:03:24 +0100
changeset 147929 fd8d6e5c0dec504085e0fc2c0a2b7c1480031dfe
parent 147928 b487258a64506f4112551f314edcda233bf27172
child 147930 c0dfc5460b9d267872041e261d5a08ded96575e7
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats, lsblakk
bugs892246
milestone24.0a2
Bug 892246 - Allow subdocument scrolling to reveal margins. r=kats, a=lsblakk This adds a notification callback to PanZoomTarget that the PanZoomController can call to notify GeckoLayerClient that a subdocument is being scrolled. This allows GeckoLayerClient to call LayerMarginsAnimator and alter the margins accordingly, stopping a page from trapping the toolbar on/off the screen with a screen-covering subframe.
mobile/android/base/gfx/GeckoLayerClient.java
mobile/android/base/gfx/JavaPanZoomController.java
mobile/android/base/gfx/PanZoomTarget.java
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -849,16 +849,31 @@ public class GeckoLayerClient implements
      */
     @Override
     public void scrollBy(float dx, float dy) {
         // Set mViewportMetrics manually so the margin changes take.
         mViewportMetrics = mMarginsAnimator.scrollBy(mViewportMetrics, dx, dy);
         viewportMetricsChanged(true);
     }
 
+    /** Implementation of PanZoomTarget
+     * Notification that a subdocument has been scrolled by a certain amount.
+     * This is used here to make sure that the margins are still accessible
+     * during subdocument scrolling.
+     *
+     * You must hold the monitor while calling this.
+     */
+    @Override
+    public void onSubdocumentScrollBy(float dx, float dy) {
+        ImmutableViewportMetrics newMarginsMetrics =
+            mMarginsAnimator.scrollBy(mViewportMetrics, dx, dy);
+        mViewportMetrics = mViewportMetrics.setMarginsFrom(newMarginsMetrics);
+        viewportMetricsChanged(true);
+    }
+
     /** Implementation of PanZoomTarget */
     @Override
     public void panZoomStopped() {
         if (mViewportChangeListener != null) {
             mViewportChangeListener.onPanZoomStopped();
         }
     }
 
--- a/mobile/android/base/gfx/JavaPanZoomController.java
+++ b/mobile/android/base/gfx/JavaPanZoomController.java
@@ -801,17 +801,21 @@ class JavaPanZoomController
 
     private void updatePosition() {
         mX.displace();
         mY.displace();
         PointF displacement = resetDisplacement();
         if (FloatUtils.fuzzyEquals(displacement.x, 0.0f) && FloatUtils.fuzzyEquals(displacement.y, 0.0f)) {
             return;
         }
-        if (! mSubscroller.scrollBy(displacement)) {
+        if (mSubscroller.scrollBy(displacement)) {
+            synchronized (mTarget.getLock()) {
+                mTarget.onSubdocumentScrollBy(displacement.x, displacement.y);
+            }
+        } else {
             synchronized (mTarget.getLock()) {
                 scrollBy(displacement.x, displacement.y);
             }
         }
     }
 
     private abstract class AnimationRunnable implements Runnable {
         private boolean mAnimationTerminated;
--- a/mobile/android/base/gfx/PanZoomTarget.java
+++ b/mobile/android/base/gfx/PanZoomTarget.java
@@ -12,16 +12,17 @@ import android.graphics.PointF;
 public interface PanZoomTarget {
     public ImmutableViewportMetrics getViewportMetrics();
     public ZoomConstraints getZoomConstraints();
     public boolean isFullScreen();
 
     public void setAnimationTarget(ImmutableViewportMetrics viewport);
     public void setViewportMetrics(ImmutableViewportMetrics viewport);
     public void scrollBy(float dx, float dy);
+    public void onSubdocumentScrollBy(float dx, float dy);
     public void panZoomStopped();
     /** This triggers an (asynchronous) viewport update/redraw. */
     public void forceRedraw(DisplayPortMetrics displayPort);
 
     public boolean post(Runnable action);
     public boolean postDelayed(Runnable action, long delayMillis);
     public Object getLock();
     public PointF convertViewPointToLayerPoint(PointF viewPoint);