Delete nsLayoutUtils::GetAbsoluteCoord(); fold logic into callers and simplify. (Bug 437335) r+sr=dbaron

This commit is contained in:
Zack Weinberg 2008-07-17 16:37:12 -07:00
Родитель 2cf6d4a1cd
Коммит d8e5c0aeb0
12 изменённых файлов: 186 добавлений и 295 удалений

Просмотреть файл

@ -1493,9 +1493,17 @@ static nscoord AddPercents(nsLayoutUtils::IntrinsicWidthType aType,
return result;
}
static PRBool GetAbsoluteCoord(const nsStyleCoord& aStyle, nscoord& aResult)
{
if (eStyleUnit_Coord != aStyle.GetUnit())
return PR_FALSE;
aResult = aStyle.GetCoordValue();
return PR_TRUE;
}
static PRBool
GetPercentHeight(const nsStyleCoord& aStyle,
nsIRenderingContext* aRenderingContext,
nsIFrame* aFrame,
nscoord& aResult)
{
@ -1513,9 +1521,8 @@ GetPercentHeight(const nsStyleCoord& aStyle,
const nsStylePosition *pos = f->GetStylePosition();
nscoord h;
if (!nsLayoutUtils::
GetAbsoluteCoord(pos->mHeight, aRenderingContext, f, h) &&
!GetPercentHeight(pos->mHeight, aRenderingContext, f, h)) {
if (!GetAbsoluteCoord(pos->mHeight, h) &&
!GetPercentHeight(pos->mHeight, f, h)) {
NS_ASSERTION(pos->mHeight.GetUnit() == eStyleUnit_Auto ||
pos->mHeight.GetUnit() == eStyleUnit_Percent,
"unknown height unit");
@ -1528,9 +1535,8 @@ GetPercentHeight(const nsStyleCoord& aStyle,
}
nscoord maxh;
if (nsLayoutUtils::
GetAbsoluteCoord(pos->mMaxHeight, aRenderingContext, f, maxh) ||
GetPercentHeight(pos->mMaxHeight, aRenderingContext, f, maxh)) {
if (GetAbsoluteCoord(pos->mMaxHeight, maxh) ||
GetPercentHeight(pos->mMaxHeight, f, maxh)) {
if (maxh < h)
h = maxh;
} else {
@ -1540,9 +1546,8 @@ GetPercentHeight(const nsStyleCoord& aStyle,
}
nscoord minh;
if (nsLayoutUtils::
GetAbsoluteCoord(pos->mMinHeight, aRenderingContext, f, minh) ||
GetPercentHeight(pos->mMinHeight, aRenderingContext, f, minh)) {
if (GetAbsoluteCoord(pos->mMinHeight, minh) ||
GetPercentHeight(pos->mMinHeight, f, minh)) {
if (minh > h)
h = minh;
} else {
@ -1686,21 +1691,21 @@ nsLayoutUtils::IntrinsicForContainer(nsIRenderingContext *aRenderingContext,
if (ratio.height != 0) {
nscoord h;
if (GetAbsoluteCoord(styleHeight, aRenderingContext, aFrame, h) ||
GetPercentHeight(styleHeight, aRenderingContext, aFrame, h)) {
if (GetAbsoluteCoord(styleHeight, h) ||
GetPercentHeight(styleHeight, aFrame, h)) {
result =
NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
}
if (GetAbsoluteCoord(styleMaxHeight, aRenderingContext, aFrame, h) ||
GetPercentHeight(styleMaxHeight, aRenderingContext, aFrame, h)) {
if (GetAbsoluteCoord(styleMaxHeight, h) ||
GetPercentHeight(styleMaxHeight, aFrame, h)) {
h = NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
if (h < result)
result = h;
}
if (GetAbsoluteCoord(styleMinHeight, aRenderingContext, aFrame, h) ||
GetPercentHeight(styleMinHeight, aRenderingContext, aFrame, h)) {
if (GetAbsoluteCoord(styleMinHeight, h) ||
GetPercentHeight(styleMinHeight, aFrame, h)) {
h = NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
if (h > result)
result = h;
@ -1755,7 +1760,7 @@ nsLayoutUtils::IntrinsicForContainer(nsIRenderingContext *aRenderingContext,
pctTotal += pctOutsideWidth;
nscoord w;
if (GetAbsoluteCoord(styleWidth, aRenderingContext, aFrame, w) ||
if (GetAbsoluteCoord(styleWidth, w) ||
GetIntrinsicCoord(styleWidth, aRenderingContext, aFrame,
PROP_WIDTH, w)) {
result = AddPercents(aType, w + coordOutsideWidth, pctOutsideWidth);
@ -1770,7 +1775,7 @@ nsLayoutUtils::IntrinsicForContainer(nsIRenderingContext *aRenderingContext,
}
nscoord maxw;
if (GetAbsoluteCoord(styleMaxWidth, aRenderingContext, aFrame, maxw) ||
if (GetAbsoluteCoord(styleMaxWidth, maxw) ||
GetIntrinsicCoord(styleMaxWidth, aRenderingContext, aFrame,
PROP_MAX_WIDTH, maxw)) {
maxw = AddPercents(aType, maxw + coordOutsideWidth, pctOutsideWidth);
@ -1779,7 +1784,7 @@ nsLayoutUtils::IntrinsicForContainer(nsIRenderingContext *aRenderingContext,
}
nscoord minw;
if (GetAbsoluteCoord(styleMinWidth, aRenderingContext, aFrame, minw) ||
if (GetAbsoluteCoord(styleMinWidth, minw) ||
GetIntrinsicCoord(styleMinWidth, aRenderingContext, aFrame,
PROP_MIN_WIDTH, minw)) {
minw = AddPercents(aType, minw + coordOutsideWidth, pctOutsideWidth);
@ -1822,19 +1827,15 @@ nsLayoutUtils::IntrinsicForContainer(nsIRenderingContext *aRenderingContext,
/* static */ nscoord
nsLayoutUtils::ComputeWidthDependentValue(
nsIRenderingContext* aRenderingContext,
nsIFrame* aFrame,
nscoord aContainingBlockWidth,
const nsStyleCoord& aCoord)
{
NS_PRECONDITION(aFrame, "non-null frame expected");
NS_PRECONDITION(aRenderingContext, "non-null rendering context expected");
NS_PRECONDITION(aContainingBlockWidth != NS_UNCONSTRAINEDSIZE,
"unconstrained widths no longer supported");
nscoord result;
if (GetAbsoluteCoord(aCoord, aRenderingContext, aFrame, result)) {
return result;
if (eStyleUnit_Coord == aCoord.GetUnit()) {
return aCoord.GetCoordValue();
}
if (eStyleUnit_Percent == aCoord.GetUnit()) {
return NSToCoordFloor(aContainingBlockWidth * aCoord.GetPercentValue());
@ -1862,7 +1863,8 @@ nsLayoutUtils::ComputeWidthValue(
"width less than zero");
nscoord result;
if (GetAbsoluteCoord(aCoord, aRenderingContext, aFrame, result)) {
if (eStyleUnit_Coord == aCoord.GetUnit()) {
result = aCoord.GetCoordValue();
NS_ASSERTION(result >= 0, "width less than zero");
result -= aContentEdgeToBoxSizing;
} else if (eStyleUnit_Percent == aCoord.GetUnit()) {
@ -1906,17 +1908,12 @@ nsLayoutUtils::ComputeWidthValue(
/* static */ nscoord
nsLayoutUtils::ComputeHeightDependentValue(
nsIRenderingContext* aRenderingContext,
nsIFrame* aFrame,
nscoord aContainingBlockHeight,
const nsStyleCoord& aCoord)
{
NS_PRECONDITION(aFrame, "non-null frame expected");
NS_PRECONDITION(aRenderingContext, "non-null rendering context expected");
nscoord result;
if (GetAbsoluteCoord(aCoord, aRenderingContext, aFrame, result)) {
return result;
if (eStyleUnit_Coord == aCoord.GetUnit()) {
return aCoord.GetCoordValue();
}
if (eStyleUnit_Percent == aCoord.GetUnit()) {
// XXXldb Some callers explicitly check aContainingBlockHeight
@ -2005,16 +2002,16 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
NS_ASSERTION(minWidth >= 0, "negative result from ComputeWidthValue");
if (!isAutoHeight) {
height = nsLayoutUtils::ComputeHeightDependentValue(aRenderingContext,
aFrame, aCBSize.height, stylePos->mHeight) -
height = nsLayoutUtils::
ComputeHeightDependentValue(aCBSize.height, stylePos->mHeight) -
boxSizingAdjust.height;
if (height < 0)
height = 0;
}
if (!IsAutoHeight(stylePos->mMaxHeight, aCBSize.height)) {
maxHeight = nsLayoutUtils::ComputeHeightDependentValue(aRenderingContext,
aFrame, aCBSize.height, stylePos->mMaxHeight) -
maxHeight = nsLayoutUtils::
ComputeHeightDependentValue(aCBSize.height, stylePos->mMaxHeight) -
boxSizingAdjust.height;
if (maxHeight < 0)
maxHeight = 0;
@ -2023,8 +2020,8 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
}
if (!IsAutoHeight(stylePos->mMinHeight, aCBSize.height)) {
minHeight = nsLayoutUtils::ComputeHeightDependentValue(aRenderingContext,
aFrame, aCBSize.height, stylePos->mMinHeight) -
minHeight = nsLayoutUtils::
ComputeHeightDependentValue(aCBSize.height, stylePos->mMinHeight) -
boxSizingAdjust.height;
if (minHeight < 0)
minHeight = 0;
@ -2055,9 +2052,8 @@ nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
(aIntrinsicSize.height.GetUnit() == eStyleUnit_Percent &&
aCBSize.height != NS_AUTOHEIGHT)) {
hasIntrinsicHeight = PR_TRUE;
intrinsicHeight = nsLayoutUtils::ComputeHeightDependentValue(
aRenderingContext, aFrame, aCBSize.height,
aIntrinsicSize.height);
intrinsicHeight = nsLayoutUtils::
ComputeHeightDependentValue(aCBSize.height, aIntrinsicSize.height);
if (intrinsicHeight < 0)
intrinsicHeight = 0;
} else {

Просмотреть файл

@ -582,40 +582,6 @@ public:
*/
static PRBool IsViewportScrollbarFrame(nsIFrame* aFrame);
/**
* Return the value of aStyle as an nscoord if it can be determined without
* reference to ancestors or children (e.g. is not a percentage width)
* @param aStyle the style coord
* @param aRenderingContext the rendering context to use for font measurement
* @param aFrame the frame whose style context should be used for font information
* @param aResult the nscoord value of the style coord
* @return TRUE if the unit is eStyleUnit_Coord
*/
static PRBool GetAbsoluteCoord(const nsStyleCoord& aStyle,
nsIRenderingContext* aRenderingContext,
nsIFrame* aFrame,
nscoord& aResult)
{
return GetAbsoluteCoord(aStyle, aRenderingContext,
aFrame->GetStyleContext(), aResult);
}
/**
* Same as above but doesn't need a frame
*/
static PRBool GetAbsoluteCoord(const nsStyleCoord& aStyle,
nsIRenderingContext* aRenderingContext,
nsStyleContext* aStyleContext,
nscoord& aResult)
{
nsStyleUnit unit = aStyle.GetUnit();
if (eStyleUnit_Coord == unit) {
aResult = aStyle.GetCoordValue();
return PR_TRUE;
}
return PR_FALSE;
}
/**
* Get the contribution of aFrame to its containing block's intrinsic
* width. This considers the child's intrinsic width, its 'width',
@ -632,8 +598,6 @@ public:
* containing block width.
*/
static nscoord ComputeWidthDependentValue(
nsIRenderingContext* aRenderingContext,
nsIFrame* aFrame,
nscoord aContainingBlockWidth,
const nsStyleCoord& aCoord);
@ -667,8 +631,6 @@ public:
* containing block height.
*/
static nscoord ComputeHeightDependentValue(
nsIRenderingContext* aRenderingContext,
nsIFrame* aFrame,
nscoord aContainingBlockHeight,
const nsStyleCoord& aCoord);

Просмотреть файл

@ -1310,8 +1310,7 @@ nsTextControlFrame::CalcIntrinsicSize(nsIRenderingContext* aRenderingContext,
NS_ENSURE_SUCCESS(rv, rv);
aRenderingContext->SetFont(fontMet);
lineHeight = nsHTMLReflowState::CalcLineHeight(aRenderingContext,
this);
lineHeight = nsHTMLReflowState::CalcLineHeight(this);
fontMet->GetAveCharWidth(charWidth);
fontMet->GetMaxAdvance(charMaxAdvance);

Просмотреть файл

@ -150,8 +150,7 @@ BRFrame::Reflow(nsPresContext* aPresContext,
nscoord ascent, descent;
fm->GetMaxAscent(ascent);
fm->GetMaxDescent(descent);
nscoord logicalHeight =
aReflowState.CalcLineHeight(aReflowState.rendContext, this);
nscoord logicalHeight = aReflowState.CalcLineHeight(this);
nscoord leading = logicalHeight - ascent - descent;
aMetrics.height = logicalHeight;
aMetrics.ascent = ascent + (leading/2);

Просмотреть файл

@ -139,8 +139,7 @@ nsBlockReflowState::nsBlockReflowState(const nsHTMLReflowState& aReflowState,
mPrevChild = nsnull;
mCurrentLine = aFrame->end_lines();
mMinLineHeight = nsHTMLReflowState::CalcLineHeight(aReflowState.rendContext,
aReflowState.frame);
mMinLineHeight = nsHTMLReflowState::CalcLineHeight(aReflowState.frame);
// Calculate mOutsideBulletX
GetAvailableSpace();

Просмотреть файл

@ -229,15 +229,12 @@ GetAvailableContentHeight(const nsHTMLReflowState& aReflowState)
static nscoord
GetColumnGap(nsColumnSetFrame* aFrame,
const nsStyleColumn* aColStyle,
nsIRenderingContext* aRenderingContext)
const nsStyleColumn* aColStyle)
{
nscoord colGap;
if (eStyleUnit_Normal == aColStyle->mColumnGap.GetUnit())
return aFrame->GetStyleFont()->mFont.size;
else if (nsLayoutUtils::GetAbsoluteCoord(aColStyle->mColumnGap,
aRenderingContext,
aFrame, colGap)) {
if (eStyleUnit_Coord == aColStyle->mColumnGap.GetUnit()) {
nscoord colGap = aColStyle->mColumnGap.GetCoordValue();
NS_ASSERTION(colGap >= 0, "negative column gap");
return colGap;
}
@ -259,13 +256,12 @@ nsColumnSetFrame::ChooseColumnStrategy(const nsHTMLReflowState& aReflowState)
colHeight = aReflowState.ComputedHeight();
}
nscoord colGap = GetColumnGap(this, colStyle, aReflowState.rendContext);
nscoord colGap = GetColumnGap(this, colStyle);
PRInt32 numColumns = colStyle->mColumnCount;
nscoord colWidth;
if (nsLayoutUtils::GetAbsoluteCoord(colStyle->mColumnWidth,
aReflowState.rendContext,
this, colWidth)) {
if (colStyle->mColumnWidth.GetUnit() == eStyleUnit_Coord) {
colWidth = colStyle->mColumnWidth.GetCoordValue();
NS_ASSERTION(colWidth >= 0, "negative column width");
// Reduce column count if necessary to make columns fit in the
// available width. Compute max number of columns that fit in
@ -371,16 +367,17 @@ nsColumnSetFrame::GetMinWidth(nsIRenderingContext *aRenderingContext) {
}
const nsStyleColumn* colStyle = GetStyleColumn();
nscoord colWidth;
if (nsLayoutUtils::GetAbsoluteCoord(colStyle->mColumnWidth,
aRenderingContext, this, colWidth)) {
// As available width reduces to zero, we reduce our number of columns to one,
// and don't enforce the column width, so just return the min of the
// child's min-width with any specified column width.
if (colStyle->mColumnWidth.GetUnit() == eStyleUnit_Coord) {
colWidth = colStyle->mColumnWidth.GetCoordValue();
// As available width reduces to zero, we reduce our number of columns
// to one, and don't enforce the column width, so just return the min
// of the child's min-width with any specified column width.
width = PR_MIN(width, colWidth);
} else {
NS_ASSERTION(colStyle->mColumnCount > 0, "column-count and column-width can't both be auto");
// As available width reduces to zero, we still have mColumnCount columns, so
// multiply the child's min-width by the number of columns.
NS_ASSERTION(colStyle->mColumnCount > 0,
"column-count and column-width can't both be auto");
// As available width reduces to zero, we still have mColumnCount columns,
// so multiply the child's min-width by the number of columns.
colWidth = width;
width *= colStyle->mColumnCount;
// The multiplication above can make 'width' negative (integer overflow),
@ -394,22 +391,21 @@ nsColumnSetFrame::GetMinWidth(nsIRenderingContext *aRenderingContext) {
nscoord
nsColumnSetFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext) {
// Our preferred width is our desired column width, if specified, otherwise the
// child's preferred width, times the number of columns, plus the width of any
// required column gaps
// Our preferred width is our desired column width, if specified, otherwise
// the child's preferred width, times the number of columns, plus the width
// of any required column gaps
// XXX what about forced column breaks here?
const nsStyleColumn* colStyle = GetStyleColumn();
nscoord colGap = GetColumnGap(this, colStyle, aRenderingContext);
nscoord colGap = GetColumnGap(this, colStyle);
nscoord colWidth;
if (!nsLayoutUtils::GetAbsoluteCoord(colStyle->mColumnWidth,
aRenderingContext, this, colWidth)) {
if (mFrames.FirstChild()) {
if (colStyle->mColumnWidth.GetUnit() == eStyleUnit_Coord) {
colWidth = colStyle->mColumnWidth.GetCoordValue();
} else if (mFrames.FirstChild()) {
colWidth = mFrames.FirstChild()->GetPrefWidth(aRenderingContext);
} else {
colWidth = 0;
}
}
PRInt32 numColumns = colStyle->mColumnCount;
if (numColumns <= 0) {

Просмотреть файл

@ -3086,16 +3086,16 @@ nsFrame::ComputeSize(nsIRenderingContext *aRenderingContext,
if (!IsAutoHeight(stylePos->mHeight, aCBSize.height)) {
result.height =
nsLayoutUtils::ComputeHeightDependentValue(aRenderingContext, this,
aCBSize.height, stylePos->mHeight) -
nsLayoutUtils::ComputeHeightDependentValue(aCBSize.height,
stylePos->mHeight) -
boxSizingAdjust.height;
}
if (result.height != NS_UNCONSTRAINEDSIZE) {
if (!IsAutoHeight(stylePos->mMaxHeight, aCBSize.height)) {
nscoord maxHeight =
nsLayoutUtils::ComputeHeightDependentValue(aRenderingContext, this,
aCBSize.height, stylePos->mMaxHeight) -
nsLayoutUtils::ComputeHeightDependentValue(aCBSize.height,
stylePos->mMaxHeight) -
boxSizingAdjust.height;
if (maxHeight < result.height)
result.height = maxHeight;
@ -3103,8 +3103,8 @@ nsFrame::ComputeSize(nsIRenderingContext *aRenderingContext,
if (!IsAutoHeight(stylePos->mMinHeight, aCBSize.height)) {
nscoord minHeight =
nsLayoutUtils::ComputeHeightDependentValue(aRenderingContext, this,
aCBSize.height, stylePos->mMinHeight) -
nsLayoutUtils::ComputeHeightDependentValue(aCBSize.height,
stylePos->mMinHeight) -
boxSizingAdjust.height;
if (minHeight > result.height)
result.height = minHeight;

Просмотреть файл

@ -178,16 +178,6 @@ nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
}
}
inline void
nsCSSOffsetState::ComputeWidthDependentValue(nscoord aContainingBlockWidth,
const nsStyleCoord& aCoord,
nscoord& aResult)
{
aResult = nsLayoutUtils::ComputeWidthDependentValue(rendContext, frame,
aContainingBlockWidth,
aCoord);
}
inline nscoord
nsCSSOffsetState::ComputeWidthValue(nscoord aContainingBlockWidth,
nscoord aContentEdgeToBoxSizing,
@ -222,16 +212,6 @@ nsCSSOffsetState::ComputeWidthValue(nscoord aContainingBlockWidth,
outside, aCoord);
}
inline void
nsCSSOffsetState::ComputeHeightDependentValue(nscoord aContainingBlockHeight,
const nsStyleCoord& aCoord,
nscoord& aResult)
{
aResult = nsLayoutUtils::ComputeHeightDependentValue(rendContext, frame,
aContainingBlockHeight,
aCoord);
}
void
nsHTMLReflowState::SetComputedWidth(nscoord aComputedWidth)
{
@ -635,9 +615,9 @@ nsHTMLReflowState::ComputeRelativeOffsets(const nsHTMLReflowState* cbrs,
mComputedOffsets.left = mComputedOffsets.right = 0;
} else {
// 'Right' isn't 'auto' so compute its value
mComputedOffsets.right = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
mStylePosition->mOffset.GetRight(),
mComputedOffsets.right);
mStylePosition->mOffset.GetRight());
// Computed value for 'left' is minus the value of 'right'
mComputedOffsets.left = -mComputedOffsets.right;
@ -647,9 +627,9 @@ nsHTMLReflowState::ComputeRelativeOffsets(const nsHTMLReflowState* cbrs,
NS_ASSERTION(rightIsAuto, "unexpected specified constraint");
// 'Left' isn't 'auto' so compute its value
mComputedOffsets.left = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
mStylePosition->mOffset.GetLeft(),
mComputedOffsets.left);
mStylePosition->mOffset.GetLeft());
// Computed value for 'right' is minus the value of 'left'
mComputedOffsets.right = -mComputedOffsets.left;
@ -683,9 +663,9 @@ nsHTMLReflowState::ComputeRelativeOffsets(const nsHTMLReflowState* cbrs,
mComputedOffsets.top = mComputedOffsets.bottom = 0;
} else {
// 'Bottom' isn't 'auto' so compute its value
mComputedOffsets.bottom = nsLayoutUtils::
ComputeHeightDependentValue(aContainingBlockHeight,
mStylePosition->mOffset.GetBottom(),
mComputedOffsets.bottom);
mStylePosition->mOffset.GetBottom());
// Computed value for 'top' is minus the value of 'bottom'
mComputedOffsets.top = -mComputedOffsets.bottom;
@ -695,9 +675,9 @@ nsHTMLReflowState::ComputeRelativeOffsets(const nsHTMLReflowState* cbrs,
NS_ASSERTION(bottomIsAuto, "unexpected specified constraint");
// 'Top' isn't 'auto' so compute its value
mComputedOffsets.top = nsLayoutUtils::
ComputeHeightDependentValue(aContainingBlockHeight,
mStylePosition->mOffset.GetTop(),
mComputedOffsets.top);
mStylePosition->mOffset.GetTop());
// Computed value for 'bottom' is minus the value of 'top'
mComputedOffsets.bottom = -mComputedOffsets.top;
@ -817,12 +797,12 @@ nsHTMLReflowState::CalculateHorizBorderPaddingMargin(
// See if the style system can provide us the padding directly
if (!mStylePadding->GetPadding(padding)) {
// We have to compute the left and right values
padding.left = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
mStylePadding->mPadding.GetLeft(),
padding.left);
mStylePadding->mPadding.GetLeft());
padding.right = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
mStylePadding->mPadding.GetRight(),
padding.right);
mStylePadding->mPadding.GetRight());
}
// See if the style system can provide us the margin directly
@ -832,17 +812,17 @@ nsHTMLReflowState::CalculateHorizBorderPaddingMargin(
// XXX FIXME (or does CalculateBlockSideMargins do this?)
margin.left = 0; // just ignore
} else {
margin.left = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
mStyleMargin->mMargin.GetLeft(),
margin.left);
mStyleMargin->mMargin.GetLeft());
}
if (eStyleUnit_Auto == mStyleMargin->mMargin.GetRightUnit()) {
// XXX FIXME (or does CalculateBlockSideMargins do this?)
margin.right = 0; // just ignore
} else {
margin.right = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
mStyleMargin->mMargin.GetRight(),
margin.right);
mStyleMargin->mMargin.GetRight());
}
}
@ -1156,17 +1136,17 @@ nsHTMLReflowState::InitAbsoluteConstraints(nsPresContext* aPresContext,
mComputedOffsets.left = 0;
leftIsAuto = PR_TRUE;
} else {
mComputedOffsets.left = nsLayoutUtils::
ComputeWidthDependentValue(containingBlockWidth,
mStylePosition->mOffset.GetLeft(),
mComputedOffsets.left);
mStylePosition->mOffset.GetLeft());
}
if (eStyleUnit_Auto == mStylePosition->mOffset.GetRightUnit()) {
mComputedOffsets.right = 0;
rightIsAuto = PR_TRUE;
} else {
mComputedOffsets.right = nsLayoutUtils::
ComputeWidthDependentValue(containingBlockWidth,
mStylePosition->mOffset.GetRight(),
mComputedOffsets.right);
mStylePosition->mOffset.GetRight());
}
// Use the horizontal component of the hypothetical box in the cases
@ -1193,17 +1173,17 @@ nsHTMLReflowState::InitAbsoluteConstraints(nsPresContext* aPresContext,
mComputedOffsets.top = 0;
topIsAuto = PR_TRUE;
} else {
mComputedOffsets.top = nsLayoutUtils::
ComputeHeightDependentValue(containingBlockHeight,
mStylePosition->mOffset.GetTop(),
mComputedOffsets.top);
mStylePosition->mOffset.GetTop());
}
if (eStyleUnit_Auto == mStylePosition->mOffset.GetBottomUnit()) {
mComputedOffsets.bottom = 0;
bottomIsAuto = PR_TRUE;
} else {
mComputedOffsets.bottom = nsLayoutUtils::
ComputeHeightDependentValue(containingBlockHeight,
mStylePosition->mOffset.GetBottom(),
mComputedOffsets.bottom);
mStylePosition->mOffset.GetBottom());
}
if (topIsAuto && bottomIsAuto) {
@ -1802,9 +1782,9 @@ nsHTMLReflowState::InitConstraints(nsPresContext* aPresContext,
} else {
NS_ASSERTION(heightUnit == mStylePosition->mHeight.GetUnit(),
"unexpected height unit change");
mComputedHeight = nsLayoutUtils::
ComputeHeightDependentValue(aContainingBlockHeight,
mStylePosition->mHeight,
mComputedHeight);
mStylePosition->mHeight);
}
// Doesn't apply to table elements
@ -2050,43 +2030,35 @@ GetNormalLineHeight(nsIFontMetrics* aFontMetrics)
return normalLineHeight;
}
// Need only one of aRenderingContext and aDeviceContext
static nscoord
ComputeLineHeight(nsIRenderingContext* aRenderingContext,
nsStyleContext* aStyleContext)
ComputeLineHeight(nsStyleContext* aStyleContext)
{
nscoord lineHeight;
const nsStyleCoord& lhCoord = aStyleContext->GetStyleText()->mLineHeight;
if (!nsLayoutUtils::GetAbsoluteCoord(lhCoord, aRenderingContext,
aStyleContext, lineHeight)) {
const nsStyleFont* font = aStyleContext->GetStyleFont();
if (lhCoord.GetUnit() == eStyleUnit_Factor) {
if (lhCoord.GetUnit() == eStyleUnit_Coord)
return lhCoord.GetCoordValue();
if (lhCoord.GetUnit() == eStyleUnit_Factor)
// For factor units the computed value of the line-height property
// is found by multiplying the factor by the font's computed size
// (adjusted for min-size prefs and text zoom).
float factor = lhCoord.GetFactorValue();
lineHeight = NSToCoordRound(factor * font->mFont.size);
} else {
return NSToCoordRound(lhCoord.GetFactorValue() *
aStyleContext->GetStyleFont()->mFont.size);
NS_ASSERTION(eStyleUnit_Normal == lhCoord.GetUnit(), "bad unit");
nsCOMPtr<nsIFontMetrics> fm;
nsLayoutUtils::GetFontMetricsForStyleContext(aStyleContext,
getter_AddRefs(fm));
lineHeight = GetNormalLineHeight(fm);
}
}
return lineHeight;
return GetNormalLineHeight(fm);
}
nscoord
nsHTMLReflowState::CalcLineHeight(nsIRenderingContext* aRenderingContext,
nsStyleContext* aStyleContext)
nsHTMLReflowState::CalcLineHeight(nsStyleContext* aStyleContext)
{
NS_PRECONDITION(aRenderingContext, "Must have a rendering context");
NS_PRECONDITION(aStyleContext, "Must have a style context");
nscoord lineHeight = ComputeLineHeight(aRenderingContext, aStyleContext);
nscoord lineHeight = ComputeLineHeight(aStyleContext);
NS_ASSERTION(lineHeight >= 0, "ComputeLineHeight screwed up");
@ -2122,24 +2094,24 @@ nsCSSOffsetState::ComputeMargin(nscoord aContainingBlockWidth)
}
} else {
mComputedMargin.left = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
styleMargin->mMargin.GetLeft(),
mComputedMargin.left);
styleMargin->mMargin.GetLeft());
mComputedMargin.right = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
styleMargin->mMargin.GetRight(),
mComputedMargin.right);
styleMargin->mMargin.GetRight());
}
// According to the CSS2 spec, margin percentages are
// calculated with respect to the *width* of the containing
// block, even for margin-top and margin-bottom.
// XXX This isn't true for page boxes, if we implement them.
mComputedMargin.top = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
styleMargin->mMargin.GetTop(),
mComputedMargin.top);
styleMargin->mMargin.GetTop());
mComputedMargin.bottom = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
styleMargin->mMargin.GetBottom(),
mComputedMargin.bottom);
styleMargin->mMargin.GetBottom());
// XXX We need to include 'auto' horizontal margins in this too!
// ... but if we did that, we'd need to fix nsFrame::GetUsedMargin
@ -2158,21 +2130,21 @@ nsCSSOffsetState::ComputePadding(nscoord aContainingBlockWidth)
const nsStylePadding *stylePadding = frame->GetStylePadding();
if (!stylePadding->GetPadding(mComputedPadding)) {
// We have to compute the value
mComputedPadding.left = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
stylePadding->mPadding.GetLeft(),
mComputedPadding.left);
stylePadding->mPadding.GetLeft());
mComputedPadding.right = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
stylePadding->mPadding.GetRight(),
mComputedPadding.right);
stylePadding->mPadding.GetRight());
// According to the CSS2 spec, percentages are calculated with respect to
// containing block width for padding-top and padding-bottom
mComputedPadding.top = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
stylePadding->mPadding.GetTop(),
mComputedPadding.top);
stylePadding->mPadding.GetTop());
mComputedPadding.bottom = nsLayoutUtils::
ComputeWidthDependentValue(aContainingBlockWidth,
stylePadding->mPadding.GetBottom(),
mComputedPadding.bottom);
stylePadding->mPadding.GetBottom());
frame->SetProperty(nsGkAtoms::usedPaddingProperty,
new nsMargin(mComputedPadding),
@ -2241,8 +2213,9 @@ nsHTMLReflowState::ComputeMinMaxValues(nscoord aContainingBlockWidth,
(eStyleUnit_Percent == mStylePosition->mMinHeight.GetUnit())) {
mComputedMinHeight = 0;
} else {
mComputedMinHeight = nsLayoutUtils::
ComputeHeightDependentValue(aContainingBlockHeight,
mStylePosition->mMinHeight, mComputedMinHeight);
mStylePosition->mMinHeight);
}
nsStyleUnit maxHeightUnit = mStylePosition->mMaxHeight.GetUnit();
if (eStyleUnit_None == maxHeightUnit) {
@ -2255,8 +2228,9 @@ nsHTMLReflowState::ComputeMinMaxValues(nscoord aContainingBlockWidth,
(eStyleUnit_Percent == maxHeightUnit)) {
mComputedMaxHeight = NS_UNCONSTRAINEDSIZE;
} else {
mComputedMaxHeight = nsLayoutUtils::
ComputeHeightDependentValue(aContainingBlockHeight,
mStylePosition->mMaxHeight, mComputedMaxHeight);
mStylePosition->mMaxHeight);
}
}

Просмотреть файл

@ -194,15 +194,6 @@ protected:
const nsMargin *aBorder = nsnull,
const nsMargin *aPadding = nsnull);
/*
* Convert nsStyleCoord to nscoord when percentages depend on the
* containing block width.
*/
// XXX Make aResult a return value
inline void ComputeWidthDependentValue(nscoord aContainingBlockWidth,
const nsStyleCoord& aCoord,
nscoord& aResult);
/*
* Convert nsStyleCoord to nscoord when percentages depend on the
* containing block width, and enumerated values are for width,
@ -217,15 +208,6 @@ protected:
nscoord ComputeWidthValue(nscoord aContainingBlockWidth,
PRUint8 aBoxSizing,
const nsStyleCoord& aCoord);
/*
* Convert nsStyleCoord to nscoord when percentages depend on the
* containing block height.
*/
// XXX Make aResult a return value
inline void ComputeHeightDependentValue(nscoord aContainingBlockHeight,
const nsStyleCoord& aCoord,
nscoord& aResult);
};
/**
@ -422,17 +404,15 @@ public:
* Calculate the raw line-height property for the given frame. The return
* value will be >= 0.
*/
static nscoord CalcLineHeight(nsIRenderingContext* aRenderingContext,
nsIFrame* aFrame)
static nscoord CalcLineHeight(nsIFrame* aFrame)
{
return CalcLineHeight(aRenderingContext, aFrame->GetStyleContext());
return CalcLineHeight(aFrame->GetStyleContext());
}
/**
* Same as above, but doesn't need a frame.
*/
static nscoord CalcLineHeight(nsIRenderingContext* aRenderingContext,
nsStyleContext* aStyleContext);
static nscoord CalcLineHeight(nsStyleContext* aStyleContext);
void ComputeContainingBlockRectangle(nsPresContext* aPresContext,

Просмотреть файл

@ -1666,7 +1666,7 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
// Compute the logical height for this span. The logical height
// is based on the line-height value, not the font-size. Also
// compute the top leading.
nscoord logicalHeight = nsHTMLReflowState::CalcLineHeight(rc, spanFrame);
nscoord logicalHeight = nsHTMLReflowState::CalcLineHeight(spanFrame);
nscoord contentHeight = spanFramePFD->mBounds.height -
spanFramePFD->mBorderPadding.top - spanFramePFD->mBorderPadding.bottom;
@ -1912,7 +1912,7 @@ nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
case eStyleUnit_Percent:
// Similar to a length value (eStyleUnit_Coord) except that the
// percentage is a function of the elements line-height value.
elementLineHeight = nsHTMLReflowState::CalcLineHeight(rc, frame);
elementLineHeight = nsHTMLReflowState::CalcLineHeight(frame);
percentOffset = nscoord(
textStyle->mVerticalAlign.GetPercentValue() * elementLineHeight
);

Просмотреть файл

@ -2955,19 +2955,7 @@ nsComputedDOMStyle::GetPaddingWidthFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
PRBool
nsComputedDOMStyle::GetLineHeightCoord(nscoord& aCoord)
{
// Get a rendering context
nsCOMPtr<nsIRenderingContext> cx;
nsIFrame* frame = mPresShell->FrameManager()->GetRootFrame();
if (frame) {
mPresShell->CreateRenderingContext(frame, getter_AddRefs(cx));
}
if (!cx) {
// Give up
aCoord = 0;
return PR_FALSE;
}
aCoord = nsHTMLReflowState::CalcLineHeight(cx, mStyleContextHolder);
aCoord = nsHTMLReflowState::CalcLineHeight(mStyleContextHolder);
// CalcLineHeight uses font->mFont.size, but we want to use
// font->mSize as the font size. Adjust for that. Also adjust for

Просмотреть файл

@ -664,20 +664,20 @@ nsIFrame::Redraw(nsBoxLayoutState& aState,
PRBool
nsIBox::AddCSSPrefSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize)
{
PRBool heightSet = PR_FALSE;
PRBool widthSet = PR_FALSE, heightSet = PR_FALSE;
// add in the css min, max, pref
const nsStylePosition* position = aBox->GetStylePosition();
// see if the width or height was specifically set
PRBool widthSet =
nsLayoutUtils::GetAbsoluteCoord(position->mWidth,
aState.GetRenderingContext(),
aBox, aSize.width);
// XXX Handle eStyleUnit_Enumerated?
// (Handling the eStyleUnit_Enumerated types requires
// GetPrefSize/GetMinSize methods that don't consider
// (min-/max-/)(width/height) properties.
// (min-/max-/)(width/height) properties.)
if (position->mWidth.GetUnit() == eStyleUnit_Coord) {
aSize.width = position->mWidth.GetCoordValue();
widthSet = PR_TRUE;
}
if (position->mHeight.GetUnit() == eStyleUnit_Coord) {
aSize.height = position->mHeight.GetCoordValue();
@ -750,10 +750,8 @@ nsIBox::AddCSSMinSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize)
// same for min size. Unfortunately min size is always set to 0. So for now
// we will assume 0 means not set.
nscoord min;
if (nsLayoutUtils::GetAbsoluteCoord(position->mMinWidth,
aState.GetRenderingContext(),
aBox, min)) {
if (position->mMinWidth.GetUnit() == eStyleUnit_Coord) {
nscoord min = position->mMinWidth.GetCoordValue();
if (min && (!widthSet || (min > aSize.width && canOverride))) {
aSize.width = min;
widthSet = PR_TRUE;
@ -819,24 +817,24 @@ nsIBox::AddCSSMinSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize)
PRBool
nsIBox::AddCSSMaxSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize)
{
PRBool heightSet = PR_FALSE;
PRBool widthSet = PR_FALSE, heightSet = PR_FALSE;
// add in the css min, max, pref
const nsStylePosition* position = aBox->GetStylePosition();
// and max
PRBool widthSet =
nsLayoutUtils::GetAbsoluteCoord(position->mMaxWidth,
aState.GetRenderingContext(),
aBox, aSize.width);
// see if the width or height was specifically set
// XXX Handle eStyleUnit_Enumerated?
// (Handling the eStyleUnit_Enumerated types requires
// GetPrefSize/GetMinSize methods that don't consider
// (min-/max-/)(width/height) properties.
// (min-/max-/)(width/height) properties.)
if (position->mMaxWidth.GetUnit() == eStyleUnit_Coord) {
aSize.width = position->mMaxWidth.GetCoordValue();
widthSet = PR_TRUE;
}
if (position->mMaxHeight.GetUnit() == eStyleUnit_Coord) {
nscoord max = position->mMaxHeight.GetCoordValue();
aSize.height = max;
aSize.height = position->mMaxHeight.GetCoordValue();
heightSet = PR_TRUE;
}