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;
|
||||
}
|
||||
|
||||
nsresult
|
||||
CharacterData::SubstringData(uint32_t aStart, uint32_t aCount,
|
||||
nsAString& aReturn)
|
||||
{
|
||||
ErrorResult rv;
|
||||
SubstringData(aStart, aCount, aReturn, rv);
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
|
||||
void
|
||||
CharacterData::SubstringData(uint32_t aStart, uint32_t aCount,
|
||||
nsAString& aReturn, ErrorResult& rv)
|
||||
|
|
|
|||
|
|
@ -89,14 +89,14 @@ public:
|
|||
SetFlags(NS_MAYBE_MODIFIED_FREQUENTLY);
|
||||
}
|
||||
|
||||
NS_IMPL_FROMCONTENT_HELPER(CharacterData, IsCharacterData())
|
||||
|
||||
virtual void GetNodeValueInternal(nsAString& aNodeValue) override;
|
||||
virtual void SetNodeValueInternal(const nsAString& aNodeValue,
|
||||
ErrorResult& aError) override;
|
||||
|
||||
// Implementation for nsIDOMCharacterData
|
||||
nsresult GetLength(uint32_t* aLength);
|
||||
nsresult SubstringData(uint32_t aOffset, uint32_t aCount,
|
||||
nsAString& aReturn);
|
||||
nsresult AppendData(const nsAString& aArg);
|
||||
nsresult InsertData(uint32_t aOffset, const nsAString& aArg);
|
||||
nsresult DeleteData(uint32_t aOffset, uint32_t aCount);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/ProcessingInstruction.h"
|
||||
#include "mozilla/dom/ShadowRoot.h"
|
||||
#include "mozilla/dom/Text.h"
|
||||
#include "nsLayoutUtils.h"
|
||||
#include "mozilla/ScopeExit.h"
|
||||
|
||||
|
|
@ -1599,7 +1600,7 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t
|
|||
{
|
||||
// some special casing for text nodes
|
||||
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 (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
|
||||
// general solution that truly detects all cases of non-significant
|
||||
// whitesace with no false alarms.
|
||||
nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(aNode);
|
||||
nsAutoString text;
|
||||
nodeAsText->SubstringData(0, offset, text);
|
||||
nodeAsText->SubstringData(0, offset, text, IgnoreErrors());
|
||||
text.CompressWhitespace();
|
||||
if (!text.IsEmpty())
|
||||
return NS_OK;
|
||||
|
|
@ -1675,7 +1675,7 @@ nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t
|
|||
{
|
||||
// some special casing for text nodes
|
||||
nsCOMPtr<nsINode> n = do_QueryInterface(aNode);
|
||||
if (IsTextNode(n))
|
||||
if (auto nodeAsText = n->GetAsText())
|
||||
{
|
||||
// if not at end of text node, we are done
|
||||
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
|
||||
// general solution that truly detects all cases of non-significant
|
||||
// whitespace with no false alarms.
|
||||
nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(aNode);
|
||||
nsAutoString text;
|
||||
nodeAsText->SubstringData(offset, len-offset, text);
|
||||
nodeAsText->SubstringData(offset, len-offset, text, IgnoreErrors());
|
||||
text.CompressWhitespace();
|
||||
if (!text.IsEmpty())
|
||||
return NS_OK;
|
||||
|
|
|
|||
|
|
@ -1009,19 +1009,19 @@ inline nsIContent* nsINode::AsContent()
|
|||
}
|
||||
|
||||
#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; \
|
||||
} \
|
||||
static const _class* FromContent(const nsIContent* aContent) \
|
||||
static const _class* FromContent(const nsINode* aContent) \
|
||||
{ \
|
||||
return aContent->_check ? static_cast<const _class*>(aContent) : nullptr; \
|
||||
} \
|
||||
static _class* FromContentOrNull(nsIContent* aContent) \
|
||||
static _class* FromContentOrNull(nsINode* aContent) \
|
||||
{ \
|
||||
return aContent ? FromContent(aContent) : nullptr; \
|
||||
} \
|
||||
static const _class* FromContentOrNull(const nsIContent* aContent) \
|
||||
static const _class* FromContentOrNull(const nsINode* aContent) \
|
||||
{ \
|
||||
return aContent ? FromContent(aContent) : nullptr; \
|
||||
}
|
||||
|
|
|
|||
|
|
@ -523,6 +523,19 @@ public:
|
|||
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;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2289,9 +2289,7 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
|||
// XXX_kin: We need to also handle ProcessingInstruction
|
||||
// XXX_kin: according to the spec.
|
||||
|
||||
nsCOMPtr<nsIDOMCharacterData> charData(do_QueryInterface(node));
|
||||
|
||||
if (charData)
|
||||
if (auto charData = CharacterData::FromContent(node))
|
||||
{
|
||||
uint32_t dataLength = 0;
|
||||
|
||||
|
|
@ -2306,10 +2304,12 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
|||
{
|
||||
if (retval) {
|
||||
nsAutoString cutValue;
|
||||
rv = charData->SubstringData(startOffset, endOffset - startOffset,
|
||||
cutValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
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);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
|
|
@ -2340,9 +2340,11 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
|||
if (dataLength >= startOffset) {
|
||||
if (retval) {
|
||||
nsAutoString cutValue;
|
||||
rv = charData->SubstringData(startOffset, dataLength, cutValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
ErrorResult err;
|
||||
charData->SubstringData(startOffset, dataLength, cutValue, err);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
}
|
||||
nsCOMPtr<nsINode> clone = node->CloneNode(false, err);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
|
|
@ -2369,9 +2371,11 @@ nsRange::CutContents(DocumentFragment** aFragment)
|
|||
// Delete or extract everything before endOffset.
|
||||
if (retval) {
|
||||
nsAutoString cutValue;
|
||||
rv = charData->SubstringData(0, endOffset, cutValue);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
ErrorResult err;
|
||||
charData->SubstringData(0, endOffset, cutValue, err);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
}
|
||||
nsCOMPtr<nsINode> clone = node->CloneNode(false, err);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@
|
|||
interface nsIDOMCharacterData : nsIDOMNode
|
||||
{
|
||||
readonly attribute unsigned long length;
|
||||
DOMString substringData(in unsigned long offset,
|
||||
in unsigned long count)
|
||||
raises(DOMException);
|
||||
void appendData(in DOMString arg)
|
||||
raises(DOMException);
|
||||
void insertData(in unsigned long offset,
|
||||
|
|
|
|||
|
|
@ -123,12 +123,15 @@ DeleteTextTransaction::DoTransaction()
|
|||
}
|
||||
|
||||
// Get the text that we're about to delete
|
||||
nsresult rv = mCharData->SubstringData(mOffset, mLengthToDelete,
|
||||
mDeletedText);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
rv = mCharData->DeleteData(mOffset, mLengthToDelete);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
ErrorResult err;
|
||||
mCharData->SubstringData(mOffset, mLengthToDelete, mDeletedText, err);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
}
|
||||
|
||||
mCharData->DeleteData(mOffset, mLengthToDelete, err);
|
||||
if (NS_WARN_IF(err.Failed())) {
|
||||
return err.StealNSResult();
|
||||
}
|
||||
|
||||
mEditorBase->RangeUpdaterRef().
|
||||
|
|
|
|||
|
|
@ -3221,7 +3221,7 @@ EditorBase::SplitNodeImpl(const EditorDOMPoint& aStartOfRightNode,
|
|||
// Fix right node
|
||||
nsAutoString leftText;
|
||||
rightAsText->SubstringData(0, aStartOfRightNode.Offset(),
|
||||
leftText);
|
||||
leftText, IgnoreErrors());
|
||||
rightAsText->DeleteData(0, aStartOfRightNode.Offset());
|
||||
// Fix left node
|
||||
leftAsText->GetAsText()->SetData(leftText, IgnoreErrors());
|
||||
|
|
|
|||
Loading…
Reference in a new issue