mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-03 05:47:29 +09:00
Issue #2135 - Bug 1410578: Make <link rel="stylesheet"> work in shadow trees
This commit is contained in:
parent
45c179d01b
commit
588c2154a5
4 changed files with 21 additions and 49 deletions
|
|
@ -304,14 +304,6 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a ShadowRoot because link elements are inert in a
|
|
||||||
// ShadowRoot.
|
|
||||||
ShadowRoot* containingShadow = thisContent->GetContainingShadow();
|
|
||||||
if (thisContent->IsHTMLElement(nsGkAtoms::link) &&
|
|
||||||
(aOldShadowRoot || containingShadow)) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXXheycam ServoStyleSheets do not support <style scoped>.
|
// XXXheycam ServoStyleSheets do not support <style scoped>.
|
||||||
Element* oldScopeElement = nullptr;
|
Element* oldScopeElement = nullptr;
|
||||||
if (mStyleSheet) {
|
if (mStyleSheet) {
|
||||||
|
|
@ -346,15 +338,16 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When static documents are created, stylesheets are cloned manually.
|
nsCOMPtr<nsIDocument> doc = thisContent->IsInShadowTree() ?
|
||||||
if (mDontLoadStyle || !mUpdatesEnabled ||
|
thisContent->OwnerDoc() : thisContent->GetUncomposedDoc();
|
||||||
thisContent->OwnerDoc()->IsStaticDocument()) {
|
|
||||||
|
// Loader could be null during unlink, see bug 1425866.
|
||||||
|
if (!doc || !doc->CSSLoader() || !doc->CSSLoader()->GetEnabled()) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDocument> doc = thisContent->IsInShadowTree() ?
|
// When static documents are created, stylesheets are cloned manually.
|
||||||
thisContent->OwnerDoc() : thisContent->GetUncomposedDoc();
|
if (mDontLoadStyle || !mUpdatesEnabled || doc->IsStaticDocument()) {
|
||||||
if (!doc || !doc->CSSLoader()->GetEnabled()) {
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -426,8 +419,7 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
||||||
rv = doc->CSSLoader()->
|
rv = doc->CSSLoader()->
|
||||||
LoadInlineStyle(thisContent, text, mLineNumber, title, media,
|
LoadInlineStyle(thisContent, text, mLineNumber, title, media,
|
||||||
scopeElement, aObserver, &doneLoading, &isAlternate, &isExplicitlyEnabled);
|
scopeElement, aObserver, &doneLoading, &isAlternate, &isExplicitlyEnabled);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
nsAutoString integrity;
|
nsAutoString integrity;
|
||||||
thisContent->GetAttr(kNameSpaceID_None, nsGkAtoms::integrity, integrity);
|
thisContent->GetAttr(kNameSpaceID_None, nsGkAtoms::integrity, integrity);
|
||||||
if (!integrity.IsEmpty()) {
|
if (!integrity.IsEmpty()) {
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,8 @@ HTMLLinkElement::HasDeferredDNSPrefetchRequest()
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
HTMLLinkElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
HTMLLinkElement::BindToTree(nsIDocument* aDocument,
|
||||||
|
nsIContent* aParent,
|
||||||
nsIContent* aBindingParent,
|
nsIContent* aBindingParent,
|
||||||
bool aCompileEventHandlers)
|
bool aCompileEventHandlers)
|
||||||
{
|
{
|
||||||
|
|
@ -173,12 +174,8 @@ HTMLLinkElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
||||||
aCompileEventHandlers);
|
aCompileEventHandlers);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
// Link must be inert in ShadowRoot.
|
if (nsIDocument* doc = GetComposedDoc()) {
|
||||||
if (aDocument && !GetContainingShadow()) {
|
doc->RegisterPendingLinkUpdate(this);
|
||||||
aDocument->RegisterPendingLinkUpdate(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsInComposedDoc()) {
|
|
||||||
TryDNSPrefetchPreconnectOrPrefetch();
|
TryDNSPrefetchPreconnectOrPrefetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -222,11 +219,7 @@ HTMLLinkElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
||||||
// If this is reinserted back into the document it will not be
|
// If this is reinserted back into the document it will not be
|
||||||
// from the parser.
|
// from the parser.
|
||||||
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
|
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
|
||||||
|
ShadowRoot* oldShadowRoot = GetContainingShadow();
|
||||||
// Check for a ShadowRoot because link elements are inert in a
|
|
||||||
// ShadowRoot.
|
|
||||||
ShadowRoot* oldShadowRoot = GetBindingParent() ?
|
|
||||||
GetBindingParent()->GetShadowRoot() : nullptr;
|
|
||||||
|
|
||||||
OwnerDoc()->UnregisterPendingLinkUpdate(this);
|
OwnerDoc()->UnregisterPendingLinkUpdate(this);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,22 +22,7 @@ isnot(document.baseURI, "http://www.example.org/", "Base element should be inert
|
||||||
|
|
||||||
SimpleTest.waitForExplicitFinish();
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
// Check that <link> is inert.
|
SimpleTest.finish();
|
||||||
var numStyleBeforeLoad = document.styleSheets.length;
|
|
||||||
|
|
||||||
shadow.innerHTML = '<link id="shadowlink" rel="stylesheet" type="text/css" href="inert_style.css" /><span id="shadowspan"></span>';
|
|
||||||
shadow.applyAuthorStyles = true;
|
|
||||||
var shadowSpan = shadow.getElementById("shadowspan");
|
|
||||||
var shadowStyle = shadow.getElementById("shadowlink");
|
|
||||||
|
|
||||||
function runChecks() {
|
|
||||||
isnot(getComputedStyle(shadowSpan, null).getPropertyValue("padding-top"), "10px", "Link element should be inert.");
|
|
||||||
is(document.styleSheets.length, numStyleBeforeLoad, "Document style count should remain the same because the style should not be in the doucment.");
|
|
||||||
is(shadow.styleSheets.length, 0, "Inert link should not add style to ShadowRoot.");
|
|
||||||
// Remove link to make sure we don't get assertions.
|
|
||||||
shadow.removeChild(shadowStyle);
|
|
||||||
SimpleTest.finish();
|
|
||||||
};
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -2024,9 +2024,7 @@ Loader::LoadInlineStyle(nsIContent* aElement,
|
||||||
PrepareSheet(sheet, aTitle, aMedia, nullptr, aScopeElement, *aIsAlternate, *aIsExplicitlyEnabled);
|
PrepareSheet(sheet, aTitle, aMedia, nullptr, aScopeElement, *aIsAlternate, *aIsExplicitlyEnabled);
|
||||||
|
|
||||||
if (aElement->HasFlag(NODE_IS_IN_SHADOW_TREE)) {
|
if (aElement->HasFlag(NODE_IS_IN_SHADOW_TREE)) {
|
||||||
ShadowRoot* containingShadow = aElement->GetContainingShadow();
|
aElement->GetContainingShadow()->InsertSheet(sheet, aElement);
|
||||||
MOZ_ASSERT(containingShadow);
|
|
||||||
containingShadow->InsertSheet(sheet, aElement);
|
|
||||||
} else {
|
} else {
|
||||||
rv = InsertSheetInDoc(sheet, aElement, mDocument);
|
rv = InsertSheetInDoc(sheet, aElement, mDocument);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
@ -2120,8 +2118,12 @@ Loader::LoadStyleLink(nsIContent* aElement,
|
||||||
|
|
||||||
PrepareSheet(sheet, aTitle, aMedia, nullptr, nullptr, *aIsAlternate, *aIsExplicitlyEnabled);
|
PrepareSheet(sheet, aTitle, aMedia, nullptr, nullptr, *aIsAlternate, *aIsExplicitlyEnabled);
|
||||||
|
|
||||||
rv = InsertSheetInDoc(sheet, aElement, mDocument);
|
if (aElement->HasFlag(NODE_IS_IN_SHADOW_TREE)) {
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
aElement->GetContainingShadow()->InsertSheet(sheet, aElement);
|
||||||
|
} else {
|
||||||
|
rv = InsertSheetInDoc(sheet, aElement, mDocument);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIStyleSheetLinkingElement> owningElement(do_QueryInterface(aElement));
|
nsCOMPtr<nsIStyleSheetLinkingElement> owningElement(do_QueryInterface(aElement));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue