diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index b291a83bac53..c44a9e7978d7 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -1148,10 +1148,12 @@ nsPresContext::SetImageAnimationModeExternal(PRUint16 aMode) } already_AddRefed -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; } diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index 0f058071d892..e3094aed16ae 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -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) - GetMetricsFor(const nsFont& aFont); + GetMetricsFor(const nsFont& aFont, PRBool aUseUserFontSet = PR_TRUE); /** * Get the default font corresponding to the given ID. This object is diff --git a/layout/style/crashtests/473892-1.html b/layout/style/crashtests/473892-1.html new file mode 100644 index 000000000000..362e38a6d912 --- /dev/null +++ b/layout/style/crashtests/473892-1.html @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/layout/style/crashtests/crashtests.list b/layout/style/crashtests/crashtests.list index 01f7306fded3..4064f75ea608 100644 --- a/layout/style/crashtests/crashtests.list +++ b/layout/style/crashtests/crashtests.list @@ -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 diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 81e149c1a4f1..0261333af9f6 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -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 fm = aPresContext->GetMetricsFor(font); + nsCOMPtr 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 fm = aPresContext->GetMetricsFor(font); + nsCOMPtr fm = + aPresContext->GetMetricsFor(font, aUseUserFontSet); nsCOMPtr 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