From ff48c12997f7bb78081aba39bf6d7771194ce1e4 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Fri, 17 Jun 2022 04:13:04 +0000 Subject: [PATCH] Bug 1770877 - part 8: Get rid of `HTMLEditor::CollectEditTargetNodesInExtendedSelectionRanges` r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D149072 --- editor/libeditor/HTMLEditor.h | 44 +++++------------ editor/libeditor/HTMLEditorState.cpp | 71 ++++++++++++++++++---------- 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/editor/libeditor/HTMLEditor.h b/editor/libeditor/HTMLEditor.h index 784a3e79f1ca..702e8e4576c1 100644 --- a/editor/libeditor/HTMLEditor.h +++ b/editor/libeditor/HTMLEditor.h @@ -1223,8 +1223,6 @@ class HTMLEditor final : public EditorBase, * CollectEditTargetNodes() collects edit target nodes in aArrayOfRanges. * First, this collects all nodes in given ranges, then, modifies the * result for specific edit sub-actions. - * FYI: You can use CollectEditTargetNodesInExtendedSelectionRanges() instead - * if you want to call this with extended selection ranges. */ nsresult CollectEditTargetNodes( nsTArray>& aArrayOfRanges, @@ -1308,26 +1306,6 @@ class HTMLEditor final : public EditorBase, nsTArray>& aOutArrayOfRanges, EditSubAction aEditSubAction); - /** - * CollectEditTargetNodesInExtendedSelectionRanges() calls - * CollectEditTargetNodes() with result of - * GetSelectionRangesExtendedToHardLineStartAndEnd(). See comments for these - * methods for the detail. - */ - nsresult CollectEditTargetNodesInExtendedSelectionRanges( - nsTArray>& aOutArrayOfContents, - EditSubAction aEditSubAction, - CollectNonEditableNodes aCollectNonEditableNodes) { - AutoTArray, 4> extendedSelectionRanges; - GetSelectionRangesExtendedToHardLineStartAndEnd(extendedSelectionRanges, - aEditSubAction); - nsresult rv = - CollectEditTargetNodes(extendedSelectionRanges, aOutArrayOfContents, - aEditSubAction, aCollectNonEditableNodes); - NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "CollectEditTargetNodes() failed"); - return rv; - } - /** * SelectBRElementIfCollapsedInEmptyBlock() helper method for * CreateRangeIncludingAdjuscentWhiteSpaces() and @@ -4590,11 +4568,13 @@ class HTMLEditor final : public EditorBase, friend class JoinNodesTransaction; // DidJoinNodesTransaction, DoJoinNodes, // DoSplitNode, RangeUpdaterRef friend class - ListElementSelectionState; // CollectEditTargetNodesInExtendedSelectionRanges, - // CollectNonEditableNodes + ListElementSelectionState; // CollectEditTargetNodes, + // CollectNonEditableNodes, + // GetSelectionRangesExtendedToHardLineStartAndEnd friend class - ListItemElementSelectionState; // CollectEditTargetNodesInExtendedSelectionRanges, - // CollectNonEditableNodes + ListItemElementSelectionState; // CollectEditTargetNodes, + // CollectNonEditableNodes, + // GetSelectionRangesExtendedToHardLineStartAndEnd friend class MoveNodeResult; // AllowsTransactionsToChangeSelection, // CollapseSelectionTo friend class MoveNodeTransaction; // AllowsTransactionsToChangeSelection, @@ -4602,10 +4582,11 @@ class HTMLEditor final : public EditorBase, // RangeUpdaterRef friend class ParagraphStateAtSelection; // CollectChildren, - // CollectEditTargetNodesInExtendedSelectionRanges, + // CollectEditTargetNodes, // CollectListChildren, // CollectNonEditableNodes, - // CollectTableChildren + // CollectTableChildren, + // GetSelectionRangesExtendedToHardLineStartAndEnd friend class SlurpBlobEventListener; // BlobReader friend class SplitNodeResult; // CollapseSelectionTo friend class SplitNodeTransaction; // DoJoinNodes, DoSplitNode @@ -4742,9 +4723,10 @@ class MOZ_STACK_CLASS ParagraphStateAtSelection final { /** * CollectEditableFormatNodesInSelection() collects only editable nodes * around selection ranges (with - * `HTMLEditor::CollectEditTargetNodesInExtendedSelectionRanges()`, see its - * document for the detail). If it includes list, list item or table - * related elements, they will be replaced their children. + * `HTMLEditor::GetSelectionRangesExtendedToHardLineStartAndEnd()` and + * `HTMLEditor::CollectEditTargetNodes()`, see its document for the detail). + * If it includes list, list item or table related elements, they will be + * replaced their children. */ static nsresult CollectEditableFormatNodesInSelection( HTMLEditor& aHTMLEditor, diff --git a/editor/libeditor/HTMLEditorState.cpp b/editor/libeditor/HTMLEditorState.cpp index 818f17b1a223..deebe9f62739 100644 --- a/editor/libeditor/HTMLEditorState.cpp +++ b/editor/libeditor/HTMLEditorState.cpp @@ -65,15 +65,21 @@ ListElementSelectionState::ListElementSelectionState(HTMLEditor& aHTMLEditor, } AutoTArray, 64> arrayOfContents; - nsresult rv = aHTMLEditor.CollectEditTargetNodesInExtendedSelectionRanges( - arrayOfContents, EditSubAction::eCreateOrChangeList, - HTMLEditor::CollectNonEditableNodes::No); - if (NS_FAILED(rv)) { - NS_WARNING( - "HTMLEditor::CollectEditTargetNodesInExtendedSelectionRanges(" - "eCreateOrChangeList, CollectNonEditableNodes::No) failed"); - aRv = EditorBase::ToGenericNSResult(rv); - return; + { + AutoTArray, 4> extendedSelectionRanges; + aHTMLEditor.GetSelectionRangesExtendedToHardLineStartAndEnd( + extendedSelectionRanges, EditSubAction::eCreateOrChangeList); + nsresult rv = aHTMLEditor.CollectEditTargetNodes( + extendedSelectionRanges, arrayOfContents, + EditSubAction::eCreateOrChangeList, + HTMLEditor::CollectNonEditableNodes::No); + if (NS_FAILED(rv)) { + NS_WARNING( + "HTMLEditor::CollectEditTargetNodes(EditSubAction::" + "eCreateOrChangeList, CollectNonEditableNodes::No) failed"); + aRv = EditorBase::ToGenericNSResult(rv); + return; + } } // Examine list type for nodes in selection. @@ -130,15 +136,22 @@ ListItemElementSelectionState::ListItemElementSelectionState( } AutoTArray, 64> arrayOfContents; - nsresult rv = aHTMLEditor.CollectEditTargetNodesInExtendedSelectionRanges( - arrayOfContents, EditSubAction::eCreateOrChangeList, - HTMLEditor::CollectNonEditableNodes::No); - if (NS_FAILED(rv)) { - NS_WARNING( - "HTMLEditor::CollectEditTargetNodesInExtendedSelectionRanges(" - "eCreateOrChangeList, CollectNonEditableNodes::No) failed"); - aRv = EditorBase::ToGenericNSResult(rv); - return; + { + AutoTArray, 4> extendedSelectionRanges; + aHTMLEditor.GetSelectionRangesExtendedToHardLineStartAndEnd( + extendedSelectionRanges, EditSubAction::eCreateOrChangeList); + nsresult rv = aHTMLEditor.CollectEditTargetNodes( + extendedSelectionRanges, arrayOfContents, + EditSubAction::eCreateOrChangeList, + HTMLEditor::CollectNonEditableNodes::No); + if (NS_FAILED(rv)) { + NS_WARNING_ASSERTION( + NS_SUCCEEDED(rv), + "HTMLEditor::CollectEditTargetNodes(EditSubAction::" + "eCreateOrChangeList, CollectNonEditableNodes::No) failed"); + aRv = EditorBase::ToGenericNSResult(rv); + return; + } } // examine list type for nodes in selection @@ -570,14 +583,20 @@ void ParagraphStateAtSelection::AppendDescendantFormatNodesAndFirstInlineNode( nsresult ParagraphStateAtSelection::CollectEditableFormatNodesInSelection( HTMLEditor& aHTMLEditor, nsTArray>& aArrayOfContents) { - nsresult rv = aHTMLEditor.CollectEditTargetNodesInExtendedSelectionRanges( - aArrayOfContents, EditSubAction::eCreateOrRemoveBlock, - HTMLEditor::CollectNonEditableNodes::Yes); - if (NS_FAILED(rv)) { - NS_WARNING( - "HTMLEditor::CollectEditTargetNodesInExtendedSelectionRanges(" - "eCreateOrRemoveBlock, CollectNonEditableNodes::Yes) failed"); - return rv; + { + AutoTArray, 4> extendedSelectionRanges; + aHTMLEditor.GetSelectionRangesExtendedToHardLineStartAndEnd( + extendedSelectionRanges, EditSubAction::eCreateOrRemoveBlock); + nsresult rv = aHTMLEditor.CollectEditTargetNodes( + extendedSelectionRanges, aArrayOfContents, + EditSubAction::eCreateOrRemoveBlock, + HTMLEditor::CollectNonEditableNodes::Yes); + if (NS_FAILED(rv)) { + NS_WARNING( + "HTMLEditor::CollectEditTargetNodes(EditSubAction::" + "eCreateOrRemoveBlock, CollectNonEditableNodes::Yes) failed"); + return rv; + } } // Pre-process our list of nodes