Refactor some repetitive computed style code. Bug 365932, r+sr=dbaron

git-svn-id: svn://10.0.0.236/trunk@220587 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bzbarsky%mit.edu
2007-02-20 18:43:16 +00:00
parent 52c9a4d6cd
commit 8a1cc76eca
21 changed files with 1012 additions and 475 deletions

View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<body>
<div style="width: 400px; padding: 0 200px;
-moz-column-gap: 200px; -moz-column-width: 100px">
This is text 1.
This is text 2.
This is text 3.
This is text 4.
</div>
<div style="width: 400px; border-width: 0 100px; border-style: solid;
border-color: transparent; -moz-column-gap: 200px;
-moz-column-width: 100px">
This is text 1.
This is text 2.
This is text 3.
This is text 4.
</div>
<div style="width: 400px; border-width: 0 100px; border-style: solid;
border-color: transparent; -moz-column-gap: 40px;
-moz-column-width: 100px">
This is text 1.
This is text 2.
This is text 3.
This is text 4.
</div>
</body>
</html>

View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<body>
<div style="width: 400px; padding: 0 200px;
-moz-column-gap: 50%; -moz-column-width: 100px">
This is text 1.
This is text 2.
This is text 3.
This is text 4.
</div>
<div style="width: 400px; border-width: 0 100px; border-style: solid;
border-color: transparent; -moz-column-gap: 50%;
-moz-column-width: 100px">
This is text 1.
This is text 2.
This is text 3.
This is text 4.
</div>
<div style="width: 400px; border-width: 0 100px; border-style: solid;
border-color: transparent; -moz-column-gap: 10%;
-moz-column-width: 100px">
This is text 1.
This is text 2.
This is text 3.
This is text 4.
</div>
</body>
</html>

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<body style="width: 400px; padding: 0 200px; -moz-column-gap: 200px; -moz-column-width: 100px">
This is text 1.
This is text 2.
This is text 3.
This is text 4.
This is text 5.
This is text 6.
</body>
</html>

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<body style="width: 400px; padding: 0 200px; -moz-column-gap: 10%; -moz-column-width: 100px">
This is text 1.
This is text 2.
This is text 3.
This is text 4.
This is text 5.
This is text 6.
</body>
</html>

View File

@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<style>
div:empty { background: yellow; border: 1px solid black;
padding: 0; margin: 0; }
body > div:not(:empty) { height: 20px}
</style>
</head>
<body>
<div style="height: 10px; max-height: 15px;"></div>
<div style="height: 10px; max-height: 5px;"></div>
<div style="height: 10px; max-height: 5px; min-height: 2px"></div>
<div style="height: 10px; max-height: 5px; min-height: 15px"></div>
<div style="max-height: 5px; min-height: 15px"></div>
<div>
<div style="height: 50%;"></div>
</div>
<div>
<div style="height: 50%; max-height: 15px;"></div>
</div>
<div>
<div style="height: 50%; max-height: 5px;"></div>
</div>
<div>
<div style="height: 50%; max-height: 75%;"></div>
</div>
<div>
<div style="height: 50%; max-height: 10%;"></div>
</div>
<div style="padding: 10px 0;">
<div style="height: 50%; max-height: 75%;"></div>
</div>
<div style="padding: 10px 0;">
<div style="height: 50%; max-height: 10%;"></div>
</div>
<div style="border-width: 10px 0; border-style: solid;
border-color: transparent;">
<div style="height: 50%; max-height: 75%;"></div>
</div>
<div style="border-width: 10px 0; border-style: solid;
border-color: transparent;">
<div style="height: 50%; max-height: 10%;"></div>
</div>
</body>
</html>

View File

@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<style>
div:empty { background: yellow; border: 1px solid black;
padding: 0; margin: 0; }
body > div:not(:empty) { height: 20px; }
</style>
</head>
<body>
<div style="height: 10px;"></div>
<div style="height: 5px;"></div>
<div style="height: 5px;"></div>
<div style="height: 15px;"></div>
<div style="height: 15px;"></div>
<div>
<div style="height: 10px;"></div>
</div>
<div>
<div style="height: 10px;"></div>
</div>
<div>
<div style="height: 5px;"></div>
</div>
<div>
<div style="height: 10px;"></div>
</div>
<div>
<div style="height: 2px;"></div>
</div>
<div style="padding: 10px 0;">
<div style="height: 10px;"></div>
</div>
<div style="padding: 10px 0;">
<div style="height: 2px;"></div>
</div>
<div style="border-width: 10px 0; border-style: solid;
border-color: transparent;">
<div style="height: 10px;"></div>
</div>
<div style="border-width: 10px 0; border-style: solid;
border-color: transparent;">
<div style="height: 2px;"></div>
</div>
</body>
</html>

View File

@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<style>
div:empty { background: yellow; border: 1px solid black; height: 10px;
padding: 0; margin: 0; }
body > div:not(:empty) { width: 400px; }
</style>
</head>
<body>
<div style="width: 100px;"></div>
<div style="width: 50px;"></div>
<div style="width: 50px;"></div>
<div style="width: 150px;"></div>
<div style="width: 150px;"></div>
<div>
<div style="width: 200px;"></div>
</div>
<div>
<div style="width: 200px;"></div>
</div>
<div>
<div style="width: 100px;"></div>
</div>
<div>
<div style="width: 200px;"></div>
</div>
<div>
<div style="width: 40px;"></div>
</div>
<div style="padding: 0 100px;">
<div style="width: 200px;"></div>
</div>
<div style="padding: 0 100px;">
<div style="width: 40px;"></div>
</div>
<div style="border-width: 0 100px; border-style: solid;
border-color: transparent;">
<div style="width: 200px;"></div>
</div>
<div style="border-width: 0 100px; border-style: solid;
border-color: transparent;">
<div style="width: 40px;"></div>
</div>
</body>
</html>

View File

