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;
}
/* 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
nsLayoutUtils::ComputeBSizeDependentValue(
nscoord aContainingBlockBSize,

View File

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

View File

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

View File

@ -41,6 +41,7 @@
#include "mozilla/Sprintf.h"
#include "nsFrameManager.h"
#include "nsLayoutUtils.h"
#include "LayoutLogging.h"
#include "mozilla/RestyleManager.h"
#include "mozilla/RestyleManagerHandle.h"
#include "mozilla/RestyleManagerHandleInlines.h"
@ -4710,9 +4711,9 @@ nsFrame::ComputeSize(nsRenderingContext* aRenderingContext,
if (inlineStyleCoord->GetUnit() != eStyleUnit_Auto) {
result.ISize(aWM) =
nsLayoutUtils::ComputeISizeValue(aRenderingContext, this,
aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize,
*inlineStyleCoord);
ComputeISizeValue(aRenderingContext, aCBSize.ISize(aWM),
boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize,
*inlineStyleCoord);
}
// Flex items ignore their min & max sizing properties in their
@ -4723,9 +4724,9 @@ nsFrame::ComputeSize(nsRenderingContext* aRenderingContext,
if (maxISizeCoord.GetUnit() != eStyleUnit_None &&
!(isFlexItem && isInlineFlexItem)) {
maxISize =
nsLayoutUtils::ComputeISizeValue(aRenderingContext, this,
aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize,
maxISizeCoord);
ComputeISizeValue(aRenderingContext, aCBSize.ISize(aWM),
boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize,
maxISizeCoord);
result.ISize(aWM) = std::min(maxISize, result.ISize(aWM));
}
@ -4734,9 +4735,9 @@ nsFrame::ComputeSize(nsRenderingContext* aRenderingContext,
if (minISizeCoord.GetUnit() != eStyleUnit_Auto &&
!(isFlexItem && isInlineFlexItem)) {
minISize =
nsLayoutUtils::ComputeISizeValue(aRenderingContext, this,
aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize,
minISizeCoord);
ComputeISizeValue(aRenderingContext, aCBSize.ISize(aWM),
boxSizingAdjust.ISize(aWM), boxSizingToMarginEdgeISize,
minISizeCoord);
} else if (MOZ_UNLIKELY(isGridItem)) {
// This implements "Implied Minimum Size of Grid Items".
// https://drafts.csswg.org/css-grid/#min-size-auto
@ -4961,8 +4962,8 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
bool stretchB = false;
if (!isAutoISize) {
iSize = nsLayoutUtils::ComputeISizeValue(aRenderingContext,
this, aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
iSize = ComputeISizeValue(aRenderingContext,
aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
boxSizingToMarginEdgeISize, *inlineStyleCoord);
} else if (MOZ_UNLIKELY(isGridItem)) {
MOZ_ASSERT(!IS_TRUE_OVERFLOW_CONTAINER(this));
@ -4995,8 +4996,8 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
if (maxISizeCoord.GetUnit() != eStyleUnit_None &&
!(isFlexItem && isInlineFlexItem)) {
maxISize = nsLayoutUtils::ComputeISizeValue(aRenderingContext,
this, aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
maxISize = ComputeISizeValue(aRenderingContext,
aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
boxSizingToMarginEdgeISize, maxISizeCoord);
} else {
maxISize = nscoord_MAX;
@ -5010,8 +5011,8 @@ nsFrame::ComputeSizeWithIntrinsicDimensions(nsRenderingContext* aRenderingConte
if (minISizeCoord.GetUnit() != eStyleUnit_Auto &&
!(isFlexItem && isInlineFlexItem)) {
minISize = nsLayoutUtils::ComputeISizeValue(aRenderingContext,
this, aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
minISize = ComputeISizeValue(aRenderingContext,
aCBSize.ISize(aWM), boxSizingAdjust.ISize(aWM),
boxSizingToMarginEdgeISize, minISizeCoord);
} else {
// Treat "min-width: auto" as 0.
@ -5324,6 +5325,64 @@ nsFrame::ShrinkWidthToFit(nsRenderingContext* aRenderingContext,
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
nsFrame::DidReflow(nsPresContext* aPresContext,
const ReflowInput* aReflowInput,

View File

@ -3377,6 +3377,14 @@ public:
int32_t aIncrement,
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:
// Members
nsRect mRect;

View File

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

View File

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