Bug 747346 - Cleanup nsTextEditRules::CreateTrailingBRIfNeeded(); r=ehsan
authorMs2ger <ms2ger@gmail.com>
Sat, 05 May 2012 11:00:05 +0200
changeset 95508 ec7da992029b6eb90ebe42214c1fb16df5cc029f
parent 95507 f5e54f531a4e6d7e27986514e65ba8edf4eace6e
child 95509 3859550a1cbb1a3304ff0ba8b2c9c41ac46ee361
push idunknown
push userunknown
push dateunknown
reviewersehsan
bugs747346
milestone15.0a1
Bug 747346 - Cleanup nsTextEditRules::CreateTrailingBRIfNeeded(); r=ehsan
editor/libeditor/text/nsTextEditRules.cpp
--- a/editor/libeditor/text/nsTextEditRules.cpp
+++ b/editor/libeditor/text/nsTextEditRules.cpp
@@ -1084,47 +1084,45 @@ nsTextEditRules::RemoveRedundantTrailing
                 kMOZEditorBogusNodeValue, false);
   return NS_OK;
 }
 
 nsresult
 nsTextEditRules::CreateTrailingBRIfNeeded()
 {
   // but only if we aren't a single line edit field
-  if (IsSingleLineEditor())
+  if (IsSingleLineEditor()) {
     return NS_OK;
-  nsCOMPtr<nsIDOMNode> body = do_QueryInterface(mEditor->GetRoot());
+  }
+
+  dom::Element* body = mEditor->GetRoot();
   NS_ENSURE_TRUE(body, NS_ERROR_NULL_POINTER);
-  nsCOMPtr<nsIDOMNode> lastChild;
-  nsresult res = body->GetLastChild(getter_AddRefs(lastChild));
+
+  nsIContent* lastChild = body->GetLastChild();
   // assuming CreateBogusNodeIfNeeded() has been called first
-  NS_ENSURE_SUCCESS(res, res);  
   NS_ENSURE_TRUE(lastChild, NS_ERROR_NULL_POINTER);
 
-  if (!nsTextEditUtils::IsBreak(lastChild))
-  {
+  if (!lastChild->IsHTML(nsGkAtoms::br)) {
     nsAutoTxnsConserveSelection dontSpazMySelection(mEditor);
-    PRUint32 rootLen;
-    res = mEditor->GetLengthOfDOMNode(body, rootLen);
-    NS_ENSURE_SUCCESS(res, res); 
+    nsCOMPtr<nsIDOMNode> domBody = do_QueryInterface(body);
     nsCOMPtr<nsIDOMNode> unused;
-    res = CreateMozBR(body, rootLen, address_of(unused));
-  } else {
-    // Check to see if the trailing BR is a former bogus node - this will have stuck
-    // around if we previously morphed a trailing node into a bogus node
-    nsCOMPtr<nsIContent> lastBR = do_QueryInterface(lastChild);
-    if (!mEditor->IsMozEditorBogusNode(lastBR))
-      return NS_OK;
+    return CreateMozBR(domBody, body->Length(), address_of(unused));
+  }
 
-    // Morph it back to a mozBR
-    dom::Element* elem = lastBR->AsElement();
-    elem->UnsetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom, false);
-    elem->SetAttr(kNameSpaceID_None, nsGkAtoms::type, NS_LITERAL_STRING("_moz"), true);
+  // Check to see if the trailing BR is a former bogus node - this will have
+  // stuck around if we previously morphed a trailing node into a bogus node.
+  if (!mEditor->IsMozEditorBogusNode(lastChild)) {
+    return NS_OK;
   }
-  return res;
+
+  // Morph it back to a mozBR
+  lastChild->UnsetAttr(kNameSpaceID_None, kMOZEditorBogusNodeAttrAtom, false);
+  lastChild->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
+                     NS_LITERAL_STRING("_moz"), true);
+  return NS_OK;
 }
 
 nsresult
 nsTextEditRules::CreateBogusNodeIfNeeded(nsISelection *aSelection)
 {
   NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   NS_ENSURE_TRUE(mEditor, NS_ERROR_NULL_POINTER);