Bug 1180295 - Hook up the fixed-position layer margins to the DynamicToolbarAnimator. r=rbarker
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 18 Aug 2015 14:27:19 -0400
changeset 258266 99247cd12b2bfb2a18c107a37a776c1f9da52944
parent 258265 2f960e690b57279cc48b8f5cb3e4b83123a4512f
child 258267 b95c4c965912e94dc714a31bd7bfad3ff9a99da8
push id29249
push userryanvm@gmail.com
push dateWed, 19 Aug 2015 11:17:27 +0000
treeherdermozilla-central@706b23a03d1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker
bugs1180295
milestone43.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 1180295 - Hook up the fixed-position layer margins to the DynamicToolbarAnimator. r=rbarker
mobile/android/base/gfx/DynamicToolbarAnimator.java
mobile/android/base/gfx/GeckoLayerClient.java
--- a/mobile/android/base/gfx/DynamicToolbarAnimator.java
+++ b/mobile/android/base/gfx/DynamicToolbarAnimator.java
@@ -313,16 +313,31 @@ public class DynamicToolbarAnimator {
             return false;
         }
 
         fireListeners();
         mTarget.getView().requestRender();
         return true;
     }
 
+    private float bottomOfCssViewport(ImmutableViewportMetrics aMetrics) {
+        return aMetrics.getHeight() + mMaxTranslation - mLayerViewTranslation;
+    }
+
+    void populateFixedPositionMargins(ViewTransform aTransform, ImmutableViewportMetrics aMetrics) {
+        Log.v(LOGTAG, "Populating top fixed margin using " + mLayerViewTranslation + " - " + mToolbarTranslation);
+        aTransform.fixedLayerMarginTop = mLayerViewTranslation - mToolbarTranslation;
+        float bottomOfScreen = mTarget.getView().getHeight();
+        // We want to move a fixed item from "bottomOfCssViewport" to
+        // "bottomOfScreen". But also the bottom margin > 0 means that bottom
+        // fixed-pos items will move upwards.
+        Log.v(LOGTAG, "Populating bottom fixed margin using " + bottomOfCssViewport(aMetrics) + " - " + bottomOfScreen);
+        aTransform.fixedLayerMarginBottom = bottomOfCssViewport(aMetrics) - bottomOfScreen;
+    }
+
     class DynamicToolbarAnimationTask extends RenderTask {
         private final float mStartTranslation;
         private final float mEndTranslation;
         private boolean mContinueAnimation;
 
         public DynamicToolbarAnimationTask(boolean aRunAfter, float aTranslation) {
             super(aRunAfter);
             mContinueAnimation = true;
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -59,17 +59,16 @@ class GeckoLayerClient implements LayerV
      * accessed by the compositor thread, and so needs no synchronisation.
      */
     private ImmutableViewportMetrics mFrameMetrics;
 
     private final List<DrawListener> mDrawListeners;
 
     /* Used as temporaries by syncViewportInfo */
     private final ViewTransform mCurrentViewTransform;
-    private final RectF mCurrentViewTransformMargins;
 
     /* Used as the return value of progressiveUpdateCallback */
     private final ProgressiveUpdateData mProgressiveUpdateData;
     private DisplayPortMetrics mProgressiveUpdateDisplayPort;
     private boolean mLastProgressiveUpdateWasLowPrecision;
     private boolean mProgressiveUpdateWasInDanger;
 
     private boolean mForceRedraw;
@@ -113,17 +112,16 @@ class GeckoLayerClient implements LayerV
         // to before being read
         mContext = context;
         mScreenSize = new IntSize(0, 0);
         mWindowSize = new IntSize(0, 0);
         mDisplayPort = new DisplayPortMetrics();
         mRecordDrawTimes = true;
         mDrawTimingQueue = new DrawTimingQueue();
         mCurrentViewTransform = new ViewTransform(0, 0, 1);
-        mCurrentViewTransformMargins = new RectF();
         mProgressiveUpdateData = new ProgressiveUpdateData();
         mProgressiveUpdateDisplayPort = new DisplayPortMetrics();
 
         mForceRedraw = true;
         DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
         mViewportMetrics = new ImmutableViewportMetrics(displayMetrics)
                            .setViewportSize(view.getWidth(), view.getHeight());
         mZoomConstraints = new ZoomConstraints(false);
@@ -245,17 +243,18 @@ class GeckoLayerClient implements LayerV
         return mToolbarAnimator;
     }
 
     /* Informs Gecko that the screen size has changed. */
     private void sendResizeEventIfNecessary(boolean force) {
         DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
 
         IntSize newScreenSize = new IntSize(metrics.widthPixels, metrics.heightPixels);
-        IntSize newWindowSize = new IntSize(mView.getWidth(), mView.getHeight());
+        IntSize newWindowSize = new IntSize(mViewportMetrics.viewportRectWidth,
+                                            mViewportMetrics.viewportRectHeight);
 
         boolean screenSizeChanged = !mScreenSize.equals(newScreenSize);
         boolean windowSizeChanged = !mWindowSize.equals(newWindowSize);
 
         if (!force && !screenSizeChanged && !windowSizeChanged) {
             return;
         }
 
@@ -293,71 +292,16 @@ class GeckoLayerClient implements LayerV
             @Override
             public void run() {
                 mPanZoomController.pageRectUpdated();
                 mView.requestRender();
             }
         });
     }
 
