Bug 1300369 part 11 - Move nsLayoutUtils::ComputeISizeValue to a nsIFrame method (idempotent patch). r=dholbert

This commit is contained in:
Mats Palmgren 2016-11-05 02:57:07 +01:00
parent 5bcffbffeb
commit 6b1b0153ba
7 changed files with 96 additions and 103 deletions

View File

@ -5275,67 +5275,6 @@ nsLayoutUtils::ComputeCBDependentValue(nscoord aPercentBasis,
return 0; return 0;
} }
/* static */ nscoord
nsLayoutUtils::ComputeISizeValue(
nsRenderingContext* aRenderingContext,
nsIFrame* aFrame,
nscoord aContainingBlockISize,
nscoord aContentEdgeToBoxSizing,
nscoord aBoxSizingToMarginEdge,
const nsStyleCoord& aCoord)
{
NS_PRECONDITION(aFrame, "non-null frame expected");
NS_PRECONDITION(aRenderingContext, "non-null rendering context expected");
LAYOUT_WARN_IF_FALSE(aContainingBlockISize != NS_UNCONSTRAINEDSIZE,
"have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size "
"calculation");
NS_PRECONDITION(aContainingBlockISize >= 0,
"inline-size less than zero");
nscoord result;
if (aCoord.IsCoordPercentCalcUnit()) {
result = nsRuleNode::ComputeCoordPercentCalc(aCoord,
aContainingBlockISize);
// The result of a calc() expression might be less than 0; we
// should clamp at runtime (below). (Percentages and coords that
// are less than 0 have already been dropped by the parser.)
result -= aContentEdgeToBoxSizing;
} else {
MOZ_ASSERT(eStyleUnit_Enumerated == aCoord.GetUnit());
// If aFrame is a container for font size inflation, then shrink
// wrapping inside of it should not apply font size inflation.
AutoMaybeDisableFontInflation an(aFrame);
int32_t val = aCoord.GetIntValue();
switch (val) {
case NS_STYLE_WIDTH_MAX_CONTENT:
result = aFrame->GetPrefISize(aRenderingContext);
NS_ASSERTION(result >= 0, "inline-size less than zero");
break;
case NS_STYLE_WIDTH_MIN_CONTENT:
result = aFrame->GetMinISize(aRenderingContext);
NS_ASSERTION(result >= 0, "inline-size less than zero");
break;
case NS_STYLE_WIDTH_FIT_CONTENT:
{
nscoord pref = aFrame->GetPrefISize(aRenderingContext),
min = aFrame->GetMinISize(aRenderingContext),
fill = aContainingBlockISize -
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
result = std::max(min, std::min(pref, fill));
NS_ASSERTION(result >= 0, "inline-size less than zero");
}
break;
case NS_STYLE_WIDTH_AVAILABLE:
result = aContainingBlockISize -
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
}
}
return std::max(0, result);
}
/* static */ nscoord /* static */ nscoord
nsLayoutUtils::ComputeBSizeDependentValue( nsLayoutUtils::ComputeBSizeDependentValue(
nscoord aContainingBlockBSize, nscoord aContainingBlockBSize,

View File

@ -1449,14 +1449,6 @@ public:
static nscoord ComputeCBDependentValue(nscoord aPercentBasis, static nscoord ComputeCBDependentValue(nscoord aPercentBasis,
const nsStyleCoord& aCoord); const nsStyleCoord& aCoord);
static nscoord ComputeISizeValue(
nsRenderingContext* aRenderingContext,
nsIFrame* aFrame,
nscoord aContainingBlockISize,
nscoord aContentEdgeToBoxSizing,
nscoord aBoxSizingToMarginEdge,
const nsStyleCoord& aCoord);
static nscoord ComputeBSizeDependentValue( static nscoord ComputeBSizeDependentValue(
nscoord aContainingBlockBSize, nscoord aContainingBlockBSize,
const nsStyleCoord& aCoord); const nsStyleCoord& aCoord);

View File

@ -265,11 +265,11 @@ SizeComputationInput::ComputeISizeValue(nscoord aContainingBlockISize,
nscoord aBoxSizingToMarginEdge, nscoord aBoxSizingToMarginEdge,
const nsStyleCoord& aCoord) const const nsStyleCoord& aCoord) const
{ {
return nsLayoutUtils::ComputeISizeValue(mRenderingContext, mFrame, return mFrame->ComputeISizeValue(mRenderingContext,
aContainingBlockISize, aContainingBlockISize,
aContentEdgeToBoxSizing, aContentEdgeToBoxSizing,
aBoxSizingToMarginEdge, aBoxSizingToMarginEdge,
aCoord); aCoord);
} }
nscoord nscoord

View File

@ -41,6 +41,7 @@
#include "mozilla/Sprintf.h" #include "mozilla/Sprintf.h"
#include "nsFrameManager.h" #include "nsFrameManager.h"
#include "nsLayoutUtils.h" #include "nsLayoutUtils.h"
#include "LayoutLogging.h"
#include "mozilla/RestyleManager.h" #include "mozilla/RestyleManager.h"
#include "mozilla/RestyleManagerHandle.h" #include "mozilla/RestyleManagerHandle.h"
#include "mozilla/RestyleManagerHandleInlines.h" #include "mozilla/RestyleManagerHandleInlines.h"
@ -4710,9 +4711,9 @@ nsFrame::ComputeSize(nsRenderingContext* aRenderingContext,
if (inlineStyleCoord->GetUnit() != eStyleUnit_Auto) { if (inlineStyleCoord->GetUnit() != eStyleUnit_Auto) {
result.ISize(aWM) = result.ISize(aWM) =
nsLayoutUtils::ComputeISizeValue(aRenderingContext, this, ComputeISizeValue(aRenderingContext, aCBSize.ISize(aWM),
aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize, boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize,
*inlineStyleCoord); *inlineStyleCoord);
} }
// Flex items ignore their min & max sizing properties in their // Flex items ignore their min & max sizing properties in their
@ -4723,9 +4724,9 @@ nsFrame::ComputeSize(nsRenderingContext* aRenderingContext,
if (maxISizeCoord.GetUnit() != eStyleUnit_None && if (maxISizeCoord.GetUnit() != eStyleUnit_None &&
!(isFlexItem && isInlineFlexItem)) { !(isFlexItem && isInlineFlexItem)) {
maxISize = maxISize =
nsLayoutUtils::ComputeISizeValue(aRenderingContext, this, ComputeISizeValue(aRenderingContext, aCBSize.ISize(aWM),
aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize, boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize,
maxISizeCoord); maxISizeCoord);
result.ISize(aWM) = std::min(maxISize, result.ISize(aWM)); result.ISize(aWM) = std::min(maxISize, result.ISize(aWM));
} }
@ -4734,9 +4735,9 @@ nsFrame::ComputeSize(nsRenderingContext* aRenderingContext,
if (minISizeCoord.GetUnit() != eStyleUnit_Auto && if (minISizeCoord.GetUnit() != eStyleUnit_Auto &&
!(isFlexItem && isInlineFlexItem)) { !(isFlexItem && isInlineFlexItem)) {
minISize = minISize =
nsLayoutUtils::ComputeISizeValue(aRenderingContext, this, ComputeISizeValue(aRenderingContext, aCBSize.ISize(aWM),
aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize, boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize,
minISizeCoord); minISizeCoord);
} else if (MOZ_UNLIKELY(isGridItem)) { } else if (MOZ_UNLIKELY(isGridItem)) {
// This implements "Implied Minimum Size of Grid Items". // This implements "Implied Minimum Size of Grid Items".
// https://drafts.csswg.org/css-grid/#min-size-auto // https://drafts.csswg.org/css-grid/#min-size-auto
@ -4961,8 +4962,8 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
bool stretchB = false; bool stretchB = false;
if (!isAutoISize) { if (!isAutoISize) {
iSize = nsLayoutUtils::ComputeISizeValue(aRenderingContext, iSize = ComputeISizeValue(aRenderingContext,
this, aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
boxSizingToMarginEdgeISize, *inlineStyleCoord); boxSizingToMarginEdgeISize, *inlineStyleCoord);
} else if (MOZ_UNLIKELY(isGridItem)) { } else if (MOZ_UNLIKELY(isGridItem)) {
MOZ_ASSERT(!IS_TRUE_OVERFLOW_CONTAINER(this)); MOZ_ASSERT(!IS_TRUE_OVERFLOW_CONTAINER(this));
@ -4995,8 +4996,8 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
if (maxISizeCoord.GetUnit() != eStyleUnit_None && if (maxISizeCoord.GetUnit() != eStyleUnit_None &&
!(isFlexItem && isInlineFlexItem)) { !(isFlexItem && isInlineFlexItem)) {
maxISize = nsLayoutUtils::ComputeISizeValue(aRenderingContext, maxISize = ComputeISizeValue(aRenderingContext,
this, aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
boxSizingToMarginEdgeISize, maxISizeCoord); boxSizingToMarginEdgeISize, maxISizeCoord);
} else { } else {
maxISize = nscoord_MAX; maxISize = nscoord_MAX;
@ -5010,8 +5011,8 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
if (minISizeCoord.GetUnit() != eStyleUnit_Auto && if (minISizeCoord.GetUnit() != eStyleUnit_Auto &&
!(isFlexItem && isInlineFlexItem)) { !(isFlexItem && isInlineFlexItem)) {
minISize = nsLayoutUtils::ComputeISizeValue(aRenderingContext, minISize = ComputeISizeValue(aRenderingContext,
this, aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
boxSizingToMarginEdgeISize, minISizeCoord); boxSizingToMarginEdgeISize, minISizeCoord);
} else { } else {
// Treat "min-width: auto" as 0. // Treat "min-width: auto" as 0.
@ -5324,6 +5325,64 @@ nsFrame::ShrinkWidthToFit(nsRenderingContext* aRenderingContext,
return result; return result;
} }
nscoord
nsIFrame::ComputeISizeValue(nsRenderingContext* aRenderingContext,
nscoord aContainingBlockISize,
nscoord aContentEdgeToBoxSizing,
nscoord aBoxSizingToMarginEdge,
const nsStyleCoord& aCoord)
{
NS_PRECONDITION(aRenderingContext, "non-null rendering context expected");
LAYOUT_WARN_IF_FALSE(aContainingBlockISize != NS_UNCONSTRAINEDSIZE,
"have unconstrained inline-size; this should only result from "
"very large sizes, not attempts at intrinsic inline-size "
"calculation");
NS_PRECONDITION(aContainingBlockISize >= 0,
"inline-size less than zero");
nscoord result;
if (aCoord.IsCoordPercentCalcUnit()) {
result = nsRuleNode::ComputeCoordPercentCalc(aCoord,
aContainingBlockISize);
// The result of a calc() expression might be less than 0; we
// should clamp at runtime (below). (Percentages and coords that
// are less than 0 have already been dropped by the parser.)
result -= aContentEdgeToBoxSizing;
} else {
MOZ_ASSERT(eStyleUnit_Enumerated == aCoord.GetUnit());
// If 'this' is a container for font size inflation, then shrink
// wrapping inside of it should not apply font size inflation.
AutoMaybeDisableFontInflation an(this);
int32_t val = aCoord.GetIntValue();
switch (val) {
case NS_STYLE_WIDTH_MAX_CONTENT:
result = GetPrefISize(aRenderingContext);
NS_ASSERTION(result >= 0, "inline-size less than zero");
break;
case NS_STYLE_WIDTH_MIN_CONTENT:
result = GetMinISize(aRenderingContext);
NS_ASSERTION(result >= 0, "inline-size less than zero");
break;
case NS_STYLE_WIDTH_FIT_CONTENT:
{
nscoord pref = GetPrefISize(aRenderingContext),
min = GetMinISize(aRenderingContext),
fill = aContainingBlockISize -
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
result = std::max(min, std::min(pref, fill));
NS_ASSERTION(result >= 0, "inline-size less than zero");
}
break;
case NS_STYLE_WIDTH_AVAILABLE:
result = aContainingBlockISize -
(aBoxSizingToMarginEdge + aContentEdgeToBoxSizing);
}
}
return std::max(0, result);
}
void void
nsFrame::DidReflow(nsPresContext* aPresContext, nsFrame::DidReflow(nsPresContext* aPresContext,
const ReflowInput* aReflowInput, const ReflowInput* aReflowInput,

View File

@ -3377,6 +3377,14 @@ public:
int32_t aIncrement, int32_t aIncrement,
bool aForCounting) { return false; } bool aForCounting) { return false; }
/**
* Helper function - computes the content-box inline size for aCoord.
*/
nscoord ComputeISizeValue(nsRenderingContext* aRenderingContext,
nscoord aContainingBlockISize,
nscoord aContentEdgeToBoxSizing,
nscoord aBoxSizingToMarginEdge,
const nsStyleCoord& aCoord);
protected: protected:
// Members // Members
nsRect mRect; nsRect mRect;

View File

@ -143,8 +143,7 @@ GetISizeInfo(nsRenderingContext *aRenderingContext,
// isize, it will (in some cases) subtract the box-sizing edges. // isize, it will (in some cases) subtract the box-sizing edges.
// We prevent this unwanted behavior by calling it with // We prevent this unwanted behavior by calling it with
// aContentEdgeToBoxSizing and aBoxSizingToMarginEdge set to 0. // aContentEdgeToBoxSizing and aBoxSizingToMarginEdge set to 0.
nscoord c = nsLayoutUtils::ComputeISizeValue(aRenderingContext, nscoord c = aFrame->ComputeISizeValue(aRenderingContext, 0, 0, 0, iSize);
aFrame, 0, 0, 0, iSize);
// Quirk: A cell with "nowrap" set and a coord value for the // Quirk: A cell with "nowrap" set and a coord value for the
// isize which is bigger than the intrinsic minimum isize uses // isize which is bigger than the intrinsic minimum isize uses
// that coord value as the minimum isize. // that coord value as the minimum isize.
@ -191,9 +190,8 @@ GetISizeInfo(nsRenderingContext *aRenderingContext,
// XXX To really implement 'max-inline-size' well, we'd need to store // XXX To really implement 'max-inline-size' well, we'd need to store
// it separately on the columns. // it separately on the columns.
if (maxISize.ConvertsToLength() || unit == eStyleUnit_Enumerated) { if (maxISize.ConvertsToLength() || unit == eStyleUnit_Enumerated) {
nscoord c = nscoord c = aFrame->ComputeISizeValue(aRenderingContext,
nsLayoutUtils::ComputeISizeValue(aRenderingContext, aFrame, 0, 0, 0, maxISize);
0, 0, 0, maxISize);
minCoord = std::min(c, minCoord); minCoord = std::min(c, minCoord);
prefCoord = std::min(c, prefCoord); prefCoord = std::min(c, prefCoord);
} else if (unit == eStyleUnit_Percent) { } else if (unit == eStyleUnit_Percent) {
@ -217,9 +215,8 @@ GetISizeInfo(nsRenderingContext *aRenderingContext,
} }
unit = minISize.GetUnit(); unit = minISize.GetUnit();
if (minISize.ConvertsToLength() || unit == eStyleUnit_Enumerated) { if (minISize.ConvertsToLength() || unit == eStyleUnit_Enumerated) {
nscoord c = nscoord c = aFrame->ComputeISizeValue(aRenderingContext,
nsLayoutUtils::ComputeISizeValue(aRenderingContext, aFrame, 0, 0, 0, minISize);
0, 0, 0, minISize);
minCoord = std::max(c, minCoord); minCoord = std::max(c, minCoord);
prefCoord = std::max(c, prefCoord); prefCoord = std::max(c, prefCoord);
} else if (unit == eStyleUnit_Percent) { } else if (unit == eStyleUnit_Percent) {

View File

@ -69,9 +69,8 @@ FixedTableLayoutStrategy::GetMinISize(nsRenderingContext* aRenderingContext)
nscoord spacing = mTableFrame->GetColSpacing(col); nscoord spacing = mTableFrame->GetColSpacing(col);
const nsStyleCoord *styleISize = &colFrame->StylePosition()->ISize(wm); const nsStyleCoord *styleISize = &colFrame->StylePosition()->ISize(wm);
if (styleISize->ConvertsToLength()) { if (styleISize->ConvertsToLength()) {
result += nsLayoutUtils::ComputeISizeValue(aRenderingContext, result += colFrame->ComputeISizeValue(aRenderingContext,
colFrame, 0, 0, 0, 0, 0, 0, *styleISize);
*styleISize);
} else if (styleISize->GetUnit() == eStyleUnit_Percent) { } else if (styleISize->GetUnit() == eStyleUnit_Percent) {
// do nothing // do nothing
} else { } else {
@ -213,9 +212,8 @@ FixedTableLayoutStrategy::ComputeColumnISizes(const ReflowInput& aReflowInput)
const nsStyleCoord *styleISize = &colFrame->StylePosition()->ISize(wm); const nsStyleCoord *styleISize = &colFrame->StylePosition()->ISize(wm);
nscoord colISize; nscoord colISize;
if (styleISize->ConvertsToLength()) { if (styleISize->ConvertsToLength()) {
colISize = nsLayoutUtils::ComputeISizeValue(aReflowInput.mRenderingContext, colISize = colFrame->ComputeISizeValue(aReflowInput.mRenderingContext,
colFrame, 0, 0, 0, 0, 0, 0, *styleISize);
*styleISize);
specTotal += colISize; specTotal += colISize;
} else if (styleISize->GetUnit() == eStyleUnit_Percent) { } else if (styleISize->GetUnit() == eStyleUnit_Percent) {
float pct = styleISize->GetPercentValue(); float pct = styleISize->GetPercentValue();