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

This commit is contained in:
Zack Weinberg 2008-07-01 20:24:36 -07:00
Родитель 6dfe3bef4e
Коммит cb5bc9d2a1
13 изменённых файлов: 25 добавлений и 132 удалений

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

@ -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()) {

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

@ -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

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

@ -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));

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

@ -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;
}

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

@ -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<nsIRenderingContext> 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<nsIRenderingContext> 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;

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

@ -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;

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

@ -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(' '));
}

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

@ -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;
}

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

@ -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;

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

@ -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;
}

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

@ -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);

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

@ -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))) {

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

@ -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) {