mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1673931
- Move ElementCallbackType from Document.h to CustomElementRegistry.h.
Differential Revision: https://phabricator.services.mozilla.com/D95184 Depends on D95048
This commit is contained in:
parent
6fac745ea4
commit
e21b3c5809
@ -104,25 +104,25 @@ size_t LifecycleCallbackArgs::SizeOfExcludingThis(
|
||||
|
||||
void CustomElementCallback::Call() {
|
||||
switch (mType) {
|
||||
case Document::eConnected:
|
||||
case ElementCallbackType::eConnected:
|
||||
static_cast<LifecycleConnectedCallback*>(mCallback.get())
|
||||
->Call(mThisObject);
|
||||
break;
|
||||
case Document::eDisconnected:
|
||||
case ElementCallbackType::eDisconnected:
|
||||
static_cast<LifecycleDisconnectedCallback*>(mCallback.get())
|
||||
->Call(mThisObject);
|
||||
break;
|
||||
case Document::eAdopted:
|
||||
case ElementCallbackType::eAdopted:
|
||||
static_cast<LifecycleAdoptedCallback*>(mCallback.get())
|
||||
->Call(mThisObject, mAdoptedCallbackArgs.mOldDocument,
|
||||
mAdoptedCallbackArgs.mNewDocument);
|
||||
break;
|
||||
case Document::eAttributeChanged:
|
||||
case ElementCallbackType::eAttributeChanged:
|
||||
static_cast<LifecycleAttributeChangedCallback*>(mCallback.get())
|
||||
->Call(mThisObject, mArgs.name, mArgs.oldValue, mArgs.newValue,
|
||||
mArgs.namespaceURI);
|
||||
break;
|
||||
case Document::eGetCustomInterface:
|
||||
case ElementCallbackType::eGetCustomInterface:
|
||||
MOZ_ASSERT_UNREACHABLE("Don't call GetCustomInterface through callback");
|
||||
break;
|
||||
}
|
||||
@ -155,7 +155,7 @@ size_t CustomElementCallback::SizeOfIncludingThis(
|
||||
}
|
||||
|
||||
CustomElementCallback::CustomElementCallback(
|
||||
Element* aThisObject, Document::ElementCallbackType aCallbackType,
|
||||
Element* aThisObject, ElementCallbackType aCallbackType,
|
||||
mozilla::dom::CallbackFunction* aCallback)
|
||||
: mThisObject(aThisObject), mCallback(aCallback), mType(aCallbackType) {}
|
||||
|
||||
@ -440,7 +440,7 @@ void CustomElementRegistry::UnregisterUnresolvedElement(Element* aElement,
|
||||
/* static */
|
||||
UniquePtr<CustomElementCallback>
|
||||
CustomElementRegistry::CreateCustomElementCallback(
|
||||
Document::ElementCallbackType aType, Element* aCustomElement,
|
||||
ElementCallbackType aType, Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs,
|
||||
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
|
||||
CustomElementDefinition* aDefinition) {
|
||||
@ -451,31 +451,31 @@ CustomElementRegistry::CreateCustomElementCallback(
|
||||
// Let CALLBACK be the callback associated with the key NAME in CALLBACKS.
|
||||
CallbackFunction* func = nullptr;
|
||||
switch (aType) {
|
||||
case Document::eConnected:
|
||||
case ElementCallbackType::eConnected:
|
||||
if (aDefinition->mCallbacks->mConnectedCallback.WasPassed()) {
|
||||
func = aDefinition->mCallbacks->mConnectedCallback.Value();
|
||||
}
|
||||
break;
|
||||
|
||||
case Document::eDisconnected:
|
||||
case ElementCallbackType::eDisconnected:
|
||||
if (aDefinition->mCallbacks->mDisconnectedCallback.WasPassed()) {
|
||||
func = aDefinition->mCallbacks->mDisconnectedCallback.Value();
|
||||
}
|
||||
break;
|
||||
|
||||
case Document::eAdopted:
|
||||
case ElementCallbackType::eAdopted:
|
||||
if (aDefinition->mCallbacks->mAdoptedCallback.WasPassed()) {
|
||||
func = aDefinition->mCallbacks->mAdoptedCallback.Value();
|
||||
}
|
||||
break;
|
||||
|
||||
case Document::eAttributeChanged:
|
||||
case ElementCallbackType::eAttributeChanged:
|
||||
if (aDefinition->mCallbacks->mAttributeChangedCallback.WasPassed()) {
|
||||
func = aDefinition->mCallbacks->mAttributeChangedCallback.Value();
|
||||
}
|
||||
break;
|
||||
|
||||
case Document::eGetCustomInterface:
|
||||
case ElementCallbackType::eGetCustomInterface:
|
||||
MOZ_ASSERT_UNREACHABLE("Don't call GetCustomInterface through callback");
|
||||
break;
|
||||
}
|
||||
@ -502,7 +502,7 @@ CustomElementRegistry::CreateCustomElementCallback(
|
||||
// https://html.spec.whatwg.org/commit-snapshots/65f39c6fc0efa92b0b2b23b93197016af6ac0de6/#enqueue-a-custom-element-callback-reaction
|
||||
/* static */
|
||||
void CustomElementRegistry::EnqueueLifecycleCallback(
|
||||
Document::ElementCallbackType aType, Element* aCustomElement,
|
||||
ElementCallbackType aType, Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs,
|
||||
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
|
||||
CustomElementDefinition* aDefinition) {
|
||||
@ -531,7 +531,7 @@ void CustomElementRegistry::EnqueueLifecycleCallback(
|
||||
return;
|
||||
}
|
||||
|
||||
if (aType == Document::eAttributeChanged) {
|
||||
if (aType == ElementCallbackType::eAttributeChanged) {
|
||||
RefPtr<nsAtom> attrName = NS_Atomize(aArgs->name);
|
||||
if (definition->mObservedAttributes.IsEmpty() ||
|
||||
!definition->mObservedAttributes.Contains(attrName)) {
|
||||
@ -1189,15 +1189,17 @@ void CustomElementRegistry::Upgrade(Element* aElement,
|
||||
nsDependentAtomString(attrName), VoidString(), attrValue,
|
||||
(namespaceURI.IsEmpty() ? VoidString() : namespaceURI)};
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
Document::eAttributeChanged, aElement, &args, nullptr, aDefinition);
|
||||
ElementCallbackType::eAttributeChanged, aElement, &args, nullptr,
|
||||
aDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 5.
|
||||
if (aElement->IsInComposedDoc()) {
|
||||
nsContentUtils::EnqueueLifecycleCallback(Document::eConnected, aElement,
|
||||
nullptr, nullptr, aDefinition);
|
||||
nsContentUtils::EnqueueLifecycleCallback(ElementCallbackType::eConnected,
|
||||
aElement, nullptr, nullptr,
|
||||
aDefinition);
|
||||
}
|
||||
|
||||
// Step 6.
|
||||
|
@ -32,6 +32,14 @@ class CustomElementReaction;
|
||||
class DocGroup;
|
||||
class Promise;
|
||||
|
||||
enum class ElementCallbackType {
|
||||
eConnected,
|
||||
eDisconnected,
|
||||
eAdopted,
|
||||
eAttributeChanged,
|
||||
eGetCustomInterface
|
||||
};
|
||||
|
||||
struct LifecycleCallbackArgs {
|
||||
nsString name;
|
||||
nsString oldValue;
|
||||
@ -48,21 +56,20 @@ struct LifecycleAdoptedCallbackArgs {
|
||||
|
||||
class CustomElementCallback {
|
||||
public:
|
||||
CustomElementCallback(Element* aThisObject,
|
||||
Document::ElementCallbackType aCallbackType,
|
||||
CustomElementCallback(Element* aThisObject, ElementCallbackType aCallbackType,
|
||||
CallbackFunction* aCallback);
|
||||
void Traverse(nsCycleCollectionTraversalCallback& aCb) const;
|
||||
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
|
||||
void Call();
|
||||
void SetArgs(LifecycleCallbackArgs& aArgs) {
|
||||
MOZ_ASSERT(mType == Document::eAttributeChanged,
|
||||
MOZ_ASSERT(mType == ElementCallbackType::eAttributeChanged,
|
||||
"Arguments are only used by attribute changed callback.");
|
||||
mArgs = aArgs;
|
||||
}
|
||||
|
||||
void SetAdoptedCallbackArgs(
|
||||
LifecycleAdoptedCallbackArgs& aAdoptedCallbackArgs) {
|
||||
MOZ_ASSERT(mType == Document::eAdopted,
|
||||
MOZ_ASSERT(mType == ElementCallbackType::eAdopted,
|
||||
"Arguments are only used by adopted callback.");
|
||||
mAdoptedCallbackArgs = aAdoptedCallbackArgs;
|
||||
}
|
||||
@ -72,7 +79,7 @@ class CustomElementCallback {
|
||||
RefPtr<Element> mThisObject;
|
||||
RefPtr<CallbackFunction> mCallback;
|
||||
// The type of callback (eCreated, eAttached, etc.)
|
||||
Document::ElementCallbackType mType;
|
||||
ElementCallbackType mType;
|
||||
// Arguments to be passed to the callback,
|
||||
// used by the attribute changed callback.
|
||||
LifecycleCallbackArgs mArgs;
|
||||
@ -400,7 +407,7 @@ class CustomElementRegistry final : public nsISupports, public nsWrapperCache {
|
||||
JSContext* aCx, JSObject* aConstructor) const;
|
||||
|
||||
static void EnqueueLifecycleCallback(
|
||||
Document::ElementCallbackType aType, Element* aCustomElement,
|
||||
ElementCallbackType aType, Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs,
|
||||
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
|
||||
CustomElementDefinition* aDefinition);
|
||||
@ -482,7 +489,7 @@ class CustomElementRegistry final : public nsISupports, public nsWrapperCache {
|
||||
nsTArray<RefPtr<nsAtom>>& aArray, ErrorResult& aRv);
|
||||
|
||||
static UniquePtr<CustomElementCallback> CreateCustomElementCallback(
|
||||
Document::ElementCallbackType aType, Element* aCustomElement,
|
||||
ElementCallbackType aType, Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs,
|
||||
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
|
||||
CustomElementDefinition* aDefinition);
|
||||
|
@ -3298,14 +3298,6 @@ class Document : public nsINode,
|
||||
// GetDoctype defined above
|
||||
Element* GetDocumentElement() const { return GetRootElement(); }
|
||||
|
||||
enum ElementCallbackType {
|
||||
eConnected,
|
||||
eDisconnected,
|
||||
eAdopted,
|
||||
eAttributeChanged,
|
||||
eGetCustomInterface
|
||||
};
|
||||
|
||||
WindowContext* GetTopLevelWindowContext() const;
|
||||
|
||||
Document* GetTopLevelContentDocument();
|
||||
|
@ -1706,7 +1706,8 @@ nsresult Element::BindToTree(BindContext& aContext, nsINode& aParent) {
|
||||
// connected.
|
||||
if (CustomElementData* data = GetCustomElementData()) {
|
||||
if (data->mState == CustomElementData::State::eCustom) {
|
||||
nsContentUtils::EnqueueLifecycleCallback(Document::eConnected, this);
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
ElementCallbackType::eConnected, this);
|
||||
} else {
|
||||
// Step 7.7.2.2 https://dom.spec.whatwg.org/#concept-node-insert
|
||||
nsContentUtils::TryToUpgradeElement(this);
|
||||
@ -1940,7 +1941,8 @@ void Element::UnbindFromTree(bool aNullParent) {
|
||||
CustomElementData* data = GetCustomElementData();
|
||||
if (data) {
|
||||
if (data->mState == CustomElementData::State::eCustom) {
|
||||
nsContentUtils::EnqueueLifecycleCallback(Document::eDisconnected, this);
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
ElementCallbackType::eDisconnected, this);
|
||||
} else {
|
||||
// Remove an unresolved custom element that is a candidate for upgrade
|
||||
// when a custom element is disconnected.
|
||||
@ -2495,7 +2497,8 @@ nsresult Element::SetAttrAndNotify(
|
||||
(ns.IsEmpty() ? VoidString() : ns)};
|
||||
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
Document::eAttributeChanged, this, &args, nullptr, definition);
|
||||
ElementCallbackType::eAttributeChanged, this, &args, nullptr,
|
||||
definition);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2677,7 +2680,8 @@ nsresult Element::OnAttrSetButNotChanged(int32_t aNamespaceID, nsAtom* aName,
|
||||
(ns.IsEmpty() ? VoidString() : ns)};
|
||||
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
Document::eAttributeChanged, this, &args, nullptr, definition);
|
||||
ElementCallbackType::eAttributeChanged, this, &args, nullptr,
|
||||
definition);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2789,7 +2793,8 @@ nsresult Element::UnsetAttr(int32_t aNameSpaceID, nsAtom* aName, bool aNotify) {
|
||||
VoidString(), (ns.IsEmpty() ? VoidString() : ns)};
|
||||
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
Document::eAttributeChanged, this, &args, nullptr, definition);
|
||||
ElementCallbackType::eAttributeChanged, this, &args, nullptr,
|
||||
definition);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9598,7 +9598,7 @@ void nsContentUtils::EnqueueUpgradeReaction(
|
||||
|
||||
/* static */
|
||||
void nsContentUtils::EnqueueLifecycleCallback(
|
||||
Document::ElementCallbackType aType, Element* aCustomElement,
|
||||
ElementCallbackType aType, Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs,
|
||||
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
|
||||
CustomElementDefinition* aDefinition) {
|
||||
|
@ -188,6 +188,7 @@ class MessageBroadcaster;
|
||||
class NodeInfo;
|
||||
class Selection;
|
||||
class WorkerPrivate;
|
||||
enum class ElementCallbackType;
|
||||
} // namespace dom
|
||||
|
||||
namespace intl {
|
||||
@ -3051,7 +3052,7 @@ class nsContentUtils {
|
||||
Element* aElement, mozilla::dom::CustomElementDefinition* aDefinition);
|
||||
|
||||
static void EnqueueLifecycleCallback(
|
||||
Document::ElementCallbackType aType, Element* aCustomElement,
|
||||
mozilla::dom::ElementCallbackType aType, Element* aCustomElement,
|
||||
mozilla::dom::LifecycleCallbackArgs* aArgs = nullptr,
|
||||
mozilla::dom::LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs =
|
||||
nullptr,
|
||||
|
@ -3197,8 +3197,8 @@ already_AddRefed<nsINode> nsINode::CloneAndAdopt(
|
||||
CustomElementData* data = elem->GetCustomElementData();
|
||||
if (data && data->mState == CustomElementData::State::eCustom) {
|
||||
LifecycleAdoptedCallbackArgs args = {oldDoc, newDoc};
|
||||
nsContentUtils::EnqueueLifecycleCallback(Document::eAdopted, elem,
|
||||
nullptr, &args);
|
||||
nsContentUtils::EnqueueLifecycleCallback(ElementCallbackType::eAdopted,
|
||||
elem, nullptr, &args);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "mozilla/BasePrincipal.h"
|
||||
#include "mozilla/HoldDropJSObjects.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Services.h"
|
||||
|
||||
#define INTL_APP_LOCALES_CHANGED "intl:app-locales-changed"
|
||||
#define L10N_PSEUDO_PREF "intl.l10n.pseudo"
|
||||
|
Loading…
Reference in New Issue
Block a user