summaryrefslogtreecommitdiff
path: root/layout/generic
diff options
context:
space:
mode:
authorFranklinDM <mrmineshafter17@gmail.com>2022-04-06 23:59:01 +0800
committerFranklinDM <mrmineshafter17@gmail.com>2022-04-07 18:35:49 +0800
commit79b640795aacac89e67043a22cb3ceb622bd0864 (patch)
tree21a5ef80ff911eb79f4fd7787f40f59609a13001 /layout/generic
parent0b75a2a787eeec1c87f7d6f3fa0d114c00f950f8 (diff)
downloaduxp-79b640795aacac89e67043a22cb3ceb622bd0864.tar.gz
Issue #1370 - Part 3: Implement `content` keyword for `flex-basis` property
Partially based on https://bugzilla.mozilla.org/show_bug.cgi?id=1105111
Diffstat (limited to 'layout/generic')
-rw-r--r--layout/generic/nsContainerFrame.cpp25
-rw-r--r--layout/generic/nsFrame.cpp16
2 files changed, 37 insertions, 4 deletions
diff --git a/layout/generic/nsContainerFrame.cpp b/layout/generic/nsContainerFrame.cpp
index 125d602635..dd20ccffee 100644
--- a/layout/generic/nsContainerFrame.cpp
+++ b/layout/generic/nsContainerFrame.cpp
@@ -944,8 +944,29 @@ nsContainerFrame::ComputeAutoSize(nsRenderingContext* aRenderingContext,
aBorder.ISize(aWM) - aPadding.ISize(aWM);
// replaced elements always shrink-wrap
if ((aFlags & ComputeSizeFlags::eShrinkWrap) || IsFrameOfType(eReplaced)) {
- // don't bother setting it if the result won't be used
- if (StylePosition()->ISize(aWM).GetUnit() == eStyleUnit_Auto) {
+ const nsStylePosition* position = StylePosition();
+
+ bool isFlexBasisContent = false;
+ if (IsFlexItem()) {
+ uint32_t flexDirection =
+ GetParent()->StylePosition()->mFlexDirection;
+ bool isInlineFlexItem =
+ flexDirection == NS_STYLE_FLEX_DIRECTION_ROW ||
+ flexDirection == NS_STYLE_FLEX_DIRECTION_ROW_REVERSE;
+ isFlexBasisContent =
+ position->mFlexBasis.GetUnit() == eStyleUnit_Enumerated &&
+ position->mFlexBasis.GetIntValue() == NS_STYLE_FLEX_BASIS_CONTENT &&
+ isInlineFlexItem;
+ }
+
+ // Only bother computing our 'auto' ISize if the result will be used.
+ // It'll be used under two scenarios:
+ // - If our ISize property is itself 'auto'.
+ // - If we're using flex-basis in place of our ISize property (i.e. we're a
+ // flex item with our inline axis being the main axis), AND we have
+ // flex-basis:content.
+ bool isAuto = position->ISize(aWM).GetUnit() == eStyleUnit_Auto;
+ if (isAuto || isFlexBasisContent) {
result.ISize(aWM) = ShrinkWidthToFit(aRenderingContext, availBased, aFlags);
}
} else {
diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp
index 99442e681f..141c148673 100644
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -4647,11 +4647,23 @@ nsFrame::SetCoordToFlexBasis(bool aIsInlineFlexItem,
return;
}
+ const nsStyleCoord* newCoord = aFlexBasis;
+
+ // Having 'content' as the value of the 'flex-basis' property is
+ // equivalent to setting both 'flex-basis' and the main size
+ // properties to 'auto', which is why a dummy 'auto' value will
+ // be used here for the main size property.
+ if (aFlexBasis->GetUnit() == eStyleUnit_Enumerated &&
+ aFlexBasis->GetIntValue() == NS_STYLE_FLEX_BASIS_CONTENT) {
+ static const nsStyleCoord autoStyleCoord(eStyleUnit_Auto);
+ newCoord = &autoStyleCoord;
+ }
+
// Override whichever styleCoord is in the flex container's main axis
if (aIsInlineFlexItem) {
- *aInlineStyle = aFlexBasis;
+ *aInlineStyle = newCoord;
} else {
- *aBlockStyle = aFlexBasis;
+ *aBlockStyle = newCoord;
}
}