Bug 1153629 part 3 - Clean up nsHTMLEditRules::GetNodesFromPoint; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Fri, 24 Apr 2015 14:27:35 +0300
changeset 259347 21318cef2ac4d4b836ed0c425da6dd8206ea0eb9
parent 259346 b028d352877dad2071a4b4140c262ecbd8813bbd
child 259348 77f01af28007584ad919fda95dc794a46611c35e
push id1728
push usermartin.thomson@gmail.com
push dateFri, 24 Apr 2015 18:56:35 +0000
reviewersehsan
bugs1153629
milestone40.0a1
Bug 1153629 part 3 - Clean up nsHTMLEditRules::GetNodesFromPoint; r=ehsan
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -2857,40 +2857,35 @@ nsHTMLEditRules::JoinBlocks(nsIDOMNode *
 *         nsIDOMNode *aLeftBlock         parent to receive moved content
 *         nsIDOMNode *aRightBlock        parent to provide moved content
 *         int32_t aLeftOffset            offset in aLeftBlock to move content to
 *         int32_t aRightOffset           offset in aRightBlock to move content from
 */
 nsresult
 nsHTMLEditRules::MoveBlock(nsIDOMNode *aLeftBlock, nsIDOMNode *aRightBlock, int32_t aLeftOffset, int32_t aRightOffset)
 {
-  nsCOMArray<nsIDOMNode> arrayOfNodes;
-  nsCOMPtr<nsISupports> isupports;
+  nsTArray<nsCOMPtr<nsINode>> arrayOfNodes;
   // GetNodesFromPoint is the workhorse that figures out what we wnat to move.
   nsresult res = GetNodesFromPoint(::DOMPoint(aRightBlock,aRightOffset),
-                                   EditAction::makeList, arrayOfNodes, true);
-  NS_ENSURE_SUCCESS(res, res);
-  int32_t listCount = arrayOfNodes.Count();
-  int32_t i;
-  for (i=0; i<listCount; i++)
-  {
+                                   EditAction::makeList, arrayOfNodes,
+                                   TouchContent::no);
+  NS_ENSURE_SUCCESS(res, res);
+  for (auto& curNode : arrayOfNodes) {
     // get the node to act on
-    nsIDOMNode* curNode = arrayOfNodes[i];
-    if (IsBlockNode(curNode))
-    {
+    if (IsBlockNode(GetAsDOMNode(curNode))) {
       // For block nodes, move their contents only, then delete block.
-      res = MoveContents(curNode, aLeftBlock, &aLeftOffset); 
+      res = MoveContents(GetAsDOMNode(curNode), aLeftBlock, &aLeftOffset); 
       NS_ENSURE_SUCCESS(res, res);
       NS_ENSURE_STATE(mHTMLEditor);
       res = mHTMLEditor->DeleteNode(curNode);
     }
     else
     {
       // otherwise move the content as is, checking against the dtd.
-      res = MoveNodeSmart(curNode, aLeftBlock, &aLeftOffset);
+      res = MoveNodeSmart(GetAsDOMNode(curNode), aLeftBlock, &aLeftOffset);
     }
   }
   return res;
 }
 
 /*****************************************************************************************************
 *    MoveNodeSmart: this method is used to move node aSource to (aDest,aOffset).
 *    DTD containment rules are followed throughout.  aOffset is updated to point _after_
@@ -6249,48 +6244,46 @@ nsHTMLEditRules::GetHighestInlineParent(
   {
     inlineNode = node;
     inlineNode->GetParentNode(getter_AddRefs(node));
   }
   return inlineNode;
 }
 
 
-///////////////////////////////////////////////////////////////////////////
-// GetNodesFromPoint: given a particular operation, construct a list  
-//                     of nodes from a point that will be operated on. 
-//                       
-nsresult 
-nsHTMLEditRules::GetNodesFromPoint(::DOMPoint point,
-                                   EditAction operation,
-                                   nsCOMArray<nsIDOMNode> &arrayOfNodes,
-                                   bool dontTouchContent)
-{
-  NS_ENSURE_STATE(point.node);
-  nsRefPtr<nsRange> range = new nsRange(point.node);
-  nsresult res = range->SetStart(point.node, point.offset);
-  NS_ENSURE_SUCCESS(res, res);
-  
-  // expand the range to include adjacent inlines
-  PromoteRange(*range, operation);
-      
-  // make array of ranges
+///////////////////////////////////////////////////////////////////////////////
+// GetNodesFromPoint: Given a particular operation, construct a list of nodes
+//                    from a point that will be operated on.
+//
+nsresult
+nsHTMLEditRules::GetNodesFromPoint(::DOMPoint aPoint,
+                                   EditAction aOperation,
+                                   nsTArray<nsCOMPtr<nsINode>>& outArrayOfNodes,
+                                   TouchContent aTouchContent)
+{
+  NS_ENSURE_STATE(aPoint.node);
+  nsRefPtr<nsRange> range = new nsRange(aPoint.node);
+  nsresult res = range->SetStart(aPoint.node, aPoint.offset);
+  MOZ_ASSERT(NS_SUCCEEDED(res));
+
+  // Expand the range to include adjacent inlines
+  PromoteRange(*range, aOperation);
+
+  // Make array of ranges
   nsTArray<nsRefPtr<nsRange>> arrayOfRanges;
-  
-  // stuff new opRange into array
+
+  // Stuff new opRange into array
   arrayOfRanges.AppendElement(range);
-  
-  // use these ranges to contruct a list of nodes to act on.
-  nsTArray<nsCOMPtr<nsINode>> array;
-  res = GetNodesForOperation(arrayOfRanges, array, operation, dontTouchContent
-                             ? TouchContent::no : TouchContent::yes);
-  for (auto& node : array) {
-    arrayOfNodes.AppendObject(GetAsDOMNode(node));
-  }
-  return res;
+
+  // Use these ranges to contruct a list of nodes to act on
+  res = GetNodesForOperation(arrayOfRanges, outArrayOfNodes, aOperation,
+                             aTouchContent);
+  NS_ENSURE_SUCCESS(res, res);
+
+  return NS_OK;
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // GetNodesFromSelection: Given a particular operation, construct a list of
 //                        nodes from the selection that will be operated on.
 //
 nsresult
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -272,20 +272,20 @@ protected:
   void PromoteRange(nsRange& aRange, EditAction inOperationType);
   enum class TouchContent { no, yes };
   nsresult GetNodesForOperation(nsTArray<nsRefPtr<nsRange>>& aArrayOfRanges,
                                 nsTArray<nsCOMPtr<nsINode>>& aOutArrayOfNodes,
                                 EditAction aOperationType,
                                 TouchContent aTouchContent = TouchContent::yes);
   nsresult GetChildNodesForOperation(nsIDOMNode *inNode, 
                                      nsCOMArray<nsIDOMNode>& outArrayOfNodes);
-  nsresult GetNodesFromPoint(::DOMPoint point,
-                             EditAction operation,
-                             nsCOMArray<nsIDOMNode>& arrayOfNodes,
-                             bool dontTouchContent);
+  nsresult GetNodesFromPoint(::DOMPoint aPoint,
+                             EditAction aOperation,
+                             nsTArray<nsCOMPtr<nsINode>>& outArrayOfNodes,
+                             TouchContent aTouchContent);
   nsresult GetNodesFromSelection(mozilla::dom::Selection& aSelection,
                                  EditAction aOperation,
                                  nsTArray<nsCOMPtr<nsINode>>& outArrayOfNodes,
                                  TouchContent aTouchContent = TouchContent::yes);
   enum class EntireList { no, yes };
   nsresult GetListActionNodes(nsTArray<nsCOMPtr<nsINode>>& aOutArrayOfNodes,
                               EntireList aEntireList,
                               TouchContent aTouchContent = TouchContent::yes);