Bug 1417344 - Clean up HTMLEditor::InsertBR. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 16 Nov 2017 13:59:14 +0900
changeset 698857 bb69d91f5f680871aeded47a75b52140cf74b6f0
parent 698679 f41930a869a84af81df1a88d8e82323ff3a6509a
child 740452 25fc426d673c49e12c105f5c361cc9453a521094
push id89375
push userbmo:m_kato@ga2.so-net.ne.jp
push dateThu, 16 Nov 2017 05:04:32 +0000
reviewersmasayuki
bugs1417344
milestone59.0a1
Bug 1417344 - Clean up HTMLEditor::InsertBR. r?masayuki No one uses out parameter of InsertBR, so we should remove it. Also, CreateBR has direction parameter for selection, so we should use it. MozReview-Commit-ID: 8heqaXpR9He
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -949,18 +949,17 @@ HTMLEditor::TypedText(const nsAString& a
                       ETypingAction aAction)
 {
   MOZ_ASSERT(!aString.IsEmpty() || aAction != eTypedText);
 
   AutoPlaceholderBatch batch(this, nsGkAtoms::TypingTxnName);
 
   if (aAction == eTypedBR) {
     // only inserts a br node
-    nsCOMPtr<nsIDOMNode> brNode;
-    return InsertBR(address_of(brNode));
+    return InsertBR();
   }
 
   return TextEditor::TypedText(aString, aAction);
 }
 
 nsresult
 HTMLEditor::TabInTable(bool inIsShift,
                        bool* outHandled)
@@ -1057,53 +1056,41 @@ HTMLEditor::CreateBR(nsIDOMNode* aNode,
                      EDirection aSelect)
 {
   nsCOMPtr<nsIDOMNode> parent = aNode;
   int32_t offset = aOffset;
   return CreateBRImpl(address_of(parent), &offset, outBRNode, aSelect);
 }
 
 nsresult
-HTMLEditor::InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode)
+HTMLEditor::InsertBR()
 {
-  NS_ENSURE_TRUE(outBRNode, NS_ERROR_NULL_POINTER);
-  *outBRNode = nullptr;
-
   // calling it text insertion to trigger moz br treatment by rules
   AutoRules beginRulesSniffing(this, EditAction::insertText, nsIEditor::eNext);
 
   RefPtr<Selection> selection = GetSelection();
   NS_ENSURE_STATE(selection);
 
   if (!selection->Collapsed()) {
     nsresult rv = DeleteSelection(nsIEditor::eNone, nsIEditor::eStrip);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  nsCOMPtr<nsIDOMNode> selNode;
+  nsCOMPtr<nsINode> selNode;
   int32_t selOffset;
   nsresult rv =
     GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = CreateBR(selNode, selOffset, outBRNode);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  selection->SetInterlinePosition(true);
-
   // position selection after br
-  nsCOMPtr<nsINode> brNode = do_QueryInterface(*outBRNode);
-  if (NS_WARN_IF(!brNode)) {
+  RefPtr<Element> br = CreateBR(selNode, selOffset, nsIEditor::eNext);
+  if (NS_WARN_IF(!br)) {
     return NS_ERROR_FAILURE;
   }
-  EditorRawDOMPoint afterBrNode(brNode);
-  if (NS_WARN_IF(!afterBrNode.AdvanceOffset())) {
-    return NS_ERROR_FAILURE;
-  }
-  return selection->Collapse(afterBrNode);
+  return NS_OK;
 }
 
 void
 HTMLEditor::CollapseSelectionToDeepestNonTableFirstChild(Selection* aSelection,
                                                          nsINode* aNode)
 {
   MOZ_ASSERT(aNode);
 
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -472,17 +472,17 @@ protected:
   nsresult TabInTable(bool inIsShift, bool* outHandled);
   already_AddRefed<Element> CreateBR(nsINode* aNode, int32_t aOffset,
                                      EDirection aSelect = eNone);
   NS_IMETHOD CreateBR(
                nsIDOMNode* aNode, int32_t aOffset,
                nsCOMPtr<nsIDOMNode>* outBRNode,
                nsIEditor::EDirection aSelect = nsIEditor::eNone) override;
 
-  nsresult InsertBR(nsCOMPtr<nsIDOMNode>* outBRNode);
+  nsresult InsertBR();
 
   // Table Editing (implemented in nsTableEditor.cpp)
 
   /**
    * Insert a new cell after or before supplied aCell.
    * Optional: If aNewCell supplied, returns the newly-created cell (addref'd,
    * of course)
    * This doesn't change or use the current selection.