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
// HTMLEditor::MoveBlock() to request special handling in
// HTMLEditor::CreateRangeExtendedToHardLineStartAndEnd() and
// HTMLEditor::SplitInlinesAndCollectEditTargetNodes().
// AutoRangeArray::CreateRangeWrappingStartAndEndLinesContainingBoundaries()
// and HTMLEditor::SplitInlinesAndCollectEditTargetNodes().
eMergeBlockContents,
// eRemoveList removes specific type of list but keep its content.

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

@ -480,9 +480,18 @@ void AutoRangeArray::
}
}
// static
EditorDOMPoint
AutoRangeArray::GetPointAtFirstContentOfLineOrParentBlockIfFirstContentOfBlock(
/**
* Get the point before the line containing aPointInLine.
*
* @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 Element& aEditingHost) {
// FYI: This was moved from
@ -580,9 +589,19 @@ AutoRangeArray::GetPointAtFirstContentOfLineOrParentBlockIfFirstContentOfBlock(
return point;
}
// static
EditorDOMPoint
AutoRangeArray::GetPointAfterFollowingLineBreakOrAtFollowingBlock(
/**
* Get the point after the following line break or the block which breaks the
* 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) {
// FYI: This was moved from
// https://searchfox.org/mozilla-central/rev/3419858c997f422e3e70020a46baae7f0ec6dacc/editor/libeditor/HTMLEditSubActionHandler.cpp#6541
@ -728,6 +747,77 @@ AutoRangeArray::GetPointAfterFollowingLineBreakOrAtFollowingBlock(
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
*****************************************************************************/

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

@ -580,34 +580,18 @@ class MOZ_STACK_CLASS AutoRangeArray final {
const dom::Element& aEditingHost);
/**
* Get the point before the line containing aPointInLine.
*
* @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.
* 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.
*/
static EditorDOMPoint
GetPointAtFirstContentOfLineOrParentBlockIfFirstContentOfBlock(
const EditorDOMPoint& aPointInLine, EditSubAction aEditSubAction,
static already_AddRefed<nsRange>
CreateRangeWrappingStartAndEndLinesContainingBoundaries(
const EditorDOMRange& aRange, EditSubAction aEditSubAction,
const dom::Element& aEditingHost);
/**
* Get the point after the following line break or the block which breaks the
* 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& aPoint, const dom::Element& aEditingHost);
static already_AddRefed<nsRange>
CreateRangeWrappingStartAndEndLinesContainingBoundaries(
const EditorDOMPoint& aStartPoint, const EditorDOMPoint& aEndPoint,
EditSubAction aEditSubAction, const dom::Element& aEditingHost);
private:
AutoTArray<mozilla::OwningNonNull<nsRange>, 8> mRanges;

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

@ -129,28 +129,6 @@ HTMLEditor::CreateRangeIncludingAdjuscentWhiteSpaces(
template already_AddRefed<nsRange>
HTMLEditor::CreateRangeIncludingAdjuscentWhiteSpaces(
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() {
MOZ_ASSERT(IsEditActionDataAvailable());
@ -368,7 +346,7 @@ nsresult HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal() {
AutoTransactionsConserveSelection dontChangeMySelection(*this);
{
EditorRawDOMRange changedRange(
EditorDOMRange changedRange(
*TopLevelEditSubActionDataRef().mChangedRange);
if (changedRange.IsPositioned() &&
changedRange.EnsureNotInNativeAnonymousSubtree()) {
@ -392,16 +370,18 @@ nsresult HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal() {
break;
}
default: {
RefPtr<nsRange> extendedChangedRange =
CreateRangeExtendedToHardLineStartAndEnd(
changedRange, GetTopLevelEditSubAction());
if (extendedChangedRange) {
MOZ_ASSERT(extendedChangedRange->IsPositioned());
// Use extended range temporarily.
TopLevelEditSubActionDataRef().mChangedRange =
std::move(extendedChangedRange);
if (Element* editingHost = ComputeEditingHost()) {
if (RefPtr<nsRange> extendedChangedRange = AutoRangeArray::
CreateRangeWrappingStartAndEndLinesContainingBoundaries(
changedRange, GetTopLevelEditSubAction(),
*editingHost)) {
MOZ_ASSERT(extendedChangedRange->IsPositioned());
// Use extended range temporarily.
TopLevelEditSubActionDataRef().mChangedRange =
std::move(extendedChangedRange);
}
break;
}
break;
}
}
}
@ -6422,6 +6402,8 @@ void HTMLEditor::GetSelectionRangesExtendedToHardLineStartAndEnd(
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(aOutArrayOfRanges.IsEmpty());
Element* editingHost = ComputeEditingHost();
const uint32_t rangeCount = SelectionRef().RangeCount();
aOutArrayOfRanges.SetCapacity(rangeCount);
for (const uint32_t i : IntegerRange(rangeCount)) {
@ -6431,14 +6413,18 @@ void HTMLEditor::GetSelectionRangesExtendedToHardLineStartAndEnd(
// blocks that we will affect. This call alters opRange.
nsRange* selectionRange = SelectionRef().GetRangeAt(i);
MOZ_ASSERT(selectionRange);
EditorRawDOMRange rawRange(*selectionRange);
if (!rawRange.IsPositioned() ||
!rawRange.EnsureNotInNativeAnonymousSubtree()) {
EditorDOMRange editorRange(*selectionRange);
if (!editorRange.IsPositioned() ||
!editorRange.EnsureNotInNativeAnonymousSubtree()) {
continue; // ignore ranges which are in orphan fragment which were
// disconnected from native anonymous subtrees
}
RefPtr<nsRange> extendedRange =
CreateRangeExtendedToHardLineStartAndEnd(rawRange, aEditSubAction);
RefPtr<nsRange> extendedRange;
if (editingHost) {
extendedRange = AutoRangeArray::
CreateRangeWrappingStartAndEndLinesContainingBoundaries(
editorRange, aEditSubAction, *editingHost);
}
if (!extendedRange) {
extendedRange = selectionRange->CloneRange();
}
@ -6531,81 +6517,6 @@ already_AddRefed<nsRange> HTMLEditor::CreateRangeIncludingAdjuscentWhiteSpaces(
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(
nsTArray<OwningNonNull<nsRange>>& aArrayOfRanges,
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents,

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

@ -1243,19 +1243,6 @@ class HTMLEditor final : public EditorBase,
const EditorDOMPointType1& aStartPoint,
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
* 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.
* @param aPointToInsert Point to insert contents of the hard
* line.
* @param aEditingHost The editing host.
* @param aMoveToEndOfContainer If `Yes`, aPointToInsert.Offset() will
* be ignored and instead, all contents
* will be appended to the container of
@ -1996,7 +1984,7 @@ class HTMLEditor final : public EditorBase,
[[nodiscard]] MOZ_CAN_RUN_SCRIPT MoveNodeResult
MoveOneHardLineContentsWithTransaction(
const EditorDOMPoint& aPointInHardLine,
const EditorDOMPoint& aPointToInsert,
const EditorDOMPoint& aPointToInsert, const Element& aEditingHost,
MoveToEndOfContainer aMoveToEndOfContainer = MoveToEndOfContainer::No);
/**
@ -2007,9 +1995,9 @@ class HTMLEditor final : public EditorBase,
*
* @param aPointInHardLine A point in a hard line.
*/
template <typename PT, typename CT>
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

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

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

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

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

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

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