@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<style>
div:empty { background: yellow; border: 1px solid black; height: 10px;
padding: 0; margin: 0; }
body > div:not(:empty) { width: 400px; }
</style>
</head>
<body>
<div style="width: 100px; max-width: 150px;"></div>
<div style="width: 100px; max-width: 50px;"></div>
<div style="width: 100px; max-width: 50px; min-width: 20px"></div>
<div style="width: 100px; max-width: 50px; min-width: 150px"></div>
<div style="max-width: 50px; min-width: 150px"></div>
<div>
<div style="width: 50%;"></div>
</div>
<div>
<div style="width: 50%; max-width: 300px;"></div>
</div>
<div>
<div style="width: 50%; max-width: 100px;"></div>
</div>
<div>
<div style="width: 50%; max-width: 75%;"></div>
</div>
<div>
<div style="width: 50%; max-width: 10%;"></div>
</div>
<div style="padding: 0 100px;">
<div style="width: 50%; max-width: 75%;"></div>
</div>
<div style="padding: 0 100px;">
<div style="width: 50%; max-width: 10%;"></div>
</div>
<div style="border-width: 0 100px; border-style: solid;
border-color: transparent;">
<div style="width: 50%; max-width: 75%;"></div>
</div>
<div style="border-width: 0 100px; border-style: solid;
border-color: transparent;">
<div style="width: 50%; max-width: 10%;"></div>
</div>
</body>
</html>

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<style>
div:empty { background: yellow; border: 1px solid black;
padding: 0; margin: 0; }
body > div:not(:empty) { height: 20px; }
</style>
</head>
<body>
<div style="height: 10px;"></div>
<div style="height: 15px;"></div>
<div>
<div style="height: 10px;"></div>
</div>
<div>
<div style="height: 10px;"></div>
</div>
<div>
<div style="height: 15px;"></div>
</div>
<div>
<div style="height: 10px;"></div>
</div>
<div>
<div style="height: 15px;"></div>
</div>
<div style="padding: 10px 0;">
<div style="height: 10px;"></div>
</div>
<div style="padding: 10px 0;">
<div style="height: 15px;"></div>
</div>
<div style="border-width: 10px 0; border-style: solid;
border-color: transparent;">
<div style="height: 10px;"></div>
</div>
<div style="border-width: 10px 0; border-style: solid;
border-color: transparent;">
<div style="height: 15px;"></div>
</div>
</body>
</html>

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<style>
div:empty { background: yellow; border: 1px solid black;
padding: 0; margin: 0; }
body > div:not(:empty) { height: 20px; }
</style>
</head>
<body>
<div style="height: 10px; min-height: 5px;"></div>
<div style="height: 10px; min-height: 15px;"></div>
<div>
<div style="height: 50%;"></div>
</div>
<div>
<div style="height: 50%; min-height: 5px;"></div>
</div>
<div>
<div style="height: 50%; min-height: 15px;"></div>
</div>
<div>
<div style="height: 50%; min-height: 10%;"></div>
</div>
<div>
<div style="height: 50%; min-height: 75%;"></div>
</div>
<div style="padding: 10px 0">
<div style="height: 50%; min-height: 10%;"></div>
</div>
<div style="padding: 10px 0;">
<div style="height: 50%; min-height: 75%;"></div>
</div>
<div style="border-width: 10px 0; border-style: solid;
border-color: transparent;">
<div style="height: 50%; min-height: 10%;"></div>
</div>
<div style="border-width: 10px 0; border-style: solid;
border-color: transparent;">
<div style="height: 50%; min-height: 75%;"></div>
</div>
</body>
</html>

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<style>
div:empty { background: yellow; border: 1px solid black; height: 10px;
padding: 0; margin: 0; }
body > div:not(:empty) { width: 400px; }
</style>
</head>
<body>
<div style="width: 100px;"></div>
<div style="width: 150px;"></div>
<div>
<div style="width: 200px;"></div>
</div>
<div>
<div style="width: 200px;"></div>
</div>
<div>
<div style="width: 300px;"></div>
</div>
<div>
<div style="width: 200px;"></div>
</div>
<div>
<div style="width: 300px;"></div>
</div>
<div style="padding: 0 100px;">
<div style="width: 200px;"></div>
</div>
<div style="padding: 0 100px;">
<div style="width: 300px;"></div>
</div>
<div style="border-width: 0 100px; border-style: solid;
border-color: transparent;">
<div style="width: 200px;"></div>
</div>
<div style="border-width: 0 100px; border-style: solid;
border-color: transparent;">
<div style="width: 300px;"></div>
</div>
</body>
</html>

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<style>
div:empty { background: yellow; border: 1px solid black; height: 10px;
padding: 0; margin: 0; }
body > div:not(:empty) { width: 400px; }
</style>
</head>
<body>
<div style="width: 100px; min-width: 50px;"></div>
<div style="width: 100px; min-width: 150px;"></div>
<div>
<div style="width: 50%;"></div>
</div>
<div>
<div style="width: 50%; min-width: 100px;"></div>
</div>
<div>
<div style="width: 50%; min-width: 300px;"></div>
</div>
<div>
<div style="width: 50%; min-width: 10%;"></div>
</div>
<div>
<div style="width: 50%; min-width: 75%;"></div>
</div>
<div style="padding: 0 100px;">
<div style="width: 50%; min-width: 10%;"></div>
</div>
<div style="padding: 0 100px;">
<div style="width: 50%; min-width: 75%;"></div>
</div>
<div style="border-width: 0 100px; border-style: solid;
border-color: transparent;">
<div style="width: 50%; min-width: 10%;"></div>
</div>
<div style="border-width: 0 100px; border-style: solid;
border-color: transparent;">
<div style="width: 50%; min-width: 75%;"></div>
</div>
</body>
</html>

View File

@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<style>
div {
outline-width: 10px; outline-style: solid;
width: 400px; height: 50px;
margin: 20px 0;
border-style: solid; border-color: transparent; border-width: 0;
padding: 0;
}
</style>
</head>
<body>
<div style="-moz-outline-radius: 20px;"></div>
<div style="-moz-outline-radius: 40px;"></div>
<div style="-moz-outline-radius: 80px;"></div>
<div style="padding: 0 100px; -moz-outline-radius: 60px;"></div>
<div style="padding: 0 100px 0 0; -moz-outline-radius: 50px;"></div>
<div style="padding: 0 0 0 100px; -moz-outline-radius: 50px;"></div>
<div style="border-width: 0 100px; -moz-outline-radius: 60px;"></div>
<div style="border-width: 0 100px 0 0; -moz-outline-radius: 50px;"></div>
<div style="border-width: 0 0 0 100px; -moz-outline-radius: 50px;"></div>
<div style="border-width: 0 100px; padding: 0 100px;
-moz-outline-radius: 80px;"></div>
</body>
</html>

View File

