mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 15:58:39 +09:00
Bug 1121994 - Implement adopted callback for custom elements.
Tag UXP Issue #1344
This commit is contained in:
parent
659204631b
commit
d35ff2985e
14 changed files with 76 additions and 130 deletions
|
|
@ -47,7 +47,7 @@ CustomElementCallback::Call()
|
|||
ni->LocalName(), ni->NamespaceID(),
|
||||
extType.IsEmpty() ? nullptr : &extType);
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
nsIDocument::eConnected, mThisObject, nullptr, definition);
|
||||
nsIDocument::eConnected, mThisObject, nullptr, nullptr, definition);
|
||||
}
|
||||
|
||||
static_cast<LifecycleCreatedCallback *>(mCallback.get())->Call(mThisObject, rv);
|
||||
|
|
@ -60,6 +60,10 @@ CustomElementCallback::Call()
|
|||
case nsIDocument::eDisconnected:
|
||||
static_cast<LifecycleDisconnectedCallback *>(mCallback.get())->Call(mThisObject, rv);
|
||||
break;
|
||||
case nsIDocument::eAdopted:
|
||||
static_cast<LifecycleAdoptedCallback *>(mCallback.get())->Call(mThisObject,
|
||||
mAdoptedCallbackArgs.mOldDocument, mAdoptedCallbackArgs.mNewDocument, rv);
|
||||
break;
|
||||
case nsIDocument::eAttributeChanged:
|
||||
static_cast<LifecycleAttributeChangedCallback *>(mCallback.get())->Call(mThisObject,
|
||||
mArgs.name, mArgs.oldValue, mArgs.newValue, mArgs.namespaceURI, rv);
|
||||
|
|
@ -332,7 +336,9 @@ CustomElementRegistry::SetupCustomElement(Element* aElement,
|
|||
/* static */ UniquePtr<CustomElementCallback>
|
||||
CustomElementRegistry::CreateCustomElementCallback(
|
||||
nsIDocument::ElementCallbackType aType, Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs, CustomElementDefinition* aDefinition)
|
||||
LifecycleCallbackArgs* aArgs,
|
||||
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
|
||||
CustomElementDefinition* aDefinition)
|
||||
{
|
||||
MOZ_ASSERT(aDefinition, "CustomElementDefinition should not be null");
|
||||
|
||||
|
|
@ -360,6 +366,12 @@ CustomElementRegistry::CreateCustomElementCallback(
|
|||
}
|
||||
break;
|
||||
|
||||
case nsIDocument::eAdopted:
|
||||
if (aDefinition->mCallbacks->mAdoptedCallback.WasPassed()) {
|
||||
func = aDefinition->mCallbacks->mAdoptedCallback.Value();
|
||||
}
|
||||
break;
|
||||
|
||||
case nsIDocument::eAttributeChanged:
|
||||
if (aDefinition->mCallbacks->mAttributeChangedCallback.WasPassed()) {
|
||||
func = aDefinition->mCallbacks->mAttributeChangedCallback.Value();
|
||||
|
|
@ -388,6 +400,9 @@ CustomElementRegistry::CreateCustomElementCallback(
|
|||
callback->SetArgs(*aArgs);
|
||||
}
|
||||
|
||||
if (aAdoptedCallbackArgs) {
|
||||
callback->SetAdoptedCallbackArgs(*aAdoptedCallbackArgs);
|
||||
}
|
||||
return Move(callback);
|
||||
}
|
||||
|
||||
|
|
@ -395,6 +410,7 @@ CustomElementRegistry::CreateCustomElementCallback(
|
|||
CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
|
||||
Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs,
|
||||
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
|
||||
CustomElementDefinition* aDefinition)
|
||||
{
|
||||
CustomElementDefinition* definition = aDefinition;
|
||||
|
|
@ -407,7 +423,8 @@ CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType
|
|||
}
|
||||
|
||||
auto callback =
|
||||
CreateCustomElementCallback(aType, aCustomElement, aArgs, definition);
|
||||
CreateCustomElementCallback(aType, aCustomElement, aArgs,
|
||||
aAdoptedCallbackArgs, definition);
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -926,7 +943,7 @@ CustomElementRegistry::Upgrade(Element* aElement,
|
|||
};
|
||||
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eAttributeChanged,
|
||||
aElement,
|
||||
&args, aDefinition);
|
||||
&args, nullptr, aDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -934,7 +951,7 @@ CustomElementRegistry::Upgrade(Element* aElement,
|
|||
// Step 4.
|
||||
if (aElement->IsInComposedDoc()) {
|
||||
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eConnected, aElement,
|
||||
nullptr, aDefinition);
|
||||
nullptr, nullptr, aDefinition);
|
||||
}
|
||||
|
||||
// Step 5.
|
||||
|
|
@ -958,7 +975,8 @@ CustomElementRegistry::Upgrade(Element* aElement,
|
|||
|
||||
// This is for old spec.
|
||||
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eCreated,
|
||||
aElement, nullptr, aDefinition);
|
||||
aElement, nullptr,
|
||||
nullptr, aDefinition);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
|
@ -1141,6 +1159,11 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CustomElementDefinition)
|
|||
cb.NoteXPCOMChild(callbacks->mDisconnectedCallback.Value());
|
||||
}
|
||||
|
||||
if (callbacks->mAdoptedCallback.WasPassed()) {
|
||||
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCallbacks->mAdoptedCallback");
|
||||
cb.NoteXPCOMChild(callbacks->mAdoptedCallback.Value());
|
||||
}
|
||||
|
||||
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mConstructor");
|
||||
cb.NoteXPCOMChild(tmp->mConstructor);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue