From cb5bc9d2a1645064281829706426e2a64e1deff9 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Tue, 1 Jul 2008 20:24:36 -0700 Subject: [PATCH] Remove eStyleUnit_Chars and the special cases for it throughout layout, and make ch units go through the normal eStyleUnit_Coord cases. (Bug 363706) r+sr=dbaron --- layout/base/nsLayoutUtils.cpp | 34 -------------------- layout/base/nsLayoutUtils.h | 24 +++++++------- layout/generic/nsAbsoluteContainingBlock.cpp | 12 +++---- layout/generic/nsFrame.cpp | 5 --- layout/style/nsComputedDOMStyle.cpp | 34 -------------------- layout/style/nsRuleNode.cpp | 15 ++------- layout/style/nsStyleCoord.cpp | 3 -- layout/style/nsStyleCoord.h | 5 +-- layout/style/nsStyleStruct.cpp | 4 --- layout/style/nsStyleStruct.h | 2 +- layout/tables/BasicTableLayoutStrategy.cpp | 8 ++--- layout/tables/FixedTableLayoutStrategy.cpp | 8 ++--- layout/xul/base/src/nsBox.cpp | 3 -- 13 files changed, 25 insertions(+), 132 deletions(-) diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 70b06930e05..d5485b5319e 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -1493,25 +1493,6 @@ static nscoord AddPercents(nsLayoutUtils::IntrinsicWidthType aType, return result; } -/* static */ PRBool -nsLayoutUtils::GetAbsoluteCoord(const nsStyleCoord& aStyle, - nsIRenderingContext* aRenderingContext, - nsStyleContext* aStyleContext, - nscoord& aResult) -{ - nsStyleUnit unit = aStyle.GetUnit(); - if (eStyleUnit_Coord == unit) { - aResult = aStyle.GetCoordValue(); - return PR_TRUE; - } - if (eStyleUnit_Chars == unit) { - aResult = nsLayoutUtils::CharsToCoord(aStyle, aRenderingContext, - aStyleContext); - return PR_TRUE; - } - return PR_FALSE; -} - static PRBool GetPercentHeight(const nsStyleCoord& aStyle, nsIRenderingContext* aRenderingContext, @@ -2651,21 +2632,6 @@ nsLayoutUtils::SetFontFromStyle(nsIRenderingContext* aRC, nsStyleContext* aSC) aRC->SetFont(font->mFont, visibility->mLangGroup); } -nscoord -nsLayoutUtils::CharsToCoord(const nsStyleCoord& aStyle, - nsIRenderingContext* aRenderingContext, - nsStyleContext* aStyleContext) -{ - NS_ASSERTION(aStyle.GetUnit() == eStyleUnit_Chars, - "Shouldn't have called this"); - - SetFontFromStyle(aRenderingContext, aStyleContext); - nscoord fontWidth; - aRenderingContext->SetTextRunRTL(PR_FALSE); - aRenderingContext->GetWidth('M', fontWidth); - return aStyle.GetIntValue() * fontWidth; -} - static PRBool NonZeroStyleCoord(const nsStyleCoord& aCoord) { switch (aCoord.GetUnit()) { diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 38f1cdf2a84..2c7d71540ed 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -589,7 +589,7 @@ public: * @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 or eStyleUnit_Chars + * @return TRUE if the unit is eStyleUnit_Coord */ static PRBool GetAbsoluteCoord(const nsStyleCoord& aStyle, nsIRenderingContext* aRenderingContext, @@ -606,7 +606,16 @@ public: static PRBool GetAbsoluteCoord(const nsStyleCoord& aStyle, nsIRenderingContext* aRenderingContext, nsStyleContext* aStyleContext, - nscoord& aResult); + 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', @@ -761,17 +770,6 @@ public: */ static void SetFontFromStyle(nsIRenderingContext* aRC, nsStyleContext* aSC); - /** - * Convert an eStyleUnit_Chars nsStyleCoord to an nscoord. - * - * @param aStyle the style coord - * @param aRenderingContext the rendering context to use for font measurement - * @param aStyleContext the style context to use for font infomation - */ - static nscoord CharsToCoord(const nsStyleCoord& aStyle, - nsIRenderingContext* aRenderingContext, - nsStyleContext* aStyleContext); - /** * Determine if any style coordinate is nonzero * @param aCoord the style sides diff --git a/layout/generic/nsAbsoluteContainingBlock.cpp b/layout/generic/nsAbsoluteContainingBlock.cpp index d0db643577c..03128314d9c 100644 --- a/layout/generic/nsAbsoluteContainingBlock.cpp +++ b/layout/generic/nsAbsoluteContainingBlock.cpp @@ -210,26 +210,24 @@ nsAbsoluteContainingBlock::Reflow(nsContainerFrame* aDelegatingFrame, } static inline PRBool IsFixedPaddingSize(nsStyleUnit aUnit) { - return aUnit == eStyleUnit_Coord || aUnit == eStyleUnit_Chars; + return aUnit == eStyleUnit_Coord; } static inline PRBool IsFixedMarginSize(nsStyleUnit aUnit) { - return aUnit == eStyleUnit_Coord || aUnit == eStyleUnit_Chars; + return aUnit == eStyleUnit_Coord; } static inline PRBool IsFixedMaxSize(nsStyleUnit aUnit) { - return aUnit == eStyleUnit_None || aUnit == eStyleUnit_Coord || - aUnit == eStyleUnit_Chars; + return aUnit == eStyleUnit_None || aUnit == eStyleUnit_Coord; } static inline PRBool IsFixedOffset(nsStyleUnit aUnit) { - return aUnit == eStyleUnit_Coord || aUnit == eStyleUnit_Chars; + return aUnit == eStyleUnit_Coord; } static inline PRBool IsFixedHeight(nsStyleUnit aUnit) { - return aUnit == eStyleUnit_Coord || aUnit == eStyleUnit_Chars; + return aUnit == eStyleUnit_Coord; } static inline PRBool IsFixedWidth(const nsStyleCoord& aCoord) { return aCoord.GetUnit() == eStyleUnit_Coord || - aCoord.GetUnit() == eStyleUnit_Chars || (aCoord.GetUnit() == eStyleUnit_Enumerated && (aCoord.GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT || aCoord.GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT)); diff --git a/layout/generic/nsFrame.cpp b/layout/generic/nsFrame.cpp index 00eb0739f72..9159306d335 100644 --- a/layout/generic/nsFrame.cpp +++ b/layout/generic/nsFrame.cpp @@ -2963,11 +2963,6 @@ AddCoord(const nsStyleCoord& aStyle, case eStyleUnit_Percent: *aPercent += aStyle.GetPercentValue(); break; - case eStyleUnit_Chars: { - *aCoord += nsLayoutUtils::CharsToCoord(aStyle, aRenderingContext, - aFrame->GetStyleContext()); - break; - } default: break; } diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index 8fb5c142777..def6537e56e 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -2771,7 +2771,6 @@ nsComputedDOMStyle::GetRelativeOffset(PRUint8 aSide, nsIDOMCSSValue** aValue) NS_ASSERTION(coord.GetUnit() == eStyleUnit_Coord || coord.GetUnit() == eStyleUnit_Percent || - coord.GetUnit() == eStyleUnit_Chars || coord.GetUnit() == eStyleUnit_Auto, "Unexpected unit"); @@ -3058,24 +3057,6 @@ nsComputedDOMStyle::SetValueToCoord(nsROCSSPrimitiveValue* aValue, aTable)); break; - case eStyleUnit_Chars: { - // Get a rendering context - nsCOMPtr cx; - nsIFrame* frame = mPresShell->FrameManager()->GetRootFrame(); - if (frame) { - mPresShell->CreateRenderingContext(frame, getter_AddRefs(cx)); - } - if (cx) { - nscoord val = - nsLayoutUtils::CharsToCoord(aCoord, cx, mStyleContextHolder); - aValue->SetAppUnits(PR_MAX(aMinAppUnits, PR_MIN(val, aMaxAppUnits))); - } else { - // Oh, well. Give up. - aValue->SetAppUnits(0); - } - break; - } - case eStyleUnit_None: aValue->SetIdent(nsGkAtoms::none); break; @@ -3095,21 +3076,6 @@ nsComputedDOMStyle::StyleCoordToNSCoord(const nsStyleCoord& aCoord, switch (aCoord.GetUnit()) { case eStyleUnit_Coord: return aCoord.GetCoordValue(); - case eStyleUnit_Chars: - { - // Get a rendering context - nsCOMPtr cx; - nsIFrame* frame = mPresShell->FrameManager()->GetRootFrame(); - if (frame) { - mPresShell->CreateRenderingContext(frame, getter_AddRefs(cx)); - } - if (!cx) { - // Return the default value, I guess - break; - } - - return nsLayoutUtils::CharsToCoord(aCoord, cx, mStyleContextHolder); - } case eStyleUnit_Percent: { nscoord percentageBase; diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 0a5c3ecd09d..023e9d48ba8 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -320,10 +320,6 @@ static PRBool SetCoord(const nsCSSValue& aValue, nsStyleCoord& aCoord, if (aValue.GetUnit() == eCSSUnit_Null) { result = PR_FALSE; } - else if (((aMask & SETCOORD_LENGTH) != 0) && - (aValue.GetUnit() == eCSSUnit_Char)) { - aCoord.SetIntValue(NSToIntFloor(aValue.GetFloatValue()), eStyleUnit_Chars); - } else if (((aMask & SETCOORD_LENGTH) != 0) && aValue.IsLengthUnit()) { aCoord.SetCoordValue(CalcLength(aValue, aStyleContext, aPresContext, aInherited)); @@ -3733,15 +3729,8 @@ nsRuleNode::ComputeBorderData(void* aStartStruct, // OK to pass bad aParentCoord since we're not passing SETCOORD_INHERIT else if (SetCoord(value, coord, nsStyleCoord(), SETCOORD_LENGTH, aContext, mPresContext, inherited)) { - if (coord.GetUnit() == eStyleUnit_Coord) { - border->SetBorderWidth(side, coord.GetCoordValue()); - } -#ifdef DEBUG - else { - NS_ASSERTION(coord.GetUnit() == eStyleUnit_Chars, "unexpected unit"); - NS_WARNING("Border set in chars; we don't handle that"); - } -#endif + NS_ASSERTION(coord.GetUnit() == eStyleUnit_Coord, "unexpected unit"); + border->SetBorderWidth(side, coord.GetCoordValue()); } else if (eCSSUnit_Inherit == value.GetUnit()) { inherited = PR_TRUE; diff --git a/layout/style/nsStyleCoord.cpp b/layout/style/nsStyleCoord.cpp index 34c66e91b0a..b4f9d6deb10 100644 --- a/layout/style/nsStyleCoord.cpp +++ b/layout/style/nsStyleCoord.cpp @@ -129,10 +129,8 @@ void nsStyleCoord::SetCoordValue(nscoord aValue) void nsStyleCoord::SetIntValue(PRInt32 aValue, nsStyleUnit aUnit) { NS_ASSERTION((aUnit == eStyleUnit_Enumerated) || - (aUnit == eStyleUnit_Chars) || (aUnit == eStyleUnit_Integer), "not an int value"); if ((aUnit == eStyleUnit_Enumerated) || - (aUnit == eStyleUnit_Chars) || (aUnit == eStyleUnit_Integer)) { mUnit = aUnit; mValue.mInt = aValue; @@ -196,7 +194,6 @@ void nsStyleCoord::AppendToString(nsString& aBuffer) const case eStyleUnit_None: aBuffer.AppendLiteral("None"); break; case eStyleUnit_Enumerated: aBuffer.AppendLiteral("enum"); break; case eStyleUnit_Integer: aBuffer.AppendLiteral("int"); break; - case eStyleUnit_Chars: aBuffer.AppendLiteral("chars"); break; } aBuffer.Append(PRUnichar(' ')); } diff --git a/layout/style/nsStyleCoord.h b/layout/style/nsStyleCoord.h index 56e3fbce186..9931937f9e2 100644 --- a/layout/style/nsStyleCoord.h +++ b/layout/style/nsStyleCoord.h @@ -55,8 +55,7 @@ enum nsStyleUnit { eStyleUnit_Factor = 11, // (float) a multiplier eStyleUnit_Coord = 20, // (nscoord) value is twips eStyleUnit_Integer = 30, // (int) value is simple integer - eStyleUnit_Enumerated = 32, // (int) value has enumerated meaning - eStyleUnit_Chars = 33 // (int) value is number of characters + eStyleUnit_Enumerated = 32 // (int) value has enumerated meaning }; typedef union { @@ -197,10 +196,8 @@ inline PRInt32 nsStyleCoord::GetCoordValue(void) const inline PRInt32 nsStyleCoord::GetIntValue(void) const { NS_ASSERTION((mUnit == eStyleUnit_Enumerated) || - (mUnit == eStyleUnit_Chars) || (mUnit == eStyleUnit_Integer), "not an int value"); if ((mUnit == eStyleUnit_Enumerated) || - (mUnit == eStyleUnit_Chars) || (mUnit == eStyleUnit_Integer)) { return mValue.mInt; } diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index f234fc8051d..b9c6becc38d 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -231,10 +231,6 @@ static nscoord CalcCoord(const nsStyleCoord& aCoord, } } break; - case eStyleUnit_Chars: - // XXX we need a frame and a rendering context to calculate this, bug 281972, bug 282126. - NS_NOTYETIMPLEMENTED("CalcCoord: eStyleUnit_Chars"); - return 0; default: NS_ERROR("bad unit type"); break; diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index be08ccf5376..174627835b6 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -526,7 +526,7 @@ struct nsStyleOutline { aOffset = NS_ROUND_OFFSET_TO_PIXELS(offset, mTwipsPerPixel); return PR_TRUE; } else { - NS_NOTYETIMPLEMENTED("GetOutlineOffset: eStyleUnit_Chars"); + NS_ERROR("GetOutlineOffset: bad unit type"); aOffset = 0; return PR_FALSE; } diff --git a/layout/tables/BasicTableLayoutStrategy.cpp b/layout/tables/BasicTableLayoutStrategy.cpp index fdbd99ddc06..679f28a1829 100644 --- a/layout/tables/BasicTableLayoutStrategy.cpp +++ b/layout/tables/BasicTableLayoutStrategy.cpp @@ -121,7 +121,7 @@ GetWidthInfo(nsIRenderingContext *aRenderingContext, // XXXldb Should we consider -moz-box-sizing? nsStyleUnit unit = aStylePos->mWidth.GetUnit(); - if (unit == eStyleUnit_Coord || unit == eStyleUnit_Chars) { + if (unit == eStyleUnit_Coord) { hasSpecifiedWidth = PR_TRUE; nscoord w = nsLayoutUtils::ComputeWidthValue(aRenderingContext, aFrame, 0, 0, 0, aStylePos->mWidth); @@ -171,8 +171,7 @@ GetWidthInfo(nsIRenderingContext *aRenderingContext, unit = maxWidth.GetUnit(); // XXX To really implement 'max-width' well, we'd need to store // it separately on the columns. - if (unit == eStyleUnit_Coord || unit == eStyleUnit_Chars || - unit == eStyleUnit_Enumerated) { + if (unit == eStyleUnit_Coord || unit == eStyleUnit_Enumerated) { nscoord w = nsLayoutUtils::ComputeWidthValue(aRenderingContext, aFrame, 0, 0, 0, maxWidth); @@ -197,8 +196,7 @@ GetWidthInfo(nsIRenderingContext *aRenderingContext, eStyleUnit_Enumerated); } unit = minWidth.GetUnit(); - if (unit == eStyleUnit_Coord || unit == eStyleUnit_Chars || - unit == eStyleUnit_Enumerated) { + if (unit == eStyleUnit_Coord || unit == eStyleUnit_Enumerated) { nscoord w = nsLayoutUtils::ComputeWidthValue(aRenderingContext, aFrame, 0, 0, 0, minWidth); diff --git a/layout/tables/FixedTableLayoutStrategy.cpp b/layout/tables/FixedTableLayoutStrategy.cpp index 236c9d6e1b4..53e8338bd18 100644 --- a/layout/tables/FixedTableLayoutStrategy.cpp +++ b/layout/tables/FixedTableLayoutStrategy.cpp @@ -98,8 +98,7 @@ FixedTableLayoutStrategy::GetMinWidth(nsIRenderingContext* aRenderingContext) } const nsStyleCoord *styleWidth = &colFrame->GetStylePosition()->mWidth; - if (styleWidth->GetUnit() == eStyleUnit_Coord || - styleWidth->GetUnit() == eStyleUnit_Chars) { + if (styleWidth->GetUnit() == eStyleUnit_Coord) { result += nsLayoutUtils::ComputeWidthValue(aRenderingContext, colFrame, 0, 0, 0, *styleWidth); } else if (styleWidth->GetUnit() == eStyleUnit_Percent) { @@ -118,7 +117,6 @@ FixedTableLayoutStrategy::GetMinWidth(nsIRenderingContext* aRenderingContext) if (cellFrame) { styleWidth = &cellFrame->GetStylePosition()->mWidth; if (styleWidth->GetUnit() == eStyleUnit_Coord || - styleWidth->GetUnit() == eStyleUnit_Chars || (styleWidth->GetUnit() == eStyleUnit_Enumerated && (styleWidth->GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT || styleWidth->GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT))) { @@ -216,8 +214,7 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt const nsStyleCoord *styleWidth = &colFrame->GetStylePosition()->mWidth; nscoord colWidth; - if (styleWidth->GetUnit() == eStyleUnit_Coord || - styleWidth->GetUnit() == eStyleUnit_Chars) { + if (styleWidth->GetUnit() == eStyleUnit_Coord) { colWidth = nsLayoutUtils::ComputeWidthValue( aReflowState.rendContext, colFrame, 0, 0, 0, *styleWidth); @@ -240,7 +237,6 @@ FixedTableLayoutStrategy::ComputeColumnWidths(const nsHTMLReflowState& aReflowSt if (cellFrame) { styleWidth = &cellFrame->GetStylePosition()->mWidth; if (styleWidth->GetUnit() == eStyleUnit_Coord || - styleWidth->GetUnit() == eStyleUnit_Chars || (styleWidth->GetUnit() == eStyleUnit_Enumerated && (styleWidth->GetIntValue() == NS_STYLE_WIDTH_MAX_CONTENT || styleWidth->GetIntValue() == NS_STYLE_WIDTH_MIN_CONTENT))) { diff --git a/layout/xul/base/src/nsBox.cpp b/layout/xul/base/src/nsBox.cpp index d44b71ae179..f0495fb906c 100644 --- a/layout/xul/base/src/nsBox.cpp +++ b/layout/xul/base/src/nsBox.cpp @@ -683,7 +683,6 @@ nsIBox::AddCSSPrefSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize) aSize.height = position->mHeight.GetCoordValue(); heightSet = PR_TRUE; } - // XXX Handle eStyleUnit_Chars? nsIContent* content = aBox->GetContent(); // ignore 'height' and 'width' attributes if the actual element is not XUL @@ -782,7 +781,6 @@ nsIBox::AddCSSMinSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize) aSize.height = 0; heightSet = PR_TRUE; } - // XXX Handle eStyleUnit_Chars? nsIContent* content = aBox->GetContent(); if (content) { @@ -841,7 +839,6 @@ nsIBox::AddCSSMaxSize(nsBoxLayoutState& aState, nsIBox* aBox, nsSize& aSize) aSize.height = max; heightSet = PR_TRUE; } - // XXX Handle eStyleUnit_Chars? nsIContent* content = aBox->GetContent(); if (content) {