Bug 1770877 - part 13: Move `HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd` into `AutoRangeArray` r=m_kato

This patch makes them take `const Element& aEditingHost` so that this patch
becomes bigger than what this patch does.

Differential Revision: https://phabricator.services.mozilla.com/D149077
This commit is contained in:
Masayuki Nakano 2022-06-17 08:23:20 +00:00
Родитель 6e5fc9e18e
Коммит de381e88aa
8 изменённых файлов: 250 добавлений и 247 удалений

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

@ -451,8 +451,8 @@ enum class EditSubAction : int32_t {
// eMergeBlockContents is not an actual sub-action, but this is used by // eMergeBlockContents is not an actual sub-action, but this is used by
// HTMLEditor::MoveBlock() to request special handling in // HTMLEditor::MoveBlock() to request special handling in
// HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd() and // AutoRangeArray::CreateRangeWrappingStartAndEndLinesContainingBoundaries()
// HTMLEditor::SplitInlinesAndCollectEditTargetNodes(). // and HTMLEditor::SplitInlinesAndCollectEditTargetNodes().
eMergeBlockContents, eMergeBlockContents,
// eRemoveList removes specific type of list but keep its content. // eRemoveList removes specific type of list but keep its content.

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

@ -480,9 +480,18 @@ void AutoRangeArray::
} }
} }
// static /**
EditorDOMPoint * Get the point before the line containing aPointInLine.
AutoRangeArray::GetPointAtFirstContentOfLineOrParentBlockIfFirstContentOfBlock( *
* @return If the line starts after a `<br>` element, returns next
* sibling of the `<br>` element.
* If the line is first line of a block, returns point of
* the block.
* NOTE: The result may be point of editing host. I.e., the container may be
* outside of editing host.
*/
static EditorDOMPoint
GetPointAtFirstContentOfLineOrParentBlockIfFirstContentOfBlock(
const EditorDOMPoint& aPointInLine, EditSubAction aEditSubAction, const EditorDOMPoint& aPointInLine, EditSubAction aEditSubAction,
const Element& aEditingHost) { const Element& aEditingHost) {
// FYI: This was moved from // FYI: This was moved from
@ -580,9 +589,19 @@ AutoRangeArray::GetPointAtFirstContentOfLineOrParentBlockIfFirstContentOfBlock(
return point; return point;
} }
// static /**
EditorDOMPoint * Get the point after the following line break or the block which breaks the
AutoRangeArray::GetPointAfterFollowingLineBreakOrAtFollowingBlock( * line containing aPointInLine.
*
* @return If the line ends with a visible `<br>` element, returns
* the point after the `<br>` element.
* If the line ends with a preformatted linefeed, returns
* the point after the linefeed unless it's an invisible
* line break immediately before a block boundary.
* If the line ends with a block boundary, returns the
* point of the block.
*/
static EditorDOMPoint GetPointAfterFollowingLineBreakOrAtFollowingBlock(
const EditorDOMPoint& aPointInLine, const Element& aEditingHost) { const EditorDOMPoint& aPointInLine, const Element& aEditingHost) {
// FYI: This was moved from // FYI: This was moved from
// https://searchfox.org/mozilla-central/rev/3419858c997f422e3e70020a46baae7f0ec6dacc/editor/libeditor/HTMLEditSubActionHandler.cpp#6541 // https://searchfox.org/mozilla-central/rev/3419858c997f422e3e70020a46baae7f0ec6dacc/editor/libeditor/HTMLEditSubActionHandler.cpp#6541
@ -728,6 +747,77 @@ AutoRangeArray::GetPointAfterFollowingLineBreakOrAtFollowingBlock(
return point; return point;
} }
// static
already_AddRefed<nsRange>
AutoRangeArray::CreateRangeWrappingStartAndEndLinesContainingBoundaries(
const EditorDOMRange& aRange, EditSubAction aEditSubAction,
const Element& aEditingHost) {
if (!aRange.IsPositioned()) {
return nullptr;
}
return CreateRangeWrappingStartAndEndLinesContainingBoundaries(
aRange.StartRef(), aRange.EndRef(), aEditSubAction, aEditingHost);
}
// static
already_AddRefed<nsRange>
AutoRangeArray::CreateRangeWrappingStartAndEndLinesContainingBoundaries(
const EditorDOMPoint& aStartPoint, const EditorDOMPoint& aEndPoint,
EditSubAction aEditSubAction, const Element& aEditingHost) {
MOZ_DIAGNOSTIC_ASSERT(!aStartPoint.IsInNativeAnonymousSubtree());
MOZ_DIAGNOSTIC_ASSERT(!aEndPoint.IsInNativeAnonymousSubtree());
if (NS_WARN_IF(!aStartPoint.IsSet()) || NS_WARN_IF(!aEndPoint.IsSet())) {
return nullptr;
}
EditorDOMPoint startPoint(aStartPoint), endPoint(aEndPoint);
AutoRangeArray::UpdatePointsToSelectAllChildrenIfCollapsedInEmptyBlockElement(
startPoint, endPoint, aEditingHost);
// Make a new adjusted range to represent the appropriate block content.
// This is tricky. The basic idea is to push out the range endpoints to
// truly enclose the blocks that we will affect.
// Make sure that the new range ends up to be in the editable section.
// XXX Looks like that this check wastes the time. Perhaps, we should
// implement a method which checks both two DOM points in the editor
// root.
startPoint = GetPointAtFirstContentOfLineOrParentBlockIfFirstContentOfBlock(
startPoint, aEditSubAction, aEditingHost);
// XXX GetPointAtFirstContentOfLineOrParentBlockIfFirstContentOfBlock() may
// return point of editing host. Perhaps, we should change it and stop
// checking it here since this check may be expensive.
// XXX If the container is an element in the editing host but it points end of
// the container, this returns nullptr. Is it intentional?
if (!startPoint.GetChildOrContainerIfDataNode() ||
!startPoint.GetChildOrContainerIfDataNode()->IsInclusiveDescendantOf(
&aEditingHost)) {
return nullptr;
}
endPoint =
GetPointAfterFollowingLineBreakOrAtFollowingBlock(endPoint, aEditingHost);
const EditorDOMPoint lastRawPoint =
endPoint.IsStartOfContainer() ? endPoint : endPoint.PreviousPoint();
// XXX GetPointAfterFollowingLineBreakOrAtFollowingBlock() may return point of
// editing host. Perhaps, we should change it and stop checking it here
// since this check may be expensive.
// XXX If the container is an element in the editing host but it points end of
// the container, this returns nullptr. Is it intentional?
if (!lastRawPoint.GetChildOrContainerIfDataNode() ||
!lastRawPoint.GetChildOrContainerIfDataNode()->IsInclusiveDescendantOf(
&aEditingHost)) {
return nullptr;
}
RefPtr<nsRange> range =
nsRange::Create(startPoint.ToRawRangeBoundary(),
endPoint.ToRawRangeBoundary(), IgnoreErrors());
NS_WARNING_ASSERTION(range, "nsRange::Create() failed");
return range.forget();
}
/****************************************************************************** /******************************************************************************
* some general purpose editor utils * some general purpose editor utils
*****************************************************************************/ *****************************************************************************/

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

@ -580,34 +580,18 @@ class MOZ_STACK_CLASS AutoRangeArray final {
const dom::Element& aEditingHost); const dom::Element& aEditingHost);
/** /**
* Get the point before the line containing aPointInLine. * CreateRangeExtendedToHardLineStartAndEnd() creates an nsRange instance
* * which may be expanded to start/end of hard line at both edges of the given
* @return If the line starts after a `<br>` element, returns next * range. If this fails handling something, returns nullptr.
* sibling of the `<br>` element.
* If the line is first line of a block, returns point of
* the block.
* NOTE: The result may be point of editing host. I.e., the container may be
* outside of editing host.
*/ */
static EditorDOMPoint static already_AddRefed<nsRange>
GetPointAtFirstContentOfLineOrParentBlockIfFirstContentOfBlock( CreateRangeWrappingStartAndEndLinesContainingBoundaries(
const EditorDOMPoint& aPointInLine, EditSubAction aEditSubAction, const EditorDOMRange& aRange, EditSubAction aEditSubAction,
const dom::Element& aEditingHost); const dom::Element& aEditingHost);
static already_AddRefed<nsRange>
/** CreateRangeWrappingStartAndEndLinesContainingBoundaries(
* Get the point after the following line break or the block which breaks the const EditorDOMPoint& aStartPoint, const EditorDOMPoint& aEndPoint,
* line containing aPointInLine. EditSubAction aEditSubAction, const dom::Element& aEditingHost);
*
* @return If the line ends with a visible `<br>` element, returns
* the point after the `<br>` element.
* If the line ends with a preformatted linefeed, returns
* the point after the linefeed unless it's an invisible
* line break immediately before a block boundary.
* If the line ends with a block boundary, returns the
* point of the block.
*/
static EditorDOMPoint GetPointAfterFollowingLineBreakOrAtFollowingBlock(
const EditorDOMPoint& aPoint, const dom::Element& aEditingHost);
private: private:
AutoTArray<mozilla::OwningNonNull<nsRange>, 8> mRanges; AutoTArray<mozilla::OwningNonNull<nsRange>, 8> mRanges;

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

@ -129,28 +129,6 @@ HTMLEditor::CreateRangeIncludingAdjuscentWhiteSpaces(
template already_AddRefed<nsRange> template already_AddRefed<nsRange>
HTMLEditor::CreateRangeIncludingAdjuscentWhiteSpaces( HTMLEditor::CreateRangeIncludingAdjuscentWhiteSpaces(
const EditorRawDOMPoint& aStartPoint, const EditorRawDOMPoint& aEndPoint); const EditorRawDOMPoint& aStartPoint, const EditorRawDOMPoint& aEndPoint);
template already_AddRefed<nsRange>
HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd(
const EditorDOMRange& aRange, EditSubAction aEditSubAction) const;
template already_AddRefed<nsRange>
HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd(
const EditorRawDOMRange& aRange, EditSubAction aEditSubAction) const;
template already_AddRefed<nsRange>
HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd(
const EditorDOMPoint& aStartPoint, const EditorDOMPoint& aEndPoint,
EditSubAction aEditSubAction) const;
template already_AddRefed<nsRange>
HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd(
const EditorRawDOMPoint& aStartPoint, const EditorDOMPoint& aEndPoint,
EditSubAction aEditSubAction) const;
template already_AddRefed<nsRange>
HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd(
const EditorDOMPoint& aStartPoint, const EditorRawDOMPoint& aEndPoint,
EditSubAction aEditSubAction) const;
template already_AddRefed<nsRange>
HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd(
const EditorRawDOMPoint& aStartPoint, const EditorRawDOMPoint& aEndPoint,
EditSubAction aEditSubAction) const;
nsresult HTMLEditor::InitEditorContentAndSelection() { nsresult HTMLEditor::InitEditorContentAndSelection() {
MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(IsEditActionDataAvailable());
@ -368,7 +346,7 @@ nsresult HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal() {
AutoTransactionsConserveSelection dontChangeMySelection(*this); AutoTransactionsConserveSelection dontChangeMySelection(*this);
{ {
EditorRawDOMRange changedRange( EditorDOMRange changedRange(
*TopLevelEditSubActionDataRef().mChangedRange); *TopLevelEditSubActionDataRef().mChangedRange);
if (changedRange.IsPositioned() && if (changedRange.IsPositioned() &&
changedRange.EnsureNotInNativeAnonymousSubtree()) { changedRange.EnsureNotInNativeAnonymousSubtree()) {
@ -392,16 +370,18 @@ nsresult HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal() {
break; break;
} }
default: { default: {
RefPtr<nsRange> extendedChangedRange = if (Element* editingHost = ComputeEditingHost()) {
CreateRangeExtendedToHardLineStartAndEnd( if (RefPtr<nsRange> extendedChangedRange = AutoRangeArray::
changedRange, GetTopLevelEditSubAction()); CreateRangeWrappingStartAndEndLinesContainingBoundaries(
if (extendedChangedRange) { changedRange, GetTopLevelEditSubAction(),
MOZ_ASSERT(extendedChangedRange->IsPositioned()); *editingHost)) {
// Use extended range temporarily. MOZ_ASSERT(extendedChangedRange->IsPositioned());
TopLevelEditSubActionDataRef().mChangedRange = // Use extended range temporarily.
std::move(extendedChangedRange); TopLevelEditSubActionDataRef().mChangedRange =
std::move(extendedChangedRange);
}
break;
} }
break;
} }
} }
} }
@ -6422,6 +6402,8 @@ void HTMLEditor::GetSelectionRangesExtendedToHardLineStartAndEnd(
MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(aOutArrayOfRanges.IsEmpty()); MOZ_ASSERT(aOutArrayOfRanges.IsEmpty());
Element* editingHost = ComputeEditingHost();
const uint32_t rangeCount = SelectionRef().RangeCount(); const uint32_t rangeCount = SelectionRef().RangeCount();
aOutArrayOfRanges.SetCapacity(rangeCount); aOutArrayOfRanges.SetCapacity(rangeCount);
for (const uint32_t i : IntegerRange(rangeCount)) { for (const uint32_t i : IntegerRange(rangeCount)) {
@ -6431,14 +6413,18 @@ void HTMLEditor::GetSelectionRangesExtendedToHardLineStartAndEnd(
// blocks that we will affect. This call alters opRange. // blocks that we will affect. This call alters opRange.
nsRange* selectionRange = SelectionRef().GetRangeAt(i); nsRange* selectionRange = SelectionRef().GetRangeAt(i);
MOZ_ASSERT(selectionRange); MOZ_ASSERT(selectionRange);
EditorRawDOMRange rawRange(*selectionRange); EditorDOMRange editorRange(*selectionRange);
if (!rawRange.IsPositioned() || if (!editorRange.IsPositioned() ||
!rawRange.EnsureNotInNativeAnonymousSubtree()) { !editorRange.EnsureNotInNativeAnonymousSubtree()) {
continue; // ignore ranges which are in orphan fragment which were continue; // ignore ranges which are in orphan fragment which were
// disconnected from native anonymous subtrees // disconnected from native anonymous subtrees
} }
RefPtr<nsRange> extendedRange = RefPtr<nsRange> extendedRange;
CreateRangeExtendedToHardLineStartAndEnd(rawRange, aEditSubAction); if (editingHost) {
extendedRange = AutoRangeArray::
CreateRangeWrappingStartAndEndLinesContainingBoundaries(
editorRange, aEditSubAction, *editingHost);
}
if (!extendedRange) { if (!extendedRange) {
extendedRange = selectionRange->CloneRange(); extendedRange = selectionRange->CloneRange();
} }
@ -6531,81 +6517,6 @@ already_AddRefed<nsRange> HTMLEditor::CreateRangeIncludingAdjuscentWhiteSpaces(
return range.forget(); return range.forget();
} }
template <typename EditorDOMRangeType>
already_AddRefed<nsRange> HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd(
const EditorDOMRangeType& aRange, EditSubAction aEditSubAction) const {
if (!aRange.IsPositioned()) {
return nullptr;
}
return CreateRangeExtendedToHardLineStartAndEnd(
aRange.StartRef(), aRange.EndRef(), aEditSubAction);
}
template <typename EditorDOMPointType1, typename EditorDOMPointType2>
already_AddRefed<nsRange> HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd(
const EditorDOMPointType1& aStartPoint,
const EditorDOMPointType2& aEndPoint, EditSubAction aEditSubAction) const {
MOZ_DIAGNOSTIC_ASSERT(!aStartPoint.IsInNativeAnonymousSubtree());
MOZ_DIAGNOSTIC_ASSERT(!aEndPoint.IsInNativeAnonymousSubtree());
if (NS_WARN_IF(!aStartPoint.IsSet()) || NS_WARN_IF(!aEndPoint.IsSet())) {
return nullptr;
}
const Element* const editingHost = ComputeEditingHost();
if (NS_WARN_IF(!editingHost)) {
return nullptr;
}
auto startPoint = aStartPoint.template To<EditorDOMPoint>();
auto endPoint = aEndPoint.template To<EditorDOMPoint>();
AutoRangeArray::UpdatePointsToSelectAllChildrenIfCollapsedInEmptyBlockElement(
startPoint, endPoint, *editingHost);
// Make a new adjusted range to represent the appropriate block content.
// This is tricky. The basic idea is to push out the range endpoints to
// truly enclose the blocks that we will affect.
// Make sure that the new range ends up to be in the editable section.
// XXX Looks like that this check wastes the time. Perhaps, we should
// implement a method which checks both two DOM points in the editor
// root.
startPoint = AutoRangeArray::
GetPointAtFirstContentOfLineOrParentBlockIfFirstContentOfBlock(
startPoint, aEditSubAction, *editingHost);
// XXX GetPointAtFirstContentOfLineOrParentBlockIfFirstContentOfBlock() may
// return point of editing host. Perhaps, we should change it and stop
// checking it here since this check may be expensive.
// XXX If the container is an element in the editing host but it points end of
// the container, this returns nullptr. Is it intentional?
if (!startPoint.GetChildOrContainerIfDataNode() ||
!startPoint.GetChildOrContainerIfDataNode()->IsInclusiveDescendantOf(
editingHost)) {
return nullptr;
}
endPoint = AutoRangeArray::GetPointAfterFollowingLineBreakOrAtFollowingBlock(
endPoint, *editingHost);
const EditorDOMPoint lastRawPoint =
endPoint.IsStartOfContainer() ? endPoint : endPoint.PreviousPoint();
// XXX GetPointAfterFollowingLineBreakOrAtFollowingBlock() may return point of
// editing host. Perhaps, we should change it and stop checking it here
// since this check may be expensive.
// XXX If the container is an element in the editing host but it points end of
// the container, this returns nullptr. Is it intentional?
if (!lastRawPoint.GetChildOrContainerIfDataNode() ||
!lastRawPoint.GetChildOrContainerIfDataNode()->IsInclusiveDescendantOf(
editingHost)) {
return nullptr;
}
RefPtr<nsRange> range =
nsRange::Create(startPoint.ToRawRangeBoundary(),
endPoint.ToRawRangeBoundary(), IgnoreErrors());
NS_WARNING_ASSERTION(range, "nsRange::Create() failed");
return range.forget();
}
nsresult HTMLEditor::SplitInlinesAndCollectEditTargetNodes( nsresult HTMLEditor::SplitInlinesAndCollectEditTargetNodes(
nsTArray<OwningNonNull<nsRange>>& aArrayOfRanges, nsTArray<OwningNonNull<nsRange>>& aArrayOfRanges,
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents, nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents,

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

@ -1243,19 +1243,6 @@ class HTMLEditor final : public EditorBase,
const EditorDOMPointType1& aStartPoint, const EditorDOMPointType1& aStartPoint,
const EditorDOMPointType2& aEndPoint); const EditorDOMPointType2& aEndPoint);
/**
* CreateRangeExtendedToHardLineStartAndEnd() creates an nsRange instance
* which may be expanded to start/end of hard line at both edges of the given
* range. If this fails handling something, returns nullptr.
*/
template <typename EditorDOMRangeType>
already_AddRefed<nsRange> CreateRangeExtendedToHardLineStartAndEnd(
const EditorDOMRangeType& aRange, EditSubAction aEditSubAction) const;
template <typename EditorDOMPointType1, typename EditorDOMPointType2>
already_AddRefed<nsRange> CreateRangeExtendedToHardLineStartAndEnd(
const EditorDOMPointType1& aStartPoint,
const EditorDOMPointType2& aEndPoint, EditSubAction aEditSubAction) const;
/** /**
* GetSelectionRangesExtendedToHardLineStartAndEnd() collects selection ranges * GetSelectionRangesExtendedToHardLineStartAndEnd() collects selection ranges
* with extending to start/end of hard line from each range start and end. * with extending to start/end of hard line from each range start and end.
@ -1982,6 +1969,7 @@ class HTMLEditor final : public EditorBase,
* same hard line will be moved. * same hard line will be moved.
* @param aPointToInsert Point to insert contents of the hard * @param aPointToInsert Point to insert contents of the hard
* line. * line.
* @param aEditingHost The editing host.
* @param aMoveToEndOfContainer If `Yes`, aPointToInsert.Offset() will * @param aMoveToEndOfContainer If `Yes`, aPointToInsert.Offset() will
* be ignored and instead, all contents * be ignored and instead, all contents
* will be appended to the container of * will be appended to the container of
@ -1996,7 +1984,7 @@ class HTMLEditor final : public EditorBase,
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MoveNodeResult [[nodiscard]] MOZ_CAN_RUN_SCRIPT MoveNodeResult
MoveOneHardLineContentsWithTransaction( MoveOneHardLineContentsWithTransaction(
const EditorDOMPoint& aPointInHardLine, const EditorDOMPoint& aPointInHardLine,
const EditorDOMPoint& aPointToInsert, const EditorDOMPoint& aPointToInsert, const Element& aEditingHost,
MoveToEndOfContainer aMoveToEndOfContainer = MoveToEndOfContainer::No); MoveToEndOfContainer aMoveToEndOfContainer = MoveToEndOfContainer::No);
/** /**
@ -2007,9 +1995,9 @@ class HTMLEditor final : public EditorBase,
* *
* @param aPointInHardLine A point in a hard line. * @param aPointInHardLine A point in a hard line.
*/ */
template <typename PT, typename CT>
Result<bool, nsresult> CanMoveOrDeleteSomethingInHardLine( Result<bool, nsresult> CanMoveOrDeleteSomethingInHardLine(
const EditorDOMPointBase<PT, CT>& aPointInHardLine) const; const EditorDOMPoint& aPointInHardLine,
const Element& aEditingHost) const;
/** /**
* SplitNodeWithTransaction() creates a transaction to create a new node * SplitNodeWithTransaction() creates a transaction to create a new node

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

@ -61,10 +61,6 @@ template nsresult HTMLEditor::DeleteTextAndTextNodesWithTransaction(
const EditorDOMPointInText& aStartPoint, const EditorDOMPointInText& aStartPoint,
const EditorDOMPointInText& aEndPoint, const EditorDOMPointInText& aEndPoint,
TreatEmptyTextNodes aTreatEmptyTextNodes); TreatEmptyTextNodes aTreatEmptyTextNodes);
template Result<bool, nsresult> HTMLEditor::CanMoveOrDeleteSomethingInHardLine(
const EditorDOMPoint& aPointInHardLine) const;
template Result<bool, nsresult> HTMLEditor::CanMoveOrDeleteSomethingInHardLine(
const EditorRawDOMPoint& aPointInHardLine) const;
/***************************************************************************** /*****************************************************************************
* AutoSetTemporaryAncestorLimiter * AutoSetTemporaryAncestorLimiter
@ -123,7 +119,7 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
*/ */
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult ComputeRangesToDelete( [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult ComputeRangesToDelete(
const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount, const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
AutoRangeArray& aRangesToDelete); AutoRangeArray& aRangesToDelete, const Element& aEditingHost);
/** /**
* Deletes content in or around aRangesToDelete. * Deletes content in or around aRangesToDelete.
@ -173,7 +169,8 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
nsresult ComputeRangesToDeleteAroundCollapsedRanges( nsresult ComputeRangesToDeleteAroundCollapsedRanges(
const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount, const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
AutoRangeArray& aRangesToDelete, const WSRunScanner& aWSRunScannerAtCaret, AutoRangeArray& aRangesToDelete, const WSRunScanner& aWSRunScannerAtCaret,
const WSScanResult& aScanFromCaretPointResult) const; const WSScanResult& aScanFromCaretPointResult,
const Element& aEditingHost) const;
/** /**
* HandleDeleteNonCollapsedRanges() handles deletion with non-collapsed * HandleDeleteNonCollapsedRanges() handles deletion with non-collapsed
@ -201,7 +198,8 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
nsresult ComputeRangesToDeleteNonCollapsedRanges( nsresult ComputeRangesToDeleteNonCollapsedRanges(
const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount, const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
AutoRangeArray& aRangesToDelete, AutoRangeArray& aRangesToDelete,
SelectionWasCollapsed aSelectionWasCollapsed) const; SelectionWasCollapsed aSelectionWasCollapsed,
const Element& aEditingHost) const;
/** /**
* HandleDeleteTextAroundCollapsedRanges() handles deletion of collapsed * HandleDeleteTextAroundCollapsedRanges() handles deletion of collapsed
@ -525,8 +523,8 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
const Element& aEditingHost) { const Element& aEditingHost) {
switch (mMode) { switch (mMode) {
case Mode::JoinCurrentBlock: { case Mode::JoinCurrentBlock: {
EditActionResult result = EditActionResult result = HandleDeleteAtCurrentBlockBoundary(
HandleDeleteAtCurrentBlockBoundary(aHTMLEditor, aCaretPoint); aHTMLEditor, aCaretPoint, aEditingHost);
NS_WARNING_ASSERTION(result.Succeeded(), NS_WARNING_ASSERTION(result.Succeeded(),
"AutoBlockElementsJoiner::" "AutoBlockElementsJoiner::"
"HandleDeleteAtCurrentBlockBoundary() failed"); "HandleDeleteAtCurrentBlockBoundary() failed");
@ -564,11 +562,12 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
nsresult ComputeRangesToDelete(const HTMLEditor& aHTMLEditor, nsresult ComputeRangesToDelete(const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EDirection aDirectionAndAmount,
const EditorDOMPoint& aCaretPoint, const EditorDOMPoint& aCaretPoint,
AutoRangeArray& aRangesToDelete) const { AutoRangeArray& aRangesToDelete,
const Element& aEditingHost) const {
switch (mMode) { switch (mMode) {
case Mode::JoinCurrentBlock: { case Mode::JoinCurrentBlock: {
nsresult rv = ComputeRangesToDeleteAtCurrentBlockBoundary( nsresult rv = ComputeRangesToDeleteAtCurrentBlockBoundary(
aHTMLEditor, aCaretPoint, aRangesToDelete); aHTMLEditor, aCaretPoint, aRangesToDelete, aEditingHost);
NS_WARNING_ASSERTION( NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), NS_SUCCEEDED(rv),
"AutoBlockElementsJoiner::" "AutoBlockElementsJoiner::"
@ -577,7 +576,8 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
} }
case Mode::JoinOtherBlock: { case Mode::JoinOtherBlock: {
nsresult rv = ComputeRangesToDeleteAtOtherBlockBoundary( nsresult rv = ComputeRangesToDeleteAtOtherBlockBoundary(
aHTMLEditor, aDirectionAndAmount, aCaretPoint, aRangesToDelete); aHTMLEditor, aDirectionAndAmount, aCaretPoint, aRangesToDelete,
aEditingHost);
NS_WARNING_ASSERTION( NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), NS_SUCCEEDED(rv),
"AutoBlockElementsJoiner::" "AutoBlockElementsJoiner::"
@ -621,7 +621,8 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
Run(HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount, Run(HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers, nsIEditor::EStripWrappers aStripWrappers,
AutoRangeArray& aRangesToDelete, AutoRangeArray& aRangesToDelete,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed) { AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const Element& aEditingHost) {
switch (mMode) { switch (mMode) {
case Mode::JoinCurrentBlock: case Mode::JoinCurrentBlock:
case Mode::JoinOtherBlock: case Mode::JoinOtherBlock:
@ -650,7 +651,7 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
case Mode::DeleteNonCollapsedRanges: { case Mode::DeleteNonCollapsedRanges: {
EditActionResult result = HandleDeleteNonCollapsedRanges( EditActionResult result = HandleDeleteNonCollapsedRanges(
aHTMLEditor, aDirectionAndAmount, aStripWrappers, aRangesToDelete, aHTMLEditor, aDirectionAndAmount, aStripWrappers, aRangesToDelete,
aSelectionWasCollapsed); aSelectionWasCollapsed, aEditingHost);
NS_WARNING_ASSERTION(result.Succeeded(), NS_WARNING_ASSERTION(result.Succeeded(),
"AutoBlockElementsJoiner::" "AutoBlockElementsJoiner::"
"HandleDeleteNonCollapsedRange() failed"); "HandleDeleteNonCollapsedRange() failed");
@ -668,8 +669,8 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
const HTMLEditor& aHTMLEditor, const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EDirection aDirectionAndAmount,
AutoRangeArray& aRangesToDelete, AutoRangeArray& aRangesToDelete,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed) AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const { const Element& aEditingHost) const {
switch (mMode) { switch (mMode) {
case Mode::JoinCurrentBlock: case Mode::JoinCurrentBlock:
case Mode::JoinOtherBlock: case Mode::JoinOtherBlock:
@ -698,7 +699,7 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
case Mode::DeleteNonCollapsedRanges: { case Mode::DeleteNonCollapsedRanges: {
nsresult rv = ComputeRangesToDeleteNonCollapsedRanges( nsresult rv = ComputeRangesToDeleteNonCollapsedRanges(
aHTMLEditor, aDirectionAndAmount, aRangesToDelete, aHTMLEditor, aDirectionAndAmount, aRangesToDelete,
aSelectionWasCollapsed); aSelectionWasCollapsed, aEditingHost);
NS_WARNING_ASSERTION( NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), NS_SUCCEEDED(rv),
"AutoBlockElementsJoiner::" "AutoBlockElementsJoiner::"
@ -722,10 +723,11 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
private: private:
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult [[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
HandleDeleteAtCurrentBlockBoundary(HTMLEditor& aHTMLEditor, HandleDeleteAtCurrentBlockBoundary(HTMLEditor& aHTMLEditor,
const EditorDOMPoint& aCaretPoint); const EditorDOMPoint& aCaretPoint,
const Element& aEditingHost);
nsresult ComputeRangesToDeleteAtCurrentBlockBoundary( nsresult ComputeRangesToDeleteAtCurrentBlockBoundary(
const HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCaretPoint, const HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCaretPoint,
AutoRangeArray& aRangesToDelete) const; AutoRangeArray& aRangesToDelete, const Element& aEditingHost) const;
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult [[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
HandleDeleteAtOtherBlockBoundary(HTMLEditor& aHTMLEditor, HandleDeleteAtOtherBlockBoundary(HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EDirection aDirectionAndAmount,
@ -741,8 +743,8 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
ComputeRangesToDeleteAtOtherBlockBoundary( ComputeRangesToDeleteAtOtherBlockBoundary(
const HTMLEditor& aHTMLEditor, const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EDirection aDirectionAndAmount,
const EditorDOMPoint& aCaretPoint, const EditorDOMPoint& aCaretPoint, AutoRangeArray& aRangesToDelete,
AutoRangeArray& aRangesToDelete) const; const Element& aEditingHost) const;
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult [[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
JoinBlockElementsInSameParent(HTMLEditor& aHTMLEditor, JoinBlockElementsInSameParent(HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EDirection aDirectionAndAmount,
@ -770,13 +772,14 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount, HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers, nsIEditor::EStripWrappers aStripWrappers,
AutoRangeArray& aRangesToDelete, AutoRangeArray& aRangesToDelete,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed); AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const Element& aEditingHost);
nsresult ComputeRangesToDeleteNonCollapsedRanges( nsresult ComputeRangesToDeleteNonCollapsedRanges(
const HTMLEditor& aHTMLEditor, const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EDirection aDirectionAndAmount,
AutoRangeArray& aRangesToDelete, AutoRangeArray& aRangesToDelete,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed) AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const; const Element& aEditingHost) const;
/** /**
* JoinNodesDeepWithTransaction() joins aLeftNode and aRightNode "deeply". * JoinNodesDeepWithTransaction() joins aLeftNode and aRightNode "deeply".
@ -863,7 +866,8 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
* Prepare for joining inclusive ancestor block elements. When this * Prepare for joining inclusive ancestor block elements. When this
* returns false, the deletion should be canceled. * returns false, the deletion should be canceled.
*/ */
Result<bool, nsresult> Prepare(const HTMLEditor& aHTMLEditor); Result<bool, nsresult> Prepare(const HTMLEditor& aHTMLEditor,
const Element& aEditingHost);
/** /**
* When this returns true, this can join the blocks with `Run()`. * When this returns true, this can join the blocks with `Run()`.
@ -902,7 +906,7 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
* left block. * left block.
*/ */
[[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult [[nodiscard]] MOZ_CAN_RUN_SCRIPT EditActionResult
Run(HTMLEditor& aHTMLEditor); Run(HTMLEditor& aHTMLEditor, const Element& aEditingHost);
private: private:
/** /**
@ -1077,8 +1081,8 @@ nsresult HTMLEditor::ComputeTargetRanges(
} }
AutoDeleteRangesHandler deleteHandler; AutoDeleteRangesHandler deleteHandler;
// Should we delete target ranges which cannot delete actually? // Should we delete target ranges which cannot delete actually?
nsresult rv = deleteHandler.ComputeRangesToDelete(*this, aDirectionAndAmount, nsresult rv = deleteHandler.ComputeRangesToDelete(
aRangesToDelete); *this, aDirectionAndAmount, aRangesToDelete, *editingHost);
NS_WARNING_ASSERTION( NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::ComputeRangesToDelete() failed"); "AutoDeleteRangesHandler::ComputeRangesToDelete() failed");
@ -1160,7 +1164,7 @@ EditActionResult HTMLEditor::HandleDeleteSelection(
nsresult HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDelete( nsresult HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDelete(
const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount, const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
AutoRangeArray& aRangesToDelete) { AutoRangeArray& aRangesToDelete, const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable()); MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty()); MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty());
@ -1322,7 +1326,7 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDelete(
aRangesToDelete.Initialize(aHTMLEditor.SelectionRef()); aRangesToDelete.Initialize(aHTMLEditor.SelectionRef());
AutoDeleteRangesHandler anotherHandler(this); AutoDeleteRangesHandler anotherHandler(this);
rv = anotherHandler.ComputeRangesToDelete( rv = anotherHandler.ComputeRangesToDelete(
aHTMLEditor, aDirectionAndAmount, aRangesToDelete); aHTMLEditor, aDirectionAndAmount, aRangesToDelete, aEditingHost);
NS_WARNING_ASSERTION( NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), NS_SUCCEEDED(rv),
"Recursive AutoDeleteRangesHandler::ComputeRangesToDelete() " "Recursive AutoDeleteRangesHandler::ComputeRangesToDelete() "
@ -1384,7 +1388,7 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDelete(
nsresult rv = ComputeRangesToDeleteAroundCollapsedRanges( nsresult rv = ComputeRangesToDeleteAroundCollapsedRanges(
aHTMLEditor, aDirectionAndAmount, aRangesToDelete, aHTMLEditor, aDirectionAndAmount, aRangesToDelete,
wsRunScannerAtCaret, scanFromCaretPointResult); wsRunScannerAtCaret, scanFromCaretPointResult, aEditingHost);
NS_WARNING_ASSERTION( NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::ComputeRangesToDeleteAroundCollapsedRanges(" "AutoDeleteRangesHandler::ComputeRangesToDeleteAroundCollapsedRanges("
@ -1394,7 +1398,8 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDelete(
} }
nsresult rv = ComputeRangesToDeleteNonCollapsedRanges( nsresult rv = ComputeRangesToDeleteNonCollapsedRanges(
aHTMLEditor, aDirectionAndAmount, aRangesToDelete, selectionWasCollapsed); aHTMLEditor, aDirectionAndAmount, aRangesToDelete, selectionWasCollapsed,
aEditingHost);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::" "AutoDeleteRangesHandler::"
"ComputeRangesToDeleteNonCollapsedRanges() failed"); "ComputeRangesToDeleteNonCollapsedRanges() failed");
@ -1668,7 +1673,8 @@ nsresult
HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteAroundCollapsedRanges( HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteAroundCollapsedRanges(
const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount, const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
AutoRangeArray& aRangesToDelete, const WSRunScanner& aWSRunScannerAtCaret, AutoRangeArray& aRangesToDelete, const WSRunScanner& aWSRunScannerAtCaret,
const WSScanResult& aScanFromCaretPointResult) const { const WSScanResult& aScanFromCaretPointResult,
const Element& aEditingHost) const {
if (aScanFromCaretPointResult.InCollapsibleWhiteSpaces() || if (aScanFromCaretPointResult.InCollapsibleWhiteSpaces() ||
aScanFromCaretPointResult.InNonCollapsibleCharacters() || aScanFromCaretPointResult.InNonCollapsibleCharacters() ||
aScanFromCaretPointResult.ReachedPreformattedLineBreak()) { aScanFromCaretPointResult.ReachedPreformattedLineBreak()) {
@ -1740,7 +1746,7 @@ HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteAroundCollapsedRanges(
} }
nsresult rv = joiner.ComputeRangesToDelete( nsresult rv = joiner.ComputeRangesToDelete(
aHTMLEditor, aDirectionAndAmount, aWSRunScannerAtCaret.ScanStartRef(), aHTMLEditor, aDirectionAndAmount, aWSRunScannerAtCaret.ScanStartRef(),
aRangesToDelete); aRangesToDelete, aEditingHost);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoBlockElementsJoiner::ComputeRangesToDelete() " "AutoBlockElementsJoiner::ComputeRangesToDelete() "
"failed (other block boundary)"); "failed (other block boundary)");
@ -1760,7 +1766,7 @@ HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteAroundCollapsedRanges(
} }
nsresult rv = joiner.ComputeRangesToDelete( nsresult rv = joiner.ComputeRangesToDelete(
aHTMLEditor, aDirectionAndAmount, aWSRunScannerAtCaret.ScanStartRef(), aHTMLEditor, aDirectionAndAmount, aWSRunScannerAtCaret.ScanStartRef(),
aRangesToDelete); aRangesToDelete, aEditingHost);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoBlockElementsJoiner::ComputeRangesToDelete() " "AutoBlockElementsJoiner::ComputeRangesToDelete() "
"failed (current block boundary)"); "failed (current block boundary)");
@ -2549,8 +2555,8 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
ComputeRangesToDeleteAtOtherBlockBoundary( ComputeRangesToDeleteAtOtherBlockBoundary(
const HTMLEditor& aHTMLEditor, const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EDirection aDirectionAndAmount,
const EditorDOMPoint& aCaretPoint, const EditorDOMPoint& aCaretPoint, AutoRangeArray& aRangesToDelete,
AutoRangeArray& aRangesToDelete) const { const Element& aEditingHost) const {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable()); MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(aCaretPoint.IsSetAndValid()); MOZ_ASSERT(aCaretPoint.IsSetAndValid());
MOZ_ASSERT(mLeftContent); MOZ_ASSERT(mLeftContent);
@ -2577,7 +2583,8 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent, AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
*mRightContent); *mRightContent);
Result<bool, nsresult> canJoinThem = joiner.Prepare(aHTMLEditor); Result<bool, nsresult> canJoinThem =
joiner.Prepare(aHTMLEditor, aEditingHost);
if (canJoinThem.isErr()) { if (canJoinThem.isErr()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed"); NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
return canJoinThem.unwrapErr(); return canJoinThem.unwrapErr();
@ -2629,7 +2636,7 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
aRangesToDelete.Initialize(aHTMLEditor.SelectionRef()); aRangesToDelete.Initialize(aHTMLEditor.SelectionRef());
AutoDeleteRangesHandler anotherHandler(mDeleteRangesHandlerConst); AutoDeleteRangesHandler anotherHandler(mDeleteRangesHandlerConst);
rv = anotherHandler.ComputeRangesToDelete(aHTMLEditor, aDirectionAndAmount, rv = anotherHandler.ComputeRangesToDelete(aHTMLEditor, aDirectionAndAmount,
aRangesToDelete); aRangesToDelete, aEditingHost);
NS_WARNING_ASSERTION( NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), NS_SUCCEEDED(rv),
"Recursive AutoDeleteRangesHandler::ComputeRangesToDelete() failed"); "Recursive AutoDeleteRangesHandler::ComputeRangesToDelete() failed");
@ -2684,7 +2691,8 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
// Else we are joining content to block // Else we are joining content to block
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent, AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
*mRightContent); *mRightContent);
Result<bool, nsresult> canJoinThem = joiner.Prepare(aHTMLEditor); Result<bool, nsresult> canJoinThem =
joiner.Prepare(aHTMLEditor, aEditingHost);
if (canJoinThem.isErr()) { if (canJoinThem.isErr()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed"); NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
return EditActionResult(canJoinThem.unwrapErr()); return EditActionResult(canJoinThem.unwrapErr());
@ -2709,7 +2717,7 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
{ {
AutoTrackDOMPoint tracker(aHTMLEditor.RangeUpdaterRef(), AutoTrackDOMPoint tracker(aHTMLEditor.RangeUpdaterRef(),
&pointToPutCaret); &pointToPutCaret);
result |= joiner.Run(aHTMLEditor); result |= joiner.Run(aHTMLEditor, aEditingHost);
if (result.Failed()) { if (result.Failed()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed"); NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed");
return result; return result;
@ -2830,13 +2838,14 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner:: nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
ComputeRangesToDeleteAtCurrentBlockBoundary( ComputeRangesToDeleteAtCurrentBlockBoundary(
const HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCaretPoint, const HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCaretPoint,
AutoRangeArray& aRangesToDelete) const { AutoRangeArray& aRangesToDelete, const Element& aEditingHost) const {
MOZ_ASSERT(mLeftContent); MOZ_ASSERT(mLeftContent);
MOZ_ASSERT(mRightContent); MOZ_ASSERT(mRightContent);
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent, AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
*mRightContent); *mRightContent);
Result<bool, nsresult> canJoinThem = joiner.Prepare(aHTMLEditor); Result<bool, nsresult> canJoinThem =
joiner.Prepare(aHTMLEditor, aEditingHost);
if (canJoinThem.isErr()) { if (canJoinThem.isErr()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed"); NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
return canJoinThem.unwrapErr(); return canJoinThem.unwrapErr();
@ -2859,13 +2868,15 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner:: EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
HandleDeleteAtCurrentBlockBoundary(HTMLEditor& aHTMLEditor, HandleDeleteAtCurrentBlockBoundary(HTMLEditor& aHTMLEditor,
const EditorDOMPoint& aCaretPoint) { const EditorDOMPoint& aCaretPoint,
const Element& aEditingHost) {
MOZ_ASSERT(mLeftContent); MOZ_ASSERT(mLeftContent);
MOZ_ASSERT(mRightContent); MOZ_ASSERT(mRightContent);
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent, AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
*mRightContent); *mRightContent);
Result<bool, nsresult> canJoinThem = joiner.Prepare(aHTMLEditor); Result<bool, nsresult> canJoinThem =
joiner.Prepare(aHTMLEditor, aEditingHost);
if (canJoinThem.isErr()) { if (canJoinThem.isErr()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed"); NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
return EditActionResult(canJoinThem.unwrapErr()); return EditActionResult(canJoinThem.unwrapErr());
@ -2888,7 +2899,7 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
EditorDOMPoint pointToPutCaret(aCaretPoint); EditorDOMPoint pointToPutCaret(aCaretPoint);
if (joiner.CanJoinBlocks()) { if (joiner.CanJoinBlocks()) {
AutoTrackDOMPoint tracker(aHTMLEditor.RangeUpdaterRef(), &pointToPutCaret); AutoTrackDOMPoint tracker(aHTMLEditor.RangeUpdaterRef(), &pointToPutCaret);
result |= joiner.Run(aHTMLEditor); result |= joiner.Run(aHTMLEditor, aEditingHost);
if (result.Failed()) { if (result.Failed()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed"); NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed");
return result; return result;
@ -2925,8 +2936,8 @@ nsresult
HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteNonCollapsedRanges( HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteNonCollapsedRanges(
const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount, const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
AutoRangeArray& aRangesToDelete, AutoRangeArray& aRangesToDelete,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed) AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const { const Element& aEditingHost) const {
MOZ_ASSERT(!aRangesToDelete.IsCollapsed()); MOZ_ASSERT(!aRangesToDelete.IsCollapsed());
if (NS_WARN_IF(!aRangesToDelete.FirstRangeRef()->StartRef().IsSet()) || if (NS_WARN_IF(!aRangesToDelete.FirstRangeRef()->StartRef().IsSet()) ||
@ -3013,9 +3024,9 @@ HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteNonCollapsedRanges(
if (!joiner.PrepareToDeleteNonCollapsedRanges(aHTMLEditor, aRangesToDelete)) { if (!joiner.PrepareToDeleteNonCollapsedRanges(aHTMLEditor, aRangesToDelete)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsresult rv = nsresult rv = joiner.ComputeRangesToDelete(
joiner.ComputeRangesToDelete(aHTMLEditor, aDirectionAndAmount, aHTMLEditor, aDirectionAndAmount, aRangesToDelete, aSelectionWasCollapsed,
aRangesToDelete, aSelectionWasCollapsed); aEditingHost);
NS_WARNING_ASSERTION( NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), NS_SUCCEEDED(rv),
"AutoBlockElementsJoiner::ComputeRangesToDelete() failed"); "AutoBlockElementsJoiner::ComputeRangesToDelete() failed");
@ -3172,7 +3183,7 @@ HTMLEditor::AutoDeleteRangesHandler::HandleDeleteNonCollapsedRanges(
} }
EditActionResult result = EditActionResult result =
joiner.Run(aHTMLEditor, aDirectionAndAmount, aStripWrappers, joiner.Run(aHTMLEditor, aDirectionAndAmount, aStripWrappers,
aRangesToDelete, aSelectionWasCollapsed); aRangesToDelete, aSelectionWasCollapsed, aEditingHost);
NS_WARNING_ASSERTION(result.Succeeded(), NS_WARNING_ASSERTION(result.Succeeded(),
"AutoBlockElementsJoiner::Run() failed"); "AutoBlockElementsJoiner::Run() failed");
return result; return result;
@ -3555,8 +3566,8 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
const HTMLEditor& aHTMLEditor, const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, nsIEditor::EDirection aDirectionAndAmount,
AutoRangeArray& aRangesToDelete, AutoRangeArray& aRangesToDelete,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed) AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const { const Element& aEditingHost) const {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable()); MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(!aRangesToDelete.IsCollapsed()); MOZ_ASSERT(!aRangesToDelete.IsCollapsed());
MOZ_ASSERT(mLeftContent); MOZ_ASSERT(mLeftContent);
@ -3588,7 +3599,8 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent, AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
*mRightContent); *mRightContent);
Result<bool, nsresult> canJoinThem = joiner.Prepare(aHTMLEditor); Result<bool, nsresult> canJoinThem =
joiner.Prepare(aHTMLEditor, aEditingHost);
if (canJoinThem.isErr()) { if (canJoinThem.isErr()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed"); NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
return canJoinThem.unwrapErr(); return canJoinThem.unwrapErr();
@ -3616,7 +3628,8 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount, HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers, nsIEditor::EStripWrappers aStripWrappers,
AutoRangeArray& aRangesToDelete, AutoRangeArray& aRangesToDelete,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed) { AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable()); MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(!aRangesToDelete.IsCollapsed()); MOZ_ASSERT(!aRangesToDelete.IsCollapsed());
MOZ_ASSERT(mDeleteRangesHandler); MOZ_ASSERT(mDeleteRangesHandler);
@ -3670,7 +3683,8 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent, AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
*mRightContent); *mRightContent);
Result<bool, nsresult> canJoinThem = joiner.Prepare(aHTMLEditor); Result<bool, nsresult> canJoinThem =
joiner.Prepare(aHTMLEditor, aEditingHost);
if (canJoinThem.isErr()) { if (canJoinThem.isErr()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed"); NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
return EditActionResult(canJoinThem.unwrapErr()); return EditActionResult(canJoinThem.unwrapErr());
@ -3700,7 +3714,7 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
break; break;
} }
result |= joiner.Run(aHTMLEditor); result |= joiner.Run(aHTMLEditor, aEditingHost);
if (result.Failed()) { if (result.Failed()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed"); NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed");
return result; return result;
@ -4365,7 +4379,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::AutoDeleteRangesHandler::
Result<bool, nsresult> HTMLEditor::AutoDeleteRangesHandler:: Result<bool, nsresult> HTMLEditor::AutoDeleteRangesHandler::
AutoBlockElementsJoiner::AutoInclusiveAncestorBlockElementsJoiner::Prepare( AutoBlockElementsJoiner::AutoInclusiveAncestorBlockElementsJoiner::Prepare(
const HTMLEditor& aHTMLEditor) { const HTMLEditor& aHTMLEditor, const Element& aEditingHost) {
mLeftBlockElement = HTMLEditUtils::GetInclusiveAncestorElement( mLeftBlockElement = HTMLEditUtils::GetInclusiveAncestorElement(
mInclusiveDescendantOfLeftBlockElement, mInclusiveDescendantOfLeftBlockElement,
HTMLEditUtils::ClosestEditableBlockElementExceptHRElement); HTMLEditUtils::ClosestEditableBlockElementExceptHRElement);
@ -4464,7 +4478,8 @@ Result<bool, nsresult> HTMLEditor::AutoDeleteRangesHandler::
Result<bool, nsresult> firstLineHasContent = Result<bool, nsresult> firstLineHasContent =
aHTMLEditor.CanMoveOrDeleteSomethingInHardLine( aHTMLEditor.CanMoveOrDeleteSomethingInHardLine(
mPointContainingTheOtherBlockElement mPointContainingTheOtherBlockElement
.NextPoint<EditorRawDOMPoint>()); .NextPoint<EditorDOMPoint>(),
aEditingHost);
mFallbackToDeleteLeafContent = mFallbackToDeleteLeafContent =
firstLineHasContent.isOk() && !firstLineHasContent.inspect(); firstLineHasContent.isOk() && !firstLineHasContent.inspect();
} }
@ -4500,7 +4515,7 @@ Result<bool, nsresult> HTMLEditor::AutoDeleteRangesHandler::
// Marked as handled only when it actually moves a content node. // Marked as handled only when it actually moves a content node.
Result<bool, nsresult> firstLineHasContent = Result<bool, nsresult> firstLineHasContent =
aHTMLEditor.CanMoveOrDeleteSomethingInHardLine( aHTMLEditor.CanMoveOrDeleteSomethingInHardLine(
EditorRawDOMPoint(mRightBlockElement, 0)); EditorDOMPoint(mRightBlockElement, 0u), aEditingHost);
mFallbackToDeleteLeafContent = mFallbackToDeleteLeafContent =
firstLineHasContent.isOk() && !firstLineHasContent.inspect(); firstLineHasContent.isOk() && !firstLineHasContent.inspect();
} }
@ -4600,7 +4615,8 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
} }
EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner:: EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
AutoInclusiveAncestorBlockElementsJoiner::Run(HTMLEditor& aHTMLEditor) { AutoInclusiveAncestorBlockElementsJoiner::Run(HTMLEditor& aHTMLEditor,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable()); MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(mLeftBlockElement); MOZ_ASSERT(mLeftBlockElement);
MOZ_ASSERT(mRightBlockElement); MOZ_ASSERT(mRightBlockElement);
@ -4624,7 +4640,7 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
MOZ_KnownLive(*mRightBlockElement), MOZ_KnownLive(*mRightBlockElement),
mPointContainingTheOtherBlockElement, mPointContainingTheOtherBlockElement,
mNewListElementTagNameOfRightListElement, mNewListElementTagNameOfRightListElement,
MOZ_KnownLive(mPrecedingInvisibleBRElement)); MOZ_KnownLive(mPrecedingInvisibleBRElement), aEditingHost);
NS_WARNING_ASSERTION(result.Succeeded(), NS_WARNING_ASSERTION(result.Succeeded(),
"WhiteSpaceVisibilityKeeper::" "WhiteSpaceVisibilityKeeper::"
"MergeFirstLineOfRightBlockElementIntoDescendantLeftBl" "MergeFirstLineOfRightBlockElementIntoDescendantLeftBl"
@ -4647,7 +4663,7 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
mPointContainingTheOtherBlockElement, mPointContainingTheOtherBlockElement,
MOZ_KnownLive(*mInclusiveDescendantOfLeftBlockElement), MOZ_KnownLive(*mInclusiveDescendantOfLeftBlockElement),
mNewListElementTagNameOfRightListElement, mNewListElementTagNameOfRightListElement,
MOZ_KnownLive(mPrecedingInvisibleBRElement)); MOZ_KnownLive(mPrecedingInvisibleBRElement), aEditingHost);
NS_WARNING_ASSERTION(result.Succeeded(), NS_WARNING_ASSERTION(result.Succeeded(),
"WhiteSpaceVisibilityKeeper::" "WhiteSpaceVisibilityKeeper::"
"MergeFirstLineOfRightBlockElementIntoAncestorLeftBloc" "MergeFirstLineOfRightBlockElementIntoAncestorLeftBloc"
@ -4666,7 +4682,7 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
aHTMLEditor, MOZ_KnownLive(*mLeftBlockElement), aHTMLEditor, MOZ_KnownLive(*mLeftBlockElement),
MOZ_KnownLive(*mRightBlockElement), MOZ_KnownLive(*mRightBlockElement),
mNewListElementTagNameOfRightListElement, mNewListElementTagNameOfRightListElement,
MOZ_KnownLive(mPrecedingInvisibleBRElement)); MOZ_KnownLive(mPrecedingInvisibleBRElement), aEditingHost);
NS_WARNING_ASSERTION( NS_WARNING_ASSERTION(
result.Succeeded(), result.Succeeded(),
"WhiteSpaceVisibilityKeeper::" "WhiteSpaceVisibilityKeeper::"
@ -4674,16 +4690,17 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
return result; return result;
} }
template <typename PT, typename CT>
Result<bool, nsresult> HTMLEditor::CanMoveOrDeleteSomethingInHardLine( Result<bool, nsresult> HTMLEditor::CanMoveOrDeleteSomethingInHardLine(
const EditorDOMPointBase<PT, CT>& aPointInHardLine) const { const EditorDOMPoint& aPointInHardLine, const Element& aEditingHost) const {
if (MOZ_UNLIKELY(NS_WARN_IF(!aPointInHardLine.IsSet()) || if (MOZ_UNLIKELY(NS_WARN_IF(!aPointInHardLine.IsSet()) ||
NS_WARN_IF(aPointInHardLine.IsInNativeAnonymousSubtree()))) { NS_WARN_IF(aPointInHardLine.IsInNativeAnonymousSubtree()))) {
return Err(NS_ERROR_INVALID_ARG); return Err(NS_ERROR_INVALID_ARG);
} }
RefPtr<nsRange> oneLineRange = CreateRangeExtendedToHardLineStartAndEnd( RefPtr<nsRange> oneLineRange =
aPointInHardLine, aPointInHardLine, EditSubAction::eMergeBlockContents); AutoRangeArray::CreateRangeWrappingStartAndEndLinesContainingBoundaries(
aPointInHardLine, aPointInHardLine,
EditSubAction::eMergeBlockContents, aEditingHost);
if (!oneLineRange || oneLineRange->Collapsed() || if (!oneLineRange || oneLineRange->Collapsed() ||
!oneLineRange->IsPositioned() || !oneLineRange->IsPositioned() ||
!oneLineRange->GetStartContainer()->IsContent() || !oneLineRange->GetStartContainer()->IsContent() ||
@ -4758,7 +4775,7 @@ Result<bool, nsresult> HTMLEditor::CanMoveOrDeleteSomethingInHardLine(
MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction( MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
const EditorDOMPoint& aPointInHardLine, const EditorDOMPoint& aPointInHardLine,
const EditorDOMPoint& aPointToInsert, const EditorDOMPoint& aPointToInsert, const Element& aEditingHost,
MoveToEndOfContainer MoveToEndOfContainer
aMoveToEndOfContainer /* = MoveToEndOfContainer::No */) { aMoveToEndOfContainer /* = MoveToEndOfContainer::No */) {
MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(IsEditActionDataAvailable());
@ -4773,8 +4790,10 @@ MoveNodeResult HTMLEditor::MoveOneHardLineContentsWithTransaction(
{ {
AutoTrackDOMPoint tackPointToInsert(RangeUpdaterRef(), &pointToInsert); AutoTrackDOMPoint tackPointToInsert(RangeUpdaterRef(), &pointToInsert);
RefPtr<nsRange> oneLineRange = CreateRangeExtendedToHardLineStartAndEnd( RefPtr<nsRange> oneLineRange =
aPointInHardLine, aPointInHardLine, EditSubAction::eMergeBlockContents); AutoRangeArray::CreateRangeWrappingStartAndEndLinesContainingBoundaries(
aPointInHardLine, aPointInHardLine,
EditSubAction::eMergeBlockContents, aEditingHost);
if (MOZ_UNLIKELY(!oneLineRange)) { if (MOZ_UNLIKELY(!oneLineRange)) {
// XXX It's odd to create collapsed range because it'll split parents at // XXX It's odd to create collapsed range because it'll split parents at
// the collapsed range even though we won't move anything from there. // the collapsed range even though we won't move anything from there.

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

@ -159,7 +159,8 @@ EditActionResult WhiteSpaceVisibilityKeeper::
HTMLEditor& aHTMLEditor, Element& aLeftBlockElement, HTMLEditor& aHTMLEditor, Element& aLeftBlockElement,
Element& aRightBlockElement, const EditorDOMPoint& aAtRightBlockChild, Element& aRightBlockElement, const EditorDOMPoint& aAtRightBlockChild,
const Maybe<nsAtom*>& aListElementTagName, const Maybe<nsAtom*>& aListElementTagName,
const HTMLBRElement* aPrecedingInvisibleBRElement) { const HTMLBRElement* aPrecedingInvisibleBRElement,
const Element& aEditingHost) {
MOZ_ASSERT( MOZ_ASSERT(
EditorUtils::IsDescendantOf(aLeftBlockElement, aRightBlockElement)); EditorUtils::IsDescendantOf(aLeftBlockElement, aRightBlockElement));
MOZ_ASSERT(&aRightBlockElement == aAtRightBlockChild.GetContainer()); MOZ_ASSERT(&aRightBlockElement == aAtRightBlockChild.GetContainer());
@ -282,13 +283,14 @@ EditActionResult WhiteSpaceVisibilityKeeper::
"The relation is not guaranteed but assumed"); "The relation is not guaranteed but assumed");
#ifdef DEBUG #ifdef DEBUG
Result<bool, nsresult> firstLineHasContent = Result<bool, nsresult> firstLineHasContent =
aHTMLEditor.CanMoveOrDeleteSomethingInHardLine(EditorRawDOMPoint( aHTMLEditor.CanMoveOrDeleteSomethingInHardLine(
rightBlockElement, afterRightBlockChild.Offset())); EditorDOMPoint(rightBlockElement, afterRightBlockChild.Offset()),
aEditingHost);
#endif // #ifdef DEBUG #endif // #ifdef DEBUG
MoveNodeResult moveNodeResult = MoveNodeResult moveNodeResult =
aHTMLEditor.MoveOneHardLineContentsWithTransaction( aHTMLEditor.MoveOneHardLineContentsWithTransaction(
EditorDOMPoint(rightBlockElement, afterRightBlockChild.Offset()), EditorDOMPoint(rightBlockElement, afterRightBlockChild.Offset()),
EditorDOMPoint(&aLeftBlockElement, 0u), EditorDOMPoint(&aLeftBlockElement, 0u), aEditingHost,
HTMLEditor::MoveToEndOfContainer::Yes); HTMLEditor::MoveToEndOfContainer::Yes);
if (moveNodeResult.isErr()) { if (moveNodeResult.isErr()) {
NS_WARNING( NS_WARNING(
@ -337,7 +339,8 @@ EditActionResult WhiteSpaceVisibilityKeeper::
Element& aRightBlockElement, const EditorDOMPoint& aAtLeftBlockChild, Element& aRightBlockElement, const EditorDOMPoint& aAtLeftBlockChild,
nsIContent& aLeftContentInBlock, nsIContent& aLeftContentInBlock,
const Maybe<nsAtom*>& aListElementTagName, const Maybe<nsAtom*>& aListElementTagName,
const HTMLBRElement* aPrecedingInvisibleBRElement) { const HTMLBRElement* aPrecedingInvisibleBRElement,
const Element& aEditingHost) {
MOZ_ASSERT( MOZ_ASSERT(
EditorUtils::IsDescendantOf(aRightBlockElement, aLeftBlockElement)); EditorUtils::IsDescendantOf(aRightBlockElement, aLeftBlockElement));
MOZ_ASSERT( MOZ_ASSERT(
@ -515,7 +518,7 @@ EditActionResult WhiteSpaceVisibilityKeeper::
#ifdef DEBUG #ifdef DEBUG
Result<bool, nsresult> firstLineHasContent = Result<bool, nsresult> firstLineHasContent =
aHTMLEditor.CanMoveOrDeleteSomethingInHardLine( aHTMLEditor.CanMoveOrDeleteSomethingInHardLine(
EditorRawDOMPoint(&aRightBlockElement, 0)); EditorDOMPoint(&aRightBlockElement, 0u), aEditingHost);
#endif // #ifdef DEBUG #endif // #ifdef DEBUG
Element* editingHost = Element* editingHost =
@ -555,7 +558,8 @@ EditActionResult WhiteSpaceVisibilityKeeper::
MoveNodeResult moveNodeResult = MoveNodeResult moveNodeResult =
aHTMLEditor.MoveOneHardLineContentsWithTransaction( aHTMLEditor.MoveOneHardLineContentsWithTransaction(
EditorDOMPoint(&aRightBlockElement, 0u), atPreviousContent); EditorDOMPoint(&aRightBlockElement, 0u), atPreviousContent,
aEditingHost);
if (moveNodeResult.isErr()) { if (moveNodeResult.isErr()) {
NS_WARNING("HTMLEditor::MoveOneHardLineContentsWithTransaction() failed"); NS_WARNING("HTMLEditor::MoveOneHardLineContentsWithTransaction() failed");
return EditActionResult(moveNodeResult.unwrapErr()); return EditActionResult(moveNodeResult.unwrapErr());
@ -596,7 +600,8 @@ EditActionResult WhiteSpaceVisibilityKeeper::
MergeFirstLineOfRightBlockElementIntoLeftBlockElement( MergeFirstLineOfRightBlockElementIntoLeftBlockElement(
HTMLEditor& aHTMLEditor, Element& aLeftBlockElement, HTMLEditor& aHTMLEditor, Element& aLeftBlockElement,
Element& aRightBlockElement, const Maybe<nsAtom*>& aListElementTagName, Element& aRightBlockElement, const Maybe<nsAtom*>& aListElementTagName,
const HTMLBRElement* aPrecedingInvisibleBRElement) { const HTMLBRElement* aPrecedingInvisibleBRElement,
const Element& aEditingHost) {
MOZ_ASSERT( MOZ_ASSERT(
!EditorUtils::IsDescendantOf(aLeftBlockElement, aRightBlockElement)); !EditorUtils::IsDescendantOf(aLeftBlockElement, aRightBlockElement));
MOZ_ASSERT( MOZ_ASSERT(
@ -660,14 +665,14 @@ EditActionResult WhiteSpaceVisibilityKeeper::
#ifdef DEBUG #ifdef DEBUG
Result<bool, nsresult> firstLineHasContent = Result<bool, nsresult> firstLineHasContent =
aHTMLEditor.CanMoveOrDeleteSomethingInHardLine( aHTMLEditor.CanMoveOrDeleteSomethingInHardLine(
EditorRawDOMPoint(&aRightBlockElement, 0)); EditorDOMPoint(&aRightBlockElement, 0u), aEditingHost);
#endif // #ifdef DEBUG #endif // #ifdef DEBUG
// Nodes are dissimilar types. // Nodes are dissimilar types.
MoveNodeResult moveNodeResult = MoveNodeResult moveNodeResult =
aHTMLEditor.MoveOneHardLineContentsWithTransaction( aHTMLEditor.MoveOneHardLineContentsWithTransaction(
EditorDOMPoint(&aRightBlockElement, 0u), EditorDOMPoint(&aRightBlockElement, 0u),
EditorDOMPoint(&aLeftBlockElement, 0u), EditorDOMPoint(&aLeftBlockElement, 0u), aEditingHost,
HTMLEditor::MoveToEndOfContainer::Yes); HTMLEditor::MoveToEndOfContainer::Yes);
if (moveNodeResult.isErr()) { if (moveNodeResult.isErr()) {
NS_WARNING( NS_WARNING(

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

@ -1394,13 +1394,15 @@ class WhiteSpaceVisibilityKeeper final {
* @param aListElementTagName Set some if aRightBlockElement is a list * @param aListElementTagName Set some if aRightBlockElement is a list
* element and it'll be merged with another * element and it'll be merged with another
* list element. * list element.
* @param aEditingHost The editing host.
*/ */
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static EditActionResult [[nodiscard]] MOZ_CAN_RUN_SCRIPT static EditActionResult
MergeFirstLineOfRightBlockElementIntoDescendantLeftBlockElement( MergeFirstLineOfRightBlockElementIntoDescendantLeftBlockElement(
HTMLEditor& aHTMLEditor, Element& aLeftBlockElement, HTMLEditor& aHTMLEditor, Element& aLeftBlockElement,
Element& aRightBlockElement, const EditorDOMPoint& aAtRightBlockChild, Element& aRightBlockElement, const EditorDOMPoint& aAtRightBlockChild,
const Maybe<nsAtom*>& aListElementTagName, const Maybe<nsAtom*>& aListElementTagName,
const HTMLBRElement* aPrecedingInvisibleBRElement); const HTMLBRElement* aPrecedingInvisibleBRElement,
const Element& aEditingHost);
/** /**
* MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement() merges * MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement() merges
@ -1421,6 +1423,7 @@ class WhiteSpaceVisibilityKeeper final {
* @param aListElementTagName Set some if aRightBlockElement is a list * @param aListElementTagName Set some if aRightBlockElement is a list
* element and it'll be merged with another * element and it'll be merged with another
* list element. * list element.
* @param aEditingHost The editing host.
*/ */
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static EditActionResult [[nodiscard]] MOZ_CAN_RUN_SCRIPT static EditActionResult
MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement( MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement(
@ -1428,7 +1431,8 @@ class WhiteSpaceVisibilityKeeper final {
Element& aRightBlockElement, const EditorDOMPoint& aAtLeftBlockChild, Element& aRightBlockElement, const EditorDOMPoint& aAtLeftBlockChild,
nsIContent& aLeftContentInBlock, nsIContent& aLeftContentInBlock,
const Maybe<nsAtom*>& aListElementTagName, const Maybe<nsAtom*>& aListElementTagName,
const HTMLBRElement* aPrecedingInvisibleBRElement); const HTMLBRElement* aPrecedingInvisibleBRElement,
const Element& aEditingHost);
/** /**
* MergeFirstLineOfRightBlockElementIntoLeftBlockElement() merges first * MergeFirstLineOfRightBlockElementIntoLeftBlockElement() merges first
@ -1443,12 +1447,14 @@ class WhiteSpaceVisibilityKeeper final {
* removed when this becomes empty. * removed when this becomes empty.
* @param aListElementTagName Set some if aRightBlockElement is a list * @param aListElementTagName Set some if aRightBlockElement is a list
* element and its type needs to be changed. * element and its type needs to be changed.
* @param aEditingHost The editing host.
*/ */
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static EditActionResult [[nodiscard]] MOZ_CAN_RUN_SCRIPT static EditActionResult
MergeFirstLineOfRightBlockElementIntoLeftBlockElement( MergeFirstLineOfRightBlockElementIntoLeftBlockElement(
HTMLEditor& aHTMLEditor, Element& aLeftBlockElement, HTMLEditor& aHTMLEditor, Element& aLeftBlockElement,
Element& aRightBlockElement, const Maybe<nsAtom*>& aListElementTagName, Element& aRightBlockElement, const Maybe<nsAtom*>& aListElementTagName,
const HTMLBRElement* aPrecedingInvisibleBRElement); const HTMLBRElement* aPrecedingInvisibleBRElement,
const Element& aEditingHost);
/** /**
* InsertBRElement() inserts a <br> node at (before) aPointToInsert and delete * InsertBRElement() inserts a <br> node at (before) aPointToInsert and delete