@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<style>
div {
outline-width: 10px; outline-style: solid;
width: 400px; height: 50px;
margin: 20px 0;
border-style: solid; border-color: transparent; border-width: 0;
padding: 0;
}
</style>
</head>
<body>
<div style="-moz-outline-radius: 5%;"></div>
<div style="-moz-outline-radius: 10%;"></div>
<div style="-moz-outline-radius: 20%;"></div>
<div style="padding: 0 100px; -moz-outline-radius: 10%;"></div>
<div style="padding: 0 100px 0 0; -moz-outline-radius: 10%;"></div>
<div style="padding: 0 0 0 100px; -moz-outline-radius: 10%;"></div>
<div style="border-width: 0 100px; -moz-outline-radius: 10%;"></div>
<div style="border-width: 0 100px 0 0; -moz-outline-radius: 10%;"></div>
<div style="border-width: 0 0 0 100px; -moz-outline-radius: 10%;"></div>
<div style="border-width: 0 100px; padding: 0 100px;
-moz-outline-radius: 10%;"></div>
</body>
</html>

View File

@@ -0,0 +1,7 @@
== column-gap-percent-1.html column-gap-percent-1-ref.html
!= column-gap-percent-2.html column-gap-percent-2-ref.html
== outline-radius-percent-1.html outline-radius-percent-1-ref.html
== min-width-1.html min-width-1-ref.html
== min-height-1.html min-height-1-ref.html
== max-width-1.html max-width-1-ref.html
== max-height-1.html max-height-1-ref.html

View File

@@ -294,3 +294,6 @@ fails == object/svg-with-type.html object/svg-with-type-ref.html
# xul-document-load/
include xul-document-load/reftest.list
# box-properties/
include box-properties/reftest.list

View File

@@ -43,6 +43,10 @@ include $(DEPTH)/config/autoconf.mk
DIRS = xbl-marquee
ifdef MOZ_MOCHITEST
DIRS += test
endif
MODULE = layout
LIBRARY_NAME = gkstyle_s
LIBXUL_LIBRARY = 1

View File

