Skip to content

Commit

Permalink
Bug 1733952 - When computing inline intrinsic sizes, resolve with a 0…
Browse files Browse the repository at this point in the history
… percentage basis rather than just resolving to zero if there's a percentage. r=jfkthame

This matches other browsers, the spec
(https://drafts.csswg.org/css-sizing/#cyclic-percentage-contribution):

  For the min size properties, as well as for margins and paddings (and
  gutters), a cyclic percentage is resolved against zero for determining
  intrinsic size contributions.

And also what we do in SizeComputationInput::Compute{Margin,Padding}:

  https://searchfox.org/mozilla-central/rev/75e9d727ce5ba2c14653cf8fb0f1367f085271b7/layout/generic/ReflowInput.cpp#2811-2832
  https://searchfox.org/mozilla-central/rev/75e9d727ce5ba2c14653cf8fb0f1367f085271b7/layout/generic/ReflowInput.cpp#2861-2868

This fixes a compat issue with the menu alignment in lume.io:

  webcompat/web-bugs#88484 (comment)

It's also simpler.

Differential Revision: https://phabricator.services.mozilla.com/D127441
  • Loading branch information
emilio committed Oct 4, 2021
1 parent 622ae51 commit 438aa90
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
34 changes: 8 additions & 26 deletions layout/generic/nsContainerFrameInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,14 @@

#include "nsContainerFrame.h"

namespace mozilla {
namespace detail {

static nscoord GetCoord(const LengthPercentage& aCoord, nscoord aIfNotCoord) {
if (aCoord.ConvertsToLength()) {
return aCoord.ToLength();
}
return aIfNotCoord;
}

static nscoord GetCoord(const LengthPercentageOrAuto& aCoord,
nscoord aIfNotCoord) {
if (aCoord.IsAuto()) {
return aIfNotCoord;
}
return GetCoord(aCoord.AsLengthPercentage(), aIfNotCoord);
}

} // namespace detail
} // namespace mozilla

template <typename ISizeData, typename F>
void nsContainerFrame::DoInlineIntrinsicISize(ISizeData* aData,
F& aHandleChildren) {
using namespace mozilla;
using mozilla::detail::GetCoord;

auto GetMargin = [](const LengthPercentageOrAuto& aCoord) -> nscoord {
return aCoord.IsAuto() ? 0 : aCoord.AsLengthPercentage().Resolve(0);
};

if (GetPrevInFlow()) return; // Already added.

Expand All @@ -61,9 +43,9 @@ void nsContainerFrame::DoInlineIntrinsicISize(ISizeData* aData,
if (!GetPrevContinuation() || MOZ_UNLIKELY(!sliceBreak)) {
nscoord startPBM =
// clamp negative calc() to 0
std::max(GetCoord(stylePadding->mPadding.Get(startSide), 0), 0) +
std::max(stylePadding->mPadding.Get(startSide).Resolve(0), 0) +
styleBorder->GetComputedBorderWidth(startSide) +
GetCoord(styleMargin->mMargin.Get(startSide), 0);
GetMargin(styleMargin->mMargin.Get(startSide));
if (MOZ_LIKELY(sliceBreak)) {
aData->mCurrentLine += startPBM;
} else {
Expand All @@ -73,9 +55,9 @@ void nsContainerFrame::DoInlineIntrinsicISize(ISizeData* aData,

nscoord endPBM =
// clamp negative calc() to 0
std::max(GetCoord(stylePadding->mPadding.Get(endSide), 0), 0) +
std::max(stylePadding->mPadding.Get(endSide).Resolve(0), 0) +
styleBorder->GetComputedBorderWidth(endSide) +
GetCoord(styleMargin->mMargin.Get(endSide), 0);
GetMargin(styleMargin->mMargin.Get(endSide));
if (MOZ_UNLIKELY(!sliceBreak)) {
clonePBM += endPBM;
aData->mCurrentLine += clonePBM;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<title>Calc gets resolved with 0 percent basis for intrinsic size computation</title>
<style>
div {
background-color: green;
width: max-content;
}
span {
margin-left: 30px;
padding-left: 50px;
}
</style>
<div>
<span>ABCD</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<title>Calc gets resolved with 0 percent basis for intrinsic size computation</title>
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="match" href="inline-intrinsic-size-calc-ref.html">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1733952">
<link rel="help" href="https://drafts.csswg.org/css-sizing/#cyclic-percentage-contribution">
<style>
div {
background-color: green;
width: max-content;
}
span {
margin-left: calc(0% + 30px);
padding-left: calc(0% + 50px);
}
</style>
<div>
<span>ABCD</span>
</div>

0 comments on commit 438aa90

Please sign in to comment.