From a468f781198ad6b9a0471b86705db9cf86c878e2 Mon Sep 17 00:00:00 2001 From: Tanushree Podder Date: Sun, 22 Jul 2018 01:59:37 -0400 Subject: [PATCH] Bug 1473699 - Async-scroll the layout viewport even if it's smaller than the visual viewport. r=botond When the layout viewport is smaller than the visual viewport and the user scrolls a web page, the layout viewport remains fixed to its position before the scroll event took place. However, the visual viewport moves according to the new scroll position. This patch addresses this issue by moving the layout viewport along with the visual viewport. MozReview-Commit-ID: 3Mk1o6AF2wr --HG-- extra : rebase_source : 8c6068059593038dc443cb9c96242483de97e9d9 --- gfx/layers/FrameMetrics.cpp | 56 ++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/gfx/layers/FrameMetrics.cpp b/gfx/layers/FrameMetrics.cpp index 0b23a3cd2b1e..90c3adad5600 100644 --- a/gfx/layers/FrameMetrics.cpp +++ b/gfx/layers/FrameMetrics.cpp @@ -26,24 +26,48 @@ FrameMetrics::RecalculateViewportOffset() // Additionally, if the composition bounds changes (due to an orientation // change, window resize, etc.), it may take a few frames for mViewport to // update and during that time, the visual viewport may be larger than the - // layout viewport, so don't attempt to make any adjustments. - if (mViewport.Contains(visualViewport) || - (mViewport.Width() < visualViewport.Width() && - !FuzzyEqualsMultiplicative(mViewport.Width(), visualViewport.Width())) || - (mViewport.Height() < visualViewport.Height() && - !FuzzyEqualsMultiplicative(mViewport.Height(), visualViewport.Height()))) { + // layout viewport. In such situations, we take an early exit if the visual + // viewport contains the layout viewport. + if (mViewport.Contains(visualViewport) || visualViewport.Contains(mViewport)) { return; } - if (visualViewport.X() < mViewport.X()) { - mViewport.MoveToX(visualViewport.X()); - } else if (mViewport.XMost() < visualViewport.XMost()) { - mViewport.MoveByX(visualViewport.XMost() - mViewport.XMost()); - } - if (visualViewport.Y() < mViewport.Y()) { - mViewport.MoveToY(visualViewport.Y()); - } else if (mViewport.YMost() < visualViewport.YMost()) { - mViewport.MoveByY(visualViewport.YMost() - mViewport.YMost()); - } + + // If visual viewport size is greater than the layout viewport, move the layout + // viewport such that it remains inside the visual viewport. Otherwise, + // move the layout viewport such that the visual viewport is contained + // inside the layout viewport. + if ((mViewport.Width() < visualViewport.Width() && + !FuzzyEqualsMultiplicative(mViewport.Width(), visualViewport.Width())) || + (mViewport.Height() < visualViewport.Height() && + !FuzzyEqualsMultiplicative(mViewport.Height(), visualViewport.Height()))) { + + if (mViewport.X() < visualViewport.X()) { + // layout viewport moves right + mViewport.MoveToX(visualViewport.X()); + } else if (visualViewport.XMost() < mViewport.XMost()) { + // layout viewport moves left + mViewport.MoveByX(visualViewport.XMost() - mViewport.XMost()); + } + if (mViewport.Y() < visualViewport.Y()) { + // layout viewport moves down + mViewport.MoveToY(visualViewport.Y()); + } else if (visualViewport.YMost() < mViewport.YMost()) { + // layout viewport moves up + mViewport.MoveByY(visualViewport.YMost() - mViewport.YMost()); + } + } else { + + if (visualViewport.X() < mViewport.X()) { + mViewport.MoveToX(visualViewport.X()); + } else if (mViewport.XMost() < visualViewport.XMost()) { + mViewport.MoveByX(visualViewport.XMost() - mViewport.XMost()); + } + if (visualViewport.Y() < mViewport.Y()) { + mViewport.MoveToY(visualViewport.Y()); + } else if (mViewport.YMost() < visualViewport.YMost()) { + mViewport.MoveByY(visualViewport.YMost() - mViewport.YMost()); + } + } } void