From e21b3c58092fdee48eb1b3aa9592e3205e5e7f3a Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Mon, 23 Nov 2020 16:08:11 +0000 Subject: [PATCH] Bug 1673931 - Move ElementCallbackType from Document.h to CustomElementRegistry.h. Differential Revision: https://phabricator.services.mozilla.com/D95184 Depends on D95048 --- dom/base/CustomElementRegistry.cpp | 36 ++++++++++++++++-------------- dom/base/CustomElementRegistry.h | 21 +++++++++++------ dom/base/Document.h | 8 ------- dom/base/Element.cpp | 15 ++++++++----- dom/base/nsContentUtils.cpp | 2 +- dom/base/nsContentUtils.h | 3 ++- dom/base/nsINode.cpp | 4 ++-- intl/l10n/Localization.cpp | 1 + 8 files changed, 49 insertions(+), 41 deletions(-) diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index 663b0bdda1e7..7854ee8f6194 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -104,25 +104,25 @@ size_t LifecycleCallbackArgs::SizeOfExcludingThis( void CustomElementCallback::Call() { switch (mType) { - case Document::eConnected: + case ElementCallbackType::eConnected: static_cast(mCallback.get()) ->Call(mThisObject); break; - case Document::eDisconnected: + case ElementCallbackType::eDisconnected: static_cast(mCallback.get()) ->Call(mThisObject); break; - case Document::eAdopted: + case ElementCallbackType::eAdopted: static_cast(mCallback.get()) ->Call(mThisObject, mAdoptedCallbackArgs.mOldDocument, mAdoptedCallbackArgs.mNewDocument); break; - case Document::eAttributeChanged: + case ElementCallbackType::eAttributeChanged: static_cast(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 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 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. diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h index fe6ad090890d..a95d395e9407 100644 --- a/dom/base/CustomElementRegistry.h +++ b/dom/base/CustomElementRegistry.h @@ -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 mThisObject; RefPtr 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>& aArray, ErrorResult& aRv); static UniquePtr CreateCustomElementCallback( - Document::ElementCallbackType aType, Element* aCustomElement, + ElementCallbackType aType, Element* aCustomElement, LifecycleCallbackArgs* aArgs, LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs, CustomElementDefinition* aDefinition); diff --git a/dom/base/Document.h b/dom/base/Document.h index e8593e8c2445..4a97adfd3e10 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -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(); diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index c4f3cb8a79ba..8a5bec9dc95f 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -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); } } diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 3cce0006e630..defee8be9b60 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -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) { diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 0dd1ff13bbd4..097bc0d5281a 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -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, diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp index 26544a685d3d..56c9fbf37378 100644 --- a/dom/base/nsINode.cpp +++ b/dom/base/nsINode.cpp @@ -3197,8 +3197,8 @@ already_AddRefed 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); } } diff --git a/intl/l10n/Localization.cpp b/intl/l10n/Localization.cpp index 6432193362a6..bc3f133f1a0c 100644 --- a/intl/l10n/Localization.cpp +++ b/intl/l10n/Localization.cpp @@ -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"