From 6fb9ce56f56688ccfb44275c9a060357b8928e20 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Sat, 1 Aug 2009 08:53:40 -0700 Subject: [PATCH] Don't resolve a new context for the root when we're computing rem units for the root. (Bug 478321) r=bzbarsky --- layout/style/crashtests/478321-1.xhtml | 1 + layout/style/crashtests/crashtests.list | 1 + layout/style/nsRuleNode.cpp | 13 +++- layout/style/test/Makefile.in | 1 + layout/style/test/test_rem_unit.html | 81 +++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 layout/style/crashtests/478321-1.xhtml create mode 100644 layout/style/test/test_rem_unit.html diff --git a/layout/style/crashtests/478321-1.xhtml b/layout/style/crashtests/478321-1.xhtml new file mode 100644 index 00000000000..654e11c1062 --- /dev/null +++ b/layout/style/crashtests/478321-1.xhtml @@ -0,0 +1 @@ + diff --git a/layout/style/crashtests/crashtests.list b/layout/style/crashtests/crashtests.list index fe390f391c1..24269ab78ae 100644 --- a/layout/style/crashtests/crashtests.list +++ b/layout/style/crashtests/crashtests.list @@ -36,6 +36,7 @@ HTTP(..) load 472237-1.html load 473720-1.html load 473892-1.html load 473914-1.html +load 478321-1.xhtml skip load long-url-list-stack-overflow.html # skipped due to being slow (bug 477490) load 495269-1.html load 495269-2.html diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 47625d13eab..c6f49c85094 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -172,6 +172,7 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue, { NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit"); NS_ASSERTION(aStyleFont || aStyleContext, "Must have style data"); + NS_ASSERTION(!aStyleFont || !aStyleContext, "Duplicate sources of data"); NS_ASSERTION(aPresContext, "Must have prescontext"); if (aValue.IsFixedLengthUnit()) { @@ -197,9 +198,17 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue, if (aUseProvidedRootEmSize) { // We should use the provided aFontSize as the reference length to - // scale. This only happens when we are calculating something on the - // root element, in which case aFontSize is already the value we want. + // scale. This only happens when we are calculating font-size or + // an equivalent (scriptminsize or CalcLengthWithInitialFont) on + // the root element, in which case aFontSize is already the + // value we want. rootFontSize = aFontSize; + } else if (aStyleContext && !aStyleContext->GetParent()) { + // This is the root element (XXX we don't really know this, but + // nsRuleNode::SetFont makes the same assumption!), so we should + // use GetStyleFont on this context to get the root element's + // font size. + rootFontSize = aStyleFont->mFont.size; } else { // This is not the root element or we are calculating something other // than font size, so rem is relative to the root element's font size. diff --git a/layout/style/test/Makefile.in b/layout/style/test/Makefile.in index ac5c876d5f2..8abd57dc4bd 100644 --- a/layout/style/test/Makefile.in +++ b/layout/style/test/Makefile.in @@ -124,6 +124,7 @@ _TEST_FILES = test_acid3_test46.html \ test_property_database.html \ test_priority_preservation.html \ test_property_syntax_errors.html \ + test_rem_unit.html \ test_selectors.html \ test_selectors_on_anonymous_content.html \ test_shorthand_property_getters.html \ diff --git a/layout/style/test/test_rem_unit.html b/layout/style/test/test_rem_unit.html new file mode 100644 index 00000000000..94fdc9656c6 --- /dev/null +++ b/layout/style/test/test_rem_unit.html @@ -0,0 +1,81 @@ + + + + + Test for CSS 'rem' unit + + + + + +Mozilla Bug 478321 +

+

+ +
+
+
+ +