From cfbd7fa1616584905484ebc095a6ce55553d62d9 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 5 May 2012 11:00:06 +0200 Subject: [PATCH] Bug 750103 - Cleanup nsEditor::EndOfDocument(); r=ehsan --- editor/libeditor/base/nsEditor.cpp | 35 ++++++++++-------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index e67bcb31241f..d9d4a1c8c14f 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -1103,39 +1103,28 @@ NS_IMETHODIMP nsEditor::BeginningOfDocument() } NS_IMETHODIMP -nsEditor::EndOfDocument() +nsEditor::EndOfDocument() { - if (!mDocWeak) { return NS_ERROR_NOT_INITIALIZED; } - nsresult res; + NS_ENSURE_TRUE(mDocWeak, NS_ERROR_NOT_INITIALIZED); // get selection nsCOMPtr selection; - res = GetSelection(getter_AddRefs(selection)); - NS_ENSURE_SUCCESS(res, res); + nsresult rv = GetSelection(getter_AddRefs(selection)); + NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER); // get the root element - nsCOMPtr node = do_QueryInterface(GetRoot()); + nsINode* node = GetRoot(); NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER); - nsCOMPtr child; + nsINode* child = node->GetLastChild(); - do { - node->GetLastChild(getter_AddRefs(child)); + while (child && IsContainer(child->AsDOMNode())) { + node = child; + child = node->GetLastChild(); + } - if (child) { - if (IsContainer(child)) { - node = child; - } else { - break; - } - } - } while (child); - - PRUint32 length = 0; - res = GetLengthOfDOMNode(node, length); - NS_ENSURE_SUCCESS(res, res); - - return selection->Collapse(node, (PRInt32)length); + PRUint32 length = node->Length(); + return selection->CollapseNative(node, PRInt32(length)); } NS_IMETHODIMP