Bug 1153629 part 11 - Clean up nsHTMLEditRules::AdjustSpecialBreaks; r=ehsan
☠☠ backed out by 329dd852c06b ☠ ☠
authorAryeh Gregor <ayg@aryeh.name>
Wed, 22 Apr 2015 14:26:58 +0300
changeset 240515 a9d071f07242b749088bdd88d9796c039598fee5
parent 240514 1f0fdf67005d39f40355bca20c2db7c2e5d5ce27
child 240516 25bc426c8c0e6b75fdbd5717b8bd46bf8001aab2
push id28636
push userkwierso@gmail.com
push dateThu, 23 Apr 2015 00:16:12 +0000
treeherdermozilla-central@a5af73b32ac8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1153629
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1153629 part 11 - Clean up nsHTMLEditRules::AdjustSpecialBreaks; r=ehsan
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -271,18 +271,17 @@ nsHTMLEditRules::Init(nsPlaintextEditor 
   nsAutoLockRulesSniffing lockIt((nsTextEditRules*)this);
   if (!mDocChangeRange) {
     mDocChangeRange = new nsRange(node);
   }
 
   if (node->IsElement()) {
     ErrorResult rv;
     mDocChangeRange->SelectNode(*node, rv);
-    res = AdjustSpecialBreaks(node);
-    NS_ENSURE_SUCCESS(res, res);
+    AdjustSpecialBreaks();
   }
 
   // add ourselves as a listener to edit actions
   res = mHTMLEditor->AddEditActionListener(this);
 
   return res;
 }
 
@@ -456,18 +455,17 @@ nsHTMLEditRules::AfterEditInner(EditActi
     // That's why this is here rather than DidDeleteSelection().
     if ((action == EditAction::deleteSelection) && mDidRangedDelete)
     {
       res = InsertBRIfNeeded(selection);
       NS_ENSURE_SUCCESS(res, res);
     }  
     
     // add in any needed <br>s, and remove any unneeded ones.
-    res = AdjustSpecialBreaks();
-    NS_ENSURE_SUCCESS(res, res);
+    AdjustSpecialBreaks();
     
     // merge any adjacent text nodes
     if ( (action != EditAction::insertText &&
          action != EditAction::insertIMEText) )
     {
       NS_ENSURE_STATE(mHTMLEditor);
       res = mHTMLEditor->CollapseAdjacentTextNodes(mDocChangeRange);
       NS_ENSURE_SUCCESS(res, res);
@@ -7290,47 +7288,36 @@ nsHTMLEditRules::ClearCachedStyles()
   // clear the mPresent bits in mCachedStyles array
   for (uint32_t j = 0; j < SIZE_STYLE_TABLE; j++) {
     mCachedStyles[j].mPresent = false;
     mCachedStyles[j].value.Truncate();
   }
 }
 
 
-nsresult 
-nsHTMLEditRules::AdjustSpecialBreaks(bool aSafeToAskFrames)
-{
-  nsCOMArray<nsIDOMNode> arrayOfNodes;
-  nsCOMPtr<nsISupports> isupports;
-  int32_t nodeCount,j;
-  
-  // gather list of empty nodes
-  NS_ENSURE_STATE(mHTMLEditor);
+void
+nsHTMLEditRules::AdjustSpecialBreaks()
+{
+  NS_ENSURE_TRUE(mHTMLEditor, );
+
+  // Gather list of empty nodes
+  nsTArray<nsCOMPtr<nsINode>> nodeArray;
   nsEmptyEditableFunctor functor(mHTMLEditor);
   nsDOMIterator iter(*mDocChangeRange);
-  iter.AppendList(functor, arrayOfNodes);
-
-  // put moz-br's into these empty li's and td's
-  nodeCount = arrayOfNodes.Count();
-  for (j = 0; j < nodeCount; j++)
-  {
-    // need to put br at END of node.  It may have
-    // empty containers in it and still pass the "IsEmptynode" test,
-    // and we want the br's to be after them.  Also, we want the br
-    // to be after the selection if the selection is in this node.
-    uint32_t len;
-    nsCOMPtr<nsIDOMNode> theNode = arrayOfNodes[0];
-    arrayOfNodes.RemoveObjectAt(0);
-    nsresult res = nsEditor::GetLengthOfDOMNode(theNode, len);
-    NS_ENSURE_SUCCESS(res, res);
-    res = CreateMozBR(theNode, (int32_t)len);
-    NS_ENSURE_SUCCESS(res, res);
-  }
-  
-  return NS_OK;
+  iter.AppendList(functor, nodeArray);
+
+  // Put moz-br's into these empty li's and td's
+  for (auto& node : nodeArray) {
+    // Need to put br at END of node.  It may have empty containers in it and
+    // still pass the "IsEmptyNode" test, and we want the br's to be after
+    // them.  Also, we want the br to be after the selection if the selection
+    // is in this node.
+    nsresult res = CreateMozBR(node->AsDOMNode(), (int32_t)node->Length());
+    NS_ENSURE_SUCCESS(res, );
+  }
 }
 
 nsresult 
 nsHTMLEditRules::AdjustWhitespace(Selection* aSelection)
 {
   // get selection point
   nsCOMPtr<nsIDOMNode> selNode;
   int32_t selOffset;
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -307,17 +307,17 @@ protected:
   nsresult AddTerminatingBR(nsIDOMNode *aBlock);
   ::DOMPoint JoinNodesSmart(nsIContent& aNodeLeft, nsIContent& aNodeRight);
   mozilla::dom::Element* GetTopEnclosingMailCite(nsINode& aNode);
   nsresult PopListItem(nsIDOMNode *aListItem, bool *aOutOfList);
   nsresult RemoveListStructure(nsIDOMNode *aList);
   nsresult CacheInlineStyles(nsIDOMNode *aNode);
   nsresult ReapplyCachedStyles();
   void ClearCachedStyles();
-  nsresult AdjustSpecialBreaks(bool aSafeToAskFrames = false);
+  void AdjustSpecialBreaks();
   nsresult AdjustWhitespace(mozilla::dom::Selection* aSelection);
   nsresult PinSelectionToNewBlock(mozilla::dom::Selection* aSelection);
   nsresult CheckInterlinePosition(mozilla::dom::Selection* aSelection);
   nsresult AdjustSelection(mozilla::dom::Selection* aSelection,
                            nsIEditor::EDirection aAction);
   nsresult FindNearSelectableNode(nsIDOMNode *aSelNode, 
                                   int32_t aSelOffset, 
                                   nsIEditor::EDirection &aDirection,