From f15895390e381e3e958cf962789c6fad26793b69 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Mon, 23 Nov 2020 16:08:40 +0000 Subject: [PATCH] Bug 1673931 - Avoid including Element.h from header files. Differential Revision: https://phabricator.services.mozilla.com/D96535 Depends on D96534 --- accessible/base/ARIAMap.cpp | 5 ++ accessible/base/ARIAMap.h | 10 ++-- accessible/base/nsCoreUtils.cpp | 6 +++ accessible/base/nsCoreUtils.h | 7 +-- accessible/generic/Accessible.cpp | 4 ++ accessible/generic/Accessible.h | 8 +-- docshell/base/LoadContext.h | 5 +- docshell/base/nsDocShellEditorData.h | 5 +- dom/animation/CSSPseudoElement.cpp | 5 ++ dom/animation/CSSPseudoElement.h | 6 +-- dom/animation/KeyframeEffect.cpp | 5 ++ dom/animation/KeyframeEffect.h | 7 +-- dom/base/CharacterData.cpp | 4 ++ dom/base/CharacterData.h | 6 +-- dom/base/IDTracker.cpp | 19 ++++++++ dom/base/IDTracker.h | 22 +++------ dom/base/PopupBlocker.h | 1 - dom/base/RangeUtils.h | 1 - dom/base/nsDOMAttributeMap.h | 5 -- dom/base/nsDOMMutationObserver.cpp | 30 ++++++++++++ dom/base/nsDOMMutationObserver.h | 33 ++----------- dom/base/nsDOMTokenList.h | 2 +- dom/base/nsFrameLoader.cpp | 10 ++++ dom/base/nsFrameLoader.h | 12 ++--- dom/base/nsStyledElement.h | 1 - dom/base/nsTreeSanitizer.h | 4 +- dom/grid/Grid.h | 2 +- dom/html/HTMLFormControlsCollection.h | 2 +- dom/html/HTMLFormSubmission.cpp | 11 +++++ dom/html/HTMLFormSubmission.h | 11 +---- dom/html/TextControlState.h | 2 +- dom/html/nsDOMStringMap.h | 1 - dom/html/nsGenericHTMLElement.h | 1 - dom/l10n/DOMLocalization.h | 2 +- dom/l10n/L10nOverlays.h | 2 +- dom/script/ScriptLoadRequest.cpp | 14 ++++++ dom/script/ScriptLoadRequest.h | 16 ++---- dom/smil/SMILTargetIdentifier.h | 3 ++ dom/xslt/xslt/txMozillaXMLOutput.h | 2 +- dom/xul/XULBroadcastManager.cpp | 42 ++++++++++++++++ dom/xul/XULBroadcastManager.h | 43 +--------------- dom/xul/nsXULPopupListener.h | 2 +- dom/xul/nsXULPrototypeDocument.h | 5 +- editor/libeditor/CreateElementTransaction.h | 4 +- layout/base/AccessibleCaret.h | 2 +- layout/forms/nsTextControlFrame.h | 1 - layout/style/AnimationCollection.cpp | 8 +++ layout/style/AnimationCollection.h | 11 ++--- layout/style/ServoElementSnapshot.cpp | 46 ++++++++++++++++++ layout/style/ServoElementSnapshot.h | 54 ++------------------- layout/style/nsComputedDOMStyle.h | 1 - layout/svg/SVGObserverUtils.h | 2 +- 52 files changed, 286 insertions(+), 227 deletions(-) diff --git a/accessible/base/ARIAMap.cpp b/accessible/base/ARIAMap.cpp index a19fe904f389..757dee891004 100644 --- a/accessible/base/ARIAMap.cpp +++ b/accessible/base/ARIAMap.cpp @@ -1462,6 +1462,11 @@ bool aria::HasDefinedARIAHidden(nsIContent* aContent) { //////////////////////////////////////////////////////////////////////////////// // AttrIterator class +AttrIterator::AttrIterator(nsIContent* aContent) + : mElement(dom::Element::FromNode(aContent)), mAttrIdx(0) { + mAttrCount = mElement ? mElement->GetAttrCount() : 0; +} + bool AttrIterator::Next(nsAString& aAttrName, nsAString& aAttrValue) { while (mAttrIdx < mAttrCount) { const nsAttrName* attr = mElement->GetAttrNameAt(mAttrIdx); diff --git a/accessible/base/ARIAMap.h b/accessible/base/ARIAMap.h index c20433ca972d..78d632c493c1 100644 --- a/accessible/base/ARIAMap.h +++ b/accessible/base/ARIAMap.h @@ -14,10 +14,13 @@ #include "nsAtom.h" #include "nsIContent.h" -#include "mozilla/dom/Element.h" class nsINode; +namespace mozilla::dom { +class Element; +} + //////////////////////////////////////////////////////////////////////////////// // Value constants @@ -276,10 +279,7 @@ bool HasDefinedARIAHidden(nsIContent* aContent); */ class AttrIterator { public: - explicit AttrIterator(nsIContent* aContent) - : mElement(dom::Element::FromNode(aContent)), mAttrIdx(0) { - mAttrCount = mElement ? mElement->GetAttrCount() : 0; - } + explicit AttrIterator(nsIContent* aContent); bool Next(nsAString& aAttrName, nsAString& aAttrValue); diff --git a/accessible/base/nsCoreUtils.cpp b/accessible/base/nsCoreUtils.cpp index 21f183059888..f00942fb012b 100644 --- a/accessible/base/nsCoreUtils.cpp +++ b/accessible/base/nsCoreUtils.cpp @@ -542,6 +542,12 @@ void nsCoreUtils::ScrollTo(PresShell* aPresShell, nsIContent* aContent, ScrollFlags::ScrollOverflowHidden); } +bool nsCoreUtils::IsHTMLTableHeader(nsIContent* aContent) { + return aContent->NodeInfo()->Equals(nsGkAtoms::th) || + (aContent->IsElement() && + aContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::scope)); +} + bool nsCoreUtils::IsWhitespaceString(const nsAString& aString) { nsAString::const_char_iterator iterBegin, iterEnd; diff --git a/accessible/base/nsCoreUtils.h b/accessible/base/nsCoreUtils.h index d566944a4360..a61409eca557 100644 --- a/accessible/base/nsCoreUtils.h +++ b/accessible/base/nsCoreUtils.h @@ -7,7 +7,6 @@ #define nsCoreUtils_h_ #include "mozilla/EventForwards.h" -#include "mozilla/dom/Element.h" #include "nsIAccessibleEvent.h" #include "nsIContent.h" #include "mozilla/FlushType.h" @@ -296,11 +295,7 @@ class nsCoreUtils { /** * Return true if the given node is table header element. */ - static bool IsHTMLTableHeader(nsIContent* aContent) { - return aContent->NodeInfo()->Equals(nsGkAtoms::th) || - (aContent->IsElement() && aContent->AsElement()->HasAttr( - kNameSpaceID_None, nsGkAtoms::scope)); - } + static bool IsHTMLTableHeader(nsIContent* aContent); /** * Returns true if the given string is empty or contains whitespace symbols diff --git a/accessible/generic/Accessible.cpp b/accessible/generic/Accessible.cpp index 7d0eb44dc3ed..691bd51561b8 100644 --- a/accessible/generic/Accessible.cpp +++ b/accessible/generic/Accessible.cpp @@ -2130,6 +2130,10 @@ nsIFrame* Accessible::GetFrame() const { nsINode* Accessible::GetNode() const { return mContent; } +dom::Element* Accessible::Elm() const { + return dom::Element::FromNodeOrNull(mContent); +} + void Accessible::Language(nsAString& aLanguage) { aLanguage.Truncate(); diff --git a/accessible/generic/Accessible.h b/accessible/generic/Accessible.h index 20ed9745871e..380fab4920e1 100644 --- a/accessible/generic/Accessible.h +++ b/accessible/generic/Accessible.h @@ -11,8 +11,6 @@ #include "mozilla/a11y/Role.h" #include "mozilla/a11y/States.h" -#include "mozilla/dom/Element.h" - #include "mozilla/UniquePtr.h" #include "nsIContent.h" @@ -25,6 +23,10 @@ struct nsRoleMapEntry; class nsIFrame; class nsIPersistentProperties; +namespace mozilla::dom { +class Element; +} + namespace mozilla { namespace a11y { @@ -161,7 +163,7 @@ class Accessible : public nsISupports { virtual nsINode* GetNode() const; nsIContent* GetContent() const { return mContent; } - dom::Element* Elm() const { return dom::Element::FromNodeOrNull(mContent); } + dom::Element* Elm() const; /** * Return node type information of DOM node associated with the accessible. diff --git a/docshell/base/LoadContext.h b/docshell/base/LoadContext.h index eb35125e1992..5cb71ff34731 100644 --- a/docshell/base/LoadContext.h +++ b/docshell/base/LoadContext.h @@ -11,10 +11,13 @@ #include "mozilla/Attributes.h" #include "mozilla/BasePrincipal.h" #include "nsIWeakReferenceUtils.h" -#include "mozilla/dom/Element.h" #include "nsIInterfaceRequestor.h" #include "nsILoadContext.h" +namespace mozilla::dom { +class Element; +} + namespace mozilla { /** diff --git a/docshell/base/nsDocShellEditorData.h b/docshell/base/nsDocShellEditorData.h index 5bbb140aa586..27f840675bd1 100644 --- a/docshell/base/nsDocShellEditorData.h +++ b/docshell/base/nsDocShellEditorData.h @@ -10,13 +10,16 @@ # include "nsCOMPtr.h" #endif -#include "mozilla/HTMLEditor.h" #include "mozilla/RefPtr.h" #include "mozilla/dom/Document.h" class nsIDocShell; class nsEditingSession; +namespace mozilla { +class HTMLEditor; +} + class nsDocShellEditorData { public: explicit nsDocShellEditorData(nsIDocShell* aOwningDocShell); diff --git a/dom/animation/CSSPseudoElement.cpp b/dom/animation/CSSPseudoElement.cpp index 90565dca56c6..ad8c92ca0f64 100644 --- a/dom/animation/CSSPseudoElement.cpp +++ b/dom/animation/CSSPseudoElement.cpp @@ -44,6 +44,11 @@ JSObject* CSSPseudoElement::WrapObject(JSContext* aCx, return CSSPseudoElement_Binding::Wrap(aCx, this, aGivenProto); } +already_AddRefed CSSPseudoElement::Element() const { + RefPtr retVal(mOriginatingElement); + return retVal.forget(); +} + /* static */ already_AddRefed CSSPseudoElement::GetCSSPseudoElement( dom::Element* aElement, PseudoStyleType aType) { diff --git a/dom/animation/CSSPseudoElement.h b/dom/animation/CSSPseudoElement.h index c424544190c7..0a195bec1e36 100644 --- a/dom/animation/CSSPseudoElement.h +++ b/dom/animation/CSSPseudoElement.h @@ -11,7 +11,6 @@ #include "mozilla/Attributes.h" #include "mozilla/ErrorResult.h" #include "mozilla/dom/BindingDeclarations.h" -#include "mozilla/dom/Element.h" #include "mozilla/RefPtr.h" #include "nsCSSPseudoElements.h" #include "nsWrapperCache.h" @@ -49,10 +48,7 @@ class CSSPseudoElement final : public nsWrapperCache { aRetVal.Append( nsDependentAtomString(nsCSSPseudoElements::GetPseudoAtom(mPseudoType))); } - already_AddRefed Element() const { - RefPtr retVal(mOriginatingElement); - return retVal.forget(); - } + already_AddRefed Element() const; // Given an element:pseudoType pair, returns the CSSPseudoElement stored as a // property on |aElement|. If there is no CSSPseudoElement for the specified diff --git a/dom/animation/KeyframeEffect.cpp b/dom/animation/KeyframeEffect.cpp index ce11a5d54d99..8817836905fc 100644 --- a/dom/animation/KeyframeEffect.cpp +++ b/dom/animation/KeyframeEffect.cpp @@ -1090,6 +1090,11 @@ already_AddRefed KeyframeEffect::Constructor( return effect.forget(); } +already_AddRefed KeyframeEffect::GetTarget() const { + RefPtr ret = mTarget.mElement; + return ret.forget(); +} + void KeyframeEffect::SetPseudoElement(const nsAString& aPseudoElement, ErrorResult& aRv) { PseudoStyleType pseudoType = PseudoStyleType::NotPseudo; diff --git a/dom/animation/KeyframeEffect.h b/dom/animation/KeyframeEffect.h index 2b9668781372..2794d6d787f7 100644 --- a/dom/animation/KeyframeEffect.h +++ b/dom/animation/KeyframeEffect.h @@ -29,7 +29,6 @@ #include "mozilla/StyleAnimationValue.h" #include "mozilla/dom/AnimationEffect.h" #include "mozilla/dom/BindingDeclarations.h" -#include "mozilla/dom/Element.h" struct JSContext; class JSObject; @@ -47,6 +46,7 @@ class ComputedStyle; class PresShell; namespace dom { +class Element; class GlobalObject; class UnrestrictedDoubleOrKeyframeAnimationOptions; class UnrestrictedDoubleOrKeyframeEffectOptions; @@ -142,10 +142,7 @@ class KeyframeEffect : public AnimationEffect { const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions, ErrorResult& aRv); - already_AddRefed GetTarget() const { - RefPtr ret = mTarget.mElement; - return ret.forget(); - } + already_AddRefed GetTarget() const; NonOwningAnimationTarget GetAnimationTarget() const { return NonOwningAnimationTarget(mTarget.mElement, mTarget.mPseudoType); } diff --git a/dom/base/CharacterData.cpp b/dom/base/CharacterData.cpp index d2cd625f4f42..75981cbadb11 100644 --- a/dom/base/CharacterData.cpp +++ b/dom/base/CharacterData.cpp @@ -62,6 +62,10 @@ CharacterData::~CharacterData() { } } +Element* CharacterData::GetNameSpaceElement() { + return Element::FromNodeOrNull(GetParentNode()); +} + NS_IMPL_CYCLE_COLLECTION_CLASS(CharacterData) NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(CharacterData) diff --git a/dom/base/CharacterData.h b/dom/base/CharacterData.h index 31674acfee78..f3b50f3e17bf 100644 --- a/dom/base/CharacterData.h +++ b/dom/base/CharacterData.h @@ -17,13 +17,13 @@ #include "nsTextFragment.h" #include "nsError.h" -#include "mozilla/dom/Element.h" #include "nsCycleCollectionParticipant.h" #include "mozilla/dom/ShadowRoot.h" namespace mozilla { namespace dom { +class Element; class HTMLSlotElement; } // namespace dom } // namespace mozilla @@ -215,9 +215,7 @@ class CharacterData : public nsIContent { protected: virtual ~CharacterData(); - Element* GetNameSpaceElement() final { - return Element::FromNodeOrNull(GetParentNode()); - } + Element* GetNameSpaceElement() final; nsresult SetTextInternal( uint32_t aOffset, uint32_t aCount, const char16_t* aBuffer, diff --git a/dom/base/IDTracker.cpp b/dom/base/IDTracker.cpp index eae778232a6d..4b36c0387e97 100644 --- a/dom/base/IDTracker.cpp +++ b/dom/base/IDTracker.cpp @@ -188,6 +188,8 @@ void IDTracker::Unlink() { mReferencingImage = false; } +void IDTracker::ElementChanged(Element* aFrom, Element* aTo) { mElement = aTo; } + bool IDTracker::Observe(Element* aOldElement, Element* aNewElement, void* aData) { IDTracker* p = static_cast(aData); @@ -208,6 +210,23 @@ bool IDTracker::Observe(Element* aOldElement, Element* aNewElement, return keepTracking; } +IDTracker::ChangeNotification::ChangeNotification(IDTracker* aTarget, + Element* aFrom, Element* aTo) + : mozilla::Runnable("IDTracker::ChangeNotification"), + Notification(aTarget), + mFrom(aFrom), + mTo(aTo) {} + +IDTracker::ChangeNotification::~ChangeNotification() = default; + +void IDTracker::ChangeNotification::SetTo(Element* aTo) { mTo = aTo; } + +void IDTracker::ChangeNotification::Clear() { + Notification::Clear(); + mFrom = nullptr; + mTo = nullptr; +} + NS_IMPL_ISUPPORTS_INHERITED0(IDTracker::ChangeNotification, mozilla::Runnable) NS_IMPL_ISUPPORTS(IDTracker::DocumentLoadNotification, nsIObserver) diff --git a/dom/base/IDTracker.h b/dom/base/IDTracker.h index dba3f6d9bb0a..c76cfda38866 100644 --- a/dom/base/IDTracker.h +++ b/dom/base/IDTracker.h @@ -8,7 +8,7 @@ #define mozilla_dom_IDTracker_h_ #include "mozilla/Attributes.h" -#include "mozilla/dom/Element.h" +#include "nsIObserver.h" #include "nsThreadUtils.h" class nsAtom; @@ -21,6 +21,8 @@ namespace mozilla { namespace dom { class Document; +class DocumentOrShadowRoot; +class Element; /** * Class to track what element is referenced by a given ID. @@ -94,7 +96,7 @@ class IDTracker { * to call this superclass method to change mElement. This is called * at script-runnable time. */ - virtual void ElementChanged(Element* aFrom, Element* aTo) { mElement = aTo; } + virtual void ElementChanged(Element* aFrom, Element* aTo); /** * Override this to convert from a single-shot notification to @@ -127,11 +129,7 @@ class IDTracker { class ChangeNotification : public mozilla::Runnable, public Notification { public: - ChangeNotification(IDTracker* aTarget, Element* aFrom, Element* aTo) - : mozilla::Runnable("IDTracker::ChangeNotification"), - Notification(aTarget), - mFrom(aFrom), - mTo(aTo) {} + ChangeNotification(IDTracker* aTarget, Element* aFrom, Element* aTo); // We need to actually declare all of nsISupports, because // Notification inherits from it but doesn't declare it. @@ -143,15 +141,11 @@ class IDTracker { } return NS_OK; } - virtual void SetTo(Element* aTo) override { mTo = aTo; } - virtual void Clear() override { - Notification::Clear(); - mFrom = nullptr; - mTo = nullptr; - } + void SetTo(Element* aTo) override; + void Clear() override; protected: - virtual ~ChangeNotification() = default; + virtual ~ChangeNotification(); RefPtr mFrom; RefPtr mTo; diff --git a/dom/base/PopupBlocker.h b/dom/base/PopupBlocker.h index 293376637280..d6e82151f6c0 100644 --- a/dom/base/PopupBlocker.h +++ b/dom/base/PopupBlocker.h @@ -7,7 +7,6 @@ #ifndef mozilla_dom_PopupBlocker_h #define mozilla_dom_PopupBlocker_h -#include "Element.h" #include "mozilla/BasicEvents.h" class nsIPrincipal; diff --git a/dom/base/RangeUtils.h b/dom/base/RangeUtils.h index 950bb0258edd..294dc58e8d54 100644 --- a/dom/base/RangeUtils.h +++ b/dom/base/RangeUtils.h @@ -7,7 +7,6 @@ #ifndef mozilla_RangeUtils_h #define mozilla_RangeUtils_h -#include "Element.h" #include "mozilla/Maybe.h" #include "mozilla/RangeBoundary.h" #include "nsIContent.h" diff --git a/dom/base/nsDOMAttributeMap.h b/dom/base/nsDOMAttributeMap.h index d9206c3ece56..c7066f25bc2e 100644 --- a/dom/base/nsDOMAttributeMap.h +++ b/dom/base/nsDOMAttributeMap.h @@ -172,9 +172,4 @@ class nsDOMAttributeMap final : public nsISupports, public nsWrapperCache { Attr* GetAttribute(mozilla::dom::NodeInfo* aNodeInfo); }; -// XXX khuey yes this is strange. The bindings code needs to see this include, -// but if we pull it in at the top of the file we get a circular include -// problem. -#include "mozilla/dom/Element.h" - #endif /* nsDOMAttributeMap_h */ diff --git a/dom/base/nsDOMMutationObserver.cpp b/dom/base/nsDOMMutationObserver.cpp index b1308e80706d..217ff5040052 100644 --- a/dom/base/nsDOMMutationObserver.cpp +++ b/dom/base/nsDOMMutationObserver.cpp @@ -72,6 +72,36 @@ bool nsMutationReceiverBase::IsObservable(nsIContent* aContent) { (Observer()->IsChrome() || !aContent->IsInNativeAnonymousSubtree()); } +bool nsMutationReceiverBase::ObservesAttr(nsINode* aRegisterTarget, + mozilla::dom::Element* aElement, + int32_t aNameSpaceID, nsAtom* aAttr) { + if (mParent) { + return mParent->ObservesAttr(aRegisterTarget, aElement, aNameSpaceID, + aAttr); + } + if (!Attributes() || (!Subtree() && aElement != Target()) || + (Subtree() && + aRegisterTarget->SubtreeRoot() != aElement->SubtreeRoot()) || + !IsObservable(aElement)) { + return false; + } + if (AllAttributes()) { + return true; + } + + if (aNameSpaceID != kNameSpaceID_None) { + return false; + } + + nsTArray>& filters = AttributeFilter(); + for (size_t i = 0; i < filters.Length(); ++i) { + if (filters[i] == aAttr) { + return true; + } + } + return false; +} + NS_IMPL_ADDREF(nsMutationReceiver) NS_IMPL_RELEASE(nsMutationReceiver) diff --git a/dom/base/nsDOMMutationObserver.h b/dom/base/nsDOMMutationObserver.h index 6420c7fdba57..9286e7b4d5e4 100644 --- a/dom/base/nsDOMMutationObserver.h +++ b/dom/base/nsDOMMutationObserver.h @@ -12,7 +12,6 @@ #include "mozilla/Attributes.h" #include "mozilla/dom/Animation.h" #include "mozilla/dom/Document.h" -#include "mozilla/dom/Element.h" #include "mozilla/dom/MutationEventBinding.h" #include "mozilla/dom/MutationObserverBinding.h" #include "mozilla/dom/Nullable.h" @@ -34,6 +33,10 @@ class nsIPrincipal; class nsDOMMutationObserver; using mozilla::dom::MutationObservingInfo; +namespace mozilla::dom { +class Element; +} + class nsDOMMutationRecord final : public nsISupports, public nsWrapperCache { virtual ~nsDOMMutationRecord() = default; @@ -247,33 +250,7 @@ class nsMutationReceiverBase : public nsStubAnimationObserver { bool IsObservable(nsIContent* aContent); bool ObservesAttr(nsINode* aRegisterTarget, mozilla::dom::Element* aElement, - int32_t aNameSpaceID, nsAtom* aAttr) { - if (mParent) { - return mParent->ObservesAttr(aRegisterTarget, aElement, aNameSpaceID, - aAttr); - } - if (!Attributes() || (!Subtree() && aElement != Target()) || - (Subtree() && - aRegisterTarget->SubtreeRoot() != aElement->SubtreeRoot()) || - !IsObservable(aElement)) { - return false; - } - if (AllAttributes()) { - return true; - } - - if (aNameSpaceID != kNameSpaceID_None) { - return false; - } - - nsTArray>& filters = AttributeFilter(); - for (size_t i = 0; i < filters.Length(); ++i) { - if (filters[i] == aAttr) { - return true; - } - } - return false; - } + int32_t aNameSpaceID, nsAtom* aAttr); // The target for the MutationObserver.observe() method. nsINode* mTarget; diff --git a/dom/base/nsDOMTokenList.h b/dom/base/nsDOMTokenList.h index 6cb17c49fade..79a370766b32 100644 --- a/dom/base/nsDOMTokenList.h +++ b/dom/base/nsDOMTokenList.h @@ -16,7 +16,6 @@ #include "nsDOMString.h" #include "nsWhitespaceTokenizer.h" #include "nsWrapperCache.h" -#include "mozilla/dom/Element.h" #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/DOMTokenListSupportedTokens.h" @@ -24,6 +23,7 @@ namespace mozilla { class ErrorResult; namespace dom { class DocGroup; +class Element; } // namespace dom } // namespace mozilla diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp index 4556a8a635fb..07b332c70e86 100644 --- a/dom/base/nsFrameLoader.cpp +++ b/dom/base/nsFrameLoader.cpp @@ -2065,6 +2065,8 @@ bool nsFrameLoader::OwnerIsMozBrowserFrame() { return browserFrame ? browserFrame->GetReallyIsBrowser() : false; } +nsIContent* nsFrameLoader::GetParentObject() const { return mOwnerContent; } + void nsFrameLoader::AssertSafeToInit() { MOZ_DIAGNOSTIC_ASSERT(nsContentUtils::IsSafeToRunScript() || mOwnerContent->OwnerDoc()->IsStaticDocument(), @@ -2668,6 +2670,14 @@ bool nsFrameLoader::TryRemoteBrowser() { return false; } +nsIFrame* nsFrameLoader::GetPrimaryFrameOfOwningContent() const { + return mOwnerContent ? mOwnerContent->GetPrimaryFrame() : nullptr; +} + +Document* nsFrameLoader::GetOwnerDoc() const { + return mOwnerContent ? mOwnerContent->OwnerDoc() : nullptr; +} + bool nsFrameLoader::IsRemoteFrame() { if (mIsRemoteFrame) { MOZ_ASSERT(!GetDocShell(), "Found a remote frame with a DocShell"); diff --git a/dom/base/nsFrameLoader.h b/dom/base/nsFrameLoader.h index df36b4db7d2e..a432b660f1e9 100644 --- a/dom/base/nsFrameLoader.h +++ b/dom/base/nsFrameLoader.h @@ -21,7 +21,6 @@ #include "mozilla/Attributes.h" #include "mozilla/RefPtr.h" #include "mozilla/dom/BrowsingContext.h" -#include "mozilla/dom/Element.h" #include "mozilla/dom/Nullable.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/WindowProxyHolder.h" @@ -61,6 +60,7 @@ namespace dom { class ChromeMessageSender; class ContentParent; class Document; +class Element; class TabListener; class InProcessBrowserChildMessageManager; class MessageSender; @@ -262,7 +262,7 @@ class nsFrameLoader final : public nsStubMutationObserver, */ bool OwnerIsMozBrowserFrame(); - nsIContent* GetParentObject() const { return mOwnerContent; } + nsIContent* GetParentObject() const; /** * MessageManagerCallback methods that we override. @@ -313,17 +313,13 @@ class nsFrameLoader final : public nsStubMutationObserver, * Return the primary frame for our owning content, or null if it * can't be found. */ - nsIFrame* GetPrimaryFrameOfOwningContent() const { - return mOwnerContent ? mOwnerContent->GetPrimaryFrame() : nullptr; - } + nsIFrame* GetPrimaryFrameOfOwningContent() const; /** * Return the document that owns this, or null if we don't have * an owner. */ - Document* GetOwnerDoc() const { - return mOwnerContent ? mOwnerContent->OwnerDoc() : nullptr; - } + Document* GetOwnerDoc() const; /** * Returns whether this frame is a remote frame. diff --git a/dom/base/nsStyledElement.h b/dom/base/nsStyledElement.h index 65fc55f96c91..534baa914e5a 100644 --- a/dom/base/nsStyledElement.h +++ b/dom/base/nsStyledElement.h @@ -16,7 +16,6 @@ #include "mozilla/Attributes.h" #include "mozilla/dom/Element.h" #include "nsString.h" -#include "mozilla/dom/Element.h" namespace mozilla { class DeclarationBlock; diff --git a/dom/base/nsTreeSanitizer.h b/dom/base/nsTreeSanitizer.h index 956a67569561..6777e993a20c 100644 --- a/dom/base/nsTreeSanitizer.h +++ b/dom/base/nsTreeSanitizer.h @@ -8,7 +8,6 @@ #include "nsAtom.h" #include "nsHashKeys.h" #include "nsIPrincipal.h" -#include "mozilla/dom/Element.h" #include "nsTHashtable.h" class nsIContent; @@ -20,7 +19,8 @@ class DeclarationBlock; namespace mozilla::dom { class DocumentFragment; -} // namespace mozilla::dom +class Element; +} /** * See the documentation of nsIParserUtils::sanitize for documentation diff --git a/dom/grid/Grid.h b/dom/grid/Grid.h index d64a479fcf0e..946a5fee78fc 100644 --- a/dom/grid/Grid.h +++ b/dom/grid/Grid.h @@ -8,7 +8,6 @@ #define mozilla_dom_Grid_h #include "GridArea.h" -#include "mozilla/dom/Element.h" #include "nsGridContainerFrame.h" #include "nsISupports.h" #include "nsWrapperCache.h" @@ -16,6 +15,7 @@ namespace mozilla { namespace dom { +class Element; class GridDimension; class Grid : public nsISupports, public nsWrapperCache { diff --git a/dom/html/HTMLFormControlsCollection.h b/dom/html/HTMLFormControlsCollection.h index aa5f59238346..9e31b9df9040 100644 --- a/dom/html/HTMLFormControlsCollection.h +++ b/dom/html/HTMLFormControlsCollection.h @@ -7,7 +7,6 @@ #ifndef mozilla_dom_HTMLFormControlsCollection_h #define mozilla_dom_HTMLFormControlsCollection_h -#include "mozilla/dom/Element.h" // DOMProxyHandler::getOwnPropertyDescriptor #include "nsIHTMLCollection.h" #include "nsInterfaceHashtable.h" #include "nsTArray.h" @@ -20,6 +19,7 @@ class RefPtr; namespace mozilla { namespace dom { +class Element; class HTMLFormElement; class HTMLImageElement; class OwningRadioNodeListOrElement; diff --git a/dom/html/HTMLFormSubmission.cpp b/dom/html/HTMLFormSubmission.cpp index 7154543e9a02..20164bc79982 100644 --- a/dom/html/HTMLFormSubmission.cpp +++ b/dom/html/HTMLFormSubmission.cpp @@ -707,6 +707,17 @@ nsresult FSTextPlain::GetEncodedSubmission(nsIURI* aURI, // -------------------------------------------------------------------------- +HTMLFormSubmission::HTMLFormSubmission( + nsIURI* aActionURL, const nsAString& aTarget, + mozilla::NotNull aEncoding, Element* aSubmitter) + : mActionURL(aActionURL), + mTarget(aTarget), + mEncoding(aEncoding), + mSubmitter(aSubmitter), + mInitiatedFromUserInput(UserActivation::IsHandlingUserInput()) { + MOZ_COUNT_CTOR(HTMLFormSubmission); +} + EncodingFormSubmission::EncodingFormSubmission( nsIURI* aActionURL, const nsAString& aTarget, NotNull aEncoding, Element* aSubmitter) diff --git a/dom/html/HTMLFormSubmission.h b/dom/html/HTMLFormSubmission.h index 67217e28edf2..dcdaef82118b 100644 --- a/dom/html/HTMLFormSubmission.h +++ b/dom/html/HTMLFormSubmission.h @@ -8,7 +8,6 @@ #define mozilla_dom_HTMLFormSubmission_h #include "mozilla/Attributes.h" -#include "mozilla/dom/Element.h" #include "mozilla/dom/UserActivation.h" #include "mozilla/dom/HTMLDialogElement.h" #include "nsCOMPtr.h" @@ -25,6 +24,7 @@ namespace dom { class Blob; class Directory; +class Element; class HTMLFormElement; /** @@ -122,14 +122,7 @@ class HTMLFormSubmission { */ HTMLFormSubmission(nsIURI* aActionURL, const nsAString& aTarget, mozilla::NotNull aEncoding, - Element* aSubmitter) - : mActionURL(aActionURL), - mTarget(aTarget), - mEncoding(aEncoding), - mSubmitter(aSubmitter), - mInitiatedFromUserInput(UserActivation::IsHandlingUserInput()) { - MOZ_COUNT_CTOR(HTMLFormSubmission); - } + Element* aSubmitter); // The action url. nsCOMPtr mActionURL; diff --git a/dom/html/TextControlState.h b/dom/html/TextControlState.h index 45de0e309ecf..ac6272461d4e 100644 --- a/dom/html/TextControlState.h +++ b/dom/html/TextControlState.h @@ -13,7 +13,6 @@ #include "mozilla/TextControlElement.h" #include "mozilla/TextEditor.h" #include "mozilla/WeakPtr.h" -#include "mozilla/dom/Element.h" #include "mozilla/dom/HTMLInputElementBinding.h" #include "mozilla/dom/Nullable.h" #include "nsCycleCollectionParticipant.h" @@ -32,6 +31,7 @@ class TextInputListener; class TextInputSelectionController; namespace dom { +class Element; class HTMLInputElement; } // namespace dom diff --git a/dom/html/nsDOMStringMap.h b/dom/html/nsDOMStringMap.h index e03a91431017..284627dfa80b 100644 --- a/dom/html/nsDOMStringMap.h +++ b/dom/html/nsDOMStringMap.h @@ -12,7 +12,6 @@ #include "nsTArray.h" #include "nsString.h" #include "nsWrapperCache.h" -#include "mozilla/dom/Element.h" #include "js/friend/DOMProxy.h" // JS::ExpandoAndGeneration #include "js/RootingAPI.h" // JS::Handle diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index af04525721c7..9a3be6621f4b 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -18,7 +18,6 @@ #include "mozilla/dom/Element.h" #include "mozilla/dom/DOMRect.h" #include "mozilla/dom/ValidityState.h" -#include "mozilla/dom/Element.h" class nsDOMTokenList; class nsIFormControlFrame; diff --git a/dom/l10n/DOMLocalization.h b/dom/l10n/DOMLocalization.h index 0e023fe4cef3..f6ea7bd9b327 100644 --- a/dom/l10n/DOMLocalization.h +++ b/dom/l10n/DOMLocalization.h @@ -10,7 +10,6 @@ #include "nsXULPrototypeDocument.h" #include "mozilla/intl/Localization.h" #include "mozilla/dom/DOMLocalizationBinding.h" -#include "mozilla/dom/Element.h" #include "mozilla/dom/L10nMutations.h" #include "mozilla/dom/L10nOverlaysBinding.h" #include "mozilla/dom/LocalizationBinding.h" @@ -21,6 +20,7 @@ namespace mozilla { namespace dom { +class Element; class L10nMutations; class DOMLocalization : public intl::Localization { diff --git a/dom/l10n/L10nOverlays.h b/dom/l10n/L10nOverlays.h index b60d11187b46..0450fb130ddc 100644 --- a/dom/l10n/L10nOverlays.h +++ b/dom/l10n/L10nOverlays.h @@ -7,7 +7,6 @@ #ifndef mozilla_dom_l10n_L10nOverlays_h #define mozilla_dom_l10n_L10nOverlays_h -#include "mozilla/dom/Element.h" #include "mozilla/dom/L10nOverlaysBinding.h" #include "mozilla/dom/LocalizationBinding.h" @@ -17,6 +16,7 @@ namespace mozilla { namespace dom { class DocumentFragment; +class Element; class L10nOverlays { public: diff --git a/dom/script/ScriptLoadRequest.cpp b/dom/script/ScriptLoadRequest.cpp index e97fb4c009fa..08c72a118c46 100644 --- a/dom/script/ScriptLoadRequest.cpp +++ b/dom/script/ScriptLoadRequest.cpp @@ -260,6 +260,20 @@ void ScriptLoadRequest::PrioritizeAsPreload() { } } +nsIScriptElement* ScriptLoadRequest::GetScriptElement() const { + nsCOMPtr scriptElement = + do_QueryInterface(mFetchOptions->mElement); + return scriptElement; +} + +void ScriptLoadRequest::SetIsLoadRequest(nsIScriptElement* aElement) { + MOZ_ASSERT(aElement); + MOZ_ASSERT(!GetScriptElement()); + MOZ_ASSERT(IsPreload()); + mFetchOptions->mElement = do_QueryInterface(aElement); + mFetchOptions->mIsPreload = false; +} + ////////////////////////////////////////////////////////////// // ScriptLoadRequestList ////////////////////////////////////////////////////////////// diff --git a/dom/script/ScriptLoadRequest.h b/dom/script/ScriptLoadRequest.h index da1a19a15a97..a63f9dac87e5 100644 --- a/dom/script/ScriptLoadRequest.h +++ b/dom/script/ScriptLoadRequest.h @@ -12,7 +12,6 @@ #include "mozilla/Atomics.h" #include "mozilla/Assertions.h" #include "mozilla/CORSMode.h" -#include "mozilla/dom/Element.h" #include "mozilla/dom/SRIMetadata.h" #include "mozilla/LinkedList.h" #include "mozilla/Maybe.h" @@ -30,6 +29,7 @@ class nsICacheInfoChannel; namespace mozilla { namespace dom { +class Element; class ModuleLoadRequest; class ScriptLoadRequestList; @@ -248,11 +248,7 @@ class ScriptLoadRequest enum ReferrerPolicy ReferrerPolicy() const { return mFetchOptions->mReferrerPolicy; } - nsIScriptElement* GetScriptElement() const { - nsCOMPtr scriptElement = - do_QueryInterface(mFetchOptions->mElement); - return scriptElement; - } + nsIScriptElement* GetScriptElement() const; nsIPrincipal* TriggeringPrincipal() const { return mFetchOptions->mTriggeringPrincipal; } @@ -265,13 +261,7 @@ class ScriptLoadRequest } // Make a preload request into an actual load request for the given element. - void SetIsLoadRequest(nsIScriptElement* aElement) { - MOZ_ASSERT(aElement); - MOZ_ASSERT(!GetScriptElement()); - MOZ_ASSERT(IsPreload()); - mFetchOptions->mElement = do_QueryInterface(aElement); - mFetchOptions->mIsPreload = false; - } + void SetIsLoadRequest(nsIScriptElement* aElement); FromParser GetParserCreated() const { nsIScriptElement* element = GetScriptElement(); diff --git a/dom/smil/SMILTargetIdentifier.h b/dom/smil/SMILTargetIdentifier.h index 945c47743086..14a2ee315242 100644 --- a/dom/smil/SMILTargetIdentifier.h +++ b/dom/smil/SMILTargetIdentifier.h @@ -15,6 +15,9 @@ class nsIContent; namespace mozilla { +namespace dom { +class Element; +} /** * Struct: SMILTargetIdentifier diff --git a/dom/xslt/xslt/txMozillaXMLOutput.h b/dom/xslt/xslt/txMozillaXMLOutput.h index 1c4dac6c0822..6b9e5d24da49 100644 --- a/dom/xslt/xslt/txMozillaXMLOutput.h +++ b/dom/xslt/xslt/txMozillaXMLOutput.h @@ -14,7 +14,6 @@ #include "nsICSSLoaderObserver.h" #include "txStack.h" #include "mozilla/Attributes.h" -#include "mozilla/dom/Element.h" class nsIContent; class nsAtom; @@ -26,6 +25,7 @@ namespace mozilla { namespace dom { class Document; class DocumentFragment; +class Element; } // namespace dom } // namespace mozilla diff --git a/dom/xul/XULBroadcastManager.cpp b/dom/xul/XULBroadcastManager.cpp index f7d721e5d313..9246ad19bed4 100644 --- a/dom/xul/XULBroadcastManager.cpp +++ b/dom/xul/XULBroadcastManager.cpp @@ -64,6 +64,48 @@ namespace mozilla { namespace dom { static LazyLogModule sXULBroadCastManager("XULBroadcastManager"); +class XULBroadcastManager::nsDelayedBroadcastUpdate { + public: + nsDelayedBroadcastUpdate(Element* aBroadcaster, Element* aListener, + const nsAString& aAttr) + : mBroadcaster(aBroadcaster), + mListener(aListener), + mAttr(aAttr), + mSetAttr(false), + mNeedsAttrChange(false) {} + + nsDelayedBroadcastUpdate(Element* aBroadcaster, Element* aListener, + nsAtom* aAttrName, const nsAString& aAttr, + bool aSetAttr, bool aNeedsAttrChange) + : mBroadcaster(aBroadcaster), + mListener(aListener), + mAttr(aAttr), + mAttrName(aAttrName), + mSetAttr(aSetAttr), + mNeedsAttrChange(aNeedsAttrChange) {} + + nsDelayedBroadcastUpdate(const nsDelayedBroadcastUpdate& aOther) = delete; + nsDelayedBroadcastUpdate(nsDelayedBroadcastUpdate&& aOther) = default; + + nsCOMPtr mBroadcaster; + nsCOMPtr mListener; + // Note if mAttrName isn't used, this is the name of the attr, otherwise + // this is the value of the attribute. + nsString mAttr; + RefPtr mAttrName; + bool mSetAttr; + bool mNeedsAttrChange; + + class Comparator { + public: + static bool Equals(const nsDelayedBroadcastUpdate& a, + const nsDelayedBroadcastUpdate& b) { + return a.mBroadcaster == b.mBroadcaster && a.mListener == b.mListener && + a.mAttrName == b.mAttrName; + } + }; +}; + /* static */ bool XULBroadcastManager::MayNeedListener(const Element& aElement) { if (aElement.NodeInfo()->Equals(nsGkAtoms::observes, kNameSpaceID_XUL)) { diff --git a/dom/xul/XULBroadcastManager.h b/dom/xul/XULBroadcastManager.h index d350939468f6..c5fcbf3bf7ec 100644 --- a/dom/xul/XULBroadcastManager.h +++ b/dom/xul/XULBroadcastManager.h @@ -7,7 +7,6 @@ #ifndef mozilla_dom_XULBroadcastManager_h #define mozilla_dom_XULBroadcastManager_h -#include "mozilla/dom/Element.h" #include "nsAtom.h" #include "nsTArray.h" @@ -75,47 +74,7 @@ class XULBroadcastManager final { */ PLDHashTable* mBroadcasterMap; - class nsDelayedBroadcastUpdate { - public: - nsDelayedBroadcastUpdate(Element* aBroadcaster, Element* aListener, - const nsAString& aAttr) - : mBroadcaster(aBroadcaster), - mListener(aListener), - mAttr(aAttr), - mSetAttr(false), - mNeedsAttrChange(false) {} - - nsDelayedBroadcastUpdate(Element* aBroadcaster, Element* aListener, - nsAtom* aAttrName, const nsAString& aAttr, - bool aSetAttr, bool aNeedsAttrChange) - : mBroadcaster(aBroadcaster), - mListener(aListener), - mAttr(aAttr), - mAttrName(aAttrName), - mSetAttr(aSetAttr), - mNeedsAttrChange(aNeedsAttrChange) {} - - nsDelayedBroadcastUpdate(const nsDelayedBroadcastUpdate& aOther) = delete; - nsDelayedBroadcastUpdate(nsDelayedBroadcastUpdate&& aOther) = default; - - nsCOMPtr mBroadcaster; - nsCOMPtr mListener; - // Note if mAttrName isn't used, this is the name of the attr, otherwise - // this is the value of the attribute. - nsString mAttr; - RefPtr mAttrName; - bool mSetAttr; - bool mNeedsAttrChange; - - class Comparator { - public: - static bool Equals(const nsDelayedBroadcastUpdate& a, - const nsDelayedBroadcastUpdate& b) { - return a.mBroadcaster == b.mBroadcaster && a.mListener == b.mListener && - a.mAttrName == b.mAttrName; - } - }; - }; + class nsDelayedBroadcastUpdate; nsTArray mDelayedBroadcasters; nsTArray mDelayedAttrChangeBroadcasts; bool mHandlingDelayedAttrChange; diff --git a/dom/xul/nsXULPopupListener.h b/dom/xul/nsXULPopupListener.h index db203ae793f2..8f94e6d6cf0e 100644 --- a/dom/xul/nsXULPopupListener.h +++ b/dom/xul/nsXULPopupListener.h @@ -12,7 +12,6 @@ #include "nsCOMPtr.h" -#include "mozilla/dom/Element.h" #include "nsIDOMEventListener.h" #include "nsCycleCollectionParticipant.h" @@ -20,6 +19,7 @@ class nsIContent; namespace mozilla { namespace dom { +class Element; class MouseEvent; } // namespace dom } // namespace mozilla diff --git a/dom/xul/nsXULPrototypeDocument.h b/dom/xul/nsXULPrototypeDocument.h index 29fdb5f745c8..3db185403e9c 100644 --- a/dom/xul/nsXULPrototypeDocument.h +++ b/dom/xul/nsXULPrototypeDocument.h @@ -14,7 +14,6 @@ #include "nsISerializable.h" #include "nsCycleCollectionParticipant.h" #include -#include "mozilla/dom/Element.h" class nsAtom; class nsIPrincipal; @@ -23,6 +22,10 @@ class nsNodeInfoManager; class nsXULPrototypeElement; class nsXULPrototypePI; +namespace mozilla::dom { +class Element; +} + /** * A "prototype" document that stores shared document information * for the XUL cache. diff --git a/editor/libeditor/CreateElementTransaction.h b/editor/libeditor/CreateElementTransaction.h index 7278ea94fbcc..fc87f500b1dc 100644 --- a/editor/libeditor/CreateElementTransaction.h +++ b/editor/libeditor/CreateElementTransaction.h @@ -9,7 +9,6 @@ #include "mozilla/EditorDOMPoint.h" #include "mozilla/EditTransactionBase.h" #include "mozilla/RefPtr.h" -#include "mozilla/dom/Element.h" #include "nsCycleCollectionParticipant.h" #include "nsISupportsImpl.h" @@ -19,6 +18,9 @@ class nsAtom; * A transaction that creates a new node in the content tree. */ namespace mozilla { +namespace dom { +class Element; +} class EditorBase; diff --git a/layout/base/AccessibleCaret.h b/layout/base/AccessibleCaret.h index 31e2449e998e..a1ffab3b4fd8 100644 --- a/layout/base/AccessibleCaret.h +++ b/layout/base/AccessibleCaret.h @@ -9,7 +9,6 @@ #include "mozilla/Attributes.h" #include "mozilla/dom/AnonymousContent.h" -#include "mozilla/dom/Element.h" #include "nsCOMPtr.h" #include "nsIDOMEventListener.h" #include "nsIFrame.h" // for WeakFrame only @@ -26,6 +25,7 @@ struct nsPoint; namespace mozilla { class PresShell; namespace dom { +class Element; class Event; } // namespace dom diff --git a/layout/forms/nsTextControlFrame.h b/layout/forms/nsTextControlFrame.h index 753854f4e316..c7298fc164b8 100644 --- a/layout/forms/nsTextControlFrame.h +++ b/layout/forms/nsTextControlFrame.h @@ -9,7 +9,6 @@ #include "mozilla/Attributes.h" #include "mozilla/TextControlElement.h" -#include "mozilla/dom/Element.h" #include "nsContainerFrame.h" #include "nsIAnonymousContentCreator.h" #include "nsIContent.h" diff --git a/layout/style/AnimationCollection.cpp b/layout/style/AnimationCollection.cpp index c10ff0acbee1..1226c742029c 100644 --- a/layout/style/AnimationCollection.cpp +++ b/layout/style/AnimationCollection.cpp @@ -128,6 +128,14 @@ AnimationCollection::GetPropertyAtomForPseudoType( return propName; } +template +void AnimationCollection::Destroy() { + mCalledDestroy = true; + + // This will call our destructor. + mElement->RemoveProperty(mElementProperty); +} + // Explicit class instantiations template class AnimationCollection; diff --git a/layout/style/AnimationCollection.h b/layout/style/AnimationCollection.h index de174ef1f9a1..8bfd00ab9bfc 100644 --- a/layout/style/AnimationCollection.h +++ b/layout/style/AnimationCollection.h @@ -7,7 +7,6 @@ #ifndef mozilla_AnimationCollection_h #define mozilla_AnimationCollection_h -#include "mozilla/dom/Element.h" #include "mozilla/Assertions.h" #include "mozilla/LinkedList.h" #include "mozilla/RefPtr.h" @@ -19,6 +18,9 @@ class nsIFrame; class nsPresContext; namespace mozilla { +namespace dom { +class Element; +} // Traits class to define the specific atoms used when storing specializations // of AnimationCollection as a property on an Element (e.g. which atom @@ -46,12 +48,7 @@ class AnimationCollection LinkedListElement::remove(); } - void Destroy() { - mCalledDestroy = true; - - // This will call our destructor. - mElement->RemoveProperty(mElementProperty); - } + void Destroy(); static void PropertyDtor(void* aObject, nsAtom* aPropertyName, void* aPropertyValue, void* aData); diff --git a/layout/style/ServoElementSnapshot.cpp b/layout/style/ServoElementSnapshot.cpp index b81aa3db8678..8c661072dfdb 100644 --- a/layout/style/ServoElementSnapshot.cpp +++ b/layout/style/ServoElementSnapshot.cpp @@ -38,4 +38,50 @@ void ServoElementSnapshot::AddOtherPseudoClassState(const Element& aElement) { mContains |= Flags::OtherPseudoClassState; } +void ServoElementSnapshot::AddAttrs(const Element& aElement, + int32_t aNameSpaceID, nsAtom* aAttribute) { + if (aNameSpaceID == kNameSpaceID_None) { + if (aAttribute == nsGkAtoms::_class) { + if (mClassAttributeChanged) { + return; + } + mClassAttributeChanged = true; + } else if (aAttribute == nsGkAtoms::id) { + if (mIdAttributeChanged) { + return; + } + mIdAttributeChanged = true; + } + } + + if (!mChangedAttrNames.Contains(aAttribute)) { + mChangedAttrNames.AppendElement(aAttribute); + } + + if (HasAttrs()) { + return; + } + + uint32_t attrCount = aElement.GetAttrCount(); + mAttrs.SetCapacity(attrCount); + for (uint32_t i = 0; i < attrCount; ++i) { + const BorrowedAttrInfo info = aElement.GetAttrInfoAt(i); + MOZ_ASSERT(info); + mAttrs.AppendElement(AttrArray::InternalAttr{*info.mName, *info.mValue}); + } + + mContains |= Flags::Attributes; + if (aElement.HasID()) { + mContains |= Flags::Id; + } + + if (const nsAttrValue* classValue = aElement.GetClasses()) { + // FIXME(emilio): It's pretty unfortunate that this is only relevant for + // SVG, yet it's a somewhat expensive copy. We should be able to do + // better! + mClass = *classValue; + mContains |= Flags::MaybeClass; + } +} + } // namespace mozilla diff --git a/layout/style/ServoElementSnapshot.h b/layout/style/ServoElementSnapshot.h index 0094eaa53ba2..5f422f04a59f 100644 --- a/layout/style/ServoElementSnapshot.h +++ b/layout/style/ServoElementSnapshot.h @@ -11,7 +11,6 @@ #include "mozilla/EventStates.h" #include "mozilla/TypedEnumBits.h" #include "mozilla/dom/BorrowedAttrInfo.h" -#include "mozilla/dom/Element.h" #include "nsAttrName.h" #include "nsAttrValue.h" #include "nsChangeHint.h" @@ -19,6 +18,9 @@ #include "nsAtom.h" namespace mozilla { +namespace dom { +class Element; +} /** * A bitflags enum class used to determine what data does a ServoElementSnapshot @@ -80,8 +82,7 @@ class ServoElementSnapshot { * The attribute name and namespace are used to note which kind of attribute * has changed. */ - inline void AddAttrs(const Element&, int32_t aNameSpaceID, - nsAtom* aAttribute); + void AddAttrs(const Element&, int32_t aNameSpaceID, nsAtom* aAttribute); /** * Captures some other pseudo-class matching state not included in @@ -167,53 +168,6 @@ class ServoElementSnapshot { bool mIdAttributeChanged : 1; }; -inline void ServoElementSnapshot::AddAttrs(const Element& aElement, - int32_t aNameSpaceID, - nsAtom* aAttribute) { - if (aNameSpaceID == kNameSpaceID_None) { - if (aAttribute == nsGkAtoms::_class) { - if (mClassAttributeChanged) { - return; - } - mClassAttributeChanged = true; - } else if (aAttribute == nsGkAtoms::id) { - if (mIdAttributeChanged) { - return; - } - mIdAttributeChanged = true; - } - } - - if (!mChangedAttrNames.Contains(aAttribute)) { - mChangedAttrNames.AppendElement(aAttribute); - } - - if (HasAttrs()) { - return; - } - - uint32_t attrCount = aElement.GetAttrCount(); - mAttrs.SetCapacity(attrCount); - for (uint32_t i = 0; i < attrCount; ++i) { - const BorrowedAttrInfo info = aElement.GetAttrInfoAt(i); - MOZ_ASSERT(info); - mAttrs.AppendElement(AttrArray::InternalAttr{*info.mName, *info.mValue}); - } - - mContains |= Flags::Attributes; - if (aElement.HasID()) { - mContains |= Flags::Id; - } - - if (const nsAttrValue* classValue = aElement.GetClasses()) { - // FIXME(emilio): It's pretty unfortunate that this is only relevant for - // SVG, yet it's a somewhat expensive copy. We should be able to do - // better! - mClass = *classValue; - mContains |= Flags::MaybeClass; - } -} - } // namespace mozilla #endif diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h index b45dfa39729a..4f27ae307512 100644 --- a/layout/style/nsComputedDOMStyle.h +++ b/layout/style/nsComputedDOMStyle.h @@ -12,7 +12,6 @@ #include "mozilla/Attributes.h" #include "mozilla/StyleColorInlines.h" #include "mozilla/UniquePtr.h" -#include "mozilla/dom/Element.h" #include "nsCOMPtr.h" #include "nsContentUtils.h" #include "nscore.h" diff --git a/layout/svg/SVGObserverUtils.h b/layout/svg/SVGObserverUtils.h index db2ece668250..2d8cb875ceae 100644 --- a/layout/svg/SVGObserverUtils.h +++ b/layout/svg/SVGObserverUtils.h @@ -10,7 +10,6 @@ #include "mozilla/Attributes.h" #include "mozilla/dom/IDTracker.h" #include "FrameProperties.h" -#include "mozilla/dom/Element.h" #include "nsID.h" #include "nsIFrame.h" // only for LayoutFrameType #include "nsIMutationObserver.h" @@ -35,6 +34,7 @@ class SVGPaintServerFrame; namespace dom { class CanvasRenderingContext2D; +class Element; class SVGGeometryElement; } // namespace dom } // namespace mozilla