nsresult HTMLLinkElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, bool aCompileEventHandlers) { Link::ResetLinkState(false, Link::ElementHasHref()); nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent, aBindingParent, aCompileEventHandlers); NS_ENSURE_SUCCESS(rv, rv); // Link must be inert in ShadowRoot. if (aDocument && !GetContainingShadow()) { aDocument->RegisterPendingLinkUpdate(this); } void (HTMLLinkElement::*update)() = &HTMLLinkElement::UpdateStyleSheetInternal; nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, update)); void (HTMLLinkElement::*updateImport)() = &HTMLLinkElement::UpdateImport; nsContentUtils::AddScriptRunner(NS_NewRunnableMethod(this, updateImport)); CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMLinkAdded")); return rv; }
void HTMLLinkElement::UnbindFromTree(bool aDeep, bool aNullParent) { // Cancel any DNS prefetches // Note: Must come before ResetLinkState. If called after, it will recreate // mCachedURI based on data that is invalid - due to a call to GetHostname. CancelDNSPrefetch(HTML_LINK_DNS_PREFETCH_DEFERRED, HTML_LINK_DNS_PREFETCH_REQUESTED); CancelPrefetchOrPreload(); // Without removing the link state we risk a dangling pointer // in the mStyledLinks hashtable Link::ResetLinkState(false, Link::ElementHasHref()); // If this is reinserted back into the document it will not be // from the parser. Document* oldDoc = GetUncomposedDoc(); ShadowRoot* oldShadowRoot = GetContainingShadow(); // We want to update the localization but only if the // link is removed from a DOM change, and not // because the document is going away. bool ignore; if (oldDoc && oldDoc->GetScriptHandlingObject(ignore) && this->AttrValueIs(kNameSpaceID_None, nsGkAtoms::rel, nsGkAtoms::localization, eIgnoreCase)) { oldDoc->LocalizationLinkRemoved(this); } CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMLinkRemoved")); nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent); Unused << UpdateStyleSheetInternal(oldDoc, oldShadowRoot); }
void HTMLStyleElement::UnbindFromTree(bool aDeep, bool aNullParent) { nsCOMPtr<nsIDocument> oldDoc = GetCurrentDoc(); ShadowRoot* oldShadow = GetContainingShadow(); nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent); UpdateStyleSheetInternal(oldDoc, oldShadow); }
void HTMLStyleElement::UnbindFromTree(bool aDeep, bool aNullParent) { nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc(); ShadowRoot* oldShadow = GetContainingShadow(); nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent); if (oldShadow && GetContainingShadow()) { // The style is in a shadow tree and is still in the // shadow tree. Thus the sheets in the shadow DOM // do not need to be updated. return; } UpdateStyleSheetInternal(oldDoc, oldShadow); }
void HTMLStyleElement::UnbindFromTree(bool aDeep, bool aNullParent) { nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc(); nsCOMPtr<nsIDocument> oldComposedDoc = GetComposedDoc(); ShadowRoot* oldShadow = GetContainingShadow(); nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent); if (GetContainingShadow() && !oldComposedDoc) { // The style is in a shadow tree and was already not // in the composed document. Thus the sheet does not // need to be updated. return; } UpdateStyleSheetInternal(oldDoc, oldShadow); }
void CharacterData::UnbindFromTree(bool aDeep, bool aNullParent) { // Unset frame flags; if we need them again later, they'll get set again. UnsetFlags(NS_CREATE_FRAME_IF_NON_WHITESPACE | NS_REFRAME_IF_WHITESPACE); nsIDocument* document = GetComposedDoc(); if (aNullParent) { if (this->IsRootOfNativeAnonymousSubtree()) { nsNodeUtils::NativeAnonymousChildListChange(this, true); } if (GetParent()) { NS_RELEASE(mParent); } else { mParent = nullptr; } SetParentIsContent(false); } ClearInDocument(); if (aNullParent || !mParent->IsInShadowTree()) { UnsetFlags(NODE_IS_IN_SHADOW_TREE); // Begin keeping track of our subtree root. SetSubtreeRootPointer(aNullParent ? this : mParent->SubtreeRoot()); } if (document && !GetContainingShadow()) { // Notify XBL- & nsIAnonymousContentCreator-generated // anonymous content that the document is changing. // Unlike XBL, bindings for web components shadow DOM // do not get uninstalled. if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) { nsContentUtils::AddScriptRunner( new RemoveFromBindingManagerRunnable(document->BindingManager(), this, document)); } } nsExtendedContentSlots* slots = GetExistingExtendedContentSlots(); if (slots) { slots->mBindingParent = nullptr; if (aNullParent || !mParent->IsInShadowTree()) { slots->mContainingShadow = nullptr; } } nsNodeUtils::ParentChainChanged(this); }