Bug 1149163 part 8 - Clean up nsHTMLEditRules::GetPromotedRanges; r=froydnj
☠☠ backed out by 329dd852c06b ☠ ☠
authorAryeh Gregor <ayg@aryeh.name>
Wed, 22 Apr 2015 14:26:57 +0300
changeset 240503 54a8ecc0301d40bf1fdefa195802bd36a20a55e7
parent 240502 a31a87b6dfb7ada1f9ac7b05df6c83b7e156486a
child 240504 641439af501f0cf1f9c4e84a96f03baa2baa95e3
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)
reviewersfroydnj
bugs1149163
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 1149163 part 8 - Clean up nsHTMLEditRules::GetPromotedRanges; r=froydnj
editor/libeditor/nsHTMLEditRules.cpp
editor/libeditor/nsHTMLEditRules.h
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -831,18 +831,17 @@ nsHTMLEditRules::GetAlignment(bool *aMix
     // if we have selected the body, let's look at the first editable node
     NS_ENSURE_STATE(mHTMLEditor);
     nodeToExamine =
       GetAsDOMNode(mHTMLEditor->GetNextNode(parent, offset, true));
   }
   else
   {
     nsTArray<nsRefPtr<nsRange>> arrayOfRanges;
-    res = GetPromotedRanges(selection, arrayOfRanges, EditAction::align);
-    NS_ENSURE_SUCCESS(res, res);
+    GetPromotedRanges(*selection, arrayOfRanges, EditAction::align);
 
     // use these ranges to construct a list of nodes to act on.
     nsTArray<nsCOMPtr<nsINode>> arrayOfNodes;
     res = GetNodesForOperation(arrayOfRanges, arrayOfNodes,
                                EditAction::align, TouchContent::no);
     NS_ENSURE_SUCCESS(res, res);                                 
     nodeToExamine = GetAsDOMNode(arrayOfNodes.SafeElementAt(0));
   }
@@ -3374,18 +3373,17 @@ nsHTMLEditRules::WillRemoveList(Selectio
   *aHandled = true;
   
   nsresult res = NormalizeSelection(aSelection);
   NS_ENSURE_SUCCESS(res, res);
   NS_ENSURE_STATE(mHTMLEditor);
   nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor);
   
   nsTArray<nsRefPtr<nsRange>> arrayOfRanges;
-  res = GetPromotedRanges(aSelection, arrayOfRanges, EditAction::makeList);
-  NS_ENSURE_SUCCESS(res, res);
+  GetPromotedRanges(*aSelection, arrayOfRanges, EditAction::makeList);
   
   // use these ranges to contruct a list of nodes to act on.
   nsCOMArray<nsIDOMNode> arrayOfNodes;
   res = GetListActionNodes(arrayOfNodes, false);
   NS_ENSURE_SUCCESS(res, res);                                 
                                      
   // Remove all non-editable nodes.  Leave them be.
   int32_t listCount = arrayOfNodes.Count();
@@ -3864,18 +3862,17 @@ nsHTMLEditRules::WillHTMLIndent(Selectio
   nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor);
   
   // convert the selection ranges into "promoted" selection ranges:
   // this basically just expands the range to include the immediate
   // block parent, and then further expands to include any ancestors
   // whose children are all in the range
   
   nsTArray<nsRefPtr<nsRange>> arrayOfRanges;
-  res = GetPromotedRanges(aSelection, arrayOfRanges, EditAction::indent);
-  NS_ENSURE_SUCCESS(res, res);
+  GetPromotedRanges(*aSelection, arrayOfRanges, EditAction::indent);
   
   // use these ranges to contruct a list of nodes to act on.
   nsTArray<nsCOMPtr<nsINode>> array;
   res = GetNodesForOperation(arrayOfRanges, array, EditAction::indent);
   NS_ENSURE_SUCCESS(res, res);                                 
                                      
   nsCOMArray<nsIDOMNode> arrayOfNodes;
   for (auto& node : array) {
@@ -5731,53 +5728,42 @@ nsHTMLEditRules::GetPromotedPoint(RulesE
     NS_ENSURE_TRUE(mHTMLEditor, /* void */);
     nearNode = mHTMLEditor->GetNextHTMLNode(node, offset, true);
   }
   *outNode = node->AsDOMNode();
   *outOffset = offset;
 }
 
 
-///////////////////////////////////////////////////////////////////////////
-// GetPromotedRanges: run all the selection range endpoint through 
+///////////////////////////////////////////////////////////////////////////////
+// GetPromotedRanges: Run all the selection range endpoint through
 //                    GetPromotedPoint()
