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
This commit is contained in:
Emilio Cobos Álvarez 2018-11-30 18:01:48 +01:00
Родитель b7eb50f8ed
Коммит 5cf44383eb
1 изменённых файлов: 6 добавлений и 5 удалений

Просмотреть файл

@ -508,11 +508,12 @@ already_AddRefed<ComputedStyle> nsComputedDOMStyle::DoGetComputedStyleNoFlush(
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;
}