Bug 1511138 - Never return styles for disconnected elements. r=smaug
☠☠ backed out by 90189bd84466 ☠ ☠
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 30 Nov 2018 18:01:48 +0100
changeset 508759 e601a2fbd07720ad837cef0567233f2a631e038a
parent 508758 bae83f7c52f51ca0470b4bc353de4f56f8c7d128
child 508760 d2d3e7a822b5f4c78e58d6552bbd1c8fa431a8ef
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)) {