diff --git a/editor/libeditor/nsEditor.cpp b/editor/libeditor/nsEditor.cpp index ae95fdf1599b..6e87d773ab90 100644 --- a/editor/libeditor/nsEditor.cpp +++ b/editor/libeditor/nsEditor.cpp @@ -2269,11 +2269,11 @@ NS_IMETHODIMP nsEditor::ScrollSelectionIntoView(bool aScrollToAnchor) return NS_OK; } -NS_IMETHODIMP +nsresult nsEditor::InsertTextImpl(const nsAString& aStringToInsert, - nsCOMPtr* aInOutNode, + nsCOMPtr* aInOutNode, int32_t* aInOutOffset, - nsIDOMDocument* aDoc) + nsIDocument* aDoc) { // NOTE: caller *must* have already used nsAutoTxnsConserveSelection // stack-based class to turn off txn selection updating. Caller also turned @@ -2285,8 +2285,7 @@ nsEditor::InsertTextImpl(const nsAString& aStringToInsert, return NS_OK; } - nsCOMPtr node = do_QueryInterface(*aInOutNode); - NS_ENSURE_STATE(node); + nsCOMPtr node = *aInOutNode; uint32_t offset = static_cast(*aInOutOffset); if (!node->IsNodeOfType(nsINode::eTEXT) && IsPlaintextEditor()) { @@ -2324,11 +2323,9 @@ nsEditor::InsertTextImpl(const nsAString& aStringToInsert, if (mComposition) { if (!node->IsNodeOfType(nsINode::eTEXT)) { // create a text node - nsCOMPtr doc = do_QueryInterface(aDoc); - NS_ENSURE_STATE(doc); - nsRefPtr newNode = doc->CreateTextNode(EmptyString()); + nsRefPtr newNode = aDoc->CreateTextNode(EmptyString()); // then we insert it into the dom tree - res = InsertNode(newNode->AsDOMNode(), node->AsDOMNode(), offset); + res = InsertNode(*newNode, *node, offset); NS_ENSURE_SUCCESS(res, res); node = newNode; offset = 0; @@ -2347,18 +2344,16 @@ nsEditor::InsertTextImpl(const nsAString& aStringToInsert, } else { // we are inserting text into a non-text node. first we have to create a // textnode (this also populates it with the text) - nsCOMPtr doc = do_QueryInterface(aDoc); - NS_ENSURE_STATE(doc); - nsRefPtr newNode = doc->CreateTextNode(aStringToInsert); + nsRefPtr newNode = aDoc->CreateTextNode(aStringToInsert); // then we insert it into the dom tree - res = InsertNode(newNode->AsDOMNode(), node->AsDOMNode(), offset); + res = InsertNode(*newNode, *node, offset); NS_ENSURE_SUCCESS(res, res); node = newNode; offset = aStringToInsert.Length(); } } - *aInOutNode = node->AsDOMNode(); + *aInOutNode = node; *aInOutOffset = static_cast(offset); return NS_OK; } diff --git a/editor/libeditor/nsEditor.h b/editor/libeditor/nsEditor.h index 2e917ac3a020..ca1e79b75f68 100644 --- a/editor/libeditor/nsEditor.h +++ b/editor/libeditor/nsEditor.h @@ -202,10 +202,10 @@ public: virtual bool IsModifiableNode(nsINode *aNode); - NS_IMETHOD InsertTextImpl(const nsAString& aStringToInsert, - nsCOMPtr *aInOutNode, - int32_t *aInOutOffset, - nsIDOMDocument *aDoc); + virtual nsresult InsertTextImpl(const nsAString& aStringToInsert, + nsCOMPtr* aInOutNode, + int32_t* aInOutOffset, + nsIDocument* aDoc); nsresult InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert, mozilla::dom::Text& aTextNode, int32_t aOffset, diff --git a/editor/libeditor/nsHTMLEditRules.cpp b/editor/libeditor/nsHTMLEditRules.cpp index 64262ad96372..d21fc97f8cd3 100644 --- a/editor/libeditor/nsHTMLEditRules.cpp +++ b/editor/libeditor/nsHTMLEditRules.cpp @@ -1325,9 +1325,6 @@ nsHTMLEditRules::WillInsertText(EditAction aAction, *aCancel = false; *aHandled = true; nsresult res; - nsCOMPtr selNode; - int32_t selOffset; - // If the selection isn't collapsed, delete it. Don't delete existing inline // tags, because we're hopefully going to insert text (bug 787432). if (!aSelection->Collapsed()) { @@ -1344,24 +1341,26 @@ nsHTMLEditRules::WillInsertText(EditAction aAction, // we need to get the doc NS_ENSURE_STATE(mHTMLEditor); - nsCOMPtr doc = mHTMLEditor->GetDOMDocument(); - nsCOMPtr doc_ = mHTMLEditor->GetDocument(); - NS_ENSURE_TRUE(doc && doc_, NS_ERROR_NOT_INITIALIZED); + nsCOMPtr doc = mHTMLEditor->GetDocument(); + nsCOMPtr domDoc = mHTMLEditor->GetDOMDocument(); + NS_ENSURE_TRUE(doc && domDoc, NS_ERROR_NOT_INITIALIZED); // for every property that is set, insert a new inline style node - res = CreateStyleForInsertText(aSelection, doc); + res = CreateStyleForInsertText(aSelection, domDoc); NS_ENSURE_SUCCESS(res, res); // get the (collapsed) selection location NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - NS_ENSURE_SUCCESS(res, res); + NS_ENSURE_STATE(aSelection->GetRangeAt(0)); + nsCOMPtr selNode = aSelection->GetRangeAt(0)->GetStartParent(); + int32_t selOffset = aSelection->GetRangeAt(0)->StartOffset(); + NS_ENSURE_STATE(selNode); // dont put text in places that can't have it NS_ENSURE_STATE(mHTMLEditor); if (!mHTMLEditor->IsTextNode(selNode) && - (!mHTMLEditor || - !mHTMLEditor->CanContainTag(selNode, nsGkAtoms::textTagName))) { + (!mHTMLEditor || !mHTMLEditor->CanContainTag(GetAsDOMNode(selNode), + nsGkAtoms::textTagName))) { return NS_ERROR_FAILURE; } @@ -1371,29 +1370,28 @@ nsHTMLEditRules::WillInsertText(EditAction aAction, if (inString->IsEmpty()) { NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->InsertTextImpl(*inString, address_of(selNode), &selOffset, doc); + res = mHTMLEditor->InsertTextImpl(*inString, address_of(selNode), + &selOffset, doc); } else { NS_ENSURE_STATE(mHTMLEditor); - nsCOMPtr selNode_(do_QueryInterface(selNode)); - nsWSRunObject wsObj(mHTMLEditor, selNode_, selOffset); - res = wsObj.InsertText(*inString, address_of(selNode_), &selOffset, doc_); - selNode = GetAsDOMNode(selNode_); + nsWSRunObject wsObj(mHTMLEditor, selNode, selOffset); + res = wsObj.InsertText(*inString, address_of(selNode), &selOffset, doc); } NS_ENSURE_SUCCESS(res, res); } else // aAction == kInsertText { // find where we are - nsCOMPtr curNode = selNode; + nsCOMPtr curNode = selNode; int32_t curOffset = selOffset; // is our text going to be PREformatted? // We remember this so that we know how to handle tabs. bool isPRE; NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->IsPreformatted(selNode, &isPRE); + res = mHTMLEditor->IsPreformatted(GetAsDOMNode(selNode), &isPRE); NS_ENSURE_SUCCESS(res, res); // turn off the edit listener: we know how to @@ -1407,7 +1405,6 @@ nsHTMLEditRules::WillInsertText(EditAction aAction, nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor); nsAutoString tString(*inString); const char16_t *unicodeBuf = tString.get(); - nsCOMPtr unused; int32_t pos = 0; NS_NAMED_LITERAL_STRING(newlineStr, LFSTR); @@ -1441,15 +1438,19 @@ nsHTMLEditRules::WillInsertText(EditAction aAction, if (subStr.Equals(newlineStr)) { NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->CreateBRImpl(address_of(curNode), &curOffset, address_of(unused), nsIEditor::eNone); + nsCOMPtr br = + mHTMLEditor->CreateBRImpl(address_of(curNode), &curOffset, + nsIEditor::eNone); + NS_ENSURE_STATE(br); pos++; } else { NS_ENSURE_STATE(mHTMLEditor); - res = mHTMLEditor->InsertTextImpl(subStr, address_of(curNode), &curOffset, doc); + res = mHTMLEditor->InsertTextImpl(subStr, address_of(curNode), + &curOffset, doc); + NS_ENSURE_SUCCESS(res, res); } - NS_ENSURE_SUCCESS(res, res); } } else @@ -1483,27 +1484,23 @@ nsHTMLEditRules::WillInsertText(EditAction aAction, // is it a tab? if (subStr.Equals(tabStr)) { - nsCOMPtr curNode_(do_QueryInterface(curNode)); - res = wsObj.InsertText(spacesStr, address_of(curNode_), &curOffset, doc_); - curNode = GetAsDOMNode(curNode_); + res = + wsObj.InsertText(spacesStr, address_of(curNode), &curOffset, doc); NS_ENSURE_SUCCESS(res, res); pos++; } // is it a return? else if (subStr.Equals(newlineStr)) { - nsCOMPtr node(do_QueryInterface(curNode)); - nsCOMPtr br = - wsObj.InsertBreak(address_of(node), &curOffset, nsIEditor::eNone); + nsCOMPtr br = wsObj.InsertBreak(address_of(curNode), + &curOffset, + nsIEditor::eNone); NS_ENSURE_TRUE(br, NS_ERROR_FAILURE); - curNode = GetAsDOMNode(node); pos++; } else { - nsCOMPtr curNode_(do_QueryInterface(curNode)); - res = wsObj.InsertText(subStr, address_of(curNode_), &curOffset, doc_); - curNode = GetAsDOMNode(curNode_); + res = wsObj.InsertText(subStr, address_of(curNode), &curOffset, doc); NS_ENSURE_SUCCESS(res, res); } NS_ENSURE_SUCCESS(res, res); @@ -1517,9 +1514,7 @@ nsHTMLEditRules::WillInsertText(EditAction aAction, // the correct portion of the document. if (!mDocChangeRange) { - nsCOMPtr node = do_QueryInterface(selNode); - NS_ENSURE_STATE(node); - mDocChangeRange = new nsRange(node); + mDocChangeRange = new nsRange(selNode); } res = mDocChangeRange->SetStart(selNode, selOffset); NS_ENSURE_SUCCESS(res, res); diff --git a/editor/libeditor/nsHTMLEditor.cpp b/editor/libeditor/nsHTMLEditor.cpp index bb8894ff9e08..75f06bd884ff 100644 --- a/editor/libeditor/nsHTMLEditor.cpp +++ b/editor/libeditor/nsHTMLEditor.cpp @@ -3194,17 +3194,18 @@ nsHTMLEditor::DeleteText(nsGenericDOMDataNode& aCharData, uint32_t aOffset, return nsEditor::DeleteText(aCharData, aOffset, aLength); } -NS_IMETHODIMP nsHTMLEditor::InsertTextImpl(const nsAString& aStringToInsert, - nsCOMPtr *aInOutNode, - int32_t *aInOutOffset, - nsIDOMDocument *aDoc) +nsresult +nsHTMLEditor::InsertTextImpl(const nsAString& aStringToInsert, + nsCOMPtr* aInOutNode, + int32_t* aInOutOffset, nsIDocument* aDoc) { - // do nothing if the node is read-only + // Do nothing if the node is read-only if (!IsModifiableNode(*aInOutNode)) { return NS_ERROR_FAILURE; } - return nsEditor::InsertTextImpl(aStringToInsert, aInOutNode, aInOutOffset, aDoc); + return nsEditor::InsertTextImpl(aStringToInsert, aInOutNode, aInOutOffset, + aDoc); } void diff --git a/editor/libeditor/nsHTMLEditor.h b/editor/libeditor/nsHTMLEditor.h index a9cbde0f4535..7396be387ce0 100644 --- a/editor/libeditor/nsHTMLEditor.h +++ b/editor/libeditor/nsHTMLEditor.h @@ -313,10 +313,10 @@ public: NS_IMETHODIMP DeleteNode(nsIDOMNode * aNode); nsresult DeleteText(nsGenericDOMDataNode& aTextNode, uint32_t aOffset, uint32_t aLength); - NS_IMETHOD InsertTextImpl(const nsAString& aStringToInsert, - nsCOMPtr *aInOutNode, - int32_t *aInOutOffset, - nsIDOMDocument *aDoc); + virtual nsresult InsertTextImpl(const nsAString& aStringToInsert, + nsCOMPtr* aInOutNode, + int32_t* aInOutOffset, + nsIDocument* aDoc) MOZ_OVERRIDE; NS_IMETHOD_(bool) IsModifiableNode(nsIDOMNode *aNode); virtual bool IsModifiableNode(nsINode *aNode); diff --git a/editor/libeditor/nsPlaintextEditor.cpp b/editor/libeditor/nsPlaintextEditor.cpp index b1dfc09a6a59..26e9cb621aa5 100644 --- a/editor/libeditor/nsPlaintextEditor.cpp +++ b/editor/libeditor/nsPlaintextEditor.cpp @@ -770,18 +770,19 @@ NS_IMETHODIMP nsPlaintextEditor::InsertLineBreak() if (!cancel && !handled) { // get the (collapsed) selection location - nsCOMPtr selNode; - int32_t selOffset; - res = GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); - NS_ENSURE_SUCCESS(res, res); + NS_ENSURE_STATE(selection->GetRangeAt(0)); + nsCOMPtr selNode = selection->GetRangeAt(0)->GetStartParent(); + int32_t selOffset = selection->GetRangeAt(0)->StartOffset(); + NS_ENSURE_STATE(selNode); // don't put text in places that can't have it - if (!IsTextNode(selNode) && !CanContainTag(selNode, nsGkAtoms::textTagName)) { + if (!IsTextNode(selNode) && !CanContainTag(GetAsDOMNode(selNode), + nsGkAtoms::textTagName)) { return NS_ERROR_FAILURE; } // we need to get the doc - nsCOMPtr doc = GetDOMDocument(); + nsCOMPtr doc = GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED); // don't spaz my selection in subtransactions @@ -803,8 +804,8 @@ NS_IMETHODIMP nsPlaintextEditor::InsertLineBreak() int32_t endOffset; res = GetEndNodeAndOffset(selection, getter_AddRefs(endNode), &endOffset); - if (NS_SUCCEEDED(res) && endNode == selNode && endOffset == selOffset) - { + if (NS_SUCCEEDED(res) && endNode == GetAsDOMNode(selNode) + && endOffset == selOffset) { // SetInterlinePosition(true) means we want the caret to stick to the content on the "right". // We want the caret to stick to whatever is past the break. This is // because the break is on the same line we were on, but the next content diff --git a/editor/libeditor/nsTextEditRules.cpp b/editor/libeditor/nsTextEditRules.cpp index 97cdfbba93e1..e988d79230d0 100644 --- a/editor/libeditor/nsTextEditRules.cpp +++ b/editor/libeditor/nsTextEditRules.cpp @@ -700,22 +700,21 @@ nsTextEditRules::WillInsertText(EditAction aAction, } // get the (collapsed) selection location - nsCOMPtr selNode; - int32_t selOffset; - NS_ENSURE_STATE(mEditor); - res = mEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(selNode), &selOffset); - NS_ENSURE_SUCCESS(res, res); + NS_ENSURE_STATE(aSelection->GetRangeAt(0)); + nsCOMPtr selNode = aSelection->GetRangeAt(0)->GetStartParent(); + int32_t selOffset = aSelection->GetRangeAt(0)->StartOffset(); + NS_ENSURE_STATE(selNode); // don't put text in places that can't have it NS_ENSURE_STATE(mEditor); if (!mEditor->IsTextNode(selNode) && - !mEditor->CanContainTag(selNode, nsGkAtoms::textTagName)) { + !mEditor->CanContainTag(GetAsDOMNode(selNode), nsGkAtoms::textTagName)) { return NS_ERROR_FAILURE; } // we need to get the doc NS_ENSURE_STATE(mEditor); - nsCOMPtr doc = mEditor->GetDOMDocument(); + nsCOMPtr doc = mEditor->GetDocument(); NS_ENSURE_TRUE(doc, NS_ERROR_NOT_INITIALIZED); if (aAction == EditAction::insertIMEText) { @@ -724,7 +723,7 @@ nsTextEditRules::WillInsertText(EditAction aAction, NS_ENSURE_SUCCESS(res, res); } else { // aAction == EditAction::insertText; find where we are - nsCOMPtr curNode = selNode; + nsCOMPtr curNode = selNode; int32_t curOffset = selOffset; // don't spaz my selection in subtransactions diff --git a/editor/libeditor/nsWSRunObject.cpp b/editor/libeditor/nsWSRunObject.cpp index 795793cd690c..dfc6302aaaeb 100644 --- a/editor/libeditor/nsWSRunObject.cpp +++ b/editor/libeditor/nsWSRunObject.cpp @@ -382,11 +382,8 @@ nsWSRunObject::InsertText(const nsAString& aStringToInsert, } // Ready, aim, fire! - nsCOMPtr parent(GetAsDOMNode(*aInOutParent)); - nsCOMPtr doc(do_QueryInterface(aDoc)); - res = mHTMLEditor->InsertTextImpl(theString, address_of(parent), - aInOutOffset, doc); - *aInOutParent = do_QueryInterface(parent); + res = mHTMLEditor->InsertTextImpl(theString, aInOutParent, aInOutOffset, + aDoc); return NS_OK; }