зеркало из https://github.com/mozilla/pjs.git
Parse delimiters out of Comment nodes. CharacterData Nodes now return an empty childNodes list instead of null.
This commit is contained in:
Родитель
bcf97a7ed1
Коммит
716f931345
|
@ -32,11 +32,13 @@
|
|||
|
||||
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
|
||||
static NS_DEFINE_IID(kIEnumeratorIID, NS_IENUMERATOR_IID);
|
||||
static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID);
|
||||
|
||||
class nsCommentNode : public nsIDOMComment,
|
||||
public nsIScriptObjectOwner,
|
||||
public nsIDOMEventReceiver,
|
||||
public nsIContent
|
||||
public nsIContent,
|
||||
public nsITextContent
|
||||
{
|
||||
public:
|
||||
nsCommentNode();
|
||||
|
@ -159,6 +161,18 @@ public:
|
|||
return mInner.GetRangeList(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetText(const nsTextFragment*& aFragmentsResult,
|
||||
PRInt32& aNumFragmentsResult)
|
||||
{ return mInner.GetText(aFragmentsResult, aNumFragmentsResult); }
|
||||
NS_IMETHOD SetText(const PRUnichar* aBuffer,
|
||||
PRInt32 aLength,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD SetText(const char* aBuffer,
|
||||
PRInt32 aLength,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult)
|
||||
{ return mInner.IsOnlyWhitespace(aResult); }
|
||||
|
||||
protected:
|
||||
nsGenericDOMDataNode mInner;
|
||||
};
|
||||
|
@ -202,6 +216,12 @@ nsCommentNode::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kITextContentIID)) {
|
||||
nsITextContent* tmp = this;
|
||||
*aInstancePtr = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
@ -230,20 +250,30 @@ nsCommentNode::GetNodeType(PRUint16* aNodeType)
|
|||
NS_IMETHODIMP
|
||||
nsCommentNode::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsCommentNode* it = new nsCommentNode();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsAutoString data;
|
||||
nsresult result = GetData(data);
|
||||
// XXX Increment the ref count before calling any
|
||||
// methods. If they do a QI and then a Release()
|
||||
// the instance will be deleted.
|
||||
result = it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
if (NS_FAILED(result)) {
|
||||
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 it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -254,13 +284,13 @@ nsCommentNode::List(FILE* out, PRInt32 aIndent) const
|
|||
PRInt32 indx;
|
||||
for (indx = aIndent; --indx >= 0; ) fputs(" ", out);
|
||||
|
||||
fprintf(out, "Comment refcount=%d<", mRefCnt);
|
||||
fprintf(out, "Comment refcount=%d<!--", mRefCnt);
|
||||
|
||||
nsAutoString tmp;
|
||||
mInner.ToCString(tmp, 0, mInner.mText.GetLength());
|
||||
fputs(tmp, out);
|
||||
|
||||
fputs(">\n", out);
|
||||
fputs("-->\n", out);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -385,3 +415,65 @@ nsCommentNode::FinishConvertToXIF(nsXIFConverter& aConverter) const
|
|||
}
|
||||
#endif
|
||||
|
||||
// This would ideally be done by the parser, but for the sake
|
||||
// of "genericity" it's being done in the comment content code
|
||||
static void
|
||||
StripCommentDelimiters(nsString& aCommentString)
|
||||
{
|
||||
PRInt32 offset;
|
||||
static char* kCommentStart = "<!";
|
||||
static char* kCommentEnd = "->";
|
||||
static char* kCommentAlternateEnd = "--!>";
|
||||
static char kMinus = '-';
|
||||
static char kExclamation = '!';
|
||||
|
||||
offset = aCommentString.Find(kCommentStart);
|
||||
offset += strlen(kCommentStart);
|
||||
if (-1 != offset) {
|
||||
// Take up to 2 '-' characters
|
||||
if (kMinus == aCommentString.CharAt(offset)) {
|
||||
offset++;
|
||||
if (kMinus == aCommentString.CharAt(offset)) {
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
aCommentString.Cut(0, offset);
|
||||
}
|
||||
|
||||
offset = aCommentString.RFind(kCommentEnd);
|
||||
if (-1 != offset) {
|
||||
// Take up to 1 more '-'
|
||||
if (kMinus == aCommentString.CharAt(offset-1)) {
|
||||
offset--;
|
||||
}
|
||||
aCommentString.Cut(offset, aCommentString.Length()-offset);
|
||||
}
|
||||
else {
|
||||
offset = aCommentString.RFind(kCommentAlternateEnd);
|
||||
if (-1 != offset) {
|
||||
aCommentString.Cut(offset, aCommentString.Length()-offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCommentNode::SetText(const PRUnichar* aBuffer,
|
||||
PRInt32 aLength,
|
||||
PRBool aNotify)
|
||||
{
|
||||
nsAutoString str(aBuffer);
|
||||
|
||||
StripCommentDelimiters(str);
|
||||
return mInner.SetText(str.GetUnicode(), str.Length(), aNotify);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCommentNode::SetText(const char* aBuffer,
|
||||
PRInt32 aLength,
|
||||
PRBool aNotify)
|
||||
{
|
||||
nsAutoString str(aBuffer);
|
||||
|
||||
StripCommentDelimiters(str);
|
||||
return mInner.SetText(str.GetUnicode(), str.Length(), aNotify);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ static NS_DEFINE_IID(kIEnumeratorIID, NS_IENUMERATOR_IID);
|
|||
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
|
||||
static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMNodeListIID, NS_IDOMNODELIST_IID);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
@ -184,6 +185,20 @@ nsGenericDOMDataNode::GetNextSibling(nsIDOMNode** aNextSibling)
|
|||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDOMDataNode::GetChildNodes(nsIDOMNodeList** aChildNodes)
|
||||
{
|
||||
// XXX Since we believe this won't be done very often, we won't
|
||||
// burn another slot in the data node and just create a new
|
||||
// (empty) childNodes list every time we're asked.
|
||||
nsChildContentList* list = new nsChildContentList(nsnull);
|
||||
if (nsnull == list) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return list->QueryInterface(kIDOMNodeListIID, (void**)aChildNodes);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDOMDataNode::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
|
||||
{
|
||||
|
@ -238,13 +253,20 @@ nsGenericDOMDataNode::SetData(const nsString& aData)
|
|||
// text replacement we should just collapse all the ranges.
|
||||
if (mRangeList) nsRange::TextOwnerChanged(mContent, 0, mText.GetLength(), 0);
|
||||
|
||||
mText = aData;
|
||||
|
||||
// Notify the document that the text changed
|
||||
if (nsnull != mDocument) {
|
||||
mDocument->ContentChanged(mContent, nsnull);
|
||||
nsresult result;
|
||||
nsCOMPtr<nsITextContent> textContent = do_QueryInterface(mContent, &result);
|
||||
|
||||
// If possible, let the container content object have a go at it.
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = textContent->SetText(aData.GetUnicode(),
|
||||
aData.Length(),
|
||||
PR_TRUE);
|
||||
}
|
||||
return NS_OK;
|
||||
else {
|
||||
result = SetText(aData.GetUnicode(), aData.Length(), PR_TRUE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -308,6 +330,8 @@ nsresult
|
|||
nsGenericDOMDataNode::ReplaceData(PRUint32 aOffset, PRUint32 aCount,
|
||||
const nsString& aData)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
// sanitize arguments
|
||||
PRUint32 textLength = mText.GetLength();
|
||||
if (aOffset > textLength) {
|
||||
|
@ -343,15 +367,18 @@ nsGenericDOMDataNode::ReplaceData(PRUint32 aOffset, PRUint32 aCount,
|
|||
}
|
||||
|
||||
// Switch to new buffer
|
||||
mText.SetTo(to, newLength);
|
||||
nsCOMPtr<nsITextContent> textContent = do_QueryInterface(mContent, &result);
|
||||
|
||||
// If possible, let the container content object have a go at it.
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = textContent->SetText(to, newLength, PR_TRUE);
|
||||
}
|
||||
else {
|
||||
result = SetText(to, newLength, PR_TRUE);
|
||||
}
|
||||
delete [] to;
|
||||
|
||||
// Notify the document that the text changed
|
||||
if (nsnull != mDocument) {
|
||||
mDocument->ContentChanged(mContent, nsnull);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -62,10 +62,7 @@ struct nsGenericDOMDataNode {
|
|||
}
|
||||
nsresult GetPreviousSibling(nsIDOMNode** aPreviousSibling);
|
||||
nsresult GetNextSibling(nsIDOMNode** aNextSibling);
|
||||
nsresult GetChildNodes(nsIDOMNodeList** aChildNodes) {
|
||||
*aChildNodes = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetChildNodes(nsIDOMNodeList** aChildNodes);
|
||||
nsresult HasChildNodes(PRBool* aHasChildNodes) {
|
||||
*aHasChildNodes = PR_FALSE;
|
||||
return NS_OK;
|
||||
|
|
|
@ -142,21 +142,31 @@ nsTextNode::GetNodeType(PRUint16* aNodeType)
|
|||
NS_IMETHODIMP
|
||||
nsTextNode::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsTextNode* it;
|
||||
NS_NEWXPCOM(it, nsTextNode);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsAutoString data;
|
||||
nsresult result = GetData(data);
|
||||
// XXX Increment the ref count before calling any
|
||||
// methods. If they do a QI and then a Release()
|
||||
// the instance will be deleted.
|
||||
result = it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
if (NS_FAILED(result)) {
|
||||
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 it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -148,21 +148,31 @@ nsXMLCDATASection::GetNodeType(PRUint16* aNodeType)
|
|||
NS_IMETHODIMP
|
||||
nsXMLCDATASection::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsXMLCDATASection* it;
|
||||
NS_NEWXPCOM(it, nsXMLCDATASection);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsAutoString data;
|
||||
nsresult result = GetData(data);
|
||||
// XXX Increment the ref count before calling any
|
||||
// methods. If they do a QI and then a Release()
|
||||
// the instance will be deleted.
|
||||
result = it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
if (NS_FAILED(result)) {
|
||||
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 it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -32,11 +32,13 @@
|
|||
|
||||
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
|
||||
static NS_DEFINE_IID(kIEnumeratorIID, NS_IENUMERATOR_IID);
|
||||
static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID);
|
||||
|
||||
class nsCommentNode : public nsIDOMComment,
|
||||
public nsIScriptObjectOwner,
|
||||
public nsIDOMEventReceiver,
|
||||
public nsIContent
|
||||
public nsIContent,
|
||||
public nsITextContent
|
||||
{
|
||||
public:
|
||||
nsCommentNode();
|
||||
|
@ -159,6 +161,18 @@ public:
|
|||
return mInner.GetRangeList(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetText(const nsTextFragment*& aFragmentsResult,
|
||||
PRInt32& aNumFragmentsResult)
|
||||
{ return mInner.GetText(aFragmentsResult, aNumFragmentsResult); }
|
||||
NS_IMETHOD SetText(const PRUnichar* aBuffer,
|
||||
PRInt32 aLength,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD SetText(const char* aBuffer,
|
||||
PRInt32 aLength,
|
||||
PRBool aNotify);
|
||||
NS_IMETHOD IsOnlyWhitespace(PRBool* aResult)
|
||||
{ return mInner.IsOnlyWhitespace(aResult); }
|
||||
|
||||
protected:
|
||||
nsGenericDOMDataNode mInner;
|
||||
};
|
||||
|
@ -202,6 +216,12 @@ nsCommentNode::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kITextContentIID)) {
|
||||
nsITextContent* tmp = this;
|
||||
*aInstancePtr = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
@ -230,20 +250,30 @@ nsCommentNode::GetNodeType(PRUint16* aNodeType)
|
|||
NS_IMETHODIMP
|
||||
nsCommentNode::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsCommentNode* it = new nsCommentNode();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsAutoString data;
|
||||
nsresult result = GetData(data);
|
||||
// XXX Increment the ref count before calling any
|
||||
// methods. If they do a QI and then a Release()
|
||||
// the instance will be deleted.
|
||||
result = it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
if (NS_FAILED(result)) {
|
||||
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 it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -254,13 +284,13 @@ nsCommentNode::List(FILE* out, PRInt32 aIndent) const
|
|||
PRInt32 indx;
|
||||
for (indx = aIndent; --indx >= 0; ) fputs(" ", out);
|
||||
|
||||
fprintf(out, "Comment refcount=%d<", mRefCnt);
|
||||
fprintf(out, "Comment refcount=%d<!--", mRefCnt);
|
||||
|
||||
nsAutoString tmp;
|
||||
mInner.ToCString(tmp, 0, mInner.mText.GetLength());
|
||||
fputs(tmp, out);
|
||||
|
||||
fputs(">\n", out);
|
||||
fputs("-->\n", out);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -385,3 +415,65 @@ nsCommentNode::FinishConvertToXIF(nsXIFConverter& aConverter) const
|
|||
}
|
||||
#endif
|
||||
|
||||
// This would ideally be done by the parser, but for the sake
|
||||
// of "genericity" it's being done in the comment content code
|
||||
static void
|
||||
StripCommentDelimiters(nsString& aCommentString)
|
||||
{
|
||||
PRInt32 offset;
|
||||
static char* kCommentStart = "<!";
|
||||
static char* kCommentEnd = "->";
|
||||
static char* kCommentAlternateEnd = "--!>";
|
||||
static char kMinus = '-';
|
||||
static char kExclamation = '!';
|
||||
|
||||
offset = aCommentString.Find(kCommentStart);
|
||||
offset += strlen(kCommentStart);
|
||||
if (-1 != offset) {
|
||||
// Take up to 2 '-' characters
|
||||
if (kMinus == aCommentString.CharAt(offset)) {
|
||||
offset++;
|
||||
if (kMinus == aCommentString.CharAt(offset)) {
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
aCommentString.Cut(0, offset);
|
||||
}
|
||||
|
||||
offset = aCommentString.RFind(kCommentEnd);
|
||||
if (-1 != offset) {
|
||||
// Take up to 1 more '-'
|
||||
if (kMinus == aCommentString.CharAt(offset-1)) {
|
||||
offset--;
|
||||
}
|
||||
aCommentString.Cut(offset, aCommentString.Length()-offset);
|
||||
}
|
||||
else {
|
||||
offset = aCommentString.RFind(kCommentAlternateEnd);
|
||||
if (-1 != offset) {
|
||||
aCommentString.Cut(offset, aCommentString.Length()-offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCommentNode::SetText(const PRUnichar* aBuffer,
|
||||
PRInt32 aLength,
|
||||
PRBool aNotify)
|
||||
{
|
||||
nsAutoString str(aBuffer);
|
||||
|
||||
StripCommentDelimiters(str);
|
||||
return mInner.SetText(str.GetUnicode(), str.Length(), aNotify);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCommentNode::SetText(const char* aBuffer,
|
||||
PRInt32 aLength,
|
||||
PRBool aNotify)
|
||||
{
|
||||
nsAutoString str(aBuffer);
|
||||
|
||||
StripCommentDelimiters(str);
|
||||
return mInner.SetText(str.GetUnicode(), str.Length(), aNotify);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ static NS_DEFINE_IID(kIEnumeratorIID, NS_IENUMERATOR_IID);
|
|||
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID);
|
||||
static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMNodeListIID, NS_IDOMNODELIST_IID);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
|
@ -184,6 +185,20 @@ nsGenericDOMDataNode::GetNextSibling(nsIDOMNode** aNextSibling)
|
|||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDOMDataNode::GetChildNodes(nsIDOMNodeList** aChildNodes)
|
||||
{
|
||||
// XXX Since we believe this won't be done very often, we won't
|
||||
// burn another slot in the data node and just create a new
|
||||
// (empty) childNodes list every time we're asked.
|
||||
nsChildContentList* list = new nsChildContentList(nsnull);
|
||||
if (nsnull == list) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return list->QueryInterface(kIDOMNodeListIID, (void**)aChildNodes);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericDOMDataNode::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
|
||||
{
|
||||
|
@ -238,13 +253,20 @@ nsGenericDOMDataNode::SetData(const nsString& aData)
|
|||
// text replacement we should just collapse all the ranges.
|
||||
if (mRangeList) nsRange::TextOwnerChanged(mContent, 0, mText.GetLength(), 0);
|
||||
|
||||
mText = aData;
|
||||
|
||||
// Notify the document that the text changed
|
||||
if (nsnull != mDocument) {
|
||||
mDocument->ContentChanged(mContent, nsnull);
|
||||
nsresult result;
|
||||
nsCOMPtr<nsITextContent> textContent = do_QueryInterface(mContent, &result);
|
||||
|
||||
// If possible, let the container content object have a go at it.
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = textContent->SetText(aData.GetUnicode(),
|
||||
aData.Length(),
|
||||
PR_TRUE);
|
||||
}
|
||||
return NS_OK;
|
||||
else {
|
||||
result = SetText(aData.GetUnicode(), aData.Length(), PR_TRUE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -308,6 +330,8 @@ nsresult
|
|||
nsGenericDOMDataNode::ReplaceData(PRUint32 aOffset, PRUint32 aCount,
|
||||
const nsString& aData)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
// sanitize arguments
|
||||
PRUint32 textLength = mText.GetLength();
|
||||
if (aOffset > textLength) {
|
||||
|
@ -343,15 +367,18 @@ nsGenericDOMDataNode::ReplaceData(PRUint32 aOffset, PRUint32 aCount,
|
|||
}
|
||||
|
||||
// Switch to new buffer
|
||||
mText.SetTo(to, newLength);
|
||||
nsCOMPtr<nsITextContent> textContent = do_QueryInterface(mContent, &result);
|
||||
|
||||
// If possible, let the container content object have a go at it.
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = textContent->SetText(to, newLength, PR_TRUE);
|
||||
}
|
||||
else {
|
||||
result = SetText(to, newLength, PR_TRUE);
|
||||
}
|
||||
delete [] to;
|
||||
|
||||
// Notify the document that the text changed
|
||||
if (nsnull != mDocument) {
|
||||
mDocument->ContentChanged(mContent, nsnull);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -62,10 +62,7 @@ struct nsGenericDOMDataNode {
|
|||
}
|
||||
nsresult GetPreviousSibling(nsIDOMNode** aPreviousSibling);
|
||||
nsresult GetNextSibling(nsIDOMNode** aNextSibling);
|
||||
nsresult GetChildNodes(nsIDOMNodeList** aChildNodes) {
|
||||
*aChildNodes = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
nsresult GetChildNodes(nsIDOMNodeList** aChildNodes);
|
||||
nsresult HasChildNodes(PRBool* aHasChildNodes) {
|
||||
*aHasChildNodes = PR_FALSE;
|
||||
return NS_OK;
|
||||
|
|
|
@ -142,21 +142,31 @@ nsTextNode::GetNodeType(PRUint16* aNodeType)
|
|||
NS_IMETHODIMP
|
||||
nsTextNode::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsTextNode* it;
|
||||
NS_NEWXPCOM(it, nsTextNode);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsAutoString data;
|
||||
nsresult result = GetData(data);
|
||||
// XXX Increment the ref count before calling any
|
||||
// methods. If they do a QI and then a Release()
|
||||
// the instance will be deleted.
|
||||
result = it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
if (NS_FAILED(result)) {
|
||||
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 it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -148,21 +148,31 @@ nsXMLCDATASection::GetNodeType(PRUint16* aNodeType)
|
|||
NS_IMETHODIMP
|
||||
nsXMLCDATASection::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
nsXMLCDATASection* it;
|
||||
NS_NEWXPCOM(it, nsXMLCDATASection);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsAutoString data;
|
||||
nsresult result = GetData(data);
|
||||
// XXX Increment the ref count before calling any
|
||||
// methods. If they do a QI and then a Release()
|
||||
// the instance will be deleted.
|
||||
result = it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
if (NS_FAILED(result)) {
|
||||
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 it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
Загрузка…
Ссылка в новой задаче