@@ -552,22 +552,9 @@ nsComputedDOMStyle::GetColumnWidth(nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStyleColumn* column = GetStyleColumn();
switch (column->mColumnWidth.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(column->mColumnWidth.GetCoordValue());
break;
case eStyleUnit_Auto:
// XXX fix this. When we actually have a column frame, I think
// we should return the computed column width.
val->SetIdent(nsGkAtoms::_auto);
break;
default:
NS_ERROR("Unexpected column width unit");
val->SetAppUnits(0);
break;
}
// XXX fix the auto case. When we actually have a column frame, I think
// we should return the computed column width.
SetValueToCoord(val, GetStyleColumn()->mColumnWidth);
return CallQueryInterface(val, aValue);
}
@@ -579,25 +566,11 @@ nsComputedDOMStyle::GetColumnGap(nsIDOMCSSValue** aValue)
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStyleColumn* column = GetStyleColumn();
switch (column->mColumnGap.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(column->mColumnGap.GetCoordValue());
break;
case eStyleUnit_Percent:
if (mFrame) {
val->SetAppUnits(column->mColumnGap.GetPercentValue()*mFrame->GetSize().width);
} else {
val->SetPercent(column->mColumnGap.GetPercentValue());
}
break;
case eStyleUnit_Normal:
val->SetAppUnits(GetStyleFont()->mFont.size);
break;
default:
NS_ERROR("Unexpected column gap unit");
val->SetAppUnits(0);
break;
if (column->mColumnGap.GetUnit() == eStyleUnit_Normal) {
val->SetAppUnits(GetStyleFont()->mFont.size);
} else {
SetValueToCoord(val, GetStyleColumn()->mColumnGap,
&nsComputedDOMStyle::GetFrameContentWidth);
}
return CallQueryInterface(val, aValue);
@@ -1248,23 +1221,7 @@ nsComputedDOMStyle::GetMarkerOffset(nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStyleContent* content = GetStyleContent();
switch (content->mMarkerOffset.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(content->mMarkerOffset.GetCoordValue());
break;
case eStyleUnit_Auto:
val->SetIdent(nsGkAtoms::_auto);
break;
case eStyleUnit_Null: // XXX doesn't seem like a valid unit per CSS2?
val->SetIdent(nsGkAtoms::none);
break;
default:
NS_ERROR("Unexpected marker offset unit");
val->SetAppUnits(0);
break;
}
SetValueToCoord(val, GetStyleContent()->mMarkerOffset);
return CallQueryInterface(val, aValue);
}
@@ -1293,27 +1250,7 @@ nsComputedDOMStyle::GetOutlineWidth(nsIDOMCSSValue** aValue)
} else {
coord = outline->mOutlineWidth;
}
switch (coord.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(coord.GetCoordValue());
break;
case eStyleUnit_Enumerated:
{
const nsAFlatCString& width =
nsCSSProps::ValueToKeyword(coord.GetIntValue(),
nsCSSProps::kBorderWidthKTable);
val->SetIdent(width);
break;
}
case eStyleUnit_Chars:
// XXX we need a frame and a rendering context to calculate this, bug 281972, bug 282126.
val->SetAppUnits(0);
break;
default:
NS_ERROR("Unexpected outline width unit");
val->SetAppUnits(0);
break;
}
SetValueToCoord(val, coord, nsnull, nsCSSProps::kBorderWidthKTable);
return CallQueryInterface(val, aValue);
}
@@ -1348,21 +1285,7 @@ nsComputedDOMStyle::GetOutlineOffset(nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStyleOutline* outline = GetStyleOutline();
switch (outline->mOutlineOffset.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(outline->mOutlineOffset.GetCoordValue());
break;
case eStyleUnit_Chars:
// XXX we need a frame and a rendering context to calculate this, bug 281972, bug 282126.
val->SetAppUnits(0);
break;
default:
NS_ERROR("Unexpected outline offset unit");
val->SetAppUnits(0);
break;
}
SetValueToCoord(val, GetStyleOutline()->mOutlineOffset);
return CallQueryInterface(val, aValue);
}
@@ -1416,23 +1339,8 @@ nsComputedDOMStyle::GetOutlineRadiusFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
nsStyleCoord coord;
GetStyleOutline()->mOutlineRadius.Get(aSide, coord);
switch (coord.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(coord.GetCoordValue());
break;
case eStyleUnit_Percent:
if (mFrame) {
val->SetAppUnits(coord.GetPercentValue() * mFrame->GetSize().width);
} else {
val->SetPercent(coord.GetPercentValue());
}
break;
default:
NS_ERROR("Unexpected outline radius unit");
break;
}
SetValueToCoord(val, GetStyleOutline()->mOutlineRadius.Get(aSide, coord),
&nsComputedDOMStyle::GetFrameBorderRectWidth);
return CallQueryInterface(val, aValue);
}
@@ -1443,19 +1351,7 @@ nsComputedDOMStyle::GetZIndex(nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStylePosition* position = GetStylePosition();
switch (position->mZIndex.GetUnit()) {
case eStyleUnit_Integer:
val->SetNumber(position->mZIndex.GetIntValue());
break;
default:
NS_ERROR("Unexpected z-index unit");
// fall through
case eStyleUnit_Auto:
val->SetIdent(nsGkAtoms::_auto);
break;
}
SetValueToCoord(val, GetStylePosition()->mZIndex);
return CallQueryInterface(val, aValue);
}
@@ -1572,28 +1468,11 @@ nsComputedDOMStyle::GetLineHeight(nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStyleText *text = GetStyleText();
nscoord lineHeight;
nsresult rv = GetLineHeightCoord(text, lineHeight);
if (NS_SUCCEEDED(rv)) {
if (GetLineHeightCoord(lineHeight)) {
val->SetAppUnits(lineHeight);
} else {
switch (text->mLineHeight.GetUnit()) {
case eStyleUnit_Percent:
val->SetPercent(text->mLineHeight.GetPercentValue());
break;
case eStyleUnit_Factor:
val->SetNumber(text->mLineHeight.GetFactorValue());
break;
case eStyleUnit_Normal:
val->SetIdent(nsGkAtoms::normal);
break;
default:
NS_ERROR("Unexpected line-height unit");
break;
}
SetValueToCoord(val, GetStyleText()->mLineHeight);
}
return CallQueryInterface(val, aValue);
@@ -1605,39 +1484,9 @@ nsComputedDOMStyle::GetVerticalAlign(nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStyleTextReset *text = GetStyleTextReset();
switch (text->mVerticalAlign.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(text->mVerticalAlign.GetCoordValue());
break;
case eStyleUnit_Enumerated:
{
const nsAFlatCString& align =
nsCSSProps::ValueToKeyword(text->mVerticalAlign.GetIntValue(),
nsCSSProps::kVerticalAlignKTable);
val->SetIdent(align);
break;
}
case eStyleUnit_Percent:
{
const nsStyleText *textData = GetStyleText();
nscoord lineHeight = 0;
nsresult rv = GetLineHeightCoord(textData, lineHeight);
if (NS_SUCCEEDED(rv)) {
val->SetAppUnits(lineHeight * text->mVerticalAlign.GetPercentValue());
} else {
val->SetPercent(text->mVerticalAlign.GetPercentValue());
}
break;
}
default:
NS_ERROR("double check the vertical-align");
break;
}
SetValueToCoord(val, GetStyleTextReset()->mVerticalAlign,
&nsComputedDOMStyle::GetLineHeightCoord,
nsCSSProps::kVerticalAlignKTable);
return CallQueryInterface(val, aValue);
}
@@ -1715,30 +1564,8 @@ nsComputedDOMStyle::GetTextIndent(nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStyleText *text = GetStyleText();
FlushPendingReflows();
switch (text->mTextIndent.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(text->mTextIndent.GetCoordValue());
break;
case eStyleUnit_Percent:
{
nsIFrame *container = GetContainingBlockFor(mFrame);
if (container) {
val->SetAppUnits(container->GetSize().width *
text->mTextIndent.GetPercentValue());
} else {
// no containing block
val->SetPercent(text->mTextIndent.GetPercentValue());
}
break;
}
default:
val->SetAppUnits(0);
break;
}
SetValueToCoord(val, GetStyleText()->mTextIndent,
&nsComputedDOMStyle::GetCBContentWidth);
return CallQueryInterface(val, aValue);
}
@@ -1769,13 +1596,7 @@ nsComputedDOMStyle::GetLetterSpacing(nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStyleText *text = GetStyleText();
if (text->mLetterSpacing.GetUnit() == eStyleUnit_Coord) {
val->SetAppUnits(text->mLetterSpacing.GetCoordValue());
} else {
val->SetIdent(nsGkAtoms::normal);
}
SetValueToCoord(val, GetStyleText()->mLetterSpacing);
return CallQueryInterface(val, aValue);
}
@@ -1786,13 +1607,7 @@ nsComputedDOMStyle::GetWordSpacing(nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStyleText *text = GetStyleText();
if (text->mWordSpacing.GetUnit() == eStyleUnit_Coord) {
val->SetAppUnits(text->mWordSpacing.GetCoordValue());
} else {
val->SetIdent(nsGkAtoms::normal);
}
SetValueToCoord(val, GetStyleText()->mWordSpacing);
return CallQueryInterface(val, aValue);
}
@@ -2343,8 +2158,6 @@ nsComputedDOMStyle::GetHeight(nsIDOMCSSValue** aValue)
if (mFrame) {
calcHeight = PR_TRUE;
FlushPendingReflows();
const nsStyleDisplay* displayData = GetStyleDisplay();
if (displayData->mDisplay == NS_STYLE_DISPLAY_INLINE &&
!(mFrame->IsFrameOfType(nsIFrame::eReplaced))) {
@@ -2353,25 +2166,14 @@ nsComputedDOMStyle::GetHeight(nsIDOMCSSValue** aValue)
}
if (calcHeight) {
FlushPendingReflows();
val->SetAppUnits(mFrame->GetContentRect().height);
} else {
// Just return the value in the style context
const nsStylePosition* positionData = GetStylePosition();
switch (positionData->mHeight.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(positionData->mHeight.GetCoordValue());
break;
case eStyleUnit_Percent:
val->SetPercent(positionData->mHeight.GetPercentValue());
break;
case eStyleUnit_Auto:
val->SetIdent(nsGkAtoms::_auto);
break;
default:
NS_ERROR("Unexpected height unit");
val->SetAppUnits(0);
break;
}
// XXXbz if not mFrame, why aren't we including the min-height the
// way max-height does?
SetValueToCoord(val, GetStylePosition()->mHeight);
}
return CallQueryInterface(val, aValue);
@@ -2388,8 +2190,6 @@ nsComputedDOMStyle::GetWidth(nsIDOMCSSValue** aValue)
if (mFrame) {
calcWidth = PR_TRUE;
FlushPendingReflows();
const nsStyleDisplay *displayData = GetStyleDisplay();
if (displayData->mDisplay == NS_STYLE_DISPLAY_INLINE &&
!(mFrame->IsFrameOfType(nsIFrame::eReplaced))) {
@@ -2398,25 +2198,14 @@ nsComputedDOMStyle::GetWidth(nsIDOMCSSValue** aValue)
}
if (calcWidth) {
FlushPendingReflows();
val->SetAppUnits(mFrame->GetContentRect().width);
} else {
// Just return the value in the style context
const nsStylePosition *positionData = GetStylePosition();
switch (positionData->mWidth.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(positionData->mWidth.GetCoordValue());
break;
case eStyleUnit_Percent:
val->SetPercent(positionData->mWidth.GetPercentValue());
break;
case eStyleUnit_Auto:
val->SetIdent(nsGkAtoms::_auto);
break;
default:
NS_ERROR("Unexpected width unit");
val->SetAppUnits(0);
break;
}
// XXXbz if not mFrame, why aren't we including the min-width the
// way max-width does?
SetValueToCoord(val, GetStylePosition()->mWidth);
}
return CallQueryInterface(val, aValue);
@@ -2430,49 +2219,13 @@ nsComputedDOMStyle::GetMaxHeight(nsIDOMCSSValue** aValue)
const nsStylePosition *positionData = GetStylePosition();
FlushPendingReflows();
nscoord minHeight =
StyleCoordToNSCoord(positionData->mMinHeight,
&nsComputedDOMStyle::GetCBContentHeight);
nsIFrame *container = nsnull;
nsSize size;
nscoord minHeight = 0;
if (positionData->mMinHeight.GetUnit() == eStyleUnit_Percent) {
container = GetContainingBlockFor(mFrame);
if (container) {
size = container->GetSize();
minHeight = nscoord(size.height *
positionData->mMinHeight.GetPercentValue());
}
} else if (positionData->mMinHeight.GetUnit() == eStyleUnit_Coord) {
minHeight = positionData->mMinHeight.GetCoordValue();
}
switch (positionData->mMaxHeight.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(PR_MAX(minHeight,
positionData->mMaxHeight.GetCoordValue()));
break;
case eStyleUnit_Percent:
if (!container) {
container = GetContainingBlockFor(mFrame);
if (container) {
size = container->GetSize();
} else {
// no containing block
val->SetPercent(positionData->mMaxHeight.GetPercentValue());
}
}
if (container) {
val->SetAppUnits(PR_MAX(minHeight, size.height *
positionData->mMaxHeight.GetPercentValue()));
}
break;
default:
val->SetIdent(nsGkAtoms::none);
break;
}
SetValueToCoord(val, positionData->mMaxHeight,
&nsComputedDOMStyle::GetCBContentHeight,
nsnull, minHeight);
return CallQueryInterface(val, aValue);
}
@@ -2485,49 +2238,13 @@ nsComputedDOMStyle::GetMaxWidth(nsIDOMCSSValue** aValue)
const nsStylePosition *positionData = GetStylePosition();
FlushPendingReflows();
nscoord minWidth =
StyleCoordToNSCoord(positionData->mMinWidth,
&nsComputedDOMStyle::GetCBContentWidth);
nsIFrame *container = nsnull;
nsSize size;
nscoord minWidth = 0;
if (positionData->mMinWidth.GetUnit() == eStyleUnit_Percent) {
container = GetContainingBlockFor(mFrame);
if (container) {
size = container->GetSize();
minWidth = nscoord(size.width *
positionData->mMinWidth.GetPercentValue());
}
} else if (positionData->mMinWidth.GetUnit() == eStyleUnit_Coord) {
minWidth = positionData->mMinWidth.GetCoordValue();
}
switch (positionData->mMaxWidth.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(PR_MAX(minWidth,
positionData->mMaxWidth.GetCoordValue()));
break;
case eStyleUnit_Percent:
if (!container) {
container = GetContainingBlockFor(mFrame);
if (container) {
size = container->GetSize();
} else {
// no containing block
val->SetPercent(positionData->mMaxWidth.GetPercentValue());
}
}
if (container) {
val->SetAppUnits(PR_MAX(minWidth, size.width *
positionData->mMaxWidth.GetPercentValue()));
}
break;
default:
val->SetIdent(nsGkAtoms::none);
break;
}
SetValueToCoord(val, positionData->mMaxWidth,
&nsComputedDOMStyle::GetCBContentWidth,
nsnull, minWidth);
return CallQueryInterface(val, aValue);
}
@@ -2538,31 +2255,8 @@ nsComputedDOMStyle::GetMinHeight(nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStylePosition *positionData = GetStylePosition();
FlushPendingReflows();
nsIFrame *container = nsnull;
switch (positionData->mMinHeight.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(positionData->mMinHeight.GetCoordValue());
break;
case eStyleUnit_Percent:
container = GetContainingBlockFor(mFrame);
if (container) {
val->SetAppUnits(container->GetSize().height *
positionData->mMinHeight.GetPercentValue());
} else {
// no containing block
val->SetPercent(positionData->mMinHeight.GetPercentValue());
}
break;
default:
val->SetAppUnits(0);
break;
}
SetValueToCoord(val, GetStylePosition()->mMinHeight,
&nsComputedDOMStyle::GetCBContentHeight);
return CallQueryInterface(val, aValue);
}
@@ -2573,29 +2267,8 @@ nsComputedDOMStyle::GetMinWidth(nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue *val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
const nsStylePosition *positionData = GetStylePosition();
FlushPendingReflows();
nsIFrame *container = nsnull;
switch (positionData->mMinWidth.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(positionData->mMinWidth.GetCoordValue());
break;
case eStyleUnit_Percent:
container = GetContainingBlockFor(mFrame);
if (container) {
val->SetAppUnits(container->GetSize().width *
positionData->mMinWidth.GetPercentValue());
} else {
// no containing block
val->SetPercent(positionData->mMinWidth.GetPercentValue());
}
break;
default:
val->SetAppUnits(0);
break;
}
SetValueToCoord(val, GetStylePosition()->mMinWidth,
&nsComputedDOMStyle::GetCBContentWidth);
return CallQueryInterface(val, aValue);
}
@@ -2785,26 +2458,7 @@ nsComputedDOMStyle::GetStaticOffset(PRUint8 aSide, nsIDOMCSSValue** aValue)
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
nsStyleCoord coord;
GetStylePosition()->mOffset.Get(aSide, coord);
switch(coord.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(coord.GetCoordValue());
break;
case eStyleUnit_Percent:
val->SetPercent(coord.GetPercentValue());
break;
case eStyleUnit_Auto:
val->SetIdent(nsGkAtoms::_auto);
break;
default:
NS_ERROR("Unexpected left/right/top/bottom unit");
val->SetAppUnits(0);
break;
}
SetValueToCoord(val, GetStylePosition()->mOffset.Get(aSide, coord));
return CallQueryInterface(val, aValue);
}
@@ -2848,60 +2502,38 @@ nsComputedDOMStyle::GetPaddingWidthFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
FlushPendingReflows();
val->SetAppUnits(0);
if (!mFrame) {
nsStyleCoord c;
GetStylePadding()->mPadding.Get(aSide, c);
switch (c.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(c.GetCoordValue());
break;
case eStyleUnit_Percent:
val->SetPercent(c.GetPercentValue());
break;
default:
break;
}
SetValueToCoord(val, GetStylePadding()->mPadding.Get(aSide, c));
} else {
FlushPendingReflows();
val->SetAppUnits(mFrame->GetUsedPadding().side(aSide));
}
return CallQueryInterface(val, aValue);
}
nsresult
nsComputedDOMStyle::GetLineHeightCoord(const nsStyleText *aText,
nscoord& aCoord)
PRBool
nsComputedDOMStyle::GetLineHeightCoord(nscoord& aCoord)
{
nsresult rv = NS_ERROR_FAILURE;
if (aText) {
const nsStyleFont *font = GetStyleFont();
switch (aText->mLineHeight.GetUnit()) {
case eStyleUnit_Coord:
aCoord = aText->mLineHeight.GetCoordValue();
rv = NS_OK;
break;
case eStyleUnit_Percent:
aCoord = nscoord(aText->mLineHeight.GetPercentValue() * font->mSize);
rv = NS_OK;
break;
case eStyleUnit_Factor:
aCoord = nscoord(aText->mLineHeight.GetFactorValue() * font->mSize);
rv = NS_OK;
break;
const nsStyleText* text = GetStyleText();
const nsStyleFont *font = GetStyleFont();
switch (text->mLineHeight.GetUnit()) {
case eStyleUnit_Coord:
aCoord = text->mLineHeight.GetCoordValue();
return PR_TRUE;
case eStyleUnit_Percent:
aCoord = nscoord(text->mLineHeight.GetPercentValue() * font->mSize);
return PR_TRUE;
case eStyleUnit_Factor:
aCoord = nscoord(text->mLineHeight.GetFactorValue() * font->mSize);
return PR_TRUE;
default:
break;
}
break;
}
if (NS_FAILED(rv))
aCoord = 0;
return rv;
return PR_FALSE;
}
nsresult
@@ -2962,23 +2594,8 @@ nsComputedDOMStyle::GetBorderRadiusFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
nsStyleCoord coord;
GetStyleBorder()->mBorderRadius.Get(aSide, coord);
switch (coord.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(coord.GetCoordValue());
break;
case eStyleUnit_Percent:
if (mFrame) {
val->SetAppUnits(coord.GetPercentValue() * mFrame->GetSize().width);
} else {
val->SetPercent(coord.GetPercentValue());
}
break;
default:
NS_ERROR("Unexpected border radius unit");
break;
}
SetValueToCoord(val, GetStyleBorder()->mBorderRadius.Get(aSide, coord),
&nsComputedDOMStyle::GetFrameBorderRectWidth);
return CallQueryInterface(val, aValue);
}
@@ -3041,27 +2658,12 @@ nsComputedDOMStyle::GetMarginWidthFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
nsROCSSPrimitiveValue* val = GetROCSSPrimitiveValue();
NS_ENSURE_TRUE(val, NS_ERROR_OUT_OF_MEMORY);
FlushPendingReflows();
val->SetAppUnits(0);
if (!mFrame) {
nsStyleCoord c;
GetStyleMargin()->mMargin.Get(aSide, c);
switch (c.GetUnit()) {
case eStyleUnit_Coord:
val->SetAppUnits(c.GetCoordValue());
break;
case eStyleUnit_Percent:
val->SetPercent(c.GetPercentValue());
break;
case eStyleUnit_Auto:
val->SetIdent(nsGkAtoms::_auto);
break;
default:
break;
}
SetValueToCoord(val, GetStyleMargin()->mMargin.Get(aSide, c));
} else {
FlushPendingReflows();
val->SetAppUnits(mFrame->GetUsedMargin().side(aSide));
}
@@ -3088,8 +2690,160 @@ nsComputedDOMStyle::GetBorderStyleFor(PRUint8 aSide, nsIDOMCSSValue** aValue)
return CallQueryInterface(val, aValue);
}
void
nsComputedDOMStyle::SetValueToCoord(nsROCSSPrimitiveValue* aValue,
nsStyleCoord aCoord,
PercentageBaseGetter aPercentageBaseGetter,
const PRInt32 aTable[],
nscoord aMinAppUnits)
{
NS_PRECONDITION(aValue, "Must have a value to work with");
switch (aCoord.GetUnit()) {
case eStyleUnit_Normal:
aValue->SetIdent(nsGkAtoms::normal);
break;
case eStyleUnit_Auto:
aValue->SetIdent(nsGkAtoms::_auto);
break;
case eStyleUnit_Percent:
{
nscoord percentageBase;
if (aPercentageBaseGetter &&
(this->*aPercentageBaseGetter)(percentageBase)) {
nscoord val = nscoord(aCoord.GetPercentValue() * percentageBase);
aValue->SetAppUnits(PR_MAX(aMinAppUnits, val));
} else {
aValue->SetPercent(aCoord.GetPercentValue());
}
}
break;
case eStyleUnit_Factor:
aValue->SetNumber(aCoord.GetFactorValue());
break;
case eStyleUnit_Coord:
{
nscoord val = aCoord.GetCoordValue();
aValue->SetAppUnits(PR_MAX(aMinAppUnits, val));
}
break;
case eStyleUnit_Integer:
aValue->SetNumber(aCoord.GetIntValue());
break;
case eStyleUnit_Enumerated:
NS_ASSERTION(aTable, "Must have table to handle this case");
aValue->SetIdent(nsCSSProps::ValueToKeyword(aCoord.GetIntValue(),
aTable));
break;
case eStyleUnit_Chars:
// XXX we need a frame and a rendering context to calculate this, bug 281972, bug 282126.
aValue->SetAppUnits(0);
break;
case eStyleUnit_Null:
aValue->SetIdent(nsGkAtoms::none);
break;
default:
// eStyleUnit_Proportional
NS_ERROR("Can't handle this unit");
break;
}
}
#define COMPUTED_STYLE_MAP_ENTRY(_prop, _method) \
nscoord
nsComputedDOMStyle::StyleCoordToNSCoord(nsStyleCoord aCoord,
PercentageBaseGetter aPercentageBaseGetter)
{
NS_PRECONDITION(aPercentageBaseGetter, "Must have a percentage base getter");
switch (aCoord.GetUnit()) {
case eStyleUnit_Coord:
return aCoord.GetCoordValue();
case eStyleUnit_Percent:
{
nscoord percentageBase;
if ((this->*aPercentageBaseGetter)(percentageBase)) {
return nscoord(aCoord.GetPercentValue() * percentageBase);
}
}
// Fall through to returning 0 if we have no percentage base
default:
break;
}
return 0;
}
PRBool
nsComputedDOMStyle::GetFrameContentWidth(nscoord& aWidth)
{
if (!mFrame) {
return PR_FALSE;
}
FlushPendingReflows();
aWidth = mFrame->GetContentRect().width;
return PR_TRUE;
}
PRBool
nsComputedDOMStyle::GetCBContentWidth(nscoord& aWidth)
{
if (!mFrame) {
return PR_FALSE;
}
nsIFrame* container = GetContainingBlockFor(mFrame);
if (!container) {
return PR_FALSE;
}
FlushPendingReflows();
aWidth = container->GetContentRect().width;
return PR_TRUE;
}
PRBool
nsComputedDOMStyle::GetCBContentHeight(nscoord& aHeight)
{
if (!mFrame) {
return PR_FALSE;
}
nsIFrame* container = GetContainingBlockFor(mFrame);
if (!container) {
return PR_FALSE;
}
FlushPendingReflows();
aHeight = container->GetContentRect().height;
return PR_TRUE;
}
PRBool
nsComputedDOMStyle::GetFrameBorderRectWidth(nscoord& aWidth)
{
if (!mFrame) {
return PR_FALSE;
}
FlushPendingReflows();
aWidth = mFrame->GetSize().width;
return PR_TRUE;
}
#define COMPUTED_STYLE_MAP_ENTRY(_prop, _method) \
{ eCSSProperty_##_prop, &nsComputedDOMStyle::Get##_method }
const nsComputedDOMStyle::ComputedStyleMapEntry*

View File

@@ -112,8 +112,7 @@ private:
nsresult GetMarginWidthFor(PRUint8 aSide, nsIDOMCSSValue** aValue);
nsresult GetLineHeightCoord(const nsStyleText *aText,
nscoord& aCoord);
PRBool GetLineHeightCoord(nscoord& aCoord);
/* Properties Queryable as CSSValues */
@@ -273,6 +272,45 @@ private:
nsROCSSPrimitiveValue* GetROCSSPrimitiveValue();
nsDOMCSSValueList* GetROCSSValueList(PRBool aCommaDelimited);
nsresult SetToRGBAColor(nsROCSSPrimitiveValue* aValue, nscolor aColor);
/**
* A method to get a percentage base for a percentage value. Returns PR_TRUE
* if a percentage base value was determined, PR_FALSE otherwise.
*/
typedef PRBool (nsComputedDOMStyle::*PercentageBaseGetter)(nscoord&);
/**
* Method to set aValue to aCoord. If aCoord is a percentage value and
* aPercentageBaseGetter is not null, aPercentageBaseGetter is called. If it
* returns PR_TRUE, the percentage base it outputs in its out param is used
* to compute an nscoord value. If the getter is null or returns PR_FALSE,
* the percent value of aCoord is set as a percent value on aValue. aTable,
* if not null, is the keyword table to handle eStyleUnit_Enumerated. When
* calling SetAppUnits on aValue (for coord or percent values), the value
* passed in will be PR_MAX of the actual value in aCoord and the value in
* aMinAppUnits.
*
* XXXbz should caller pass in some sort of bitfield indicating which units
* can be expected or something?
*/
void SetValueToCoord(nsROCSSPrimitiveValue* aValue, nsStyleCoord aCoord,
PercentageBaseGetter aPercentageBaseGetter = nsnull,
const PRInt32 aTable[] = nsnull,
nscoord aMinAppUnits = nscoord_MIN);
/**
* If aCoord is a eStyleUnit_Coord returns the nscoord. If it's
* eStyleUnit_Percent, attempts to resolve the percentage base and returns the
* resulting nscoord. If it's some other unit or a percentge base can't be
* determined, returns 0.
*/
nscoord StyleCoordToNSCoord(nsStyleCoord aCoord,
PercentageBaseGetter aPercentageBaseGetter);
PRBool GetFrameContentWidth(nscoord& aWidth);
PRBool GetCBContentWidth(nscoord& aWidth);
PRBool GetCBContentHeight(nscoord& aWidth);
PRBool GetFrameBorderRectWidth(nscoord& aWidth);
struct ComputedStyleMapEntry
{

View File

@@ -0,0 +1,51 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = layout/style/test
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = test_bug365932.html \
$(NULL)
libs:: $(_TEST_FILES)
$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)

View File

@@ -0,0 +1,192 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=365932
-->
<head>
<title>Test for Bug 365932</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<style>
#content {
width: 800px;
padding: 0 200px;
border-width: 0 200px;
border-style: solid;
border-color: transparent
}
#content2 {
display: none;
}
#content > div, #content2 > div {
width: 400px;
padding: 0 100px;
border-width: 0 100px;
border-style: solid;
border-color: transparent
}
</style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=365932">Mozilla Bug 365932</a>
<p id="display"></p>
<div id="content">
<div id="column1" style="-moz-column-gap: 200px;"></div>
<div id="column2" style="-moz-column-gap: 50%;"></div>
<div id="indent1" style="text-indent: 400px"></div>
<div id="indent2" style="text-indent: 50%"></div>
<div id="minwidth1-1" style="min-width: 200px"></div>
<div id="minwidth1-2" style="min-width: 25%"></div>
<div id="minwidth2-1" style="min-width: 600px"></div>
<div id="minwidth2-2" style="min-width: 75%"></div>
<div id="radius1" style="-moz-border-radius: 80px"></div>
<div id="radius2" style="-moz-border-radius: 10%"></div>
<div id="outlineradius1" style="-moz-outline-radius: 160px"></div>
<div id="outlineradius2" style="-moz-outline-radius: 20%"></div>
</div>
<div id="content2" style="display: none">
<div id="column3" style="-moz-column-gap: 200px;"></div>
<div id="column4" style="-moz-column-gap: 50%;"></div>
<div id="indent3" style="text-indent: 400px"></div>
<div id="indent4" style="text-indent: 50%"></div>
<div id="minwidth1-3" style="min-width: 200px"></div>
<div id="minwidth1-4" style="min-width: 25%"></div>
<div id="minwidth2-3" style="min-width: 600px"></div>
<div id="minwidth2-4" style="min-width: 75%"></div>
<div id="radius3" style="-moz-border-radius: 80px"></div>
<div id="radius4" style="-moz-border-radius: 10%"></div>
<div id="outlineradius3" style="-moz-outline-radius: 160px"></div>
<div id="outlineradius4" style="-moz-outline-radius: 20%"></div>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 365932 **/
document.body.offsetWidth;
doATest("-moz-column-gap", "column", 200, 50);
doATest("text-indent", "indent", 400, 50);
//doATest("min-width", "minwidth1-", 200, 25);
//doATest("min-width", "minwidth2-", 600, 75);
// doATest("width", "minwidth2-", 600, 0);
doATest("-moz-border-radius-topleft", "radius", 80, 10);
doATest("-moz-outline-radius-topleft", "outlineradius", 160, 20);
function style(id) {
return document.defaultView.getComputedStyle($(id), "");
}
function round(num, decimals) {
return Math.round(num * Math.pow(10, decimals))/Math.pow(10, decimals);
}
function doATest(propName, idBase, coordVal, percentVal)
{
var cssPropertiesPropName = "";
var parts = propName.split("-");
ok(parts.length > 0, "prop name", "Empty css prop name");
var i;
if (parts[0]) {
i = 0;
} else {
is(parts[1], "moz", "Testing an extension property that's not -moz");
ok(parts.length > 2, "prop name 2", "Bogus -moz prop name");
cssPropertiesPropName = "Moz";
i = 2;
}
for (; i < parts.length; ++i) {
var part = parts[i];
isnot(part, "", "Must have a nonempty part");
if (cssPropertiesPropName) {
cssPropertiesPropName += part.charAt(0).toUpperCase() +
part.substring(1, part.length);
} else {
cssPropertiesPropName += part;
}
}
var decl = style(idBase+"1");
is(decl[cssPropertiesPropName], coordVal+"px",
"Coord " + propName + " displayed");
is(decl.getPropertyCSSValue(propName).cssValueType,
CSSValue.CSS_PRIMITIVE_VALUE,
"displayed coord " + propName + " is primitive value");
is(decl.getPropertyCSSValue(propName).primitiveType,
CSSPrimitiveValue.CSS_PX, "displayed coord " + propName + " is px");
is(decl.getPropertyCSSValue(propName).cssText, coordVal + "px",
"displayed coord " + propName + " length");
/* Since floats are only accurate to like 6 decimal places, round to 3 decimal
places here. */
is(round(decl.getPropertyCSSValue(propName)
.getFloatValue(CSSPrimitiveValue.CSS_PX),
3),
coordVal, "displayed coord " + propName + " length as float value");
decl = style(idBase+"2");
is(decl[cssPropertiesPropName], coordVal+"px",
"Percent " + propName + " displayed");
is(decl.getPropertyCSSValue(propName).cssValueType,
CSSValue.CSS_PRIMITIVE_VALUE,
"displayed percent " + propName + " is primitive value");
is(decl.getPropertyCSSValue(propName).primitiveType,
CSSPrimitiveValue.CSS_PX, "displayed percent " + propName + " is px");
is(decl.getPropertyCSSValue(propName).cssText, coordVal+"px",
"displayed percent " + propName + " length");
/* Since floats are only accurate to like 6 decimal places, round to 3 decimal
places here. */
is(round(decl.getPropertyCSSValue(propName)
.getFloatValue(CSSPrimitiveValue.CSS_PX),
3),
coordVal, "displayed percent " + propName + " length as float value");
if (percentVal) {
decl = style(idBase+"3");
is(decl[cssPropertiesPropName], coordVal+"px",
"Coord " + propName +" undisplayed");
is(decl.getPropertyCSSValue(propName).cssValueType,
CSSValue.CSS_PRIMITIVE_VALUE,
"undisplayed coord " + propName + " is primitive value");
is(decl.getPropertyCSSValue(propName).primitiveType,
CSSPrimitiveValue.CSS_PX, "undisplayed coord " + propName + " is px");
is(decl.getPropertyCSSValue(propName).cssText, coordVal+"px",
"undisplayed coord " + propName + " length");
/* Since floats are only accurate to like 6 decimal places, round to 3 decimal
places here. */
is(round(decl.getPropertyCSSValue(propName)
.getFloatValue(CSSPrimitiveValue.CSS_PX),
3),
coordVal, "undisplayed coord " + propName + " length as float value");
decl = style(idBase+"4");
is(decl[cssPropertiesPropName], percentVal+"%",
"Percent " + propName + " undisplayed");
is(decl.getPropertyCSSValue(propName).cssValueType,
CSSValue.CSS_PRIMITIVE_VALUE,
"undisplayed percent " + propName + " is primitive value");
is(decl.getPropertyCSSValue(propName).primitiveType,
CSSPrimitiveValue.CSS_PERCENTAGE,
"undisplayed percent " + propName + " is percent");
is(decl.getPropertyCSSValue(propName).cssText, percentVal+"%",
"undisplayed percent " + propName + " length");
/* Since floats are only accurate to like 6 decimal places, round to 3 decimal
places here. */
is(round(decl.getPropertyCSSValue(propName)
.getFloatValue(CSSPrimitiveValue.CSS_PERCENTAGE),
3),
percentVal, "undisplayed percent " + propName + " percentage as float value");
}
}
</script>
</pre>
</body>
</html>