From 6ae79ec0655b8f43070551d0145a89871a05be42 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Fri, 22 Jul 2022 14:35:10 +0000 Subject: [PATCH] Bug 1780475 - Obey contain-intrinsic-size in ContainSizeAxes. r=emilio ContainSizeAxes::ContainSize and ContainSizeAxes::ContainIntrinsicSize were just using 0 for the axes with size containment, now they will take contain-intrinsic-width and contain-intrinsic-height into account. The WritingMode parameter is replaced with a nsIFrame from which the properties are retrieved. There are various places that aren't currently using these functions, so the effect of this patch is rather minimal, but some cases of the new test are now passing. Differential Revision: https://phabricator.services.mozilla.com/D152355 --- layout/generic/nsGfxScrollFrame.cpp | 4 +- layout/generic/nsHTMLCanvasFrame.cpp | 2 +- layout/generic/nsImageFrame.cpp | 8 +- layout/generic/nsSubDocumentFrame.cpp | 4 +- layout/generic/nsVideoFrame.cpp | 9 +- layout/style/nsStyleStruct.cpp | 46 ++++++--- layout/style/nsStyleStruct.h | 4 +- layout/svg/SVGOuterSVGFrame.cpp | 2 +- .../contain-intrinsic-size-028.html.ini | 36 +++++++ .../contain-intrinsic-size-028.html | 99 +++++++++++++++++++ 10 files changed, 182 insertions(+), 32 deletions(-) create mode 100644 testing/web-platform/meta/css/css-sizing/contain-intrinsic-size/contain-intrinsic-size-028.html.ini create mode 100644 testing/web-platform/tests/css/css-sizing/contain-intrinsic-size/contain-intrinsic-size-028.html diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 699b07ceb2fc..27454ed78c21 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -586,7 +586,7 @@ bool nsHTMLScrollFrame::TryLayout(ScrollReflowInput& aState, // XXXldb Can we depend more on ComputeSize here? nsSize kidSize = aState.mReflowInput.mStyleDisplay->GetContainSizeAxes().ContainSize( - aKidMetrics->PhysicalSize(), wm); + aKidMetrics->PhysicalSize(), *aState.mReflowInput.mFrame); const nsSize desiredInsideBorderSize = kidSize + scrollbarGutterSize; aState.mInsideBorderSize = ComputeInsideBorderSize(aState, desiredInsideBorderSize); @@ -999,7 +999,7 @@ void nsHTMLScrollFrame::ReflowContents(ScrollReflowInput& aState, aState.mHScrollbar != ShowScrollbar::Always) { nsSize kidSize = aState.mReflowInput.mStyleDisplay->GetContainSizeAxes().ContainSize( - kidDesiredSize.PhysicalSize(), desiredWm); + kidDesiredSize.PhysicalSize(), *aState.mReflowInput.mFrame); nsSize insideBorderSize = ComputeInsideBorderSize(aState, kidSize); nsRect scrolledRect = mHelper.GetUnsnappedScrolledRectInternal( kidDesiredSize.ScrollableOverflow(), insideBorderSize); diff --git a/layout/generic/nsHTMLCanvasFrame.cpp b/layout/generic/nsHTMLCanvasFrame.cpp index 09d6358e8e0c..ae9773d1ae4a 100644 --- a/layout/generic/nsHTMLCanvasFrame.cpp +++ b/layout/generic/nsHTMLCanvasFrame.cpp @@ -442,7 +442,7 @@ IntrinsicSize nsHTMLCanvasFrame::GetIntrinsicSize() { return IntrinsicSize(0, 0); } return containAxes.ContainIntrinsicSize( - IntrinsicSizeFromCanvasSize(GetCanvasSize()), GetWritingMode()); + IntrinsicSizeFromCanvasSize(GetCanvasSize()), *this); } /* virtual */ diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index fd63cf44bcc8..04876318c51c 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -640,23 +640,21 @@ static IntrinsicSize ComputeIntrinsicSize(imgIContainer* aImage, ScaleIntrinsicSizeForDensity(intrinsicSize, aFrame.GetImageFromStyle()->GetResolution()); } - return containAxes.ContainIntrinsicSize(intrinsicSize, - aFrame.GetWritingMode()); + return containAxes.ContainIntrinsicSize(intrinsicSize, aFrame); } if (aKind == nsImageFrame::Kind::ListStyleImage) { // Note: images are handled above, this handles gradients etc. nscoord defaultLength = ListImageDefaultLength(aFrame); return containAxes.ContainIntrinsicSize( - IntrinsicSize(defaultLength, defaultLength), aFrame.GetWritingMode()); + IntrinsicSize(defaultLength, defaultLength), aFrame); } if (aFrame.ShouldShowBrokenImageIcon()) { nscoord edgeLengthToUse = nsPresContext::CSSPixelsToAppUnits( ICON_SIZE + (2 * (ICON_PADDING + ALT_BORDER_WIDTH))); return containAxes.ContainIntrinsicSize( - IntrinsicSize(edgeLengthToUse, edgeLengthToUse), - aFrame.GetWritingMode()); + IntrinsicSize(edgeLengthToUse, edgeLengthToUse), aFrame); } if (aUseMappedRatio && style.StylePosition()->mAspectRatio.HasRatio()) { diff --git a/layout/generic/nsSubDocumentFrame.cpp b/layout/generic/nsSubDocumentFrame.cpp index 74d1c01e298f..bda782db314f 100644 --- a/layout/generic/nsSubDocumentFrame.cpp +++ b/layout/generic/nsSubDocumentFrame.cpp @@ -626,7 +626,7 @@ IntrinsicSize nsSubDocumentFrame::GetIntrinsicSize() { if (auto size = olc->GetSubdocumentIntrinsicSize()) { // Use the intrinsic size from the child SVG document, if available. - return containAxes.ContainIntrinsicSize(*size, GetWritingMode()); + return containAxes.ContainIntrinsicSize(*size, *this); } } @@ -640,7 +640,7 @@ IntrinsicSize nsSubDocumentFrame::GetIntrinsicSize() { // We must be an HTML