Bug 580685. We might not have a root element to resolve 'rem' against. r=dbaron
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 22 Jul 2010 17:33:37 -0400
changeset 48099 0a34cbad71b4001ba0a75a381d25427a537e1dce
parent 48098 c20a6d551bbfb985ba29cb75166259c24e31f386
child 48100 228c38e68ddace157f5610e0b8762a324b7b9b40
push id14571
push userbzbarsky@mozilla.com
push dateThu, 22 Jul 2010 21:35:07 +0000
treeherdermozilla-central@9d16542a1af2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs580685
milestone2.0b3pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 580685. We might not have a root element to resolve 'rem' against. r=dbaron
layout/style/crashtests/580685.html
layout/style/crashtests/crashtests.list
layout/style/nsRuleNode.cpp
layout/style/test/Makefile.in
layout/style/test/test_bug580685.html
new file mode 100644
--- /dev/null
+++ b/layout/style/crashtests/580685.html
@@ -0,0 +1,10 @@
+<html>
+<head></head>
+<body style="outline-offset: 0.1rem; ">
+<script>
+var body = document.body;
+document.removeChild(document.documentElement);
+var compstyle = window.getComputedStyle(body, null).getPropertyValue('outline-offset');
+</script>
+</body>
+</html>
\ No newline at end of file
--- a/layout/style/crashtests/crashtests.list
+++ b/layout/style/crashtests/crashtests.list
@@ -54,8 +54,9 @@ load 509156-1.html
 load 509569-1.html
 load 524252-1.html
 load font-face-truncated-src.html 
 load 536789-1.html
 load 565248-1.html
 load 558943-1.xhtml
 load 571105-1.xhtml
 load 573127-1.html
+load 580685.html
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -272,22 +272,25 @@ static nscoord CalcLengthWith(const nsCS
         rootFontSize = styleFont->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.
         nsRefPtr<nsStyleContext> rootStyle;
         const nsStyleFont *rootStyleFont = styleFont;
         Element* docElement = aPresContext->Document()->GetRootElement();
 
-        rootStyle = aPresContext->StyleSet()->ResolveStyleFor(docElement,
-                                                              nsnull);
-        if (rootStyle) {
-          rootStyleFont = rootStyle->GetStyleFont();
-          rootFontSize = rootStyleFont->mFont.size;
+        if (docElement) {
+          rootStyle = aPresContext->StyleSet()->ResolveStyleFor(docElement,
+                                                                nsnull);
+          if (rootStyle) {
+            rootStyleFont = rootStyle->GetStyleFont();
+          }
         }
+
+        rootFontSize = rootStyleFont->mFont.size;
       }
 
       return ScaleCoord(aValue, float(rootFontSize));
     }
     case eCSSUnit_EM: {
       return ScaleCoord(aValue, float(aFontSize));
       // XXX scale against font metrics height instead?
     }
--- a/layout/style/test/Makefile.in
+++ b/layout/style/test/Makefile.in
@@ -127,16 +127,17 @@ GARBAGE += css_properties.js
 		test_bug453896_deck.html \
 		test_bug470769.html \
 		test_bug499655.html \
 		test_bug499655.xhtml \
 		test_bug517224.html \
 		test_bug524175.html \
 		test_bug534804.html \
 		test_bug573255.html \
+		test_bug580685.html \
 		test_cascade.html \
 		test_compute_data_with_start_struct.html \
 		test_computed_style_no_pseudo.html \
 		test_css_cross_domain.html \
 		test_css_eof_handling.html \
 		test_descriptor_storage.html \
 		test_descriptor_syntax_errors.html \
 		test_dont_use_document_colors.html \
new file mode 100644
--- /dev/null
+++ b/layout/style/test/test_bug580685.html
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=580685
+-->
+<head>
+  <title>Test for Bug 580685</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=580685">Mozilla Bug 580685</a>
+<p id="display">
+  <iframe id="f" src="data:text/html,<body style='outline-offset: 1rem'>">
+  </iframe>
+</p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 580685 **/
+SimpleTest.waitForExplicitFinish()
+addLoadEvent(function() {
+  var doc = $("f").contentDocument;
+  var b = doc.body;
+  doc.removeChild(doc.documentElement);
+  is(doc.defaultView.getComputedStyle(b, "").outlineOffset,
+     doc.defaultView.getComputedStyle(b, "").fontSize,
+     "1rem did not compute correctly");
+  SimpleTest.finish();
+});
+
+
+
+
+</script>
+</pre>
+</body>
+</html>