-    /**
-     * Derives content document fixed position margins/fixed layer margins from
-     * the view margins in the given metrics object.
-     */
-    private void getFixedMargins(ImmutableViewportMetrics metrics, RectF fixedMargins) {
-        fixedMargins.left = 0;
-        fixedMargins.top = 0;
-        fixedMargins.right = 0;
-        fixedMargins.bottom = 0;
-
-        // The maximum margins are determined by the scrollable area of the page.
-        float maxMarginWidth = Math.max(0, metrics.getPageWidth() - metrics.getWidthWithoutMargins());
-        float maxMarginHeight = Math.max(0, metrics.getPageHeight() - metrics.getHeightWithoutMargins());
-
-        // If the margins can't fully hide, they're pinned on - in which case,
-        // fixed margins should always be zero.
-        if (maxMarginWidth < metrics.marginLeft + metrics.marginRight) {
-          maxMarginWidth = 0;
-        }
-        if (maxMarginHeight < metrics.marginTop + metrics.marginBottom) {
-          maxMarginHeight = 0;
-        }
-
-        PointF offset = metrics.getMarginOffset();
-        RectF overscroll = metrics.getOverscroll();
-        if (offset.x >= 0) {
-            fixedMargins.right = Math.max(0, Math.min(offset.x - overscroll.right, maxMarginWidth));
-        } else {
-            fixedMargins.left = Math.max(0, Math.min(-offset.x - overscroll.left, maxMarginWidth));
-        }
-        if (offset.y >= 0) {
-            fixedMargins.bottom = Math.max(0, Math.min(offset.y - overscroll.bottom, maxMarginHeight));
-        } else {
-            fixedMargins.top = Math.max(0, Math.min(-offset.y - overscroll.top, maxMarginHeight));
-        }
-
-        // Adjust for overscroll. If we're overscrolled on one side, add that
-        // distance to the margins of the other side (limiting to the maximum
-        // margin size calculated above).
-        if (overscroll.left > 0) {
-            fixedMargins.right = Math.min(maxMarginWidth - fixedMargins.left,
-                                          fixedMargins.right + overscroll.left);
-        } else if (overscroll.right > 0) {
-            fixedMargins.left = Math.min(maxMarginWidth - fixedMargins.right,
-                                         fixedMargins.left + overscroll.right);
-        }
-        if (overscroll.top > 0) {
-            fixedMargins.bottom = Math.min(maxMarginHeight - fixedMargins.top,
-                                           fixedMargins.bottom + overscroll.top);
-        } else if (overscroll.bottom > 0) {
-            fixedMargins.top = Math.min(maxMarginHeight - fixedMargins.bottom,
-                                        fixedMargins.top + overscroll.bottom);
-        }
-    }
-
     private void adjustViewport(DisplayPortMetrics displayPort) {
         // TODO: APZ For fennec might need margins information to deal with
         // the dynamic toolbar.
         if (AppConstants.MOZ_ANDROID_APZ)
             return;
 
         ImmutableViewportMetrics metrics = getViewportMetrics();
         ImmutableViewportMetrics clampedMetrics = metrics.clamp();
@@ -674,22 +618,17 @@ class GeckoLayerClient implements LayerV
         // metrics can change between here and there, as it's accessed outside
         // of the compositor thread.
         mFrameMetrics = getViewportMetrics();
 
         mCurrentViewTransform.x = mFrameMetrics.viewportRectLeft;
         mCurrentViewTransform.y = mFrameMetrics.viewportRectTop;
         mCurrentViewTransform.scale = mFrameMetrics.zoomFactor;
 
-        // Adjust the fixed layer margins so that overscroll subtracts from them.
-        getFixedMargins(mFrameMetrics, mCurrentViewTransformMargins);
-        mCurrentViewTransform.fixedLayerMarginLeft = mCurrentViewTransformMargins.left;
-        mCurrentViewTransform.fixedLayerMarginTop = mCurrentViewTransformMargins.top;
-        mCurrentViewTransform.fixedLayerMarginRight = mCurrentViewTransformMargins.right;
-        mCurrentViewTransform.fixedLayerMarginBottom = mCurrentViewTransformMargins.bottom;
+        mToolbarAnimator.populateFixedPositionMargins(mCurrentViewTransform, mFrameMetrics);
 
         if (mRootLayer != null) {
             mRootLayer.setPositionAndResolution(
                 x, y, x + width, y + height,
                 resolution);
         }
 
         if (layersUpdated && mRecordDrawTimes) {