Bug 1457083 - part 6: Get rid of unnecessary Selection argument from all protected/private methods of TextEditRules and HTMLEditRules r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 10 May 2018 15:03:21 +0900
changeset 797733 86a6fc9fba61cb12fb33b3418ff6395b5796ef46
parent 797732 24497df2e459a743efbe7038c2a2fb979988115a
child 797734 3eb1bca421abc6907e9fc486ee11d2b3cd689c99
push id110553
push usermasayuki@d-toybox.com
push dateMon, 21 May 2018 14:13:13 +0000
reviewersm_kato
bugs1457083
milestone62.0a1
Bug 1457083 - part 6: Get rid of unnecessary Selection argument from all protected/private methods of TextEditRules and HTMLEditRules r?m_kato Now, each protected/private method of TextEditRules and HTMLEditRules can retrieve Selection instance safely and quickly. Therefore, their pointer or reference of Selection arguments are not necessary. Therefore, this patch removes them. MozReview-Commit-ID: 1SPmKXmd7kz
editor/libeditor/HTMLEditRules.cpp
editor/libeditor/HTMLEditRules.h
editor/libeditor/TextEditRules.cpp
editor/libeditor/TextEditRules.h
editor/libeditor/TextEditRulesBidi.cpp
--- a/editor/libeditor/HTMLEditRules.cpp
+++ b/editor/libeditor/HTMLEditRules.cpp
@@ -492,17 +492,17 @@ HTMLEditRules::AfterEditInner(EditAction
     PromoteRange(*mDocChangeRange, aAction);
 
     // if we did a ranged deletion or handling backspace key, make sure we have
     // a place to put caret.
     // Note we only want to do this if the overall operation was deletion,
     // not if deletion was done along the way for EditAction::loadHTML, EditAction::insertText, etc.
     // That's why this is here rather than DidDeleteSelection().
     if (aAction == EditAction::deleteSelection && mDidRangedDelete) {
-      nsresult rv = InsertBRIfNeeded(&SelectionRef());
+      nsresult rv = InsertBRIfNeeded();
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
     // add in any needed <br>s, and remove any unneeded ones.
     AdjustSpecialBreaks();
 
@@ -523,17 +523,17 @@ HTMLEditRules::AfterEditInner(EditAction
 
     // attempt to transform any unneeded nbsp's into spaces after doing various operations
     if (aAction == EditAction::insertText ||
         aAction == EditAction::insertIMEText ||
         aAction == EditAction::deleteSelection ||
         aAction == EditAction::insertBreak ||
         aAction == EditAction::htmlPaste ||
         aAction == EditAction::loadHTML) {
-      rv = AdjustWhitespace(&SelectionRef());
+      rv = AdjustWhitespace();
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
 
       // also do this for original selection endpoints.
       NS_ENSURE_STATE(mRangeItem->mStartContainer);
       NS_ENSURE_STATE(mRangeItem->mEndContainer);
       WSRunObject(&HTMLEditorRef(), mRangeItem->mStartContainer,
@@ -543,30 +543,30 @@ HTMLEditRules::AfterEditInner(EditAction
           mRangeItem->mStartOffset != mRangeItem->mEndOffset) {
         WSRunObject(&HTMLEditorRef(), mRangeItem->mEndContainer,
                     mRangeItem->mEndOffset).AdjustWhitespace();
       }
     }
 
     // if we created a new block, make sure selection lands in it
     if (mNewBlock) {
-      rv = PinSelectionToNewBlock(&SelectionRef());
+      rv = PinSelectionToNewBlock();
       NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
         "Failed to pin selection to the new block");
       mNewBlock = nullptr;
     }
 
     // adjust selection for insert text, html paste, and delete actions
     if (aAction == EditAction::insertText ||
         aAction == EditAction::insertIMEText ||
         aAction == EditAction::deleteSelection ||
         aAction == EditAction::insertBreak ||
         aAction == EditAction::htmlPaste ||
         aAction == EditAction::loadHTML) {
-      rv = AdjustSelection(&SelectionRef(), aDirection);
+      rv = AdjustSelection(aDirection);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
     // check for any styles which were removed inappropriately
     if (aAction == EditAction::insertText ||
         aAction == EditAction::insertIMEText ||
@@ -590,24 +590,24 @@ HTMLEditRules::AfterEditInner(EditAction
                       rangeStartOffset,
                       rangeEndContainer,
                       rangeEndOffset);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // detect empty doc
-  rv = CreateBogusNodeIfNeeded(&SelectionRef());
+  rv = CreateBogusNodeIfNeeded();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // adjust selection HINT if needed
   if (!mDidExplicitlySetInterline) {
-    CheckInterlinePosition(SelectionRef());
+    CheckInterlinePosition();
   }
 
   return NS_OK;
 }
 
 nsresult
 HTMLEditRules::WillDoAction(Selection* aSelection,
                             RulesInfo* aInfo,
@@ -663,57 +663,55 @@ HTMLEditRules::WillDoAction(Selection* a
       *aCancel = true;
       return NS_OK;
     }
   }
 
   switch (aInfo->action) {
     case EditAction::insertText:
     case EditAction::insertIMEText:
-      UndefineCaretBidiLevel(&SelectionRef());
-      return WillInsertText(aInfo->action, &SelectionRef(), aCancel, aHandled,
+      UndefineCaretBidiLevel();
+      return WillInsertText(aInfo->action, aCancel, aHandled,
                             aInfo->inString, aInfo->outString,
                             aInfo->maxLength);
     case EditAction::loadHTML:
-      return WillLoadHTML(&SelectionRef(), aCancel);
+      return WillLoadHTML(aCancel);
     case EditAction::insertBreak:
-      UndefineCaretBidiLevel(&SelectionRef());
-      return WillInsertBreak(SelectionRef(), aCancel, aHandled);
+      UndefineCaretBidiLevel();
+      return WillInsertBreak(aCancel, aHandled);
     case EditAction::deleteSelection:
-      return WillDeleteSelection(&SelectionRef(), aInfo->collapsedAction,
-                                 aInfo->stripWrappers, aCancel, aHandled);
+      return WillDeleteSelection(aInfo->collapsedAction, aInfo->stripWrappers,
+                                 aCancel, aHandled);
     case EditAction::makeList:
-      return WillMakeList(&SelectionRef(), aInfo->blockType, aInfo->entireList,
+      return WillMakeList(aInfo->blockType, aInfo->entireList,
                           aInfo->bulletType, aCancel, aHandled);
     case EditAction::indent:
-      return WillIndent(&SelectionRef(), aCancel, aHandled);
+      return WillIndent(aCancel, aHandled);
     case EditAction::outdent:
-      return WillOutdent(SelectionRef(), aCancel, aHandled);
+      return WillOutdent(aCancel, aHandled);
     case EditAction::setAbsolutePosition:
-      return WillAbsolutePosition(SelectionRef(), aCancel, aHandled);
+      return WillAbsolutePosition(aCancel, aHandled);
     case EditAction::removeAbsolutePosition:
-      return WillRemoveAbsolutePosition(&SelectionRef(), aCancel, aHandled);
+      return WillRemoveAbsolutePosition(aCancel, aHandled);
     case EditAction::align:
-      return WillAlign(SelectionRef(), *aInfo->alignType, aCancel, aHandled);
+      return WillAlign(*aInfo->alignType, aCancel, aHandled);
     case EditAction::makeBasicBlock:
-      return WillMakeBasicBlock(SelectionRef(), *aInfo->blockType, aCancel,
-                                aHandled);
+      return WillMakeBasicBlock(*aInfo->blockType, aCancel, aHandled);
     case EditAction::removeList:
-      return WillRemoveList(&SelectionRef(), aInfo->bOrdered,
-                            aCancel, aHandled);
+      return WillRemoveList(aInfo->bOrdered, aCancel, aHandled);
     case EditAction::makeDefListItem:
-      return WillMakeDefListItem(&SelectionRef(), aInfo->blockType,
+      return WillMakeDefListItem(aInfo->blockType,
                                  aInfo->entireList, aCancel, aHandled);
     case EditAction::insertElement:
-      WillInsert(SelectionRef(), aCancel);
+      WillInsert(aCancel);
       return NS_OK;
     case EditAction::decreaseZIndex:
-      return WillRelativeChangeZIndex(&SelectionRef(), -1, aCancel, aHandled);
+      return WillRelativeChangeZIndex(-1, aCancel, aHandled);
     case EditAction::increaseZIndex:
-      return WillRelativeChangeZIndex(&SelectionRef(), 1, aCancel, aHandled);
+      return WillRelativeChangeZIndex(1, aCancel, aHandled);
     default:
       return TextEditRules::WillDoAction(&SelectionRef(), aInfo,
                                          aCancel, aHandled);
   }
 }
 
 nsresult
 HTMLEditRules::DidDoAction(Selection* aSelection,
@@ -726,27 +724,26 @@ HTMLEditRules::DidDoAction(Selection* aS
   if (NS_WARN_IF(!mHTMLEditor)) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   AutoSafeEditorData setData(*this, *mHTMLEditor, *aSelection);
 
   switch (aInfo->action) {
     case EditAction::insertBreak:
-      return DidInsertBreak(&SelectionRef(), aResult);
+      return DidInsertBreak(aResult);
     case EditAction::deleteSelection:
-      return DidDeleteSelection(&SelectionRef(), aInfo->collapsedAction,
-                                aResult);
+      return DidDeleteSelection(aInfo->collapsedAction, aResult);
     case EditAction::makeBasicBlock:
     case EditAction::indent:
     case EditAction::outdent:
     case EditAction::align:
-      return DidMakeBasicBlock(&SelectionRef(), aInfo, aResult);
+      return DidMakeBasicBlock(aInfo, aResult);
     case EditAction::setAbsolutePosition: {
-      nsresult rv = DidMakeBasicBlock(&SelectionRef(), aInfo, aResult);
+      nsresult rv = DidMakeBasicBlock(aInfo, aResult);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
       return DidAbsolutePosition();
     }
     default:
       return TextEditRules::DidDoAction(aSelection, aInfo, aResult);
   }
@@ -943,17 +940,17 @@ HTMLEditRules::GetAlignment(bool* aMixed
              atStartOfSelection.Offset() == static_cast<uint32_t>(rootOffset)) {
     // If we have selected the body, let's look at the first editable node
     nodeToExamine = HTMLEditorRef().GetNextEditableNode(atStartOfSelection);
     if (NS_WARN_IF(!nodeToExamine)) {
       return NS_ERROR_FAILURE;
     }
   } else {
     nsTArray<RefPtr<nsRange>> arrayOfRanges;
-    GetPromotedRanges(SelectionRef(), arrayOfRanges, EditAction::align);
+    GetPromotedRanges(arrayOfRanges, EditAction::align);
 
     // Use these ranges to construct a list of nodes to act on.
     nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
     nsresult rv = GetNodesForOperation(arrayOfRanges, arrayOfNodes,
                                        EditAction::align, TouchContent::no);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
@@ -1089,18 +1086,18 @@ HTMLEditRules::GetIndentState(bool* aCan
   if (NS_WARN_IF(!selection)) {
     return NS_ERROR_FAILURE;
   }
 
   AutoSafeEditorData setData(*this, *mHTMLEditor, *selection);
 
   // contruct a list of nodes to act on.
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-  nsresult rv = GetNodesFromSelection(SelectionRef(), EditAction::indent,
-                                      arrayOfNodes, TouchContent::no);
+  nsresult rv =
+    GetNodesFromSelection(EditAction::indent, arrayOfNodes, TouchContent::no);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // examine nodes in selection for blockquotes or list elements;
   // these we can outdent.  Note that we return true for canOutdent
   // if *any* of the selection is outdentable, rather than all of it.
   bool useCSS = HTMLEditorRef().IsCSSEnabled();
@@ -1320,23 +1317,22 @@ HTMLEditRules::GetFormatString(nsINode* 
     aNode->NodeInfo()->NameAtom()->ToString(outFormat);
   } else {
     outFormat.Truncate();
   }
   return NS_OK;
 }
 
 void
-HTMLEditRules::WillInsert(Selection& aSelection,
-                          bool* aCancel)
+HTMLEditRules::WillInsert(bool* aCancel)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
   MOZ_ASSERT(aCancel);
 
-  TextEditRules::WillInsert(SelectionRef(), aCancel);
+  TextEditRules::WillInsert(aCancel);
 
   // Adjust selection to prevent insertion after a moz-BR.  This next only
   // works for collapsed selections right now, because selection is a pain to
   // work with when not collapsed.  (no good way to extend start or end of
   // selection), so we ignore those types of selections.
   if (!SelectionRef().IsCollapsed()) {
     return;
   }
@@ -1386,27 +1382,25 @@ HTMLEditRules::WillInsert(Selection& aSe
   // exceptions
   if (!IsStyleCachePreservingAction(mTheAction)) {
     ClearCachedStyles();
   }
 }
 
 nsresult
 HTMLEditRules::WillInsertText(EditAction aAction,
-                              Selection* aSelection,
                               bool* aCancel,
                               bool* aHandled,
                               const nsAString* inString,
                               nsAString* outString,
                               int32_t aMaxLength)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (NS_WARN_IF(!aSelection) ||
-      NS_WARN_IF(!aCancel) ||
+  if (NS_WARN_IF(!aCancel) ||
       NS_WARN_IF(!aHandled)) {
     return NS_ERROR_NULL_POINTER;
   }
 
   // initialize out param
   *aCancel = false;
   *aHandled = true;
   // If the selection isn't collapsed, delete it.  Don't delete existing inline
@@ -1415,29 +1409,29 @@ HTMLEditRules::WillInsertText(EditAction
     nsresult rv =
       HTMLEditorRef().DeleteSelectionAsAction(nsIEditor::eNone,
                                               nsIEditor::eNoStrip);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
-  WillInsert(SelectionRef(), aCancel);
+  WillInsert(aCancel);
   // initialize out param
   // we want to ignore result of WillInsert()
   *aCancel = false;
 
   // we need to get the doc
   nsCOMPtr<nsIDocument> doc = HTMLEditorRef().GetDocument();
   if (NS_WARN_IF(!doc)) {
     return NS_ERROR_FAILURE;
   }
 
   // for every property that is set, insert a new inline style node
-  nsresult rv = CreateStyleForInsertText(SelectionRef(), *doc);
+  nsresult rv = CreateStyleForInsertText(*doc);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // get the (collapsed) selection location
   nsRange* firstRange = SelectionRef().GetRangeAt(0);
   if (NS_WARN_IF(!firstRange)) {
     return NS_ERROR_FAILURE;
@@ -1677,22 +1671,23 @@ HTMLEditRules::WillInsertText(EditAction
   rv = mDocChangeRange->CollapseTo(pointToInsert);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::WillLoadHTML(Selection* aSelection,
-                            bool* aCancel)
+HTMLEditRules::WillLoadHTML(bool* aCancel)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  NS_ENSURE_TRUE(aSelection && aCancel, NS_ERROR_NULL_POINTER);
+  if (NS_WARN_IF(!aCancel)) {
+    return NS_ERROR_INVALID_ARG;
+  }
 
   *aCancel = false;
 
   // Delete mBogusNode if it exists. If we really need one,
   // it will be added during post-processing in AfterEditInner().
 
   if (mBogusNode) {
     DebugOnly<nsresult> rv =
@@ -1728,18 +1723,17 @@ HTMLEditRules::CanContainParagraph(Eleme
   }
 
   // XXX Otherwise, Chromium checks the CSS box is a block, but we don't do it
   //     for now.
   return false;
 }
 
 nsresult
-HTMLEditRules::WillInsertBreak(Selection& aSelection,
-                               bool* aCancel,
+HTMLEditRules::WillInsertBreak(bool* aCancel,
                                bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   MOZ_ASSERT(aCancel && aHandled);
   *aCancel = false;
   *aHandled = false;
 
@@ -1748,25 +1742,25 @@ HTMLEditRules::WillInsertBreak(Selection
     nsresult rv =
       HTMLEditorRef().DeleteSelectionAsAction(nsIEditor::eNone,
                                               nsIEditor::eStrip);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
-  WillInsert(SelectionRef(), aCancel);
+  WillInsert(aCancel);
 
   // Initialize out param.  We want to ignore result of WillInsert().
   *aCancel = false;
 
   // Split any mailcites in the way.  Should we abort this if we encounter
   // table cell boundaries?
   if (IsMailEditor()) {
-    nsresult rv = SplitMailCites(&SelectionRef(), aHandled);
+    nsresult rv = SplitMailCites(aHandled);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     if (*aHandled) {
       return NS_OK;
     }
   }
 
@@ -1832,30 +1826,29 @@ HTMLEditRules::WillInsertBreak(Selection
          blockAncestor = HTMLEditor::GetBlockNodeParent(blockAncestor, host)) {
       insertBRElement = !CanContainParagraph(*blockAncestor);
     }
   }
 
   // If we cannot insert a <p>/<div> element at the selection, we should insert
   // a <br> element instead.
   if (insertBRElement) {
-    nsresult rv = InsertBRElement(SelectionRef(), atStartOfSelection);
+    nsresult rv = InsertBRElement(atStartOfSelection);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     *aHandled = true;
     return NS_OK;
   }
 
   if (host == blockParent && separator != ParagraphSeparator::br) {
     // Insert a new block first
     MOZ_ASSERT(separator == ParagraphSeparator::div ||
                separator == ParagraphSeparator::p);
-    nsresult rv = MakeBasicBlock(SelectionRef(),
-                                 ParagraphSeparatorElement(separator));
+    nsresult rv = MakeBasicBlock(ParagraphSeparatorElement(separator));
     // We warn on failure, but don't handle it, because it might be harmless.
     // Instead we just check that a new block was actually created.
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                          "HTMLEditRules::MakeBasicBlock() failed");
 
     firstRange = SelectionRef().GetRangeAt(0);
     if (NS_WARN_IF(!firstRange)) {
       return NS_ERROR_FAILURE;
@@ -1869,17 +1862,17 @@ HTMLEditRules::WillInsertBreak(Selection
 
     blockParent =
       HTMLEditor::GetBlock(*atStartOfSelection.GetContainer(), host);
     if (NS_WARN_IF(!blockParent)) {
       return NS_ERROR_UNEXPECTED;
     }
     if (NS_WARN_IF(blockParent == host)) {
       // Didn't create a new block for some reason, fall back to <br>
-      rv = InsertBRElement(SelectionRef(), atStartOfSelection);
+      rv = InsertBRElement(atStartOfSelection);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
       *aHandled = true;
       return NS_OK;
     }
     // Now, mNewBlock is last created block element for wrapping inline
     // elements around the caret position and AfterEditInner() will move
@@ -1904,27 +1897,25 @@ HTMLEditRules::WillInsertBreak(Selection
                                                      endOfBlockParent);
     if (NS_WARN_IF(!brElement)) {
       return NS_ERROR_FAILURE;
     }
   }
 
   nsCOMPtr<Element> listItem = IsInListItem(blockParent);
   if (listItem && listItem != host) {
-    ReturnInListItem(SelectionRef(),
-                     *listItem, *atStartOfSelection.GetContainer(),
+    ReturnInListItem(*listItem, *atStartOfSelection.GetContainer(),
                      atStartOfSelection.Offset());
     *aHandled = true;
     return NS_OK;
   }
 
   if (HTMLEditUtils::IsHeader(*blockParent)) {
     // Headers: close (or split) header
-    ReturnInHeader(SelectionRef(),
-                   *blockParent, *atStartOfSelection.GetContainer(),
+    ReturnInHeader(*blockParent, *atStartOfSelection.GetContainer(),
                    atStartOfSelection.Offset());
     *aHandled = true;
     return NS_OK;
   }
 
   // XXX Ideally, we should take same behavior with both <p> container and
   //     <div> container.  However, we are still using <br> as default
   //     paragraph separator (non-standard) and we've split only <p> container
@@ -1933,17 +1924,17 @@ HTMLEditRules::WillInsertBreak(Selection
   //     paragraph separator is <br>.  Otherwise, take consistent behavior
   //     between <p> container and <div> container.
   if ((separator == ParagraphSeparator::br &&
        blockParent->IsHTMLElement(nsGkAtoms::p)) ||
       (separator != ParagraphSeparator::br &&
        blockParent->IsAnyOfHTMLElements(nsGkAtoms::p, nsGkAtoms::div))) {
     AutoEditorDOMPointChildInvalidator lockOffset(atStartOfSelection);
     // Paragraphs: special rules to look for <br>s
-    EditActionResult result = ReturnInParagraph(SelectionRef(), *blockParent);
+    EditActionResult result = ReturnInParagraph(*blockParent);
     if (NS_WARN_IF(result.Failed())) {
       return result.Rv();
     }
     *aHandled = result.Handled();
     *aCancel = result.Canceled();
     if (result.Handled()) {
       // Now, atStartOfSelection may be invalid because the left paragraph
       // may have less children than its offset.  For avoiding warnings of
@@ -1954,27 +1945,26 @@ HTMLEditRules::WillInsertBreak(Selection
     // Fall through, if ReturnInParagraph() didn't handle it.
     MOZ_ASSERT(!*aCancel, "ReturnInParagraph canceled this edit action, "
                           "WillInsertBreak() needs to handle such case");
   }
 
   // If nobody handles this edit action, let's insert new <br> at the selection.
   MOZ_ASSERT(!*aHandled, "Reached last resort of WillInsertBreak() "
                          "after the edit action is handled");
-  nsresult rv = InsertBRElement(SelectionRef(), atStartOfSelection);
+  nsresult rv = InsertBRElement(atStartOfSelection);
   *aHandled = true;
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::InsertBRElement(Selection& aSelection,
-                               const EditorDOMPoint& aPointToBreak)
+HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   if (NS_WARN_IF(!aPointToBreak.IsSet())) {
     return NS_ERROR_INVALID_ARG;
   }
 
   bool brElementIsAfterBlock = false;
@@ -2101,29 +2091,27 @@ HTMLEditRules::InsertBRElement(Selection
   SelectionRef().Collapse(afterBRElement, error);
   if (NS_WARN_IF(error.Failed())) {
     return error.StealNSResult();
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::DidInsertBreak(Selection* aSelection,
-                              nsresult aResult)
+HTMLEditRules::DidInsertBreak(nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::SplitMailCites(Selection* aSelection,
-                              bool* aHandled)
+HTMLEditRules::SplitMailCites(bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (NS_WARN_IF(!aSelection) || NS_WARN_IF(!aHandled)) {
+  if (NS_WARN_IF(!aHandled)) {
     return NS_ERROR_INVALID_ARG;
   }
 
   EditorRawDOMPoint pointToSplit(EditorBase::GetStartPoint(&SelectionRef()));
   if (NS_WARN_IF(!pointToSplit.IsSet())) {
     return NS_ERROR_FAILURE;
   }
 
@@ -2299,34 +2287,34 @@ HTMLEditRules::SplitMailCites(Selection*
   }
 
   *aHandled = true;
   return NS_OK;
 }
 
 
 nsresult
-HTMLEditRules::WillDeleteSelection(Selection* aSelection,
-                                   nsIEditor::EDirection aAction,
+HTMLEditRules::WillDeleteSelection(nsIEditor::EDirection aAction,
                                    nsIEditor::EStripWrappers aStripWrappers,
                                    bool* aCancel,
                                    bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
   MOZ_ASSERT(aStripWrappers == nsIEditor::eStrip ||
              aStripWrappers == nsIEditor::eNoStrip);
 
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
   }
   // Initialize out params
   *aCancel = false;
   *aHandled = false;
 
-  // Remember that we did a selection deletion.  Used by CreateStyleForInsertText()
+  // Remember that we did a selection deletion.  Used by
+  // CreateStyleForInsertText()
   mDidDeleteSelection = true;
 
   // If there is only bogus content, cancel the operation
   if (mBogusNode) {
     *aCancel = true;
     return NS_OK;
   }
 
@@ -2365,28 +2353,26 @@ HTMLEditRules::WillDeleteSelection(Selec
   int32_t startOffset = firstRange->StartOffset();
 
   if (bCollapsed) {
     // If we are inside an empty block, delete it.
     RefPtr<Element> host = HTMLEditorRef().GetActiveEditingHost();
     if (NS_WARN_IF(!host)) {
       return NS_ERROR_FAILURE;
     }
-    rv = CheckForEmptyBlock(startNode, host, &SelectionRef(),
-                            aAction, aHandled);
+    rv = CheckForEmptyBlock(startNode, host, aAction, aHandled);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     if (*aHandled) {
       return NS_OK;
     }
 
     // Test for distance between caret and text that will be deleted
-    rv = CheckBidiLevelForDeletion(&SelectionRef(),
-                                   EditorRawDOMPoint(startNode, startOffset),
+    rv = CheckBidiLevelForDeletion(EditorRawDOMPoint(startNode, startOffset),
                                    aAction, aCancel);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     if (*aCancel) {
       return NS_OK;
     }
 
@@ -2447,17 +2433,17 @@ HTMLEditRules::WillDeleteSelection(Selec
           return rv;
         }
       } else {
         rv = wsObj.DeleteWSBackward();
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       }
-      rv = InsertBRIfNeeded(&SelectionRef());
+      rv = InsertBRIfNeeded();
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
       return NS_OK;
     }
 
     if (wsType == WSType::text) {
       // Found normal text to delete.
@@ -2516,17 +2502,17 @@ HTMLEditRules::WillDeleteSelection(Selec
       //     text nodes when removing the first character of the non-empty
       //     text node.  Chromium removes only selected empty text node and
       //     following empty text nodes and the first character of the
       //     non-empty text node.  For now, we should keep our traditional
       //     behavior same as Chromium for backward compatibility.
 
       DeleteNodeIfCollapsedText(nodeAsText);
 
-      rv = InsertBRIfNeeded(&SelectionRef());
+      rv = InsertBRIfNeeded();
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
 
       // Remember that we did a ranged delete for the benefit of
       // AfterEditInner().
       mDidRangedDelete = true;
 
@@ -2537,18 +2523,17 @@ HTMLEditRules::WillDeleteSelection(Selec
         visNode->IsHTMLElement(nsGkAtoms::hr)) {
       // Short circuit for invisible breaks.  delete them and recurse.
       if (visNode->IsHTMLElement(nsGkAtoms::br) &&
           !HTMLEditorRef().IsVisibleBRElement(visNode)) {
         rv = HTMLEditorRef().DeleteNodeWithTransaction(*visNode);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
-        rv = WillDeleteSelection(&SelectionRef(), aAction, aStripWrappers,
-                                 aCancel, aHandled);
+        rv = WillDeleteSelection(aAction, aStripWrappers, aCancel, aHandled);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
         return NS_OK;
       }
 
       // Special handling for backspace when positioned after <hr>
       if (aAction == nsIEditor::ePrevious &&
@@ -2670,17 +2655,17 @@ HTMLEditRules::WillDeleteSelection(Selec
         }
         // Fix up selection
         ErrorResult error;
         SelectionRef().Collapse(pt, error);
         if (NS_WARN_IF(error.Failed())) {
           return error.StealNSResult();
         }
       }
-      rv = InsertBRIfNeeded(&SelectionRef());
+      rv = InsertBRIfNeeded();
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
       return NS_OK;
     }
 
     if (wsType == WSType::otherBlock) {
       // Make sure it's not a table element.  If so, cancel the operation
@@ -2783,18 +2768,17 @@ HTMLEditRules::WillDeleteSelection(Selec
       // node of the block.
       if (!*aHandled && !*aCancel && leafNode != startNode) {
         int32_t offset =
           aAction == nsIEditor::ePrevious ?
             static_cast<int32_t>(leafNode->Length()) : 0;
         rv = SelectionRef().Collapse(leafNode, offset);
         NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
           "Failed to collapse selection at the leaf node");
-        rv = WillDeleteSelection(&SelectionRef(), aAction, aStripWrappers,
-                                 aCancel, aHandled);
+        rv = WillDeleteSelection(aAction, aStripWrappers, aCancel, aHandled);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
         return NS_OK;
       }
 
       // Otherwise, we must have deleted the selection as user expected.
       rv = SelectionRef().Collapse(selPointNode, selPointOffset);
@@ -2860,17 +2844,17 @@ HTMLEditRules::WillDeleteSelection(Selec
       rv = SelectionRef().Collapse(selPointNode, selPointOffset);
       NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to collapse selection");
       return NS_OK;
     }
   }
 
 
   // Else we have a non-collapsed selection.  First adjust the selection.
-  rv = ExpandSelectionForDeletion(SelectionRef());
+  rv = ExpandSelectionForDeletion();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Remember that we did a ranged delete for the benefit of AfterEditInner().
   mDidRangedDelete = true;
 
   // Refresh start and end points
@@ -3120,24 +3104,20 @@ HTMLEditRules::DeleteNodeIfCollapsedText
 /**
  * InsertBRIfNeeded() determines if a br is needed for current selection to not
  * be spastic.  If so, it inserts one.  Callers responsibility to only call
  * with collapsed selection.
  *
  * @param aSelection        The collapsed selection.
  */
 nsresult
-HTMLEditRules::InsertBRIfNeeded(Selection* aSelection)
+HTMLEditRules::InsertBRIfNeeded()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (NS_WARN_IF(!aSelection)) {
-    return NS_ERROR_INVALID_ARG;
-  }
-
   EditorRawDOMPoint atStartOfSelection(
                       EditorBase::GetStartPoint(&SelectionRef()));
   if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
     return NS_ERROR_FAILURE;
   }
 
   // inline elements don't need any br
   if (!IsBlockNode(*atStartOfSelection.GetContainer())) {
@@ -3677,26 +3657,21 @@ HTMLEditRules::DeleteNonTableElements(ns
   for (const auto& child: childList) {
     nsresult rv = DeleteNonTableElements(child);
     NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::DidDeleteSelection(Selection* aSelection,
-                                  nsIEditor::EDirection aDir,
+HTMLEditRules::DidDeleteSelection(nsIEditor::EDirection aDir,
                                   nsresult aResult)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (!aSelection) {
-    return NS_ERROR_NULL_POINTER;
-  }
-
   // find where we are
   EditorDOMPoint atStartOfSelection(EditorBase::GetStartPoint(&SelectionRef()));
   if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
     return NS_ERROR_FAILURE;
   }
 
   // find any enclosing mailcite
   RefPtr<Element> citeNode =
@@ -3725,37 +3700,36 @@ HTMLEditRules::DidDeleteSelection(Select
         SelectionRef().Collapse(EditorRawDOMPoint(brElement), error);
         NS_WARNING_ASSERTION(!error.Failed(),
           "Failed to collapse selection at the new <br> element");
       }
     }
   }
 
   // call through to base class
-  return TextEditRules::DidDeleteSelection(&SelectionRef(), aDir, aResult);
+  return TextEditRules::DidDeleteSelection(aDir, aResult);
 }
 
 nsresult
-HTMLEditRules::WillMakeList(Selection* aSelection,
-                            const nsAString* aListType,
+HTMLEditRules::WillMakeList(const nsAString* aListType,
                             bool aEntireList,
                             const nsAString* aBulletType,
                             bool* aCancel,
                             bool* aHandled,
                             const nsAString* aItemType)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (!aSelection || !aListType || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
+  if (NS_WARN_IF(!aListType) || NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
   }
 
   OwningNonNull<nsAtom> listType = NS_Atomize(*aListType);
 
-  WillInsert(SelectionRef(), aCancel);
+  WillInsert(aCancel);
 
   // initialize out param
   // we want to ignore result of WillInsert()
   *aCancel = false;
   *aHandled = false;
 
   // deduce what tag to use for list items
   RefPtr<nsAtom> itemType;
@@ -3769,17 +3743,17 @@ HTMLEditRules::WillMakeList(Selection* a
 
   // 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
 
   *aHandled = true;
 
-  nsresult rv = NormalizeSelection(&SelectionRef());
+  nsresult rv = NormalizeSelection();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
 
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
   rv = GetListActionNodes(arrayOfNodes,
@@ -4103,39 +4077,38 @@ HTMLEditRules::WillMakeList(Selection* a
     }
   }
 
   return NS_OK;
 }
 
 
 nsresult
-HTMLEditRules::WillRemoveList(Selection* aSelection,
-                              bool aOrdered,
+HTMLEditRules::WillRemoveList(bool aOrdered,
                               bool* aCancel,
                               bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
   }
   // initialize out param
   *aCancel = false;
   *aHandled = true;
 
-  nsresult rv = NormalizeSelection(&SelectionRef());
+  nsresult rv = NormalizeSelection();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
 
   nsTArray<RefPtr<nsRange>> arrayOfRanges;
-  GetPromotedRanges(SelectionRef(), arrayOfRanges, EditAction::makeList);
+  GetPromotedRanges(arrayOfRanges, EditAction::makeList);
 
   // use these ranges to contruct a list of nodes to act on.
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
   rv = GetListActionNodes(arrayOfNodes, EntireList::no);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
@@ -4164,73 +4137,70 @@ HTMLEditRules::WillRemoveList(Selection*
         return rv;
       }
     }
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::WillMakeDefListItem(Selection* aSelection,
-                                   const nsAString *aItemType,
+HTMLEditRules::WillMakeDefListItem(const nsAString *aItemType,
                                    bool aEntireList,
                                    bool* aCancel,
                                    bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   // for now we let WillMakeList handle this
   NS_NAMED_LITERAL_STRING(listType, "dl");
-  nsresult rv = WillMakeList(&SelectionRef(), &listType.AsString(), aEntireList,
+  nsresult rv = WillMakeList(&listType.AsString(), aEntireList,
                              nullptr, aCancel, aHandled, aItemType);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::WillMakeBasicBlock(Selection& aSelection,
-                                  const nsAString& aBlockType,
+HTMLEditRules::WillMakeBasicBlock(const nsAString& aBlockType,
                                   bool* aCancel,
                                   bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
   MOZ_ASSERT(aCancel && aHandled);
 
   OwningNonNull<nsAtom> blockType = NS_Atomize(aBlockType);
 
-  WillInsert(SelectionRef(), aCancel);
+  WillInsert(aCancel);
   // We want to ignore result of WillInsert()
   *aCancel = false;
   *aHandled = true;
 
-  nsresult rv = MakeBasicBlock(SelectionRef(), blockType);
+  nsresult rv = MakeBasicBlock(blockType);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::MakeBasicBlock(Selection& aSelection, nsAtom& blockType)
+HTMLEditRules::MakeBasicBlock(nsAtom& blockType)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  nsresult rv = NormalizeSelection(&SelectionRef());
+  nsresult rv = NormalizeSelection();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
   AutoTransactionsConserveSelection dontChangeMySelection(&HTMLEditorRef());
 
   // Contruct a list of nodes to act on.
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
-  rv = GetNodesFromSelection(SelectionRef(), EditAction::makeBasicBlock,
-                             arrayOfNodes);
+  rv = GetNodesFromSelection(EditAction::makeBasicBlock, arrayOfNodes);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // If nothing visible in list, make an empty block
   if (ListIsEmptyLine(arrayOfNodes)) {
     nsRange* firstRange = SelectionRef().GetRangeAt(0);
     if (NS_WARN_IF(!firstRange)) {
@@ -4354,23 +4324,21 @@ HTMLEditRules::MakeBasicBlock(Selection&
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::DidMakeBasicBlock(Selection* aSelection,
-                                 RulesInfo* aInfo,
+HTMLEditRules::DidMakeBasicBlock(RulesInfo* aInfo,
                                  nsresult aResult)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   // check for empty block.  if so, put a moz br in it.
   if (!SelectionRef().IsCollapsed()) {
     return NS_OK;
   }
 
   nsRange* firstRange = SelectionRef().GetRangeAt(0);
   if (NS_WARN_IF(!firstRange)) {
     return NS_ERROR_FAILURE;
@@ -4382,55 +4350,53 @@ HTMLEditRules::DidMakeBasicBlock(Selecti
   nsresult rv = InsertMozBRIfNeeded(*atStartOfSelection.Container());
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::WillIndent(Selection* aSelection,
-                          bool* aCancel,
+HTMLEditRules::WillIndent(bool* aCancel,
                           bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   if (HTMLEditorRef().IsCSSEnabled()) {
-    nsresult rv = WillCSSIndent(&SelectionRef(), aCancel, aHandled);
+    nsresult rv = WillCSSIndent(aCancel, aHandled);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   } else {
-    nsresult rv = WillHTMLIndent(&SelectionRef(), aCancel, aHandled);
+    nsresult rv = WillHTMLIndent(aCancel, aHandled);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::WillCSSIndent(Selection* aSelection,
-                             bool* aCancel,
+HTMLEditRules::WillCSSIndent(bool* aCancel,
                              bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
-  }
-
-  WillInsert(SelectionRef(), aCancel);
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  WillInsert(aCancel);
 
   // initialize out param
   // we want to ignore result of WillInsert()
   *aCancel = false;
   *aHandled = true;
 
-  nsresult rv = NormalizeSelection(&SelectionRef());
+  nsresult rv = NormalizeSelection();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
   nsTArray<OwningNonNull<nsRange>> arrayOfRanges;
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
 
   // short circuit: detect case of collapsed selection inside an <li>.
@@ -4452,18 +4418,17 @@ HTMLEditRules::WillCSSIndent(Selection* 
 
   if (liNode) {
     arrayOfNodes.AppendElement(*liNode);
   } else {
     // 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
-    rv = GetNodesFromSelection(SelectionRef(), EditAction::indent,
-                               arrayOfNodes);
+    rv = GetNodesFromSelection(EditAction::indent, arrayOfNodes);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   // if nothing visible in list, make an empty block
   if (ListIsEmptyLine(arrayOfNodes)) {
     // get selection location
@@ -4642,47 +4607,46 @@ HTMLEditRules::WillCSSIndent(Selection* 
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::WillHTMLIndent(Selection* aSelection,
-                              bool* aCancel,
+HTMLEditRules::WillHTMLIndent(bool* aCancel,
                               bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
-  }
-
-  WillInsert(SelectionRef(), aCancel);
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  WillInsert(aCancel);
 
   // initialize out param
   // we want to ignore result of WillInsert()
   *aCancel = false;
   *aHandled = true;
 
-  nsresult rv = NormalizeSelection(&SelectionRef());
+  nsresult rv = NormalizeSelection();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
 
   // 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<RefPtr<nsRange>> arrayOfRanges;
-  GetPromotedRanges(SelectionRef(), arrayOfRanges, EditAction::indent);
+  GetPromotedRanges(arrayOfRanges, EditAction::indent);
 
   // use these ranges to contruct a list of nodes to act on.
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
   rv = GetNodesForOperation(arrayOfRanges, arrayOfNodes, EditAction::indent);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
@@ -4921,44 +4885,42 @@ HTMLEditRules::WillHTMLIndent(Selection*
     // forget curList, if any
     curList = nullptr;
   }
   return NS_OK;
 }
 
 
 nsresult
-HTMLEditRules::WillOutdent(Selection& aSelection,
-                           bool* aCancel,
+HTMLEditRules::WillOutdent(bool* aCancel,
                            bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
   MOZ_ASSERT(aCancel && aHandled);
   *aCancel = false;
   *aHandled = true;
   nsCOMPtr<nsIContent> rememberedLeftBQ, rememberedRightBQ;
 
   bool useCSS = HTMLEditorRef().IsCSSEnabled();
 
-  nsresult rv = NormalizeSelection(&SelectionRef());
+  nsresult rv = NormalizeSelection();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Some scoping for selection resetting - we may need to tweak it
   {
     AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
 
     // 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<OwningNonNull<nsINode>> arrayOfNodes;
-    rv = GetNodesFromSelection(SelectionRef(), EditAction::outdent,
-                               arrayOfNodes);
+    rv = GetNodesFromSelection(EditAction::outdent, arrayOfNodes);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     // Okay, now go through all the nodes and remove a level of blockquoting,
     // or whatever is appropriate.  Wohoo!
 
     nsCOMPtr<Element> curBlockQuote;
@@ -5373,18 +5335,17 @@ HTMLEditRules::ConvertListType(Element* 
 }
 
 
 /**
  * CreateStyleForInsertText() takes care of clearing and setting appropriate
  * style nodes for text insertion.
  */
 nsresult
-HTMLEditRules::CreateStyleForInsertText(Selection& aSelection,
-                                        nsIDocument& aDoc)
+HTMLEditRules::CreateStyleForInsertText(nsIDocument& aDoc)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
   MOZ_ASSERT(HTMLEditorRef().mTypeInState);
 
   bool weDidSomething = false;
   nsRange* firstRange = SelectionRef().GetRangeAt(0);
   if (NS_WARN_IF(!firstRange)) {
     return NS_ERROR_FAILURE;
@@ -5503,43 +5464,42 @@ HTMLEditRules::IsEmptyBlockElement(Eleme
                                 aIgnoreSingleBR == IgnoreSingleBR::eYes);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return false;
   }
   return isEmpty;
 }
 
 nsresult
-HTMLEditRules::WillAlign(Selection& aSelection,
-                         const nsAString& aAlignType,
+HTMLEditRules::WillAlign(const nsAString& aAlignType,
                          bool* aCancel,
                          bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
   MOZ_ASSERT(aCancel && aHandled);
 
-  WillInsert(SelectionRef(), aCancel);
+  WillInsert(aCancel);
 
   // Initialize out param.  We want to ignore result of WillInsert().
   *aCancel = false;
   *aHandled = false;
 
-  nsresult rv = NormalizeSelection(&SelectionRef());
+  nsresult rv = NormalizeSelection();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
 
   // 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
   *aHandled = true;
   nsTArray<OwningNonNull<nsINode>> nodeArray;
-  rv = GetNodesFromSelection(SelectionRef(), EditAction::align, nodeArray);
+  rv = GetNodesFromSelection(EditAction::align, nodeArray);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // If we don't have any nodes, or we have only a single br, then we are
   // creating an empty alignment div.  We have to do some different things for
   // these.
   bool emptyDiv = nodeArray.IsEmpty();
@@ -5847,17 +5807,16 @@ HTMLEditRules::AlignBlockContents(nsINod
 
 /**
  * CheckForEmptyBlock() is called by WillDeleteSelection() to detect and handle
  * case of deleting from inside an empty block.
  */
 nsresult
 HTMLEditRules::CheckForEmptyBlock(nsINode* aStartNode,
                                   Element* aBodyNode,
-                                  Selection* aSelection,
                                   nsIEditor::EDirection aAction,
                                   bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   // If the editing host is an inline element, bail out early.
   if (aBodyNode && IsInlineNode(*aBodyNode)) {
     return NS_OK;
@@ -6058,17 +6017,17 @@ HTMLEditRules::GetInnerContent(
     }
   }
 }
 
 /**
  * Promotes selection to include blocks that have all their children selected.
  */
 nsresult
-HTMLEditRules::ExpandSelectionForDeletion(Selection& aSelection)
+HTMLEditRules::ExpandSelectionForDeletion()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   // Don't need to touch collapsed selections
   if (SelectionRef().IsCollapsed()) {
     return NS_OK;
   }
 
@@ -6210,22 +6169,20 @@ HTMLEditRules::ExpandSelectionForDeletio
 /**
  * NormalizeSelection() tweaks non-collapsed selections to be more "natural".
  * Idea here is to adjust selection endpoint so that they do not cross breaks
  * or block boundaries unless something editable beyond that boundary is also
  * selected.  This adjustment makes it much easier for the various block
  * operations to determine what nodes to act on.
  */
 nsresult
-HTMLEditRules::NormalizeSelection(Selection* inSelection)
+HTMLEditRules::NormalizeSelection()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  NS_ENSURE_TRUE(inSelection, NS_ERROR_NULL_POINTER);
-
   // don't need to touch collapsed selections
   if (SelectionRef().IsCollapsed()) {
     return NS_OK;
   }
 
   // we don't need to mess with cell selections, and we assume multirange selections are those.
   if (SelectionRef().RangeCount() != 1) {
     return NS_OK;
@@ -6574,18 +6531,17 @@ HTMLEditRules::GetPromotedPoint(RulesEnd
   return point;
 }
 
 /**
  * GetPromotedRanges() runs all the selection range endpoint through
  * GetPromotedPoint().
  */
 void
-HTMLEditRules::GetPromotedRanges(Selection& aSelection,
-                                 nsTArray<RefPtr<nsRange>>& outArrayOfRanges,
+HTMLEditRules::GetPromotedRanges(nsTArray<RefPtr<nsRange>>& outArrayOfRanges,
                                  EditAction inOperationType)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   uint32_t rangeCount = SelectionRef().RangeCount();
   for (uint32_t i = 0; i < rangeCount; i++) {
     RefPtr<nsRange> selectionRange = SelectionRef().GetRangeAt(i);
     MOZ_ASSERT(selectionRange);
@@ -6916,17 +6872,17 @@ HTMLEditRules::GetListActionNodes(
     }
   }
 
   {
     // We don't like other people messing with our selection!
     AutoTransactionsConserveSelection dontChangeMySelection(&HTMLEditorRef());
 
     // contruct a list of nodes to act on.
-    nsresult rv = GetNodesFromSelection(SelectionRef(), EditAction::makeList,
+    nsresult rv = GetNodesFromSelection(EditAction::makeList,
                                         aOutArrayOfNodes, aTouchContent);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
   // Pre-process our list of nodes
   for (int32_t i = aOutArrayOfNodes.Length() - 1; i >= 0; i--) {
@@ -7028,17 +6984,17 @@ nsresult
 HTMLEditRules::GetParagraphFormatNodes(
                  nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
                  TouchContent aTouchContent)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   // Contruct a list of nodes to act on.
   nsresult rv =
-   GetNodesFromSelection(SelectionRef(), EditAction::makeBasicBlock,
+   GetNodesFromSelection(EditAction::makeBasicBlock,
                          outArrayOfNodes, aTouchContent);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Pre-process our list of nodes
   for (int32_t i = outArrayOfNodes.Length() - 1; i >= 0; i--) {
     OwningNonNull<nsINode> testNode = outArrayOfNodes[i];
@@ -7249,26 +7205,25 @@ HTMLEditRules::GetNodesFromPoint(
 }
 
 /**
  * GetNodesFromSelection() constructs a list of nodes from the selection that
  * will be operated on.
  */
 nsresult
 HTMLEditRules::GetNodesFromSelection(
-                 Selection& aSelection,
                  EditAction aOperation,
                  nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
                  TouchContent aTouchContent)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   // Promote selection ranges
   nsTArray<RefPtr<nsRange>> arrayOfRanges;
-  GetPromotedRanges(SelectionRef(), arrayOfRanges, aOperation);
+  GetPromotedRanges(arrayOfRanges, aOperation);
 
   // Use these ranges to contruct a list of nodes to act on.
   nsresult rv = GetNodesForOperation(arrayOfRanges, outArrayOfNodes,
                                      aOperation, aTouchContent);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
@@ -7332,18 +7287,17 @@ HTMLEditRules::DefaultParagraphSeparator
   return ParagraphSeparatorElement(
            HTMLEditorRef().GetDefaultParagraphSeparator());
 }
 
 /**
  * ReturnInHeader: do the right thing for returns pressed in headers
  */
 nsresult
-HTMLEditRules::ReturnInHeader(Selection& aSelection,
-                              Element& aHeader,
+HTMLEditRules::ReturnInHeader(Element& aHeader,
                               nsINode& aNode,
                               int32_t aOffset)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   // Remember where the header is
   nsCOMPtr<nsINode> headerParent = aHeader.GetParentNode();
   int32_t offset = headerParent ? headerParent->ComputeIndexOf(&aHeader) : -1;
@@ -7448,18 +7402,17 @@ HTMLEditRules::ReturnInHeader(Selection&
     if (NS_WARN_IF(error.Failed())) {
       return error.StealNSResult();
     }
   }
   return NS_OK;
 }
 
 EditActionResult
-HTMLEditRules::ReturnInParagraph(Selection& aSelection,
-                                 Element& aParentDivOrP)
+HTMLEditRules::ReturnInParagraph(Element& aParentDivOrP)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   nsRange* firstRange = SelectionRef().GetRangeAt(0);
   if (NS_WARN_IF(!firstRange)) {
     return EditActionResult(NS_ERROR_FAILURE);
   }
 
@@ -7630,29 +7583,27 @@ HTMLEditRules::ReturnInParagraph(Selecti
       // We split the parent after the br we've just inserted.
       pointToSplitParentDivOrP.Set(brContent);
       DebugOnly<bool> advanced = pointToSplitParentDivOrP.AdvanceOffset();
       NS_WARNING_ASSERTION(advanced,
         "Failed to advance offset after the new <br>");
     }
   }
   EditActionResult result(
-    SplitParagraph(SelectionRef(), aParentDivOrP, pointToSplitParentDivOrP,
-                   brContent));
+    SplitParagraph(aParentDivOrP, pointToSplitParentDivOrP, brContent));
   result.MarkAsHandled();
   if (NS_WARN_IF(result.Failed())) {
     return result;
   }
   return result;
 }
 
 template<typename PT, typename CT>
 nsresult
 HTMLEditRules::SplitParagraph(
-                 Selection& aSelection,
                  Element& aParentDivOrP,
                  const EditorDOMPointBase<PT, CT>& aStartOfRightNode,
                  nsIContent* aNextBRNode)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   // split para
   // get ws code to adjust any ws
@@ -7730,18 +7681,17 @@ HTMLEditRules::SplitParagraph(
   }
   return NS_OK;
 }
 
 /**
  * ReturnInListItem: do the right thing for returns pressed in list items
  */
 nsresult
-HTMLEditRules::ReturnInListItem(Selection& aSelection,
-                                Element& aListItem,
+HTMLEditRules::ReturnInListItem(Element& aListItem,
                                 nsINode& aNode,
                                 int32_t aOffset)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
   MOZ_ASSERT(HTMLEditUtils::IsListItem(&aListItem));
 
   // Get the item parent and the active editing host.
   RefPtr<Element> host = HTMLEditorRef().GetActiveEditingHost();
@@ -8609,17 +8559,17 @@ HTMLEditRules::AdjustSpecialBreaks()
     RefPtr<Element> brElement = CreateMozBR(endOfNode);
     if (NS_WARN_IF(!brElement)) {
       return;
     }
   }
 }
 
 nsresult
-HTMLEditRules::AdjustWhitespace(Selection* aSelection)
+HTMLEditRules::AdjustWhitespace()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   EditorRawDOMPoint selectionStartPoint(
                       EditorBase::GetStartPoint(&SelectionRef()));
   if (NS_WARN_IF(!selectionStartPoint.IsSet())) {
     return NS_ERROR_FAILURE;
   }
@@ -8629,21 +8579,20 @@ HTMLEditRules::AdjustWhitespace(Selectio
     WSRunObject(&HTMLEditorRef(), selectionStartPoint).AdjustWhitespace();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::PinSelectionToNewBlock(Selection* aSelection)
+HTMLEditRules::PinSelectionToNewBlock()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   if (!SelectionRef().IsCollapsed()) {
     return NS_OK;
   }
 
   if (NS_WARN_IF(!mNewBlock)) {
     return NS_ERROR_NULL_POINTER;
   }
 
@@ -8711,17 +8660,17 @@ HTMLEditRules::PinSelectionToNewBlock(Se
   SelectionRef().Collapse(atStartOfBlock, error);
   if (NS_WARN_IF(error.Failed())) {
     return error.StealNSResult();
   }
   return NS_OK;
 }
 
 void
-HTMLEditRules::CheckInterlinePosition(Selection& aSelection)
+HTMLEditRules::CheckInterlinePosition()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   // If the selection isn't collapsed, do nothing.
   if (!SelectionRef().IsCollapsed()) {
     return;
   }
 
@@ -8774,25 +8723,20 @@ HTMLEditRules::CheckInterlinePosition(Se
     IgnoredErrorResult ignoredError;
     SelectionRef().SetInterlinePosition(false, ignoredError);
     NS_WARNING_ASSERTION(!ignoredError.Failed(),
       "Failed to unset interline position");
   }
 }
 
 nsresult
-HTMLEditRules::AdjustSelection(Selection* aSelection,
-                               nsIEditor::EDirection aAction)
+HTMLEditRules::AdjustSelection(nsIEditor::EDirection aAction)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (NS_WARN_IF(!aSelection)) {
-    return NS_ERROR_INVALID_ARG;
-  }
-
   // if the selection isn't collapsed, do nothing.
   // moose: one thing to do instead is check for the case of
   // only a single break selected, and collapse it.  Good thing?  Beats me.
   if (!SelectionRef().IsCollapsed()) {
     return NS_OK;
   }
 
   // get the (collapsed) selection location
@@ -9982,49 +9926,47 @@ HTMLEditRules::ChangeIndentation(Element
   nsresult rv = HTMLEditorRef().RemoveContainerWithTransaction(aElement);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::WillAbsolutePosition(Selection& aSelection,
-                                    bool* aCancel,
+HTMLEditRules::WillAbsolutePosition(bool* aCancel,
                                     bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
   MOZ_ASSERT(aCancel && aHandled);
 
-  WillInsert(SelectionRef(), aCancel);
+  WillInsert(aCancel);
 
   // We want to ignore result of WillInsert()
   *aCancel = false;
   *aHandled = true;
 
   RefPtr<Element> focusElement = HTMLEditorRef().GetSelectionContainer();
   if (focusElement && HTMLEditUtils::IsImage(focusElement)) {
     mNewBlock = focusElement;
     return NS_OK;
   }
 
-  nsresult rv = NormalizeSelection(&SelectionRef());
+  nsresult rv = NormalizeSelection();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   AutoSelectionRestorer selectionRestorer(&SelectionRef(), &HTMLEditorRef());
 
   // 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<RefPtr<nsRange>> arrayOfRanges;
-  GetPromotedRanges(SelectionRef(), arrayOfRanges,
-                    EditAction::setAbsolutePosition);
+  GetPromotedRanges(arrayOfRanges, EditAction::setAbsolutePosition);
 
   // Use these ranges to contruct a list of nodes to act on.
   nsTArray<OwningNonNull<nsINode>> arrayOfNodes;
   rv = GetNodesForOperation(arrayOfRanges, arrayOfNodes,
                             EditAction::setAbsolutePosition);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
@@ -10247,27 +10189,26 @@ HTMLEditRules::DidAbsolutePosition()
   nsresult rv = HTMLEditorRef().SetPositionToAbsoluteOrStatic(*mNewBlock, true);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::WillRemoveAbsolutePosition(Selection* aSelection,
-                                          bool* aCancel,
+HTMLEditRules::WillRemoveAbsolutePosition(bool* aCancel,
                                           bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
-  }
-
-  WillInsert(SelectionRef(), aCancel);
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  WillInsert(aCancel);
 
   // initialize out param
   // we want to ignore aCancel from WillInsert()
   *aCancel = false;
   *aHandled = true;
 
   RefPtr<Element> element =
     HTMLEditorRef().GetAbsolutelyPositionedSelectionContainer();
@@ -10280,28 +10221,27 @@ HTMLEditRules::WillRemoveAbsolutePositio
   nsresult rv = HTMLEditorRef().SetPositionToAbsoluteOrStatic(*element, false);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   return NS_OK;
 }
 
 nsresult
-HTMLEditRules::WillRelativeChangeZIndex(Selection* aSelection,
-                                        int32_t aChange,
+HTMLEditRules::WillRelativeChangeZIndex(int32_t aChange,
                                         bool* aCancel,
                                         bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
-  }
-
-  WillInsert(SelectionRef(), aCancel);
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  WillInsert(aCancel);
 
   // initialize out param
   // we want to ignore aCancel from WillInsert()
   *aCancel = false;
   *aHandled = true;
 
   RefPtr<Element> element =
     HTMLEditorRef().GetAbsolutelyPositionedSelectionContainer();
@@ -10354,12 +10294,12 @@ HTMLEditRules::DocumentModifiedWorker()
     DebugOnly<nsresult> rv =
       HTMLEditorRef().DeleteNodeWithTransaction(*mBogusNode);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
       "Failed to remove the bogus node");
     mBogusNode = nullptr;
   }
 
   // Try to recreate the bogus node if needed.
-  CreateBogusNodeIfNeeded(&SelectionRef());
+  CreateBogusNodeIfNeeded();
 }
 
 } // namespace mozilla
--- a/editor/libeditor/HTMLEditRules.h
+++ b/editor/libeditor/HTMLEditRules.h
@@ -135,50 +135,44 @@ protected:
   enum RulesEndpoint
   {
     kStart,
     kEnd
   };
 
   void InitFields();
 
-  void WillInsert(Selection& aSelection, bool* aCancel);
+  void WillInsert(bool* aCancel);
   nsresult WillInsertText(EditAction aAction,
-                          Selection* aSelection,
                           bool* aCancel,
                           bool* aHandled,
                           const nsAString* inString,
                           nsAString* outString,
                           int32_t aMaxLength);
-  nsresult WillLoadHTML(Selection* aSelection, bool* aCancel);
-  nsresult WillInsertBreak(Selection& aSelection, bool* aCancel,
-                           bool* aHandled);
+  nsresult WillLoadHTML(bool* aCancel);
+  nsresult WillInsertBreak(bool* aCancel, bool* aHandled);
 
   void DeleteNodeIfCollapsedText(nsINode& aNode);
 
   /**
    * InsertBRElement() inserts a <br> element into aInsertToBreak.
    *
-   * @param aSelection          The selection.
    * @param aInsertToBreak      The point where new <br> element will be
    *                            inserted before.
    */
-  nsresult InsertBRElement(Selection& aSelection,
-                           const EditorDOMPoint& aInsertToBreak);
+  nsresult InsertBRElement(const EditorDOMPoint& aInsertToBreak);
 
-  nsresult DidInsertBreak(Selection* aSelection, nsresult aResult);
-  nsresult SplitMailCites(Selection* aSelection, bool* aHandled);
-  nsresult WillDeleteSelection(Selection* aSelection,
-                               nsIEditor::EDirection aAction,
+  nsresult DidInsertBreak(nsresult aResult);
+  nsresult SplitMailCites(bool* aHandled);
+  nsresult WillDeleteSelection(nsIEditor::EDirection aAction,
                                nsIEditor::EStripWrappers aStripWrappers,
                                bool* aCancel, bool* aHandled);
-  nsresult DidDeleteSelection(Selection* aSelection,
-                              nsIEditor::EDirection aDir,
+  nsresult DidDeleteSelection(nsIEditor::EDirection aDir,
                               nsresult aResult);
-  nsresult InsertBRIfNeeded(Selection* aSelection);
+  nsresult InsertBRIfNeeded();
 
   /**
    * CanContainParagraph() returns true if aElement can have a <p> element as
    * its child or its descendant.
    */
   bool CanContainParagraph(Element& aElement) const;
 
   /**
@@ -248,100 +242,85 @@ protected:
    * @return                        Sets true to handled if this actually moves
    *                                the nodes.
    *                                canceled is always false.
    */
   EditActionResult MoveContents(Element& aElement, Element& aDestElement,
                                 int32_t* aInOutDestOffset);
 
   nsresult DeleteNonTableElements(nsINode* aNode);
-  nsresult WillMakeList(Selection* aSelection,
-                        const nsAString* aListType,
+  nsresult WillMakeList(const nsAString* aListType,
                         bool aEntireList,
                         const nsAString* aBulletType,
                         bool* aCancel, bool* aHandled,
                         const nsAString* aItemType = nullptr);
-  nsresult WillRemoveList(Selection* aSelection, bool aOrdered, bool* aCancel,
-                          bool* aHandled);
-  nsresult WillIndent(Selection* aSelection, bool* aCancel, bool* aHandled);
-  nsresult WillCSSIndent(Selection* aSelection, bool* aCancel, bool* aHandled);
-  nsresult WillHTMLIndent(Selection* aSelection, bool* aCancel,
-                          bool* aHandled);
-  nsresult WillOutdent(Selection& aSelection, bool* aCancel, bool* aHandled);
-  nsresult WillAlign(Selection& aSelection, const nsAString& aAlignType,
+  nsresult WillRemoveList(bool aOrdered, bool* aCancel, bool* aHandled);
+  nsresult WillIndent(bool* aCancel, bool* aHandled);
+  nsresult WillCSSIndent(bool* aCancel, bool* aHandled);
+  nsresult WillHTMLIndent(bool* aCancel, bool* aHandled);
+  nsresult WillOutdent(bool* aCancel, bool* aHandled);
+  nsresult WillAlign(const nsAString& aAlignType,
                      bool* aCancel, bool* aHandled);
-  nsresult WillAbsolutePosition(Selection& aSelection, bool* aCancel,
-                                bool* aHandled);
-  nsresult WillRemoveAbsolutePosition(Selection* aSelection, bool* aCancel,
-                                      bool* aHandled);
-  nsresult WillRelativeChangeZIndex(Selection* aSelection, int32_t aChange,
+  nsresult WillAbsolutePosition(bool* aCancel, bool* aHandled);
+  nsresult WillRemoveAbsolutePosition(bool* aCancel, bool* aHandled);
+  nsresult WillRelativeChangeZIndex(int32_t aChange,
                                     bool* aCancel, bool* aHandled);
-  nsresult WillMakeDefListItem(Selection* aSelection,
-                               const nsAString* aBlockType, bool aEntireList,
+  nsresult WillMakeDefListItem(const nsAString* aBlockType, bool aEntireList,
                                bool* aCancel, bool* aHandled);
-  nsresult WillMakeBasicBlock(Selection& aSelection,
-                              const nsAString& aBlockType,
+  nsresult WillMakeBasicBlock(const nsAString& aBlockType,
                               bool* aCancel, bool* aHandled);
-  nsresult MakeBasicBlock(Selection& aSelection, nsAtom& aBlockType);
-  nsresult DidMakeBasicBlock(Selection* aSelection, RulesInfo* aInfo,
-                             nsresult aResult);
+  nsresult MakeBasicBlock(nsAtom& aBlockType);
+  nsresult DidMakeBasicBlock(RulesInfo* aInfo, nsresult aResult);
   nsresult DidAbsolutePosition();
   nsresult AlignInnerBlocks(nsINode& aNode, const nsAString& aAlignType);
   nsresult AlignBlockContents(nsINode& aNode, const nsAString& aAlignType);
   nsresult AppendInnerFormatNodes(nsTArray<OwningNonNull<nsINode>>& aArray,
                                   nsINode* aNode);
   nsresult GetFormatString(nsINode* aNode, nsAString &outFormat);
   enum class Lists { no, yes };
   enum class Tables { no, yes };
   void GetInnerContent(nsINode& aNode,
                        nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes,
                        int32_t* aIndex, Lists aLists = Lists::yes,
                        Tables aTables = Tables::yes);
   Element* IsInListItem(nsINode* aNode);
   nsAtom& DefaultParagraphSeparator();
-  nsresult ReturnInHeader(Selection& aSelection, Element& aHeader,
-                          nsINode& aNode, int32_t aOffset);
+  nsresult ReturnInHeader(Element& aHeader, nsINode& aNode, int32_t aOffset);
 
   /**
    * ReturnInParagraph() does the right thing for Enter key press or
    * 'insertParagraph' command in aParentDivOrP.  aParentDivOrP will be
    * split at start of first selection range.
    *
-   * @param aSelection      The selection.  aParentDivOrP will be split at
-   *                        start of the first selection range.
    * @param aParentDivOrP   The parent block.  This must be <p> or <div>
    *                        element.
    * @return                Returns with NS_OK if this doesn't meat any
    *                        unexpected situation.  If this method tries to
    *                        split the paragraph, marked as handled.
    */
-  EditActionResult ReturnInParagraph(Selection& aSelection,
-                                     Element& aParentDivOrP);
+  EditActionResult ReturnInParagraph(Element& aParentDivOrP);
 
   /**
    * SplitParagraph() splits the parent block, aPara, at aSelNode - aOffset.
    *
-   * @param aSelection          The selection.
    * @param aParentDivOrP       The parent block to be split.  This must be <p>
    *                            or <div> element.
    * @param aStartOfRightNode   The point to be start of right node after
    *                            split.  This must be descendant of
    *                            aParentDivOrP.
    * @param aNextBRNode         Next <br> node if there is.  Otherwise, nullptr.
    *                            If this is not nullptr, the <br> node may be
    *                            removed.
    */
   template<typename PT, typename CT>
-  nsresult SplitParagraph(Selection& aSelection,
-                          Element& aParentDivOrP,
+  nsresult SplitParagraph(Element& aParentDivOrP,
                           const EditorDOMPointBase<PT, CT>& aStartOfRightNode,
                           nsIContent* aBRNode);
 
-  nsresult ReturnInListItem(Selection& aSelection, Element& aHeader,
-                            nsINode& aNode, int32_t aOffset);
+  nsresult ReturnInListItem(Element& aHeader, nsINode& aNode, int32_t aOffset);
   nsresult AfterEditInner(EditAction action,
                           nsIEditor::EDirection aDirection);
   nsresult RemovePartOfBlock(Element& aBlock, nsIContent& aStartChild,
                              nsIContent& aEndChild);
   void SplitBlock(Element& aBlock,
                   nsIContent& aStartChild,
                   nsIContent& aEndChild,
                   nsIContent** aOutLeftNode = nullptr,
@@ -352,59 +331,56 @@ protected:
                               nsIContent& aEndChild,
                               bool aIsBlockIndentedWithCSS,
                               nsIContent** aOutLeftNode,
                               nsIContent** aOutRightNode);
 
   already_AddRefed<Element> ConvertListType(Element* aList, nsAtom* aListType,
                                             nsAtom* aItemType);
 
-  nsresult CreateStyleForInsertText(Selection& aSelection, nsIDocument& aDoc);
+  nsresult CreateStyleForInsertText(nsIDocument& aDoc);
 
   /**
    * IsEmptyBlockElement() returns true if aElement is a block level element
    * and it doesn't have any visible content.
    */
   enum class IgnoreSingleBR
   {
     eYes,
     eNo
   };
   bool IsEmptyBlockElement(Element& aElement,
                            IgnoreSingleBR aIgnoreSingleBR);
 
   nsresult CheckForEmptyBlock(nsINode* aStartNode, Element* aBodyNode,
-                              Selection* aSelection,
                               nsIEditor::EDirection aAction, bool* aHandled);
   enum class BRLocation { beforeBlock, blockEnd };
   Element* CheckForInvisibleBR(Element& aBlock, BRLocation aWhere,
                                int32_t aOffset = 0);
-  nsresult ExpandSelectionForDeletion(Selection& aSelection);
-  nsresult NormalizeSelection(Selection* aSelection);
+  nsresult ExpandSelectionForDeletion();
+  nsresult NormalizeSelection();
   EditorDOMPoint GetPromotedPoint(RulesEndpoint aWhere, nsINode& aNode,
                                   int32_t aOffset, EditAction actionID);
-  void GetPromotedRanges(Selection& aSelection,
-                         nsTArray<RefPtr<nsRange>>& outArrayOfRanges,
+  void GetPromotedRanges(nsTArray<RefPtr<nsRange>>& outArrayOfRanges,
                          EditAction inOperationType);
   void PromoteRange(nsRange& aRange, EditAction inOperationType);
   enum class TouchContent { no, yes };
   nsresult GetNodesForOperation(
              nsTArray<RefPtr<nsRange>>& aArrayOfRanges,
              nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes,
              EditAction aOperationType,
              TouchContent aTouchContent = TouchContent::yes);
   void GetChildNodesForOperation(
          nsINode& aNode,
          nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes);
   nsresult GetNodesFromPoint(const EditorDOMPoint& aPoint,
                              EditAction aOperation,
                              nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
                              TouchContent aTouchContent);
   nsresult GetNodesFromSelection(
-             Selection& aSelection,
              EditAction aOperation,
              nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes,
              TouchContent aTouchContent = TouchContent::yes);
   enum class EntireList { no, yes };
   nsresult GetListActionNodes(
              nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes,
              EntireList aEntireList,
              TouchContent aTouchContent = TouchContent::yes);
@@ -496,21 +472,20 @@ protected:
 
   Element* GetTopEnclosingMailCite(nsINode& aNode);
   nsresult PopListItem(nsIContent& aListItem, bool* aOutOfList = nullptr);
   nsresult RemoveListStructure(Element& aList);
   nsresult CacheInlineStyles(nsINode* aNode);
   nsresult ReapplyCachedStyles();
   void ClearCachedStyles();
   void AdjustSpecialBreaks();
-  nsresult AdjustWhitespace(Selection* aSelection);
-  nsresult PinSelectionToNewBlock(Selection* aSelection);
-  void CheckInterlinePosition(Selection& aSelection);
-  nsresult AdjustSelection(Selection* aSelection,
-                           nsIEditor::EDirection aAction);
+  nsresult AdjustWhitespace();
+  nsresult PinSelectionToNewBlock();
+  void CheckInterlinePosition();
+  nsresult AdjustSelection(nsIEditor::EDirection aAction);
 
   /**
    * FindNearEditableNode() tries to find an editable node near aPoint.
    *
    * @param aPoint      The DOM point where to start to search from.
    * @param aDirection  If nsIEditor::ePrevious is set, this searches an
    *                    editable node from next nodes.  Otherwise, from
    *                    previous nodes.
--- a/editor/libeditor/TextEditRules.cpp
+++ b/editor/libeditor/TextEditRules.cpp
@@ -140,17 +140,17 @@ TextEditRules::Init(TextEditor* aTextEdi
   InitFields();
 
   // We hold a non-refcounted reference back to our editor.
   mTextEditor = aTextEditor;
   AutoSafeEditorData setData(*this, *mTextEditor, *selection);
 
   // Put in a magic <br> if needed. This method handles null selection,
   // which should never happen anyway
-  nsresult rv = CreateBogusNodeIfNeeded(&SelectionRef());
+  nsresult rv = CreateBogusNodeIfNeeded();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // If the selection hasn't been set up yet, set it up collapsed to the end of
   // our editable content.
   if (!SelectionRef().RangeCount()) {
     rv = TextEditorRef().CollapseSelectionToEnd(&SelectionRef());
@@ -269,29 +269,29 @@ TextEditRules::AfterEdit(EditAction aAct
 
     // if only trailing <br> remaining remove it
     rv = RemoveRedundantTrailingBR();
     if (NS_FAILED(rv)) {
       return rv;
     }
 
     // detect empty doc
-    rv = CreateBogusNodeIfNeeded(&SelectionRef());
+    rv = CreateBogusNodeIfNeeded();
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     // ensure trailing br node
     rv = CreateTrailingBRIfNeeded();
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     // collapse the selection to the trailing BR if it's at the end of our text node
-    CollapseSelectionToTrailingBRIfNeeded(&SelectionRef());
+    CollapseSelectionToTrailingBRIfNeeded();
   }
   return NS_OK;
 }
 
 nsresult
 TextEditRules::WillDoAction(Selection* aSelection,
                             RulesInfo* aInfo,
                             bool* aCancel,
@@ -310,47 +310,45 @@ TextEditRules::WillDoAction(Selection* a
   *aCancel = false;
   *aHandled = false;
 
   AutoSafeEditorData setData(*this, *mTextEditor, *aSelection);
 
   // my kingdom for dynamic cast
   switch (aInfo->action) {
     case EditAction::insertBreak:
-      UndefineCaretBidiLevel(&SelectionRef());
-      return WillInsertBreak(&SelectionRef(), aCancel, aHandled,
-                             aInfo->maxLength);
+      UndefineCaretBidiLevel();
+      return WillInsertBreak(aCancel, aHandled, aInfo->maxLength);
     case EditAction::insertText:
     case EditAction::insertIMEText:
-      UndefineCaretBidiLevel(&SelectionRef());
-      return WillInsertText(aInfo->action, &SelectionRef(), aCancel, aHandled,
+      UndefineCaretBidiLevel();
+      return WillInsertText(aInfo->action, aCancel, aHandled,
                             aInfo->inString, aInfo->outString,
                             aInfo->maxLength);
     case EditAction::setText:
-      UndefineCaretBidiLevel(&SelectionRef());
-      return WillSetText(SelectionRef(), aCancel, aHandled, aInfo->inString,
+      UndefineCaretBidiLevel();
+      return WillSetText(aCancel, aHandled, aInfo->inString,
                          aInfo->maxLength);
     case EditAction::deleteSelection:
-      return WillDeleteSelection(&SelectionRef(), aInfo->collapsedAction,
-                                 aCancel, aHandled);
+      return WillDeleteSelection(aInfo->collapsedAction, aCancel, aHandled);
     case EditAction::undo:
-      return WillUndo(&SelectionRef(), aCancel, aHandled);
+      return WillUndo(aCancel, aHandled);
     case EditAction::redo:
-      return WillRedo(&SelectionRef(), aCancel, aHandled);
+      return WillRedo(aCancel, aHandled);
     case EditAction::setTextProperty:
-      return WillSetTextProperty(&SelectionRef(), aCancel, aHandled);
+      return WillSetTextProperty(aCancel, aHandled);
     case EditAction::removeTextProperty:
-      return WillRemoveTextProperty(&SelectionRef(), aCancel, aHandled);
+      return WillRemoveTextProperty(aCancel, aHandled);
     case EditAction::outputText:
-      return WillOutputText(&SelectionRef(), aInfo->outputFormat,
-                            aInfo->outString, aInfo->flags, aCancel, aHandled);
+      return WillOutputText(aInfo->outputFormat, aInfo->outString, aInfo->flags,
+                            aCancel, aHandled);
     case EditAction::insertElement:
       // i had thought this would be html rules only.  but we put pre elements
       // into plaintext mail when doing quoting for reply!  doh!
-      WillInsert(SelectionRef(), aCancel);
+      WillInsert(aCancel);
       return NS_OK;
     default:
       return NS_ERROR_FAILURE;
   }
 }
 
 nsresult
 TextEditRules::DidDoAction(Selection* aSelection,
@@ -367,35 +365,34 @@ TextEditRules::DidDoAction(Selection* aS
   AutoSafeEditorData setData(*this, *mTextEditor, *aSelection);
 
   // don't let any txns in here move the selection around behind our back.
   // Note that this won't prevent explicit selection setting from working.
   AutoTransactionsConserveSelection dontChangeMySelection(&TextEditorRef());
 
   switch (aInfo->action) {
     case EditAction::insertBreak:
-      return DidInsertBreak(&SelectionRef(), aResult);
+      return DidInsertBreak(aResult);
     case EditAction::insertText:
     case EditAction::insertIMEText:
-      return DidInsertText(&SelectionRef(), aResult);
+      return DidInsertText(aResult);
     case EditAction::setText:
-      return DidSetText(SelectionRef(), aResult);
+      return DidSetText(aResult);
     case EditAction::deleteSelection:
-      return DidDeleteSelection(&SelectionRef(), aInfo->collapsedAction,
-                                aResult);
+      return DidDeleteSelection(aInfo->collapsedAction, aResult);
     case EditAction::undo:
-      return DidUndo(&SelectionRef(), aResult);
+      return DidUndo(aResult);
     case EditAction::redo:
-      return DidRedo(&SelectionRef(), aResult);
+      return DidRedo(aResult);
     case EditAction::setTextProperty:
-      return DidSetTextProperty(&SelectionRef(), aResult);
+      return DidSetTextProperty(aResult);
     case EditAction::removeTextProperty:
-      return DidRemoveTextProperty(&SelectionRef(), aResult);
+      return DidRemoveTextProperty(aResult);
     case EditAction::outputText:
-      return DidOutputText(&SelectionRef(), aResult);
+      return DidOutputText(aResult);
     default:
       // Don't fail on transactions we don't handle here!
       return NS_OK;
   }
 }
 
 /**
  * Return false if the editor has non-empty text nodes or non-text
@@ -409,17 +406,17 @@ TextEditRules::DocumentIsEmpty()
   if (!mTextEditor || NS_FAILED(mTextEditor->DocumentIsEmpty(&retVal))) {
     retVal = true;
   }
 
   return retVal;
 }
 
 void
-TextEditRules::WillInsert(Selection& aSelection, bool* aCancel)
+TextEditRules::WillInsert(bool* aCancel)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
   MOZ_ASSERT(aCancel);
 
   if (IsReadonly() || IsDisabled()) {
     *aCancel = true;
     return;
   }
@@ -433,44 +430,42 @@ TextEditRules::WillInsert(Selection& aSe
       TextEditorRef().DeleteNodeWithTransaction(*mBogusNode);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
       "Failed to remove the bogus node");
     mBogusNode = nullptr;
   }
 }
 
 nsresult
-TextEditRules::DidInsert(Selection* aSelection,
-                         nsresult aResult)
+TextEditRules::DidInsert(nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-TextEditRules::WillInsertBreak(Selection* aSelection,
-                               bool* aCancel,
+TextEditRules::WillInsertBreak(bool* aCancel,
                                bool* aHandled,
                                int32_t aMaxLength)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
   }
   CANCEL_OPERATION_IF_READONLY_OR_DISABLED
   *aHandled = false;
   if (IsSingleLineEditor()) {
     *aCancel = true;
   } else {
     // handle docs with a max length
     // NOTE, this function copies inString into outString for us.
     NS_NAMED_LITERAL_STRING(inString, "\n");
     nsAutoString outString;
     bool didTruncate;
     nsresult rv =
-      TruncateInsertionIfNeeded(&SelectionRef(), &inString.AsString(),
+      TruncateInsertionIfNeeded(&inString.AsString(),
                                 &outString, aMaxLength, &didTruncate);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     if (didTruncate) {
       *aCancel = true;
       return NS_OK;
     }
@@ -481,33 +476,32 @@ TextEditRules::WillInsertBreak(Selection
     if (!SelectionRef().IsCollapsed()) {
       rv = TextEditorRef().DeleteSelectionAsAction(nsIEditor::eNone,
                                                    nsIEditor::eStrip);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
     }
 
-    WillInsert(SelectionRef(), aCancel);
+    WillInsert(aCancel);
     // initialize out param
     // we want to ignore result of WillInsert()
     *aCancel = false;
   }
   return NS_OK;
 }
 
 nsresult
-TextEditRules::DidInsertBreak(Selection* aSelection,
-                              nsresult aResult)
+TextEditRules::DidInsertBreak(nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-TextEditRules::CollapseSelectionToTrailingBRIfNeeded(Selection* aSelection)
+TextEditRules::CollapseSelectionToTrailingBRIfNeeded()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   // we only need to execute the stuff below if we are a plaintext editor.
   // html editors have a different mechanism for putting in mozBR's
   // (because there are a bunch more places you have to worry about it in html)
   if (!IsPlaintextEditor()) {
     return NS_OK;
@@ -668,27 +662,26 @@ TextEditRules::HandleNewLines(nsString& 
       // even if we're pasting newlines, don't paste leading/trailing ones
       aString.Trim(CRLF, true, true);
       break;
   }
 }
 
 nsresult
 TextEditRules::WillInsertText(EditAction aAction,
-                              Selection* aSelection,
                               bool* aCancel,
                               bool* aHandled,
                               const nsAString* inString,
                               nsAString* outString,
                               int32_t aMaxLength)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
   }
 
   if (inString->IsEmpty() && aAction != EditAction::insertIMEText) {
     // HACK: this is a fix for bug 19395
     // I can't outlaw all empty insertions
     // because IME transaction depend on them
     // There is more work to do to make the
     // world safe for IME.
@@ -699,18 +692,18 @@ TextEditRules::WillInsertText(EditAction
 
   // initialize out param
   *aCancel = false;
   *aHandled = true;
 
   // handle docs with a max length
   // NOTE, this function copies inString into outString for us.
   bool truncated = false;
-  nsresult rv = TruncateInsertionIfNeeded(&SelectionRef(), inString, outString,
-                                          aMaxLength, &truncated);
+  nsresult rv =
+    TruncateInsertionIfNeeded(inString, outString, aMaxLength, &truncated);
   NS_ENSURE_SUCCESS(rv, rv);
   // If we're exceeding the maxlength when composing IME, we need to clean up
   // the composing text, so we shouldn't return early.
   if (truncated && outString->IsEmpty() &&
       aAction != EditAction::insertIMEText) {
     *aCancel = true;
     return NS_OK;
   }
@@ -729,17 +722,17 @@ TextEditRules::WillInsertText(EditAction
   if (!SelectionRef().IsCollapsed()) {
     rv = TextEditorRef().DeleteSelectionAsAction(nsIEditor::eNone,
                                                  nsIEditor::eStrip);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
 
-  WillInsert(SelectionRef(), aCancel);
+  WillInsert(aCancel);
   // initialize out param
   // we want to ignore result of WillInsert()
   *aCancel = false;
 
   // handle password field data
   // this has the side effect of changing all the characters in aOutString
   // to the replacement character
   if (IsPasswordEditor() &&
@@ -858,25 +851,23 @@ TextEditRules::WillInsertText(EditAction
         "Failed to collapse selection after inserting string");
     }
   }
   ASSERT_PASSWORD_LENGTHS_EQUAL()
   return NS_OK;
 }
 
 nsresult
-TextEditRules::DidInsertText(Selection* aSelection,
-                             nsresult aResult)
+TextEditRules::DidInsertText(nsresult aResult)
 {
-  return DidInsert(aSelection, aResult);
+  return DidInsert(aResult);
 }
 
 nsresult
-TextEditRules::WillSetText(Selection& aSelection,
-                           bool* aCancel,
+TextEditRules::WillSetText(bool* aCancel,
                            bool* aHandled,
                            const nsAString* aString,
                            int32_t aMaxLength)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
   MOZ_ASSERT(aCancel);
   MOZ_ASSERT(aHandled);
   MOZ_ASSERT(aString);
@@ -893,17 +884,17 @@ TextEditRules::WillSetText(Selection& aS
   }
 
   if (IsPasswordEditor() && LookAndFeel::GetEchoPassword() &&
       !DontEchoPassword()) {
     // Echo password timer will implement on InsertText.
     return NS_OK;
   }
 
-  WillInsert(SelectionRef(), aCancel);
+  WillInsert(aCancel);
   // we want to ignore result of WillInsert()
   *aCancel = false;
 
   RefPtr<Element> rootElement = TextEditorRef().GetRoot();
   uint32_t count = rootElement->GetChildCount();
 
   // handles only when there is only one node and it's a text node, or empty.
 
@@ -962,78 +953,72 @@ TextEditRules::WillSetText(Selection& aS
   *aHandled = true;
 
   ASSERT_PASSWORD_LENGTHS_EQUAL();
 
   return NS_OK;
 }
 
 nsresult
-TextEditRules::DidSetText(Selection& aSelection,
-                          nsresult aResult)
+TextEditRules::DidSetText(nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-TextEditRules::WillSetTextProperty(Selection* aSelection,
-                                   bool* aCancel,
+TextEditRules::WillSetTextProperty(bool* aCancel,
                                    bool* aHandled)
 {
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
   }
 
   // XXX: should probably return a success value other than NS_OK that means "not allowed"
   if (IsPlaintextEditor()) {
     *aCancel = true;
   }
   return NS_OK;
 }
 
 nsresult
-TextEditRules::DidSetTextProperty(Selection* aSelection,
-                                  nsresult aResult)
+TextEditRules::DidSetTextProperty(nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-TextEditRules::WillRemoveTextProperty(Selection* aSelection,
-                                      bool* aCancel,
+TextEditRules::WillRemoveTextProperty(bool* aCancel,
                                       bool* aHandled)
 {
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
   }
 
   // XXX: should probably return a success value other than NS_OK that means "not allowed"
   if (IsPlaintextEditor()) {
     *aCancel = true;
   }
   return NS_OK;
 }
 
 nsresult
-TextEditRules::DidRemoveTextProperty(Selection* aSelection,
-                                     nsresult aResult)
+TextEditRules::DidRemoveTextProperty(nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
-TextEditRules::WillDeleteSelection(Selection* aSelection,
-                                   nsIEditor::EDirection aCollapsedAction,
+TextEditRules::WillDeleteSelection(nsIEditor::EDirection aCollapsedAction,
                                    bool* aCancel,
                                    bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
   }
   CANCEL_OPERATION_IF_READONLY_OR_DISABLED
 
   // initialize out param
   *aCancel = false;
   *aHandled = false;
 
   // if there is only bogus content, cancel the operation
@@ -1099,18 +1084,17 @@ TextEditRules::WillDeleteSelection(Selec
     }
 
     if (!SelectionRef().IsCollapsed()) {
       return NS_OK;
     }
 
     // Test for distance between caret and text that will be deleted
     nsresult rv =
-      CheckBidiLevelForDeletion(&SelectionRef(), selectionStartPoint,
-                                aCollapsedAction, aCancel);
+      CheckBidiLevelForDeletion(selectionStartPoint, aCollapsedAction, aCancel);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
     if (*aCancel) {
       return NS_OK;
     }
 
     rv = TextEditorRef().ExtendSelectionForDelete(&SelectionRef(),
@@ -1128,18 +1112,17 @@ TextEditRules::WillDeleteSelection(Selec
   }
 
   *aHandled = true;
   ASSERT_PASSWORD_LENGTHS_EQUAL()
   return NS_OK;
 }
 
 nsresult
-TextEditRules::DidDeleteSelection(Selection* aSelection,
-                                  nsIEditor::EDirection aCollapsedAction,
+TextEditRules::DidDeleteSelection(nsIEditor::EDirection aCollapsedAction,
                                   nsresult aResult)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   EditorRawDOMPoint selectionStartPoint(
                       EditorBase::GetStartPoint(&SelectionRef()));
   if (NS_WARN_IF(!selectionStartPoint.IsSet())) {
     return NS_ERROR_FAILURE;
@@ -1163,84 +1146,78 @@ TextEditRules::DidDeleteSelection(Select
   // (i.e. the end of previous line) after this deletion.  Bug 92124
   ErrorResult err;
   SelectionRef().SetInterlinePosition(true, err);
   NS_WARNING_ASSERTION(!err.Failed(), "Failed to set interline position");
   return err.StealNSResult();
 }
 
 nsresult
-TextEditRules::WillUndo(Selection* aSelection,
-                        bool* aCancel,
+TextEditRules::WillUndo(bool* aCancel,
                         bool* aHandled)
 {
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
   }
   CANCEL_OPERATION_IF_READONLY_OR_DISABLED
   // initialize out param
   *aCancel = false;
   *aHandled = false;
   return NS_OK;
 }
 
 /**
  * The idea here is to see if the magic empty node has suddenly reappeared as
  * the result of the undo.  If it has, set our state so we remember it.
  * There is a tradeoff between doing here and at redo, or doing it everywhere
  * else that might care.  Since undo and redo are relatively rare, it makes
  * sense to take the (small) performance hit here.
  */
 nsresult
-TextEditRules::DidUndo(Selection* aSelection,
-                       nsresult aResult)
+TextEditRules::DidUndo(nsresult aResult)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
   // If aResult is an error, we return it.
-  NS_ENSURE_SUCCESS(aResult, aResult);
+  if (NS_WARN_IF(NS_FAILED(aResult))) {
+    return aResult;
+  }
 
   Element* rootElement = TextEditorRef().GetRoot();
   if (NS_WARN_IF(!rootElement)) {
     return NS_ERROR_FAILURE;
   }
   nsIContent* node = TextEditorRef().GetLeftmostChild(rootElement);
   if (node && TextEditorRef().IsMozEditorBogusNode(node)) {
     mBogusNode = node;
   } else {
     mBogusNode = nullptr;
   }
   return aResult;
 }
 
 nsresult
-TextEditRules::WillRedo(Selection* aSelection,
-                        bool* aCancel,
+TextEditRules::WillRedo(bool* aCancel,
                         bool* aHandled)
 {
-  if (!aSelection || !aCancel || !aHandled) {
-    return NS_ERROR_NULL_POINTER;
+  if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
+    return NS_ERROR_INVALID_ARG;
   }
   CANCEL_OPERATION_IF_READONLY_OR_DISABLED
   // initialize out param
   *aCancel = false;
   *aHandled = false;
   return NS_OK;
 }
 
 nsresult
-TextEditRules::DidRedo(Selection* aSelection,
-                       nsresult aResult)
+TextEditRules::DidRedo(nsresult aResult)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (!aSelection) {
-    return NS_ERROR_NULL_POINTER;
-  }
   if (NS_FAILED(aResult)) {
     return aResult; // if aResult is an error, we return it.
   }
 
   Element* rootElement = TextEditorRef().GetRoot();
   if (NS_WARN_IF(!rootElement)) {
     return NS_ERROR_FAILURE;
   }
@@ -1261,18 +1238,17 @@ TextEditRules::DidRedo(Selection* aSelec
     mBogusNode = brElement;
   } else {
     mBogusNode = nullptr;
   }
   return NS_OK;
 }
 
 nsresult
-TextEditRules::WillOutputText(Selection* aSelection,
-                              const nsAString* aOutputFormat,
+TextEditRules::WillOutputText(const nsAString* aOutputFormat,
                               nsAString* aOutString,
                               uint32_t aFlags,
                               bool* aCancel,
                               bool* aHandled)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   // null selection ok
@@ -1374,18 +1350,17 @@ TextEditRules::WillOutputText(Selection*
   // Otherwise, the text is the value.
   text->GetData(*aOutString);
 
   *aHandled = true;
   return NS_OK;
 }
 
 nsresult
-TextEditRules::DidOutputText(Selection* aSelection,
-                             nsresult aResult)
+TextEditRules::DidOutputText(nsresult aResult)
 {
   return NS_OK;
 }
 
 nsresult
 TextEditRules::RemoveRedundantTrailingBR()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
@@ -1478,22 +1453,20 @@ TextEditRules::CreateTrailingBRIfNeeded(
                                     false);
   lastChild->AsElement()->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
                                   NS_LITERAL_STRING("_moz"),
                                   true);
   return NS_OK;
 }
 
 nsresult
-TextEditRules::CreateBogusNodeIfNeeded(Selection* aSelection)
+TextEditRules::CreateBogusNodeIfNeeded()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  NS_ENSURE_TRUE(aSelection, NS_ERROR_NULL_POINTER);
-
   if (mBogusNode) {
     // Let's not create more than one, ok?
     return NS_OK;
   }
 
   // tell rules system to not do any post-processing
   AutoRules beginRulesSniffing(&TextEditorRef(), EditAction::ignore,
                                nsIEditor::eNone);
@@ -1552,26 +1525,25 @@ TextEditRules::CreateBogusNodeIfNeeded(S
   SelectionRef().Collapse(EditorRawDOMPoint(rootElement, 0), error);
   NS_WARNING_ASSERTION(!error.Failed(),
     "Failed to collapse selection at start of the root element");
   return NS_OK;
 }
 
 
 nsresult
-TextEditRules::TruncateInsertionIfNeeded(Selection* aSelection,
-                                         const nsAString* aInString,
+TextEditRules::TruncateInsertionIfNeeded(const nsAString* aInString,
                                          nsAString* aOutString,
                                          int32_t aMaxLength,
                                          bool* aTruncated)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
-  if (!aSelection || !aInString || !aOutString) {
-    return NS_ERROR_NULL_POINTER;
+  if (NS_WARN_IF(!aInString) || NS_WARN_IF(!aOutString)) {
+    return NS_ERROR_INVALID_ARG;
   }
 
   if (!aOutString->Assign(*aInString, mozilla::fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   if (aTruncated) {
     *aTruncated = false;
   }
--- a/editor/libeditor/TextEditRules.h
+++ b/editor/libeditor/TextEditRules.h
@@ -125,98 +125,89 @@ public:
   }
 
 protected:
 
   void InitFields();
 
   // TextEditRules implementation methods
   nsresult WillInsertText(EditAction aAction,
-                          Selection* aSelection,
                           bool* aCancel,
                           bool* aHandled,
                           const nsAString* inString,
                           nsAString* outString,
                           int32_t aMaxLength);
-  nsresult DidInsertText(Selection* aSelection, nsresult aResult);
+  nsresult DidInsertText(nsresult aResult);
 
-  nsresult WillInsertBreak(Selection* aSelection, bool* aCancel,
-                           bool* aHandled, int32_t aMaxLength);
-  nsresult DidInsertBreak(Selection* aSelection, nsresult aResult);
+  nsresult WillInsertBreak(bool* aCancel, bool* aHandled, int32_t aMaxLength);
+  nsresult DidInsertBreak(nsresult aResult);
 
-  nsresult WillSetText(Selection& aSelection,
-                       bool* aCancel,
+  nsresult WillSetText(bool* aCancel,
                        bool* aHandled,
                        const nsAString* inString,
                        int32_t aMaxLength);
-  nsresult DidSetText(Selection& aSelection, nsresult aResult);
+  nsresult DidSetText(nsresult aResult);
 
-  void WillInsert(Selection& aSelection, bool* aCancel);
-  nsresult DidInsert(Selection* aSelection, nsresult aResult);
+  void WillInsert(bool* aCancel);
+  nsresult DidInsert(nsresult aResult);
 
-  nsresult WillDeleteSelection(Selection* aSelection,
-                               nsIEditor::EDirection aCollapsedAction,
+  nsresult WillDeleteSelection(nsIEditor::EDirection aCollapsedAction,
                                bool* aCancel,
                                bool* aHandled);
-  nsresult DidDeleteSelection(Selection* aSelection,
-                              nsIEditor::EDirection aCollapsedAction,
+  nsresult DidDeleteSelection(nsIEditor::EDirection aCollapsedAction,
                               nsresult aResult);
 
-  nsresult WillSetTextProperty(Selection* aSelection, bool* aCancel,
-                               bool* aHandled);
-  nsresult DidSetTextProperty(Selection* aSelection, nsresult aResult);
+  nsresult WillSetTextProperty(bool* aCancel, bool* aHandled);
+  nsresult DidSetTextProperty(nsresult aResult);
+
+  nsresult WillRemoveTextProperty(bool* aCancel, bool* aHandled);
+  nsresult DidRemoveTextProperty(nsresult aResult);
 
-  nsresult WillRemoveTextProperty(Selection* aSelection, bool* aCancel,
-                                  bool* aHandled);
-  nsresult DidRemoveTextProperty(Selection* aSelection, nsresult aResult);
+  nsresult WillUndo(bool* aCancel, bool* aHandled);
+  nsresult DidUndo(nsresult aResult);
 
-  nsresult WillUndo(Selection* aSelection, bool* aCancel, bool* aHandled);
-  nsresult DidUndo(Selection* aSelection, nsresult aResult);
-
-  nsresult WillRedo(Selection* aSelection, bool* aCancel, bool* aHandled);
-  nsresult DidRedo(Selection* aSelection, nsresult aResult);
+  nsresult WillRedo(bool* aCancel, bool* aHandled);
+  nsresult DidRedo(nsresult aResult);
 
   /**
    * Called prior to nsIEditor::OutputToString.
-   * @param aSelection
+   *
    * @param aInFormat  The format requested for the output, a MIME type.
    * @param aOutText   The string to use for output, if aCancel is set to true.
    * @param aOutCancel If set to true, the caller should cancel the operation
    *                   and use aOutText as the result.
    */
-  nsresult WillOutputText(Selection* aSelection,
-                          const nsAString* aInFormat,
+  nsresult WillOutputText(const nsAString* aInFormat,
                           nsAString* aOutText,
                           uint32_t aFlags,
                           bool* aOutCancel,
                           bool* aHandled);
 
-  nsresult DidOutputText(Selection* aSelection, nsresult aResult);
+  nsresult DidOutputText(nsresult aResult);
 
   /**
    * Check for and replace a redundant trailing break.
    */
   nsresult RemoveRedundantTrailingBR();
 
   /**
    * Creates a trailing break in the text doc if there is not one already.
    */
   nsresult CreateTrailingBRIfNeeded();
 
   /**
    * Creates a bogus text node if the document has no editable content.
    */
-  nsresult CreateBogusNodeIfNeeded(Selection* aSelection);
+  nsresult CreateBogusNodeIfNeeded();
 
   /**
    * Returns a truncated insertion string if insertion would place us over
    * aMaxLength
    */
-  nsresult TruncateInsertionIfNeeded(Selection* aSelection,
-                                     const nsAString* aInString,
+  nsresult TruncateInsertionIfNeeded(const nsAString* aInString,
                                      nsAString* aOutString,
                                      int32_t aMaxLength,
                                      bool* aTruncated);
 
   /**
    * Remove IME composition text from password buffer.
    */
   void RemoveIMETextFromPWBuf(uint32_t& aStart, nsAString* aIMEString);
@@ -258,26 +249,25 @@ protected:
    * @param aCreateMozBR        true if the caller wants to create a moz-<br>
    *                            element.  Otherwise, false.
    * @return                    Returns created <br> element.
    */
   already_AddRefed<Element>
   CreateBRInternal(const EditorRawDOMPoint& aPointToInsert,
                    bool aCreateMozBR);
 
-  void UndefineCaretBidiLevel(Selection* aSelection);
+  void UndefineCaretBidiLevel();
 
-  nsresult CheckBidiLevelForDeletion(Selection* aSelection,
-                                     const EditorRawDOMPoint& aSelectionPoint,
+  nsresult CheckBidiLevelForDeletion(const EditorRawDOMPoint& aSelectionPoint,
                                      nsIEditor::EDirection aAction,
                                      bool* aCancel);
 
   nsresult HideLastPWInput();
 
-  nsresult CollapseSelectionToTrailingBRIfNeeded(Selection* aSelection);
+  nsresult CollapseSelectionToTrailingBRIfNeeded();
 
   bool IsPasswordEditor() const;
   bool IsSingleLineEditor() const;
   bool IsPlaintextEditor() const;
   bool IsReadonly() const;
   bool IsDisabled() const;
   bool IsMailEditor() const;
   bool DontEchoPassword() const;
--- a/editor/libeditor/TextEditRulesBidi.cpp
+++ b/editor/libeditor/TextEditRulesBidi.cpp
@@ -20,17 +20,16 @@
 
 namespace mozilla {
 
 using namespace dom;
 
 // Test for distance between caret and text that will be deleted
 nsresult
 TextEditRules::CheckBidiLevelForDeletion(
-                 Selection* aSelection,
                  const EditorRawDOMPoint& aSelectionPoint,
                  nsIEditor::EDirection aAction,
                  bool* aCancel)
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   if (NS_WARN_IF(!aCancel)) {
     return NS_ERROR_INVALID_ARG;
@@ -80,17 +79,17 @@ TextEditRules::CheckBidiLevelForDeletion
 
   // Set the bidi level of the caret to that of the
   // character that will be (or would have been) deleted
   frameSelection->SetCaretBidiLevel(levelOfDeletion);
   return NS_OK;
 }
 
 void
-TextEditRules::UndefineCaretBidiLevel(Selection* aSelection)
+TextEditRules::UndefineCaretBidiLevel()
 {
   MOZ_ASSERT(IsEditorDataAvailable());
 
   /**
    * After inserting text the caret Bidi level must be set to the level of the
    * inserted text.This is difficult, because we cannot know what the level is
    * until after the Bidi algorithm is applied to the whole paragraph.
    *