From d042e82e853725cb1e88b52e4e7f755c45bf19b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 1 Jul 2018 17:17:40 +0200 Subject: [PATCH] Bug 1472529: Cleanup CharacterData, and add a non-virtual function to get the text fragment. r=smaug I'm going to use that from nsFind. MozReview-Commit-ID: EhkNQ3BFTvX --- dom/base/CharacterData.cpp | 103 +--------------------------- dom/base/CharacterData.h | 133 +++++++++++++++++++++++++++---------- 2 files changed, 101 insertions(+), 135 deletions(-) diff --git a/dom/base/CharacterData.cpp b/dom/base/CharacterData.cpp index c66a8294744c..f66ed73fddd6 100644 --- a/dom/base/CharacterData.cpp +++ b/dom/base/CharacterData.cpp @@ -441,7 +441,8 @@ CharacterData::ToCString(nsAString& aBuf, int32_t aOffset, nsresult -CharacterData::BindToTree(nsIDocument* aDocument, nsIContent* aParent, +CharacterData::BindToTree(nsIDocument* aDocument, + nsIContent* aParent, nsIContent* aBindingParent, bool aCompileEventHandlers) { @@ -601,97 +602,10 @@ CharacterData::UnbindFromTree(bool aDeep, bool aNullParent) nsNodeUtils::ParentChainChanged(this); } -already_AddRefed -CharacterData::GetChildren(uint32_t aFilter) -{ - return nullptr; -} - -uint32_t -CharacterData::GetChildCount() const -{ - return 0; -} - -nsIContent * -CharacterData::GetChildAt_Deprecated(uint32_t aIndex) const -{ - return nullptr; -} - - -int32_t -CharacterData::ComputeIndexOf(const nsINode* aPossibleChild) const -{ - return -1; -} - -nsresult -CharacterData::InsertChildBefore(nsIContent* aKid, - nsIContent* aBeforeThis, - bool aNotify) -{ - return NS_OK; -} - -void -CharacterData::RemoveChildNode(nsIContent* aKid, bool aNotify) -{ -} - -nsXBLBinding * -CharacterData::DoGetXBLBinding() const -{ - return nullptr; -} - -bool -CharacterData::IsNodeOfType(uint32_t aFlags) const -{ - return false; -} - -void -CharacterData::SaveSubtreeState() -{ -} - -#ifdef DEBUG -void -CharacterData::List(FILE* out, int32_t aIndent) const -{ -} - -void -CharacterData::DumpContent(FILE* out, int32_t aIndent, - bool aDumpAll) const -{ -} -#endif - -bool -CharacterData::IsLink(nsIURI** aURI) const -{ - *aURI = nullptr; - return false; -} - //---------------------------------------------------------------------- // Implementation of the nsIContent interface text functions -const nsTextFragment * -CharacterData::GetText() -{ - return &mText; -} - -uint32_t -CharacterData::TextLength() const -{ - return TextDataLength(); -} - nsresult CharacterData::SetText(const char16_t* aBuffer, uint32_t aLength, @@ -759,19 +673,6 @@ CharacterData::ThreadSafeTextIsOnlyWhitespace() const return true; } -void -CharacterData::AppendTextTo(nsAString& aResult) -{ - mText.AppendTo(aResult); -} - -bool -CharacterData::AppendTextTo(nsAString& aResult, - const mozilla::fallible_t& aFallible) -{ - return mText.AppendTo(aResult, aFallible); -} - already_AddRefed CharacterData::GetCurrentValueAtom() { diff --git a/dom/base/CharacterData.h b/dom/base/CharacterData.h index f9f8027c2ff7..24ff675f61be 100644 --- a/dom/base/CharacterData.h +++ b/dom/base/CharacterData.h @@ -100,20 +100,40 @@ public: ErrorResult& aError) override; // nsINode methods - virtual uint32_t GetChildCount() const override; - virtual nsIContent *GetChildAt_Deprecated(uint32_t aIndex) const override; - virtual int32_t ComputeIndexOf(const nsINode* aPossibleChild) const override; - virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis, - bool aNotify) override; - virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override; - virtual void GetTextContentInternal(nsAString& aTextContent, - OOMReporter& aError) override + uint32_t GetChildCount() const final + { + return 0; + } + + nsIContent* GetChildAt_Deprecated(uint32_t aIndex) const final + { + return nullptr; + } + + int32_t ComputeIndexOf(const nsINode* aPossibleChild) const final + { + return -1; + } + + nsresult InsertChildBefore(nsIContent* aKid, + nsIContent* aBeforeThis, + bool aNotify) final + { + return NS_OK; + } + + void RemoveChildNode(nsIContent* aKid, bool aNotify) final + { + } + + void GetTextContentInternal(nsAString& aTextContent, OOMReporter&) final { GetNodeValue(aTextContent); } - virtual void SetTextContentInternal(const nsAString& aTextContent, - nsIPrincipal* aSubjectPrincipal, - ErrorResult& aError) override + + void SetTextContentInternal(const nsAString& aTextContent, + nsIPrincipal* aSubjectPrincipal, + ErrorResult& aError) final { // Batch possible DOMSubtreeModified events. mozAutoSubtreeModified subtree(OwnerDoc(), nullptr); @@ -121,22 +141,39 @@ public: } // Implementation for nsIContent - virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, - nsIContent* aBindingParent, - bool aCompileEventHandlers) override; - virtual void UnbindFromTree(bool aDeep = true, - bool aNullParent = true) override; + nsresult BindToTree(nsIDocument* aDocument, + nsIContent* aParent, + nsIContent* aBindingParent, + bool aCompileEventHandlers) override; - virtual already_AddRefed GetChildren(uint32_t aFilter) override; + void UnbindFromTree(bool aDeep = true, bool aNullParent = true) override; - virtual const nsTextFragment *GetText() override; - virtual uint32_t TextLength() const override; + already_AddRefed GetChildren(uint32_t aFilter) final + { + return nullptr; + } + + const nsTextFragment* GetText() override + { + return &mText; + } + + const nsTextFragment& TextFragment() const + { + return mText; + } + + uint32_t TextLength() const final + { + return TextDataLength(); + } /** * Set the text to the given value. If aNotify is true then * the document is notified of the content change. */ - nsresult SetText(const char16_t* aBuffer, uint32_t aLength, + nsresult SetText(const char16_t* aBuffer, + uint32_t aLength, bool aNotify); /** * Append the given value to the current text. If aNotify is true then @@ -151,35 +188,63 @@ public: * Append the given value to the current text. If aNotify is true then * the document is notified of the content change. */ - nsresult AppendText(const char16_t* aBuffer, uint32_t aLength, + nsresult AppendText(const char16_t* aBuffer, + uint32_t aLength, bool aNotify); - virtual bool TextIsOnlyWhitespace() override; + bool TextIsOnlyWhitespace() final; bool ThreadSafeTextIsOnlyWhitespace() const final; /** * Append the text content to aResult. */ - void AppendTextTo(nsAString& aResult); + void AppendTextTo(nsAString& aResult) const + { + mText.AppendTo(aResult); + } + /** * Append the text content to aResult. */ MOZ_MUST_USE - bool AppendTextTo(nsAString& aResult, const fallible_t&); + bool AppendTextTo(nsAString& aResult, const fallible_t& aFallible) const + { + return mText.AppendTo(aResult, aFallible); + } - virtual void SaveSubtreeState() override; + void SaveSubtreeState() final + { + } #ifdef DEBUG - virtual void List(FILE* out, int32_t aIndent) const override; - virtual void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const override; + void List(FILE* out, int32_t aIndent) const override + { + } + + void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const override + { + } #endif - virtual nsXBLBinding* DoGetXBLBinding() const override; - virtual bool IsNodeOfType(uint32_t aFlags) const override; - virtual bool IsLink(nsIURI** aURI) const override; + nsXBLBinding* DoGetXBLBinding() const final + { + return nullptr; + } - virtual nsresult Clone(dom::NodeInfo *aNodeInfo, nsINode **aResult, - bool aPreallocateChildren) const override + bool IsNodeOfType(uint32_t aFlags) const override + { + return false; + } + + bool IsLink(nsIURI** aURI) const final + { + *aURI = nullptr; + return false; + } + + nsresult Clone(dom::NodeInfo* aNodeInfo, + nsINode** aResult, + bool aPreallocateChildren) const override { RefPtr result = CloneDataNode(aNodeInfo, true); result.forget(aResult); @@ -220,7 +285,7 @@ public: protected: virtual ~CharacterData(); - virtual Element* GetNameSpaceElement() override + Element* GetNameSpaceElement() final { return Element::FromNodeOrNull(GetParentNode()); } @@ -239,7 +304,7 @@ protected: * @return the clone */ virtual already_AddRefed - CloneDataNode(dom::NodeInfo *aNodeInfo, bool aCloneText) const = 0; + CloneDataNode(dom::NodeInfo* aNodeInfo, bool aCloneText) const = 0; nsTextFragment mText;