Bug 1391978 - Part 1. Replace nsISelection::GetRangeCount with Selection::RangeCount. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Mon, 28 Aug 2017 14:52:25 +0900
changeset 426940 fe569af2097b960d3657951460024ace04493cec
parent 426939 18bf4e0a7ec742c46b0336b576b92559e8c8005b
child 426941 876b85ec5e06d35cf9c42cc79b154439352b0301
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1391978
milestone57.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 1391978 - Part 1. Replace nsISelection::GetRangeCount with Selection::RangeCount. r=masayuki I would like to remove more dependency of old nsISelection interface from editor if possible. So we can replace nsISelection::GetRangeCount with Selection::RangeCount. MozReview-Commit-ID: 2Mh5ceQI2om
editor/composer/nsEditorSpellCheck.cpp
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorEventListener.cpp
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditorEventListener.cpp
editor/libeditor/HTMLTableEditor.cpp
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditorDataTransfer.cpp
editor/txtsvc/nsTextServicesDocument.cpp
--- a/editor/composer/nsEditorSpellCheck.cpp
+++ b/editor/composer/nsEditorSpellCheck.cpp
@@ -355,22 +355,17 @@ nsEditorSpellCheck::InitSpellChecker(nsI
 
     nsCOMPtr<nsISelection> domSelection;
     aEditor->GetSelection(getter_AddRefs(domSelection));
     if (NS_WARN_IF(!domSelection)) {
       return NS_ERROR_FAILURE;
     }
     RefPtr<Selection> selection = domSelection->AsSelection();
 
-    int32_t count = 0;
-
-    rv = selection->GetRangeCount(&count);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (count > 0) {
+    if (selection->RangeCount()) {
       RefPtr<nsRange> range = selection->GetRangeAt(0);
       NS_ENSURE_STATE(range);
 
       bool collapsed = false;
       rv = range->GetCollapsed(&collapsed);
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (!collapsed) {
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -4899,19 +4899,17 @@ EditorBase::InitializeSelection(nsIDOMEv
   if (selectionRootContent->GetParent()) {
     selection->SetAncestorLimiter(selectionRootContent);
   } else {
     selection->SetAncestorLimiter(nullptr);
   }
 
   // XXX What case needs this?
   if (isTargetDoc) {
-    int32_t rangeCount;
-    selection->GetRangeCount(&rangeCount);
-    if (!rangeCount) {
+    if (!selection->RangeCount()) {
       BeginningOfDocument();
     }
   }
 
   // If there is composition when this is called, we may need to restore IME
   // selection because if the editor is reframed, this already forgot IME
   // selection and the transaction.
   if (mComposition && !mIMETextNode && mIMETextLength) {
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -1018,21 +1018,18 @@ EditorEventListener::CanDrop(nsIDOMDragE
   if (NS_FAILED(rv) || !parent) {
     return false;
   }
 
   int32_t offset = 0;
   rv = aEvent->GetRangeOffset(&offset);
   NS_ENSURE_SUCCESS(rv, false);
 
-  int32_t rangeCount;
-  rv = selection->GetRangeCount(&rangeCount);
-  NS_ENSURE_SUCCESS(rv, false);
-
-  for (int32_t i = 0; i < rangeCount; i++) {
+  uint32_t rangeCount = selection->RangeCount();
+  for (uint32_t i = 0; i < rangeCount; i++) {
     RefPtr<nsRange> range = selection->GetRangeAt(i);
     if (!range) {
       // Don't bail yet, iterate through them all
       continue;
     }
 
     bool inRange = true;
     range->IsPointInRange(parent, offset, &inRange);
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -5307,32 +5307,28 @@ HTMLEditRules::NormalizeSelection(Select
 {
   NS_ENSURE_TRUE(inSelection, NS_ERROR_NULL_POINTER);
 
   // don't need to touch collapsed selections
   if (inSelection->Collapsed()) {
     return NS_OK;
   }
 
-  int32_t rangeCount;
-  nsresult rv = inSelection->GetRangeCount(&rangeCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
   // we don't need to mess with cell selections, and we assume multirange selections are those.
-  if (rangeCount != 1) {
+  if (inSelection->RangeCount() != 1) {
     return NS_OK;
   }
 
   RefPtr<nsRange> range = inSelection->GetRangeAt(0);
   NS_ENSURE_TRUE(range, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMNode> startNode, endNode;
   uint32_t startOffset, endOffset;
   nsCOMPtr<nsIDOMNode> newStartNode, newEndNode;
 
-  rv = range->GetStartContainer(getter_AddRefs(startNode));
+  nsresult rv = range->GetStartContainer(getter_AddRefs(startNode));
   NS_ENSURE_SUCCESS(rv, rv);
   rv = range->GetStartOffset(&startOffset);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = range->GetEndContainer(getter_AddRefs(endNode));
   NS_ENSURE_SUCCESS(rv, rv);
   rv = range->GetEndOffset(&endOffset);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/editor/libeditor/HTMLEditorEventListener.cpp
+++ b/editor/libeditor/HTMLEditorEventListener.cpp
@@ -126,21 +126,19 @@ HTMLEditorEventListener::MouseDown(nsIDO
 
     int32_t offset = 0;
     rv = aMouseEvent->GetRangeOffset(&offset);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // Detect if mouse point is within current selection for context click
     bool nodeIsInSelection = false;
     if (isContextClick && !selection->Collapsed()) {
-      int32_t rangeCount;
-      rv = selection->GetRangeCount(&rangeCount);
-      NS_ENSURE_SUCCESS(rv, rv);
+      uint32_t rangeCount = selection->RangeCount();
 
-      for (int32_t i = 0; i < rangeCount; i++) {
+      for (uint32_t i = 0; i < rangeCount; i++) {
         RefPtr<nsRange> range = selection->GetRangeAt(i);
         if (!range) {
           // Don't bail yet, iterate through them all
           continue;
         }
 
         range->IsPointInRange(parent, offset, &nodeIsInSelection);
 
--- a/editor/libeditor/HTMLTableEditor.cpp
+++ b/editor/libeditor/HTMLTableEditor.cpp
@@ -759,21 +759,17 @@ HTMLEditor::DeleteTableCell(int32_t aNum
   // Prevent rules testing until we're done
   AutoRules beginRulesSniffing(this, EditAction::deleteNode, nsIEditor::eNext);
 
   nsCOMPtr<nsIDOMElement> firstCell;
   nsCOMPtr<nsIDOMRange> range;
   rv = GetFirstSelectedCell(getter_AddRefs(range), getter_AddRefs(firstCell));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  int32_t rangeCount;
-  rv = selection->GetRangeCount(&rangeCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (firstCell && rangeCount > 1) {
+  if (firstCell && selection->RangeCount() > 1) {
     // When > 1 selected cell,
     //  ignore aNumber and use selected cells
     cell = firstCell;
 
     int32_t rowCount, colCount;
     rv = GetTableSize(table, &rowCount, &colCount);
     NS_ENSURE_SUCCESS(rv, rv);
 
@@ -1033,19 +1029,17 @@ HTMLEditor::DeleteTableColumn(int32_t aN
   AutoRules beginRulesSniffing(this, EditAction::deleteNode, nsIEditor::eNext);
 
   // Test if deletion is controlled by selected cells
   nsCOMPtr<nsIDOMElement> firstCell;
   nsCOMPtr<nsIDOMRange> range;
   rv = GetFirstSelectedCell(getter_AddRefs(range), getter_AddRefs(firstCell));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  int32_t rangeCount;
-  rv = selection->GetRangeCount(&rangeCount);
-  NS_ENSURE_SUCCESS(rv, rv);
+  uint32_t rangeCount = selection->RangeCount();
 
   if (firstCell && rangeCount > 1) {
     // Fetch indexes again - may be different for selected cells
     rv = GetCellIndexes(firstCell, &startRowIndex, &startColIndex);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   //We control selection resetting after the insert...
   AutoSelectionSetterAfterTableEdit setCaret(*this, table, startRowIndex,
@@ -1198,19 +1192,17 @@ HTMLEditor::DeleteTableRow(int32_t aNumb
   // Prevent rules testing until we're done
   AutoRules beginRulesSniffing(this, EditAction::deleteNode, nsIEditor::eNext);
 
   nsCOMPtr<nsIDOMElement> firstCell;
   nsCOMPtr<nsIDOMRange> range;
   rv = GetFirstSelectedCell(getter_AddRefs(range), getter_AddRefs(firstCell));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  int32_t rangeCount;
-  rv = selection->GetRangeCount(&rangeCount);
-  NS_ENSURE_SUCCESS(rv, rv);
+  uint32_t rangeCount = selection->RangeCount();
 
   if (firstCell && rangeCount > 1) {
     // Fetch indexes again - may be different for selected cells
     rv = GetCellIndexes(firstCell, &startRowIndex, &startColIndex);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   //We control selection resetting after the insert...
@@ -2211,22 +2203,20 @@ HTMLEditor::JoinTableCells(bool aMergeNo
         rv = DeleteNode(node);
         NS_ENSURE_SUCCESS(rv, rv);
       }
     }
     // Cleanup selection: remove ranges where cells were deleted
     RefPtr<Selection> selection = GetSelection();
     NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
 
-    int32_t rangeCount;
-    rv = selection->GetRangeCount(&rangeCount);
-    NS_ENSURE_SUCCESS(rv, rv);
+    uint32_t rangeCount = selection->RangeCount();
 
     RefPtr<nsRange> range;
-    for (int32_t i = 0; i < rangeCount; i++) {
+    for (uint32_t i = 0; i < rangeCount; i++) {
       range = selection->GetRangeAt(i);
       NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
 
       nsCOMPtr<nsIDOMElement> deletedCell;
       GetCellFromRange(range, getter_AddRefs(deletedCell));
       if (!deletedCell) {
         selection->RemoveRange(range);
         rangeCount--;
@@ -3203,18 +3193,17 @@ HTMLEditor::GetSelectedOrParentTableElem
                                      getter_AddRefs(tableOrCellElement));
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_NAMED_LITERAL_STRING(tdName, "td");
 
   if (tableOrCellElement) {
       // Each cell is in its own selection range,
       //  so count signals multiple-cell selection
-      rv = selection->GetRangeCount(aSelectedCount);
-      NS_ENSURE_SUCCESS(rv, rv);
+      *aSelectedCount = selection->RangeCount();
       aTagName = tdName;
   } else {
     nsCOMPtr<nsIDOMNode> anchorNode;
     rv = selection->GetAnchorNode(getter_AddRefs(anchorNode));
     if (NS_FAILED(rv)) {
       return rv;
     }
     NS_ENSURE_TRUE(anchorNode, NS_ERROR_FAILURE);
@@ -3237,18 +3226,17 @@ HTMLEditor::GetSelectedOrParentTableElem
       } else {
         nsCOMPtr<nsIAtom> atom = EditorBase::GetTag(selectedNode);
 
         if (atom == nsGkAtoms::td) {
           tableOrCellElement = do_QueryInterface(selectedNode);
           aTagName = tdName;
           // Each cell is in its own selection range,
           //  so count signals multiple-cell selection
-          rv = selection->GetRangeCount(aSelectedCount);
-          NS_ENSURE_SUCCESS(rv, rv);
+          *aSelectedCount = selection->RangeCount();
         } else if (atom == nsGkAtoms::table) {
           tableOrCellElement = do_QueryInterface(selectedNode);
           aTagName.AssignLiteral("table");
           *aSelectedCount = 1;
         } else if (atom == nsGkAtoms::tr) {
           tableOrCellElement = do_QueryInterface(selectedNode);
           aTagName.AssignLiteral("tr");
           *aSelectedCount = 1;
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -127,20 +127,17 @@ TextEditRules::Init(TextEditor* aTextEdi
 
   // Put in a magic br if needed. This method handles null selection,
   // which should never happen anyway
   nsresult rv = CreateBogusNodeIfNeeded(selection);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // If the selection hasn't been set up yet, set it up collapsed to the end of
   // our editable content.
-  int32_t rangeCount;
-  rv = selection->GetRangeCount(&rangeCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-  if (!rangeCount) {
+  if (!selection->RangeCount()) {
     rv = mTextEditor->CollapseSelectionToEnd(selection);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   if (IsPlaintextEditor()) {
     // ensure trailing br node
     rv = CreateTrailingBRIfNeeded();
     NS_ENSURE_SUCCESS(rv, rv);
--- a/editor/libeditor/TextEditorDataTransfer.cpp
+++ b/editor/libeditor/TextEditorDataTransfer.cpp
@@ -231,21 +231,19 @@ TextEditor::InsertFromDrop(nsIDOMEvent* 
 
   // Check if mouse is in the selection
   // if so, jump through some hoops to determine if mouse is over selection (bail)
   // and whether user wants to copy selection or delete it
   if (!isCollapsed) {
     // We never have to delete if selection is already collapsed
     bool cursorIsInSelection = false;
 
-    int32_t rangeCount;
-    rv = selection->GetRangeCount(&rangeCount);
-    NS_ENSURE_SUCCESS(rv, rv);
+    uint32_t rangeCount = selection->RangeCount();
 
-    for (int32_t j = 0; j < rangeCount; j++) {
+    for (uint32_t j = 0; j < rangeCount; j++) {
       RefPtr<nsRange> range = selection->GetRangeAt(j);
       if (!range) {
         // don't bail yet, iterate through them all
         continue;
       }
 
       rv = range->IsPointInRange(newSelectionParent, newSelectionOffset, &cursorIsInSelection);
       if (cursorIsInSelection) {
--- a/editor/txtsvc/nsTextServicesDocument.cpp
+++ b/editor/txtsvc/nsTextServicesDocument.cpp
@@ -686,24 +686,17 @@ nsTextServicesDocument::LastSelectedBloc
   }
 
   // If we get here, we have an uncollapsed selection!
   // Look backwards through each range in the selection till you
   // find the first text node. If you find one, find the
   // beginning of its text block, and make it the current
   // block.
 
-  int32_t rangeCount;
-  rv = selection->GetRangeCount(&rangeCount);
-
-  if (NS_FAILED(rv)) {
-    UNLOCK_DOC(this);
-    return rv;
-  }
-
+  int32_t rangeCount = static_cast<int32_t>(selection->RangeCount());
   NS_ASSERTION(rangeCount > 0, "Unexpected range count!");
 
   if (rangeCount <= 0) {
     UNLOCK_DOC(this);
     return NS_OK;
   }
 
   // XXX: We may need to add some code here to make sure
@@ -2565,17 +2558,17 @@ nsTextServicesDocument::GetUncollapsedSe
   RefPtr<Selection> selection = domSelection->AsSelection();
 
   // It is assumed that the calling function has made sure that the
   // selection is not collapsed, and that the input params to this
   // method are initialized to some defaults.
 
   nsCOMPtr<nsIDOMNode> startContainer, endContainer;
   int32_t startOffset, endOffset;
-  int32_t rangeCount, tableCount;
+  int32_t tableCount;
   int32_t e1s1 = 0, e1s2 = 0, e2s1 = 0, e2s2 = 0;
 
   OffsetEntry *eStart, *eEnd;
   int32_t eStartOffset, eEndOffset;
 
   tableCount = mOffsetTable.Length();
 
   // Get pointers to the first and last offset entries
@@ -2587,24 +2580,22 @@ nsTextServicesDocument::GetUncollapsedSe
     eEnd = mOffsetTable[tableCount - 1];
   } else {
     eEnd = eStart;
   }
 
   eStartOffset = eStart->mNodeOffset;
   eEndOffset   = eEnd->mNodeOffset + eEnd->mLength;
 
-  rv = selection->GetRangeCount(&rangeCount);
-
-  NS_ENSURE_SUCCESS(rv, rv);
+  uint32_t rangeCount = selection->RangeCount();
 
   // Find the first range in the selection that intersects
   // the current text block.
 
-  for (int32_t i = 0; i < rangeCount; i++) {
+  for (uint32_t i = 0; i < rangeCount; i++) {
     range = selection->GetRangeAt(i);
     NS_ENSURE_STATE(range);
 
     rv = GetRangeEndPoints(range,
                            getter_AddRefs(startContainer), &startOffset,
                            getter_AddRefs(endContainer), &endOffset);
 
     NS_ENSURE_SUCCESS(rv, rv);