зеркало из https://github.com/mozilla/pjs.git
Fix for bug 17726. Text.splitText now creates the correct type of node. Added nsITextContent::CloneContent to enable cloning without copying of the text. a=dagley r=nisheeth
This commit is contained in:
Родитель
514d3b99e4
Коммит
1c0c61c381
|
@ -74,6 +74,12 @@ public:
|
|||
* Query method to see if the frame is nothing but whitespace
|
||||
*/
|
||||
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult) = 0;
|
||||
|
||||
/**
|
||||
* Clone this content node. Unlike the nsIDOMNode equivalent, this
|
||||
* method allows you to specify whether to copy the text as well.
|
||||
*/
|
||||
NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone) = 0;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -201,6 +201,7 @@ public:
|
|||
PRBool aNotify);
|
||||
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult)
|
||||
{ return mInner.IsOnlyWhitespace(aResult); }
|
||||
NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone);
|
||||
|
||||
protected:
|
||||
nsGenericDOMDataNode mInner;
|
||||
|
@ -306,6 +307,33 @@ nsCommentNode::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCommentNode::CloneContent(PRBool aCloneText, nsITextContent** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsCommentNode* it;
|
||||
NS_NEWXPCOM(it, nsCommentNode);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
result = it->QueryInterface(kITextContentIID, (void**) aReturn);
|
||||
if (NS_FAILED(result) || !aCloneText) {
|
||||
return result;
|
||||
}
|
||||
nsAutoString data;
|
||||
result = GetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
result = it->SetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCommentNode::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
|
|
|
@ -897,47 +897,67 @@ nsGenericDOMDataNode::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult,
|
|||
nsresult
|
||||
nsGenericDOMDataNode::SplitText(PRUint32 aOffset, nsIDOMText** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsIContent* newNode;
|
||||
nsITextContent* text;
|
||||
nsresult rv = NS_OK;
|
||||
nsAutoString cutText;
|
||||
nsIContent* parentNode;
|
||||
PRUint32 length;
|
||||
|
||||
GetLength(&length);
|
||||
// Cut the second part out of the original text node
|
||||
result = SubstringData(aOffset, length-aOffset, cutText);
|
||||
if (NS_OK == result) {
|
||||
result = DeleteData(aOffset, length-aOffset);
|
||||
if (NS_OK == result) {
|
||||
// Create a new text node and set its data to the
|
||||
// string we just cut out
|
||||
result = NS_NewTextNode(&newNode);
|
||||
if (NS_OK == result) {
|
||||
result = newNode->QueryInterface(kITextContentIID, (void**)&text);
|
||||
if (NS_OK == result) {
|
||||
text->SetText(cutText.GetUnicode(), cutText.Length(), PR_FALSE);
|
||||
// Find the parent of the current node and insert the
|
||||
// new text node as a child after the current node
|
||||
GetParent(parentNode);
|
||||
if (nsnull != parentNode) {
|
||||
PRInt32 index;
|
||||
|
||||
result = parentNode->IndexOf(mContent, index);
|
||||
if (NS_OK == result) {
|
||||
result = parentNode->InsertChildAt(newNode, index+1, PR_TRUE);
|
||||
}
|
||||
NS_RELEASE(parentNode);
|
||||
}
|
||||
result = text->QueryInterface(kIDOMTextIID, (void**)aReturn);
|
||||
NS_RELEASE(text);
|
||||
}
|
||||
NS_RELEASE(newNode);
|
||||
}
|
||||
}
|
||||
if (aOffset > length) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
||||
return result;
|
||||
rv = SubstringData(aOffset, length-aOffset, cutText);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = DeleteData(aOffset, length-aOffset);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Use CloneContent() for creating the new node so that the new node is of
|
||||
* same class as this node!
|
||||
*/
|
||||
|
||||
nsCOMPtr<nsITextContent> tmpContent(do_QueryInterface(mContent, &rv));
|
||||
nsCOMPtr<nsITextContent> newContent;
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = tmpContent->CloneContent(PR_FALSE, getter_AddRefs(newContent));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(newContent, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = newNode->SetNodeValue(cutText);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContent> parentNode;
|
||||
GetParent(*getter_AddRefs(parentNode));
|
||||
|
||||
if (parentNode) {
|
||||
PRInt32 index;
|
||||
|
||||
rv = parentNode->IndexOf(mContent, index);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(newNode));
|
||||
|
||||
rv = parentNode->InsertChildAt(content, index+1, PR_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
return newNode->QueryInterface(kIDOMTextIID, (void**)aReturn);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -517,7 +517,8 @@ struct nsGenericDOMDataNode {
|
|||
} \
|
||||
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult){ \
|
||||
return mInner.IsOnlyWhitespace(aResult); \
|
||||
}
|
||||
} \
|
||||
NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone);
|
||||
|
||||
/**
|
||||
* This macro implements the portion of query interface that is
|
||||
|
|
|
@ -177,6 +177,33 @@ nsTextNode::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextNode::CloneContent(PRBool aCloneText, nsITextContent** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsTextNode* it;
|
||||
NS_NEWXPCOM(it, nsTextNode);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
result = it->QueryInterface(kITextContentIID, (void**) aReturn);
|
||||
if (NS_FAILED(result) || !aCloneText) {
|
||||
return result;
|
||||
}
|
||||
nsAutoString data;
|
||||
result = GetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
result = it->SetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextNode::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
|
@ -219,3 +246,4 @@ nsTextNode::SetContentID(PRUint32 aID)
|
|||
mContentID = aID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -180,6 +180,7 @@ public:
|
|||
PRInt32 aLength,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult);
|
||||
NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone);
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
|
@ -538,6 +539,27 @@ nsAttributeContent::IsOnlyWhitespace(PRBool* aResult)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAttributeContent::CloneContent(PRBool aCloneText, nsITextContent** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsAttributeContent* it;
|
||||
NS_NEWXPCOM(it, nsAttributeContent);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
result = it->QueryInterface(kITextContentIID, (void**) aReturn);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
result = it->Init(mContent, mNameSpaceID, mAttrName);
|
||||
if (NS_FAILED(result) || !aCloneText) {
|
||||
return result;
|
||||
}
|
||||
it->mText = mText;
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAttributeContent::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
||||
{
|
||||
|
|
|
@ -184,6 +184,33 @@ nsXMLCDATASection::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLCDATASection::CloneContent(PRBool aCloneText, nsITextContent** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsXMLCDATASection* it;
|
||||
NS_NEWXPCOM(it, nsXMLCDATASection);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
result = it->QueryInterface(kITextContentIID, (void**) aReturn);
|
||||
if (NS_FAILED(result) || !aCloneText) {
|
||||
return result;
|
||||
}
|
||||
nsAutoString data;
|
||||
result = GetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
result = it->SetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLCDATASection::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
|
|
|
@ -74,6 +74,12 @@ public:
|
|||
* Query method to see if the frame is nothing but whitespace
|
||||
*/
|
||||
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult) = 0;
|
||||
|
||||
/**
|
||||
* Clone this content node. Unlike the nsIDOMNode equivalent, this
|
||||
* method allows you to specify whether to copy the text as well.
|
||||
*/
|
||||
NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone) = 0;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -201,6 +201,7 @@ public:
|
|||
PRBool aNotify);
|
||||
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult)
|
||||
{ return mInner.IsOnlyWhitespace(aResult); }
|
||||
NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone);
|
||||
|
||||
protected:
|
||||
nsGenericDOMDataNode mInner;
|
||||
|
@ -306,6 +307,33 @@ nsCommentNode::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCommentNode::CloneContent(PRBool aCloneText, nsITextContent** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsCommentNode* it;
|
||||
NS_NEWXPCOM(it, nsCommentNode);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
result = it->QueryInterface(kITextContentIID, (void**) aReturn);
|
||||
if (NS_FAILED(result) || !aCloneText) {
|
||||
return result;
|
||||
}
|
||||
nsAutoString data;
|
||||
result = GetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
result = it->SetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCommentNode::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
|
|
|
@ -897,47 +897,67 @@ nsGenericDOMDataNode::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult,
|
|||
nsresult
|
||||
nsGenericDOMDataNode::SplitText(PRUint32 aOffset, nsIDOMText** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsIContent* newNode;
|
||||
nsITextContent* text;
|
||||
nsresult rv = NS_OK;
|
||||
nsAutoString cutText;
|
||||
nsIContent* parentNode;
|
||||
PRUint32 length;
|
||||
|
||||
GetLength(&length);
|
||||
// Cut the second part out of the original text node
|
||||
result = SubstringData(aOffset, length-aOffset, cutText);
|
||||
if (NS_OK == result) {
|
||||
result = DeleteData(aOffset, length-aOffset);
|
||||
if (NS_OK == result) {
|
||||
// Create a new text node and set its data to the
|
||||
// string we just cut out
|
||||
result = NS_NewTextNode(&newNode);
|
||||
if (NS_OK == result) {
|
||||
result = newNode->QueryInterface(kITextContentIID, (void**)&text);
|
||||
if (NS_OK == result) {
|
||||
text->SetText(cutText.GetUnicode(), cutText.Length(), PR_FALSE);
|
||||
// Find the parent of the current node and insert the
|
||||
// new text node as a child after the current node
|
||||
GetParent(parentNode);
|
||||
if (nsnull != parentNode) {
|
||||
PRInt32 index;
|
||||
|
||||
result = parentNode->IndexOf(mContent, index);
|
||||
if (NS_OK == result) {
|
||||
result = parentNode->InsertChildAt(newNode, index+1, PR_TRUE);
|
||||
}
|
||||
NS_RELEASE(parentNode);
|
||||
}
|
||||
result = text->QueryInterface(kIDOMTextIID, (void**)aReturn);
|
||||
NS_RELEASE(text);
|
||||
}
|
||||
NS_RELEASE(newNode);
|
||||
}
|
||||
}
|
||||
if (aOffset > length) {
|
||||
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
}
|
||||
|
||||
return result;
|
||||
rv = SubstringData(aOffset, length-aOffset, cutText);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = DeleteData(aOffset, length-aOffset);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Use CloneContent() for creating the new node so that the new node is of
|
||||
* same class as this node!
|
||||
*/
|
||||
|
||||
nsCOMPtr<nsITextContent> tmpContent(do_QueryInterface(mContent, &rv));
|
||||
nsCOMPtr<nsITextContent> newContent;
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = tmpContent->CloneContent(PR_FALSE, getter_AddRefs(newContent));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(newContent, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = newNode->SetNodeValue(cutText);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContent> parentNode;
|
||||
GetParent(*getter_AddRefs(parentNode));
|
||||
|
||||
if (parentNode) {
|
||||
PRInt32 index;
|
||||
|
||||
rv = parentNode->IndexOf(mContent, index);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(newNode));
|
||||
|
||||
rv = parentNode->InsertChildAt(content, index+1, PR_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
return newNode->QueryInterface(kIDOMTextIID, (void**)aReturn);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -517,7 +517,8 @@ struct nsGenericDOMDataNode {
|
|||
} \
|
||||
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult){ \
|
||||
return mInner.IsOnlyWhitespace(aResult); \
|
||||
}
|
||||
} \
|
||||
NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone);
|
||||
|
||||
/**
|
||||
* This macro implements the portion of query interface that is
|
||||
|
|
|
@ -177,6 +177,33 @@ nsTextNode::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextNode::CloneContent(PRBool aCloneText, nsITextContent** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsTextNode* it;
|
||||
NS_NEWXPCOM(it, nsTextNode);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
result = it->QueryInterface(kITextContentIID, (void**) aReturn);
|
||||
if (NS_FAILED(result) || !aCloneText) {
|
||||
return result;
|
||||
}
|
||||
nsAutoString data;
|
||||
result = GetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
result = it->SetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextNode::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
|
@ -219,3 +246,4 @@ nsTextNode::SetContentID(PRUint32 aID)
|
|||
mContentID = aID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -180,6 +180,7 @@ public:
|
|||
PRInt32 aLength,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult);
|
||||
NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone);
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
|
@ -538,6 +539,27 @@ nsAttributeContent::IsOnlyWhitespace(PRBool* aResult)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAttributeContent::CloneContent(PRBool aCloneText, nsITextContent** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsAttributeContent* it;
|
||||
NS_NEWXPCOM(it, nsAttributeContent);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
result = it->QueryInterface(kITextContentIID, (void**) aReturn);
|
||||
if (NS_FAILED(result)) {
|
||||
return result;
|
||||
}
|
||||
result = it->Init(mContent, mNameSpaceID, mAttrName);
|
||||
if (NS_FAILED(result) || !aCloneText) {
|
||||
return result;
|
||||
}
|
||||
it->mText = mText;
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAttributeContent::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const
|
||||
{
|
||||
|
|
|
@ -184,6 +184,33 @@ nsXMLCDATASection::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
|||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLCDATASection::CloneContent(PRBool aCloneText, nsITextContent** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsXMLCDATASection* it;
|
||||
NS_NEWXPCOM(it, nsXMLCDATASection);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
result = it->QueryInterface(kITextContentIID, (void**) aReturn);
|
||||
if (NS_FAILED(result) || !aCloneText) {
|
||||
return result;
|
||||
}
|
||||
nsAutoString data;
|
||||
result = GetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
result = it->SetData(data);
|
||||
if (NS_FAILED(result)) {
|
||||
NS_RELEASE(*aReturn);
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLCDATASection::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче