Bug 957915 - Handle calc(%) on tables. r=mats

This patch makes us handle calc with percentages when we can convert to
percentages the same way we handle plain percentages in table layout.

We still treat length + percentage as auto (this matches Blink / WebKit as
well). There's one case we differ with Blink / WebKit, which is calc(% + 0px),
which they'd treat as auto instead of a percentage.

I think this is a bug on them (or at least worth some spec clarification). I
filed https://github.com/w3c/csswg-drafts/issues/3482 for that.

In practice what that'd means for us if the WG decides that Blink / WebKit is
right in that case is that we'd need to keep track of whether the calc()
specifies lengths, and return false from ConvertsToPercent if so.

In any case, nothing that would massively change this patch, and I think enough
of an edge case that is not worth blocking on the CSSWG decision here. Though I
could be convinced otherwise of course.

Differential Revision: https://phabricator.services.mozilla.com/D15719
This commit is contained in:
Emilio Cobos Álvarez
2019-01-15 19:39:23 +00:00
parent ab7e297952
commit 7f0ace82b0
10 changed files with 87 additions and 60 deletions

View File

@@ -71,13 +71,13 @@ FixedTableLayoutStrategy::~FixedTableLayoutStrategy() {}
if (styleISize->ConvertsToLength()) {
result +=
colFrame->ComputeISizeValue(aRenderingContext, 0, 0, 0, *styleISize);
} else if (styleISize->GetUnit() == eStyleUnit_Percent) {
} else if (styleISize->ConvertsToPercent()) {
// do nothing
} else {
NS_ASSERTION(
styleISize->GetUnit() == eStyleUnit_Auto ||
styleISize->GetUnit() == eStyleUnit_Enumerated ||
(styleISize->IsCalcUnit() && styleISize->CalcHasPercent()),
(styleISize->IsCalcUnit() && !styleISize->ConvertsToPercent()),
"bad inline size");
// The 'table-layout: fixed' algorithm considers only cells in the
@@ -102,14 +102,14 @@ FixedTableLayoutStrategy::~FixedTableLayoutStrategy() {}
cellISize = ((cellISize + spacing) / colSpan) - spacing;
}
result += cellISize;
} else if (styleISize->GetUnit() == eStyleUnit_Percent) {
} else if (styleISize->ConvertsToPercent()) {
if (colSpan > 1) {
// XXX Can this force columns to negative inline sizes?
result -= spacing * (colSpan - 1);
}
}
// else, for 'auto', '-moz-available', '-moz-fit-content',
// and 'calc()' with percentages, do nothing
// and 'calc()' with both lengths and percentages, do nothing
}
}
}
@@ -209,8 +209,8 @@ static inline nscoord AllocateUnassigned(nscoord aUnassignedSpace,
colISize = colFrame->ComputeISizeValue(aReflowInput.mRenderingContext, 0,
0, 0, *styleISize);
specTotal += colISize;
} else if (styleISize->GetUnit() == eStyleUnit_Percent) {
float pct = styleISize->GetPercentValue();
} else if (styleISize->ConvertsToPercent()) {
float pct = styleISize->ToPercent();
colISize = NSToCoordFloor(pct * float(tableISize));
colFrame->AddPrefPercent(pct);
pctTotal += pct;
@@ -218,7 +218,7 @@ static inline nscoord AllocateUnassigned(nscoord aUnassignedSpace,
NS_ASSERTION(
styleISize->GetUnit() == eStyleUnit_Auto ||
styleISize->GetUnit() == eStyleUnit_Enumerated ||
(styleISize->IsCalcUnit() && styleISize->CalcHasPercent()),
(styleISize->IsCalcUnit() && !styleISize->ConvertsToPercent()),
"bad inline size");
// The 'table-layout: fixed' algorithm considers only cells in the
@@ -242,9 +242,9 @@ static inline nscoord AllocateUnassigned(nscoord aUnassignedSpace,
colISize = nsLayoutUtils::IntrinsicForContainer(
aReflowInput.mRenderingContext, cellFrame,
nsLayoutUtils::MIN_ISIZE);
} else if (styleISize->GetUnit() == eStyleUnit_Percent) {
} else if (styleISize->ConvertsToPercent()) {
// XXX This should use real percentage padding
float pct = styleISize->GetPercentValue();
float pct = styleISize->ToPercent();
colISize = NSToCoordFloor(pct * float(tableISize));
if (cellStylePos->mBoxSizing == StyleBoxSizing::Content) {
@@ -273,7 +273,7 @@ static inline nscoord AllocateUnassigned(nscoord aUnassignedSpace,
colISize = 0;
}
}
if (styleISize->GetUnit() != eStyleUnit_Percent) {
if (!styleISize->ConvertsToPercent()) {
specTotal += colISize;
}
}