Avoid building user font set when handling units involving font metrics in media query expressions. (Bug 473892) r+sr=bzbarsky

This commit is contained in:
L. David Baron 2009-01-16 19:44:21 -08:00
parent e77bcd1f39
commit 7e835827aa
5 changed files with 37 additions and 10 deletions

View File

@ -1148,10 +1148,12 @@ nsPresContext::SetImageAnimationModeExternal(PRUint16 aMode)
}
already_AddRefed<nsIFontMetrics>
nsPresContext::GetMetricsFor(const nsFont& aFont)
nsPresContext::GetMetricsFor(const nsFont& aFont, PRBool aUseUserFontSet)
{
nsIFontMetrics* metrics = nsnull;
mDeviceContext->GetMetricsFor(aFont, mLangGroup, GetUserFontSet(), metrics);
mDeviceContext->GetMetricsFor(aFont, mLangGroup,
aUseUserFontSet ? GetUserFontSet() : nsnull,
metrics);
return metrics;
}

View File

@ -287,9 +287,14 @@ public:
/**
* Get the font metrics for a given font.
*
* If aUseUserFontSet is false, don't build or use the user font set.
* This is intended only for nsRuleNode::CalcLengthWithInitialFont
* (which is used from media query matching, which is in turn called
* when building the user font set).
*/
NS_HIDDEN_(already_AddRefed<nsIFontMetrics>)
GetMetricsFor(const nsFont& aFont);
GetMetricsFor(const nsFont& aFont, PRBool aUseUserFontSet = PR_TRUE);
/**
* Get the default font corresponding to the given ID. This object is

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@media (width: 5ex) { }
</style>
</head>
<body>
</body>
</html>

View File

@ -27,5 +27,6 @@ load 460217-1.html
load 466845-1.html
HTTP(..) load 472237-1.html
load 473720-1.html
load 473892-1.html
load 473914-1.html
load long-url-list-stack-overflow.html

View File

@ -171,6 +171,10 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue,
const nsStyleFont* aStyleFont,
nsStyleContext* aStyleContext,
nsPresContext* aPresContext,
// aUseUserFontSet should always be PR_TRUE
// except when called from
// CalcLengthWithInitialFont.
PRBool aUseUserFontSet,
PRBool& aInherited)
{
NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");
@ -202,7 +206,8 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue,
case eCSSUnit_XHeight: {
nsFont font = aStyleFont->mFont;
font.size = aFontSize;
nsCOMPtr<nsIFontMetrics> fm = aPresContext->GetMetricsFor(font);
nsCOMPtr<nsIFontMetrics> fm =
aPresContext->GetMetricsFor(font, aUseUserFontSet);
nscoord xHeight;
fm->GetXHeight(xHeight);
return NSToCoordRoundWithClamp(aValue.GetFloatValue() * float(xHeight));
@ -210,7 +215,8 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue,
case eCSSUnit_Char: {
nsFont font = aStyleFont->mFont;
font.size = aFontSize;
nsCOMPtr<nsIFontMetrics> fm = aPresContext->GetMetricsFor(font);
nsCOMPtr<nsIFontMetrics> fm =
aPresContext->GetMetricsFor(font, aUseUserFontSet);
nsCOMPtr<nsIThebesFontMetrics> tfm(do_QueryInterface(fm));
gfxFloat zeroWidth = (tfm->GetThebesFontGroup()->GetFontAt(0)
->GetMetrics().zeroOrAveCharWidth);
@ -234,7 +240,8 @@ nsRuleNode::CalcLength(const nsCSSValue& aValue,
{
NS_ASSERTION(aStyleContext, "Must have style data");
return CalcLengthWith(aValue, -1, nsnull, aStyleContext, aPresContext, aInherited);
return CalcLengthWith(aValue, -1, nsnull, aStyleContext, aPresContext,
PR_TRUE, aInherited);
}
/* Inline helper function to redirect requests to CalcLength. */
@ -254,7 +261,7 @@ nsRuleNode::CalcLengthWithInitialFont(nsPresContext* aPresContext,
nsStyleFont defaultFont(aPresContext);
PRBool inherited;
return CalcLengthWith(aValue, -1, &defaultFont, nsnull, aPresContext,
inherited);
PR_FALSE, inherited);
}
#define SETCOORD_NORMAL 0x01 // N
@ -2337,7 +2344,7 @@ nsRuleNode::SetFontSize(nsPresContext* aPresContext,
// for scriptlevel changes. A scriptlevel change between us and the parent
// is simply ignored.
*aSize = CalcLengthWith(aFontData.mSize, aParentSize, aParentFont, nsnull,
aPresContext, aInherited);
aPresContext, PR_TRUE, aInherited);
zoom = aFontData.mSize.IsFixedLengthUnit() ||
aFontData.mSize.GetUnit() == eCSSUnit_Pixel;
}
@ -2579,8 +2586,8 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
// to the parent font, or the size definitions are circular and we
//
aFont->mScriptMinSize =
CalcLengthWith(aFontData.mScriptMinSize, aParentFont->mSize, aParentFont, nsnull,
aPresContext, aInherited);
CalcLengthWith(aFontData.mScriptMinSize, aParentFont->mSize, aParentFont,
nsnull, aPresContext, PR_TRUE, aInherited);
}
// -moz-script-size-multiplier: factor, inherit, initial