diff --git a/editor/base/editor.cpp b/editor/base/editor.cpp index e79e4acfd497..bc686fc48f5f 100644 --- a/editor/base/editor.cpp +++ b/editor/base/editor.cpp @@ -35,6 +35,9 @@ static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID); static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID); static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID); static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); +static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); + nsEditor::~nsEditor() { @@ -158,13 +161,15 @@ nsEditor::MouseClick(int aX,int aY) nsresult nsEditor::AppendText(nsString *aStr) { - COM_auto_ptr mNode; - COM_auto_ptr mText; + COM_auto_ptr currentNode; + COM_auto_ptr textNode; + COM_auto_ptr text; if (!aStr) return NS_ERROR_NULL_POINTER; - if (NS_SUCCEEDED(GetCurrentNode(func_AddRefs(mNode))) && - NS_SUCCEEDED(mNode->QueryInterface(kIDOMTextIID, func_AddRefs(mText)))) { - mText->AppendData(*aStr); + if (NS_SUCCEEDED(GetCurrentNode(func_AddRefs(currentNode))) && + NS_SUCCEEDED(GetFirstTextNode(currentNode,func_AddRefs(textNode))) && + NS_SUCCEEDED(textNode->QueryInterface(kIDOMTextIID, func_AddRefs(text)))) { + text->AppendData(*aStr); } return NS_OK; @@ -176,13 +181,11 @@ nsresult nsEditor::GetCurrentNode(nsIDOMNode ** aNode) { /* If no node set, get first text node */ - COM_auto_ptr docNode; + COM_auto_ptr docNode; - if (NS_SUCCEEDED(mDomInterfaceP->GetFirstChild(func_AddRefs(docNode)))) + if (NS_SUCCEEDED(mDomInterfaceP->GetDocumentElement(func_AddRefs(docNode)))) { - *aNode = docNode; - NS_ADDREF(*aNode); - return NS_OK; + return docNode->QueryInterface(kIDOMNodeIID,(void **) aNode); } return NS_ERROR_FAILURE; } @@ -206,7 +209,10 @@ nsEditor::GetFirstTextNode(nsIDOMNode *aNode, nsIDOMNode **aRetNode) { COM_auto_ptr mNode; - aNode->GetFirstChild(func_AddRefs(mNode)); + if (!NS_SUCCEEDED(aNode->GetFirstChild(func_AddRefs(mNode)))) + { + assert(0); + } while(!answer) { GetFirstTextNode(mNode, func_AddRefs(answer)); diff --git a/editor/core/editor.cpp b/editor/core/editor.cpp index e79e4acfd497..bc686fc48f5f 100644 --- a/editor/core/editor.cpp +++ b/editor/core/editor.cpp @@ -35,6 +35,9 @@ static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID); static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID); static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID); static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); +static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); + nsEditor::~nsEditor() { @@ -158,13 +161,15 @@ nsEditor::MouseClick(int aX,int aY) nsresult nsEditor::AppendText(nsString *aStr) { - COM_auto_ptr mNode; - COM_auto_ptr mText; + COM_auto_ptr currentNode; + COM_auto_ptr textNode; + COM_auto_ptr text; if (!aStr) return NS_ERROR_NULL_POINTER; - if (NS_SUCCEEDED(GetCurrentNode(func_AddRefs(mNode))) && - NS_SUCCEEDED(mNode->QueryInterface(kIDOMTextIID, func_AddRefs(mText)))) { - mText->AppendData(*aStr); + if (NS_SUCCEEDED(GetCurrentNode(func_AddRefs(currentNode))) && + NS_SUCCEEDED(GetFirstTextNode(currentNode,func_AddRefs(textNode))) && + NS_SUCCEEDED(textNode->QueryInterface(kIDOMTextIID, func_AddRefs(text)))) { + text->AppendData(*aStr); } return NS_OK; @@ -176,13 +181,11 @@ nsresult nsEditor::GetCurrentNode(nsIDOMNode ** aNode) { /* If no node set, get first text node */ - COM_auto_ptr docNode; + COM_auto_ptr docNode; - if (NS_SUCCEEDED(mDomInterfaceP->GetFirstChild(func_AddRefs(docNode)))) + if (NS_SUCCEEDED(mDomInterfaceP->GetDocumentElement(func_AddRefs(docNode)))) { - *aNode = docNode; - NS_ADDREF(*aNode); - return NS_OK; + return docNode->QueryInterface(kIDOMNodeIID,(void **) aNode); } return NS_ERROR_FAILURE; } @@ -206,7 +209,10 @@ nsEditor::GetFirstTextNode(nsIDOMNode *aNode, nsIDOMNode **aRetNode) { COM_auto_ptr mNode; - aNode->GetFirstChild(func_AddRefs(mNode)); + if (!NS_SUCCEEDED(aNode->GetFirstChild(func_AddRefs(mNode)))) + { + assert(0); + } while(!answer) { GetFirstTextNode(mNode, func_AddRefs(answer));