From b5b96a98d8ca28e687e62eb3fbebe0210cb5607b Mon Sep 17 00:00:00 2001 From: Ting-Yu Lin Date: Thu, 6 Aug 2020 22:38:11 +0000 Subject: [PATCH] Bug 1042151 Part 4 - Consider flexbox's main & cross axis when getting scrolled rect. r=dholbert Differential Revision: https://phabricator.services.mozilla.com/D86078 --- layout/base/nsLayoutUtils.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 946867cac73e..e0ac2b763848 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -112,6 +112,7 @@ #include "nsDataHashtable.h" #include "nsDeckFrame.h" #include "nsDisplayList.h" +#include "nsFlexContainerFrame.h" #include "nsFontInflationData.h" #include "nsFontMetrics.h" #include "nsFrameList.h" @@ -2224,8 +2225,27 @@ nsRect nsLayoutUtils::GetScrolledRect(nsIFrame* aScrolledFrame, bool isInlineFlowFromTopOrLeft = !wm.IsInlineReversed(); bool isBlockFlowFromTopOrLeft = isHorizontalWM || wm.IsVerticalLR(); - // TODO: Consider flexbox's main-axis and cross-axis in - // isInlineFlowFromTopOrLeft and isBlockFlowFromTopOrLeft. + if (aScrolledFrame->IsFlexContainerFrame()) { + // In a flex container, the children flow (and overflow) along the flex + // container's main axis and cross axis. These are analogous to the + // inline/block axes, and by default they correspond exactly to those axes; + // but the flex container's CSS (e.g. flex-direction: column-reverse) may + // have swapped and/or reversed them, and we need to account for that here. + FlexboxAxisInfo info(aScrolledFrame); + if (info.mIsRowOriented) { + // The flex container's inline axis is the main axis. + isInlineFlowFromTopOrLeft = + isInlineFlowFromTopOrLeft == !info.mIsMainAxisReversed; + isBlockFlowFromTopOrLeft = + isBlockFlowFromTopOrLeft == !info.mIsCrossAxisReversed; + } else { + // The flex container's block axis is the main axis. + isBlockFlowFromTopOrLeft = + isBlockFlowFromTopOrLeft == !info.mIsMainAxisReversed; + isInlineFlowFromTopOrLeft = + isInlineFlowFromTopOrLeft == !info.mIsCrossAxisReversed; + } + } // Clamp the horizontal start-edge (x1 or x2, depending whether the logical // axis that corresponds to horizontal progresses from left-to-right or