-//                       
-nsresult 
-nsHTMLEditRules::GetPromotedRanges(Selection* inSelection, 
-                                   nsTArray<nsRefPtr<nsRange>>& outArrayOfRanges, 
+//
+void
+nsHTMLEditRules::GetPromotedRanges(Selection& aSelection,
+                                   nsTArray<nsRefPtr<nsRange>>& outArrayOfRanges,
                                    EditAction inOperationType)
 {
-  NS_ENSURE_TRUE(inSelection, NS_ERROR_NULL_POINTER);
-
-  int32_t rangeCount;
-  nsresult res = inSelection->GetRangeCount(&rangeCount);
-  NS_ENSURE_SUCCESS(res, res);
-  
-  int32_t i;
-  nsRefPtr<nsRange> selectionRange;
-  nsRefPtr<nsRange> opRange;
-
-  for (i = 0; i < rangeCount; i++)
-  {
-    selectionRange = inSelection->GetRangeAt(i);
-    NS_ENSURE_STATE(selectionRange);
-
-    // clone range so we don't muck with actual selection ranges
-    opRange = selectionRange->CloneRange();
-
-    // make a new adjusted range to represent the appropriate block content.
-    // The basic idea is to push out the range endpoints
-    // to truly enclose the blocks that we will affect.
-    // This call alters opRange.
+  uint32_t rangeCount = aSelection.RangeCount();
+
+  for (uint32_t i = 0; i < rangeCount; i++) {
+    nsRefPtr<nsRange> selectionRange = aSelection.GetRangeAt(i);
+    MOZ_ASSERT(selectionRange);
+
+    // Clone range so we don't muck with actual selection ranges
+    nsRefPtr<nsRange> opRange = selectionRange->CloneRange();
+
+    // Make a new adjusted range to represent the appropriate block content.
+    // The basic idea is to push out the range endpoints to truly enclose the
+    // blocks that we will affect.  This call alters opRange.
     PromoteRange(*opRange, inOperationType);
-      
-    // stuff new opRange into array
+
+    // Stuff new opRange into array
     outArrayOfRanges.AppendElement(opRange);
   }
-  return res;
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
 // PromoteRange: Expand a range to include any parents for which all editable
 //               children are already in range.
 //
 void
@@ -6407,18 +6393,17 @@ nsHTMLEditRules::GetNodesFromSelection(S
                                        nsCOMArray<nsIDOMNode>& arrayOfNodes,
                                        bool dontTouchContent)
 {
   NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
   nsresult res;
   
   // promote selection ranges
   nsTArray<nsRefPtr<nsRange>> arrayOfRanges;
-  res = GetPromotedRanges(selection, arrayOfRanges, operation);
-  NS_ENSURE_SUCCESS(res, res);
+  GetPromotedRanges(*selection, arrayOfRanges, operation);
   
   // 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));
   }
@@ -9033,19 +9018,18 @@ nsHTMLEditRules::WillAbsolutePosition(Se
   nsAutoSelectionReset selectionResetter(aSelection, mHTMLEditor);
   
   // convert the selection ranges into "promoted" selection ranges:
   // this basically just expands the range to include the immediate
   // block parent, and then further expands to include any ancestors
   // whose children are all in the range
   
   nsTArray<nsRefPtr<nsRange>> arrayOfRanges;
-  res = GetPromotedRanges(aSelection, arrayOfRanges,
-                          EditAction::setAbsolutePosition);
-  NS_ENSURE_SUCCESS(res, res);
+  GetPromotedRanges(*aSelection, arrayOfRanges,
+                    EditAction::setAbsolutePosition);
   
   // use these ranges to contruct a list of nodes to act on.
   nsTArray<nsCOMPtr<nsINode>> array;
   res = GetNodesForOperation(arrayOfRanges, array,
                              EditAction::setAbsolutePosition);
   NS_ENSURE_SUCCESS(res, res);                                 
                                      
   nsCOMArray<nsIDOMNode> arrayOfNodes;
--- a/editor/libeditor/nsHTMLEditRules.h
+++ b/editor/libeditor/nsHTMLEditRules.h
@@ -267,19 +267,19 @@ protected:
                                nsCOMPtr<nsIDOMNode> *outBRNode, int32_t aOffset=0);
   nsresult ExpandSelectionForDeletion(mozilla::dom::Selection* aSelection);
   bool IsFirstNode(nsIDOMNode *aNode);
   bool IsLastNode(nsIDOMNode *aNode);
   nsresult NormalizeSelection(mozilla::dom::Selection* aSelection);
   void GetPromotedPoint(RulesEndpoint aWhere, nsIDOMNode* aNode,
                         int32_t aOffset, EditAction actionID,
                         nsCOMPtr<nsIDOMNode>* outNode, int32_t* outOffset);
-  nsresult GetPromotedRanges(mozilla::dom::Selection* aSelection, 
-                             nsTArray<nsRefPtr<nsRange>>& outArrayOfRanges,
-                             EditAction inOperationType);
+  void GetPromotedRanges(mozilla::dom::Selection& aSelection, 
+                         nsTArray<nsRefPtr<nsRange>>& outArrayOfRanges,
+                         EditAction inOperationType);
   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);