Don't resolve a new context for the root when we're computing rem units for the root. (Bug 478321) r=bzbarsky

This commit is contained in:
L. David Baron 2009-08-01 08:53:40 -07:00
parent 25226ca48a
commit 6fb9ce56f5
5 changed files with 95 additions and 2 deletions

View File

@ -0,0 +1 @@
<html xmlns="http://www.w3.org/1999/xhtml" style="display: table; float: left; line-height: 1rem;"/>

View File

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

View File

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

View File

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

View File

@ -0,0 +1,81 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=478321
-->
<head>
<title>Test for CSS 'rem' unit</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478321">Mozilla Bug 478321</a>
<p id="display"></p>
<p id="display2"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for CSS 'rem' unit **/
function px_to_num(str)
{
return Number(String(str).match(/^([\d.]+)px$/)[1]);
}
function fs(elt)
{
return px_to_num(getComputedStyle(elt, "").fontSize);
}
var html = document.documentElement;
var body = document.body;
var p = document.getElementById("display");
var p2 = document.getElementById("display2");
html.style.font = "-moz-initial";
var defaultFontSize = fs(html);
// NOTE: This test assumes that the default font size is an
// integral number of pixels (which is always the case at present).
// If that ever becomes false, the calls to "is" may need to be replaced by
// calls to "isapprox" that allows errors of up to some small fraction
// of a pixel.
html.style.fontSize = "3rem";
is(fs(html), 3 * defaultFontSize,
"3rem on root should triple root's font size");
body.style.font = "-moz-initial";
is(fs(body), defaultFontSize,
"-moz-initial should produce initial font size");
body.style.fontSize = "1em";
is(fs(body), 3 * defaultFontSize, "1em should inherit from parent");
body.style.fontSize = "200%";
is(fs(body), 6 * defaultFontSize, "200% should double parent");
body.style.fontSize = "2rem";
is(fs(body), 6 * defaultFontSize, "2rem should double root");
p.style.font = "inherit";
is(fs(p), 6 * defaultFontSize, "inherit should inherit from parent");
p2.style.fontSize = "2rem";
is(fs(p2), 6 * defaultFontSize, "2rem should double root");
body.style.font = "-moz-initial";
is(fs(p), defaultFontSize, "inherit should inherit from parent");
is(fs(p2), 6 * defaultFontSize, "2rem should double root");
body.style.fontSize = "5em";
html.style.fontSize = "200%";
is(fs(p), 10 * defaultFontSize, "inherit should inherit from parent");
is(fs(p2), 4 * defaultFontSize, "2rem should double root");
// Make things readable again.
html.style.fontSize = "1em";
body.style.fontSize = "1em";
</script>
</pre>
</body>
</html>