Bug 1563450: rename `Selection::RemoveItem` to `Selection::RemoveRangeInternal`. r=smaug
authorMirko Brodesser <mbrodesser@mozilla.com>
Wed, 03 Jul 2019 15:04:47 +0200
changeset 544180 7912ff94233b7a81cbfae45ee35a9629be093ba0
parent 544179 6f2abecd04b80d3f31b5c4666d8f7bc1fa9d961e
child 544181 9342b4491a2db3dd11354fc1016e66486f923046
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1563450
milestone69.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 1563450: rename `Selection::RemoveItem` to `Selection::RemoveRangeInternal`. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D36882
dom/base/Selection.cpp
dom/base/Selection.h
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -1122,43 +1122,41 @@ nsresult Selection::AddItemInternal(nsRa
   for (uint32_t i = 0; i < temp.Length(); ++i) {
     temp[i].mRange->SetSelection(this);
   }
 
   *aOutIndex = startIndex + insertionPoint;
   return NS_OK;
 }
 
-nsresult Selection::RemoveItem(nsRange* aItem) {
-  if (!aItem) return NS_ERROR_NULL_POINTER;
-
+nsresult Selection::RemoveRangeInternal(nsRange& aRange) {
   // Find the range's index & remove it. We could use FindInsertionPoint to
   // get O(log n) time, but that requires many expensive DOM comparisons.
   // For even several thousand items, this is probably faster because the
   // comparisons are so fast.
   int32_t idx = -1;
   uint32_t i;
   for (i = 0; i < mRanges.Length(); i++) {
-    if (mRanges[i].mRange == aItem) {
+    if (mRanges[i].mRange == &aRange) {
       idx = (int32_t)i;
       break;
     }
   }
   if (idx < 0) return NS_ERROR_DOM_NOT_FOUND_ERR;
 
   mRanges.RemoveElementAt(idx);
-  aItem->SetSelection(nullptr);
+  aRange.SetSelection(nullptr);
   return NS_OK;
 }
 
 nsresult Selection::RemoveCollapsedRanges() {
   uint32_t i = 0;
   while (i < mRanges.Length()) {
     if (mRanges[i].mRange->Collapsed()) {
-      nsresult rv = RemoveItem(mRanges[i].mRange);
+      nsresult rv = RemoveRangeInternal(*mRanges[i].mRange);
       NS_ENSURE_SUCCESS(rv, rv);
     } else {
       ++i;
     }
   }
   return NS_OK;
 }
 
@@ -2079,17 +2077,17 @@ void Selection::AddRangeAndSelectFramesA
 //    another range on the frame (bug 346185).
 //
 //    We therefore find any ranges that intersect the same nodes as the range
 //    being removed, and cause them to set the selected bits back on their
 //    selected frames after we've cleared the bit from ours.
 
 void Selection::RemoveRangeAndUnselectFramesAndNotifyListeners(
     nsRange& aRange, ErrorResult& aRv) {
-  nsresult rv = RemoveItem(&aRange);
+  nsresult rv = RemoveRangeInternal(aRange);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return;
   }
 
   nsINode* beginNode = aRange.GetStartContainer();
   nsINode* endNode = aRange.GetEndContainer();
 
@@ -2385,17 +2383,17 @@ nsRange* Selection::GetRangeAt(int32_t a
 /*
 utility function
 */
 nsresult Selection::SetAnchorFocusToRange(nsRange* aRange) {
   NS_ENSURE_STATE(mAnchorFocusRange);
 
   bool collapsed = IsCollapsed();
 
-  nsresult res = RemoveItem(mAnchorFocusRange);
+  nsresult res = RemoveRangeInternal(*mAnchorFocusRange);
   if (NS_FAILED(res)) return res;
 
   int32_t aOutIndex = -1;
   res = AddRangesForSelectableNodes(aRange, &aOutIndex, !collapsed);
   if (NS_FAILED(res)) return res;
   SetAnchorFocusRange(aOutIndex);
 
   return NS_OK;
--- a/dom/base/Selection.h
+++ b/dom/base/Selection.h
@@ -168,17 +168,17 @@ class Selection final : public nsSupport
   /**
    * Adds aRange to this Selection.  If mUserInitiated is true,
    * then aRange is first scanned for -moz-user-select:none nodes and split up
    * into multiple ranges to exclude those before adding the resulting ranges
    * to this Selection.
    */
   nsresult AddRangesForSelectableNodes(nsRange* aRange, int32_t* aOutIndex,
                                        bool aNoStartSelect = false);
-  nsresult RemoveItem(nsRange* aRange);
+  nsresult RemoveRangeInternal(nsRange& aRange);
 
  public:
   nsresult RemoveCollapsedRanges();
   nsresult Clear(nsPresContext* aPresContext);
   nsresult Collapse(nsINode* aContainer, int32_t aOffset) {
     if (!aContainer) {
       return NS_ERROR_INVALID_ARG;
     }