Bug 1511138 - Never return styles for disconnected elements. r=smaug
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 30 Nov 2018 18:01:48 +0100
changeset 508899 7159c6b7e745c9fff5012d08bfb12240dd96202c
parent 508898 a6ae557a428bb1a50478db2fa6a868fb91372856
child 508900 1879534289a4034a18002756d80cbf99f73d18da
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1511138
milestone65.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 1511138 - Never return styles for disconnected elements. r=smaug https://drafts.csswg.org/cssom/#dom-window-getcomputedstyle says: > If elt is connected, part of the flat tree, and its shadow-including root... WebKit and Blink already do this, and we do it already except for cross-document situations, where we can end up with a PresShell even if GetPresShellForContent returns null. The style system should be able to rely on ShadowRoots having a non-null shadow host. Differential Revision: https://phabricator.services.mozilla.com/D13472
layout/style/nsComputedDOMStyle.cpp
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -503,21 +503,22 @@ already_AddRefed<ComputedStyle> nsComput
     }
   }
 
   CSSPseudoElementType pseudoType = GetPseudoType(aPseudo);
   if (aPseudo && pseudoType >= CSSPseudoElementType::Count) {
     return nullptr;
   }
 
-  if (aElement->IsInNativeAnonymousSubtree() && !aElement->IsInComposedDoc()) {
-    // Normal web content can't access NAC, but Accessibility, DevTools and
-    // Editor use this same API and this may get called for anonymous content.
-    // Computing the style of a pseudo-element that doesn't have a parent
-    // doesn't really make sense.
+  if (!aElement->IsInComposedDoc()) {
+    // Don't return styles for disconnected elements, that makes no sense. This
+    // can only happen with a non-null presShell for cross-document calls.
+    //
+    // FIXME(emilio, bug 1483798): This should also not return styles for
+    // elements outside of the flat tree, not just outside of the document.
     return nullptr;
   }
 
   // XXX the !aElement->IsHTMLElement(nsGkAtoms::area)
   // check is needed due to bug 135040 (to avoid using
   // mPrimaryFrame). Remove it once that's fixed.
   if (inDocWithShell && aStyleType == eAll &&
       !aElement->IsHTMLElement(nsGkAtoms::area)) {