Bug 1770877 - part 8: Get rid of `HTMLEditor::CollectEditTargetNodesInExtendedSelectionRanges` r=m_kato

Differential Revision: https://phabricator.services.mozilla.com/D149072
This commit is contained in:
Masayuki Nakano 2022-06-17 04:13:04 +00:00
Родитель 78b8f46027
Коммит ff48c12997
2 изменённых файлов: 58 добавлений и 57 удалений

Просмотреть файл

@ -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<RefPtr<nsRange>>& aArrayOfRanges,
@ -1308,26 +1306,6 @@ class HTMLEditor final : public EditorBase,
nsTArray<RefPtr<nsRange>>& aOutArrayOfRanges,
EditSubAction aEditSubAction);
/**
* CollectEditTargetNodesInExtendedSelectionRanges() calls
* CollectEditTargetNodes() with result of
* GetSelectionRangesExtendedToHardLineStartAndEnd(). See comments for these
* methods for the detail.
*/
nsresult CollectEditTargetNodesInExtendedSelectionRanges(
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents,
EditSubAction aEditSubAction,
CollectNonEditableNodes aCollectNonEditableNodes) {
AutoTArray<RefPtr<nsRange>, 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,

Просмотреть файл

@ -65,15 +65,21 @@ ListElementSelectionState::ListElementSelectionState(HTMLEditor& aHTMLEditor,
}
AutoTArray<OwningNonNull<nsIContent>, 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<RefPtr<nsRange>, 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<OwningNonNull<nsIContent>, 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<RefPtr<nsRange>, 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<OwningNonNull<nsIContent>>& 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<RefPtr<nsRange>, 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