Bug 1066554 - Load stylesheets when instantiated in shadow-dom. r=bz
authorJames Kitchener <jkitch.bug@internode.on.net>
Thu, 18 Sep 2014 06:54:00 -0400
changeset 230607 cf81dcd4302cd1a2bc46de7ee0d9c2a44a7a8cb4
parent 230606 247979f5c8def6e2dfd3556566b39cc48a9cc068
child 230608 b946eb96215c3b6d12291ceb78ab539a66be1595
push id611
push userraliiev@mozilla.com
push dateMon, 05 Jan 2015 23:23:16 +0000
treeherdermozilla-release@345cd3b9c445 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1066554
milestone35.0a1
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 1066554 - Load stylesheets when instantiated in shadow-dom. r=bz
content/svg/content/src/SVGForeignObjectElement.cpp
content/svg/content/src/SVGSVGElement.cpp
content/xul/content/src/nsXULElement.cpp
dom/mathml/nsMathMLElement.cpp
layout/reftests/bugs/1066554-1-ref.html
layout/reftests/bugs/1066554-1.html
layout/reftests/bugs/reftest.list
layout/reftests/mathml/reftest.list
layout/reftests/mathml/shadow-dom-1-ref.html
layout/reftests/mathml/shadow-dom-1.html
--- a/content/svg/content/src/SVGForeignObjectElement.cpp
+++ b/content/svg/content/src/SVGForeignObjectElement.cpp
@@ -111,25 +111,26 @@ SVGForeignObjectElement::BindToTree(nsID
                                     nsIContent* aBindingParent,
                                     bool aCompileEventHandlers)
 {
   nsresult rv = SVGGraphicsElement::BindToTree(aDocument, aParent,
                                                aBindingParent,
                                                aCompileEventHandlers);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (aDocument && aDocument->IsSVG()) {
+  nsIDocument* doc = GetComposedDoc();
+  if (doc && doc->IsSVG()) {
     // We assume that we're going to have HTML content, so we ensure that the
     // UA style sheets that nsDocumentViewer::CreateStyleSet skipped when
     // it saw the document was an SVG document are loaded.
     //
     // We setup these style sheets during binding, not element construction,
     // because elements can be moved from the document that creates them to
     // another document.
-    aDocument->AsSVGDocument()->EnsureNonSVGUserAgentStyleSheetsLoaded();
+    doc->AsSVGDocument()->EnsureNonSVGUserAgentStyleSheetsLoaded();
   }
 
   return rv;
 }
 
 NS_IMETHODIMP_(bool)
 SVGForeignObjectElement::IsAttributeMapped(const nsIAtom* name) const
 {
--- a/content/svg/content/src/SVGSVGElement.cpp
+++ b/content/svg/content/src/SVGSVGElement.cpp
@@ -751,22 +751,22 @@ SVGSVGElement::BindToTree(nsIDocument* a
     }
   }
 
   nsresult rv = SVGSVGElementBase::BindToTree(aDocument, aParent,
                                               aBindingParent,
                                               aCompileEventHandlers);
   NS_ENSURE_SUCCESS(rv,rv);
 
-  if (aDocument) {
+  nsIDocument* doc = GetComposedDoc();
+  if (doc) {
     // Setup the style sheet during binding, not element construction,
     // because we could move the root SVG element from the document
     // that created it to another document.
-    aDocument->
-      EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::SVGSheet());
+    doc->EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::SVGSheet());
   }
 
   if (mTimedDocumentRoot && smilController) {
     rv = mTimedDocumentRoot->SetParent(smilController);
     if (mStartAnimationOnBindToTree) {
       mTimedDocumentRoot->Begin();
       mStartAnimationOnBindToTree = false;
     }
--- a/content/xul/content/src/nsXULElement.cpp
+++ b/content/xul/content/src/nsXULElement.cpp
@@ -834,32 +834,33 @@ nsXULElement::BindToTree(nsIDocument* aD
     nsContentUtils::AddScriptRunner(new XULInContentErrorReporter(aDocument));
   }
 
   nsresult rv = nsStyledElement::BindToTree(aDocument, aParent,
                                             aBindingParent,
                                             aCompileEventHandlers);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (aDocument &&
-      !aDocument->LoadsFullXULStyleSheetUpFront() &&
-      !aDocument->IsUnstyledDocument()) {
+  nsIDocument* doc = GetComposedDoc();
+  if (doc &&
+      !doc->LoadsFullXULStyleSheetUpFront() &&
+      !doc->IsUnstyledDocument()) {
 
     // To save CPU cycles and memory, non-XUL documents only load the user
     // agent style sheet rules for a minimal set of XUL elements such as
     // 'scrollbar' that may be created implicitly for their content (those
     // rules being in minimal-xul.css).  This is where we make sure that all
     // the other XUL UA style sheet rules (xul.css) have been loaded if the
     // minimal set is not sufficient.
     //
     // We do this during binding, not element construction, because elements
     // can be moved from the document that creates them to another document.
 
     if (!XULElementsRulesInMinimalXULSheet(Tag())) {
-      aDocument->EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::XULSheet());
+      doc->EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::XULSheet());
       // To keep memory usage down it is important that we try and avoid
       // pulling xul.css into non-XUL documents. That should be very rare, and
       // for HTML we currently should only pull it in if the document contains
       // an <audio> or <video> element. This assertion is here to make sure
       // that we don't fail to notice if a change to bindings causes us to
       // start pulling in xul.css much more frequently. If this assertion
       // fails then we need to figure out why, and how we can continue to avoid
       // pulling in xul.css.
--- a/dom/mathml/nsMathMLElement.cpp
+++ b/dom/mathml/nsMathMLElement.cpp
@@ -97,29 +97,32 @@ nsMathMLElement::BindToTree(nsIDocument*
 
   nsresult rv = nsMathMLElementBase::BindToTree(aDocument, aParent,
                                                 aBindingParent,
                                                 aCompileEventHandlers);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (aDocument) {
     aDocument->RegisterPendingLinkUpdate(this);
-    
-    if (!aDocument->GetMathMLEnabled()) {
+  }
+
+  nsIDocument* doc = GetComposedDoc();
+  if (doc) {
+    if (!doc->GetMathMLEnabled()) {
       // Enable MathML and setup the style sheet during binding, not element
       // construction, because we could move a MathML element from the document
       // that created it to another document.
-      aDocument->SetMathMLEnabled();
-      aDocument->
+      doc->SetMathMLEnabled();
+      doc->
         EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::MathMLSheet());
 
       // Rebuild style data for the presshell, because style system
       // optimizations may have taken place assuming MathML was disabled.
       // (See nsRuleNode::CheckSpecifiedProperties.)
-      nsCOMPtr<nsIPresShell> shell = aDocument->GetShell();
+      nsCOMPtr<nsIPresShell> shell = doc->GetShell();
       if (shell) {
         shell->GetPresContext()->PostRebuildAllStyleDataEvent(nsChangeHint(0));
       }
     }
   }
 
   return rv;
 }
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/1066554-1-ref.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<meta charset="utf-8">
+<title>Test for bug 1066554 - Shadow DOM loads SVG stylesheets as needed</title>
+<body>
+  <svg width="50px" height="10px">
+    <switch>
+      <foreignObject width="50px" height="50px">
+        <div style="width: 100px; height: 10px; background: red;"></div>
+      </foreignObject>
+    </switch>
+  </svg>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/1066554-1.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<meta charset="utf-8">
+<title>Test for bug 1066554 - Shadow DOM loads SVG stylesheets as needed</title>
+<body>
+  <div id="x"></div>
+  <script>
+    function insertShadowSVG() {
+      var x = document.getElementById("x");
+      x.createShadowRoot();
+      x.shadowRoot.innerHTML =
+        '<svg width="50px" height="10px"> \
+           <switch> \
+             <foreignObject width="50px" height="50px"> \
+               <div style="width: 100px; height: 10px; background: red;"></div> \
+             </foreignObject> \
+           </switch> \
+         </svg>';
+      document.documentElement.removeAttribute("class");
+    }
+    window.addEventListener("MozReftestInvalidate", insertShadowSVG, false);
+  </script>
+</body>
+</html>
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -1828,8 +1828,9 @@ pref(browser.display.use_document_fonts,
 == 1049499-1.html 1049499-1-ref.html
 == 1050788-1.html about:blank
 == 1053035-1-flex.html 1053035-1-ref.html
 test-pref(layout.css.grid.enabled,true) == 1053035-1-grid.html 1053035-1-ref.html
 == 1059167-1.html 1059167-1-ref.html
 == 1059498-1.html 1059498-1-ref.html
 == 1059498-2.html 1059498-1-ref.html
 == 1059498-3.html 1059498-1-ref.html
+test-pref(dom.webcomponents.enabled,true) == 1066554-1.html 1066554-1-ref.html
--- a/layout/reftests/mathml/reftest.list
+++ b/layout/reftests/mathml/reftest.list
@@ -313,8 +313,9 @@ fuzzy-if(OSX,1,100) == mfrac-C-1.html mf
 random-if(winWidget&&!/^Windows\x20NT\x205\.1/.test(http.oscpu)) == mfrac-C-2.html mfrac-C-2-ref.html
 == mfrac-C-3.html mfrac-C-3-ref.html
 == mfrac-C-4.html mfrac-C-4-ref.html
 fuzzy-if(OSX,1,100) == mfrac-D-1.html mfrac-D-1-ref.html
 random-if(winWidget&&!/^Windows\x20NT\x205\.1/.test(http.oscpu)) == mfrac-D-2.html mfrac-D-2-ref.html
 == mfrac-D-3.html mfrac-D-3-ref.html
 == mfrac-D-4.html mfrac-D-4-ref.html
 == mfrac-E-1.html mfrac-E-1-ref.html
+test-pref(dom.webcomponents.enabled,true) == shadow-dom-1.html shadow-dom-1-ref.html
new file mode 100644
--- /dev/null
+++ b/layout/reftests/mathml/shadow-dom-1-ref.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<meta charset="utf-8">
+<title>Test for bug 1066554 - Shadow DOM loads MathML stylesheets as needed</title>
+<body>
+  <math>
+    <msup>
+      <mi>X</mi>
+      <mi>X</mi>
+    </msup>
+  </math>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/mathml/shadow-dom-1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+<meta charset="utf-8">
+<title>Test for bug 1066554 - Shadow DOM loads MathML stylesheets as needed</title>
+<body>
+  <div id="x"></div>
+  <script>
+    function insertShadowMathML() {
+      var x = document.getElementById("x");
+      x.createShadowRoot();
+      x.shadowRoot.innerHTML =
+        '<math><msup><mi>X</mi><mi>X</mi></msup></math>';
+      document.documentElement.removeAttribute("class");
+    }
+    window.addEventListener("MozReftestInvalidate", insertShadowMathML, false);
+  </script>
+</body>
+</html>