Bug 850889 - Fix animation conflict with overscroll and dynamic toolbar. r=kats
authorChris Lord <chrislord.net@gmail.com>
Mon, 18 Mar 2013 15:43:02 +0000
changeset 125240 e581d54aa570b9d69552a89369a08d58931727ab
parent 125239 a7ea5daa2dc952af25407605a8498dbe3838a4cc
child 125241 bee24b51a1a918b93b7e0aebe99721e945ab767f
push id24829
push userchrislord.net@gmail.com
push dateMon, 18 Mar 2013 15:43:20 +0000
treeherdermozilla-inbound@bee24b51a1a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs850889
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 850889 - Fix animation conflict with overscroll and dynamic toolbar. r=kats This fixes the conflicting animations when the dynamic toolbar is hiding/showing and overscroll is snapping back simultaneously. This is by not clamping the entire viewport on margin-setting, and by making sure that only calling setFixedLayerMargins changes the fixed layer margins.
mobile/android/base/gfx/GeckoLayerClient.java
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -316,18 +316,17 @@ public class GeckoLayerClient implements
         synchronized (this) {
             ImmutableViewportMetrics metrics;
             ImmutableViewportMetrics oldMetrics = getViewportMetrics();
 
             switch (type) {
             default:
             case UPDATE:
                 // Keep the old viewport size
-                metrics = messageMetrics.setViewportSize(oldMetrics.getWidth(), oldMetrics.getHeight())
-                                        .setFixedLayerMarginsFrom(oldMetrics);
+                metrics = messageMetrics.setViewportSize(oldMetrics.getWidth(), oldMetrics.getHeight());
                 if (!oldMetrics.fuzzyEquals(metrics)) {
                     abortPanZoomAnimation();
                 }
                 break;
             case PAGE_SIZE:
                 // adjust the page dimensions to account for differences in zoom
                 // between the rendered content (which is what Gecko tells us)
                 // and our zoom level (which may have diverged).
@@ -338,17 +337,17 @@ public class GeckoLayerClient implements
 
             final ImmutableViewportMetrics newMetrics = metrics;
             post(new Runnable() {
                 @Override
                 public void run() {
                     mGeckoViewport = newMetrics;
                 }
             });
-            setViewportMetrics(newMetrics, type == ViewportMessageType.UPDATE);
+            setViewportMetrics(newMetrics, type == ViewportMessageType.UPDATE, true);
             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) {
@@ -377,21 +376,52 @@ public class GeckoLayerClient implements
             oldMetrics.fixedLayerMarginBottom == bottom) {
             // Do nothing if the margins haven't changed.
             return;
         }
 
         ImmutableViewportMetrics newMetrics = oldMetrics.setFixedLayerMargins(left, top, right, bottom);
 
         if (mClampOnMarginChange) {
-            newMetrics = newMetrics.clampWithMargins();
+            // Only clamp on decreased margins
+            boolean changed = false;
+            float viewportRectLeft = oldMetrics.viewportRectLeft;
+            float viewportRectTop = oldMetrics.viewportRectTop;
+
+            // Clamp the x-axis if the page was over-scrolled into the margin
+            // area.
+            if (oldMetrics.fixedLayerMarginLeft > left &&
+                viewportRectLeft < oldMetrics.pageRectLeft - left) {
+                viewportRectLeft = oldMetrics.pageRectLeft - left;
+                changed = true;
+            } else if (oldMetrics.fixedLayerMarginRight > right &&
+                       oldMetrics.viewportRectRight > oldMetrics.pageRectRight + right) {
+                viewportRectLeft = oldMetrics.pageRectRight + right - oldMetrics.getWidth();
+                changed = true;
+            }
+
+            // Do the same for the y-axis.
+            if (oldMetrics.fixedLayerMarginTop > top &&
+                viewportRectTop < oldMetrics.pageRectTop - top) {
+                viewportRectTop = oldMetrics.pageRectTop - top;
+                changed = true;
+            } else if (oldMetrics.fixedLayerMarginBottom > bottom &&
+                       oldMetrics.viewportRectBottom > oldMetrics.pageRectBottom + bottom) {
+                viewportRectTop = oldMetrics.pageRectBottom + bottom - oldMetrics.getHeight();
+                changed = true;
+            }
+
+            // Set the new metrics, if they're different.
+            if (changed) {
+                newMetrics = newMetrics.setViewportOrigin(viewportRectLeft, viewportRectTop);
+            }
         }
 
         mForceRedraw = true;
-        setViewportMetrics(newMetrics, true);
+        setViewportMetrics(newMetrics, true, false);
     }
 
     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
@@ -717,21 +747,25 @@ public class GeckoLayerClient implements
         }
     }
 
     /** Implementation of PanZoomTarget
      * You must hold the monitor while calling this.
      */
     @Override
     public void setViewportMetrics(ImmutableViewportMetrics metrics) {
-        setViewportMetrics(metrics, true);
+        setViewportMetrics(metrics, true, true);
     }
 
-    private void setViewportMetrics(ImmutableViewportMetrics metrics, boolean notifyGecko) {
-        mViewportMetrics = metrics;
+    private void setViewportMetrics(ImmutableViewportMetrics metrics, boolean notifyGecko, boolean keepFixedMargins) {
+        if (keepFixedMargins) {
+            mViewportMetrics = metrics.setFixedLayerMarginsFrom(mViewportMetrics);
+        } else {
+            mViewportMetrics = metrics;
+        }
         mView.requestRender();
         if (notifyGecko && mGeckoIsReady) {
             geometryChanged();
         }
         setShadowVisibility();
     }
 
     private void setShadowVisibility() {