From b040f29dc0fe3876218a6f7efbb60c208957e385 Mon Sep 17 00:00:00 2001 From: Ting-Yu Lin Date: Fri, 7 Aug 2020 02:20:44 +0000 Subject: [PATCH] Bug 1042151 Part 2 - Refactor the conditions that decide which edge to clamp when getting scrolled rect. r=dholbert Differential Revision: https://phabricator.services.mozilla.com/D86076 --- layout/base/nsLayoutUtils.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index bc38f3473711..946867cac73e 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -2219,13 +2219,19 @@ nsRect nsLayoutUtils::GetScrolledRect(nsIFrame* aScrolledFrame, y1 = aScrolledFrameOverflowArea.y, y2 = aScrolledFrameOverflowArea.YMost(); - bool horizontal = !wm.IsVertical(); + const bool isHorizontalWM = !wm.IsVertical(); + const bool isVerticalWM = wm.IsVertical(); + bool isInlineFlowFromTopOrLeft = !wm.IsInlineReversed(); + bool isBlockFlowFromTopOrLeft = isHorizontalWM || wm.IsVerticalLR(); + + // TODO: Consider flexbox's main-axis and cross-axis in + // isInlineFlowFromTopOrLeft and isBlockFlowFromTopOrLeft. // Clamp the horizontal start-edge (x1 or x2, depending whether the logical - // axis that corresponds to horizontal progresses from L-R or R-L). - // In horizontal writing mode, we need to check IsInlineReversed() to see - // which side to clamp; in vertical mode, it depends on the block direction. - if ((horizontal && !wm.IsInlineReversed()) || wm.IsVerticalLR()) { + // axis that corresponds to horizontal progresses from left-to-right or + // right-to-left). + if ((isHorizontalWM && isInlineFlowFromTopOrLeft) || + (isVerticalWM && isBlockFlowFromTopOrLeft)) { if (x1 < 0) { x1 = 0; } @@ -2245,10 +2251,11 @@ nsRect nsLayoutUtils::GetScrolledRect(nsIFrame* aScrolledFrame, x2 += extraWidth; } - // Similarly, clamp the vertical start-edge. - // In horizontal writing mode, the block direction is always top-to-bottom; - // in vertical writing mode, we need to check IsInlineReversed(). - if (horizontal || !wm.IsInlineReversed()) { + // Similarly, clamp the vertical start-edge (y1 or y2, depending whether the + // logical axis that corresponds to vertical progresses from top-to-bottom or + // buttom-to-top). + if ((isHorizontalWM && isBlockFlowFromTopOrLeft) || + (isVerticalWM && isInlineFlowFromTopOrLeft)) { if (y1 < 0) { y1 = 0; }