forked from mirrors/gecko-dev
Bug 1446533 part 4. Remove nsIDOMCharacterData::SubstringData. r=mystor
FromContent will be renamed to FromNode in bug 1447098. MozReview-Commit-ID: DhiN6mCOb34
This commit is contained in:
parent
000840f44a
commit
0678b901b6
9 changed files with 48 additions and 41 deletions
|
|
@ -191,15 +191,6 @@ CharacterData::GetLength(uint32_t* aLength)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
|
||||||
CharacterData::SubstringData(uint32_t aStart, uint32_t aCount,
|
|
||||||
nsAString& aReturn)
|
|
||||||
{
|
|
||||||
ErrorResult rv;
|
|
||||||
SubstringData(aStart, aCount, aReturn, rv);
|
|
||||||
return rv.StealNSResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CharacterData::SubstringData(uint32_t aStart, uint32_t aCount,
|
CharacterData::SubstringData(uint32_t aStart, uint32_t aCount,
|
||||||
nsAString& aReturn, ErrorResult& rv)
|
nsAString& aReturn, ErrorResult& rv)
|
||||||
|
|
|
||||||
|
|
@ -89,14 +89,14 @@ public:
|
||||||
SetFlags(NS_MAYBE_MODIFIED_FREQUENTLY);
|
SetFlags(NS_MAYBE_MODIFIED_FREQUENTLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMPL_FROMCONTENT_HELPER(CharacterData, IsCharacterData())
|
||||||
|
|
||||||
virtual void GetNodeValueInternal(nsAString& aNodeValue) override;
|
virtual void GetNodeValueInternal(nsAString& aNodeValue) override;
|
||||||
virtual void SetNodeValueInternal(const nsAString& aNodeValue,
|
virtual void SetNodeValueInternal(const nsAString& aNodeValue,
|
||||||
ErrorResult& aError) override;
|
ErrorResult& aError) override;
|
||||||
|
|
||||||
// Implementation for nsIDOMCharacterData
|
// Implementation for nsIDOMCharacterData
|
||||||
nsresult GetLength(uint32_t* aLength);
|
nsresult GetLength(uint32_t* aLength);
|
||||||
nsresult SubstringData(uint32_t aOffset, uint32_t aCount,
|
|
||||||
nsAString& aReturn);
|
|
||||||
nsresult AppendData(const nsAString& aArg);
|
nsresult AppendData(const nsAString& aArg);
|
||||||
nsresult InsertData(uint32_t aOffset, const nsAString& aArg);
|
nsresult InsertData(uint32_t aOffset, const nsAString& aArg);
|
||||||
nsresult DeleteData(uint32_t aOffset, uint32_t aCount);
|
nsresult DeleteData(uint32_t aOffset, uint32_t aCount);
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@
|
||||||
#include "mozilla/dom/Element.h"
|
#include "mozilla/dom/Element.h"
|
||||||
#include "mozilla/dom/ProcessingInstruction.h"
|
#include "mozilla/dom/ProcessingInstruction.h"
|
||||||
#include "mozilla/dom/ShadowRoot.h"
|
#include "mozilla/dom/ShadowRoot.h"
|
||||||
|
#include "mozilla/dom/Text.h"
|
||||||
#include "nsLayoutUtils.h"
|
#include "nsLayoutUtils.h"
|
||||||
#include "mozilla/ScopeExit.h"
|
#include "mozilla/ScopeExit.h"
|
||||||
|
|
||||||
|
|
@ -1599,7 +1600,7 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t
|
||||||
{
|
{
|
||||||
// some special casing for text nodes
|
// some special casing for text nodes
|
||||||
nsCOMPtr<nsINode> t = do_QueryInterface(aNode);
|
nsCOMPtr<nsINode> t = do_QueryInterface(aNode);
|
||||||
if (IsTextNode(t))
|
if (auto nodeAsText = t->GetAsText())
|
||||||
{
|
{
|
||||||
// if not at beginning of text node, we are done
|
// if not at beginning of text node, we are done
|
||||||
if (offset > 0)
|
if (offset > 0)
|
||||||
|
|
@ -1607,9 +1608,8 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t
|
||||||
// unless everything before us in just whitespace. NOTE: we need a more
|
// unless everything before us in just whitespace. NOTE: we need a more
|
||||||
// general solution that truly detects all cases of non-significant
|
// general solution that truly detects all cases of non-significant
|
||||||
// whitesace with no false alarms.
|
// whitesace with no false alarms.
|
||||||
nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(aNode);
|
|
||||||
nsAutoString text;
|
nsAutoString text;
|
||||||
nodeAsText->SubstringData(0, offset, text);
|
nodeAsText->SubstringData(0, offset, text, IgnoreErrors());
|
||||||
text.CompressWhitespace();
|
text.CompressWhitespace();
|
||||||
if (!text.IsEmpty())
|
if (!text.IsEmpty())
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
@ -1675,7 +1675,7 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t
|
||||||
{
|
{
|
||||||
// some special casing for text nodes
|
// some special casing for text nodes
|
||||||
nsCOMPtr<nsINode> n = do_QueryInterface(aNode);
|
nsCOMPtr<nsINode> n = do_QueryInterface(aNode);
|
||||||
if (IsTextNode(n))
|
if (auto nodeAsText = n->GetAsText())
|
||||||
{
|
{
|
||||||
// if not at end of text node, we are done
|
// if not at end of text node, we are done
|
||||||
uint32_t len = n->Length();
|
uint32_t len = n->Length();
|
||||||
|
|
@ -1684,9 +1684,8 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t
|
||||||
// unless everything after us in just whitespace. NOTE: we need a more
|
// unless everything after us in just whitespace. NOTE: we need a more
|
||||||
// general solution that truly detects all cases of non-significant
|
// general solution that truly detects all cases of non-significant
|
||||||
// whitespace with no false alarms.
|
// whitespace with no false alarms.
|
||||||
nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(aNode);
|
|
||||||
nsAutoString text;
|
nsAutoString text;
|
||||||
nodeAsText->SubstringData(offset, len-offset, text);
|
nodeAsText->SubstringData(offset, len-offset, text, IgnoreErrors());
|
||||||
text.CompressWhitespace();
|
text.CompressWhitespace();
|
||||||
if (!text.IsEmpty())
|
if (!text.IsEmpty())
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
||||||
|
|
@ -1009,19 +1009,19 @@ inline nsIContent* nsINode::AsContent()
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NS_IMPL_FROMCONTENT_HELPER(_class, _check) \
|
#define NS_IMPL_FROMCONTENT_HELPER(_class, _check) \
|
||||||
static _class* FromContent(nsIContent* aContent) \
|
static _class* FromContent(nsINode* aContent) \
|
||||||
{ \
|
{ \
|
||||||
return aContent->_check ? static_cast<_class*>(aContent) : nullptr; \
|
return aContent->_check ? static_cast<_class*>(aContent) : nullptr; \
|
||||||
} \
|
} \
|
||||||
static const _class* FromContent(const nsIContent* aContent) \
|
static const _class* FromContent(const nsINode* aContent) \
|
||||||
{ \
|
{ \
|
||||||
return aContent->_check ? static_cast<const _class*>(aContent) : nullptr; \
|
return aContent->_check ? static_cast<const _class*>(aContent) : nullptr; \
|
||||||
} \
|
} \
|
||||||
static _class* FromContentOrNull(nsIContent* aContent) \
|
static _class* FromContentOrNull(nsINode* aContent) \
|
||||||
{ \
|
{ \
|
||||||
return aContent ? FromContent(aContent) : nullptr; \
|
return aContent ? FromContent(aContent) : nullptr; \
|
||||||
} \
|
} \
|
||||||
static const _class* FromContentOrNull(const nsIContent* aContent) \
|
static const _class* FromContentOrNull(const nsINode* aContent) \
|
||||||
{ \
|
{ \
|
||||||
return aContent ? FromContent(aContent) : nullptr; \
|
return aContent ? FromContent(aContent) : nullptr; \
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -523,6 +523,19 @@ public:
|
||||||
return NodeType() == PROCESSING_INSTRUCTION_NODE;
|
return NodeType() == PROCESSING_INSTRUCTION_NODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return whether the node is a CharacterData node (text, cdata,
|
||||||
|
* comment, processing instruction)
|
||||||
|
*/
|
||||||
|
bool IsCharacterData() const
|
||||||
|
{
|
||||||
|
uint32_t nodeType = NodeType();
|
||||||
|
return nodeType == TEXT_NODE ||
|
||||||
|
nodeType == CDATA_SECTION_NODE ||
|
||||||
|
nodeType == PROCESSING_INSTRUCTION_NODE ||
|
||||||
|
nodeType == COMMENT_NODE;
|
||||||
|
}
|
||||||
|
|
||||||
virtual nsIDOMNode* AsDOMNode() = 0;
|
virtual nsIDOMNode* AsDOMNode() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -2289,9 +2289,7 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
||||||
// XXX_kin: We need to also handle ProcessingInstruction
|
// XXX_kin: We need to also handle ProcessingInstruction
|
||||||
// XXX_kin: according to the spec.
|
// XXX_kin: according to the spec.
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMCharacterData> charData(do_QueryInterface(node));
|
if (auto charData = CharacterData::FromContent(node))
|
||||||
|
|
||||||
if (charData)
|
|
||||||
{
|
{
|
||||||
uint32_t dataLength = 0;
|
uint32_t dataLength = 0;
|
||||||
|
|
||||||
|
|
@ -2306,10 +2304,12 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
||||||
{
|
{
|
||||||
if (retval) {
|
if (retval) {
|
||||||
nsAutoString cutValue;
|
nsAutoString cutValue;
|
||||||
rv = charData->SubstringData(startOffset, endOffset - startOffset,
|
|
||||||
cutValue);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
ErrorResult err;
|
ErrorResult err;
|
||||||
|
charData->SubstringData(startOffset, endOffset - startOffset,
|
||||||
|
cutValue, err);
|
||||||
|
if (NS_WARN_IF(err.Failed())) {
|
||||||
|
return err.StealNSResult();
|
||||||
|
}
|
||||||
nsCOMPtr<nsINode> clone = node->CloneNode(false, err);
|
nsCOMPtr<nsINode> clone = node->CloneNode(false, err);
|
||||||
if (NS_WARN_IF(err.Failed())) {
|
if (NS_WARN_IF(err.Failed())) {
|
||||||
return err.StealNSResult();
|
return err.StealNSResult();
|
||||||
|
|
@ -2340,9 +2340,11 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
||||||
if (dataLength >= startOffset) {
|
if (dataLength >= startOffset) {
|
||||||
if (retval) {
|
if (retval) {
|
||||||
nsAutoString cutValue;
|
nsAutoString cutValue;
|
||||||
rv = charData->SubstringData(startOffset, dataLength, cutValue);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
ErrorResult err;
|
ErrorResult err;
|
||||||
|
charData->SubstringData(startOffset, dataLength, cutValue, err);
|
||||||
|
if (NS_WARN_IF(err.Failed())) {
|
||||||
|
return err.StealNSResult();
|
||||||
|
}
|
||||||
nsCOMPtr<nsINode> clone = node->CloneNode(false, err);
|
nsCOMPtr<nsINode> clone = node->CloneNode(false, err);
|
||||||
if (NS_WARN_IF(err.Failed())) {
|
if (NS_WARN_IF(err.Failed())) {
|
||||||
return err.StealNSResult();
|
return err.StealNSResult();
|
||||||
|
|
@ -2369,9 +2371,11 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
||||||
// Delete or extract everything before endOffset.
|
// Delete or extract everything before endOffset.
|
||||||
if (retval) {
|
if (retval) {
|
||||||
nsAutoString cutValue;
|
nsAutoString cutValue;
|
||||||
rv = charData->SubstringData(0, endOffset, cutValue);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
ErrorResult err;
|
ErrorResult err;
|
||||||
|
charData->SubstringData(0, endOffset, cutValue, err);
|
||||||
|
if (NS_WARN_IF(err.Failed())) {
|
||||||
|
return err.StealNSResult();
|
||||||
|
}
|
||||||
nsCOMPtr<nsINode> clone = node->CloneNode(false, err);
|
nsCOMPtr<nsINode> clone = node->CloneNode(false, err);
|
||||||
if (NS_WARN_IF(err.Failed())) {
|
if (NS_WARN_IF(err.Failed())) {
|
||||||
return err.StealNSResult();
|
return err.StealNSResult();
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,6 @@
|
||||||
interface nsIDOMCharacterData : nsIDOMNode
|
interface nsIDOMCharacterData : nsIDOMNode
|
||||||
{
|
{
|
||||||
readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
DOMString substringData(in unsigned long offset,
|
|
||||||
in unsigned long count)
|
|
||||||
raises(DOMException);
|
|
||||||
void appendData(in DOMString arg)
|
void appendData(in DOMString arg)
|
||||||
raises(DOMException);
|
raises(DOMException);
|
||||||
void insertData(in unsigned long offset,
|
void insertData(in unsigned long offset,
|
||||||
|
|
|
||||||
|
|
@ -123,12 +123,15 @@ DeleteTextTransaction::DoTransaction()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the text that we're about to delete
|
// Get the text that we're about to delete
|
||||||
nsresult rv = mCharData->SubstringData(mOffset, mLengthToDelete,
|
ErrorResult err;
|
||||||
mDeletedText);
|
mCharData->SubstringData(mOffset, mLengthToDelete, mDeletedText, err);
|
||||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
if (NS_WARN_IF(err.Failed())) {
|
||||||
rv = mCharData->DeleteData(mOffset, mLengthToDelete);
|
return err.StealNSResult();
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
}
|
||||||
return rv;
|
|
||||||
|
mCharData->DeleteData(mOffset, mLengthToDelete, err);
|
||||||
|
if (NS_WARN_IF(err.Failed())) {
|
||||||
|
return err.StealNSResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
mEditorBase->RangeUpdaterRef().
|
mEditorBase->RangeUpdaterRef().
|
||||||
|
|
|
||||||
|
|
@ -3221,7 +3221,7 @@ EditorBase::SplitNodeImpl(const EditorDOMPoint& aStartOfRightNode,
|
||||||
// Fix right node
|
// Fix right node
|
||||||
nsAutoString leftText;
|
nsAutoString leftText;
|
||||||
rightAsText->SubstringData(0, aStartOfRightNode.Offset(),
|
rightAsText->SubstringData(0, aStartOfRightNode.Offset(),
|
||||||
leftText);
|
leftText, IgnoreErrors());
|
||||||
rightAsText->DeleteData(0, aStartOfRightNode.Offset());
|
rightAsText->DeleteData(0, aStartOfRightNode.Offset());
|
||||||
// Fix left node
|
// Fix left node
|
||||||
leftAsText->GetAsText()->SetData(leftText, IgnoreErrors());
|
leftAsText->GetAsText()->SetData(leftText, IgnoreErrors());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue