Bug 856039 - Default to keeping the fixed layer margins in setViewportMetrics. r=Cwiiis
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 01 Apr 2013 10:17:38 -0400
changeset 127256 dccd236555132a061ac9ce36e51df232dfbf5ae1
parent 127255 be42980135f2f72e7e11a1252e2c9e4ac8fa5eb8
child 127257 db5c1742af263577852e2abc4cf049fe9cd1ab41
push id1651
push userjandemooij@gmail.com
push dateMon, 01 Apr 2013 19:51:43 +0000
reviewersCwiiis
bugs856039
milestone22.0a1
Bug 856039 - Default to keeping the fixed layer margins in setViewportMetrics. r=Cwiiis
mobile/android/base/gfx/GeckoLayerClient.java
mobile/android/base/gfx/ImmutableViewportMetrics.java
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -403,17 +403,17 @@ public class GeckoLayerClient implements
             if (type == ViewportMessageType.UPDATE
                     && FloatUtils.fuzzyEquals(newMetrics.viewportRectTop,
                                               newMetrics.pageRectTop)
                     && oldMetrics.fixedLayerMarginTop > 0) {
                 newMetrics = newMetrics.setViewportOrigin(newMetrics.viewportRectLeft,
                                  newMetrics.pageRectTop - oldMetrics.fixedLayerMarginTop);
             }
 
-            setViewportMetrics(newMetrics, type == ViewportMessageType.UPDATE, true);
+            setViewportMetrics(newMetrics, type == ViewportMessageType.UPDATE);
             mDisplayPort = DisplayPortCalculator.calculate(getViewportMetrics(), null);
         }
         return mDisplayPort;
     }
 
     public DisplayPortMetrics getDisplayPort(boolean pageSizeUpdate, boolean isBrowserContentDisplayed, int tabId, ImmutableViewportMetrics metrics) {
         Tabs tabs = Tabs.getInstance();
         if (tabs.isSelectedTab(tabs.getTab(tabId)) && isBrowserContentDisplayed) {
@@ -429,17 +429,17 @@ public class GeckoLayerClient implements
             return DisplayPortCalculator.calculate(metrics, null);
         }
     }
 
     /**
      * Sets margins on fixed-position layers, to be used when compositing.
      * Must be called on the UI thread!
      */
-    public void setFixedLayerMargins(float left, float top, float right, float bottom) {
+    public synchronized void setFixedLayerMargins(float left, float top, float right, float bottom) {
         ImmutableViewportMetrics oldMetrics = getViewportMetrics();
         ImmutableViewportMetrics newMetrics = oldMetrics.setFixedLayerMargins(left, top, right, bottom);
 
         if (mClampOnMarginChange) {
             // Only clamp on decreased margins
             boolean changed = false;
             float viewportRectLeft = oldMetrics.viewportRectLeft;
             float viewportRectTop = oldMetrics.viewportRectTop;
@@ -468,17 +468,19 @@ public class GeckoLayerClient implements
             }
 
             // Set the new metrics, if they're different.
             if (changed) {
                 newMetrics = newMetrics.setViewportOrigin(viewportRectLeft, viewportRectTop);
             }
         }
 
-        setViewportMetrics(newMetrics, false, false);
+        mViewportMetrics = newMetrics;
+        mView.requestRender();
+        setShadowVisibility();
     }
 
     public void setClampOnFixedLayerMarginsChange(boolean aClamp) {
         mClampOnMarginChange = aClamp;
     }
 
     // This is called on the Gecko thread to determine if we're still interested
     // in the update of this display-port to continue. We can return true here
@@ -800,31 +802,32 @@ public class GeckoLayerClient implements
         }
     }
 
     /** Implementation of PanZoomTarget
      * You must hold the monitor while calling this.
      */
     @Override
     public void setViewportMetrics(ImmutableViewportMetrics metrics) {
-        setViewportMetrics(metrics, true, true);
+        setViewportMetrics(metrics, true);
     }
 
-    private void setViewportMetrics(ImmutableViewportMetrics metrics, boolean notifyGecko, boolean keepFixedMargins) {
-        // This class owns the viewport size; don't let other pieces of code clobber our notion
-        // of the viewport size. The only place the viewport size should ever be updated is in
-        // the GeckoLayerClient.setViewportSize function, and there mViewportMetrics is updated
-        // directly.
+    /*
+     * You must hold the monitor while calling this.
+     */
+    private void setViewportMetrics(ImmutableViewportMetrics metrics, boolean notifyGecko) {
+        // This class owns the viewport size and the fixed layer margins; don't let other pieces
+        // of code clobber either of them. The only place the viewport size should ever be
+        // updated is in GeckoLayerClient.setViewportSize, and the only place the margins should
+        // ever be updated is in GeckoLayerClient.setFixedLayerMargins; both of these assign to
+        // mViewportMetrics directly.
         metrics = metrics.setViewportSize(mViewportMetrics.getWidth(), mViewportMetrics.getHeight());
+        metrics = metrics.setFixedLayerMarginsFrom(mViewportMetrics);
+        mViewportMetrics = metrics;
 
-        if (keepFixedMargins) {
-            mViewportMetrics = metrics.setFixedLayerMarginsFrom(mViewportMetrics);
-        } else {
-            mViewportMetrics = metrics;
-        }
         mView.requestRender();
         if (notifyGecko && mGeckoIsReady) {
             geometryChanged();
         }
         setShadowVisibility();
     }
 
     private void setShadowVisibility() {
--- a/mobile/android/base/gfx/ImmutableViewportMetrics.java
+++ b/mobile/android/base/gfx/ImmutableViewportMetrics.java
@@ -204,16 +204,23 @@ public class ImmutableViewportMetrics {
             pageRect.left, pageRect.top, pageRect.right, pageRect.bottom,
             cssPageRect.left, cssPageRect.top, cssPageRect.right, cssPageRect.bottom,
             viewportRectLeft, viewportRectTop, viewportRectRight, viewportRectBottom,
             fixedLayerMarginLeft, fixedLayerMarginTop, fixedLayerMarginRight, fixedLayerMarginBottom,
             zoomFactor);
     }
 
     public ImmutableViewportMetrics setFixedLayerMargins(float left, float top, float right, float bottom) {
+        if (FloatUtils.fuzzyEquals(left, fixedLayerMarginLeft)
+                && FloatUtils.fuzzyEquals(top, fixedLayerMarginTop)
+                && FloatUtils.fuzzyEquals(right, fixedLayerMarginRight)
+                && FloatUtils.fuzzyEquals(bottom, fixedLayerMarginBottom)) {
+            return this;
+        }
+
         return new ImmutableViewportMetrics(
             pageRectLeft, pageRectTop, pageRectRight, pageRectBottom,
             cssPageRectLeft, cssPageRectTop, cssPageRectRight, cssPageRectBottom,
             viewportRectLeft, viewportRectTop, viewportRectRight, viewportRectBottom,
             left, top, right, bottom, zoomFactor);
     }
 
     public ImmutableViewportMetrics setFixedLayerMarginsFrom(ImmutableViewportMetrics fromMetrics) {