Bug 1815639 - part 7: Make `WhiteSpaceVisibilityKeeper::DeleteContentNodeAndJoinTextNodesAroundIt` stop touching `Selection` directly r=m_kato

Depends on D169752

Differential Revision: https://phabricator.services.mozilla.com/D169753
This commit is contained in:
Masayuki Nakano 2023-02-21 10:38:26 +00:00
Родитель 719116aba8
Коммит 5885f9eaa8
3 изменённых файлов: 119 добавлений и 103 удалений

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

@ -247,36 +247,37 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
const EditorDOMPoint& aPointToDelete, const Element& aEditingHost);
/**
* HandleDeleteCollapsedSelectionAtVisibleChar() handles deletion of
* collapsed selection in a text node.
* Handle deletion of collapsed selection in a text node.
*
* @param aDirectionAndAmount Direction of the deletion.
* @param aPointToDelete The point in a text node to delete character(s).
* Caller must guarantee that this is in a text
* node.
* @param aEditingHost The editing host.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
HandleDeleteCollapsedSelectionAtVisibleChar(
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
const EditorDOMPoint& aPointToDelete);
const EditorDOMPoint& aPointToDelete, const Element& aEditingHost);
/**
* HandleDeleteAtomicContent() handles deletion of atomic elements like
* `<br>`, `<hr>`, `<img>`, `<input>`, etc and data nodes except text node
* (e.g., comment node). Note that don't call this directly with `<hr>`
* element. Instead, call `HandleDeleteHRElement()`. Note that don't call
* this for invisible `<br>` element.
* Handle deletion of atomic elements like <br>, <hr>, <img>, <input>, etc and
* data nodes except text node (e.g., comment node). Note that don't call this
* directly with `<hr>` element. Instead, call HandleDeleteHRElement().
* Note that don't call this for invisible `<br>` element.
*
* @param aAtomicContent The atomic content to be deleted.
* @param aCaretPoint The caret point (i.e., selection start or
* end).
* @param aWSRunScannerAtCaret WSRunScanner instance which was initialized
* with the caret point.
* @param aEditingHost The editing host.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
HandleDeleteAtomicContent(HTMLEditor& aHTMLEditor, nsIContent& aAtomicContent,
const EditorDOMPoint& aCaretPoint,
const WSRunScanner& aWSRunScannerAtCaret);
const WSRunScanner& aWSRunScannerAtCaret,
const Element& aEditingHost);
nsresult ComputeRangesToDeleteAtomicContent(
Element* aEditingHost, const nsIContent& aAtomicContent,
AutoRangeArray& aRangesToDelete) const;
@ -299,11 +300,10 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
const WSScanResult& aScanFromCaretPointResult) MOZ_NONNULL_RETURN;
/**
* HandleDeleteHRElement() handles deletion around `<hr>` element. If
* aDirectionAndAmount is nsIEditor::ePrevious, aHTElement is removed only
* when caret is at next sibling of the `<hr>` element and inter line position
* is "left". Otherwise, caret is moved and does not remove the `<hr>`
* elemnent.
* Handle deletion around `<hr>` element. If aDirectionAndAmount is
* nsIEditor::ePrevious, aHTElement is removed only when caret is at next
* sibling of the `<hr>` element and inter line position is "left".
* Otherwise, caret is moved and does not remove the `<hr>` element.
* XXX Perhaps, we can get rid of this special handling because the other
* browsers don't do this, and our `<hr>` element handling is really
* odd.
@ -314,12 +314,14 @@ class MOZ_STACK_CLASS HTMLEditor::AutoDeleteRangesHandler final {
* end).
* @param aWSRunScannerAtCaret WSRunScanner instance which was initialized
* with the caret point.
* @param aEditingHost The editing host.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<EditActionResult, nsresult>
HandleDeleteHRElement(HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount,
Element& aHRElement, const EditorDOMPoint& aCaretPoint,
const WSRunScanner& aWSRunScannerAtCaret);
const WSRunScanner& aWSRunScannerAtCaret,
const Element& aEditingHost);
nsresult ComputeRangesToDeleteHRElement(
const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
Element& aHRElement, const EditorDOMPoint& aCaretPoint,
@ -1669,32 +1671,25 @@ Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::Run(
// the caret point and use `HandleDeleteNonCollapsedRanges()`
// instead after we would create delete range computation
// method at switching to the new white-space normalizer.
nsresult rv = WhiteSpaceVisibilityKeeper::
DeleteContentNodeAndJoinTextNodesAroundIt(
aHTMLEditor,
MOZ_KnownLive(*scanFromCaretPointResult.BRElementPtr()),
caretPoint.ref());
if (NS_FAILED(rv)) {
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::
DeleteContentNodeAndJoinTextNodesAroundIt(
aHTMLEditor,
MOZ_KnownLive(*scanFromCaretPointResult.BRElementPtr()),
caretPoint.ref(), aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::"
"DeleteContentNodeAndJoinTextNodesAroundIt() failed");
return Err(rv);
return caretPointOrError.propagateErr();
}
if (MOZ_UNLIKELY(aHTMLEditor.SelectionRef().RangeCount() != 1u)) {
NS_WARNING(
"Selection was unexpected after removing an invisible `<br>` "
"element");
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
if (caretPointOrError.inspect().HasCaretPointSuggestion()) {
caretPoint = Some(caretPointOrError.unwrap().UnwrapCaretPoint());
}
AutoRangeArray rangesToDelete(aHTMLEditor.SelectionRef());
caretPoint =
Some(aRangesToDelete.GetFirstRangeStartPoint<EditorDOMPoint>());
if (MOZ_UNLIKELY(!caretPoint.ref().IsSet())) {
NS_WARNING(
"New selection after deleting invisible `<br>` element was "
"invalid");
if (NS_WARN_IF(!caretPoint->IsSetAndValid())) {
return Err(NS_ERROR_FAILURE);
}
AutoRangeArray rangesToDelete(caretPoint.ref());
if (aHTMLEditor.MayHaveMutationEventListeners(
NS_EVENT_BITS_MUTATION_SUBTREEMODIFIED |
NS_EVENT_BITS_MUTATION_NODEREMOVED |
@ -1926,7 +1921,7 @@ HTMLEditor::AutoDeleteRangesHandler::HandleDeleteAroundCollapsedRanges(
Result<EditActionResult, nsresult> result =
HandleDeleteCollapsedSelectionAtVisibleChar(
aHTMLEditor, aDirectionAndAmount,
aScanFromCaretPointResult.Point<EditorDOMPoint>());
aScanFromCaretPointResult.Point<EditorDOMPoint>(), aEditingHost);
NS_WARNING_ASSERTION(result.isOk(),
"AutoDeleteRangesHandler::"
"HandleDeleteCollapsedSelectionAtVisibleChar() "
@ -1951,7 +1946,7 @@ HTMLEditor::AutoDeleteRangesHandler::HandleDeleteAroundCollapsedRanges(
}
Result<EditActionResult, nsresult> result = HandleDeleteAtomicContent(
aHTMLEditor, *atomicContent, aWSRunScannerAtCaret.ScanStartRef(),
aWSRunScannerAtCaret);
aWSRunScannerAtCaret, aEditingHost);
NS_WARNING_ASSERTION(
result.isOk(),
"AutoDeleteRangesHandler::HandleDeleteAtomicContent() failed");
@ -1966,7 +1961,8 @@ HTMLEditor::AutoDeleteRangesHandler::HandleDeleteAroundCollapsedRanges(
Result<EditActionResult, nsresult> result = HandleDeleteHRElement(
aHTMLEditor, aDirectionAndAmount,
MOZ_KnownLive(*aScanFromCaretPointResult.ElementPtr()),
aWSRunScannerAtCaret.ScanStartRef(), aWSRunScannerAtCaret);
aWSRunScannerAtCaret.ScanStartRef(), aWSRunScannerAtCaret,
aEditingHost);
NS_WARNING_ASSERTION(
result.isOk(),
"AutoDeleteRangesHandler::HandleDeleteHRElement() failed");
@ -2177,7 +2173,7 @@ Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
HandleDeleteCollapsedSelectionAtVisibleChar(
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
const EditorDOMPoint& aPointToDelete) {
const EditorDOMPoint& aPointToDelete, const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsTopLevelEditSubActionDataAvailable());
MOZ_ASSERT(!StaticPrefs::editor_white_space_normalization_blink_compatible());
MOZ_ASSERT(aPointToDelete.IsSet());
@ -2214,7 +2210,7 @@ Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
{
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::PrepareToDeleteRangeAndTrackPoints(
aHTMLEditor, &startToDelete, &endToDelete);
aHTMLEditor, &startToDelete, &endToDelete, aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::PrepareToDeleteRangeAndTrackPoints() "
@ -2404,7 +2400,7 @@ Result<EditActionResult, nsresult>
HTMLEditor::AutoDeleteRangesHandler::HandleDeleteHRElement(
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
Element& aHRElement, const EditorDOMPoint& aCaretPoint,
const WSRunScanner& aWSRunScannerAtCaret) {
const WSRunScanner& aWSRunScannerAtCaret, const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(aHRElement.IsHTMLElement(nsGkAtoms::hr));
MOZ_ASSERT(&aHRElement != aWSRunScannerAtCaret.GetEditingHost());
@ -2416,8 +2412,9 @@ HTMLEditor::AutoDeleteRangesHandler::HandleDeleteHRElement(
return canDeleteHRElement.propagateErr();
}
if (canDeleteHRElement.inspect()) {
Result<EditActionResult, nsresult> result = HandleDeleteAtomicContent(
aHTMLEditor, aHRElement, aCaretPoint, aWSRunScannerAtCaret);
Result<EditActionResult, nsresult> result =
HandleDeleteAtomicContent(aHTMLEditor, aHRElement, aCaretPoint,
aWSRunScannerAtCaret, aEditingHost);
NS_WARNING_ASSERTION(
result.isOk(),
"AutoDeleteRangesHandler::HandleDeleteAtomicContent() failed");
@ -2464,17 +2461,27 @@ HTMLEditor::AutoDeleteRangesHandler::HandleDeleteHRElement(
}
// Delete the <br>
nsresult rv =
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::DeleteContentNodeAndJoinTextNodesAroundIt(
aHTMLEditor,
MOZ_KnownLive(*forwardScanFromCaretResult.BRElementPtr()),
aCaretPoint);
if (NS_FAILED(rv)) {
aCaretPoint, aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::DeleteContentNodeAndJoinTextNodesAroundIt("
") failed");
return caretPointOrError.propagateErr();
}
nsresult rv = caretPointOrError.unwrap().SuggestCaretPointTo(
aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});
if (NS_FAILED(rv)) {
NS_WARNING("CaretPoint::SuggestCaretPointTo() failed");
return Err(rv);
}
NS_WARNING_ASSERTION(rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
"CaretPoint::SuggestCaretPointTo() failed, but ignored");
return EditActionResult::HandledResult();
}
@ -2531,21 +2538,31 @@ HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteAtomicContent(
Result<EditActionResult, nsresult>
HTMLEditor::AutoDeleteRangesHandler::HandleDeleteAtomicContent(
HTMLEditor& aHTMLEditor, nsIContent& aAtomicContent,
const EditorDOMPoint& aCaretPoint,
const WSRunScanner& aWSRunScannerAtCaret) {
const EditorDOMPoint& aCaretPoint, const WSRunScanner& aWSRunScannerAtCaret,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(!HTMLEditUtils::IsInvisibleBRElement(aAtomicContent));
MOZ_ASSERT(&aAtomicContent != aWSRunScannerAtCaret.GetEditingHost());
nsresult rv =
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::DeleteContentNodeAndJoinTextNodesAroundIt(
aHTMLEditor, aAtomicContent, aCaretPoint);
if (NS_FAILED(rv)) {
aHTMLEditor, aAtomicContent, aCaretPoint, aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::DeleteContentNodeAndJoinTextNodesAroundIt("
") failed");
return caretPointOrError.propagateErr();
}
nsresult rv = caretPointOrError.unwrap().SuggestCaretPointTo(
aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});
if (NS_FAILED(rv)) {
NS_WARNING("CaretPoint::SuggestCaretPointTo() failed");
return Err(rv);
}
NS_WARNING_ASSERTION(rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
"CaretPoint::SuggestCaretPointTo() failed, but ignored");
const auto newCaretPosition =
aHTMLEditor.GetFirstSelectionStartPoint<EditorDOMPoint>();
@ -3422,7 +3439,8 @@ HTMLEditor::AutoDeleteRangesHandler::HandleDeleteNonCollapsedRanges(
&aRangesToDelete.FirstRangeRef());
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::PrepareToDeleteRange(
aHTMLEditor, EditorDOMRange(aRangesToDelete.FirstRangeRef()));
aHTMLEditor, EditorDOMRange(aRangesToDelete.FirstRangeRef()),
aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING("WhiteSpaceVisibilityKeeper::PrepareToDeleteRange() failed");
return caretPointOrError.propagateErr();

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

@ -686,7 +686,8 @@ Result<EditActionResult, nsresult> WhiteSpaceVisibilityKeeper::
MakeSureToKeepVisibleStateOfWhiteSpacesAroundDeletingRange(
aHTMLEditor,
EditorDOMRange(EditorDOMPoint::AtEndOf(aLeftBlockElement),
EditorDOMPoint(&aRightBlockElement, 0)));
EditorDOMPoint(&aRightBlockElement, 0)),
aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::"
@ -1435,7 +1436,7 @@ WhiteSpaceVisibilityKeeper::DeletePreviousWhiteSpace(
{
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::PrepareToDeleteRangeAndTrackPoints(
aHTMLEditor, &startToDelete, &endToDelete);
aHTMLEditor, &startToDelete, &endToDelete, aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::PrepareToDeleteRangeAndTrackPoints() "
@ -1473,7 +1474,7 @@ WhiteSpaceVisibilityKeeper::DeletePreviousWhiteSpace(
{
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::PrepareToDeleteRangeAndTrackPoints(
aHTMLEditor, &startToDelete, &endToDelete);
aHTMLEditor, &startToDelete, &endToDelete, aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::PrepareToDeleteRangeAndTrackPoints() "
@ -1546,7 +1547,7 @@ WhiteSpaceVisibilityKeeper::DeleteInclusiveNextWhiteSpace(
{
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::PrepareToDeleteRangeAndTrackPoints(
aHTMLEditor, &startToDelete, &endToDelete);
aHTMLEditor, &startToDelete, &endToDelete, aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::PrepareToDeleteRangeAndTrackPoints() "
@ -1584,7 +1585,7 @@ WhiteSpaceVisibilityKeeper::DeleteInclusiveNextWhiteSpace(
{
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::PrepareToDeleteRangeAndTrackPoints(
aHTMLEditor, &startToDelete, &endToDelete);
aHTMLEditor, &startToDelete, &endToDelete, aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::PrepareToDeleteRangeAndTrackPoints() "
@ -1626,79 +1627,71 @@ WhiteSpaceVisibilityKeeper::DeleteInclusiveNextWhiteSpace(
}
// static
nsresult WhiteSpaceVisibilityKeeper::DeleteContentNodeAndJoinTextNodesAroundIt(
Result<CaretPoint, nsresult>
WhiteSpaceVisibilityKeeper::DeleteContentNodeAndJoinTextNodesAroundIt(
HTMLEditor& aHTMLEditor, nsIContent& aContentToDelete,
const EditorDOMPoint& aCaretPoint) {
const EditorDOMPoint& aCaretPoint, const Element& aEditingHost) {
EditorDOMPoint atContent(&aContentToDelete);
if (!atContent.IsSet()) {
NS_WARNING("Deleting content node was an orphan node");
return NS_ERROR_FAILURE;
return Err(NS_ERROR_FAILURE);
}
if (!HTMLEditUtils::IsRemovableNode(aContentToDelete)) {
NS_WARNING("Deleting content node wasn't removable");
return NS_ERROR_FAILURE;
return Err(NS_ERROR_FAILURE);
}
Result<CaretPoint, nsresult> caretPointOrError = WhiteSpaceVisibilityKeeper::
MakeSureToKeepVisibleStateOfWhiteSpacesAroundDeletingRange(
aHTMLEditor, EditorDOMRange(atContent, atContent.NextPoint()));
aHTMLEditor, EditorDOMRange(atContent, atContent.NextPoint()),
aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::"
"MakeSureToKeepVisibleStateOfWhiteSpacesAroundDeletingRange() failed");
return caretPointOrError.unwrapErr();
return caretPointOrError;
}
nsresult rv = caretPointOrError.unwrap().SuggestCaretPointTo(
aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});
if (NS_FAILED(rv)) {
NS_WARNING("CaretPoint::SuggestCaretPointTo() failed");
return rv;
}
NS_WARNING_ASSERTION(rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
"CaretPoint::SuggestCaretPointTo() failed, but ignored");
nsCOMPtr<nsIContent> previousEditableSibling =
HTMLEditUtils::GetPreviousSibling(
aContentToDelete, {WalkTreeOption::IgnoreNonEditableNode});
// Delete the node, and join like nodes if appropriate
rv = aHTMLEditor.DeleteNodeWithTransaction(aContentToDelete);
nsresult rv = aHTMLEditor.DeleteNodeWithTransaction(aContentToDelete);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
return rv;
caretPointOrError.unwrap().IgnoreCaretPointSuggestion();
return Err(rv);
}
// Are they both text nodes? If so, join them!
// XXX This may cause odd behavior if there is non-editable nodes
// around the atomic content.
if (!aCaretPoint.IsInTextNode() || !previousEditableSibling ||
!previousEditableSibling->IsText()) {
return NS_OK;
return caretPointOrError;
}
nsIContent* nextEditableSibling = HTMLEditUtils::GetNextSibling(
*previousEditableSibling, {WalkTreeOption::IgnoreNonEditableNode});
if (aCaretPoint.GetContainer() != nextEditableSibling) {
return NS_OK;
return caretPointOrError;
}
caretPointOrError.unwrap().IgnoreCaretPointSuggestion();
EditorDOMPoint atFirstChildOfRightNode;
rv = aHTMLEditor.JoinNearestEditableNodesWithTransaction(
*previousEditableSibling, MOZ_KnownLive(*aCaretPoint.ContainerAs<Text>()),
&atFirstChildOfRightNode);
if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::JoinNearestEditableNodesWithTransaction() failed");
return rv;
return Err(rv);
}
if (!atFirstChildOfRightNode.IsSet()) {
NS_WARNING(
"HTMLEditor::JoinNearestEditableNodesWithTransaction() didn't return "
"right node position");
return NS_ERROR_FAILURE;
return Err(NS_ERROR_FAILURE);
}
// Fix up selection
rv = aHTMLEditor.CollapseSelectionTo(atFirstChildOfRightNode);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"EditorBase::CollapseSelectionTo() failed");
return rv;
return CaretPoint(std::move(atFirstChildOfRightNode));
}
template <typename PT, typename CT>
@ -2355,7 +2348,8 @@ WSRunScanner::TextFragmentData::VisibleWhiteSpacesDataRef() const {
// static
Result<CaretPoint, nsresult> WhiteSpaceVisibilityKeeper::
MakeSureToKeepVisibleStateOfWhiteSpacesAroundDeletingRange(
HTMLEditor& aHTMLEditor, const EditorDOMRange& aRangeToDelete) {
HTMLEditor& aHTMLEditor, const EditorDOMRange& aRangeToDelete,
const Element& aEditingHost) {
if (NS_WARN_IF(!aRangeToDelete.IsPositionedAndValid()) ||
NS_WARN_IF(!aRangeToDelete.IsInContentNodes())) {
return Err(NS_ERROR_INVALID_ARG);
@ -2368,13 +2362,12 @@ Result<CaretPoint, nsresult> WhiteSpaceVisibilityKeeper::
NS_EVENT_BITS_MUTATION_NODEREMOVEDFROMDOCUMENT |
NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED);
RefPtr<Element> editingHost = aHTMLEditor.ComputeEditingHost();
TextFragmentData textFragmentDataAtStart(rangeToDelete.StartRef(),
editingHost);
&aEditingHost);
if (NS_WARN_IF(!textFragmentDataAtStart.IsInitialized())) {
return Err(NS_ERROR_FAILURE);
}
TextFragmentData textFragmentDataAtEnd(rangeToDelete.EndRef(), editingHost);
TextFragmentData textFragmentDataAtEnd(rangeToDelete.EndRef(), &aEditingHost);
if (NS_WARN_IF(!textFragmentDataAtEnd.IsInitialized())) {
return Err(NS_ERROR_FAILURE);
}
@ -2470,7 +2463,7 @@ Result<CaretPoint, nsresult> WhiteSpaceVisibilityKeeper::
if (mayBecomeUnexpectedDOMTree) {
// If focus is changed by mutation event listeners, we should stop
// handling this edit action.
if (editingHost != aHTMLEditor.ComputeEditingHost()) {
if (&aEditingHost != aHTMLEditor.ComputeEditingHost()) {
NS_WARNING("Active editing host was changed");
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
@ -2482,9 +2475,9 @@ Result<CaretPoint, nsresult> WhiteSpaceVisibilityKeeper::
// should retrieve the latest data for avoiding to delete/replace
// unexpected range.
textFragmentDataAtStart =
TextFragmentData(rangeToDelete.StartRef(), editingHost);
TextFragmentData(rangeToDelete.StartRef(), &aEditingHost);
textFragmentDataAtEnd =
TextFragmentData(rangeToDelete.EndRef(), editingHost);
TextFragmentData(rangeToDelete.EndRef(), &aEditingHost);
}
}
ReplaceRangeData replaceRangeDataAtStart =

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

@ -1343,14 +1343,16 @@ class WhiteSpaceVisibilityKeeper final {
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<CaretPoint, nsresult>
PrepareToDeleteRangeAndTrackPoints(HTMLEditor& aHTMLEditor,
EditorDOMPoint* aStartPoint,
EditorDOMPoint* aEndPoint) {
EditorDOMPoint* aEndPoint,
const Element& aEditingHost) {
MOZ_ASSERT(aStartPoint->IsSetAndValid());
MOZ_ASSERT(aEndPoint->IsSetAndValid());
AutoTrackDOMPoint trackerStart(aHTMLEditor.RangeUpdaterRef(), aStartPoint);
AutoTrackDOMPoint trackerEnd(aHTMLEditor.RangeUpdaterRef(), aEndPoint);
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::PrepareToDeleteRange(
aHTMLEditor, EditorDOMRange(*aStartPoint, *aEndPoint));
aHTMLEditor, EditorDOMRange(*aStartPoint, *aEndPoint),
aEditingHost);
NS_WARNING_ASSERTION(
caretPointOrError.isOk(),
"WhiteSpaceVisibilityKeeper::PrepareToDeleteRange() failed");
@ -1359,24 +1361,26 @@ class WhiteSpaceVisibilityKeeper final {
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<CaretPoint, nsresult>
PrepareToDeleteRange(HTMLEditor& aHTMLEditor,
const EditorDOMPoint& aStartPoint,
const EditorDOMPoint& aEndPoint) {
const EditorDOMPoint& aEndPoint,
const Element& aEditingHost) {
MOZ_ASSERT(aStartPoint.IsSetAndValid());
MOZ_ASSERT(aEndPoint.IsSetAndValid());
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::PrepareToDeleteRange(
aHTMLEditor, EditorDOMRange(aStartPoint, aEndPoint));
aHTMLEditor, EditorDOMRange(aStartPoint, aEndPoint), aEditingHost);
NS_WARNING_ASSERTION(
caretPointOrError.isOk(),
"WhiteSpaceVisibilityKeeper::PrepareToDeleteRange() failed");
return caretPointOrError;
}
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<CaretPoint, nsresult>
PrepareToDeleteRange(HTMLEditor& aHTMLEditor, const EditorDOMRange& aRange) {
PrepareToDeleteRange(HTMLEditor& aHTMLEditor, const EditorDOMRange& aRange,
const Element& aEditingHost) {
MOZ_ASSERT(aRange.IsPositionedAndValid());
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::
MakeSureToKeepVisibleStateOfWhiteSpacesAroundDeletingRange(
aHTMLEditor, aRange);
aHTMLEditor, aRange, aEditingHost);
NS_WARNING_ASSERTION(
caretPointOrError.isOk(),
"WhiteSpaceVisibilityKeeper::"
@ -1542,15 +1546,15 @@ class WhiteSpaceVisibilityKeeper final {
const Element& aEditingHost);
/**
* DeleteContentNodeAndJoinTextNodesAroundIt() deletes aContentToDelete and
* may remove/replace white-spaces around it. Then, if deleting content makes
* 2 text nodes around it are adjacent siblings, this joins them and put
* selection at the joined point.
* Delete aContentToDelete and may remove/replace white-spaces around it.
* Then, if deleting content makes 2 text nodes around it are adjacent
* siblings, this joins them and put selection at the joined point.
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static nsresult
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<CaretPoint, nsresult>
DeleteContentNodeAndJoinTextNodesAroundIt(HTMLEditor& aHTMLEditor,
nsIContent& aContentToDelete,
const EditorDOMPoint& aCaretPoint);
const EditorDOMPoint& aCaretPoint,
const Element& aEditingHost);
/**
* Try to normalize visible white-space sequence around aPoint.
@ -1571,7 +1575,8 @@ class WhiteSpaceVisibilityKeeper final {
*/
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<CaretPoint, nsresult>
MakeSureToKeepVisibleStateOfWhiteSpacesAroundDeletingRange(
HTMLEditor& aHTMLEditor, const EditorDOMRange& aRangeToDelete);
HTMLEditor& aHTMLEditor, const EditorDOMRange& aRangeToDelete,
const Element& aEditingHost);
/**
* MakeSureToKeepVisibleWhiteSpacesVisibleAfterSplit() replaces ASCII white-