From 7602d38c60eb7571bde91790106214d856400782 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 1 Feb 2012 11:54:21 +0100 Subject: [PATCH] Bug 720982 - Part a: Remove nsHTMLEditor::CreateBRImpl; r=ehsan --- editor/libeditor/html/nsHTMLEditor.cpp | 81 --------------------- editor/libeditor/html/nsHTMLEditor.h | 4 - editor/libeditor/text/nsPlaintextEditor.cpp | 8 +- editor/libeditor/text/nsPlaintextEditor.h | 8 +- 4 files changed, 10 insertions(+), 91 deletions(-) diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index dec303371e7..ee712760477 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -1364,87 +1364,6 @@ NS_IMETHODIMP nsHTMLEditor::TabInTable(bool inIsShift, bool *outHandled) return res; } -NS_IMETHODIMP nsHTMLEditor::CreateBRImpl(nsCOMPtr *aInOutParent, - PRInt32 *aInOutOffset, - nsCOMPtr *outBRNode, - EDirection aSelect) -{ - NS_ENSURE_TRUE(aInOutParent && *aInOutParent && aInOutOffset && outBRNode, NS_ERROR_NULL_POINTER); - *outBRNode = nsnull; - nsresult res; - - // we need to insert a br. unfortunately, we may have to split a text node to do it. - nsCOMPtr node = *aInOutParent; - PRInt32 theOffset = *aInOutOffset; - nsCOMPtr nodeAsText = do_QueryInterface(node); - NS_NAMED_LITERAL_STRING(brType, "br"); - nsCOMPtr brNode; - if (nodeAsText) - { - nsCOMPtr tmp; - PRInt32 offset; - PRUint32 len; - nodeAsText->GetLength(&len); - GetNodeLocation(node, address_of(tmp), &offset); - NS_ENSURE_TRUE(tmp, NS_ERROR_FAILURE); - if (!theOffset) - { - // we are already set to go - } - else if (theOffset == (PRInt32)len) - { - // update offset to point AFTER the text node - offset++; - } - else - { - // split the text node - res = SplitNode(node, theOffset, getter_AddRefs(tmp)); - NS_ENSURE_SUCCESS(res, res); - res = GetNodeLocation(node, address_of(tmp), &offset); - NS_ENSURE_SUCCESS(res, res); - } - // create br - res = CreateNode(brType, tmp, offset, getter_AddRefs(brNode)); - NS_ENSURE_SUCCESS(res, res); - *aInOutParent = tmp; - *aInOutOffset = offset+1; - } - else - { - res = CreateNode(brType, node, theOffset, getter_AddRefs(brNode)); - NS_ENSURE_SUCCESS(res, res); - (*aInOutOffset)++; - } - - *outBRNode = brNode; - if (*outBRNode && (aSelect != eNone)) - { - nsCOMPtr selection; - nsCOMPtr parent; - PRInt32 offset; - res = GetSelection(getter_AddRefs(selection)); - NS_ENSURE_SUCCESS(res, res); - nsCOMPtr selPriv(do_QueryInterface(selection)); - res = GetNodeLocation(*outBRNode, address_of(parent), &offset); - NS_ENSURE_SUCCESS(res, res); - if (aSelect == eNext) - { - // position selection after br - selPriv->SetInterlinePosition(true); - res = selection->Collapse(parent, offset+1); - } - else if (aSelect == ePrevious) - { - // position selection before br - selPriv->SetInterlinePosition(true); - res = selection->Collapse(parent, offset); - } - } - return NS_OK; -} - - NS_IMETHODIMP nsHTMLEditor::CreateBR(nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPtr *outBRNode, EDirection aSelect) { nsCOMPtr parent = aNode; diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index 8acd47bce30..79a7d27a06c 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -445,10 +445,6 @@ protected: NS_IMETHOD TabInTable(bool inIsShift, bool *outHandled); NS_IMETHOD CreateBR(nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPtr *outBRNode, nsIEditor::EDirection aSelect = nsIEditor::eNone); - NS_IMETHOD CreateBRImpl(nsCOMPtr *aInOutParent, - PRInt32 *aInOutOffset, - nsCOMPtr *outBRNode, - nsIEditor::EDirection aSelect); NS_IMETHOD InsertBR(nsCOMPtr *outBRNode); // Table Editing (implemented in nsTableEditor.cpp) diff --git a/editor/libeditor/text/nsPlaintextEditor.cpp b/editor/libeditor/text/nsPlaintextEditor.cpp index 54448b54d33..5a0e0e96f2a 100644 --- a/editor/libeditor/text/nsPlaintextEditor.cpp +++ b/editor/libeditor/text/nsPlaintextEditor.cpp @@ -436,9 +436,13 @@ NS_IMETHODIMP nsPlaintextEditor::TypedText(const nsAString& aString, return NS_ERROR_FAILURE; } -NS_IMETHODIMP nsPlaintextEditor::CreateBRImpl(nsCOMPtr *aInOutParent, PRInt32 *aInOutOffset, nsCOMPtr *outBRNode, EDirection aSelect) +nsresult +nsPlaintextEditor::CreateBRImpl(nsCOMPtr* aInOutParent, + PRInt32* aInOutOffset, + nsCOMPtr* outBRNode, + EDirection aSelect) { - NS_ENSURE_SUCCESS(aInOutParent && *aInOutParent && aInOutOffset && outBRNode, NS_ERROR_NULL_POINTER); + NS_ENSURE_TRUE(aInOutParent && *aInOutParent && aInOutOffset && outBRNode, NS_ERROR_NULL_POINTER); *outBRNode = nsnull; nsresult res; diff --git a/editor/libeditor/text/nsPlaintextEditor.h b/editor/libeditor/text/nsPlaintextEditor.h index 8dbae37b740..95482da983b 100644 --- a/editor/libeditor/text/nsPlaintextEditor.h +++ b/editor/libeditor/text/nsPlaintextEditor.h @@ -193,10 +193,10 @@ protected: // key event helpers NS_IMETHOD CreateBR(nsIDOMNode *aNode, PRInt32 aOffset, nsCOMPtr *outBRNode, EDirection aSelect = eNone); - NS_IMETHOD CreateBRImpl(nsCOMPtr *aInOutParent, - PRInt32 *aInOutOffset, - nsCOMPtr *outBRNode, - EDirection aSelect); + nsresult CreateBRImpl(nsCOMPtr* aInOutParent, + PRInt32* aInOutOffset, + nsCOMPtr* outBRNode, + EDirection aSelect); NS_IMETHOD InsertBR(nsCOMPtr *outBRNode); // factored methods for handling insertion of data from transferables (drag&drop or clipboard)