mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-26 17:17:31 +09:00
Bug 1392970 - Part 2: Get CustomElementDefinition from CustomElementData when possible.
Tag UXP Issue #1344
This commit is contained in:
parent
7ce1742985
commit
d1a1106760
2 changed files with 26 additions and 46 deletions
|
|
@ -36,8 +36,19 @@ CustomElementCallback::Call()
|
||||||
// enqueue attached callback for ELEMENT.
|
// enqueue attached callback for ELEMENT.
|
||||||
nsIDocument* document = mThisObject->GetComposedDoc();
|
nsIDocument* document = mThisObject->GetComposedDoc();
|
||||||
if (document && document->GetDocShell()) {
|
if (document && document->GetDocShell()) {
|
||||||
|
NodeInfo* ni = mThisObject->NodeInfo();
|
||||||
|
nsDependentAtomString extType(mOwnerData->mType);
|
||||||
|
|
||||||
|
// We need to do this because at this point, CustomElementDefinition is
|
||||||
|
// not set to CustomElementData yet, so EnqueueLifecycleCallback will
|
||||||
|
// fail to find the CE definition for this custom element.
|
||||||
|
// This will go away eventually since there is no created callback in v1.
|
||||||
|
CustomElementDefinition* definition =
|
||||||
|
nsContentUtils::LookupCustomElementDefinition(document,
|
||||||
|
ni->LocalName(), ni->NamespaceID(),
|
||||||
|
extType.IsEmpty() ? nullptr : &extType);
|
||||||
nsContentUtils::EnqueueLifecycleCallback(
|
nsContentUtils::EnqueueLifecycleCallback(
|
||||||
document, nsIDocument::eAttached, mThisObject);
|
document, nsIDocument::eAttached, mThisObject, nullptr, definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
static_cast<LifecycleCreatedCallback *>(mCallback.get())->Call(mThisObject, rv);
|
static_cast<LifecycleCreatedCallback *>(mCallback.get())->Call(mThisObject, rv);
|
||||||
|
|
@ -324,51 +335,35 @@ CustomElementRegistry::CreateCustomElementCallback(
|
||||||
nsIDocument::ElementCallbackType aType, Element* aCustomElement,
|
nsIDocument::ElementCallbackType aType, Element* aCustomElement,
|
||||||
LifecycleCallbackArgs* aArgs, CustomElementDefinition* aDefinition)
|
LifecycleCallbackArgs* aArgs, CustomElementDefinition* aDefinition)
|
||||||
{
|
{
|
||||||
|
MOZ_ASSERT(aDefinition, "CustomElementDefinition should not be null");
|
||||||
|
|
||||||
RefPtr<CustomElementData> elementData = aCustomElement->GetCustomElementData();
|
RefPtr<CustomElementData> elementData = aCustomElement->GetCustomElementData();
|
||||||
MOZ_ASSERT(elementData, "CustomElementData should exist");
|
MOZ_ASSERT(elementData, "CustomElementData should exist");
|
||||||
|
|
||||||
// Let DEFINITION be ELEMENT's definition
|
|
||||||
CustomElementDefinition* definition = aDefinition;
|
|
||||||
if (!definition) {
|
|
||||||
mozilla::dom::NodeInfo* info = aCustomElement->NodeInfo();
|
|
||||||
|
|
||||||
// Make sure we get the correct definition in case the element
|
|
||||||
// is a extended custom element e.g. <button is="x-button">.
|
|
||||||
nsCOMPtr<nsIAtom> typeAtom = elementData ?
|
|
||||||
elementData->mType.get() : info->NameAtom();
|
|
||||||
|
|
||||||
definition = mCustomDefinitions.GetWeak(typeAtom);
|
|
||||||
if (!definition || definition->mLocalName != info->NameAtom()) {
|
|
||||||
// Trying to enqueue a callback for an element that is not
|
|
||||||
// a custom element. We are done, nothing to do.
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let CALLBACK be the callback associated with the key NAME in CALLBACKS.
|
// Let CALLBACK be the callback associated with the key NAME in CALLBACKS.
|
||||||
CallbackFunction* func = nullptr;
|
CallbackFunction* func = nullptr;
|
||||||
switch (aType) {
|
switch (aType) {
|
||||||
case nsIDocument::eCreated:
|
case nsIDocument::eCreated:
|
||||||
if (definition->mCallbacks->mCreatedCallback.WasPassed()) {
|
if (aDefinition->mCallbacks->mCreatedCallback.WasPassed()) {
|
||||||
func = definition->mCallbacks->mCreatedCallback.Value();
|
func = aDefinition->mCallbacks->mCreatedCallback.Value();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nsIDocument::eAttached:
|
case nsIDocument::eAttached:
|
||||||
if (definition->mCallbacks->mAttachedCallback.WasPassed()) {
|
if (aDefinition->mCallbacks->mAttachedCallback.WasPassed()) {
|
||||||
func = definition->mCallbacks->mAttachedCallback.Value();
|
func = aDefinition->mCallbacks->mAttachedCallback.Value();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nsIDocument::eDetached:
|
case nsIDocument::eDetached:
|
||||||
if (definition->mCallbacks->mDetachedCallback.WasPassed()) {
|
if (aDefinition->mCallbacks->mDetachedCallback.WasPassed()) {
|
||||||
func = definition->mCallbacks->mDetachedCallback.Value();
|
func = aDefinition->mCallbacks->mDetachedCallback.Value();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case nsIDocument::eAttributeChanged:
|
case nsIDocument::eAttributeChanged:
|
||||||
if (definition->mCallbacks->mAttributeChangedCallback.WasPassed()) {
|
if (aDefinition->mCallbacks->mAttributeChangedCallback.WasPassed()) {
|
||||||
func = definition->mCallbacks->mAttributeChangedCallback.Value();
|
func = aDefinition->mCallbacks->mAttributeChangedCallback.Value();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -403,21 +398,11 @@ CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType
|
||||||
LifecycleCallbackArgs* aArgs,
|
LifecycleCallbackArgs* aArgs,
|
||||||
CustomElementDefinition* aDefinition)
|
CustomElementDefinition* aDefinition)
|
||||||
{
|
{
|
||||||
RefPtr<CustomElementData> elementData = aCustomElement->GetCustomElementData();
|
|
||||||
MOZ_ASSERT(elementData, "CustomElementData should exist");
|
|
||||||
|
|
||||||
// Let DEFINITION be ELEMENT's definition
|
|
||||||
CustomElementDefinition* definition = aDefinition;
|
CustomElementDefinition* definition = aDefinition;
|
||||||
if (!definition) {
|
if (!definition) {
|
||||||
mozilla::dom::NodeInfo* info = aCustomElement->NodeInfo();
|
definition = aCustomElement->GetCustomElementDefinition();
|
||||||
|
if (!definition ||
|
||||||
// Make sure we get the correct definition in case the element
|
definition->mLocalName != aCustomElement->NodeInfo()->NameAtom()) {
|
||||||
// is a extended custom element e.g. <button is="x-button">.
|
|
||||||
nsCOMPtr<nsIAtom> typeAtom = elementData ?
|
|
||||||
elementData->mType.get() : info->NameAtom();
|
|
||||||
|
|
||||||
definition = mCustomDefinitions.GetWeak(typeAtom);
|
|
||||||
if (!definition || definition->mLocalName != info->NameAtom()) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9642,13 +9642,8 @@ nsContentUtils::GetElementDefinitionIfObservingAttr(Element* aCustomElement,
|
||||||
nsIAtom* aExtensionType,
|
nsIAtom* aExtensionType,
|
||||||
nsIAtom* aAttrName)
|
nsIAtom* aAttrName)
|
||||||
{
|
{
|
||||||
nsString extType = nsDependentAtomString(aExtensionType);
|
|
||||||
NodeInfo *ni = aCustomElement->NodeInfo();
|
|
||||||
|
|
||||||
CustomElementDefinition* definition =
|
CustomElementDefinition* definition =
|
||||||
LookupCustomElementDefinition(aCustomElement->OwnerDoc(), ni->LocalName(),
|
aCustomElement->GetCustomElementDefinition();
|
||||||
ni->NamespaceID(),
|
|
||||||
extType.IsEmpty() ? nullptr : &extType);
|
|
||||||
|
|
||||||
// Custom element not defined yet or attribute is not in the observed
|
// Custom element not defined yet or attribute is not in the observed
|
||||||
// attribute list.
|
// attribute list.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue