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
--- a/dom/base/CharacterData.cpp
+++ b/dom/base/CharacterData.cpp
@@ -436,17 +436,18 @@ CharacterData::ToCString(nsAString& aBuf
}
}
}
}
#endif
nsresult
-CharacterData::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
+CharacterData::BindToTree(nsIDocument* aDocument,
+ nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers)
{
MOZ_ASSERT(aParent || aDocument, "Must have document if no parent!");
MOZ_ASSERT(NODE_FROM(aParent, aDocument)->OwnerDoc() == OwnerDoc(),
"Must have the same owner document");
MOZ_ASSERT(!aParent || aDocument == aParent->GetUncomposedDoc(),
"aDocument must be current doc of aParent");
@@ -596,107 +597,20 @@ CharacterData::UnbindFromTree(bool aDeep
if (aNullParent || !mParent->IsInShadowTree()) {
slots->mContainingShadow = nullptr;
}
}
nsNodeUtils::ParentChainChanged(this);
}
-already_AddRefed<nsINodeList>
-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,
bool aNotify)
{
return SetTextInternal(0, mText.GetLength(), aBuffer, aLength, aNotify);
}
@@ -754,29 +668,16 @@ CharacterData::ThreadSafeTextIsOnlyWhite
}
++cp;
}
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<nsAtom>
CharacterData::GetCurrentValueAtom()
{
nsAutoString val;
GetData(val);
return NS_Atomize(val);
}
--- a/dom/base/CharacterData.h
+++ b/dom/base/CharacterData.h
@@ -95,96 +95,161 @@ public:
NS_IMPL_FROMNODE_HELPER(CharacterData, IsCharacterData())
virtual void GetNodeValueInternal(nsAString& aNodeValue) override;
virtual void SetNodeValueInternal(const nsAString& aNodeValue,
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);
return SetNodeValue(aTextContent, aError);
}
// 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;
+
+ void UnbindFromTree(bool aDeep = true, bool aNullParent = true) override;
+
+ already_AddRefed<nsINodeList> GetChildren(uint32_t aFilter) final
+ {
+ return nullptr;
+ }
- virtual already_AddRefed<nsINodeList> GetChildren(uint32_t aFilter) override;
+ const nsTextFragment* GetText() override
+ {
+ return &mText;
+ }
- virtual const nsTextFragment *GetText() override;
- virtual uint32_t TextLength() const override;
+ 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
* the document is notified of the content change.
*/
nsresult SetText(const nsAString& aStr, bool aNotify)
{
return SetText(aStr.BeginReading(), aStr.Length(), aNotify);
}
/**
* 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;
+ }
+
+ bool IsNodeOfType(uint32_t aFlags) const override
+ {
+ return false;
+ }
- virtual nsresult Clone(dom::NodeInfo *aNodeInfo, nsINode **aResult,
- bool aPreallocateChildren) const override
+ bool IsLink(nsIURI** aURI) const final
+ {
+ *aURI = nullptr;
+ return false;
+ }
+
+ nsresult Clone(dom::NodeInfo* aNodeInfo,
+ nsINode** aResult,
+ bool aPreallocateChildren) const override
{
RefPtr<CharacterData> result = CloneDataNode(aNodeInfo, true);
result.forget(aResult);
if (!*aResult) {
return NS_ERROR_OUT_OF_MEMORY;
}
@@ -215,17 +280,17 @@ public:
#endif
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_INHERITED(CharacterData,
nsIContent)
protected:
virtual ~CharacterData();
- virtual Element* GetNameSpaceElement() override
+ Element* GetNameSpaceElement() final
{
return Element::FromNodeOrNull(GetParentNode());
}
nsresult SetTextInternal(uint32_t aOffset, uint32_t aCount,
const char16_t* aBuffer, uint32_t aLength,
bool aNotify,
CharacterDataChangeInfo::Details* aDetails = nullptr);
@@ -234,17 +299,17 @@ protected:
* Method to clone this node. This needs to be overriden by all derived
* classes. If aCloneText is true the text content will be cloned too.
*
* @param aOwnerDocument the ownerDocument of the clone
* @param aCloneText if true the text content will be cloned too
* @return the clone
*/
virtual already_AddRefed<CharacterData>
- CloneDataNode(dom::NodeInfo *aNodeInfo, bool aCloneText) const = 0;
+ CloneDataNode(dom::NodeInfo* aNodeInfo, bool aCloneText) const = 0;
nsTextFragment mText;
private:
already_AddRefed<nsAtom> GetCurrentValueAtom();
};
} // namespace dom