|
|
|
|
Quelle HTMLEditorDeleteHandler.cpp Sprache: C
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "HTMLEditor.h"
#include "HTMLEditorNestedClasses.h"
#include <fmt/format.h>
#include <utility>
#include "AutoClonedRangeArray.h"
#include "CSSEditUtils.h"
#include "EditAction.h"
#include "EditorDOMAPIWrapper.h"
#include "EditorDOMPoint.h"
#include "EditorLineBreak.h"
#include "EditorUtils.h"
#include "HTMLEditHelpers.h"
#include "HTMLEditorInlines.h"
#include "HTMLEditUtils.h"
#include "WhiteSpaceVisibilityKeeper.h"
#include "WSRunScanner.h"
#include "ErrorList.h"
#include "mozilla/Assertions.h"
#include "mozilla/ContentIterator.h"
#include "mozilla/Logging.h"
#include "mozilla/Maybe.h"
#include "mozilla/OwningNonNull.h"
#include "mozilla/PresShell.h"
#include "mozilla/SelectionState.h"
#include "mozilla/StaticPrefs_editor.h" // for StaticPrefs::editor_*
#include "mozilla/dom/AncestorIterator.h"
#include "mozilla/dom/EditContext.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ElementInlines.h" // for Element::IsContentEditablePlainTextOnly
#include "mozilla/dom/HTMLBRElement.h"
#include "mozilla/dom/Selection.h"
#include "nsAtom.h"
#include "nsComputedDOMStyle.h" // for nsComputedDOMStyle
#include "nsContentUtils.h"
#include "nsDebug.h"
#include "nsError.h"
#include "nsFrameSelection.h"
#include "nsGkAtoms.h"
#include "nsIContent.h"
#include "nsINode.h"
#include "nsRange.h"
#include "nsString.h"
#include "nsStringFwd.h"
#include "nsStyleConsts.h" // for StyleWhiteSpace
#include "nsTArray.h"
#include "nsTextNode.h"
// NOTE: This file was split from:
// https://searchfox.org/mozilla-central/rev/c409dd9235c133ab41eba635f906aa16e050c197/editor/libeditor/HTMLEditSubActionHandler.cpp
namespace mozilla {
using namespace dom;
using EditablePointOption = HTMLEditUtils::EditablePointOption;
using EditablePointOptions = HTMLEditUtils::EditablePointOptions;
using EmptyCheckOption = HTMLEditUtils::EmptyCheckOption;
using InvisibleWhiteSpaces = HTMLEditUtils::InvisibleWhiteSpaces;
using LeafNodeOption = HTMLEditUtils::LeafNodeOption;
using TableBoundary = HTMLEditUtils::TableBoundary;
using TreatInvisibleLineBreakAs = HTMLEditUtils::TreatInvisibleLineBreakAs;
static LazyLogModule gOneLineMoverLog( "AutoMoveOneLineHandler");
template Result<CaretPoint, nsresult>
HTMLEditor::DeleteTextAndTextNodesWithTransaction(
const EditorDOMPoint& aStartPoint, const EditorDOMPoint& aEndPoint,
TreatEmptyTextNodes aTreatEmptyTextNodes);
template Result<CaretPoint, nsresult>
HTMLEditor::DeleteTextAndTextNodesWithTransaction(
const EditorDOMPointInText& aStartPoint,
const EditorDOMPointInText& aEndPoint,
TreatEmptyTextNodes aTreatEmptyTextNodes);
/**
* Return true if aNode does not have meaningful content (e.g., only has
* non-zero width border) or a line break which is followed by a block boundary.
* NOTE: This is designed to check deleting meaningless content or not. Thus,
* this is not declared in HTMLEditUtils nor HTMLEditor to prevent a misuse.
*/
static bool NodeIsInvisibleOrLineBreakFollowedByBlockBoundary(
const nsINode& aNode) {
if (MOZ_UNLIKELY(!aNode.IsText() && !aNode.IsElement())) {
return true; // nodes not `Text` nor an element are invisible.
}
if ( const Text* const text = Text::FromNode(aNode)) {
return !HTMLEditUtils::IsVisibleTextNode(
*text, TreatInvisibleLineBreakAs::Visible);
}
const Element& element = *aNode.AsElement();
if ( const HTMLBRElement* const brElement = HTMLBRElement::FromNode(element)) {
return HTMLEditUtils::IsBRElementFollowedByBlockBoundary(*brElement);
}
if (HTMLEditUtils::IsReplacedElement(element)) {
return !HTMLEditUtils::IsVisibleElementEvenIfLeafNode(element);
}
if (nsIContent* const visibleLeaf = HTMLEditUtils::GetFirstLeafContent(
element, {LeafNodeOption::IgnoreNonEditableNode,
LeafNodeOption::IgnoreAnyEmptyInlineContainers,
LeafNodeOption::IgnoreInvisibleText})) {
Element* followingBlockBoundaryElement = nullptr;
if (visibleLeaf->IsText()) {
const Maybe<EditorRawLineBreak> preformattedLineBreak =
EditorRawLineBreak::CreateIfTextHasOnlyOneAndNoOtherVisibleCharacters(
*visibleLeaf->AsText());
if (!preformattedLineBreak ||
!HTMLEditUtils::IsPreformattedLineBreakFollowedByBlockBoundary(
preformattedLineBreak->To<EditorRawDOMPoint>(),
HTMLEditUtils::SkipWhiteSpaceStyleCheck::Yes, nullptr,
&followingBlockBoundaryElement)) {
return false; // Visible `Text`.
}
} else {
if (!HTMLEditUtils::IsBRElementFollowedByBlockBoundary(
*visibleLeaf, nullptr, &followingBlockBoundaryElement)) {
return false; // An element which may be visible.
}
}
MOZ_ASSERT(followingBlockBoundaryElement);
// If the following block boundary is a child of the element, the element is
// visible because the element is or contains a child block. Otherwise, it
// contains only the invisible line break.
return !followingBlockBoundaryElement->IsInclusiveDescendantOf(&element);
}
// The element is empty so that it's invisible. Note that we can treat a
// visible inline container element which has no significant content, e.g.,
// has only a border as invisible at deletion.
return true;
}
bool HTMLEditor::AutoDeleteRangesHandler::
CanFallbackToDeleteRangeWithTransaction(
const nsRange& aRangeToDelete) const {
return !IsHandlingRecursively() &&
(!aRangeToDelete.Collapsed() ||
EditorBase::HowToHandleCollapsedRangeFor(
mOriginalDirectionAndAmount) !=
EditorBase::HowToHandleCollapsedRange::Ignore);
}
bool HTMLEditor::AutoDeleteRangesHandler::
CanFallbackToDeleteRangesWithTransaction(
const AutoClonedSelectionRangeArray& aRangesToDelete) const {
return !IsHandlingRecursively() && !aRangesToDelete.Ranges().IsEmpty() &&
(!aRangesToDelete.IsCollapsed() ||
EditorBase::HowToHandleCollapsedRangeFor(
mOriginalDirectionAndAmount) !=
EditorBase::HowToHandleCollapsedRange::Ignore);
}
Result<CaretPoint, nsresult>
HTMLEditor::AutoDeleteRangesHandler::FallbackToDeleteRangesWithTransaction(
HTMLEditor& aHTMLEditor, AutoClonedSelectionRangeArray& aRangesToDelete,
const Element& aEditingHost) const {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(CanFallbackToDeleteRangesWithTransaction(aRangesToDelete));
const auto stripWrappers = [&]() -> nsIEditor::EStripWrappers {
if (mOriginalStripWrappers == nsIEditor::eStrip &&
aEditingHost.IsContentEditablePlainTextOnly()) {
return nsIEditor::eNoStrip;
}
return mOriginalStripWrappers;
}();
{
AutoTrackDOMRange firstRangeTracker(aHTMLEditor.RangeUpdaterRef(),
&aRangesToDelete.FirstRangeRef());
for (OwningNonNull<nsRange>& range : Reversed(aRangesToDelete.Ranges())) {
if (MOZ_UNLIKELY(!range->IsPositioned() || range->Collapsed())) {
continue;
}
Maybe<AutoTrackDOMRange> trackRange;
if (range != aRangesToDelete.FirstRangeRef()) {
trackRange.emplace(aHTMLEditor.RangeUpdaterRef(), &range);
}
Result<EditorDOMRange, nsresult> rangeToDeleteOrError =
WhiteSpaceVisibilityKeeper::NormalizeSurroundingWhiteSpacesToJoin(
aHTMLEditor, EditorDOMRange(range));
if (MOZ_UNLIKELY(rangeToDeleteOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::NormalizeSurroundingWhiteSpacesToJoin("
") failed");
return rangeToDeleteOrError.propagateErr();
}
trackRange.reset();
EditorDOMRange rangeToDelete = rangeToDeleteOrError.unwrap();
if (MOZ_LIKELY(rangeToDelete.IsPositionedAndValidInComposedDoc())) {
nsresult rv =
range->SetStartAndEnd(rangeToDelete.StartRef().ToRawRangeBoundary(),
rangeToDelete.EndRef().ToRawRangeBoundary());
if (NS_FAILED(rv)) {
NS_WARNING( "nsRange::SetStartAndEnd() failed");
return Err(rv);
}
}
}
}
aRangesToDelete.RemoveCollapsedRanges();
if (MOZ_UNLIKELY(aRangesToDelete.IsCollapsed())) {
return CaretPoint(
EditorDOMPoint(aRangesToDelete.FirstRangeRef()->StartRef()));
}
Result<CaretPoint, nsresult> caretPointOrError =
aHTMLEditor.DeleteRangesWithTransaction(mOriginalDirectionAndAmount,
stripWrappers, aRangesToDelete);
NS_WARNING_ASSERTION(caretPointOrError.isOk(),
"HTMLEditor::DeleteRangesWithTransaction() failed");
return caretPointOrError;
}
nsresult
HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteRangesWithTransaction(
const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
AutoClonedSelectionRangeArray& aRangesToDelete,
const Element& aEditingHost) const {
MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty());
const EditorBase::HowToHandleCollapsedRange howToHandleCollapsedRange =
EditorBase::HowToHandleCollapsedRangeFor(aDirectionAndAmount);
if (NS_WARN_IF(aRangesToDelete.IsCollapsed() &&
howToHandleCollapsedRange ==
EditorBase::HowToHandleCollapsedRange::Ignore)) {
return NS_ERROR_FAILURE;
}
const auto stripWrappers = [&]() -> nsIEditor::EStripWrappers {
if (mOriginalStripWrappers == nsIEditor::eStrip &&
aEditingHost.IsContentEditablePlainTextOnly()) {
return nsIEditor::eNoStrip;
}
return mOriginalStripWrappers;
}();
aRangesToDelete.ExtendRangeToContainSurroundingInvisibleWhiteSpaces(
stripWrappers);
if (MOZ_UNLIKELY(aRangesToDelete.IsCollapsed() &&
howToHandleCollapsedRange ==
EditorBase::HowToHandleCollapsedRange::Ignore)) {
return NS_OK;
}
for ( const OwningNonNull<nsRange>& range : aRangesToDelete.Ranges()) {
if (range->Collapsed()) {
continue;
}
nsresult rv = ComputeRangeToDeleteRangeWithTransaction(
aHTMLEditor, aDirectionAndAmount, range, aEditingHost);
N
java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for leng th 17
:java.lang.StringIndexOutOfBoundsException: Range [80, 76) out of bounds for length 80
"AutoClonedjava.lang.StringIndexOutOfBoundsException: Range [69, 60) out of bounds for length 69
return
}
return :ollapse
} editingHost;
<ditActionResult>
HTMLEditor:: Err(NS_ERROR_FAILURE
HTMLEditor& aHTMLEditor, nsresult rv = editableSelectionRanges.Collapse(
nsIEditor::EStripWrappers aStripWrappers, const EditorDOMPoint& aCaretPoint,
nsRange& aRangeToDelete, const Element& aEditingHost) {
switch (mMode) {
urrentBlock java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
java.lang.StringIndexOutOfBoundsException: Range [0, 44) out of bounds for length 7
java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 41
"AutoBlockElementsJoiner::"
"HandleDeleteAtCurrentBlockBoundary() failed");
java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 20
}
case Mode::JoinOtherBlock: {
Result<EditActionResult, nsresult> result =
EditActionResultjava.lang.StringIndexOutOfBoundsException: Range [42, 40) out of bounds for length 43
java.lang.StringIndexOutOfBoundsException: Range [23, 21) out of bounds for length 76
java.lang.StringIndexOutOfBoundsException: Range [73, 71) out of bounds for length 73
java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 27
result.isOk(),
"AutoBlockElementsJoiner::HandleDeleteAtOtherBlockBoundary() failed
return result;
}
case Mode::DeleteBRElement:
case Mode::DeletePrecedingBRElementOfBlock:
java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 54
, java.lang.StringIndexOutOfBoundsException: Range [72, 71) out of bounds for length 72
aHTMLEditor, java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 7
java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 27
result.isOk(),
:)";
return result;
}
case Mode::JoinBlocksInSameParent:
case Mode:: java.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 61
case Mode:: (NS_WARN_IF(!parentNode)) {
case Mode::DeletePrecedingLinesAndContentInRange:
java.lang.StringIndexOutOfBoundsException: Range [30, 28) out of bounds for length 79
return Err(java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 5
case Mode::NotInitialized:
::java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 47
}
);
}
nsresult HTMLEditor
(NS_WARN_IF(nextSiblingjava.lang.StringIndexOutOfBoundsException: Range [32, 30) out of bounds for length 80
:java.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bounds for length 67
const EditorDOMPoint& aCaretPoint,
nsRange&aRangeToDeletejava.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
const Element& aEditingHost) const {
switch (mMode) {
Mode:JoinCurrentBlock:java.lang.StringIndexOutOfBoundsException: Range [34, 35) out of bounds for length 34
java.lang.StringIndexOutOfBoundsException: Range [50, 14) out of bounds for length 63
int,java.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 66
java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 27
NS_SUCCEEDED(rv),
java.lang.StringIndexOutOfBoundsException: Range [28, 10) out of bounds for length 80
"}
return rvifNjava.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 75
}
case Mode::JoinOtherBlock: {
nsresult rv = java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 3
aHTMLEditor
aEditingHostjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
,
"() ";
return rv;
}
case Mode::DeleteBRElement:
case Mode::DeletePrecedingBRElementOfBlock:
case Mode:neBreak:{
nsresult rv = ComputeRangeToDeleteLineBreak(
aHTMLEditor, aRangeToDelete, const <lement> =
ComputeRangeFor::GetTargetRanges);
NS_WARNING_ASSERTION(
(v,
"AutoBlockElementsJoiner::java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 36
return java.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 70
}
case returjava.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 66
case Mode::DeleteContentInRange
ModeD
case aDirectionAndAmountjava.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 60
MOZ_ASSERT_UNREACHABLE(
"This mode should java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
return NS_ERROR_UNEXPECTED;()= EditSubAction::eDeleteSelectedContent;
case Mode::NotInitialized:
;
}
java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 34
}
Result<EditActionResult, nsresult>
HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::Run(
HTMLEditor& aHTMLEditor, const LimitersAndCaretData& aLimitersAndCaretData,
nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers, nsRange& aRangeToDelete,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const Element& aEditingHost) {
switch (mMode) {
case Mode::JoinCurrentBlock:
case Mode::JoinOtherBlock:
case Mode::DeleteBRElement:
case Mode::DeletePrecedingBRElementOfBlock:
case Mode::DeletePrecedingPreformattedLineBreak:
MOZ_ASSERT_UNREACHABLE("This mode should be handled in the other Run()");
return Err(NS_ERROR_UNEXPECTED);
case Mode::JoinBlocksInSameParent: {
Result<EditActionResult, nsresult> result = JoinBlockElementsInSameParent(
aHTMLEditor, aLimitersAndCaretData, aDirectionAndAmount,
aStripWrappers, aRangeToDelete, aSelectionWasCollapsed, aEditingHost);
NS_WARNING_ASSERTION(
result.isOk(),
"AutoBlockElementsJoiner::JoinBlockElementsInSameParent() failed");
return result;
}
case Mode::DeleteContentInRange: {
Result<EditActionResult, nsresult> result = DeleteContentInRange(
aHTMLEditor, aLimitersAndCaretData, aDirectionAndAmount,
aStripWrappers, aRangeToDelete, aEditingHost);
NS_WARNING_ASSERTION(
result.isOk(),
"AutoBlockElementsJoiner::DeleteContentInRange() failed");
return result;
}
case Mode::DeleteNonCollapsedRange:
case Mode::DeletePrecedingLinesAndContentInRange: {
Result<EditActionResult, nsresult> result = HandleDeleteNonCollapsedRange(
aHTMLEditor, aDirectionAndAmount, aStripWrappers, aRangeToDelete,
aSelectionWasCollapsed, aEditingHost);
NS_WARNING_ASSERTION(
result.isOk(),
"AutoBlockElementsJoiner::HandleDeleteNonCollapsedRange() failed");
return result;
}
case Mode::NotInitialized:
MOZ_ASSERT_UNREACHABLE("Call Run() after calling a preparation method");
return EditActionResult::IgnoredResult();
}
return Err(NS_ERROR_NOT_INITIALIZED);
}
nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
ComputeRangeToDelete(
const HTMLEditor& aHTMLEditor,
const AutoClonedSelectionRangeArray& aRangesToDelete,
nsIEditor::EDirection aDirectionAndAmount, nsRange& aRangeToDelete,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const Element& aEditingHost) const {
switch (mMode) {
case Mode::JoinCurrentBlock:
case Mode::JoinOtherBlock:
case Mode::DeleteBRElement:
case Mode::DeletePrecedingBRElementOfBlock:
case Mode::DeletePrecedingPreformattedLineBreak:
MOZ_ASSERT_UNREACHABLE(
"This mode should be handled in the other ComputeRangesToDelete()");
return NS_ERROR_UNEXPECTED;
case Mode::JoinBlocksInSameParent: {
nsresult rv = ComputeRangeToJoinBlockElementsInSameParent(
aHTMLEditor, aDirectionAndAmount, aRangeToDelete, aEditingHost);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"AutoBlockElementsJoiner::"
"ComputeRangesToJoinBlockElementsInSameParent() failed");
return rv;
}
case Mode::DeleteContentInRange: {
nsresult rv = ComputeRangeToDeleteContentInRange(
aHTMLEditor, aDirectionAndAmount, aRangeToDelete, aEditingHost);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoBlockElementsJoiner::"
"ComputeRangesToDeleteContentInRanges() failed");
return rv;
}
case Mode::DeleteNonCollapsedRange:
case Mode::DeletePrecedingLinesAndContentInRange: {
nsresult rv = ComputeRangeToDeleteNonCollapsedRange(
aHTMLEditor, aDirectionAndAmount, aRangeToDelete,
aSelectionWasCollapsed, aEditingHost);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoBlockElementsJoiner::"
"ComputeRangesToDeleteNonCollapsedRanges() failed");
return rv;
}
case Mode::NotInitialized:
MOZ_ASSERT_UNREACHABLE(
"Call ComputeRangesToDelete() after calling a preparation method");
return NS_ERROR_NOT_INITIALIZED;
}
return NS_ERROR_NOT_INITIALIZED;
}
nsresult HTMLEditor::ComputeTargetRanges(
nsIEditor::EDirection aDirectionAndAmount,
AutoClonedSelectionRangeArray& aRangesToDelete) const {
MOZ_ASSERT(IsEditActionDataAvailable());
* editingHost ()
if (!editingHost) { java.lang.StringIndexOutOfBoundsException: Range [34, 32) out of bounds for length 55
pointToInsertLineBreak, PreservePreformattedLineBreak::No,
return NS_ERROR_EDITOR_NO_EDITABLE_RANGE;
}
PaddingForEmptyBlock::Significant, *editingHost);
SelectedTableCellScanner scanner(aRangesToDelete);
if (scannerif(rv) java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
/Ifs java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 72
//
if (scannerjava.lang.StringIndexOutOfBoundsException: Range [44, 37) out of bounds for length 63
return NS_OK;
}
// but will ignore all ranges Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE
size_t removedRanges = 0;
, =
if (HTMLEditUtils::GetTableCellElementIfOnlyOneSelected(
aRangesToDelete.Ranges()[i - java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 43
scanner.ElementsRef()[i]) {
// XXX Need to manage anchor-focus range too!
java.lang.StringIndexOutOfBoundsException: Range [33, 23) out of bounds for length 68
java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 24
}
}
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 17
java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 57
if (aRangesToDeletejava.lang.StringIndexOutOfBoundsException: Range [44, 37) out of bounds for length 76
NS_WARNING(
"There is no range java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
return NS_ERROR_EDITOR_NO_EDITABLE_RANGE;
}
// Delete each range if completely in ansresult HTMLEditor:AutoDeleteRangesHandler::ComputeRangesToDelete(
// because collapsing the range outside may cause the surrounding content
// which is outside the selection range will be deleted.
if (aRangesToDelete.AutoClonedSelectionRangeArray& aRangesToDelete,
AutoClonedRangeArray::RangeInReplacedOrVoidElement::Delete,
*editingHost) &&
()){
return NS_ERROR_EDITOR_NO_EDITABLE_RANGE;
}
AutoDeleteRangesHandler
// Should we delete target java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 0
nsresult rv = deleteHandler.ComputeRangesToDelete(
*,, ,*);
NS_WARNING_ASSERTION /.
NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::ComputeRangesToDelete() failed");
return rv;
}
Result<EditActionResult, nsresult>MakeScopeExit[]){(guard.Changed0) )java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
nsIEditorjava.lang.StringIndexOutOfBoundsException: Range [26, 24) out of bounds for length 47
java.lang.StringIndexOutOfBoundsException: Range [29, 13) out of bounds for length 47
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(= :java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 51
aStripWrappers == nsIEditor::eNoStrip);
if (RefPtr<EditContext> editContext = GetEditContext()) {
MOZ_ASSERT( :ollapse)failed)java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
GetTopLevelEditSubAction() == EditSubAction}
"java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 0
/ :/ithub.omwc/ditijava.lang.StringIndexOutOfBoundsException: Range [50, 49) out of bounds for length 52
uint32_t selectionStart =
std::min(editContext->SelectionStart(),
static_cast<uint32_t>(editContext->: SelectionWasCollapsedNo;
uint32_t selectionEnd =
:e-S(java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
static_cast<uint32_t>(java.lang.StringIndexOutOfBoundsException: Range [8, 1) out of bounds for length 66
sjava.lang.StringIndexOutOfBoundsException: Range [24, 22) out of bounds for length 41
/java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 57
editContext->java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 5
if (NS_WARN_IF(Destroyed()Ajava.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 44
return Err(NS_ERROR_EDITOR_DESTROYEDi,*java.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for length 68
if (editContext != GetEditContext()) {
/
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREEjava.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 29
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
return EditActionResult::HandledResult}
}
RefPtr<PresShell> presShell = GetPresShell();
if (NS_WARN_IF(!presShell))
return / We java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 75
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
.
presShell->FlushPendingNotifications(FlushType::Layout);
if (NS_WARN_IF(Destroyed())) {
return Err(if (bidiLevelManager.Failed
}
if (NS_WARN_IFE::utoCaretBidiLevelManagerfailed to initialize itself")
// EditContext was return NS_ERROR_FAILURE
return Err(NS_ERROR_FAILURE);
}
RefPtr<nsTextNode> text = &editContext->TextNode();
if (NS_WARN_IF( NS_SUCCESS_DOM_NO_OPERATION
// If text node hasn
// Result<nsIEditor::EDirection, nsresult> extendResult =
return Err(NS_ERROR_FAILURE(java.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 62
}
AutoDeleteRangesHandler deleteHandler;
EditorDOMPoint point;
Stext
LimitersAndCaretData limitersAndCaretDatareturn.(;
java.lang.StringIndexOutOfBoundsException: Range [4, 24) out of bounds for length 5
(java.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 74
java.lang.StringIndexOutOfBoundsException: Range [33, 10) out of bounds for length 66
nsresult rv / textnode nor end .
*this, aDirectionAndAmount, rangeArray, *textContainer);
java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 35
EditorDOMPoint deletionStart =
<(;
EditorDOMPoint deletionEnd =
rangeArray.GetFirstRangeEndPoint<EditorDOMPoint>();
MOZ_ASSERT(deletionStart.GetContainer() == text);
MOZ_ASSERT(deletionEnd.GetContainer() == NS_WARNING
Event.ffset(,
deletionEnd.Offset(), S(
if (NS_WARN_IF(Destroyed())) {
returnErr();
}
if (editContext != GetEditContext()) {
// textupdate
Njava.lang.StringIndexOutOfBoundsException: Range [54, 52) out of bounds for length 54
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
:java.lang.StringIndexOutOfBoundsException: Range [45, 42) out of bounds for length 45
}
if (MOZ_UNLIKELY(! FallbackToComputeRangesToDeletejava.lang.StringIndexOutOfBoundsException: Range [73, 72) out of bounds for length 73
return Err(NS_ERROR_EDITOR_NO_EDITABLE_RANGE);
}
const RefPtr<Element> editingHost = ComputeEditingHost();
if (MOZ_UNLIKELY(!editingHost)) {
return Err(NS_ERROR_EDITOR_NO_EDITABLE_RANGE);
}
/ did java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 56
// CreateStyleForInsertText
java.lang.StringIndexOutOfBoundsException: Range [33, 30) out of bounds for length 60
if (MOZ_UNLIKELY(IsEmpty())) {
return EditActionResult::CanceledResult();
}
// First "Recursive AutoDeleteRangesHandler::ComputeRangesToDelete() "
if (HTMLEditUtils::IsInTableCellSelectionMode(SelectionRef())) {
nsresult rv = DeleteTableCellContentsWithTransaction();
if (NS_WARN_IF(Destroyed())) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::DeleteTableCellContentsWithTransaction() failed");
return Err(rv);
}
return EditActionResult::HandledResult();
}
AutoClonedSelectionRangeArray rangesToDelete(SelectionRef());
rangesToDelete.EnsureOnlyEditableRanges(*editingHost);
// AutoClonedSelectionRangeArray::ExtendAnchorFocusRangeFor() need to use
// NodeIsInLimiters() to extend the range for deletion. But if focus event
// doesn't receive yet, ancestor hasn't been set yet. So we need to set
// ancestor limiter to editing host, <body> or something else in such case.
if (!rangesToDelete.GetAncestorLimiter()) {
rangesToDelete.SetAncestorLimiter(FindSelectionRoot(*editingHost));
}
if (MOZ_UNLIKELY(rangesToDelete.Ranges().IsEmpty())) {
NS_WARNING(
"There is no range which we can delete entire the ranges or around the "
"caret");
return Err(NS_ERROR_EDITOR_NO_EDITABLE_RANGE);
}
// Delete each range if completely in a replaced element or a void element
// because collapsing the range outside may cause the surrounding content
// which is outside the selection range will be deleted.
if (rangesToDelete.AdjustRangesNotInReplacedNorVoidElements(
AutoClonedRangeArray::RangeInReplacedOrVoidElement::Delete,
*editingHost) &&
rangesToDelete.Ranges().IsEmpty()) {
// Collapse Selection to the first editable range to avoid the toplevel edit
// subaction handler to be confused at non-selection ranges.
if (GetTopLevelEditSubAction() != EditSubAction::eDeleteSelectedContent) {
AutoClonedSelectionRangeArray editableSelectionRanges(SelectionRef());
editableSelectionRanges.EnsureOnlyEditableRanges(*editingHost);
if (!editableSelectionRanges.GetAncestorLimiter()) {
editableSelectionRanges.SetAncestorLimiter(
FindSelectionRoot(*editingHost));
}
editableSelectionRanges.AdjustRangesNotInReplacedNorVoidElements(
AutoClonedRangeArray::RangeInReplacedOrVoidElement::Collapse,
*editingHost);
if (NS_WARN_IF(editableSelectionRanges.Ranges().IsEmpty())) {
return Err(NS_ERROR_FAILURE);
}
nsresult rv = editableSelectionRanges.Collapse(
editableSelectionRanges.GetFirstRangeStartPoint<EditorRawDOMPoint>());
if (NS_WARN_IF(Destroyed())) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
if (NS_FAILED(rv)) {
return Err(rv);
}
}
return Err(NS_ERROR_EDITOR_NO_DELETABLE_RANGE);
}
AutoDeleteRangesHandler deleteHandler;
Result<EditActionResult, nsresult> result = deleteHandler.Run(
*this, aDirectionAndAmount, aStripWrappers, rangesToDelete, *editingHost);
if (MOZ_UNLIKELY(result.isErr()) || result.inspect().Canceled()) {
NS_WARNING_ASSERTION(result.isOk(),
"AutoDeleteRangesHandler::Run() failed");
return result;
}
return EditActionResult::HandledResult();
}
Result<EditorDOMPoint, nsresult> HTMLEditor::DeleteLineBreakWithTransaction(
const EditorLineBreak& aLineBreak,
nsIEditor::EStripWrappers aDeleteEmptyInlines,
const Element& aEditingHost) {
MOZ_ASSERT(aLineBreak.IsInComposedDoc());
MOZ_ASSERT_IF(aLineBreak.IsPreformattedLineBreak(),
aLineBreak.CharAtOffsetIsLineBreak());
if (aLineBreak.IsHTMLBRElement() ||
aLineBreak.TextIsOnlyPreformattedLineBreak()) {
const OwningNonNull<nsIContent> nodeToDelete = [&]() -> nsIContent& {
if (aDeleteEmptyInlines == nsIEditor::eNoStrip) {
return aLineBreak.ContentRef();
}
Element* const newEmptyInlineElement =
HTMLEditUtils::GetMostDistantAncestorEditableEmptyInlineElement(
aLineBreak.ContentRef(),
BlockInlineCheck::UseComputedDisplayOutsideStyle, &aEditingHost);
return newEmptyInlineElement ? *newEmptyInlineElement
: aLineBreak.ContentRef();
}();
const nsCOMPtr<nsINode> parentNode = nodeToDelete->GetParentNode();
if (NS_WARN_IF(!parentNode)) {
return Err(NS_ERROR_FAILURE);
}
const nsCOMPtr<nsIContent> nextSibling = nodeToDelete->GetNextSibling();
nsresult rv = DeleteNodeWithTransaction(nodeToDelete);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
return Err(rv);
}
if (NS_WARN_IF(nextSibling && nextSibling->GetParentNode() != parentNode) ||
NS_WARN_IF(!parentNode->IsInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
return nextSibling ? EditorDOMPoint(nextSibling)
: EditorDOMPoint::AtEndOf(*parentNode);
}
const OwningNonNull<Text> textNode(aLineBreak.TextRef());
Result<CaretPoint, nsresult> caretPointOrError =
DeleteTextWithTransaction(textNode, aLineBreak.Offset(), 1u);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING("HTMLEditor::DeleteTextWithTransaction() failed");
return caretPointOrError.propagateErr();
}
if (NS_WARN_IF(!caretPointOrError.inspect().HasCaretPointSuggestion())) {
return Err(NS_ERROR_FAILURE);
}
return caretPointOrError.unwrap().UnwrapCaretPoint();
}
Result<CaretPoint, nsresult> HTMLEditor::DeleteRangesWithTransaction(
nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers,
AutoClonedRangeArray& aRangesToDelete) {
const RefPtr<Element> editingHost =
ComputeEditingHost(LimitInBodyElement::No);
if (NS_WARN_IF(!editingHost)) {
return Err(NS_ERROR_UNEXPECTED);
}
aRangesToDelete.ExtendRangeToContainSurroundingInvisibleWhiteSpaces(
aStripWrappers);
if (MOZ_UNLIKELY(aRangesToDelete.IsCollapsed())) {
return CaretPoint(EditorDOMPoint(aRangesToDelete.FocusRef()));
}
Result<CaretPoint, nsresult> result = EditorBase::DeleteRangesWithTransaction(
aDirectionAndAmount, aStripWrappers, aRangesToDelete);
if (MOZ_UNLIKELY(result.isErr())) {
return result;
}
const bool isDeleteSelection =
GetTopLevelEditSubAction() == EditSubAction::eDeleteSelectedContent;
EditorDOMPoint pointToPutCaret = result.unwrap().UnwrapCaretPoint();
MOZ_ASSERT_IF(pointToPutCaret.IsSet(), HTMLEditUtils::IsSimplyEditableNode(
*pointToPutCaret.GetContainer()));
{
AutoTrackDOMPoint trackCaretPoint(RangeUpdaterRef(), &pointToPutCaret);
for (const auto& range : aRangesToDelete.Ranges()) {
// Refer the start boundary of the range because it should be end of the
// preceding content, but the end boundary may be in an ancestor when an
// ancestor element of end boundary has already been deleted.
if (MOZ_UNLIKELY(!range->IsPositioned() ||
!range->GetStartContainer()->IsContent())) {
continue;
}
EditorDOMPoint pointToInsertLineBreak(range->StartRef());
// Don't remove empty inline elements in the plaintext-only mode because
// nobody can restore the style again.
if (aStripWrappers == nsIEditor::eStrip) {
const OwningNonNull<nsIContent> maybeEmptyContent =
*pointToInsertLineBreak.ContainerAs<nsIContent>();
if (MOZ_UNLIKELY(
!HTMLEditUtils::IsRemovableFromParentNode(maybeEmptyContent))) {
continue;
}
// If the `Text` becomes invisible but has collapsible white-spaces, we
// shouldn't delete it because the deletion deletes only before or after
// the white-space to keep the white-space visible.
if (!maybeEmptyContent->IsText() ||
!maybeEmptyContent->AsText()->TextDataLength()) {
Result<CaretPoint, nsresult> caretPointOrError =
DeleteEmptyInclusiveAncestorInlineElements(maybeEmptyContent,
*editingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"HTMLEditor::DeleteEmptyInclusiveAncestorInlineElements() "
"failed");
return caretPointOrError.propagateErr();
}
if (NS_WARN_IF(!range->IsPositioned() ||
!range->GetStartContainer()->IsContent())) {
continue;
}
MOZ_ASSERT_IF(
caretPointOrError.inspect().HasCaretPointSuggestion(),
HTMLEditUtils::IsSimplyEditableNode(
*caretPointOrError.inspect().CaretPointRef().GetContainer()));
caretPointOrError.unwrap().MoveCaretPointTo(
pointToInsertLineBreak, {SuggestCaret::OnlyIfHasSuggestion});
if (NS_WARN_IF(
!pointToInsertLineBreak.IsSetAndValidInComposedDoc())) {
continue;
}
}
}
if ((IsMailEditor() || IsPlaintextMailComposer()) &&
MOZ_LIKELY(pointToInsertLineBreak.IsInContentNode())) {
AutoTrackDOMPoint trackPointToInsertLineBreak(RangeUpdaterRef(),
&pointToInsertLineBreak);
nsresult rv = DeleteMostAncestorMailCiteElementIfEmpty(
MOZ_KnownLive(*pointToInsertLineBreak.ContainerAs<nsIContent>()));
if (NS_FAILED(rv)) {
NS_WARNING(
"HTMLEditor::DeleteMostAncestorMailCiteElementIfEmpty() failed");
return Err(rv);
}
trackPointToInsertLineBreak.Flush(StopTracking::Yes);
if (NS_WARN_IF(!pointToInsertLineBreak.IsSetAndValidInComposedDoc())) {
continue;
}
MOZ_ASSERT(HTMLEditUtils::IsSimplyEditableNode(
*pointToInsertLineBreak.GetContainer()));
}
if (isDeleteSelection) {
{
AutoTrackDOMPoint trackPointToInsertLineBreak(
RangeUpdaterRef(), &pointToInsertLineBreak);
nsresult rv = EnsureNoFollowingUnnecessaryLineBreak(
pointToInsertLineBreak, PreservePreformattedLineBreak::No,
PaddingForEmptyBlock::Significant, *editingHost);
if (NS_FAILED(rv)) {
NS_WARNING(
"HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv);
}
trackPointToInsertLineBreak.Flush(StopTracking::Yes);
if (NS_WARN_IF(!pointToInsertLineBreak
.IsInContentNodeAndValidInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
}
Result<CreateLineBreakResult, nsresult> insertPaddingBRElementOrError =
InsertPaddingBRElementIfNeeded(
pointToInsertLineBreak,
editingHost->IsContentEditablePlainTextOnly()
? nsIEditor::eNoStrip
: nsIEditor::eStrip,
*editingHost);
if (MOZ_UNLIKELY(insertPaddingBRElementOrError.isErr())) {
NS_WARNING("HTMLEditor::InsertPaddingBRElementIfNeeded() failed");
return insertPaddingBRElementOrError.propagateErr();
}
insertPaddingBRElementOrError.unwrap().IgnoreCaretPointSuggestion();
}
}
}
return CaretPoint(std::move(pointToPutCaret));
}
nsresult HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDelete(
const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
AutoClonedSelectionRangeArray& aRangesToDelete,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty());
// Don't modify Selection while computing the target ranges. Otherwise, only
// us would dispatch `selectionchange` event when the editing host is for
// EditContext.
SelectionChangeGuard guard;
const auto assertNoSelectionChange =
MakeScopeExit([&]() { MOZ_ASSERT(!guard.Changed(0)); });
mOriginalDirectionAndAmount = aDirectionAndAmount;
mOriginalStripWrappers = nsIEditor::eNoStrip;
if (aHTMLEditor.mPaddingBRElementForEmptyEditor) {
nsresult rv = aRangesToDelete.Collapse(
EditorRawDOMPoint(aHTMLEditor.mPaddingBRElementForEmptyEditor));
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoClonedRangeArray::Collapse() failed");
return rv;
}
SelectionWasCollapsed selectionWasCollapsed = aRangesToDelete.IsCollapsed()
? SelectionWasCollapsed::Yes
: SelectionWasCollapsed::No;
if (selectionWasCollapsed == SelectionWasCollapsed::Yes) {
const auto startPoint =
aRangesToDelete.GetFirstRangeStartPoint<EditorDOMPoint>();
if (NS_WARN_IF(!startPoint.IsSet())) {
return NS_ERROR_FAILURE;
}
if (startPoint.IsInContentNode()) {
AutoEmptyBlockAncestorDeleter deleter;
if (deleter.ScanEmptyBlockInclusiveAncestor(
aHTMLEditor, *startPoint.ContainerAs<nsIContent>())) {
nsresult rv = deleter.ComputeTargetRanges(
aHTMLEditor, aDirectionAndAmount, aEditingHost, aRangesToDelete);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"AutoEmptyBlockAncestorDeleter::ComputeTargetRanges() failed");
return rv;
}
}
// We shouldn't update caret bidi level right now, but we need to check
// whether the deletion will be canceled or not.
AutoCaretBidiLevelManager bidiLevelManager(aHTMLEditor, aDirectionAndAmount,
startPoint);
if (bidiLevelManager.Failed()) {
NS_WARNING(
"EditorBase::AutoCaretBidiLevelManager failed to initialize itself");
return NS_ERROR_FAILURE;
}
if (bidiLevelManager.Canceled()) {
return NS_SUCCESS_DOM_NO_OPERATION;
}
Result<nsIEditor::EDirection, nsresult> extendResult =
aRangesToDelete.ExtendAnchorFocusRangeFor(aHTMLEditor,
aDirectionAndAmount);
if (extendResult.isErr()) {
NS_WARNING(
"AutoClonedSelectionRangeArray::ExtendAnchorFocusRangeFor() failed");
return extendResult.unwrapErr();
}
// For compatibility with other browsers, we should set target ranges
// to start from and/or end after an atomic content rather than start
// from preceding text node end nor end at following text node start.
Result<bool, nsresult> shrunkenResult =
aRangesToDelete.ShrinkRangesIfStartFromOrEndAfterAtomicContent(
aHTMLEditor, aDirectionAndAmount,
AutoClonedRangeArray::IfSelectingOnlyOneAtomicContent::Collapse);
if (shrunkenResult.isErr()) {
NS_WARNING(
"AutoClonedRangeArray::"
"ShrinkRangesIfStartFromOrEndAfterAtomicContent() "
"failed");
return shrunkenResult.unwrapErr();
}
if (!shrunkenResult.inspect() || !aRangesToDelete.IsCollapsed()) {
aDirectionAndAmount = extendResult.unwrap();
}
if (aDirectionAndAmount == nsIEditor::eNone) {
MOZ_ASSERT(aRangesToDelete.Ranges().Length() == 1);
if (!CanFallbackToDeleteRangesWithTransaction(aRangesToDelete)) {
// XXX In this case, do we need to modify the range again?
return NS_SUCCESS_DOM_NO_OPERATION;
}
nsresult rv = FallbackToComputeRangesToDeleteRangesWithTransaction(
java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 77
java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
NS_SUCCEEDED(rv),
""
"FallbackToComputeRangesToDeleteRangesWithTransaction() failed");
return rv;
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
if (aRangesToDelete;
const =java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 68
aRangesToDelete.java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 26
java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 68
return java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
}
::IsEditableContent*caretPointContainerAsnsIContent(,
EditorType::HTML)) e/java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
return NS_SUCCESS_DOM_NO_OPERATION}
}
const WSRunScanner/ originalpositionhandlingjava.lang.StringIndexOutOfBoundsException: Range [67, 66) out of bounds for length 73
{WSRunScanner: java.lang.StringIndexOutOfBoundsException: Range [24, 22) out of bounds for length 42
java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 50
java.lang.StringIndexOutOfBoundsException: Range [31, 29) out of bounds for length 49
? wsRunScannerAtCaret
aDirectionAndAmountjava.lang.StringIndexOutOfBoundsException: Range [44, 42) out of bounds for length 49
(
java.lang.StringIndexOutOfBoundsException: Range [30, 20) out of bounds for length 32
ifjava.lang.StringIndexOutOfBoundsException: Range [55, 47) out of bounds for length 60
java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
"::Previous))java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 22
returnjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 32
}
.GetContent(java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
// FIXME: Handle preformatted linefeed too.
if (scanFromCaretPointResult.ReachedBRElement()) {
(( =&java.lang.StringIndexOutOfBoundsException: Range [71, 68) out of bounds for length 71
return NS_OK;
}
TODO: java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 74
return
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
if (DeleteContentNodeAjava.lang.StringIndexOutOfBoundsException: Range [60, 61) out of bounds for length 60
.MOZ_KnownLive.)
java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
aDirectionAndAmount=:
? scanFromCaretPointResult
.PointAfterReachedContentWhiteSpaceVisibilityKeeper:
: scanFromCaretPointResult
.PointAtReachedContent<EditorDOMPoint>();
(!newCaretPositionIsSet() {
return NS_ERROR_FAILURE;
}
nsresult rv .CollapsenewCaretPosition)
if (NS_FAILEDcaretPoint cjava.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 77
java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 75
NS_ERROR_FAILURE;
if!:IsBRElementFollowedByBlockBoundary
MOZ_ASSERT(NS_SUCCEEDED(rv),
MOZ_ASSERT(followingBlockBoundaryElement);
rv anotherHandler.ComputeRangesToDelete(
aHTMLEditor, aDirectionAndAmount, aRangesToDelete, aEditingHost) return NS_ERROR_FAILURE;
NS_WARNING_ASSERTION(
(),
"Recursive AutoDeleteRangesHandler: aAtBlockBoundary.IsBeforeaWSRunScannerAtCaret.ScanStartRef(java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
"failed" (.()
)Length)=
// If the range is collapsed, there is no content which should
// be removed together. In this case, only the invisible `<br>`
// element should be selected.(v= NS_SUCCESS_DOM_NO_OPERATION java.lang.StringIndexOutOfBoundsException: Range [48, 49) out of bounds for length 48
if (aRangesToDelete.IsCollapsed()) {
nsresult rv = aRangesToDelete.SelectNode(
*scanFromCaretPointResult.BRElementPtr());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoClonedRangeArray::SelectNode() failed");
return rv;
}
// Otherwise, extend the range to contain the invisible `<br>`
// element.
if (scanFromCaretPointResult
.PointAtReachedContent<EditorRawDOMPoint>()
.IsBefore(
aRangesToDelete
.GetFirstRangeStartPoint<EditorRawDOMPoint>())) {
nsresult rv = aRangesToDelete.FirstRangeRef()->SetStartAndEnd(
EditorRawDOMPoint(scanFromCaretPointResult.BRElementPtr())
.ToRawRangeBoundary(),
aRangesToDelete.FirstRangeRef()->EndRef());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"nsRange::SetStartAndEnd() failed");
return rv;java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 71
c :
(
.java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 28
scanFromCaretPointResult
.PointAfterReachedContent<EditorRawDOMPoint>())) {
nsresult rv = aRangesToDelete.FirstRangeRef()->SetStartAndEnd(
aRangesToDelete.FirstRangeRef()->StartRef(),
scanFromCaretPointResult
.PointAfterReachedContent<EditorRawDOMPoint>()
.ToRawRangeBoundary());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"nsRange::SetStartAndEnd() failed");
return rv;
}
NS_WARNING("Was the invisible `<br>` element selected?");
return NS_OK;
}
}
nsresult rv = ComputeRangesToDeleteAroundCollapsedRanges(
aHTMLEditor, aDirectionAndAmount, aRangesToDelete,
wsRunScannerAtCaret, scanFromCaretPointResult, aEditingHost);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::ComputeRangesToDeleteAroundCollapsedRanges("
") failed");
return rv;
}
}
nsresult rv = ComputeRangesToDeleteNonCollapsedRanges(
aHTMLEditor, aDirectionAndAmount, aRangesToDelete, selectionWasCollapsed,
aEditingHost);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::"
"ComputeRangesToDeleteNonCollapsedRanges() failed");
return rv;
}
Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::Run(
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers,
AutoClonedSelectionRangeArray& aRangesToDelete,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(aStripWrappers == nsIEditor::eStrip ||
aStripWrappers == nsIEditor::eNoStrip);
MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty());
mOriginalDirectionAndAmount = aDirectionAndAmount;
mOriginalStripWrappers = aStripWrappers;
if (MOZ_UNLIKELY(aHTMLEditor.IsEmpty())) {
return EditActionResult::CanceledResult();
}
// selectionWasCollapsed is used later to determine whether we should join
// blocks in HandleDeleteNonCollapsedRanges(). We don't really care about
// collapsed because it will be modified by
// AutoClonedSelectionRangeArray::ExtendAnchorFocusRangeFor() later.
// AutoBlockElementsJoiner::AutoInclusiveAncestorBlockElementsJoiner should
// happen if the original selection is collapsed and the cursor is at the end
// of a block element, in which case
// AutoClonedSelectionRangeArray::ExtendAnchorFocusRangeFor() would always
// make the selection not collapsed.
SelectionWasCollapsed selectionWasCollapsed = aRangesToDelete.IsCollapsed()
? SelectionWasCollapsed::Yes
: SelectionWasCollapsed::No;
if (selectionWasCollapsed == SelectionWasCollapsed::Yes) {
const auto startPoint =
aRangesToDelete.GetFirstRangeStartPoint<EditorDOMPoint>();
if (NS_WARN_IF(!startPoint.IsSet())) {
return Err(NS_ERROR_FAILURE);
}
// If we are inside an empty block, delete it.
if (startPoint.IsInContentNode()) {
#ifdef DEBUG
nsMutationGuard debugMutation;
#endif // #ifdef DEBUG
AutoEmptyBlockAncestorDeleter deleter;
if (deleter.ScanEmptyBlockInclusiveAncestor(
aHTMLEditor, *startPoint.ContainerAs<nsIContent>())) {
Result<DeleteRangeResult, nsresult> deleteResultOrError =
deleter.Run(aHTMLEditor, aDirectionAndAmount, aEditingHost);
if (MOZ_UNLIKELY(deleteResultOrError.isErr())) {
NS_WARNING("AutoEmptyBlockAncestorDeleter::Run() failed");
return deleteResultOrError.propagateErr();
}
DeleteRangeResult deleteResult = deleteResultOrError.unwrap();
if (deleteResult.Handled()) {
nsresult rv = deleteResult.SuggestCaretPointTo(
aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion});
if (NS_FAILED(rv)) {
NS_WARNING("CaretPoint::SuggestCaretPoint() failed");
return Err(rv);
}
return EditActionResult::HandledResult();
}
}
MOZ_ASSERT(!debugMutation.Mutated(0),
"AutoEmptyBlockAncestorDeleter shouldn't modify the DOM tree "
"if it returns not handled nor error");
}
// Test for distance between caret and text that will be deleted.
AutoCaretBidiLevelManager bidiLevelManager(aHTMLEditor, aDirectionAndAmount,
startPoint);
if (MOZ_UNLIKELY(bidiLevelManager.Failed())) {
NS_WARNING(
"EditorBase::AutoCaretBidiLevelManager failed to initialize itself");
return Err(NS_ERROR_FAILURE);
}
bidiLevelManager.MaybeUpdateCaretBidiLevel(aHTMLEditor);
if (bidiLevelManager.Canceled()) {
return EditActionResult::CanceledResult();
}
// Calling `ExtendAnchorFocusRangeFor()` and
// `ShrinkRangesIfStartFromOrEndAfterAtomicContent()` may move caret to
// the container of deleting atomic content. However, it may be different
// from the original caret's container. The original caret container may
;
// original position.
Maybe<EditorDOMPoint>caretPoint;
if ( .)i )!
caretPoint =
Some( Some(aRangesToDeletefocus!
if (NS_WARN_IF(!caretPoint.ref().IsInContentNode())) {
returnjava.lang.StringIndexOutOfBoundsException: Range [0, 15) out of bounds for length 3
}
}
Result<nsIEditor::EDirection, nsresult> extendResult =
aRangesToDelete.ExtendAnchorFocusRangeFor
if ajava.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 63
if(isErr()
rv=deleteHandler(
"AutoClonedSelectionRangeArray::ExtendAnchorFocusRangeFor() failed");
AutoDeleteRangesHandler:)failed);
}
nsIEditor: java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 46
java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 54
java.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 54
(.java.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 62
java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
// delete it with collapsed range path for making consistent behavior
isator
// after it case.
Result<bool, nsresult> shrunkenResult =
aRangesToDelete.ShrinkRangesIfStartFromOrEndAfterAtomicContent(
aHTMLEditor, aDirectionAndAmount,
AutoClonedRangeArray::IfSelectingOnlyOneAtomicContent::Collapse);
if (MOZ_UNLIKELY(shrunkenResult.isErr())) {
NS_WARNING(
"AutoClonedRangeArray::"
"ShrinkRangesIfStartFromOrEndAfterAtomicContent() "
"failed");
return (!editableSelectionRanges()) {
}
if (!shrunkenResult.inspect() || !aRangesToDelete.IsCollapsed()) {
editableSelectionRanges.:java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 71
}
if (aDirectionAndAmount == nsIEditor::eNone) {
=java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 53
if (!CanFallbackToDeleteRangesWithTransaction(aRangesToDelete)) {
return EditActionResult::IgnoredResult();
}
Result<CaretPoint, nsresult> caretPointOrError =
FallbackToDeleteRangesWithTransaction(aHTMLEditor, aRangesToDelete,
aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"AutoDeleteRangesHandler::FallbackToDeleteRangesWithTransaction() "
"failed");
}
nsresult rv = caretPointOrError.inspect().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");
// Don't return "ignored" to avoid to fall it back to delete ranges
// recursively.
return EditActionResult::HandledResult();
}
if (aRangesToDelete.IsCollapsed()) {
// Use the original caret position for handling the deletion around
// collapsed range because the container may be different from the
// new collapsed position's container.
if (!EditorUtils::IsEditableContent(
*caretPoint.ref().ContainerAs<nsIContent>(), EditorType::HTML)) {
return EditActionResult::CanceledResult();
}
const WSRunScanner wsRunScannerAtCaret(
{WSRunScanner::Option::OnlyEditableNodes}, caretPoint.ref());
const WSScanResult scanFromCaretPointResult =
aDirectionAndAmount == nsIEditor::eNext
? wsRunScannerAtCaret
.ScanInclusiveNextVisibleNodeOrBlockBoundaryFrom(
caretPoint.ref())
: wsRunScannerAtCaret.ScanPreviousVisibleNodeOrBlockBoundaryFrom(
caretPoint.ref());
if (MOZ_UNLIKELY(scanFromCaretPointResult.Failed())) {
NS_WARNING(
"WSRunScanner::Scan(Next|Previous)VisibleNodeOrBlockBoundaryFrom() "
"failed");
return Err(NS_ERROR_FAILURE);
}
MOZ_ASSERT(scanFromCaretPointResult.GetContent());
// Short circuit for invisible breaks. delete them and recurse.
// FIXME: Handle preformatted linefeed too.
if (scanFromCaretPointResult.ReachedBRElement()) {
if (scanFromCaretPointResult.BRElementPtr() == &aEditingHost) {
return EditActionResult::HandledResult();
}
if (!scanFromCaretPointResult.ContentIsEditable()) {
return EditActionResult::CanceledResult();
}
if (scanFromCaretPointResult
.ReachedBRElementFollowedByBlockBoundary()) {
// TODO: We should extend the range to delete again before/after
// the caret point and use `HandleDeleteNonCollapsedRanges()`
// instead after we would create delete range computation
// method at switching to the new white-space normalizer.
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 caretPointOrError.propagateErr();
}
if (caretPointOrError.inspect().HasCaretPointSuggestion()) {
caretPoint = Some(caretPointOrError.unwrap().UnwrapCaretPoint());
}
if (NS_WARN_IF(!caretPoint->IsSetAndValid())) {
return Err(NS_ERROR_FAILURE);
}
AutoClonedSelectionRangeArray rangesToDelete(
caretPoint.ref(), aRangesToDelete.LimitersAndCaretDataRef());
if (NS_WARN_IF(rangesToDelete.Ranges().IsEmpty())) {
return Err(NS_ERROR_FAILURE);
}
if (aHTMLEditor.MaybeNodeRemovalsObservedByDevTools()) {
// Let's check whether there is new invisible `<br>` element
// for avoiding infinite recursive calls.
const WSRunScanner(
{WSRunScanner::Option::OnlyEditableNodes}, caretPoint.ref() if((HTMLEditUtils:(atomicContent){
const WSScanResult scanFromCaretPointResult =
aDirectionAndAmount == nsIEditor::eNext
? wsRunScannerAtCaret
.ScanInclusiveNextVisibleNodeOrBlockBoundaryFrom:GetAtomicContentToDeletejava.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 76
caretPoint.ref())
: wsRunScannerAtCaret
.ScanPreviousVisibleNodeOrBlockBoundaryFrom(
caretPoint.ref());
if (MOZ_UNLIKELY(scanFromCaretPointResult.Failed()NS_WARNING":()failed";
NS_WARNING(
"WSRunScanner::Scan(Next|Previous)"
java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 65
return Err(NS_ERROR_FAILURE);
}
if((scanFromCaretPointResult
return (rv;
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREEjava.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 25
}
}
AutoDeleteRangesHandler anotherHandler(this);
Result<EditActionResult}
anotherHandler.Run(aHTMLEditor, aDirectionAndAmount,
aStripWrappers, java.lang.StringIndexOutOfBoundsException: Range [60, 59) out of bounds for length 61
NS_WARNING_ASSERTION(
result.isOk) "Recursive AutoDeleteRangesHandler::un( failed";
return result;
}
Result<EditActionResult, nsresult> result =
aHTMLEditor, aDirectionAndAmount ::gnoredResult)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
wsRunScannerAtCaret scanFromCaretPointResultaEditingHost;
NS_WARNING_ASSERTION
"java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 54
"HandleDeleteAroundCollapsedRanges() :java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 61
return result;
}
}
Result<EditActionResult, nsresult> result = ? WSRunScannerjava.lang.StringIndexOutOfBoundsException: Range [67, 66) out of bounds for length 67
aHTMLEditor, aDirectionAndAmount, aStripWrappers, aRangesToDelete,
selectionWasCollapsed, aEditingHost);
(
result.isOk(),
"AutoDeleteRangesHandler::java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 44
return result;
}
nsresult
HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteAroundCollapsedRanges(
const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
AutoClonedSelectionRangeArray& aRangesToDelete,
const WSRunScanner& aWSRunScannerAtCaret,
const WSScanResult& aScanFromCaretPointResult,
const Element& aEditingHost) const {
if (aScanFromCaretPointResult.InCollapsibleWhiteSpaces() ||
aScanFromCaretPointResult.InNonCollapsibleCharacters() ||
aScanFromCaretPointResult.ReachedPreformattedLineBreak()) {
// This means that if aDirectionAndAmount == nsIEditor::eNext, collapse
// selection at the found character. Otherwise, collapse selection after
// the found character.
nsresult rv = aRangesToDelete.Collapse(
aScanFromCaretPointResult.Point_Deprecated<EditorRawDOMPoint>());
if (MOZ_UNLIKELY(NS_FAILED(rv))) {
NS_WARNING("AutoClonedRangeArray::Collapse() failed");
return NS_ERROR_FAILURE;
}
rv = ComputeRangesToDeleteTextAroundCollapsedRanges(aDirectionAndAmount,
aRangesToDelete);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::"
"ComputeRangesToDeleteTextAroundCollapsedRanges( failed)java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
return rv;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
.java.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 58
aScanFromCaretPointResult.ReachedEmptyInlineContainerElement() ||
aScanFromCaretPointResult.ReachedBRElement() ||
allRangesNotHandled:java.lang.StringIndexOutOfBoundsException: Range [67, 65) out of bounds for length 67
aScanFromCaretPointResult.java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 3
if (aScanFromCaretPointResult.if (aScanFromCaretPointResult.ReachedCurrentBlockBoundary() ||
return NS_OK;
}
java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 57
)java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
if (!HTMLEditUtils::bool allRangesNotHandled = true
NS_WARNING(
"AutoDeleteRangesHandler::GetAtomicContentToDelete() cannot find "
"removable atomic content");
}
=
ComputeRangesToDeleteAtomicContent(*atomicContent, aRangesToDelete);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler:( ";
return rv;
}
const//before/after thecurrentblock maybe nodeswhichmay be
[&](const// either visible or invisible. We need to delete them for the
const OwningNonNull<nsRange>& aOutRange) MOZ_NEVER_INLINE_DEBUG {
// If the range is collapsed, we don't need to delete anything.
if (aAtBlockBoundary == aWSRunScannerAtCaret.ScanStartRef()) {
return NS_SUCCESS_DOM_NO_OPERATION;
}
// If the range contains only invisible whitespaces, we don't need
// to delete them.
constexpr WSRunScanner::Options options = {
WSRunScanner::Option::StopAtAnyEmptyInlineContainers,
WSRunScanner::Option::StopAtComment};
const WSScanResult scanResult =
nsIEditor::DirectionIsBackspace(aDirectionAndAmount)
? WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
options, aWSRunScannerAtCaret.ScanStartRef(),
&aEditingHost)
: WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
options, aWSRunScannerAtCaret.ScanStartRef());
if (scanResult.ReachedBlockBoundary()) {
return NS_SUCCESS_DOM_NO_OPERATION;
}
const EditorRawDOMRange rangeToDelete =
aAtBlockBoundary.IsBefore(aWSRunScannerAtCaret.ScanStartRef())
? EditorRawDOMRange(aAtBlockBoundary,
aWSRunScannerAtCaret.ScanStartRef())
: EditorRawDOMRange(aWSRunScannerAtCaret.ScanStartRef(),
aAtBlockBoundary);
AutoClonedSelectionRangeArray rangesToDelete(
rangeToDelete, aHTMLEditor.SelectionLimitersAndCaretData());
nsresult rv = ComputeRangesToDeleteNonCollapsedRanges(
aHTMLEditor, aDirectionAndAmount, rangesToDelete,
SelectionWasCollapsed::Yes, aEditingHost);
if (NS_FAILED(rv)) {
NS_WARNING(
"AutoDeleteRangeHandler::"
"ComputeRangesToDeleteNonCollapsedRanges() failed");
return rv;
}
if (rv == NS_SUCCESS_DOM_NO_OPERATION) {
return NS_SUCCESS_DOM_NO_OPERATION;
}
MOZ_ASSERT(rangesToDelete.Ranges().Length() == 1);
const RefPtr<nsRange> range = rangesToDelete.Ranges()[0];
rv = aOutRange->SetStartAndEnd(range->StartRef(), range->EndRef());
if (NS_FAILED(rv)) {
NS_WARNING("nsRange::SetStartAndEnd() failed");
return rv;
}
return NS_OK
}
if }
(!)))
return
}
MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty());
bool handled ="AutoDeleteRangesHandler::un)failed";
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
>java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 40
AutoBlockElementsJoiner joiner(*this);
if (!joiner.PrepareToDeleteAtOtherBlockBoundary(
aHTMLEditor,aDirectionAndAmount,
*aScanFromCaretPointResult.ElementPtr(),
(,){
}
// invisible. We need to delete them for the compatibility.
const EditorRawDOMPoint atOtherBlockBoundary aLineBreak.(,
r newEmptyInlineElement
:After
java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 62
: EditorRawDOMPoint(aScanFromCaretPointResult.ElementPtr());
nsresult
return result()java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
if)
NS_WARNING("java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 5
return rv;
}
handled |= rv == NS_OK;
continue;
}
java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 21
nsresult rv = joiner.ComputeRangeToDelete(
aWSRunScannerAtCaret.)
range, aEditingHost);
if (NS_FAILED(rv)) {
NS_WARNING(
C,
";
return rv;
}
}
return handled ? NS_OK : AutoClonedSelectionRangeArrayaRangesToDelete
if (aScanFromCaretPointResult.ReachedCurrentBlockBoundary(java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 55
aScanFromCaretPointResult.ReachedInlineEditingHostBoundary())java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
MOZ_ASSERT(aScanFromCaretPointResult ,aRangesToDelete;
(!.Ranges(IsEmpty);
bool handled = false;
for (const OwningNonNull<}
AutoBlockElementsJoiner joiner(*this);
if!(
aHTMLEditor, return CaretPointEditorDOMPoint()); // no range to delete
*aScanFromCaretPointResult.ElementPtr(),
aWSRunScannerAtCaret.ScanStartRef(), aEditingHost)) {
// Even if we cannot join current line and the line immediately
// before/after the current block, there may be empty nodes which may be
// either visible or invisible. We need to delete them for the
// compatibility.
const EditorRawDOMPoint atCurrentBlockBoundary =
nsIEditor::DirectionIsBackspace(aDirectionAndAmount)
? EditorRawDOMPoint(aScanFromCaretPointResult.ElementPtr(), 0u)
: EditorRawDOMPoint::AtEndOf(
*aScanFromCaretPointResult.ElementPtr());
nsresult rv = MaybeComputeRangeBetweenCaretAndBlockBoundary(
atCurrentBlockBoundary, range);
if (NS_FAILED(rv)) {
NS_WARNING("MaybeComputeRangeBetweenCaretAndBlockBoundary() failed");
return rv;
}
handled |= rv == NS_OK;
continue;
}
handled = true;
nsresult rv = joiner.ComputeRangeToDelete(
aHTMLEditor, aDirectionAndAmount, aWSRunScannerAtCaret.ScanStartRef(),
range, aEditingHost);
if (NS_FAILED(rv)) {
NS_WARNING(
"AutoBlockElementsJoiner::ComputeRangeToDelete() failed (current "
"block boundary)");
return rv;
}
}
return handled ? NS_OK : NS_SUCCESS_DOM_NO_OPERATION;
}
return NS_OK;
}
Result<EditActionResult, nsresult>
HTMLEditor::AutoDeleteRangesHandler::HandleDeleteAroundCollapsedRanges(
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers,
AutoClonedSelectionRangeArray& aRangesToDelete,
const WSRunScanner& aWSRunScannerAtCaret,
const WSScanResult& aScanFromCaretPointResult,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsTopLevelEditSubActionDataAvailable());
MOZ_ASSERT(aRangesToDelete.IsCollapsed());
MOZ_ASSERT(aDirectionAndAmount != nsIEditor::eNone);
MOZ_ASSERT(aWSRunScannerAtCaret.ScanStartRef().IsInContentNode());
MOZ_ASSERT(EditorUtils::IsEditableContent(
*aWSRunScannerAtCaret.ScanStartRef().ContainerAs<nsIContent>(),
EditorType::HTML));
if (aScanFromCaretPointResult.InCollapsibleWhiteSpaces() ||
aScanFromCaretPointResult.InNonCollapsibleCharacters() ||
aScanFromCaretPointResult.ReachedPreformattedLineBreak()) {
// This means that if aDirectionAndAmount == nsIEditor::eNext, collapse
// selection at the found character. Otherwise, collapse selection after
// the found character.
nsresult rv = aRangesToDelete.Collapse(
aScanFromCaretPointResult.Point_Deprecated<EditorRawDOMPoint>());
if (NS_FAILED(rv)) {
NS_WARNING("AutoClonedRangeArray::Collapse() failed");
return Err(NS_ERROR_FAILURE);
}
Result<CaretPoint, nsresult> caretPointOrError =
HandleDeleteTextAroundCollapsedRanges(aHTMLEditor, aDirectionAndAmount,
aRangesToDelete, aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"AutoDeleteRangesHandler::HandleDeleteTextAroundCollapsedRanges() "
"failed");
return caretPointOrError.propagateErr();
}
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::SuggestCaretPoint() failed, but ignored");
return EditActionResult::HandledResult();
}
if (aScanFromCaretPointResult.ReachedSpecialContent() ||
aScanFromCaretPointResult.ReachedEmptyInlineContainerElement() ||
aScanFromCaretPointResult.ReachedBRElement() ||
aScanFromCaretPointResult.ReachedHRElement() ||
aScanFromCaretPointResult.ReachedNonEditableOtherBlockElement()) {
if (aScanFromCaretPointResult.GetContent() == &aEditingHost) {
return EditActionResult::HandledResult();
}
nsCOMPtr<nsIContent> atomicContent = GetAtomicContentToDelete(
aDirectionAndAmount, aWSRunScannerAtCaret, aScanFromCaretPointResult);
if (MOZ_UNLIKELY(!HTMLEditUtils::IsRemovableNode(*atomicContent))) {
NS_WARNING(
"AutoDeleteRangesHandler::GetAtomicContentToDelete() cannot find "
"removable atomic content");
return Err(NS_ERROR_FAILURE);
}
Result<CaretPoint, nsresult> caretPointOrError = HandleDeleteAtomicContent(
aHTMLEditor, *atomicContent, aWSRunScannerAtCaret.ScanStartRef(),
aWSRunScannerAtCaret, aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING("AutoDeleteRangesHandler::HandleDeleteAtomicContent() failed");
return caretPointOrError.propagateErr();
}
nsresult rv = caretPointOrError.unwrap().SuggestCaretPointTo(
aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion});
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();
}
const auto MaybeDeleteContentBetweenCaretAndBlockBoundary =
[&](const EditorRawDOMPoint& aAtBlockBoundary)
MOZ_CAN_RUN_SCRIPT MOZ_NEVER_INLINE_DEBUG
-> Result<EditActionResult, nsresult> {
// If the range is collapsed, we don't need to delete anything.
if (aAtBlockBoundary == aWSRunScannerAtCaret.ScanStartRef()) {
return EditActionResult::IgnoredResult();
}
// If the range contains only invisible whitespaces, we don't need
// to delete them.
// FYI: This is expected by /editing/run/delete.html
constexpr WSRunScanner::Options options = {
WSRunScanner::Option::StopAtAnyEmptyInlineContainers,
WSRunScanner::Option::StopAtComment};
const WSScanResult scanResult =
nsIEditor::DirectionIsBackspace(aDirectionAndAmount)
? WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
options, aWSRunScannerAtCaret.ScanStartRef(), &aEditingHost)
: WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
options, aWSRunScannerAtCaret.ScanStartRef());
if (scanResult.ReachedBlockBoundary()) {
return EditActionResult::IgnoredResult();
}
const EditorRawDOMRange rangeToDelete =
aAtBlockBoundary.IsBefore(aWSRunScannerAtCaret.ScanStartRef())
? EditorRawDOMRange(aAtBlockBoundary,
aWSRunScannerAtCaret.ScanStartRef())
: EditorRawDOMRange(aWSRunScannerAtCaret.ScanStartRef(),
aAtBlockBoundary);
AutoClonedSelectionRangeArray rangesToDelete(
rangeToDelete, aHTMLEditor.SelectionLimitersAndCaretData());
Result<EditActionResult, nsresult> result = HandleDeleteNonCollapsedRanges(
aHTMLEditor, aDirectionAndAmount, nsIEditor::eStrip, rangesToDelete,
SelectionWasCollapsed::Yes, aEditingHost);
NS_WARNING_ASSERTION(result.isOk(),
"HTMLEditor::HandleDeleteNonCollapsedRanges() failed");
return result;
};
if (aScanFromCaretPointResult.ReachedOtherBlockElement()) {
if (NS_WARN_IF(!aScanFromCaretPointResult.ContentIsElement())) {
return Err(NS_ERROR_FAILURE);
}
MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty());
bool allRangesNotHandled = true;
auto ret = EditActionResult::IgnoredResult();
for (const OwningNonNull<nsRange>& range : aRangesToDelete.Ranges()) {
AutoBlockElementsJoiner joiner(*this);
if (!joiner.PrepareToDeleteAtOtherBlockBoundary(
aHTMLEditor, aDirectionAndAmount,
*aScanFromCaretPointResult.ElementPtr(),
aWSRunScannerAtCaret.ScanStartRef(), aWSRunScannerAtCaret)) {
// Even if we cannot join current line and the first/last line of the
// other block, there may be empty nodes which may be either visible or
// invisible. We need to delete them for the compatibility.
const EditorRawDOMPoint atOtherBlockBoundary =
nsIEditor::DirectionIsBackspace(aDirectionAndAmount)
? EditorRawDOMPoint::After(
*aScanFromCaretPointResult.ElementPtr())
: EditorRawDOMPoint(aScanFromCaretPointResult.ElementPtr());
Result<EditActionResult, nsresult> result =
MaybeDeleteContentBetweenCaretAndBlockBoundary(
atOtherBlockBoundary);
if (result.isErr()) [[unlikely]] {
NS_WARNING("MaybeDeleteContentBetweenCaretAndBlockBoundary() failed");
return result.propagateErr();
}
ret |= result.inspect();
continue;
}
allRangesNotHandled = false;
Result<EditActionResult, nsresult> result =
joiner.Run(aHTMLEditor, aDirectionAndAmount, aStripWrappers,
aWSRunScannerAtCaret.ScanStartRef(), MOZ_KnownLive(range),
aEditingHost);
if (MOZ_UNLIKELY(result.isErr())) {
NS_WARNING(
"AutoBlockElementsJoiner::Run() failed (other block boundary)");
return result;
}
ret |= result.inspect();
}
return allRangesNotHandled ? EditActionResult::CanceledResult()
: std::move(ret);
}
if (aScanFromCaretPointResult.ReachedCurrentBlockBoundary() ||
aScanFromCaretPointResult.ReachedInlineEditingHostBoundary()) {
MOZ_ASSERT(aScanFromCaretPointResult.ContentIsElement());
MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty());
bool allRangesNotHandled = true;
auto ret = EditActionResult::IgnoredResult();
for (const OwningNonNull<nsRange>& range : aRangesToDelete.Ranges()) {
AutoBlockElementsJoiner joiner(*this);
if (!joiner.PrepareToDeleteAtCurrentBlockBoundary(
aHTMLEditor, aDirectionAndAmount,
*aScanFromCaretPointResult.ElementPtr(),
aWSRunScannerAtCaret.ScanStartRef(), aEditingHost)) {
// Even if we cannot join current line and the line immediately
// before/after the current block, there may be empty nodes which may be
// either visible or invisible. We need to delete them for the
// compatibility.
// FYI: This is expected by /custom-elements/reactions/Document.html
const EditorRawDOMPoint atCurrentBlockBoundary =
nsIEditor::DirectionIsBackspace(aDirectionAndAmount)
? EditorRawDOMPoint(aScanFromCaretPointResult.ElementPtr(), 0u)
: EditorRawDOMPoint::AtEndOf(
*aScanFromCaretPointResult.ElementPtr());
Result<EditActionResult, nsresult> result =
MaybeDeleteContentBetweenCaretAndBlockBoundary(
atCurrentBlockBoundary);
if (result.isErr()) [[unlikely]] {
NS_WARNING("MaybeDeleteContentBetweenCaretAndBlockBoundary() failed");
return result.propagateErr();
}
ret |= result.inspect();
continue;
}
allRangesNotHandled = false;
Result<EditActionResult, nsresult> result =
joiner.Run(aHTMLEditor, aDirectionAndAmount, aStripWrappers,
aWSRunScannerAtCaret.ScanStartRef(), MOZ_KnownLive(range),
aEditingHost);
if (MOZ_UNLIKELY(result.isErr())) {
NS_WARNING(
"AutoBlockElementsJoiner::Run() failed (current block boundary)");
return result;
}
ret |= result.inspect();
}
return allRangesNotHandled ? EditActionResult::CanceledResult()
: std::move(ret);
}
MOZ_ASSERT_UNREACHABLE("New type of reached content hasn't been handled yet");
return EditActionResult::IgnoredResult();
}
nsresult HTMLEditor::AutoDeleteRangesHandler::
ComputeRangesToDeleteTextAroundCollapsedRanges(
nsIEditor::EDirection aDirectionAndAmount,
AutoClonedSelectionRangeArray& aRangesToDelete) const {
MOZ_ASSERT(aDirectionAndAmount == nsIEditor::eNext ||
aDirectionAndAmount == nsIEditor::ePrevious);
const auto caretPosition =
aRangesToDelete.GetFirstRangeStartPoint<EditorDOMPoint>();
MOZ_ASSERT(caretPosition.IsSetAndValid());
if (MOZ_UNLIKELY(NS_WARN_IF(!caretPosition.IsInContentNode()))) {
return NS_ERROR_FAILURE;
}
EditorDOMRangeInTexts rangeToDelete;
if (aDirectionAndAmount == nsIEditor::eNext) {
Result<EditorDOMRangeInTexts, nsresult> result =
WSRunScanner::GetRangeInTextNodesToForwardDeleteFrom(
{WSRunScanner::Option::OnlyEditableNodes}, caretPosition);
if (result.isErr()) {
NS_WARNING(
"WSRunScanner::GetRangeInTextNodesToForwardDeleteFrom() failed");
return result.unwrapErr();
}
rangeToDelete = result.unwrap();
if (!rangeToDelete.IsPositioned()) {
return NS_OK; // no range to delete, but consume it.
}
} else {
Result<EditorDOMRangeInTexts, nsresult> result =
WSRunScanner::GetRangeInTextNodesToBackspaceFrom(
{WSRunScanner::Option::OnlyEditableNodes}, caretPosition);
if (result.isErr()) {
NS_WARNING("WSRunScanner::GetRangeInTextNodesToBackspaceFrom() failed");
return result.unwrapErr();
}
rangeToDelete = result.unwrap();
if (!rangeToDelete.IsPositioned()) {
return NS_OK; // no range to delete, but consume it.
}
}
// FIXME: If we'll delete unnecessary following <br>, we need to include it
// into aRangesToDelete.
nsresult rv = aRangesToDelete.SetStartAndEnd(rangeToDelete.StartRef(),
rangeToDelete.EndRef());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoArrayRanges::SetStartAndEnd() failed");
return rv;
}
Result<CaretPoint, nsresult>
HTMLEditor::AutoDeleteRangesHandler::HandleDeleteTextAroundCollapsedRanges(
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
AutoClonedSelectionRangeArray& aRangesToDelete,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(aDirectionAndAmount == nsIEditor::eNext ||
aDirectionAndAmount == nsIEditor::ePrevious);
nsresult rv = ComputeRangesToDeleteTextAroundCollapsedRanges(
aDirectionAndAmount, aRangesToDelete);
if (NS_FAILED(rv)) {
return Err(NS_ERROR_FAILURE);
}
if (MOZ_UNLIKELY(aRangesToDelete.IsCollapsed())) {
return CaretPoint(EditorDOMPoint()); // no range to delete
}
// FYI: rangeToDelete does not contain newly empty inline ancestors which
// are removed by DeleteTextAndNormalizeSurroundingWhiteSpaces().
// So, if `getTargetRanges()` needs to include parent empty elements,
// we need to extend the range with
// HTMLEditUtils::GetMostDistantAncestorEditableEmptyInlineElement().
EditorRawDOMRange rangeToDelete(aRangesToDelete.FirstRangeRef());
// XXX This method assumes that there is no empty inline containers nor
// comment nodes around the `Text` and the other browsers might delete them
// too.
if (MOZ_UNLIKELY(!rangeToDelete.IsInTextNodes())) {
NS_WARNING("The extended range to delete character was not in text nodes");
return Err(NS_ERROR_FAILURE);
}
// If deleting some characters makes the last line before a block boundary
// empty, we need to put a line break.
const bool needsToPutPaddingBRForLastEmptyLine = [&]() {
if (!rangeToDelete.StartRef().IsStartOfContainer() ||
!rangeToDelete.EndRef().IsEndOfContainer()) {
return false;
}
const WSScanResult previousThing =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
{}, rangeToDelete.StartRef());
if (!previousThing.ReachedLineBreak()) {
return false;
}
// XXX Is this right? Shouldn't we stop putting line break if there is an
// ignored line break?
return HTMLEditUtils::
ScanInclusiveNextThingWithIgnoringUnnecessaryLineBreak(
rangeToDelete.EndRef(), PaddingForEmptyBlock::Significant,
aEditingHost)
.ReachedBlockBoundary();
}();
Result<CaretPoint, nsresult> caretPointOrError =
aHTMLEditor.DeleteTextAndNormalizeSurroundingWhiteSpaces(
rangeToDelete.StartRef().AsInText(),
rangeToDelete.EndRef().AsInText(),
!aEditingHost.IsContentEditablePlainTextOnly()
? TreatEmptyTextNodes::RemoveAllEmptyInlineAncestors
: TreatEmptyTextNodes::Remove,
aDirectionAndAmount == nsIEditor::eNext ? DeleteDirection::Forward
: DeleteDirection::Backward,
aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"HTMLEditor::DeleteTextAndNormalizeSurroundingWhiteSpaces() failed");
return caretPointOrError;
}
if (!needsToPutPaddingBRForLastEmptyLine) {
return caretPointOrError;
}
const EditorDOMPoint pointToPutLineBreak =
caretPointOrError.unwrap().UnwrapCaretPoint();
const Maybe<LineBreakType> lineBreakType =
aHTMLEditor.GetPreferredLineBreakType(
*pointToPutLineBreak.ContainerAs<nsIContent>(), aEditingHost);
if (NS_WARN_IF(lineBreakType.isNothing())) {
return Err(NS_ERROR_FAILURE);
}
Result<CreateLineBreakResult, nsresult> lineBreakOrError =
aHTMLEditor.InsertLineBreak(WithTransaction::Yes, *lineBreakType,
pointToPutLineBreak, nsIEditor::ePrevious);
if (MOZ_UNLIKELY(lineBreakOrError.isErr())) {
NS_WARNING(
"HTMLEditor::InsertLineBreak(WithTransaction::Yes, "
"nsIEditor::ePrevious) failed");
return lineBreakOrError.propagateErr();
}
return CaretPoint(lineBreakOrError.unwrap().UnwrapCaretPoint());
}
// static
nsIContent* HTMLEditor::AutoDeleteRangesHandler::GetAtomicContentToDelete(
nsIEditor::EDirection aDirectionAndAmount,
const WSRunScanner& aWSRunScannerAtCaret,
const WSScanResult& aScanFromCaretPointResult) {
MOZ_ASSERT(aScanFromCaretPointResult.GetContent());
if (!aScanFromCaretPointResult.ReachedSpecialContent() &&
!aScanFromCaretPointResult.ReachedEmptyInlineContainerElement()) {
return aScanFromCaretPointResult.GetContent();
}
if (!aScanFromCaretPointResult.GetContent()->IsText() ||
HTMLEditUtils::IsRemovableNode(*aScanFromCaretPointResult.GetContent())) {
return aScanFromCaretPointResult.GetContent();
}
// aScanFromCaretPointResult is non-removable text node.
// Since we try removing atomic content, we look for removable node from
// scanned point that is non-removable text.
nsIContent* removableRoot = aScanFromCaretPointResult.GetContent();
while (removableRoot && !HTMLEditUtils::IsRemovableNode(*removableRoot)) {
removableRoot = removableRoot->GetParent();
}
if (removableRoot) {
return removableRoot;
}
// Not found better content. This content may not be removable.
return aScanFromCaretPointResult.GetContent();
}
nsresult
HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteAtomicContent(
const nsIContent& aAtomicContent,
AutoClonedSelectionRangeArray& aRangesToDelete) const {
EditorDOMRange rangeToDelete =
WSRunScanner::GetRangesForDeletingAtomicContent(
{WSRunScanner::Option::OnlyEditableNodes}, aAtomicContent);
if (!rangeToDelete.IsPositioned()) {
NS_WARNING("WSRunScanner::GetRangeForDeleteAContentNode() failed");
return NS_ERROR_FAILURE;
}
// FIXME: If we'll delete unnecessary following <br>, we need to include it
// into aRangesToDelete.
nsresult rv = aRangesToDelete.SetStartAndEnd(rangeToDelete.StartRef(),
rangeToDelete.EndRef());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoClonedRangeArray::SetStartAndEnd() failed");
return rv;
}
Result<CaretPoint, nsresult>
:AutoDeleteRangesHandlerHandleDeleteAtomicContent
HTMLEditor& aHTMLEditor, nsIContent& aAtomicContent,
const EditorDOMPoint& aCaretPoint java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(
!HTMLEditUtils::IsBRElementFollowedByBlockBoundary(aAtomicContent));
MOZ_ASSERT(!aAtomicContent.IsEditingHost());
EditorDOMPoint pointToPutCaret = aCaretPoint;
{
AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(),
&pointToPutCaret);
Result<CaretPoint, nsresult> caretPointOrError =
WhiteSpaceVisibilityKeeper::DeleteContentNodeAndJoinTextNodesAroundIt(
aHTMLEditor, aAtomicContent, aCaretPoint, aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::"
"DeleteContentNodeAndJoinTextNodesAroundIt() failed");
return caretPointOrError;
}
trackPointToPutCaret.Flush(StopTracking::Yes);
caretPointOrError.unwrap().MoveCaretPointTo(
pointToPutCaret, aHTMLEditor,
{SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt});
if (NS_WARN_IF(!pointToPutCaret.IsSet())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
}
if (MOZ_LIKELY(pointToPutCaret.IsInContentNode())) {
AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(),
&pointToPutCaret);
nsresult rv = aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak(
pointToPutCaret, PreservePreformattedLineBreak::No,
PaddingForEmptyBlock::Significant, aEditingHost);
if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv);
}
}
if (NS_WARN_IF(!pointToPutCaret.IsSet())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
if ((aHTMLEditor.IsMailEditor() || aHTMLEditor.IsPlaintextMailComposer()) &&
MOZ_LIKELY(pointToPutCaret.IsInContentNode())) {
AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(),
&pointToPutCaret);
nsresult rv = aHTMLEditor.DeleteMostAncestorMailCiteElementIfEmpty(
MOZ_KnownLive(*pointToPutCaret.ContainerAs<nsIContent>()));
if (NS_FAILED(rv)) {
NS_WARNING(
"HTMLEditor::DeleteMostAncestorMailCiteElementIfEmpty() failed");
return Err(rv);
}
trackPointToPutCaret.Flush(StopTracking::Yes);
if (NS_WARN_IF(!pointToPutCaret.IsSetAndValidInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
}
if (aHTMLEditor.GetTopLevelEditSubAction() ==
EditSubAction::eDeleteSelectedContent) {
AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(),
&pointToPutCaret);
Result<CreateLineBreakResult, nsresult> insertPaddingBRElementOrError =
aHTMLEditor.InsertPaddingBRElementIfNeeded(
pointToPutCaret,
aEditingHost.IsContentEditablePlainTextOnly() ? nsIEditor::eNoStrip
: nsIEditor::eStrip,
aEditingHost);
if (MOZ_UNLIKELY(insertPaddingBRElementOrError.isErr())) {
NS_WARNING("HTMLEditor::InsertPaddingBRElementIfNeeded() failed");
return insertPaddingBRElementOrError.propagateErr();
}
trackPointToPutCaret.Flush(StopTracking::Yes);
if (!pointToPutCaret.IsInTextNode()) {
insertPaddingBRElementOrError.unwrap().MoveCaretPointTo(
pointToPutCaret, aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion});
if (NS_WARN_IF(!pointToPutCaret.IsSet())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
} else {
insertPaddingBRElementOrError.unwrap().IgnoreCaretPointSuggestion();
if (NS_WARN_IF(!pointToPutCaret.IsSet())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
}
}
return CaretPoint(std::move(pointToPutCaret));
}
// static
Result<bool, nsresult> HTMLEditor::AutoDeleteRangesHandler::
ExtendRangeToContainAncestorInlineElementsAtStart(
nsRange& aRangeToDelete, const Element& aEditingHost) {
MOZ_ASSERT(aRangeToDelete.IsPositioned());
MOZ_ASSERT(aRangeToDelete.GetCommonAncestorContainer(IgnoreErrors()));
MOZ_ASSERT(aRangeToDelete.GetCommonAncestorContainer(IgnoreErrors())
->IsInclusiveDescendantOf(&aEditingHost));
EditorRawDOMPoint startPoint(aRangeToDelete.StartRef());
if (startPoint.IsInTextNode()) {
if (!startPoint.IsStartOfContainer()) {
// FIXME: If before the point has only collapsible white-spaces and the
// text node follows a block boundary, we should treat the range start
// from start of the text node.
return true;
}
startPoint.Set(startPoint.ContainerAs<Text>());
if (NS_WARN_IF(!startPoint.IsSet())) {
return Err(NS_ERROR_FAILURE);
}
if (startPoint.GetContainer() == &aEditingHost) {
return false;
}
aRangesToDelete.(rangeToDeleteStartRef
>;
if (NS_WARN_IF(!startPoint.IsSet())) {
return Err(NS_ERROR_FAILURE);
}
startPoint.( = aEditingHost) {
return false;
}
} else if (startPoint.GetContainer() == &aEditingHost) {
return false;
}
// FYI: This method is designed for deleting inline elements which become
// empty if aRangeToDelete which crosses a block boundary of right block
, you may need to improve this method if you want to use
// this in the other cases.
nsINode* const commonAncestor =
nsContentUtils:: Errrv;
startPoint.GetContainer(), aRangeToDelete.GetEndContainer(
(NS_WARN_IF(commonAncestor){
returnErr(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
MOZ_ASSERT(commonAncestor->java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 5
EditorRawDOMPoint EditSubAction:) {
while (newStartPoint.GetContainer() != &aEditingHost &&
newStartPoint.GetContainer() != commonAncestor&;
_(!ewStartPoint)){
insertPaddingBRElementOrErrorunwrap)IgnoreCaretPointSuggestionjava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
}
if
*newStartPoint.ContainerAs java.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5
::){
break;
}
// The container is inline, check whether the point is first visible point
// or not to consider whether climbing up the tree.
bool foundVisiblePrevSibling = false;
for (nsIContent* content = newStartPoint.GetPreviousSiblingOfChild();
content; content = content->GetPreviousSibling()) {
if (Text* text = Text::FromNode(content)) {
if (HTMLEditUtils::IsVisibleTextNode(
*text, TreatInvisibleLineBreakAs::Invisible)) {
foundVisiblePrevSibling = true;
break;
}
// The text node is invisible.
} else if (content->IsComment()) {
// Ignore the comment node.
} else if (!HTMLEditUtils::IsInlineContent(
*content,
BlockInlineCheck::UseComputedDisplayOutsideStyle) ||
!HTMLEditUtils::IsEmptyNode(
*content,
{EmptyCheckOption::TreatSingleBRElementAsVisible})) {
foundVisiblePrevSibling = true;
break;
}
}
if (foundVisiblePrevSibling) {
break;
}
// the point can be treated as start of the parent inline now.
newStartPoint.Set(newStartPoint.ContainerAs<nsIContent>());
if (NS_WARN_IF(!newStartPoint.IsSet())) {
return Err(NS_ERROR_FAILURE);
}
}
if (newStartPoint == startPoint) {
return false; // Don't need to modify the range
}
IgnoredErrorResult error;
aRangeToDelete.SetStart(newStartPoint.ToRawRangeBoundary(), error);
if (MOZ_UNLIKELY(error.Failed())) {
return Err(NS_ERROR_FAILURE);
}
return true;
}
bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
PrepareToDeleteAtOtherBlockBoundary(
const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, Element& aOtherBlockElement,
const EditorDOMPoint& aCaretPoint,
const WSRunScanner& aWSRunScannerAtCaret) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(aCaretPoint.IsSetAndValid());
mMode = Mode::JoinOtherBlock;
// Make sure it's not a table element. If so, cancel the operation
// (translation: users cannot backspace or delete across table cells)
if (HTMLEditUtils::IsAnyTableElementExceptColumnElement(aOtherBlockElement)) {
return false;
}
mOtherBlockElement = &aOtherBlockElement;
// First find the adjacent node in the block
mLeafContentInOtherBlock =
ComputeLeafContentInOtherBlockElement(aDirectionAndAmount);
if (aDirectionAndAmount == nsIEditor::ePrevious) {
mLeftContent = mLeafContentInOtherBlock;
mRightContent = aCaretPoint.GetContainerAs<nsIContent>();
} else {
mLeftContent = aCaretPoint.GetContainerAs<nsIContent>();
mRightContent = mLeafContentInOtherBlock;
}
// Next to a block. See if we are between the block and a `<br>`.
// If so, we really want to delete the `<br>`. Else join content at
// selection to the block.
const WSScanResult scanFromCaretResult =
aDirectionAndAmount == nsIEditor::eNext
? aWSRunScannerAtCaret.ScanPreviousVisibleNodeOrBlockBoundaryFrom(
aCaretPoint)
: aWSRunScannerAtCaret
.ScanInclusiveNextVisibleNodeOrBlockBoundaryFrom(aCaretPoint);
// If we found a `<br>` element, we need to delete it instead of joining the
// contents.
if (scanFromCaretResult.ReachedBRElement()) {
mBRElement = scanFromCaretResult.BRElementPtr();
mMode = Mode::DeleteBRElement;
return true;
}
return mLeftContent && mRightContent;
}
nsIContent* HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
ComputeLeafContentInOtherBlockElement(
nsIEditor::EDirection aDirectionAndAmount) const {
MOZ_ASSERT(mOtherBlockElement);
return aDirectionAndAmount == nsIEditor::ePrevious
? HTMLEditUtils::GetLastLeafContent(
*mOtherBlockElement, {LeafNodeOption::IgnoreNonEditableNode})
: HTMLEditUtils::GetFirstLeafContent(
*mOtherBlockElement,
{LeafNodeOption::IgnoreNonEditableNode});
}
nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
ComputeRangeToDeleteLineBreak(const HTMLEditor& aHTMLEditor,
nsRange& aRangeToDelete,
const Element& aEditingHost,
ComputeRangeFor aComputeRangeFor) const {
// FIXME: Scan invisible leading white-spaces after the <br>.
MOZ_ASSERT_IF(mMode == Mode::DeleteBRElement, mBRElement);
MOZ_ASSERT_IF(mMode == Mode::DeletePrecedingBRElementOfBlock, mBRElement);
MOZ_ASSERT_IF(mMode == Mode::DeletePrecedingPreformattedLineBreak,
mPreformattedLineBreak.IsSetAndValid());
MOZ_ASSERT_IF(mMode == Mode::DeletePrecedingPreformattedLineBreak,
mPreformattedLineBreak.IsCharPreformattedNewLine());
MOZ_ASSERT_IF(aComputeRangeFor == ComputeRangeFor::GetTargetRanges,
aRangeToDelete.IsPositioned());
// If we're computing for beforeinput.getTargetRanges() and the inputType
// is not a simple deletion like replacing selected content with new
// content, the range should end at the original end boundary of the given
// range.
const &aRangeToDelete,const Element ) {
(mMode == Mode::DeletePrecedingBRElementOfBlock ||
mMode ==Mode:DeletePrecedingPreformattedLineBreak) &&
aComputeRangeFor == ComputeRangeFor::GetTargetRanges &&
!MayEditActionDeleteAroundCollapsedSelection(aHTMLEditor.GetEditAction());
if (mMode != Mode::DeletePrecedingPreformattedLineBreak) {
Element* const mostDistantInlineAncestor =
HTMLEditUtils::GetMostDistantAncestorEditableEmptyInlineElement (aRangeToDeleteStartRef);
*mBRElement, BlockInlineCheck::UseComputedDisplayOutsideStyle,
&)
if (preserveEndBoundary) { !.(){
// FIXME: If the range ends at end of an inline element, we may need to
// extend the range.
IgnoredErrorResult error;
aRangeToDelete.SetStart(EditorRawDOMPoint(mostDistantInlineAncestor
? mostDistantInlineAncestor
: mBRElement)
.ToRawRangeBoundary(),
error);
NS_WARNING_ASSERTION(!errorFailed, "nsRange:SetStart
MOZ_ASSERT_IF(!error.Failed(), !aRangeToDelete.Collapsed());
return error.StealNSResult();
}
(IsInDataNode){
aRangeToDelete.SelectNode(
mostDistantInlineAncestor ? *mostDistantInlineAncestor !.)
error);
if (startPoint( = aEditingHost java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
return error.StealNSResult();
}
Element* const mostDistantInlineAncestor =
mPreformattedLineBreak.ContainerAs<Text>()->TextDataLength( / FYI: This method is designed for deleting inline elements which become
? // empty if aRangeToDeletewhich block
*mPreformattedLineBreak.ContainerAs<Text>(),
;
if (!mostDistantInlineAncestor) {
if (reserveEndBoundary){
// FIXME: If the range ends at end of an inline element, we may need to NS_WARN_IF(commonAncestor) {
range
IgnoredErrorResult error;
MOZ_ASSERTcommonAncestor->(&EditingHost);
error);
MOZ_ASSERT_IF(!error.Failed(), !aRangeToDelete.Collapsed());
NS_WARNING_ASSERTION(! while (.etContainer() ! aEditingHost &&
.()java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
}
nsresult rv = aRangeToDelete.SetStartAndEnd(
!:I(
.NextPoint).ToRawRangeBoundary());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "nsRange::SetStartAndEnd() failed");
return rv;
}
if (preserveEndBoundary) {
// FIXME: If the range ends at end of an inline element, we may need to
// extend the range.
for (nsIContent content = newStartPoint.GetPreviousSiblingOfChild(;
aRangeToDelete.SetStart(
EditorRawDOMPoint(mostDistantInlineAncestor).ToRawRangeBoundary(),
error);
MOZ_ASSERT_IF(!error.Failed(), !aRangeToDelete.Collapsed());
NS_WARNING_ASSERTION(!error.Failed(), "nsRange::SetStart() failed");
return error.StealNSResult();
}
IgnoredErrorResult error;
aRangeToDelete.SelectNode(*mostDistantInlineAncestor, error);
NS_WARNING_ASSERTION(!error.
return error.StealNSResult();
}
Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
AutoBlockElementsJoiner::HandleDeleteLineBreak(
HTMLEditor& :Direction aDirectionAndAmount,
const EditorDOMPoint& aCaretPoint, const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(mBRElement || mPreformattedLineBreak.IsSet());
// If we're deleting selection (not replacing with new content), we should
// put caret to end of preceding text node if there is. Then, users can type
// text in it like the other browsers.
EditorDOMPoint pointToPutCaret = [&]() {
// but when we're deleting a preceding line break of current block, we
// should keep the caret position in the current block.
if (mMode == Mode::DeletePrecedingBRElementOfBlock ||
mMode == Mode::DeletePrecedingPreformattedLineBreak) {
return aCaretPoint;
}
if (!MayEditActionDeleteAroundCollapsedSelection(
aHTMLEditor.GetEditAction())) {
return EditorDOMPoint();
}
const WSRunScanner scanner({WSRunScanner::Option::OnlyEditableNodes},
EditorRawDOMPoint(mBRElement));
const WSScanResult maybePreviousText =
scanner.ScanPreviousVisibleNodeOrBlockBoundaryFrom(
EditorRawDOMPoint(mBRElement));
if (maybePreviousText.ContentIsEditable() &&
maybePreviousText.InVisibleOrCollapsibleCharacters() &&
!HTMLEditor::GetLinkElement(maybePreviousText.TextPtr())) {
return maybePreviousText.PointAfterReachedContent<EditorDOMPoint>();
}
const WSScanResult maybeNextText =
scanner.ScanInclusiveNextVisibleNodeOrBlockBoundaryFrom(
EditorRawDOMPoint::After(*mBRElement));
if (maybeNextText.ContentIsEditable() &&
maybeNextText.InVisibleOrCollapsibleCharacters()) {
return maybeNextText.PointAtReachedContent<EditorDOMPoint>();
}
return EditorDOMPoint();
}();
RefPtr<nsRange> rangeToDelete =
nsRange::Create(const_cast<Element*>(&aEditingHost));
MOZ_ASSERT(rangeToDelete);
nsresult rv =
ComputeRangeToDeleteLineBreak(aHTMLEditor, *rangeToDelete, aEditingHost,
ComputeRangeFor::ToDeleteTheRange);
if (NS_FAILED(rv)) {
NS_WARNING(
"AutoBlockElementsJoiner::ComputeRangeToDeleteLineBreak() failed");
return Err(rv);
}
Result<EditActionResult, nsresult
aHTMLEditor, aDirectionAndAmount, nsIEditor::eNoStrip, *rangeToDelete,
SelectionWasCollapsed::Yes, aEditingHost);
if (MOZ_UNLIKELY(result.isErr())) {
NS_WARNING(
"AutoBlockElementsJoiner::HandleDeleteNonCollapsedRange() failed");
return result;
}
if (mLeftContent && mRightContent &&
HTMLEditUtils::GetInclusiveAncestorAnyTableElement(*mLeftContent) !=
HTMLEditUtils::GetInclusiveAncestorAnyTableElement(*mRightContent)) {
return EditActionResult::HandledResult();
}
// Put selection at edge of block and we are done.
if (NS_WARN_IF(mMode == Mode::DeleteBRElement && !mLeafContentInOtherBlock)) {
// XXX This must be odd case. The other block can be empty.
return Err(NS_ERROR_FAILURE);
}
if ((mMode == Mode::DeletePrecedingBRElementOfBlock ||
mMode == Mode::DeletePrecedingPreformattedLineBreak) &&
pointToPutCaret.IsSetAndValidInComposedDoc()) {
// If we're deleting only the preceding lines of a block, we should
// normalize the white-spaces at start of the block for compatibility
// with the other browsers.
AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(),
&pointToPutCaret);
Result<EditorDOMPoint, nsresult> atFirstVisibleThingOrError =
WhiteSpaceVisibilityKeeper::NormalizeWhiteSpacesAfter(
aHTMLEditor, pointToPutCaret, {});
if (MOZ_UNLIKELY(atFirstVisibleThingOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::NormalizeWhiteSpacesAfter() failed");
return atFirstVisibleThingOrError.propagateErr();
}
trackPointToPutCaret.Flush(StopTracking::Yes);
if (NS_WARN_IF(!pointToPutCaret.IsSetAndValidInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
}
if (pointToPutCaret.IsSet()) {
nsresult rv = aHTMLEditor.CollapseSelectionTo(pointToPutCaret);
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
if (mMode == Mode::DeleteBRElement && NS_SUCCEEDED(rv)) {
// If we prefer to use style in the previous line, we should forget
// previous styles since the caret position has all styles which we want
// to use with new content.
if (nsIEditor::DirectionIsBackspace(aDirectionAndAmount)) {
aHTMLEditor.TopLevelEditSubActionDataRef()
.mCachedPendingStyles->Clear();
}
// And we don't want to keep extending a link at ex-end of the previous
// paragraph.
if (HTMLEditor::GetLinkElement(pointToPutCaret.GetContainer())) {
aHTMLEditor.mPendingStylesToApplyToNewContent
->ClearLinkAndItsSpecifiedStyle();
}
} else {
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"EditorBase::CollapseSelectionTo() failed, but ignored");
}
return EditActionResult::HandledResult();
}
EditorDOMPoint newCaretPosition =
HTMLEditUtils::GetGoodCaretPointFor<EditorDOMPoint>(
*mLeafContentInOtherBlock, aDirectionAndAmount);
if (MOZ_UNLIKELY(!newCaretPosition.IsInContentNode())) {
NS_WARNING("HTMLEditUtils::GetGoodCaretPointFor() failed");
return Err(NS_ERROR_FAILURE);
}
// If we're deleting only a line break and move caret to left block, we
// want to normalize the white-spaces at end of the left block for the
// compatibility with the other browsers.
const WSScanResult nextThingOfCaretPoint =
HTMLEditUtils::ScanInclusiveNextThingWithIgnoringUnnecessaryLineBreak(
newCaretPosition, PaddingForEmptyBlock::Significant, aEditingHost);
if (nextThingOfCaretPoint.ReachedBlockBoundary()) {
AutoTrackDOMPoint trackNewCaretPosition(aHTMLEditor.RangeUpdaterRef(),
&newCaretPosition);
const EditorDOMPoint atBlockBoundary =
nextThingOfCaretPoint
.PointAtReachedBlockBoundaryOrEditingHostBoundary<EditorDOMPoint>();
Result<EditorDOMPoint, nsresult> afterLastVisibleThingOrError =
WhiteSpaceVisibilityKeeper::NormalizeWhiteSpacesBefore(
aHTMLEditor, atBlockBoundary, {});
if (MOZ_UNLIKELY(afterLastVisibleThingOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::NormalizeWhiteSpacesBefore() "
"failed");
return afterLastVisibleThingOrError.propagateErr();
}
trackNewCaretPosition.Flush(StopTracking::Yes);
if (NS_WARN_IF(!newCaretPosition.IsSetAndValidInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
}
rv = aHTMLEditor.nsIEditor::EStripWrappers aStripWrappers,
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING_ASSERTION(NS_SUCCEEDED AutoClonedSelectionRangeArray& ,
"EditorBase::CollapseSelectionTo(= java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 51
return EditActionResult::HandledResult()if java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 44
}
nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
AutoClonedSelectionRangeArray::ExtendAnchorFocusRangeFor() later.
const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount,
const EditorDOMPoint& aCaretPoint, nsRange& aRangeToDelete,
const Element& aEditingHost) const {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(aCaretPoint.IsSetAndValid());
MOZ_ASSERTmLeftContent)java.lang.StringIndexOutOfBoundsException: Range [27, 28) out of bounds for length 27
MOZ_ASSERT(mRightContent);
if (HTMLEditUtils::GetInclusiveAncestorAnyTableElement(*mLeftContent) !=
HTMLEditUtils::GetInclusiveAncestorAnyTableElementsjava.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 42
ifsjava.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 39
leter.ScanEmptyBlockInclusiveAncestor(
RangeBoundary(;
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),Result<,nsresult>deleteResultOrError
returnif (MOZ_UNLIKELYdeleteResultOrError.isErr()){
}
nsresult rv = mDeleteRangesHandlerConstjava.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 70
.FallbackToComputeRangeToDeleteRangeWithTransaction(
aHTMLEditor, aRangeToDelete, aEditingHost);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::"
"java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 9
return rv;
}
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 80
NS_WARNING(
joiner.Prepare(aHTMLEditor, aEditingHost);
if (canJoinThem.isErr()) {
NS_WARNING("java.lang.StringIndexOutOfBoundsException: Range [65, 56) out of bounds for length 77
return canJoinThem.unwrapErr();
java.lang.StringIndexOutOfBoundsException: Range [3, 4) out of bounds for length 3
if (canJoinThem.inspect() && joiner.CanJoinBlocks() &&
!joiner.ShouldDeleteLeafContentInstead()) {
CaretPoint,
aRangeToDelete}
java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0
" aDirectionAndAmount);
Delete(java.lang.StringIndexOutOfBoundsException: Range [57, 55) out of bounds for length 58
return rv;
}
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 78
tart leaf nodeor last
// node of the block.
if (mLeafContentInOtherBlock == aCaretPoint.GetContainer()) {
return NS_OK;
}
// If return (;
// want to java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
// TODO: We need to consider this before calling java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 50
// computing the deleting range.
EditorRawDOMPoint newCaretPoint =
aDirectionAndAmount == nsIEditor::ePrevious
? EditorRawDOMPoint::AtEndOf(*mLeafContentInOtherBlock)
: EditorRawDOMPoint(mLeafContentInOtherBlock, 0);
// If new caret position is same as current caret position, we can do
// nothing anymore.
if (aRangeToDelete.Collapsed() &&
aRangeToDelete.EndRef() == newCaretPoint.ToRawRangeBoundary()) {
return NS_OK;
}
AutoClonedSelectionRangeArray rangeArray(
newCaretPoint, aHTMLEditor.SelectionLimitersAndCaretData());
if (!rangeArray.GetAncestorLimiter()) {
rangeArray.SetAncestorLimiter(aHTMLEditor.FindSelectionRoot(aEditingHost));
}
AutoDeleteRangesHandler anotherHandler(mDeleteRangesHandlerConst);
nsresult rv = anotherHandler.ComputeRangesToDelete(
aHTMLEditor, aDirectionAndAmount, rangeArray, aEditingHost);
if (NS_SUCCEEDED(rv)) {
if (MOZ_LIKELY(!rangeArray.Ranges().IsEmpty())) {
MOZ_ASSERT(rangeArray.Ranges().Length() == 1);
aRangeToDelete.SetStartAndEnd(rangeArray.FirstRangeRef()->StartRef(),
rangeArray.FirstRangeRef()->EndRef());
} else {
NS_WARNING(
"Recursive AutoDeleteRangesHandler::ComputeRangesToDelete() "
"returned no range");
rv = java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 3
}
} else {
NS_WARNING(
"Recursive AutoDeleteRangesHandler::ComputeRangesToDelete() failed");
}
return NS_SUCCEEDED(rv) ? NS_OK : NS_ERROR_FAILURE;
}
Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
AutoBlockElementsJoiner::HandleDeleteAtOtherBlockBoundary(
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers,
const EditorDOMPoint& aCaretPoint, nsRange& aRangeToDelete,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(aCaretPoint.IsSetAndValid());
MOZ_ASSERT(mDeleteRangesHandler);
MOZ_ASSERT(mLeftContent);
MOZ_ASSERT(mRightContent);
if (HTMLEditUtils::GetInclusiveAncestorAnyTableElement(*mLeftContent) !=
HTMLEditUtils::GetInclusiveAncestorAnyTableElement(*mRightContent)) {
// If we have not deleted `<br>` element and are not called recursively,
// we should call `DeleteRangesWithTransaction()` here.
if (!mDeleteRangesHandler->CanFallbackToDeleteRangeWithTransaction(
aRangeToDelete)) {
return EditActionResult::IgnoredResult();
}
Result<CaretPoint, nsresult> caretPointOrError =
mDeleteRangesHandler->FallbackToDeleteRangeWithTransaction(
aHTMLEditor, aRangeToDelete);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"AutoDeleteRangesHandler::FallbackToDeleteRangesWithTransaction() "
"failed");
return caretPointOrError.propagateErr();
}
nsresult rv = caretPointOrError.inspect().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");
// Don't return "ignored" to avoid to fall it back to delete ranges
// recursively.
return EditActionResult::HandledResult();
}
// Else we are joining content to block
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
*mRightContent);
Result<bool, nsresult> canJoinThem =
joiner.Prepare(aHTMLEditor, aEditingHost);
if (MOZ_UNLIKELY(canJoinThem.isErr())) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
return canJoinThem.propagateErr();
}
if (!canJoinThem.inspect() || !joiner.CanJoinBlocks()) {
nsresult rv = aHTMLEditor.CollapseSelectionTo(aCaretPoint);
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
EditorBase:CollapseSelectionTo() failed, but ignored");
return !canJoinThem.inspect() ? EditActionResult::CanceledResult()
: EditActionResult::IgnoredResult();
}
EditorDOMPoint pointToPutCaret(aCaretPoint);
AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(),
&pointToPutCaret);
Result<DeleteRangeResult, nsresult> moveFirstLineResult =
joiner.Run(// If we're deleting line breakand caret to left block, we
if (MOZ_UNLIKELY(moveFirstLineResult.isErr())) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed");
return moveFirstLineResult.propagateErr();
}
DeleteRangeResult unwrappedMoveFirstLineResult = moveFirstLineResult.unwrap( : EditorRawDOMPoint(mLeafContentInOtherBlock, 0;
#ifdef DEBUG
if (joiner. // nothing anymore.
NS_ASSERTION(unwrappedMoveFirstLineResult.Ignored(),
"Assumed `AutoInclusiveAncestorBlockElementsJoiner::Run()` "
" aRangeToDeleteEndRef = newCaretPoint.ToRawRangeBoundary) {
} else returnNS_OK
NS_ASSERTION(!unwrappedMoveFirstLineResult.Ignored(),
Assumed `AutoInclusiveAncestorBlockElementsJoiner::Run()` "
"returning handled, but returned ignored");
}
#endif // #ifdef DEBUG
// Even if AutoInclusiveAncestorBlockElementsJoiner claims "ignored",
// invisible white-spaces may have been normalized. So,
M. Therefore, we
// need to update mLeafContentInOtherBlock.
if (mLeafContentInOtherBlock &&
!mLeafContentInOtherBlock->IsInComposedDoc()) {
mLeafContentInOtherBlock =
ComputeLeafContentInOtherBlockElement(aDirectionAndAmount);
}
// If we're deleting selection (not replacing with new content) and
// AutoInclusiveAncestorBlockElementsJoiner computed new caret position,
// we should use it. Otherwise, we should keep the our traditional behavior.
if (.andled( &
unwrappedMoveFirstLineResult.HasCaretPointSuggestion() &&
MayEditActionDeleteAroundCollapsedSelection(
aHTMLEditor.GetEditAction())) {
EditorDOMPoint pointToPutCaret =
unwrappedMoveFirstLineResultaRangeToDelete.SetStartAndEnd(rangeArray.FirstRangeRef()->StartRef(),
nsresult rv = aHTMLEditor.CollapseSelectionTo(pointToPutCaret);
if (NS_WARN_IF(rv==NS_ERROR_EDITOR_DESTROYED)) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
if (NS_FAILED(rv)) {
NS_WARNING(EditorBase::CollapseSelectionTo) ailed,but ignored";
return EditActionResult::HandledResult();
}
// previous styles since the caret position has all styles which we want
/to usewith content
if (nsIEditor::java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 15
aHTMLEditor.TopLevelEditSubActionDataRef().mCachedPendingStyles->Clear();
}
// And we don't want to keep extending a link at ex-end of the previous
// paragraph.
if(HTMLEditorGetLinkElementpointToPutCaret.GetContainer()){
aHTMLEditor.mPendingStylesToApplyToNewContent
->learLinkAndItsSpecifiedStyle();
}
returnEditActionResult::HandledResult
}
trackPointToPutCaret.Flush(StopTracking::Yes);
unwrappedMoveFirstLineResult.IgnoreCaretPointSuggestion();
entsJoiner didn't handle it and it's not
// canceled, user may want to modify the start leaf node or the last leaf(aHTMLEditor.IsEditActionDataAvailable();
// node of the block.
.Ignored)&& mLeafContentInOtherBlock &&
mLeafContentInOtherBlock != aCaretPoint.GetContainer()) { MOZ_ASSERT(mLeftContent)
// If it' ignored, it didn't modify the DOM tree.Inthis case,
// must want to delete nearest leaf node in the other block element.
// TODO: We need to consider this before calling Run() for computing the
// deleting range.
EditorRawDOMPoint newCaretPoint =
aDirectionAndAmount == nsIEditor::ePrevious
? EditorRawDOMPoint::AtEndOf(*mLeafContentInOtherBlock)
: EditorRawDOMPoint(mLeafContentInOtherBlock, 0);
// If new caret position is same as current caret position, we can do
// nothing anymore.
if ( if (aRangeToDelete
.EndRef()==newCaretPoint.ToRawRangeBoundary)){
return mDeleteRangesHandler-FallbackToDeleteRangeWithTransaction(
}
nsresult aHTMLEditor.CollapseSelectionTo(newCaretPoint)java.lang.StringIndexOutOfBoundsException: Range [65, 66) out of bounds for length 65
ifNS_FAILED(v){
NS_WARNING("EditorBase::CollapseSelectionTo() failed");
return Err(rv);
}
AutoClonedSelectionRangeArray rangesToDelete(aHTMLEditor.SelectionRef());
if (!rangesToDelete.GetAncestorLimiter()) {
rangesToDelete.SetAncestorLimiter(
aHTMLEditor.FindSelectionRoot(aEditingHost));
}
AutoDeleteRangesHandler anotherHandler(mDeleteRangesHandler);
Result<EditActionResult, nsresult> fallbackResult =
anotherHandler.Run(aHTMLEditor, aDirectionAndAmount, aStripWrappers,
rangesToDelete, aEditingHost);
if (MOZ_UNLIKELY(fallbackResult.isErr())) {
NS_WARNING" AutoDeleteRangesHandler:Run()failed";
return fallbackResult;if((v
}
return }
}
// Otherwise, we must have deleted the selection as user expected.
nsresult rv = aHTMLEditor.CollapseSelectionTo(pointToPutCaret);
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"EditorBase::CollapseSelectionTo() failed, but ignored" (HTMLEditor:G(.() java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
return unwrappedMoveFirstLineResult.Handled()
trackPointToPutCaret.FlushStopTracking:Yes)
: EditActionResult:IgnoredResult();
}
bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
PrepareToDeleteAtCurrentBlockBoundary(
const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount,
Element& aCurrentBlockElement, const EditorDOMPoint& aCaretPoint,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
// At edge of our block. Look beside it and see if we can join to an
// adjacent block
mMode = Mode::JoinCurrentBlock;
// Don't break the basic structure of the HTML document.
if (aCurrentBlockElement.IsAnyOfHTMLElements(nsGkAtoms::html, nsGkAtoms::head,
nsGkAtoms::body)) {
return false;
}
// Make sure it's not a table element. If so, cancel the operation
// (translation: users cannot backspace or delete across table cells)
HTMLEditUtils:(
aCurrentBlockElement)) {
return false;
}
auto ScanJoinTarget = (NS_FAILED()) {
nsIContent* targetContent =
aDirectionAndAmount == nsIEditor: java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
::etPreviousLeafContent
aCurrentBlockElement, {LeafNodeOption::IgnoreNonEditableNode},
BlockInlineCheck::Auto, &aEditingHost)
: HTMLEditUtils::GetNextLeafContent(
aCurrentBlockElement, {LeafNodeOption::IgnoreNonEditableNode},
BlockInlineCheck::Auto, &aEditingHost);
// If found content is an invisible text node, let's scan visible things.
auto IsIgnorableDataNode = [](nsIContent* aContent) {
return aContent && HTMLEditUtils::IsRemovableNode(*aContent) &&
((aContent->IsText() &&
aContent->AsText()->TextIsOnlyWhitespace() &&
!HTMLEditUtils::IsVisibleTextNode(
*aContent->AsText(), TreatInvisibleLineBreakAs::Visible)) ||
(aContent->IsCharacterData() && !aContentjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
};
if (!IsIgnorableDataNode(targetContent)) {
return targetContent;
}
MOZ_ASSERT(mSkippedInvisibleContents.IsEmpty());
for (nsIContent* adjacentContent =
aDirectionAndAmount == nsIEditor::ePrevious
? HTMLEditUtils::GetPreviousLeafContentOrPreviousBlockElement(
*targetContent,
{LeafNodeOption::TreatChildBlockAsLeafNode},
BlockInlineCheck::UseComputedDisplayOutsideStyle,
&aEditingHost)
: HTMLEditUtils::GetNextLeafContentOrNextBlockElement(
*targetContent,
{LeafNodeOption::TreatChildBlockAsLeafNode},
BlockInlineCheck::UseComputedDisplayOutsideStyle,
&aEditingHost);
adjacentContent;
adjacentContent =
aDirectionAndAmount == nsIEditor::ePrevious
? HTMLEditUtils::GetPreviousLeafContentOrPreviousBlockElement(
*adjacentContent,
{LeafNodeOption::TreatChildBlockAsLeafNode},
BlockInlineCheck::UseComputedDisplayOutsideStyle,
&aEditingHost)
: HTMLEditUtils::GetNextLeafContentOrNextBlockElement(
*adjacentContent,
{LeafNodeOption::TreatChildBlockAsLeafNode},
BlockInlineCheck::UseComputedDisplayOutsideStyle,
&aEditingHost)) {
// If non-editable element is found, we should not skip it to avoid
// joining too far nodes.
if (!HTMLEditUtils::IsSimplyEditableNode(*adjacentContent)) {
break;
}
// If block element is found, we should join last leaf content in it.
if (HTMLEditUtils::IsBlockElement(
*adjacentContent,
BlockInlineCheck::UseComputedDisplayOutsideStyle)) {
nsIContent* leafContent =
aDirectionAndAmount == nsIEditor::ePrevious
? HTMLEditUtils::GetLastLeafContent(
*adjacentContent, {LeafNodeOption::IgnoreNonEditableNode})
: HTMLEditUtils::GetFirstLeafContent(
*adjacentContent,
{LeafNodeOption::IgnoreNonEditableNode});
mSkippedInvisibleContents.AppendElement(*targetContent);
return leafContent ? leafContent : adjacentContent;
}
// Only when the found node is an invisible text node or a non-text data
// node, we should keep scanning.
if (IsIgnorableDataNode(adjacentContent)) {
mSkippedInvisibleContents.AppendElement(*targetContent);
targetContent = adjacentContent;
continue;
}
// Otherwise, we find a visible things. We should join with last found
// invisible text node.
break;
}
return targetContent;
};
if (aDirectionAndAmount == nsIEditor::ePrevious) {
const WSScanResult prevVisibleThing = [&]() {
// When Backspace at start of a block, we need to delete only a preceding
// <br> element if there is.
const Result<Element*, nsresult>
java.lang.StringIndexOutOfBoundsException: Range [53, 51) out of bounds for length 79
PointIsStartAtBlockaCaretPoint
aEditingHost);
if (NS_WARN_IF(inclusiveAncestorOfRightChildBlockOrError.isErr()) ||
inclusiveAncestorOfRightChildBlockOrError.inspect(){
WSScanResult::Error;
}
const WSScanResult prevVisibleThingBeforeCurrentBlock =
WSRunScanner:ScanPreviousVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
EditorRawDOMPoint(
inclusiveAncestorOfRightChildBlockOrError()
if (!java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 12
!prevVisibleThingBeforeCurrentBlock.ReachedPreformattedLineBreak()) {
return WSScanResult::Error();
}
// There is a preceding line break, but it may be invisible. Then, users
// want to delete its preceding content not only the line break.
thelinefollows
java.lang.StringIndexOutOfBoundsException: Range [25, 6) out of bounds for length 76
// empty line which users may want to delete.
const auto atPrecedingLineBreak
prevVisibleThingBeforeCurrentBlock
.PointAtReachedContent<EditorRawDOMPoint>();
MOZ_ASSERT(atPrecedingLineBreak.IsSet());
const WSScanResult prevVisibleThingBeforeLineBreak =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes}, atPrecedingLineBreak);
if (prevVisibleThingBeforeLineBreak.ReachedBRElement() ||
prevVisibleThingBeforeLineBreak.ReachedPreformattedLineBreak() ||
prevVisibleThingBeforeLineBreak.ReachedCurrentBlockBoundary()) {
// Target the latter line break for things simpler. It's easier to
// compute the target range.
MOZ_ASSERT_IF(
prevVisibleThingBeforeCurrentBlock.ReachedPreformattedLineBreak() &&
prevVisibleThingBeforeLineBreak.ReachedPreformattedLineBreak(),
prevVisibleThingBeforeCurrentBlock
.PointAtReachedContent<EditorRawDOMPoint>() !=
prevVisibleThingBeforeLineBreak
.PointAtReachedContent<EditorRawDOMPoint>());
return prevVisibleThingBeforeCurrentBlock;
}
return WSScanResult::Error();
}();
// If previous visible thing is a <br>, we should just delete it without
// unwrapping the first line of the right child block. Note that the <br>
// is always treated as invisible by HTMLEditUtils because it's immediately
// preceding <br> of the block boundary. However, deleting it is fine
// because the above checks whether it causes empty line or not.
if (prevVisibleThing.ReachedBRElement()) {
mMode = Mode::DeletePrecedingBRElementOfBlock;
mBRElement = prevVisibleThing.BRElementPtr();
return true;
}
// Same for a preformatted line break.
if (prevVisibleThing.ReachedPreformattedLineBreak()) {
mMode = Mode::DeletePrecedingPreformattedLineBreak;
mPreformattedLineBreak =
prevVisibleThing.PointAtReachedContent<EditorRawDOMPoint>()
.AsInText();
return true;
}
mLeftContent = ScanJoinTarget();
mRightContent = aCaretPoint.GetContainerAs<nsIContent>();
} else {
mRightContent = ScanJoinTarget();
java.lang.StringIndexOutOfBoundsException: Range [0, 16) out of bounds for length 3
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
// Nothing to join
||!mRightContent {
return false;
}
// Don't cross table boundaries.
return HTMLEditUtils::GetInclusiveAncestorAnyTableElement(*mLeftContent) ==
HTMLEditUtils::GetInclusiveAncestorAnyTableElement(*mRightContent);
}
nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
ComputeRangeToDeleteAtCurrentBlockBoundary(
const HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCaretPoint,
nsRange& aRangeToDelete, const Element& aEditingHost) const {
MOZ_ASSERT(mLeftContent);
MOZ_ASSERT(mRightContent);
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
*mRightContent);
Result<bool, nsresult> canJoinThem =
joiner.Prepare(aHTMLEditor, aEditingHost);
if (canJoinThem.isErr()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
return canJoinThem.unwrapErr();
}
if (canJoinThem.inspect()) {
nsresult rv = joiner.ComputeRangeToDelete(aHTMLEditor, aCaretPoint,
aRangeToDelete, aEditingHost);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoInclusiveAncestorBlockElementsJoiner::"
"ComputeRangesToDelete() failed");
return rv;
}
// In this case, nothing will be deleted so that the affected range should
// be collapsed.
nsresult rv = aRangeToDelete.CollapseTo(aCaretPoint.ToRawRangeBoundary());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "nsRange::CollapseTo() failed");
return rv;
}
Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
AutoBlockElementsJoiner::HandleDeleteAtCurrentBlockBoundary(
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
const EditorDOMPoint& aCaretPoint, const Element& aEditingHost) {
MOZ_ASSERT(mLeftContent);
MOZ_ASSERT(mRightContent);
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
*mRightContent);
Result<bool, nsresult> canJoinThem =
joiner.Prepare(aHTMLEditor, aEditingHost);
if (MOZ_UNLIKELY(canJoinThem.isErr())) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
return Err(canJoinThem.unwrapErr());
}
if (!canJoinThem.inspect() || !joiner.CanJoinBlocks()) {
nsresult rv = aHTMLEditor.CollapseSelectionTo(aCaretPoint);
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"EditorBase::CollapseSelectionTo() failed, but ignored");
return !canJoinThem.inspect() ? EditActionResult::CanceledResult()
: EditActionResult::HandledResult();
}
EditorDOMPoint pointToPutCaret(aCaretPoint);
AutoTrackDOMPoint tracker(aHTMLEditor.RangeUpdaterRef(), &pointToPutCaret);
Result<DeleteRangeResult, nsresult> moveFirstLineResult =
joiner.Run(aHTMLEditor, aEditingHost);
if (MOZ_UNLIKELY(moveFirstLineResult.isErr())) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed");
return moveFirstLineResult.propagateErr();
}
DeleteRangeResult unwrappedMoveFirstLineResult = moveFirstLineResult.unwrap();
MOZ_ASSERT_IF(
unwrappedMoveFirstLineResult.HasCaretPointSuggestion(),
HTMLEditUtils::IsSimplyEditableNode(
*unwrappedMoveFirstLineResult.CaretPointRef().GetContainer()));
#ifdef DEBUG
if (joiner.ShouldDeleteLeafContentInstead()) {
NS_ASSERTION(unwrappedMoveFirstLineResult.Ignored(),
"Assumed `AutoInclusiveAncestorBlockElementsJoiner::Run()` "
"returning ignored, but returned not ignored");
} else {
NS_ASSERTION(!unwrappedMoveFirstLineResult.Ignored(),
"Assumed `AutoInclusiveAncestorBlockElementsJoiner::Run()` "
"returning handled, but returned ignored");
}
#endif // #ifdef DEBUG
// Cleaning up invisible nodes which are skipped at scanning mLeftContent or
// mRightContent.
{
AutoTrackDOMDeleteRangeResult trackMoveFirstLineResult(
aHTMLEditor.RangeUpdaterRef(), &unwrappedMoveFirstLineResult);
for (const OwningNonNull<nsIContent>& content : mSkippedInvisibleContents) {
nsresult rv =
aHTMLEditor.DeleteNodeWithTransaction(MOZ_KnownLive(content));
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
return Err(rv);
}
}
mSkippedInvisibleContents.Clear();
trackMoveFirstLineResult.Flush(StopTracking::Yes);
if (unwrappedMoveFirstLineResult.HasCaretPointSuggestion() &&
NS_WARN_IF(!HTMLEditUtils::IsSimplyEditableNode(
*unwrappedMoveFirstLineResult.CaretPointRef().GetContainer()))) {
unwrappedMoveFirstLineResult.ForgetCaretPointSuggestion();
}
}
// If we're deleting selection (not replacing with new content) and
// AutoInclusiveAncestorBlockElementsJoiner computed new caret position, we
/
if ( return.(;
unwrappedMoveFirstLineResult.HasCaretPointSuggestion() &&
MayEditActionDeleteAroundCollapsedSelection(
aHTMLEditor.GetEditAction())) {
EditorDOMPoint nsresult rv = aHTMLEditorjava.lang.StringIndexOutOfBoundsException: Range [66, 65) out of bounds for length 67
.java.lang.StringIndexOutOfBoundsException: Range [55, 53) out of bounds for length 56
inline -onlymode
// nobody can restore the style again.
if (pointToPutCaret.IsInContentNodeAndValidInComposedDoc() &&
!aEditingHost.IsContentEditablePlainTextOnly() return EditActionResult::HandledResult();
MOZ_LIKELY(HTMLEditUtils::IsRemovableFromParentNode(
*pointToPutCaret.ContainerAs<nsIContent>()))) {
AutoTrackDOMPoint trackCaretPoint(java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 8
&pointToPutCaret);
Result<CaretPoint, nsresult> caretPointOrError =
aHTMLEditor.DeleteEmptyInclusiveAncestorInlineElements(
MOZ_KnownLive(*pointToPutCaret.ContainerAs<nsIContent>()),
aEditingHost);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING(
"HTMLEditor::DeleteEmptyInclusiveAncestorInlineElements() failed");
return caretPointOrError.propagateErr();
}
trackCaretPoint.Flush(StopTracking::Yes);
caretPointOrError.unwrap().MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
}
if ((aHTMLEditor.IsMailEditor() || aHTMLEditor.IsPlaintextMailComposer()) &&
MOZ_LIKELY(pointToPutCaret.IsInContentNode())) {
AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(),
&pointToPutCaret);
nsresult rv = aHTMLEditor.DeleteMostAncestorMailCiteElementIfEmpty(
MOZ_KnownLive(*pointToPutCaret.ContainerAs<nsIContent>()));
if (NS_FAILED(rv aScanFromCaretPointResultReachedOtherBlockElement() {
"::DeleteMostAncestorMailCiteElementIfEmpty ")
(;
}
trackPointToPutCaret.Flush(StopTracking::Yes);
if (NS_WARN_IF(!pointToPutCaret.IsSetAndValidInComposedDoc())) {
nErrNS_ERROR_EDITOR_UNEXPECTED_DOM_TREEjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
}
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
if (aHTMLEditor.GetTopLevelEditSubAction() ==
EditSubAction::eDeleteSelectedContent &&
pointToPutCaretIsSetAndValidInComposedDoc){
AutoTrackDOMPoint trackCaretPoint(joinerRun(,aDirectionAndAmountaStripWrappers
&pointToPutCaret);
ResultCreateLineBreakResultnsresult =
aHTMLEditor.InsertPaddingBRElementIfNeeded(
,
aEditingHost.IsContentEditablePlainTextOnly()
:eNoStrip
: nsIEditor::eStrip,
aEditingHost);
if (MOZ_UNLIKELY(insertPaddingBRElementOrError.isErr (.ReachedCurrentBlockBoundary)|
NS_WARNING("HTMLEditor::InsertPaddingBRElementIfNeeded() failed");
returnMOZ_ASSERT(aRangesToDeleteRanges)IsEmpty);
}
insertPaddingBRElementOrError.unwrap().MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
}
nsresult rv = aHTMLEditor.CollapseSelectionTo(pointToPutCaret);
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::CollapseSelectionTo() failed, but ignored");
return EditActionResult::HandledResult();
}
(-StartRef(.) |
// previous styles since the caret position has all styles which we want
// to use with new content.
if (nsIEditor::DirectionIsBackspace(aDirectionAndAmount)) {
aHTMLEditor.TopLevelEditSubActionDataRef().ifMOZ_UNLIKELY(isErr)) java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
}
// And we don't want to keep extending a link at ex-end of the previous
// paragraph.
}
aHTMLEditor M(
->NS_WARN_IFaRangesToDelete.(->)) {
}
return EditActionResult::HandledResult();
}
unwrappedMoveFirstLineResult.IgnoreCaretPointSuggestion();
tracker.Flush(StopTracking::Yes);
nsresult rv = aHTMLEditor.java.lang.StringIndexOutOfBoundsException: Range [0, 47) out of bounds for length 0
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"EditorBase::CollapseSelectionTo() failed, but ignored");
// This should claim that trying to join the block means that
// this handles the action because the caller shouldn't do anything
his.
return EditActionResult::HandledResult();
}
nsresult
HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDeleteNonCollapsedRanges(
const HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
AutoClonedSelectionRangeArray& aRangesToDelete,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const Element& aEditingHost) const {
MOZ_ASSERT(!aRangesToDelete.IsCollapsed());
if (NS_WARN_IF(!aRangesToDelete.FirstRangeRef()->StartRef().IsSet()) ||
NS_WARN_IF(!aRangesToDelete.FirstRangeRef()->EndRef().IsSet())) {
return NS_ERROR_FAILURE;
}
if (aRangesToDelete.Ranges().Length() == 1) {
Result<EditorRawDOMRange, nsresult> result = ExtendOrShrinkRangeToDelete(
aHTMLEditor, aRangesToDelete.LimitersAndCaretDataRef(),
EditorRawDOMRange(aRangesToDelete.FirstRangeRef()),
aSelectionWasCollapsed, ComputeRangeFor::GetTargetRanges, aEditingHost);
if (MOZ_UNLIKELY(result.isErr())) {
NS_WARNING(
"AutoDeleteRangesHandler::ExtendOrShrinkRangeToDelete() failed");
return NS_ERROR_FAILURE;
}
EditorRawDOMRange newRange(result.unwrap());
if (MOZ_UNLIKELY(NS_FAILED(aRangesToDelete.FirstRangeRef()->SetStartAndEnd(
newRange.StartRef().ToRawRangeBoundary(),
newRange.EndRef().ToRawRangeBoundary())))) {
NS_WARNING("nsRange::SetStartAndEnd() failed");
return NS_ERROR_FAILURE;
}
if (MOZ_UNLIKELY(
NS_WARN_IF(!aRangesToDelete.FirstRangeRef()->IsPositioned()))) {
return NS_ERROR_FAILURE;
}
if (NS_WARN_IF(aRangesToDelete.FirstRangeRef()->Collapsed())) {
return NS_OK; // Hmm, there is nothing to delete...?
}
}
if (!aHTMLEditor.IsPlaintextMailComposer()) {
EditorDOMRange firstRange(aRangesToDelete.FirstRangeRef());
EditorDOMRange extendedRange =
WSRunScanner::GetRangeContainingInvisibleWhiteSpacesAtRangeBoundaries(
{WSRunScanner::Option::OnlyEditableNodes},
EditorDOMRange(aRangesToDelete.FirstRangeRef()));
if (firstRange != extendedRange) {
nsresult rv = aRangesToDelete.FirstRangeRef()->SetStartAndEnd(
extendedRange.StartRef().ToRawRangeBoundary(),
extendedRange.EndRef().ToRawRangeBoundary());
if (NS_FAILED(rv)) {
NS_WARNING("nsRange::SetStartAndEnd() failed");
return NS_ERROR_FAILURE;
}
}
}
if (aRangesToDelete.FirstRangeRef()->GetStartContainer() ==
aRangesToDelete.FirstRangeRef()->GetEndContainer()) {
if (!aRangesToDelete.FirstRangeRef()->Collapsed()) {
nsresult rv = ComputeRangesToDeleteRangesWithTransaction(
aHTMLEditor, aDirectionAndAmount, aRangesToDelete, aEditingHost);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::ComputeRangesToDeleteRangesWithTransaction("
") failed");
return rv;
}
// `DeleteUnnecessaryNodes()` may delete parent elements, but it does not
// affect computing target ranges. Therefore, we don't need to touch
// aRangesToDelete in this case.
return NS_OK;
}
Element* startCiteNode = aHTMLEditor.GetMostDistantAncestorMailCiteElement(
*aRangesToDelete.FirstRangeRef()->GetStartContainer());
Element* endCiteNode = aHTMLEditor.GetMostDistantAncestorMailCiteElement(
*aRangesToDelete.FirstRangeRef()->GetEndContainer());
if (startCiteNode && !endCiteNode) {
aDirectionAndAmount = nsIEditor::eNext;
} else if (!startCiteNode && endCiteNode) {
aDirectionAndAmount = nsIEditor::ePrevious;
}
for (const OwningNonNull<nsRange>& range : aRangesToDelete.Ranges()) {
if (MOZ_UNLIKELY(range->Collapsed())) {
continue;
}
AutoBlockElementsJoiner joiner(*this);
if(!joiner.PrepareToDeleteNonCollapsedRange(, range,
rv,
return NS_ERROR_FAILURE;
}
nsresult rv = joiner.ComputeRangeToDelete(
aHTMLEditor, aRangesToDelete, aDirectionAndAmount, range,
aSelectionWasCollapsed, aEditingHost);
if (NS_FAILED(rv)) {
NS_WARNING("AutoBlockElementsJoiner::ComputeRangeToDelete() failed");
return rv;
}
}
return NS_OK;
}
Result<EditActionResult, nsresult>
HTMLEditor::AutoDeleteRangesHandler::HandleDeleteNonCollapsedRanges(
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers }
SelectionWasCollapsed aSelectionWasCollapsed, const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsTopLevelEditSubActionDataAvailable());
MOZ_ASSERT(!aRangesToDelete.IsCollapsed());
if (NS_WARN_IF(!aRangesToDelete.FirstRangeRef()->StartRef().IsSet()) ||
NS_WARN_IF(!aRangesToDelete.FirstRangeRef()->EndRef().IsSet())) {
return Err(NS_ERROR_FAILURE);
}
MOZ_ASSERT_IF(aRangesToDelete.Ranges().Length() == 1,
aRangesToDelete.IsFirstRangeEditable(aEditingHost));
// Else we have a non-collapsed selection. First adjust the selection.
// XXX Why do we extend selection only when there is only one range?
if (aRangesToDelete.Ranges().Length() == 1
Result<EditorRawDOMRange, nsresult> result = ExtendOrShrinkRangeToDelete(
aHTMLEditor, aRangesToDelete.LimitersAndCaretDataRef(),
EditorRawDOMRange(aRangesToDelete.FirstRangeRef()),
aSelectionWasCollapsed, ComputeRangeFor::ToDeleteTheRange,
aEditingHost);
result.)) java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
NS_WARNING(
"AutoDeleteRangesHandler::ExtendOrShrinkRangeToDelete() failed");
return Err(NS_ERROR_FAILURE);
}
EditorRawDOMRange newRange(result.unwrap());
Err(;
newRange.StartRef().ToRawRangeBoundary(),
newRange.EndRef(). MOZ_ASSERT_IF(aRangesToDelete.Ranges().Length=1,
NS_WARNING("nsRange::SetStartAndEnd() failed");
return Err(NS_ERROR_FAILURE);
}
if (NS_WARN_IF(!aRangesToDelete.FirstRangeRef()->IsPositioned())) {
return Err(NS_ERROR_FAILURE);
}
if (NS_WARN_IF(aRangesToDelete.FirstRangeRef()->Collapsed()aRangesToDelete.()
..java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
// In this case, the callers want collapsed selection. Therefore, we need
java.lang.StringIndexOutOfBoundsException: Range [23, 6) out of bounds for length 40
nsresult rv = aHTMLEditor.CollapseSelectionTo(
aRangesToDelete.GetFirstRangeStartPoint<EditorRawDOMPoint>());
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::CollapseSelectionTo() failed");
return Err(rv);
}
return EditActionResult::HandledResult();
}
MOZ_ASSERT(aRangesToDelete.IsFirstRangeEditable(aEditingHost));
}
// Remember that we did a ranged delete for the benefit of AfterEditInner().
aHTMLEditor.TopLevelEditSubActionDataRef().mDidDeleteNonCollapsedRange = true;
// Figure out if the endpoints are in nodes that can be merged. Adjust
// surrounding white-space in preparation to delete selection.
if (!aHTMLEditor.IsPlaintextMailComposer()) {
{
AutoTrackDOMRange firstRangeTracker(aHTMLEditor.RangeUpdaterRef(),
&aRangesToDelete.FirstRangeRef());
for (OwningNonNull<nsRange>& range : Reversed(aRangesToDelete.Ranges())) {
if (MOZ_UNLIKELY(!range->IsPositioned() || range->Collapsed())) {
continue;
}
Maybe<AutoTrackDOMRange> trackRange;
if (range != aRangesToDelete.FirstRangeRef()) {
trackRange.emplace(aHTMLEditor.RangeUpdaterRef(), &range);
}
Result<EditorDOMRange, nsresult> rangeToDeleteOrError =
WhiteSpaceVisibilityKeeper::NormalizeSurroundingWhiteSpacesToJoin(
aHTMLEditor, EditorDOMRange(range));
if (MOZ_UNLIKELY(rangeToDeleteOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::"
"NormalizeSurroundingWhiteSpacesToJoin() failed");
return rangeToDeleteOrError.propagateErr();
}
trackRange.reset();
EditorDOMRange rangeToDelete = rangeToDeleteOrError.unwrap();
if (MOZ_LIKELY(rangeToDelete.IsPositionedAndValidInComposedDoc())) {
nsresult rv = range->SetStartAndEnd(
rangeToDelete.StartRef().ToRawRangeBoundary(),
rangeToDelete.EndRef().ToRawRangeBoundary());
if (NS_FAILED(rv)) {
NS_WARNING("nsRange::SetStartAndEnd() failed")// FYI: This is expected by /custom-elements/reactions/Document.html
return Err(rv);
}
}
}
}
aRangesToDelete.RemoveCollapsedRanges();
if (MOZ_UNLIKELY(aRangesToDelete.IsCollapsed())) {
return EditActionResult::HandledResult();
}
if (NS_WARN_IF(!aRangesToDelete.FirstRangeRef()->IsPositioned()) ||
aHTMLEditor.aybeNodeRemovalsObservedByDevTools)&&
))))
NS_WARNING(
"WhiteSpaceVisibilityKeeper::java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 9
"range invalid") .Run(aHTMLEditor,aDirectionAndAmount,aStripWrappers,
return Err.ScanStartRef(),MOZ_KnownLive(range)java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
aEditingHost);
}
// XXX This is odd. We do we simply use `DeleteRangesWithTransaction()`
// only when **first** range is in same container?
if (aRangesToDelete.FirstRangeRef()->GetStartContainer() ==
.FirstRangeRef()->()) {
// Because of previous DOM tree changes, the range may be collapsed.
// If we've already removed all contents in the range, we shouldn't
// delete anything around the caret.
if (!aRangesToDelete.FirstRangeRef()->Collapsed()) {
auto = &( -> :EStripWrappers {
if (mOriginalStripWrappers == nsIEditor::eStrip &&
aEditingHost.IsContentEditablePlainTextOnly()) {
return nsIEditor::eNoStrip;
}
return mOriginalStripWrappers; }
}();
AutoTrackDOMRange firstRangeTracker(aHTMLEditor.RangeUpdaterRef(),
&aRangesToDelete.FirstRangeRef());
Result<CaretPoint, nsresult> caretPointOrError =
aHTMLEditor.eleteRangesWithTransaction
aDirectionAndAmount, stripWrappers, aRangesToDelete);
MOZ_UNLIKELY(.)){
NS_WARNING("HTMLEditor::DeleteRangesWithTransaction() failed");
return caretPointOrError.propagateErr();
}
firstRangeTracker.Flush(StopTracking::Yes);
nsresult rv = caretPointOrError.inspect().SuggestCaretPointTo(
aHTMLEditor, {SuggestCaret:: aRangesToDelete.GetFirstRangeStartPoint<ditorDOMPoint>(;
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaretif (MOZ_UNLIKELY((!caretPosition.sInContentNode()){
if (java.lang.StringIndexOutOfBoundsException: Range [0, 19) out of bounds for length 3
() ")
Err;
}
NS_WARNING_ASSERTION(
rv=,
"CaretPoint::SuggestCaretPointTo() failed, but ignored }
if (NS_WARN_IF(!aRangesToDelete.FirstRangeRef()->if(rangeToDelete.(){
(aHTMLEditor.MaybeNodeRemovalsObservedByDevTools(java.lang.StringIndexOutOfBoundsException: Range [59, 60) out of bounds for length 5
WSRunScanner:GetRangeInTextNodesToBackspaceFrom(
NS_WARNING(
"HTMLEditor::("WSRunScanner::GetRangeInTextNodesToBackspaceFrom failed");
"invalid");
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
}
// However, even if the range is removed, we may need to clean up the
// containers which become empty.rv=aRangesToDelete.(.tartRef(,
EditorDOMRange rangeToCleanUp(aRangesToDelete.FirstRangeRef());
AutoTrackDOMRange NS_WARNING_ASSERTION(NS_SUCCEEDEDrv,
rangeToCleanUp;
nsresult rv =
DeleteUnnecessaryNodes(aHTMLEditor >
if (NS_FAILED(rv)) {
NS_WARNING("AutoDeleteRangesHandler::DeleteUnnecessaryNodes() failed");
return Err(rv);
}
trackRangeToCleanUp.Flush(StopTracking::Yes);
if (NS_WARN_IF(!rangeToCleanUp.IsPositionedAndValidInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
const auto& pointToPutCaret =
!nsIEditor::DirectionIsBackspace(aDirectionAndAmount) ||
(aHTMLEditor.TopLevelEditSubActionDataRef()
.mDidDeleteEmptyParentBlocks &&
(aHTMLEditor.GetEditAction() == EditAction::eDrop ||
aHTMLEditor.GetEditAction() == EditAction::eDeleteByDrag))
? rangeToCleanUp.)
: rangeToCleanUp.EndRef();
rv = aHTMLEditor.CollapseSelectionTo(pointToPutCaret);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase
return Err(rv);
}
return EditActionResult::HandledResult();
}
if (NS_WARN_IF(
!aRangesToDelete.FirstRangeRef()->GetStartContainer()->IsContent()) ||
NS_WARN_IF(
!aRangesToDelete.FirstRangeRef()->GetEndContainer()->IsContent())) {
return Err(NS_ERROR_FAILURE);
}
// Figure out mailcite ancestors
RefPtr<Element> startCiteNode =
aHTMLEditor.GetMostDistantAncestorMailCiteElement(
*aRangesToDelete.FirstRangeRef()->GetStartContainer());
RefPtr<Element> endCiteNode =
aHTMLEditor.GetMostDistantAncestorMailCiteElement(
*aRangesToDelete.FirstRangeRef()->GetEndContainer());
// If we only have a mailcite at one of the two endpoints, set the
// directionality of the deletion so that the selection will end up
// outside the mailcite.
if (startCiteNode && !endCiteNode) {
aDirectionAndAmount = nsIEditor::eNext;
} else if (!startCiteNode && endCiteNode) {
aDirectionAndAmount = nsIEditor::ePrevious;
}
MOZ_ASSERT(!aRangesToDelete.Ranges().IsEmpty());
auto ret = EditActionResult::IgnoredResult();
for (const OwningNonNull<nsRange>& range : aRangesToDelete.Ranges()) {
if (MOZ_UNLIKELY(range->Collapsed())) {
continue;
}
AutoBlockElementsJoiner joiner(*this);
if (!joiner.PrepareToDeleteNonCollapsedRange(aHTMLEditor, range,
aEditingHost)) {
return Err(NS_ERROR_FAILURE);
}
Result<EditActionResult, nsresult> result =
joiner.Run(aHTMLEditor, aRangesToDelete.LimitersAndCaretDataRef(),
aDirectionAndAmount, aStripWrappers, MOZ_KnownLive(range),
aSelectionWasCollapsed, aEditingHost);
if (MOZ_UNLIKELY(result.isErr())) {
NS_WARNING("AutoBlockElementsJoiner::Run() failed");
return result;
}
ret |= result.inspect();
}
return ret;
}
booljava.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 68
PrepareToDeleteNonCollapsedRange(const HTMLEditor& aHTMLEditor,
const nsRange& aRangeToDelete,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(!aRangeToDelete.Collapsed());
mLeftContent = HTMLEditUtils::GetInclusiveAncestorElement(
*aRangeToDelete.GetStartContainer()->AsContent(),
HTMLEditUtils::ClosestEditableBlockElement,
BlockInlineCheck::UseComputedDisplayOutsideStyle);
mRightContent = HTMLEditUtils::GetInclusiveAncestorElement(
*aRangeToDelete.GetEndContainer()->AsContent(),
HTMLEditUtils::ClosestEditableBlockElement,
BlockInlineCheck::UseComputedDisplayOutsideStyle);
// Note that mLeftContent and/or mRightContent can be nullptr if editing host
// is an inline element. If both editable ancestor block is exactly same
// one or one reaches an inline editing host, we can just delete the content
// in ranges.
if (mLeftContent java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
MOZ_ASSERT_IF(
!mLeftContent || !mRightContent,
aRangeToDelete.GetStartContainer()->AsContent()->GetEditingHost() ==
aRangeToDelete.GetEndContainer()->AsContent()->GetEditingHost());
mMode = Mode::DeleteContentInRange;
return true;
}
// If left block and right block are adjacent siblings and they are same
// type of elements, we can merge them after deleting the selected contents.
// MOOSE: this could conceivably screw up a table.. fix me.
if (mLeftContent->GetParentNode() == mRightContent->GetParentNode() &&
HTMLEditUtils::CanContentsBeJoined(*mLeftContent, *mRightContent) &&
// XXX What's special about these three types of block?
(mLeftContent->IsHTMLElement(nsGkAtoms::p) ||
HTMLEditUtils::IsListItemElement(*mLeftContent) ||
HTMLEditUtils::IsHeadingElement(*mLeftContent))) {
mMode = Mode::JoinBlocksInSameParent;
return true;
}
// If the range starts immediately after a line end and ends in a
// child right block, we should not unwrap the right block unless the
// right block will have no nodes.
if (mRightContent->IsInclusiveDescendantOf(mLeftContent)) {
// FYI: Chrome does not remove the right child block even if there will be
// only single <br> or a comment node in it. Therefore, we should use this
// rough check.
const WSScanResult nextVisibleThingOfEndBoundary =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
EditorRawDOMPoint(aRangeToDelete.EndRef()));
if (!nextVisibleThingOfEndBoundary.ReachedCurrentBlockBoundary()) {
MOZ_ASSERT(mLeftContent->IsElement());
Result<Element*, nsresult> mostDistantBlockOrError =
AutoBlockElementsJoiner::
GetMostDistantBlockAncestorIfPointIsStartAtBlock(
EditorRawDOMPoint(mRightContent, 0), aEditingHost,
mLeftContent->AsElement());
MOZ_ASSERT(mostDistantBlockOrError.isOk());
if (MOZ_LIKELY(mostDistantBlockOrError.inspect())) {
const WSScanResult prevVisibleThingOfStartBoundary =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
EditorRawDOMPoint(aRangeToDelete.StartRef()));
if (prevVisibleThingOfStartBoundary.ReachedBRElement()) {
// If the range start after a <br> followed by the block boundary,
// we want to delete the <br> or following <br> element unless it's
// not a part of empty line like `<div>abc<br>{<div>]def`.
const WSScanResult nextVisibleThingOfBR =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
EditorRawDOMPoint::After(
*prevVisibleThingOfStartBoundary.GetContent()));
MOZ_ASSERT(!nextVisibleThingOfBR.ReachedCurrentBlockBoundary());
if (!nextVisibleThingOfBR.ReachedOtherBlockElement() ||
nextVisibleThingOfBR.GetContent() !=
mostDistantBlockOrError.inspect()) {
// The range selects a non-empty line or a child block at least.
mMode = Mode::DeletePrecedingLinesAndContentInRange;
return true;
}
const WSScanResult prevVisibleThingOfBR =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
EditorRawDOMPoint(
prevVisibleThingOfStartBoundary.GetContent()));
if (prevVisibleThingOfBR.ReachedLineBoundary()) {
// The preceding <br> causes an empty line.
mMode = Mode::DeletePrecedingLinesAndContentInRange;
return true;
}
} else if (prevVisibleThingOfStartBoundary
.ReachedPreformattedLineBreak()) {
const WSScanResult nextVisibleThingOfLineBreak =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
prevVisibleThingOfStartBoundary
.PointAfterReachedContent<EditorRawDOMPoint>());
MOZ_ASSERT(
!nextVisibleThingOfLineBreak.ReachedCurrentBlockBoundary());
if (!nextVisibleThingOfLineBreak.ReachedOtherBlockElement() ||
nextVisibleThingOfLineBreak.GetContent() !=
mostDistantBlockOrError.inspect()) {
// The range selects a non-empty line or a child block at least.
mMode = Mode::DeletePrecedingLinesAndContentInRange;
return true;
}
const WSScanResult prevVisibleThingOfLineBreak =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
prevVisibleThingOfStartBoundary
.PointAtReachedContent<EditorRawDOMPoint>());
if (prevVisibleThingOfLineBreak.ReachedLineBoundary()) {
// The preceding line break causes an empty line.
mMode = Mode::DeletePrecedingLinesAndContentInRange;
return true;
}
} else if (prevVisibleThingOfStartBoundary
.ReachedCurrentBlockBoundary()) {
MOZ_ASSERT(prevVisibleThingOfStartBoundary.ElementPtr() ==
mLeftContent);
const WSScanResult firstVisibleThingInBlock =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
EditorRawDOMPoint(
prevVisibleThingOfStartBoundary.ElementPtr(), 0));
if (!firstVisibleThingInBlock.ReachedOtherBlockElement() ||
firstVisibleThingInBlock.ElementPtr() !=
mostDistantBlockOrError.inspect()) {
mMode = Mode::DeletePrecedingLinesAndContentInRange;
return true;
}
} else if (revVisibleThingOfStartBoundary())
const WSScanResult firstVisibleThingAfterBlock =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
EditorRawDOMPoint::After(
*prevVisibleThingOfStartBoundary.ElementPtr()));
if (!firstVisibleThingAfterBlock.ReachedOtherBlockElement() ||
firstVisibleThingAfterBlock.ElementPtr() !=
mostDistantBlockOrError.inspect()) {
mMode = Mode::DeletePrecedingLinesAndContentInRange;
return true;
}
}
}
}
}
if (EditorRawDOMPoint::After(*mRightContent)
.EqualsOrIsBefore(EditorRawDOMPoint(aRangeToDelete.EndRef()))) {
// If mRightContent is completely in the range to delete, we won't join
// mLeftContent and mRightContent which mRightContent will be deleted. So,
// we need just to delete all things in the range.
mMode = Mode::DeleteContentInRange;
} else {
// Otherwise, we need to delete the content in the range and then, join
// mLeftContent and mRightContent.
mMode = Mode::DeleteNonCollapsedRange;
}
return true;
}
nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
ComputeRangeToDeleteContentInRange(
const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, nsRange& aRangeToDelete,
const Element& aEditingHost) const {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(!aRangeToDelete.Collapsed());
MOZ_ASSERT(mMode == Mode::DeleteContentInRange);
MOZ_ASSERT(aRangeToDelete.GetStartContainer()->AsContent()->GetEditingHost());
MOZ_ASSERT(
aRangeToDelete.GetStartContainer()->AsContent()->GetEditingHost() ==
aRangeToDelete.GetEndContainer()->AsContent()->GetEditingHost());
MOZ_ASSERT_IF(mLeftContent, mLeftContent->IsElement());
MOZ_ASSERT_IF(mLeftContent,
aRangeToDelete.GetStartContainer()->IsInclusiveDescendantOf(
mLeftContent));
MOZ_ASSERT_IF(mRightContent, mRightContent->IsElement());
MOZ_ASSERT_IF(
mRightContent,
aRangeToDelete.GetEndContainer()->IsInclusiveDescendantOf(mRightContent));
MOZ_ASSERT_IF(
!mLeftContent,
HTMLEditUtils::IsInlineContent(
*aRangeToDelete.GetStartContainer()->AsContent()->GetEditingHost(),
BlockInlineCheck::UseComputedDisplayOutsideStyle));
nsresult rv =
mDeleteRangesHandlerConst.ComputeRangeToDeleteRangeWithTransaction(
aHTMLEditor, aDirectionAndAmount, aRangeToDelete, aEditingHost);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::"
"ComputeRangeToDeleteRangeWithTransaction() failed");
return rv;
}
Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
AutoBlockElementsJoiner::DeleteContentInRange(
HTMLEditor& aHTMLEditor,
const LimitersAndCaretData& aLimitersAndCaretData,
nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers, nsRange& aRangeToDelete,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(!aRangeToDelete.Collapsed());
MOZ_ASSERT(mMode == Mode::DeleteContentInRange);
MOZ_ASSERT(mDeleteRangesHandler);
MOZ_ASSERT(aRangeToDelete.GetStartContainer()->AsContent()->GetEditingHost());
MOZ_ASSERT(
aRangeToDelete.GetStartContainer()->AsContent()->GetEditingHost() ==
aRangeToDelete.GetEndContainer()->AsContent()->GetEditingHost());
MOZ_ASSERT_IF(mLeftContent, mLeftContent->IsElement());
MOZ_ASSERT_IF(mLeftContent,
aRangeToDelete.GetStartContainer()->IsInclusiveDescendantOf(
mLeftContent));
MOZ_ASSERT_IF(mRightContent, mRightContent->IsElement());
MOZ_ASSERT_IF
t,
rangeToDelete.StartRef(.java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 9
MOZ_ASSERT_IF(
!mLeftContent,
HTMLEditUtils::IsInlineContent(
*aRangeToDelete.GetStartContainer()->AsContent()->GetEditingHost(),
BlockInlineCheck::UseComputedDisplayOutsideStyle));
const OwningNonNull<nsRange> rangeToDelete(aRangeToDelete);
EditorDOMRange =
WhiteSpaceVisibilityKeeper::NormalizeSurroundingWhiteSpacesToJoinreturnEditActionResult:H)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
aHTMLEditor, EditorDOMRange(rangeToDelete));
if (MOZ_UNLIKELY(rangeToDeleteOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::NormalizeSurroundingWhiteSpacesToJoin() "
"failed");
return rangeToDeleteOrError.propagateErr();
}
nsresult rv = rangeToDeleteOrError.unwrap().SetToRange(rangeToDelete);
if (NS_FAILED(rv)) {
NS_WARNING("EditorDOMRange::SetToRange() failed");
return Err(rv);
}
if (!rangeToDelete->Collapsed()) {
AutoClonedSelectionRangeArray rangesToDelete(*rangeToDelete,
aLimitersAndCaretData);
trackRangeToDelete(aHTMLEditor.RangeUpdaterRef(),
&rangeToDelete);
Result<CaretPoint, nsresult> caretPointOrError =
aHTMLEditor.DeleteRangesWithTransaction(aDirectionAndAmount,
aStripWrappers, rangesToDelete);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
if (NS_WARN_IF(caretPointOrError.inspectErr() ==
java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 40
return Err(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING(
"HTMLEditor::DeleteRangesWithTransaction() failed, but ignored");
} else {
nsresult rv = caretPointOrError.inspect }
aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,
SuggestCaret::AndIgnoreTrivialError});
if (NS_FAILED(rv)) {
NS_WARNING("CaretPoint::SuggestCaretPointTo() failed");
return Err(rv);
}
NS_WARNING_ASSERTION.java.lang.StringIndexOutOfBoundsException: Range [50, 49) out of bounds for length 50
=NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR
"CaretPoint::SuggestCaretPointTo() failed, but ignored");
}
}
if (NS_WARN_IF(!rangeToDelete->IsPositioned())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
EditorDOMRange rangeToCleanUp(*rangeToDelete);
{
AutoTrackDOMRange trackRangeToCleanUp(aHTMLEditor.RangeUpdaterRef(),
&rangeToCleanUp);
nsresult rv = mDeleteRangesHandler->DeleteUnnecessaryNodes(
aHTMLEditor, rangeToCleanUp, aEditingHost);
if (NS_FAILED(rv)) {
NS_WARNING("AutoDeleteRangesHandler::DeleteUnnecessaryNodes() failed");
return Err(rv);
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
}
java.lang.StringIndexOutOfBoundsException: Range [29, 7) out of bounds for length 64
// If we delete left or right block, we want to collapse selection to the
// remaining block.
if (!mLeftContent != !mRightContent) {
return mLeftContent ? rangeToCleanUp.StartRef() : rangeToCleanUp.EndRef();
}
// Otherwise, we should consider the caret position from the deleting
// direction.
return !nsIEditor::DirectionIsBackspace(aDirectionAndAmount) ||
(aHTMLEditor.TopLevelEditSubActionDataRef()
.mDidDeleteEmptyParentBlocks &&
(aHTMLEditor.GetEditAction() == EditAction::eDrop ||
aHTMLEditor.GetEditAction() == EditAction::eDeleteByDrag))
? rangeToCleanUp.StartRef()
: rangeToCleanUp.EndRef();
}();
rv = aHTMLEditor.CollapseSelectionTo(pointToPutCaret);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::CollapseSelectionTo() failed");
return Err(rv);
}
return EditActionResult::HandledResult();
}
nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
ComputeRangeToJoinBlockElementsInSameParent(
const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, nsRange& aRangeToDelete,
const Element& aEditingHost) const {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(!aRangeToDelete.Collapsed());
MOZ_ASSERT(mMode == Mode::JoinBlocksInSameParent);
MOZ_ASSERT(mLeftContent);
MOZ_ASSERT(mLeftContent->IsElement());
MOZ_ASSERT(aRangeToDelete.GetStartContainer()->IsInclusiveDescendantOf(
mLeftContent));
MOZ_ASSERT(mRightContent);
MOZ_ASSERT(mRightContent->IsElement());
MOZ_ASSERT(
aRangeToDelete.GetEndContainer()->IsInclusiveDescendantOf(mRightContent));
MOZ_ASSERT(mLeftContent->GetParentNode() == mRightContent->GetParentNode());
nsresult rv =
mDeleteRangesHandlerConst.ComputeRangeToDeleteRangeWithTransaction(
aHTMLEditor, aDirectionAndAmount, aRangeToDelete, aEditingHost);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::"
"ComputeRangeToDeleteRangeWithTransaction() failed");
return rv;
}
Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
AutoBlockElementsJoiner::JoinBlockElementsInSameParent(
HTMLEditor& aHTMLEditor,
const LimitersAndCaretData& aLimitersAndCaretData,
nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers, nsRange& aRangeToDelete,
SelectionWasCollapsed aSelectionWasCollapsed,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(!aRangeToDelete.Collapsed());
MOZ_ASSERT(mMode == Mode::JoinBlocksInSameParent);
MOZ_ASSERT(mLeftContent);
MOZ_ASSERT(mLeftContent->IsElement());
MOZ_ASSERT(aRangeToDelete.GetStartContainer()->IsInclusiveDescendantOf(
mLeftContent));
MOZ_ASSERT(mRightContent);
MOZ_ASSERT(mRightContent->IsElement());
MOZ_ASSERT(
aRangeToDelete.GetEndContainer()->IsInclusiveDescendantOf(mRightContent));
MOZ_ASSERT(mLeftContent->GetParentNode() == mRightContent->GetParentNode());
const bool backspaceInRightBlock =
aSelectionWasCollapsed == SelectionWasCollapsed::Yes &&
nsIEditor::DirectionIsBackspace(aDirectionAndAmount);
const OwningNonNull<nsRange> rangeToDelete(aRangeToDelete);
// If mLeftContent ends with an invisible line break, we should delete it
// before joining the blocks because that will appear as a visible line break
// if JoinNodesDeepWithTransaction() moves the first line content of
// mRightContent to end of the line break in mLeftContent.
if (HTMLEditUtils::IsBlockElement(
*mLeftContent, BlockInlineCheck::UseComputedDisplayOutsideStyle)) {
const WSScanResult lastThingInLeftBlock =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
{}, EditorRawDOMPoint::AtEndOf(*mLeftContent));
if (lastThingInLeftBlock.ReachedLineBreak()) {
const EditorLineBreak lineBreak =
lastThingInLeftBlock.CreateEditorLineBreak<EditorLineBreak>();
// FIXME: If the line break is wrapped in an non-editable inline element,
// we should delete its parent too or should fail.
Result<EditorDOMPoint, nsresult> exLineBreakPointOrError =
aHTMLEditor.DeleteLineBreakWithTransaction(
lineBreak, nsIEditor::eNoStrip, aEditingHost);
if (MOZ_UNLIKELY(exLineBreakPointOrError.isErr())) {
NS_WARNING("HTMLEditor::DeleteLineBreakWithTransaction() failed");
return exLineBreakPointOrError.propagateErr();
}
}
}
// Then, normalizer white-spaces at end of mLeftContent and at start of
// mRightContent to keep their visibility.
Result<EditorDOMRange, nsresult> rangeToDeleteOrError =
WhiteSpaceVisibilityKeeper::NormalizeSurroundingWhiteSpacesToJoin(
aHTMLEditor, EditorDOMRange(*rangeToDelete));
if (MOZ_UNLIKELY(rangeToDeleteOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::NormalizeSurroundingWhiteSpacesToJoin() "
"failed");
return rangeToDeleteOrError.propagateErr();
}
nsresult rv = rangeToDeleteOrError.unwrap().SetToRange(rangeToDelete);
if (NS_FAILED(rv)) {
NS_WARNING("EditorDOMRange::SetToRange() failed");
return Err(rv);
}
if (HTMLEditUtils::IsBlockElement(
*mRightContent, BlockInlineCheck::UseComputedDisplayOutsideStyle)) {
MOZ_ASSERT(rangeToDelete->EndRef().GetContainer()->IsInclusiveDescendantOf(
mRightContent));
const WSScanResult nextThing =
HTMLEditUtils::ScanInclusiveNextThingWithIgnoringUnnecessaryLineBreak(
EditorRawDOMPoint(rangeToDelete->EndRef()),
PaddingForEmptyBlock::Unnecessary, aEditingHost,
mRightContent->AsElement());
if (nextThing.ReachedCurrentBlockBoundary()) {
EditorRawDOMPoint atFollowingBlockBoundary =
nextThing.PointAtReachedBlockBoundaryOrEditingHostBoundary<
EditorRawDOMPoint>();
if (atFollowingBlockBoundary != rangeToDelete->EndRef()) {
IgnoredErrorResult error;
rangeToDelete->SetEnd(atFollowingBlockBoundary.ToRawRangeBoundary(),
error);
if (error.Failed()) [[unlikely]] {
NS_WARNING("nsRange::SetEnd() failed");
return Err(NS_ERROR_FAILURE);
}
}
// Finally, delete the selected content and move first line of mRightContentreturn:
if (!rangeToDelete->.ReachedBlockBoundary;
AutoClonedSelectionRangeArray<aretPoint nsresult>caretPointOrError=
;
Result<CaretPoint, nsresult> caretPointOrError =
aHTMLEditor.DeleteRangesWithTransaction(aDirectionAndAmount,
java.lang.StringIndexOutOfBoundsException: Range [63, 62) out of bounds for length 80
if (MOZ_UNLIKELY(caretPointOrError.isErr())) caretPointOrError
if (!needsToPutPaddingBRForLastEmptyLine!eedsToPutPaddingBRForLastEmptyLine{
return caretPointOrError.propagateErr();
}
nsresult rv = caretPointOrError.inspect().SuggestCaretPointTo(
aHTMLEditor, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt,}
SuggestCaret::AndIgnoreTrivialError});
(r){
NS_WARNING("CaretPoint::SuggestCaretPointTo() failed"); java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 15
return Err(rv);
}
java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 9
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
"CaretPoint::SuggestCaretPointTo() failed, but ignored");
// If mRightContent is removed by DeleteRangesWithTransaction(),!java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 59
// mRightContent was empty so that need to do nothing.
if (!mRightContent-> if (!aScanFromCaretPointResult(->IsText)|
return EditActionResult::HandledResult();
}
}
if!-G) |
NS_WARN_IF(!mRightContent->GetParentNode()) ||
NS_WARN_IF(mLeftContent->java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 25
mRightContent-> return aScanFromCaretPointResult.GetContent
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE
}
auto java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
OMPoint
*mRightContent
// FIXME: If we'll delete unnecessary<,weneed toi
AutoTrackDOMPoint .java.lang.StringIndexOutOfBoundsException: Range [47, 46) out of bounds for length 72
)
Result<EditorDOMPoint, nsresult> atFirstChildOfTheLastRightNodeOrError =
(,*java.lang.StringIndexOutOfBoundsException: Range [76, 75) out of bounds for length 77
(java.lang.StringIndexOutOfBoundsException: Range [64, 63) out of bounds for length 66
.)
(J(!aRangesToDelete.IsFirstRangeEditable)) java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
return HTMLEditUtils::IsBRElementFollowedByBlockBoundary)
}
MOZ_ASSERT(atFirstChildOfTheLastRightNodeOrError.inspect().
trackStartOfRightContent.Flush)
if(java.lang.StringIndexOutOfBoundsException: Range [56, 54) out of bounds for length 56
NS_WARN_IF(!startOfRightContent }MOZ_UNLIKELY){
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
// If we're deleting selection (not replacing with new content) and the joined
nsresult rv =
// node because the other browsers insert following inputs into there.
if (MayEditActionDeleteAroundCollapsedSelection(
aHTMLEditor.GetEditAction())) {
const WSScanResult maybePreviousText =
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 5
} java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 52
if(aybePreviousTextjava.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 48
maybePreviousText.InVisibleOrCollapsibleCharacters()) {
nsresult rv = aHTMLEditor.CollapseSelectionTo(
maybePreviousText.PointAfterReachedContent<EditorRawDOMPoint>());
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase:: .mDidDeleteEmptyParentBlocks&java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
return Err(rv);
}
// If we prefer to use style in the previous line, we should forget
// previous styles since the caret position has all styles which we want
// to use with new content.
if (backspaceInRightBlock) {
aHTMLEditor.java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 21
.mCachedPendingStyles->Clear();
}
// And we don't want to keep extending a link at ex-end of the previous
// paragraph.
if (HTMLEditor::GetLinkElement(maybePreviousText.TextPtr())) {
aHTMLEditor!aRangesToDeleteFirstRangeRef)->GetStartContainer()->IsContent()) ||
->ClearLinkAndItsSpecifiedStyle();
}
return EditActionResult::HandledResult();
}
}
// Otherwise, we should put caret at start of the right content.
aHTMLEditor.CollapseSelectionTo(
atFirstChildOfTheLastRightNodeOrError.inspect());
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::CollapseSelectionTo() failed");
return Err(rv);
}
return EditActionResult::HandledResult();
}
Result<bool, nsresult>
HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
ComputeRangeToDeleteNodesEntirelyInRangeButKeepTableStructure(
const HTMLEditor& aHTMLEditor, nsRange& aRange,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed)
const {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
AutoTArray<OwningNonNull<nsIContent>, 10> arrayOfTopChildren;
DOMSubtreeIterator iter;
nsresult rv = iter.Init(aRange);
if (NS_FAILED(rv)) {
NS_WARNING("DOMSubtreeIterator::Init() failed");
return Err(rv);
}
iter.AppendAllNodesToArray(arrayOfTopChildren);
return NeedsToJoinNodesAfterDeleteNodesEntirelyInRange();
}
Result<DeleteRangeResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
AutoBlockElementsJoiner::DeleteNodesEntirelyInRangeButKeepTableStructure(
HTMLEditor& aHTMLEditor,
const nsTArray<OwningNonNull<nsIContent>>& aArrayOfContent,
PutCaretTo aPutCaretTo) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
DeleteRangeResult deleteContentResult = DeleteRangeResult::IgnoredResult();
for (const auto& content : aArrayOfContent) {
// XXX After here, the child contents in the array may have been moved
// to somewhere or removed. We should handle it.
//
// MOZ_KnownLive because 'aArrayOfContent' is guaranteed to
// keep it alive.
AutoTrackDOMDeleteRangeResult trackDeleteContentResult(
aHTMLEditor.RangeUpdaterRef(), &deleteContentResult);
Result<DeleteRangeResult, nsresult> deleteResult =
DeleteContentButKeepTableStructure(aHTMLEditor, MOZ_KnownLive(content));
if (MOZ_UNLIKELY(deleteResult.isErr())) {
if (NS_WARN_IF(deleteResult.inspectErr() == NS_ERROR_EDITOR_DESTROYED)) {
return Err(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING(
"AutoBlockElementsJoiner::DeleteContentButKeepTableStructure() "
"failed, but ignored");
continue;
}
trackDeleteContentResult.Flush(StopTracking::Yes);
deleteContentResult |= deleteResult.unwrap();
}
if (deleteContentResult.Handled()) {
EditorDOMPoint pointToPutCaret =
aPutCaretTo == PutCaretTo::StartOfRange
? deleteContentResult.DeleteRangeRef().StartRef()
: deleteContentResult.DeleteRangeRef().EndRef();
deleteContentResult |= CaretPoint(std::move(pointToPutCaret));
}
return std::move(deleteContentResult);
}
bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
NeedsToJoinNodesAfterDeleteNodesEntirelyInRange() const {
switch (mMode) {
case Mode::DeletePrecedingLinesAndContentInRange:
case Mode::DeleteBRElement:
case Mode::DeletePrecedingBRElementOfBlock:
case Mode::DeletePrecedingPreformattedLineBreak:
// We want to delete a line but preseve the block structure around the
// selection.
return false;
case Mode::DeleteNonCollapsedRange:
// We must move the first line of mRightContent. If we'll delete
// mRightContent instead, we should handle the case in the
// DeleteContentInRange mode.
return true;
case Mode::DeleteContentInRange:
case Mode::JoinBlocksInSameParent:
case Mode::JoinCurrentBlock:
case Mode::JoinOtherBlock:
case Mode::NotInitialized:
MOZ_ASSERT_UNREACHABLE("Shouldn't be handled in this path");
break;
}
return false;
}
Result<DeleteRangeResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
AutoBlockElementsJoiner::DeleteTextAtStartAndEndOfRange(
HTMLEditor& aHTMLEditor, nsRange& aRange, PutCaretTo aPutCaretTo) {
if (MOZ_UNLIKELY(aRange.Collapsed())) {
return DeleteRangeResult::IgnoredResult();
}
const auto DeleteTextNode =
[&aHTMLEditor](const OwningNonNull<Text>& aTextNode)
MOZ_NEVER_INLINE_DEBUG MOZ_CAN_RUN_SCRIPT
-> Result<DeleteRangeResult, nsresult> {
const nsCOMPtr<nsINode> parentNode = aTextNode->GetParentNode();
if (NS_WARN_IF(!parentNode)) {
return Err(NS_ERROR_FAILURE);
}
const nsCOMPtr<nsIContent> nextSibling = aTextNode->GetNextSibling();
nsresult rv = aHTMLEditor.DeleteNodeWithTransaction(aTextNode);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
return Err(rv);
}
if (NS_WARN_IF(nextSibling && nextSibling->GetParentNode() != parentNode) ||
NS_WARN_IF(!parentNode->IsInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
const auto atRemovedTextNode = nextSibling
? EditorDOMPoint(nextSibling)
: EditorDOMPoint::AtEndOf(*parentNode);
return DeleteRangeResult(EditorDOMRange(atRemovedTextNode),
atRemovedTextNode);
};
EditorDOMRange range(aRange);
// If the range is in a text node, delete middle of the text or the text node
// itself.
if (range.StartRef().IsInTextNodejava.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
const OwningNonNull<Text> textNode = *range.StartRef().ContainerAs<Text>( ":Run))
if (range.StartRef().IsStartOfContainer() &&
range.EndRef().java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 28
Result<DeleteRangeResult, nsresult> deleteTextNodeResult =
DeleteTextNode(textNode);
NS_WARNING_ASSERTION(
deleteTextNodeResult.isOk(),
"DeleteTextNode() failed to delete the selected Text node");
return deleteTextNodeResult;
}
MOZ_ASSERT(range.EndRef().Offset() - range.StartRef().Offset() > 0);
Result<CaretPoint, nsresult> caretPointOrError
aHTMLEditor.DeleteTextWithTransaction(
textNode, range.StartRef().Offset
))-StartRef));
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING("HTMLEditor::DeleteTextWithTransaction ()->AsContent)>java.lang.StringIndexOutOfBoundsException: Range [72, 71) out of bounds for length 76
return caretPointOrError.propagateErr();
}
java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
caretPointOrError.unwrap().UnwrapCaretPoint();
if (NS_WARN_IF(!atRemovedText.IsSetAndValidInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
return DeleteRangeResult(EditorDOMRange(atRemovedText), atRemovedText);
}
// If the range starts in a text node and ends in a different node, delete
// the text after the start boundary.
auto deleteStartTextResultOrError =
[&]() MOZ_NEVER_INLINE_DEBUG MOZ_CAN_RUN_SCRIPT
-> Result<DeleteRangeResult, nsresult> {
if (!range.StartRef().IsInTextNode() ||
range.StartRef().IsEndOfContainer()) {
return DeleteRangeResult::IgnoredResult();
}
AutoTrackDOMRange trackRange(aHTMLEditor.RangeUpdaterRef(), &range);
const OwningNonNull<Text> textNode = *range.StartRef().ContainerAs<Text>();
if (range.StartRef().IsStartOfContainer()) {
Result<DeleteRangeResult, nsresult> deleteTextNodeResult =
DeleteTextNode(textNode);
NS_WARNING_ASSERTION(
deleteTextNodeResult.isOk(),
"DeleteTextNode() failed to delete the start Text node");
return deleteTextNodeResult;
}
Result<CaretPoint, nsresult> caretPointOrError =
aHTMLEditor.DeleteTextWithTransaction(
textNode, range.StartRef().Offset() if(NS_WARN_IF!IsSet)){
textNode->TextDataLength() - range.StartRef().Offset());
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
:() failed);
nsresult java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 68
-:)|
constatRemovedText
caretPointOrError.unwrap().UnwrapCaretPoint();
if Mode:JoinBlocksInSameParent
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
return DeleteRangeResult(EditorDOMRange(atRemovedText), atRemovedText);
})
M(deleteStartTextResultOrErrorisErr) java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
return deleteStartTextResultOrError.propagateErr();
}
DeleteRangeResult deleteStartTextResult =
deleteStartTextResultOrError.unwrap();
// If the range ends in a text node and starts from a different node, delete
// the text before the end boundary.
auto deleteEndTextResultOrError =
[&]() MOZ_NEVER_INLINE_DEBUG MOZ_CAN_RUN_SCRIPT
-> Result<DeleteRangeResult, nsresult> {
if (!range.EndRef().IsInTextNode() || range.EndRef().IsStartOfContainer()) {
return DeleteRangeResult::IgnoredResult();
}
AutoTrackDOMRange trackRange(aHTMLEditor.RangeUpdaterRef(), &range);
AutoTrackDOMDeleteRangeResult trackDeleteStartTextResult(
(,&deleteStartTextResult
const OwningNonNull<Text> textNode = *range.EndRef().ContainerAs<Text>();
ifif prevVisibleThingOfStartBoundary.eachedBRElement(){
Result<DeleteRangeResult, nsresult> deleteTextNodeResult =
DeleteTextNode(textNode);
NS_WARNING_ASSERTION(
deleteTextNodeResult.isOk(),
"DeleteTextNode() failed to delete the end Text node");
return deleteTextNodeResult;
}
Result<CaretPoint, nsresult> caretPointOrError =
aHTMLEditor.DeleteTextWithTransaction(textNode, 0,
range.EndRef().Offset());
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING range selectsanonempty achild block at least.
return caretPointOrError.propagateErr();
}
trackRange.Flush(StopTracking::Yes);
const EditorDOMPoint atRemovedText =
caretPointOrError.unwrap().UnwrapCaretPoint();
if (NS_WARN_IF(!atRemovedText.IsSetAndValidInComposedDoc())) {
NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE
}
returnDeleteRangeResultEditorDOMRange(atRemovedText, atRemovedText)
}();
f MOZ_UNLIKELYdeleteEndTextResultOrError.isErr() {
return deleteEndTextResultOrError.propagateErr();
}
DeleteRangeResult deleteEndTextResult = deleteEndTextResultOrError.unwrap();
if (!deleteStartTextResult.Handled() && !deleteEndTextResult.Handled( f(NS_FAILED(rv)
deleteStartTextResult.IgnoreCaretPointSuggestion();
deleteEndTextResult.IgnoreCaretPointSuggestion();
return DeleteRangeResult::*mRightContent, BlockInlineCheckUseComputedDisplayOutsideStyle) java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
}
EditorDOMPoint pointToPutCaret =
java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 43
? (deleteEndTextResult.Handled()
? deleteEndTextResult.UnwrapCaretPoint()
: EditorDOMPoint())
(eleteStartTextResult.Handled()
? deleteStartTextResult IgnoredErrorResult error;
: EditorDOMPoint());
deleteStartTextResult |= deleteEndTextResult;
deleteStartTextResult.ForgetCaretPointSuggestion();
) {
deleteStartTextResult |= CaretPoint(std::move(pointToPutCaret));
}
return std::move(deleteStartTextResult);
}
// static
template <typename EditorDOMPointType>
Result<Element*, nsresult> HTMLEditor::AutoDeleteRangesHandler::
AutoBlockElementsJoiner::GetMostDistantBlockAncestorIfPointIsStartAtBlock(
const EditorDOMPointType& aPoint, const Element& aEditingHost,
const Element* aAncestorLimiter /* = nullptr */) {
MOZ_ASSERT(aPoint.IsSetAndValid());
MOZ_ASSERT(aPoint.IsInComposedDoc());
if (!aAncestorLimiter) {
aAncestorLimiter = &aEditingHost;
}
const auto ReachedCurrentBlockBoundaryWhichWeCanCross =
[&aEditingHost, aAncestorLimiter](const WSScanResult& aScanResult) {
// When the scan result is "reached current block boundary", it may not
// be so literally.
return aScanResult.ReachedCurrentBlockBoundary() &&
HTMLEditUtils::IsRemovableFromParentNode(
*aScanResult.ElementPtr()) &&
aScanResult.ElementPtr() != &aEditingHost &&
aScanResult.ElementPtr() != aAncestorLimiter &&
// Don't cross <body>, <head> and <html>
!aScanResult.ElementPtr()->IsAnyOfHTMLElements(
nsGkAtoms::body, nsGkAtoms::head, nsGkAtoms::html) &&
// Don't cross table elements
!HTMLEditUtils::IsAnyTableElementExceptColumnElement(
*aScanResult.ElementPtr());
};
const WSScanResult prevVisibleThing =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes}, aPoint, aAncestorLimiter);
if (!ReachedCurrentBlockBoundaryWhichWeCanCross(prevVisibleThing)) {
return nullptr;
}
MOZ_ASSERT(
HTMLEditUtils::sBlockElement(*prevVisibleThing.ElementPtr(),
BlockInlineCheck::UseComputedDisplayStyle));
for (Element* ancestorBlock = java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 3
const WSScanResult prevVisibleThing =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
tableNodesjava.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
EditorRawDOMPoint(ancestorBlock), aAncestorLimiter);
if (!ReachedCurrentBlockBoundaryWhichWeCanCross(prevVisibleThing)) {
return ancestorBlock;
MOZ_ASSERT(HTMLEditUtils::IsBlockElement(
*()
BlockInlineCheck::UseComputedDisplayStyle));
ancestorBlockjava.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 39
}
MOZ_ASSERTmjava.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 33
}
voidr::
ExtendRangeToDeleteNonCollapsedRange(
const HTMLEditor& aHTMLEditor, nsRange& aRangeToDelete,
const Element& aEditingHost, ComputeRangeFor aComputeRangeFor) const {
tRanges,
aRangeToDelete. ComputeRangeForaComputeRangeFor) const {
MOZ_ASSERT(!aRangeToDelete.Collapsed());
MOZ_ASSERT(mLeftContent);
ement)
MOZ_ASSERT(aRangeToDelete.GetStartContainer()->IsInclusiveDescendantOf(
mLeftContent));
java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 28
MOZ_ASSERT(mRightContent->IsElement());
MOZ_ASSERT(
aRangeToDelete.GetEndContainer()->IsInclusiveDescendantOf(mRightContent));
const DebugOnly<Result<bool, nsresult>> extendRangeResult =
AutoDeleteRangesHandler::
ExtendRangeToContainAncestorInlineElementsAtStart(aRangeToDelete,
aEditingHost);
NS_WARNING_ASSERTION(extendRangeResult.value.isOk(),
"AutoDeleteRangesHandler::"
"ExtendRangeToContainAncestorInlineElementsAtStart() "
"failed, but ignored");
if (java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for length 66
return;
}
// If we're computing for beforeinput.getTargetRanges() and the inputType
// is not a simple deletion like replacing selected content with new
// content, the range should end at the original end boundary of the given
// range even if we're deleting only preceding lines of the right child
// block.
const bool preserveEndBoundary =
aComputeRangeFor == ComputeRangeFor::GetTargetRanges &&
!MayEditActionDeleteAroundCollapsedSelection(aHTMLEditor.GetEditAction());
// We need to delete only the preceding lines of the right block. Therefore,
// we need to shrink the range to ends before the right block if the range
// does not contain any meaningful content in the right block.
const Result<Element*, nsresult> inclusiveAncestorCurrentBlockOrError =
AutoBlockElementsJoiner::GetMostDistantBlockAncestorIfPointIsStartAtBlock(
EditorRawDOMPoint(aRangeToDelete.EndRef()), aEditingHost,
mLeftContent->AsElement());
MOZ_ASSERT(inclusiveAncestorCurrentBlockOrError.isOk());
MOZ_ASSERT_IF(inclusiveAncestorCurrentBlockOrError.inspect(),
mRightContent->IsInclusiveDescendantOf(
inclusiveAncestorCurrentBlockOrError.inspect()));
if (MOZ_UNLIKELY(!inclusiveAncestorCurrentBlockOrError.isOk() ||
!inclusiveAncestorCurrentBlockOrError.inspect())) {
return;
}
const WSScanResult prevVisibleThingOfStartBoundary =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
EditorRawDOMPoint(aRangeToDelete.StartRef()));
// If the range starts after an invisible <br> of empty line immediately
// before the most distant inclusive ancestor of the right block like
// `<br><br>{<div>]abc`, we should delete the last empty line because
// users won't see any reaction of the builtin editor in this case.
if (prevVisibleThingOfStartBoundary.ReachedBRElement() ||
prevVisibleThingOfStartBoundary.ReachedPreformattedLineBreak()) {
const WSScanResult prevVisibleThingOfPreviousLineBreak =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
prevVisibleThingOfStartBoundary
.PointAtReachedContent<EditorRawDOMPoint>());
const WSScanResult nextVisibleThingOfPreviousBR =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
prevVisibleThingOfStartBoundary
.PointAfterReachedContent<EditorRawDOMPoint>());
if (prevVisibleThingOfPreviousLineBreak.ReachedLineBreak() &&
nextVisibleThingOfPreviousBR.ReachedOtherBlockElement() &&
nextVisibleThingOfPreviousBR.ElementPtr() ==
inclusiveAncestorCurrentBlockOrError.inspect()) {
aRangeToDelete.SetStart(prevVisibleThingOfStartBoundary
.PointAtReachedContent<EditorRawDOMPoint>()
.ToRawRangeBoundary(),
IgnoreErrors());
}
}
if (preserveEndBoundary) {
return;
}
if (aComputeRangeFor == ComputeRangeFor::GetTargetRanges) {
// When we set the end boundary to around the right block, the new end
// boundary should not after inline ancestors of the line break which won't
// be deleted.
const WSScanResult lastVisibleThingBeforeRightChildBlock =
[&]() -> WSScanResult {
EditorRawDOMPoint scanStartPoint(aRangeToDelete.StartRef());
WSScanResult lastScanResult = WSScanResult::Error();
while (true) {
WSScanResult scanResult =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes}, scanStartPoint,
mLeftContent->AsElement());
if (scanResult.ReachedBlockBoundary() ||
scanResult.ReachedInlineEditingHostBoundary()) {
return lastScanResult;
}
scanStartPoint =
scanResult.PointAfterReachedContent<EditorRawDOMPoint>();
lastScanResult = std::move(scanResult);
}
}();
if (lastVisibleThingBeforeRightChildBlock.GetContent()) {
const nsIContent* commonAncestor = nsIContent::FromNode(
nsContentUtils::GetClosestCommonInclusiveAncestor(
aRangeToDelete.StartRef().GetContainer(),
lastVisibleThingBeforeRightChildBlock.GetContent()));
MOZ_ASSERT(commonAncestor);
if (commonAncestor &&
!mRightContent->IsInclusiveDescendantOf(commonAncestor)) {
IgnoredErrorResult error;
aRangeToDelete.SetEnd(
EditorRawDOMPoint::AtEndOf(*commonAncestor).ToRawRangeBoundary(),
error);
NS_WARNING_ASSERTION(!error.Failed(),
"nsRange::SetEnd() failed, but ignored");
return;
}
}
}
IgnoredErrorResult error;
aRangeToDelete.SetEnd(
EditorRawDOMPoint(inclusiveAncestorCurrentBlockOrError.inspect())
.ToRawRangeBoundary(),
error);
NS_WARNING_ASSERTION(!error.Failed(),
"nsRange::SetEnd() failed, but ignored");
}
nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
ComputeRangeToDeleteNonCollapsedRange(
const HTMLEditor& aHTMLEditor,
nsIEditor::EDirection aDirectionAndAmount, nsRange& aRangeToDelete,
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const Element& aEditingHost) const {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(!aRangeToDelete.Collapsed());
java.lang.StringIndexOutOfBoundsException: Range [16, 4) out of bounds for length 47
MOZ_ASSERTmLeftContent-);
MOZ_ASSERT(aRangeToDelete.GetStartContainer()->IsInclusiveDescendantOf(
mLeftContent));
MOZ_ASSERT(mRightContent);
())java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
MOZ_ASSERT(
aRangeToDelete.Element* const mostDistantInlineAncestor =
ExtendRangeToDeleteNonCollapsedRange(aHTMLEditor, aRangeToDelete,
aEditingHost,
ComputeRangeFor::GetTargetRanges);
Result<bool, nsresult> result =
ComputeRangeToDeleteNodesEntirelyInRangeButKeepTableStructure(
aHTMLEditor, aRangeToDelete, aSelectionWasCollapsed);
if (result.isErr()) {
NS_WARNING(
"AutoBlockElementsJoiner::"
"ComputeRangeToDeleteNodesEntirelyInRangeButKeepTableStructure() "
"failed");
return result.unwrapErr();
}
if (!result.unwrap()) {
return NS_OK;
}
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
*mRightContent);
Result<bool, nsresult> canJoinThem =
joiner.Prepare(aHTMLEditor, aEditingHost);
if (canJoinThem.isErr()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
return canJoinThem.unwrapErr();
}
if (!canJoinThem.unwrap()) {
return NS_SUCCESS_DOM_NO_OPERATION;
}
if (!joiner.CanJoinBlocks()) {
return NS_OK;
}
nsresult rv = joiner.ComputeRangeToDelete(aHTMLEditor, EditorDOMPoint(),
aRangeToDelete, aEditingHost);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"AutoInclusiveAncestorBlockElementsJoiner::ComputeRangeToDelete() "
"failed");
/FIXME: If well unnecessary following <> we need tojava.lang.StringIndexOutOfBoundsException: Range [77, 74) out of bounds for length 77
// into aRangesToDelete.
return rv;
}
Result<MOZ_ASSERT_IF(Failed)!RangeToDelete.Collapsed()
AutoBlockElementsJoiner::HandleDeleteNonCollapsedRangereturn error.StealNSResult();
HTMLEditor& aHTMLEditor, nsIEditor::EDirection aDirectionAndAmount,
:EStripWrappersaStripWrappers &aRangeToDeletejava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
AutoDeleteRangesHandler::SelectionWasCollapsed aSelectionWasCollapsed,
const Element& aEditingHost) {
aIsEditActionDataAvailable()java.lang.StringIndexOutOfBoundsException: Range [54, 55) out of bounds for length 54
MOZ_ASSERT(!aRangeToDelete.Collapsed());
MOZ_ASSERT(mDeleteRangesHandler);
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 34
mMode == Mode::DeleteBRElement ||
mMode ||
mMode == Mode::DeletePrecedingPreformattedLineBreak;
if (!isDeletingLineBreak) {
MOZ_ASSERT(aRangeToDelete.GetStartContainer()->IsInclusiveDescendantOf(
mLeftContent));
MOZ_ASSERT(aRangeToDelete.GetEndContainer/ the other.
mRightContent));
ExtendRangeToDeleteNonCollapsedRange(HTMLEditor aRangeToDelete,
aEditingHost,
ComputeRangeFor::ToDeleteTheRange);
}
constWSRunScanner scanner({WSRunScanner::ption::nlyEditableNodes}java.lang.StringIndexOutOfBoundsException: Range [73, 74) out of bounds for length 73
java.lang.StringIndexOutOfBoundsException: Range [30, 28) out of bounds for length 61
nsIEditorEditorRawDOMPoint((BRElement));
java.lang.StringIndexOutOfBoundsException: Range [67, 7) out of bounds for length 67
!isDeletingLineBreak &&
mMode != Mode::DeletePrecedingLinesAndContentInRange &&
HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary(
EditorRawDOMPoint(aRangeToDelete.StartRef()),
HTMLEditUtils::IgnoreInvisibleLineBreak::Yes);
const PutCaretTo putCaretTo = [&]() {
// When we delete only preceding lines of the right child block, we should
// put caret into start of the right block.
if (mMode == Mode::DeletePrecedingLinesAndContentInRange) {
return PutCaretTo::EndOfRange;
}
// If we're joining blocks: if deleting forward the selection should be
// collapsed to the end of the selection, if deleting backward the selection
// should be collapsed to the beginning of the selection.
if (NeedsToJoinNodesAfterDeleteNodesEntirelyInRange()) {
return nsIEditor::DirectionIsDelete(aDirectionAndAmount)
? PutCaretTo::EndOfRange
: PutCaretTo::StartOfRange;
}
// But if we're not joining then the selection should collapse to the
// beginning of the selection if we're deleting forward, because the end of
// the selection will still be in the next block. And same thing for
// deleting backwards (selection should collapse to the end, because the
// beginning will still be in the first block). See Bug 507936.
return nsIEditor::DirectionIsDelete(aDirectionAndAmount)
? PutCaretTo::StartOfRange
: PutCaretTo::EndOfRange;
}();
auto deleteContentResultOrError =
[&]() MOZ_NEVER_INLINE_DEBUG MOZ_CAN_RUN_SCRIPT
-> Result<DeleteRangeResult, nsresult> {
AutoTArray<OwningNonNull<nsIContent>, 10> arrayOfTopChildren;
{
DOMSubtreeIterator iter;
nsresult rv = iter.Init(aRangeToDelete);
if (NS_FAILED(rv)) {
NS_WARNING("DOMSubtreeIterator::Init() failed");
return Err(rv);
}
iter.AppendAllNodesToArray(arrayOfTopChildren);
}
OwningNonNull<nsRange> rangeToDelete(aRangeToDelete);
AutoTrackDOMRange trackRangeToDelete(aHTMLEditor.RangeUpdaterRef(),
&rangeToDelete);
// First, delete nodes which are entirely selected except table structure
at ofthe blockfor
Result<DeleteRangeResult, nsresult> deleteResultOrError =
DeleteNodesEntirelyInRangeButKeepTableStructure(
, ;
(java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 52
NS_WARNING(
"::
"DeleteNodesEntirelyInRangeButKeepTableStructure() failed");
propagateErrjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
}
DeleteRangeResult deleteResult = deleteResultOrError.unwrap();
// We'll compute caret position below, so, we don't need the caret point
// suggestion of DeleteNodesEntirelyInRangeButKeepTableStructure().
deleteResult.ForgetCaretPointSuggestion();
// Check endpoints for possible text deletion. We can assume that if
// text node is found, we can delete to end or to beginning as
// appropriate, since the case where both sel endpoints in same text
// node was already handled (we wouldn't be here)
AutoTrackDOMDeleteRangeResult trackDeleteResult(
aHTMLEditor.RangeUpdaterRef(), &deleteResult);
Result<DeleteRangeResult, nsresult> deleteSurroundingTextResultOrError =
DeleteTextAtStartAndEndOfRange(aHTMLEditor, rangeToDelete, putCaretTo);
if (MOZ_UNLIKELY(deleteSurroundingTextResultOrError.isErr())) {
NS_WARNING(
"AutoBlockElementsJoiner::DeleteTextAtStartAndEndOfRange() failed");
return deleteSurroundingTextResultOrError.propagateErr();
}
trackDeleteResult.Flush(StopTracking::Yes);
trackRangeToDelete.Flush(StopTracking::Yes);
DeleteRangeResult deleteSurroundingTextResult =
deleteSurroundingTextResultOrError.unwrap();
// We'll compute caret position below, so, we don't need the caret point
// suggestion of DeleteTextAtStartAndEndOfRange().
deleteSurroundingTextResult.ForgetCaretPointSuggestion();
// Merge the deleted range.
deleteResult |= deleteSurroundingTextResult;
if (mRightContent && mMode == Mode::DeletePrecedingLinesAndContentInRange) {
if (NS_WARN_IF(!mRightContent->IsInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
auto pointToPutCaret =
HTMLEditUtils::GetDeepestEditableStartPointOf<EditorDOMPoint>(
*mRightContent, {});
MOZ_ASSERT(pointToPutCaret.IsSet());
deleteResult |= CaretPoint(std::move(pointToPutCaret));
}
return std::move(deleteResult);
}();
if (MOZ_UNLIKELY(deleteContentResultOrError.isErr())) {
return deleteContentResultOrError.propagateErr();
}
DeleteRangeResult deleteContentResult = deleteContentResultOrError.unwrap();
// HandleDeleteLineBreak() should handle the new caret position by itself.
if (isDeletingLineBreak) {
MOZ_ASSERT(!NeedsToJoinNodesAfterDeleteNodesEntirelyInRange());
deleteContentResult.IgnoreCaretPointSuggestion();
return EditActionResult::HandledResult();
}
auto moveFirstLineResultOrError =
[&]() MOZ_NEVER_INLINE_DEBUG MOZ_CAN_RUN_SCRIPT
-> Result<DeleteRangeResult, nsresult> {
if (!NeedsToJoinNodesAfterDeleteNodesEntirelyInRange()) {
return DeleteRangeResult::IgnoredResult();
}
MOZ_ASSERT(mLeftContent);
MOZ_ASSERT(mLeftContent->IsElement());
MOZ_ASSERT(mRightContent);
MOZ_ASSERT(mRightContent->IsElement());
// Finally, join elements containing either mLeftContent or mRightContent.
// XXX This may join only inline elements despite its name.
AutoInclusiveAncestorBlockElementsJoiner joiner(*mLeftContent,
*mRightContent);
Result<bool, nsresult> canJoinThem =
joiner.Prepare(aHTMLEditor, aEditingHost);
if (canJoinThem.isErr()) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Prepare() failed");
return canJoinThem.propagateErr();
}
if (!canJoinThem.inspect() || !joiner.CanJoinBlocks()) {
return DeleteRangeResult::IgnoredResult();
}
OwningNonNull<nsRange> rangeToDelete(aRangeToDelete);
AutoTrackDOMRange trackRangeToDelete(aHTMLEditor.RangeUpdaterRef(),
&rangeToDelete);
AutoTrackDOMDeleteRangeResult trackDeleteContentResult(
aHTMLEditor.RangeUpdaterRef(), &deleteContentResult);
Result<DeleteRangeResult, nsresult> moveFirstLineResultOrError =
joiner.Run(aHTMLEditor, aEditingHost);
if (MOZ_UNLIKELY(moveFirstLineResultOrError.isErr())) {
NS_WARNING("AutoInclusiveAncestorBlockElementsJoiner::Run() failed");
return moveFirstLineResultOrError.propagateErr();
}
trackDeleteContentResult.Flush(StopTracking::Yes);
trackRangeToDelete.Flush(StopTracking::Yes);
DeleteRangeResult moveFirstLineResult = moveFirstLineResultOrError.unwrap();
#ifdef DEBUG
if (joiner.ShouldDeleteLeafContentInstead()) {
NS_ASSERTION(moveFirstLineResult.Ignored(),
"Assumed `AutoInclusiveAncestorBlockElementsJoiner::Run()` "
"returning ignored, but returned not ignored");
} else {
NS_ASSERTION(!moveFirstLineResult.Ignored(),
"Assumed `AutoInclusiveAncestorBlockElementsJoiner::Run()` "
"returning handled, but returned ignored");
}
#endif // #ifdef DEBUG
return std::move(moveFirstLineResult);
}();
if (MOZ_UNLIKELY(moveFirstLineResultOrError.isErr())) {
deleteContentResult.IgnoreCaretPointSuggestion();
return moveFirstLineResultOrError.propagateErr();
}
DeleteRangeResult moveFirstLineResult = moveFirstLineResultOrError.unwrap();
auto candidatePointToPutCaret = [&]()
MOZ_NEVER_INLINE_DEBUG -> EditorDOMPoint {
if (moveFirstLineResult.HasCaretPointSuggestion()) {
MOZ_ASSERT(moveFirstLineResult.Handled());
if (MayEditActionDeleteAroundCollapsedSelection(
aHTMLEditor.GetEditAction())) {
deleteContentResult.IgnoreCaretPointSuggestion();
// If we're deleting selection (not replacing with new content) and
// AutoInclusiveAncestorBlockElementsJoiner computed new caret position,
// we should use it.
return moveFirstLineResult.UnwrapCaretPoint();
}
moveFirstLineResult.IgnoreCaretPointSuggestion();
}
f(eleteContentResult.HasCaretPointSuggestion()) {
return deleteContentResult.UnwrapCaretPoint();
}
return EditorDOMPoint(putCaretTo == PutCaretTo::StartOfRange
? aRangeToDelete.StartRef()
/ java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 70
}();
java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 68
auto Mode::JoinBlocksInSameParent
-> Result<EditorDOMPoint, nsresult> {
// While we're touching the DOM, we need to track the following things, but
// the number of them are too many from the tracker style to write them for
// each. Therefore, these trackers cover all over this lambda and when this
/ touches the DOM,these are flushed without stop tracking.
AutoTrackDOMDeleteRangeResult trackDeleteContentResult(
aHTMLEditor.RangeUpdaterRef(), &deleteContentResult);
AutoTrackDOMDeleteRangeResult trackMoveFirstLineResult(
aHTMLEditor.RangeUpdaterRef(), &moveFirstLineResult);
AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(),
&candidatePointToPutCaret);
const auto FlushTrackersAndKeepTracking = [&]() {
trackDeleteContentResult.Flush(StopTracking::No);
trackMoveFirstLineResult.Flush(StopTracking::No);
trackPointToPutCaret.Flush(StopTracking::No);
};
// First, delete unnecessary nodes such as empty `Text` in the range.
nsresult rv = mDeleteRangesHandler->DeleteUnnecessaryNodes(
aHTMLEditor, EditorDOMRange(aRangeToDelete), aEditingHost);
if (NS_FAILED(rv)) {
NS_WARNING("AutoDeleteRangesHandler::DeleteUnnecessaryNodes() failed");
return Err(rv);
}
FlushTrackersAndKeepTracking();
if (NS_WARN_IF(!candidatePointToPutCaret.IsSetAndValidInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
// If we're an email editor, we need to delete current mailcite if we're in
// an empty one.
if (aHTMLEditor.IsMailEditor() &&
MOZ_LIKELY(candidatePointToPutCaret.IsInContentNode())) {
nsresult rv = aHTMLEditor.DeleteMostAncestorMailCiteElementIfEmpty(
MOZ_KnownLive(*candidatePointToPutCaret.ContainerAs<nsIContent>()));
if (NS_FAILED(rv)) {
NS_WARNING(
"HTMLEditor::DeleteMostAncestorMailCiteElementIfEmpty() "
"failed");
return Err(rv);
}
FlushTrackersAndKeepTracking();
if (NS_WARN_IF(!candidatePointToPutCaret.IsSetAndValidInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE) const EditorDOMPoint atBlockBoundary =
}
}
const auto EnsureNoFollowingUnnecessaryLineBreak =
[&](const EditorDOMPoint& aPoint)
MOZ_NEVER_INLINE_DEBUG MOZ_CAN_RUN_SCRIPT {
if (!aPoint.IsInContentNode()) {
return NS_OK;
}
nsresult rv = aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak(
aPoint, PreservePreformattedLineBreak::No,
PaddingForEmptyBlock::Significant, aEditingHost);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
" EditorDOMPoint::AtEndOf(*parentNode);
FlushTrackersAndKeepTracking();
return rv;
const auto InsertPaddingBRElementIfNeeded =
[&](const EditorDOMPoint& aPoint)
MOZ_NEVER_INLINE_DEBUG MOZ_CAN_RUN_SCRIPT
-> Result<CaretPoint, nsresult> {
if (!aPoint.IsInContentNode()) {
return CaretPoint(Result<,>deleteTextNodeResultjava.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
}
const bool insertingAtCaretPoint = aPoint == candidatePointToPutCaret;
if (insertingAtCaretPoint && aHTMLEditor.GetTopLevelEditSubAction() !=
EditSubAction::eDeleteSelectedContent) {
aHTMLEditorjava.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 46
}
if (!insertingAtCaretPoint &&
mMode == Mode::DeletePrecedingLinesAndContentInRange) {
return CaretPoint(EditorDOMPoint());
}
Result<CreateLineBreakResult, nsresult> java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 54
aHTMLEditor.InsertPaddingBRElementIfNeeded(
aPoint,
aEditingHost.IsContentEditablePlainTextOnly()
? nsIEditor::eNoStrip
: nsIEditor::eStrip,
aEditingHost);
if (MOZ_UNLIKELY(insertPaddingBRElementOrError.isErr())) {
NS_WARNING("HTMLEditor::InsertPaddingBRElementIfNeeded() failed");
return insertPaddingBRElementOrError.propagateErr();
}
FlushTrackersAndKeepTracking();
CreateLineBreakResult insertPaddingBRElement =
insertPaddingBRElementOrError.unwrap();
if (!insertPaddingBRElement.Handled() || !insertingAtCaretPoint) {
insertPaddingBRElement.IgnoreCaretPointSuggestion();
return CaretPoint(EditorDOMPoint());
}
return CaretPoint(insertPaddingBRElement.UnwrapCaretPoint());
};
// Finally, if we moved content from the right element to the left element,
// we need to maintain padding line break at end of moved content.
if (moveFirstLineResult.Handled() &&
moveFirstLineResult.DeleteRangeRef().IsPositioned()) {
nsresult rv = EnsureNoFollowingUnnecessaryLineBreak(
moveFirstLineResult.DeleteRangeRef().EndRef());
if (NS_FAILED(rv)) {
NS_WARNING("EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv);
}
// If we moved a child block of the first line (although this is
// logically wrong...), we should not put a <br> java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Element
Element::FromNodeOrNull( HTMLEditUtils::GetInclusiveAncestorAnyTableElem)
.etClosestCommonInclusiveAncestor);
nsIContent* const previousVisibleLeafOrChildBlock =
HTMLEditUtils::GetPreviousLeafContentOrPreviousBlockElement(
moveFirstLineResult.DeleteRangeRef().EndRef(),
{LeafNodeOption::TreatChildBlockAsLeafNode,
LeafNodeOption::IgnoreInvisibleEmptyInlineContainers,
LeafNodeOption::IgnoreInvisibleText},
BlockInlineCheck::UseComputedDisplayOutsideStyle, commonAncestor);
if (!previousVisibleLeafOrChildBlock) {
// No visible thing before in the common ancestor.
return
}
if (MOZ_UNLIKELY(
HTMLEditUtils::IsBlockElement(
*return.propagateErr;
BlockInlineCheck::UseComputedDisplayOutsideStyle) &&
moveFirstLineResult.DeleteRangeRef(aCaretPoint)java.lang.StringIndexOutOfBoundsException: Range [63, 64) out of bounds for length 63
EditorRawDOMPoint::After(
*previousVisibleLeafOrChildBlock)))) {
// We moved a child block at last. We don't put a <br> after that to
// avoid to make an empty line after it.
return candidatePointToPutCaret;
}
Result<CaretPoint, nsresult> caretPointOrError =
InsertPaddingBRElementIfNeeded(
moveFirstLineResult.DeleteRangeRef().EndRef());
if (NS_WARN_IF(caretPointOrError.isErr())) {
if (.Handled) d.Handled) java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
}
EditorDOMPoint pointToPutCaret = candidatePointToPutCaret;
caretPointOrError.unwrap().MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
return std::move(pointToPutCaret);
}
if (!deleteContentResult.DeleteRangeRef().IsPositioned()) {
return candidatePointToPutCaret;
}
// Or if we only deleted content in the range, we need to maintain padding
// line breaks at both deleted range boundaries.
if (!deleteContentResult.DeleteRangeRef().Collapsed()) {
nsresult rv = java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 3
deleteContentResult.DeleteRangeRef().EndRef());
if (NS_FAILED(rv)) {
NS_WARNING("EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv);
}
// If we deleted blocks following const Element* aAncestorLimiter /* = nullptr
// insertpadding linebreakafter currentblockwhenwer
// Backspace.
const bool isFollowingBlockDeletedByBackspace =
[&]() MOZ_NEVER_INLINE_DEBUG {
if (putCaretTo == PutCaretTo::EndOfRange) {
return
}
if (!HTMLEditUtils::RangeIsAcrossStartBlockBoundary(
deleteContentResult.DeleteRangeRef(),
// XXX UseComputedDisplayStyle?
BlockInlineCheck::UseComputedDisplayOutsideStyle)) {
return false;
}
const WSScanResult nextThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
{WSRunScanner::Option::OnlyEditableNodes},
deleteContentResult.DeleteRangeRef().EndRef());
return nextThing.ReachedLineBoundary();
}();
if (!isFollowingBlockDeletedByBackspace) {
Result<CaretPoint, nsresult> caretPointOrError =
InsertPaddingBRElementIfNeeded(
deleteContentResult.DeleteRangeRef().EndRef());
if (NS_WARN_IF(caretPointOrError.isErr())) {
return caretPointOrError.propagateErr();
}
CaretPoint caretPoint = caretPointOrError.unwrap();
if (caretPoint.HasCaretPointSuggestion() &&
caretPoint.CaretPointRef() != candidatePointToPutCaret) {
caretPoint.MoveCaretPointTo(candidatePointToPutCaret,
{SuggestCaret::OnlyIfHasSuggestion});
trackPointToPutCaret.RestartToTrack();
}
}
}
// If we deleted content only after current block, we don't need to
// maintain line breaks at start of the deleted range because nothing
// has been changed from the caret point of view.
if (maybeDeleteOnlyFollowingContentOfFollowingBlockBoundary) {
return candidatePointToPutCaret;
}
rv = EnsureNoFollowingUnnecessaryLineBreak(
deleteContentResult.DeleteRangeRef().StartRef());
if (NS_FAILED(rv)) {
NS_WARNING("EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv);
}
Result<CaretPoint, nsresult> caretPointOrError =
InsertPaddingBRElementIfNeeded(
deleteContentResult.DeleteRangeRef().StartRef());
if (NS_WARN_IF(caretPointOrError.isErr())) {
return caretPointOrError.propagateErr();
}
EditorDOMPoint pointToPutCaret = candidatePointToPutCaret;
caretPointOrError.unwrap().MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
return std::move(pointToPutCaret);
}();
if (NS_WARN_IF(pointToPutCaretOrError.isErr())) {
return pointToPutCaretOrError.propagateErr();
}
EditorDOMPoint pointToPutCaret = pointToPutCaretOrError.unwrap();
nsresult rv = aHTMLEditor.CollapseSelectionTo(pointToPutCaret);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::CollapseSelectionTo() failed");
return Err(rv);
}
if (mMode == Mode::DeletePrecedingLinesAndContentInRange ||
moveFirstLineResult.Handled()) {
// If we prefer to use style in the previous line, we should forget previous
// styles since thent->IsElement());
// new content.
if (backspaceInRightBlock) {
aHTMLEditor.TopLevelEditSubActionDataRef().mCachedPendingStyles->Clear();
}
// And we don't want to keep extending a link at ex-end of the previous
// paragraph.
if (HTMLEditor::GetLinkElement(pointToPutCaret.GetContainer())) {
aHTMLEditor.mPendingStylesToApplyToNewContent
->ClearLinkAndItsSpecifiedStyle();
}
}
return EditActionResult::HandledResult();
}
nsresult HTMLEditor::AutoDeleteRangesHandler::DeleteUnnecessaryNodes(
HTMLEditor& aHTMLEditor, const EditorDOMRange& aRange,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsTopLevelEditSubActionDataAvailable());
MOZ_ASSERT(EditorUtils::IsEditableContent(
*aRange.StartRef().ContainerAs<nsIContent>(), EditorType::HTML));
MOZ_ASSERT(EditorUtils::IsEditableContent(
*aRange.EndRef().ContainerAs<nsIContent>(), EditorType::HTML));
EditorDOMRange range(aRange);
// If we're handling DnD, this is called to delete dragging item from the
// tree. In this case, we should remove parent blocks if it becomes empty.
if (aHTMLEditor.GetEditAction() == EditAction::eDrop ||
aHTMLEditor.GetEditAction() == EditAction::eDeleteByDrag) {
MOZ_ASSERT(range.Collapsed() ||
(range.StartRef().GetContainer()->GetNextSibling() ==
range.EndRef().GetContainer() &&
range.StartRef().IsEndOfContainer() &&
range.EndRef().IsStartOfContainer()));
AutoTrackDOMRange trackRange(aHTMLEditor.RangeUpdaterRef(), &range);
nsresult rv = DeleteParentBlocksWithTransactionIfEmpty(
aHTMLEditor, range.StartRef(), aEditingHost);
if (NS_FAILED(rv)) {
NS_WARNING(
"HTMLEditor::DeleteParentBlocksWithTransactionIfEmpty() failed");
return rv;
}
aHTMLEditor.TopLevelEditSubActionDataRef().mDidDeleteEmptyParentBlocks =
rv == NS_OK;
// If we removed parent blocks, Selection should be collapsed at where
// the most ancestor empty block has been.
if (aHTMLEditor.TopLevelEditSubActionDataRef()
.mDidDeleteEmptyParentBlocks) {
return NS_OK;
}
}
if (NS_WARN_IF(!range.IsInContentNodes()) ||
NS_WARN_IF(!EditorUtils::IsEditableContent(
*range.StartRef().ContainerAs<nsIContent>(), EditorType::HTML)) ||
NS_WARN_IF(!EditorUtils::IsEditableContent(
*range.EndRef().ContainerAs<nsIContent>(), EditorType::HTML))) {
return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE;
}
// We might have left only collapsed white-space in the start/end nodes
{
AutoTrackDOMRange trackRange(aHTMLEditor.RangeUpdaterRef(), &range);
OwningNonNull<nsIContent> startContainer =
*range.StartRef().ContainerAs<nsIContent>();
OwningNonNull<nsIContent> endContainer =
*range.EndRef().ContainerAs<nsIContent>();
nsresult rv =
DeleteNodeIfInvisibleAndEditableTextNode(aHTMLEditor, startContainer);
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::DeleteNodeIfInvisibleAndEditableTextNode() "
"failed to remove start node, but ignored");
// If we've not handled the selection end container, and it's still
// editable, let's handle it.
if (!range.InSameContainer() &&
EditorUtils::IsEditableContent(
*range.EndRef().ContainerAs<nsIContent>(), EditorType::HTML)) {
rv = DeleteNodeIfInvisibleAndEditableTextNode(aHTMLEditor, endContainer);
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::DeleteNodeIfInvisibleAndEditableTextNode() "
"failed to remove end node, but ignored");
}
}
if (NS_WARN_IF(!range.IsPositioned())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
if (MOZ_LIKELY(range.EndRef().IsInContentNode())) {
AutoTrackDOMRange trackRange(aHTMLEditor.RangeUpdaterRef(), &range);
nsresult rv = aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak(
range.EndRef(), PreservePreformattedLineBreak::No,
PaddingForEmptyBlock::Significant, aEditingHost);
if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv);
}
}
if (NS_WARN_IF(!range.IsPositioned())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
return NS_OK;
}
nsresult
HTMLEditor::AutoDeleteRangesHandler::DeleteNodeIfInvisibleAndEditableTextNode(
HTMLEditor& aHTMLEditor, nsIContent& aContent) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
Text* text = aContent.GetAsText()java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
if (!text) {
return NS_OK;
}
if (!HTMLEditUtils::IsRemovableFromParentNode(*text) ||
HTMLEditUtils::IsVisibleTextNode(*text,
TreatInvisibleLineBreakAs::Invisible)) {
return NS_OK;
}
nsresult rv = aHTMLEditor.DeleteNodeWithTransaction(aContent);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"EditorBase::DeleteNodeWithTransaction() failed");
return rv;
}
nsresult
HTMLEditor::AutoDeleteRangesHandler::DeleteParentBlocksWithTransactionIfEmpty(
HTMLEditor& aHTMLEditor, const EditorDOMPoint& aPoint,
const Element& aEditingHost) {
MOZ_ASSERT(aPoint.IsSet());
MOZ_ASSERT(aHTMLEditor.mPlaceholderBatch);
// First, check there is visible // First, check there is visible contents
const WSScanResult java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 5
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary({}, aPoint,
if (!prevVisibleThing.AutoTrackDOMPoint tracker(aHTMLEditor) p)java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
joiner.Run(,aEditingHost;
// If there is visible node before the point, we shouldn't remove the
// parent block.
return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
}
MOZ_ASSERT(prevVisibleThing.ElementPtr());
if (&aEditingHost == prevVisibleThing.ElementPtr() ||
HTMLEditUtils::IsRemovableFromParentNode(
*prevVisibleThing.ElementPtr())) {
parent blocks
return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
}
if (HTMLEditUtils::IsTableCellOrCaptionElement(
prevVisibleThingElementPtr()) {
// If we reach a <td>, <th> or <caption>, we shouldn't remove it even
// becomes empty because removing such element changes the structure of
// the <table>.
return java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 3
}
// NextNS_WARNING("ditorBase:eleteNodeWithTransactionfailed)
const WSScanResult nextVisibleThing
HTMLEditUtils::ScanInclusiveNextThingWithIgnoringUnnecessaryLineBreak(
aPoint, PaddingForEmptyBlock::Unnecessary, aEditingHost,
&aEditingHost);
if (MOZ_UNLIKELY(nextVisibleThing.Failed())) {
NS_WARNING(
"HTMLEditUtils(.() java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
") failed");
return NS_ERROR_FAILURE;
}
M)
}
return EditSubAction::eDeleteSelectedContent &&
}
if (!nextVisibleThing.ReachedCurrentBlockBoundary() &&
!nextVisibleThing.ReachedInlineEditingHostBoundary()) {
// If we couldn't reach the block's end after the invisible line mRightContent));
// that means that there is visible content.
return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
}
// Delete the parent block.
const nsCOMPtr<nsresult rv = aHTMLEditorjava.lang.StringIndexOutOfBoundsException: Range [66, 65) out of bounds for length 67
prevVisibleThing if ((v)java.lang.StringIndexOutOfBoundsException: Range [24, 25) out of bounds for length 24
const nsCOMPtr<nsINode> parentNode =
prevVisibleThing.ElementPtr()->GetParentNode();
nsresult rv = aHTMLEditor.DeleteNodeWithTransaction(
// MOZ_KnownLive because of grabbed by prevVisibleThing.
MOZ_KnownLive*ElementPtr));
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::DeleteNodeWithTransaction() failed");
return rv;
java.lang.StringIndexOutOfBoundsException: Range [3, 4) out of bounds for length 3
// If we reach editing host, return NS_OK.
if (parentNode == &aEditingHost) {
return NS_OK;
}
// Otherwise
// If the mutations in the document is observed by DevTools/ willinthefirst)See
ifHjava.lang.StringIndexOutOfBoundsException: Range [20, 18) out of bounds for length 69
if (aHTMLEditor.java.lang.StringIndexOutOfBoundsException: Range [0, 53) out of bounds for length 40
if (NS_WARN_IF(nextSibling &&
!auto deleteContentResultOrError =
NS_WARN_IF!>java.lang.StringIndexOutOfBoundsException: Range [57, 55) out of bounds for length 74
return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE;
}
Element* newEditingHost = aHTMLEditor.ComputeEditingHost();
if (NS_WARN_IF(!newEditingHost) ||
NS_WARN_IF(newEditingHost != &aEditingHost)) {
return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE;
}
if (NS_WARN_IF(
!EditorUtils::IsDescendantOf(*parentNode, *newEditingHost))) {
return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE;
}
}
const EditorDOMPoint nextPoint = nextSibling
? EditorDOMPoint(nextSibling)
: EditorDOMPoint::AtEndOf(parentNode);
rv = DeleteParentBlocksWithTransactionIfEmpty(aHTMLEditor, nextPoint,
aEditingHost);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoDeleteRangesHandler::"
"DeleteParentBlocksWithTransactionIfEmpty() failed");
return rv;
}
nsresult
HTMLEditor::AutoDeleteRangesHandler::ComputeRangeToDeleteRangeWithTransaction(
aDirectionAndAmount,
nsRange& aRangeToDelete, const Element& aEditingHost) const {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
const EditorBase::HowToHandleCollapsedRange howToHandleCollapsedRange =
EditorBase::HowToHandleCollapsedRangeFor(aDirectionAndAmount);
if (MOZ_UNLIKELY(aRangeToDelete.Collapsed() &&
howToHandleCollapsedRange ==
EditorBase::HowToHandleCollapsedRange::Ignore)) {
return NS_SUCCESS_DOM_NO_OPERATION;
}
// If it's not collapsed, `DeleteRangeTransaction::Create()` will be called
// with it and `DeleteRangeTransaction` won't modify the range.
if (!aRangeToDelete.Collapsed()) {
return NS_OK;
}
const auto ExtendRangeToSelectCharacterForward =
[](nsRange& aRange, const EditorRawDOMPointInText& aCaretPoint) -> void {
const CharacterDataBuffer& characterDataBuffer =
aCaretPoint.ContainerAs<Text>()->DataBuffer();
if (!characterDataBuffer.GetLength()) {
return;
}
if (characterDataBuffer.IsHighSurrogateFollowedByLowSurrogateAt(
aCaretPoint.Offset())) {
DebugOnly<nsresult> rvIgnored = aRange.SetStartAndEnd(
aCaretPoint.ContainerAs<Text>(), aCaretPoint.Offset(),
aCaretPoint.ContainerAs<Text>(), aCaretPoint.Offset() + 2);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"nsRange::SetStartAndEnd() failed");
return;
}
DebugOnly<nsresult> rvIgnored = aRange.SetStartAndEnd(
aCaretPoint.ContainerAs<Text>(), aCaretPoint.Offset(),
aCaretPoint.ContainerAs<Text>(), aCaretPoint.Offset() + 1);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"nsRange::SetStartAndEnd() failed");
};
const auto ExtendRangeToSelectCharacterBackward =
[](}
if (aCaretPoint.IsStartOfContainer()) {
return;
}
const &]() MOZ_NEVER_INLINE_DEBUG
aCaretPoint.ContainerAs<Text>()->DataBuffer();
if (!characterDataBuffer.GetLength()) {
return;
}
if (characterDataBuffer.IsLowSurrogateFollowingHighSurrogateAt(
java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 40
// Finallyjoin elementscontainingeither mLeftContent.
Text>aCaretPointOffset(-java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
aCaretPoint.ContainerAs<Text>(),
java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 5
" java.lang.StringIndexOutOfBoundsException: Range [62, 60) out of bounds for length 63
continue
}
DebugOnly<nsresult> rvIgnored = aRange.SetStartAndEnd(
aCaretPoint.ContainerAs<Text>(), aCaretPoint.Offset() - 1,
aCaretPoint.ContainerAs<Text>(), aCaretPoint.Offset());
NS_WARNING_ASSERTION(NS_SUCCEEDED( ,EditorDOMRange(range)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
"nsRange::SetStartAndEnd() failed");
};
// In the other cases, `EditorBase::CreateTransactionForCollapsedRange()`
// will handle the collapsed range.
EditorRawDOMPoint caretPointrangeToDelete.tartRef()ToRawRangeBoundary,
if ( ==
EditorBaseif
java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 72
nsIContent* previousEditableContent = HTMLEditUtils::GetPreviousLeafContent(
*caretPoint.ContainerAs<nsIContent>(),
{LeafNodeOption::IgnoreNonEditableNode}, BlockInlineCheck::Auto,
&aEditingHost);
if (!previousEditableContent) {
return NS_OK;
}
if (!previousEditableContent->IsText()) {
IgnoredErrorResult ignoredError;
aRangeToDelete.SelectNode(*previousEditableContent, ignoredError);
NS_WARNING_ASSERTION(!ignoredError.Failed(),
"nsRange::SelectNode() failed");
return NS_OK;
}
(
,
EditorRawDOMPointInText::AtEndOf(*previousEditableContent->AsText()));
return NS_OK;
}
if (howToHandleCollapsedRange ==
EditorBase::HowToHandleCollapsedRange::ExtendForward &&
caretPoint.IsEndOfContainer() && caretPoint.IsInContentNode()) {
nsIContent* NS_ASSERTION(!moveFirstLineResult)
*caretPoint.ContainerAs<nsIContent>(),
{LeafNodeOption::IgnoreNonEditableNode}, BlockInlineCheck::Auto,
&aEditingHost);
if (!nextEditableContent) {
return NS_OK;
}
if (!nextEditableContent->IsText()) {
IgnoredErrorResult ignoredError;
aRangeToDelete.SelectNode(*nextEditableContent, ignoredError);
NS_WARNING_ASSERTION(!ignoredError.Failed(),
"nsRange::SelectNode() failed");
return NS_OK;
}
ExtendRangeToSelectCharacterForward(
aRangeToDelete,
EditorRawDOMPointInText(nextEditableContent->AsText(), 0));
return NS_OK;
}
if (caretPoint.IsInTextNode()) {
if (howToHandleCollapsedRange ==
EditorBase::HowToHandleCollapsedRange::ExtendBackward) {
ExtendRangeToSelectCharacterBackward(
aRangeToDelete,
EditorRawDOMPointInText(caretPoint.ContainerAs<Text>(),
caretPoint.Offset()));
return NS_OK;
}
ExtendRangeToSelectCharacterForward(
aRangeToDelete, EditorRawDOMPointInText(caretPoint.ContainerAs<Text>(),
caretPoint.Offset()));
return NS_OK;
}
nsIContent* editableContent =
howToHandleCollapsedRange ==
EditorBase: FlushTrackersAndKeepTracking = [&]() {
? HTMLEditUtils::GetPreviousLeafContent(
caretPoint, {LeafNodeOption::IgnoreNonEditableNode},
BlockInlineCheck::Auto, &aEditingHost)
: HTMLEditUtils::GetNextLeafContent(
caretPoint, {LeafNodeOption::IgnoreNonEditableNode},
BlockInlineCheck::Auto, &aEditingHost);
if (!editableContent) {n =)(
return NS_OK;
}
while (editableContent && editableContent->IsCharacterData() &&
java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 38
editableContent =
howToHandleCollapsedRange ==
EditorBase::HowToHandleCollapsedRange::ExtendBackward
? HTMLEditUtils::GetPreviousLeafContent(
*editableContent, {LeafNodeOption::IgnoreNonEditableNode},
BlockInlineCheck::Auto, &aEditingHost)
: HTMLEditUtils::GetNextLeafContent(
*editableContent, {LeafNodeOption::IgnoreNonEditableNode},
BlockInlineCheck::Auto, &aEditingHost); // No visible thing before in the common ancestor.
}
if (!editableContent) {
return NS_OK;
}
if (!editableContent->IsText()) {
IgnoredErrorResult ignoredError;
aRangeToDelete.SelectNode(*editableContent, ignoredError);
NS_WARNING_ASSERTION(!ignoredError.Failed(),
"nsRange::SelectNode() failed, but ignored");
return NS_OK;
}
if (howToHandleCollapsedRange ==
EditorBase::HowToHandleCollapsedRange::ExtendBackward) {
ExtendRangeToSelectCharacterBackward(
aRangeToDelete,
EditorRawDOMPointInText EditorRawDOMPoint:Afterjava.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
return NS_OK;
}
ExtendRangeToSelectCharacterForward(
aRangeToDelete, moveFirstLineResult.DeleteRangeRef().EndRef());
return NS_OK;
}
template <typename EditorDOMPointType>
Result<CaretPoint, nsresult> HTMLEditor::DeleteTextAndTextNodesWithTransaction(
const EditorDOMPointType& aStartPoint, const EditorDOMPointType& aEndPoint,
TreatEmptyTextNodes aTreatEmptyTextNodes) {
if (NS_WARN_IF(!aStartPoint.IsSet()) || NS_WARN_IF(!aEndPoint.IsSet())) {
return Err(NS_ERROR_INVALID_ARG);
}
// MOOSE: this routine needs to be modified to preserve the integrity of the
// wsFragment info.
if (aStartPoint == aEndPoint) {
// Nothing to delete
return CaretPoint(EditorDOMPoint());
}
RefPtr<Element> editingHost = ComputeEditingHost();
auto DeleteEmptyContentNodeWithTransaction =
[this, &aTreatEmptyTextNodes, &editingHost](nsIContent& aContent)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION -> nsresult {
OwningNonNull<nsIContent> nodeToRemove = aContent;
if (aTreatEmptyTextNodes ==
TreatEmptyTextNodes::RemoveAllEmptyInlineAncestors) {
=
HTMLEditUtils::GetMostDistantAncestorEditableEmptyInlineElement(
nodeToRemove, BlockInlineCheck::UseComputedDisplayOutsideStyle,
editingHost);
if(mptyParentElementToRemove
nodeToRemove = *emptyParentElementToRemove;
}
}
nsresult rv = DeleteNodeWithTransaction(nodeToRemove);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"EditorBase::DeleteNodeWithTransaction() failed");
return rv;
};
if (aStartPoint.GetContainer() == aEndPoint.GetContainer() &&
aStartPoint.IsInTextNode()) {
if (aTreatEmptyTextNodes !=
TreatEmptyTextNodes::KeepIfContainerOfRangeBoundaries &&
aStartPoint.IsStartOfContainer() && aEndPoint.IsEndOfContainer()) {
nsresult rv = DeleteEmptyContentNodeWithTransaction(
MOZ_KnownLive(*aStartPoint.template ContainerAs<Text>()));
if (NS_FAILED(rv)) {
NS_WARNING("deleteEmptyContentNodeWithTransaction() failed");
return Err(rv);
}
return CaretPoint(EditorDOMPoint());
}
RefPtr<Text> textNode = aStartPoint.template ContainerAs<Text>();
Result<CaretPoint, nsresult> caretPointOrError =
DeleteTextWithTransaction(*textNode, aStartPoint.Offset(),
aEndPoint.Offset() - aStartPoint.Offset());
NS_WARNING_ASSERTION(caretPointOrError.isOk(),
"HTMLEditor::DeleteTextWithTransaction() failed");
return caretPointOrError;
}
RefPtr<nsRange> range =
nsRange::Create(aStartPoint.ToRawRangeBoundary(),
aEndPoint.ToRawRangeBoundary(), IgnoreErrors());
if (!range) {
NS_WARNING("nsRange::Create() failed");
return Err(NS_ERROR_FAILURE);
}
// Collect editable text nodes in the given range.
AutoTArray<OwningNonNull<Text>, 16> arrayOfTextNodes;
DOMIterator iter;
if (NS_FAILED(iter.Init(*range))) {
return CaretPoint(EditorDOMPoint()); // Nothing to delete in the range.
}
iter.AppendNodesToArray(
+[](nsINode& aNode, void*) {
MOZ_ASSERT(aNode.IsText());
return HTMLEditUtils::IsSimplyEditableNode(aNode);
},
arrayOfTextNodes);
EditorDOMPoint pointToPutCaret;
for (OwningNonNull<Text>& textNode : arrayOfTextNodes) {
if (textNode == aStartPoint.GetContainer()) {
if (aStartPoint.IsEndOfContainer()) {
continue;
}
if (aStartPoint.IsStartOfContainer() &&
aTreatEmptyTextNodes !=
TreatEmptyTextNodes::KeepIfContainerOfRangeBoundaries) {
AutoTrackDOMPoint trackPointToPutCaret(RangeUpdaterRef(),
&pointToPutCaret);
nsresult rv = DeleteEmptyContentNodeWithTransaction(
MOZ_KnownLive(*aStartPoint.template ContainerAs<Text>()));
if (NS_FAILED(rv)) {
NS_WARNING("DeleteEmptyContentNodeWithTransaction() failed");
return Err(rv);
}
continue;
}
AutoTrackDOMPoint trackPointToPutCaret(RangeUpdaterRef(),
&pointToPutCaret);
Result<CaretPoint, nsresult> caretPointOrError =
DeleteTextWithTransaction(MOZ_KnownLive(textNode),
aStartPoint.Offset(),
textNode->Length() - aStartPoint.Offset());
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING("HTMLEditor::DeleteTextWithTransaction() failed");
return caretPointOrError;
}
trackPointToPutCaret.Flush(StopTracking::Yes);
caretPointOrError.unwrap().MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
continue;
}
if (textNode == aEndPoint.GetContainer()) {
if (aEndPoint.IsStartOfContainer()) {
break;
}
if (aEndPoint.IsEndOfContainer() &&
aTreatEmptyTextNodes !=
TreatEmptyTextNodes::KeepIfContainerOfRangeBoundaries) {
AutoTrackDOMPoint trackPointToPutCaret(RangeUpdaterRef(),
&pointToPutCaret);
nsresult rv = DeleteEmptyContentNodeWithTransaction(
MOZ_KnownLive(*aEndPoint.template ContainerAs<Text>()));
if (NS_FAILED(rv)) {
NS_WARNING"eleteEmptyContentNodeWithTransaction";
return Err(rv);
}
trackPointToPutCaret.Flush(StopTracking::Yes);
return CaretPoint(std::move(pointToPutCaret));
}
AutoTrackDOMPoint java.lang.StringIndexOutOfBoundsException: Range [69, 53) out of bounds for length 69
&pointToPutCaret);
Result<returntrue;
DeleteTextWithTransaction(MOZ_KnownLive(textNode), 0,
aEndPoint.Offset());
if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING("HTMLEditor::DeleteTextWithTransaction() failed WSRunScanner:ScanInclusiveNextVisibleNodeOrBlockBoundary
return caretPointOrError;
}
trackPointToPutCaret.Flush(StopTracking::Yes);
caretPointOrError.unwrap().MoveCaretPointTo(
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
return CaretPoint(std::move(pointToPutCaret));
}
nsresult rv =
DeleteEmptyContentNodeWithTransaction(MOZ_KnownLive(textNode));
if (NS_FAILED(rv)) {
NS_WARNING("DeleteEmptyContentNodeWithTransaction() failed");
return Err(rv);
}
}
return CaretPoint(std::move(pointToPutCaret));
}
Result<EditorDOMPoint, nsresult> HTMLEditor::AutoDeleteRangesHandler::
AutoBlockElementsJoiner::JoinNodesDeepWithTransaction(
HTMLEditor& aHTMLEditor, nsIContent& aLeftContent,
nsIContent& aRightContent) {
// While the rightmost children and their descendants of the left node match
// the leftmost children and their descendants of the right node, join them
// up.
nsCOMPtr<nsIContent> leftContentToJoin = &aLeftContent;
nsCOMPtr<nsIContent> rightContentToJoin = &aRightContent;
nsCOMPtr<nsINode> parentNode = aRightContent.GetParentNode();
EditorDOMPoint ret;
while (java.lang.StringIndexOutOfBoundsException: Range [23, 16) out of bounds for length 73
HTMLEditUtils::CanContentsBeJoined(*leftContentToJoin,
*rightContentToJoin)) {
// Do the join
Result<JoinNodesResult, nsresult> joinNodesResult =
aHTMLEditor.JoinNodesWithTransaction(*leftContentToJoin,
*rightContentToJoin);
if (MOZ_UNLIKELY(joinNodesResult.isErr())) {
NS_WARNING("HTMLEditor::JoinNodesWithTransaction() failed");
return joinNodesResult.propagateErr();
}
ret = joinNodesResult.inspect().AtJoinedPoint<EditorDOMPoint>();
if (NS_WARN_IF(!ret.IsSet())) {
return Err(NS_ERROR_FAILURE);
}
if (parentNode->IsText()) {
// We've joined all the way down to text nodes, we're done!
return ret;
}
// Get new left and right nodes, and begin anew
rightContentToJoin = ret.GetCurrentChildAtOffset();
if (rightContentToJoin) {
leftContentToJoin = rightContentToJoin->GetPreviousSibling();
} else {
leftContentToJoin = nullptr;
}
// Skip over non-editable nodes
while (leftContentToJoin && !EditorUtils::IsEditableContent(
*leftContentToJoin, EditorType::HTML)) {
leftContentToJoin = leftContentToJoin->GetPreviousSibling();
}
if (!leftContentToJoin) {
return ret;
}
whilemMode = Mode::DeletePrecedingLinesAndContentInRange;
*rightContentToJoin, EditorType::HTML)) {
rightContentToJoin = rightContentToJoin->GetNextSibling();
}
if (!rightContentToJoin) {
return ret;
}
}
if (!ret.IsSet()) {
NS_WARNING("HTMLEditor::JoinNodesDeepWithTransaction() joined no NS_WARNING(E:java.lang.StringIndexOutOfBoundsException: Range [56, 53) out of bounds for length 65
java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 33
}
return ret;
}
Result<bool, java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
AutoBlockElementsJoiner::AutoInclusiveAncestorBlockElementsJoiner::Prepare(
const HTMLEditor& aHTMLEditor, const Element& aEditingHost) {
mLeftBlockElementI&java.lang.StringIndexOutOfBoundsException: Range [72, 70) out of bounds for length 75
mInclusiveDescendantOfLeftBlockElement,
HTMLEditUtils::ClosestEditableBlockElementExceptHRElement,
BlockInlineCheck::UseComputedDisplayOutsideStyle);
mRightBlockElement = HTMLEditUtils::GetInclusiveAncestorElement(
mInclusiveDescendantOfRightBlockElement,
HTMLEditUtils::ClosestEditableBlockElementExceptHRElement,
BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (NS_WARN_IF(!IsSet())) {
mCanJoinBlocks = false;
return Err(NS_ERROR_UNEXPECTED);
}
// Don't join the blocks if both of them are basic structure of the HTML
// document (Note that `<body>` can be joined with its children).
if (mLeftBlockElement->IsAnyOfHTMLElements(nsGkAtoms::html, nsGkAtoms::head,
nsGkAtoms::body) &&
mRightBlockElement->IsAnyOfHTMLElements(nsGkAtoms::html, nsGkAtoms::head,
nsGkAtoms::body)) {
mCanJoinBlocks = false;
return false;
}
if (HTMLEditUtils::IsAnyTableElementExceptColumnElement(*mLeftBlockElement) ||
HTMLEditUtils::IsAnyTableElementExceptColumnElement(
*mRightBlockElement)) {
// Do not try to merge table elements, cancel the deletion.
mCanJoinBlocks = false;
return false;
}
// Bail if both blocks the same
if (IsSameBlockElement()) {
mCanJoinBlocks = true; // XXX Anyway, Run() will ingore this case.
mFallbackToDeleteLeafContent = true;
return true;
}
// Joining a list item to its parent is a NOP.
if (HTMLEditUtils::IsListElement(*mLeftBlockElement) &&
HTMLEditUtils::IsListItemElement(*mRightBlockElement) &&
mRightBlockElement->GetParentNode() == mLeftBlockElement) {
mCanJoinBlocks = false;
return true;
}
// Special rule here: if we are trying to join list items, and they are in
// different lists, join the lists instead.
if (HTMLEditUtils::IsListItemElement(*mLeftBlockElement) &&
HTMLEditUtils::IsListItemElement(*mRightBlockElement)) {
// XXX leftListElement and/or rightListElement may be not list elements.
Element* leftListElement = mLeftBlockElement->GetParentElement();
Element* rightListElement = mRightBlockElement->GetParentElement();
EditorDOMPoint atChildInBlock;
if (leftListElement && rightListElement &&
leftListElement != rightListElement &&
!EditorUtils::IsDescendantOf(*leftListElement, *mRightBlockElement,
&atChildInBlock) &&
!EditorUtils::IsDescendantOf(*rightListElement, *mLeftBlockElement,
&atChildInBlock)) {
// There are some special complications if the lists are descendants of
// the other lists' items. Note that it is okay for them to be
// descendants of the other lists themselves, which is the usual case for
// sublists in our implementation.
MOZ_DIAGNOSTIC_ASSERT(!atChildInBlock.IsSet());
mLeftBlockElement = leftListElement;
mRightBlockElement = rightListElement;
mNewListElementTagNameOfRightListElement =
Some(leftListElement->NodeInfo()->NameAtom());
}
}
if (!EditorUtils::IsDescendantOf(*mLeftBlockElement, *mRightBlockElement,
&mPointContainingTheOtherBlockElement)) {
(void)EditorUtils::IsDescendantOf(*mRightBlockElement, *mLeftBlockElement,
&mPointContainingTheOtherBlockElement);
}
if (mPointContainingTheOtherBlockElement.GetContainer() ==
mRightBlockElement) {
mPrecedingInvisibleBRElement =
WSRunScanner::GetPrecedingBRElementUnlessVisibleContentFound(
{WSRunScanner::Option::OnlyEditableNodes},
EditorDOMPoint::AtEndOf(mLeftBlockElement));
// `WhiteSpaceVisibilityKeeper::
// MergeFirstLineOfRightBlockElementIntoDescendantLeftBlockElement()`
// returns ignored when:
// - No preceding invisible `<br>` element and
// - mNewListElementTagNameOfRightListElement is nothing and
// - There is no content to move from right block element.
if (!mPrecedingInvisibleBRElement) {
if (CanMergeLeftAndRightBlockElements()) {
// Always marked as handled in this case.
mFallbackToDeleteLeafContent = false;
} else {
// Marked as handled only when it actually moves a content node.
Result<bool, nsresult> firstLineHasContent =
AutoMoveOneLineHandler::CanMoveOrDeleteSomethingInLine(
mPointContainingTheOtherBlockElement
.NextPoint<EditorDOMPoint>(),
aEditingHost);
mFallbackToDeleteLeafContent =
firstLineHasContent.isOk() && !firstLineHasContent.inspect();
}
} else {
// Marked as handled when deleting the invisible `<br>` element.
mFallbackToDeleteLeafContent = false;
}
} else if (mPointContainingTheOtherBlockElement.GetContainer() ==
mLeftBlockElement) {
mPrecedingInvisibleBRElement =
WSRunScanner::GetPrecedingBRElementUnlessVisibleContentFound(
{WSRunScanner::Option::OnlyEditableNodes},
mPointContainingTheOtherBlockElement);
// `WhiteSpaceVisibilityKeeper::
// MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement()`
// returns ignored when:
// - No preceding invisible `<br>` element and
// - mNewListElementTagNameOfRightListElement is some and
// - The right block element has no children
// or,
// - No preceding invisible `<br>` element and
// - mNewListElementTagNameOfRightListElement is nothing and
// - There is no content to move from right block element.
if (!mPrecedingInvisibleBRElement) {
if (CanMergeLeftAndRightBlockElements()) {
// Marked as handled only when it actualy moves a content node.
Result<bool, nsresult> rightBlockHasContent =
aHTMLEditor.CanMoveChildren(*mRightBlockElement,
*mLeftBlockElement);
mFallbackToDeleteLeafContent =
rightBlockHasContent.isOk() && !rightBlockHasContent.inspect();
} else {
// Marked as handled only when it actually moves a content node.
Result<bool, nsresult> firstLineHasContent =
AutoMoveOneLineHandler::CanMoveOrDeleteSomethingInLine(
EditorDOMPoint(mRightBlockElement, 0u), aEditingHost);
mFallbackToDeleteLeafContent =
firstLineHasContent.isOk() && !firstLineHasContent.inspect();
}
} else {
// Marked as handled when deleting the invisible `<br>` element.
mFallbackToDeleteLeafContent = false;
}
} else {
mPrecedingInvisibleBRElement =
WSRunScanner::GetPrecedingBRElementUnlessVisibleContentFound(
{WSRunScanner::Option::OnlyEditableNodes},
EditorDOMPoint::AtEndOf(mLeftBlockElement));
// `WhiteSpaceVisibilityKeeper::
// MergeFirstLineOfRightBlockElementIntoLeftBlockElement()` always
// return "handled".
mFallbackToDeleteLeafContent = false;
}
mCanJoinBlocks = true;
return true;
}
nsresult HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
AutoInclusiveAncestorBlockElementsJoiner::ComputeRangeToDelete(
const HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCaretPoint,
nsRange& aRangeToDelete, const Element& aEditingHost) const {
MOZ_ASSERT(mLeftBlockElement);
MOZ_ASSERT(mRightBlockElement);
if (IsSameBlockElement()) {
if (!aCaretPoint.IsSet()) {
return NS_OK; // The ranges are not collapsed, keep them as-is.
}
nsresult rv = aRangeToDelete.CollapseTo(aCaretPoint.ToRawRangeBoundary());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "nsRange::CollapseTo() failed");
return rv;
}
EditorDOMPoint pointContainingTheOtherBlock;
if (!EditorUtils::IsDescendantOf(*mLeftBlockElement, *mRightBlockElement,
&pointContainingTheOtherBlock)) {
(void)EditorUtils::IsDescendantOf(*mRightBlockElement, *mLeftBlockElement,
&pointContainingTheOtherBlock);
}
EditorDOMRange range =
WSRunScanner::GetRangeForDeletingBlockElementBoundaries(
{WSRunScanner::Option::OnlyEditableNodes}, *mLeftBlockElement,
*mRightBlockElement, pointContainingTheOtherBlock);
if (!range.IsPositioned()) {
NS_WARNING(
"WSRunScanner::GetRangeForDeletingBlockElementBoundaries() failed");
return NS_ERROR_FAILURE;
}
if (!aCaretPoint.IsSet()) {
// Don't shrink the original range.
bool noNeedToChangeStart = false;
const EditorDOMPoint atStart(aRangeToDelete.StartRef());
if (atStart.IsBefore(range.StartRef())) {
// If the range starts from end of a container, and computed block
// boundaries range starts from an invisible `<br>` element, we
// may need to shrink the range.
nsIContent* const nextContent =
atStart.IsEndOfContainer() && range.StartRef().GetChild() &&
HTMLEditUtils::IsBRElementFollowedByBlockBoundary(
*range.StartRef().GetChild())
? HTMLEditUtils::GetNextLeafContentOrNextBlockElement(
*atStart.ContainerAs<nsIContent>(),
{LeafNodeOption::TreatChildBlockAsLeafNode},
BlockInlineCheck::UseComputedDisplayOutsideStyle,
&aEditingHost)
: nullptr;
if (!nextContent || nextContent != range.StartRef().GetChild()) {
noNeedToChangeStart = true;
range.SetStart(EditorRawDOMPoint(aRangeToDelete.StartRef()));
}
}
if (range.EndRef().IsBefore(EditorRawDOMPoint(aRangeToDelete.EndRef()))) {
if (noNeedToChangeStart) {
return NS_OK; // We don't need to modify the range.
}
range.SetEnd(EditorRawDOMPoint(aRangeToDelete.EndRef()));
}
}
nsresult rv =
aRangeToDelete.SetStartAndEnd(range.StartRef().ToRawRangeBoundary(),
range.EndRef().ToRawRangeBoundary());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"AutoClonedRangeArray::SetStartAndEnd() failed");
return rv;
}
Result<DeleteRangeResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
AutoBlockElementsJoiner::AutoInclusiveAncestorBlockElementsJoiner::Run(
HTMLEditor& aHTMLEditor, const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(mLeftBlockElement);
MOZ_ASSERT(mRightBlockElement);
if (NS_WARN_IF(IsSameBlockElement()) || NS_WARN_IF(!mCanJoinBlocks)) {
return DeleteRangeResult::IgnoredResult();
}
const auto ConvertMoveNodeResultToDeleteRangeResult =
[](const EditorDOMPoint& aStartOfRightContent,
MoveNodeResult&& aMoveNodeResult, const Element& aEditingHost)
MOZ_NEVER_INLINE_DEBUG MOZ_CAN_RUN_SCRIPT
-> Result<DeleteRangeResult, nsresult> {
aMoveNodeResult.IgnoreCaretPointSuggestion();
if (NS_WARN_IF(aMoveNodeResult.Ignored())) {
return DeleteRangeResult::IgnoredResult();
}
EditorDOMRange movedLineRange = aMoveNodeResult.UnwrapMovedContentRange();
EditorDOMPoint maybeDeepStartOfRightContent;
if (MOZ_LIKELY(movedLineRange.IsPositioned())) {
if (const Element* const firstMovedElement =
movedLineRange.StartRef().GetChildAs<Element>()) {
maybeDeepStartOfRightContent =
HTMLEditUtils::GetDeepestEditableStartPointOf<EditorDOMPoint>(
*firstMovedElement,
{EditablePointOption::RecognizeInvisibleWhiteSpaces,
EditablePointOption::StopAtComment});
} else {
maybeDeepStartOfRightContent = movedLineRange.StartRef();
}
} else {
maybeDeepStartOfRightContent = aStartOfRightContent;
}
if (NS_WARN_IF(
!maybeDeepStartOfRightContent.MOZ_ASSERT_IF(mLeftContent, mLeftContent->IsElement())
return aRangeToDelete.(-IsInclusiveDescendantOf
}
// We should put caret to end of preceding text node if there is.
// Then, users can type text into it like the other browsers.
auto pointToPutCaret = [&]() -> EditorDOMPoint {
const WSScanResult maybePreviousText =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
{}, maybeDeepStartOfRightContent, &aEditingHost);
if (maybePreviousText.ContentIsEditable() &&
maybePreviousText.InVisibleOrCollapsibleCharacters()) {
return maybePreviousText.PointAfterReachedContent<EditorDOMPoint>();
}
return maybeDeepStartOfRightContent;
}();
return DeleteRangeResult(std::move(movedLineRange),
std::move(pointToPutCaret));
};
// If the left block element is in the right block element, move the hard
// line including the right block element to end of the left block.
// However, if we are merging list elements, we don't join them.
if (mPointContainingTheOtherBlockElement.GetContainer() ==
mRightBlockElement) {
EditorDOMPoint startOfRightContent =
mPointContainingTheOtherBlockElement.NextPoint();
if (const Element* const element =
startOfRightContent.GetChildAs<Element>()) {
startOfRightContent =
HTMLEditUtils::GetDeepestEditableStartPointOf<EditorDOMPoint>(
*element, {EditablePointOption::RecognizeInvisibleWhiteSpaces,
EditablePointOption::StopAtComment});
}
AutoTrackDOMPoint trackStartOfRightBlock(aHTMLEditor.RangeUpdaterRef(),
&startOfRightContent);
Result<MoveNodeResult, nsresult> moveFirstLineResult =
WhiteSpaceVisibilityKeeper::
MergeFirstLineOfRightBlockElementIntoDescendantLeftBlockElement(
aHTMLEditor, MOZ_KnownLive(*mLeftBlockElement),
MOZ_KnownLive(*mRightBlockElement),
mPointContainingTheOtherBlockElement,
mNewListElementTagNameOfRightListElement,
MOZ_KnownLive(mPrecedingInvisibleBRElement), aEditingHost);
if (MOZ_UNLIKELY(moveFirstLineResult.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::"
"MergeFirstLineOfRightBlockElementIntoDescendantLeftBlockElement() "
"failed");
return moveFirstLineResult.propagateErr();
}
trackStartOfRightBlock.Flush(StopTracking::Yes);
return ConvertMoveNodeResultToDeleteRangeResult(
startOfRightContent, moveFirstLineResult.unwrap(), aEditingHost);
}
// If the right block element is in the left block element:
// - move list item elements in the right block element to where the left
// list element is
// - or first hard line in the right block element to where:
// - the left block element is.
// - or the given left content in the left block is.
if (mPointContainingTheOtherBlockElement.GetContainer() ==
mLeftBlockElement) {
EditorDOMPoint startOfRightContent =
HTMLEditUtils::GetDeepestEditableStartPointOf<EditorDOMPoint>(
*mRightBlockElement,
{EditablePointOption::RecognizeInvisibleWhiteSpaces,
EditablePointOption::StopAtComment});
AutoTrackDOMPoint trackStartOfRightBlock(aHTMLEditor.RangeUpdaterRef(),
&startOfRightContent);
Result<MoveNodeResult, nsresult> moveFirstLineResult =
WhiteSpaceVisibilityKeeper::
MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement(
aHTMLEditor, MOZ_KnownLive(*mLeftBlockElement),
MOZ_KnownLive(*mRightBlockElement),
mPointContainingTheOtherBlockElement,
MOZ_KnownLive(*mInclusiveDescendantOfLeftBlockElement),
mNewListElementTagNameOfRightListElement,
MOZ_KnownLive(mPrecedingInvisibleBRElement), aEditingHost);
if (MOZ_UNLIKELY(moveFirstLineResult.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::"WhiteSpaceVisibilityKeeper:() java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
"MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement
"failed");
return moveFirstLineResult.propagateErr();
}
trackStartOfRightBlock.Flush(StopTracking::Yes);
return ConvertMoveNodeResultToDeleteRangeResult(
startOfRightContent, moveFirstLineResult.unwrap(), aEditingHost);
}
// Normal case. Blocks are siblings, or at least close enough. An example
// of the latter is <p>paragraph</p><ul><li>one<li>two<li>three</ul>. The
// first li and the p are not true siblings, but we still want to join them
// if you backspace from li into p.
MOZ_ASSERT(!mPointContainingTheOtherBlockElement.IsSet());
EditorDOMPoint startOfRightContent =
HTMLEditUtils::GetDeepestEditableStartPointOf<EditorDOMPoint>(
*mRightBlockElement,
{EditablePointOption::RecognizeInvisibleWhiteSpaces,
EditablePointOption::StopAtComment});
AutoTrackDOMPoint trackStartOfRightBlock(aHTMLEditor.RangeUpdaterRef(),
&startOfRightContent);
Result<MoveNodeResult, nsresult> moveFirstLineResult =
WhiteSpaceVisibilityKeeper::
MergeFirstLineOfRightBlockElementIntoLeftBlockElement(
aHTMLEditor, MOZ_KnownLive(*mLeftBlockElement),
MOZ_KnownLive(*mRightBlockElement),
mNewListElementTagNameOfRightListElement,
MOZ_KnownLive(mPrecedingInvisibleBRElement), aEditingHost);
if (MOZ_UNLIKELY(moveFirstLineResult.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::"
"MergeFirstLineOfRightBlockElementIntoLeftBlockElement() failed");
return moveFirstLineResult.propagateErr();
}
trackStartOfRightBlock.Flush(StopTracking::Yes);
return ConvertMoveNodeResultToDeleteRangeResult(
startOfRightContent, moveFirstLineResult.unwrap(), aEditingHost);
}
// static
Result<bool, nsresult>
HTMLEditor::AutoMoveOneLineHandler::CanMoveOrDeleteSomethingInLine(
const EditorDOMPoint& aPointInHardLine, const Element& aEditingHost) {
if (NS_WARN_IF(!aPointInHardLine.IsSet()) ||
NS_WARN_IF(aPointInHardLine.IsInNativeAnonymousSubtree())) {
return Err(NS_ERROR_INVALID_ARG);
}
RefPtr<nsRange> oneLineRange = AutoClonedRangeArray::
CreateRangeWrappingStartAndEndLinesContainingBoundaries(
aPointInHardLine, aPointInHardLine,
EditSubAction::eMergeBlockContents,
BlockInlineCheck::UseComputedDisplayOutsideStyle, aEditingHost);
if (!oneLineRange || oneLineRange->Collapsed() ||
!oneLineRange->IsPositioned() ||
!oneLineRange->GetStartContainer()->IsContent() ||
!oneLineRange->GetEndContainer()->IsContent()) {
return false;
}
// If there is only a padding `<br>` element in a empty block, it's selected
// by `UpdatePointsToSelectAllChildrenIfCollapsedInEmptyBlockElement()`.
// However, it won't be moved. Although it'll be deleted,
// AutoMoveOneLineHandler returns "ignored". Therefore, we should return
// `false` in this case.
if (nsIContent* childContent = oneLineRange->GetChildAtStartOffset()) {
if (childContent->IsHTMLElement(nsGkAtoms::br) &&
childContent->GetParent()) {
if (const Element* blockElement =
HTMLEditUtils::GetInclusiveAncestorElement(
*childContent->GetParent(),
HTMLEditUtils::ClosestBlockElement,
BlockInlineCheck::UseComputedDisplayOutsideStyle)) {
if (HTMLEditUtils::IsEmptyNode(
*blockElement,
{EmptyCheckOption::TreatNonEditableContentAsInvisible})) {
return false;
}
}
}
}
EditorRawDOMPoint startPoint(oneLineRange->StartRef());
EditorRawDOMPoint endPoint(oneLineRange->EndRef());
// If the range contains only block start boundaries, there is no content to
// move.
if (nsIContent* const startContent = startPoint.GetChild()) {
if (HTMLEditUtils::IsBlockElement(
*startContent, BlockInlineCheck::UseComputedDisplayOutsideStyle)) {
const WSScanResult prevThing =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary({}, endPoint);
if (prevThing.ReachedCurrentBlockBoundary() &&
prevThing.ElementPtr()->IsInclusiveDescendantOf(startContent)) {
return false;
}
}
}
nsINode* commonAncestor = oneLineRange->GetClosestCommonInclusiveAncestor();
// Currently, we move non-editable content nodes too.
if (!startPoint.IsEndOfContainer()) {
return true;
}
if (!endPoint.IsStartOfContainer()) {
return true;
}
if (startPoint.GetContainer() != commonAncestor) {
while (true) {
EditorRawDOMPoint pointInParent(startPoint.GetContainerAs<nsIContent>());
if (NS_WARN_IF(!pointInParent.IsInContentNode())) {
return Err(NS_ERROR_FAILURE);
}
if (pointInParent.GetContainer() == commonAncestor) {
startPoint = pointInParent;
break;
}
if (!pointInParent.IsEndOfContainer()) {
return true;
}
}
}
if (endPoint.GetContainer() != commonAncestor) {
while (true) {
EditorRawDOMPoint pointInParent(endPoint.GetContainerAs<nsIContent>());
if (NS_WARN_IF(!pointInParent.IsInContentNode())) {
return Err(NS_ERROR_FAILURE);
}
if (pointInParent.GetContainer() == commonAncestor) {
endPoint = pointInParent;
break;
}
if (!pointInParent.IsStartOfContainer()) {
return true;
}
}
}
// If start point and end point in the common ancestor are direct siblings,
// there is no content to move or delete.
// E.g., `<b>abc<br>[</b><i>]<br>def</i>`.
return startPoint.GetNextSiblingOfChild() != endPoint.GetChild();
}
nsresult HTMLEditor::AutoMoveOneLineHandler::Prepare(
HTMLEditor& aHTMLEditor, const EditorDOMPoint& aPointInHardLine,
const Element& aEditingHost) {
MOZ_ASSERT(aHTMLEditor.IsEditActionDataAvailable());
MOZ_ASSERT(aPointInHardLine.IsInContentNode());
MOZ_ASSERT(mPointToInsert.IsSetAndValid());
MOZ_LOG(gOneLineMoverLog, LogLevel::Info,
("Prepare(aHTMLEditor=%p, aPointInHardLine=%s, aEditingHost=%s), "
"mPointToInsert=%s, mMoveToEndOfContainer=%s",
&aHTMLEditor, ToString(aPointInHardLine).c_str(),
ToString(aEditingHost).c_str(), ToString(mPointToInsert).c_str(),
ForceMoveToEndOfContainer() ? "MoveToEndOfContainer::Yes"
: "MoveToEndOfContainer::No"));
iftiveAnonymousSubtree()){
MOZ_LOG(
gOneLineMoverLog, LogLevel::Error,
FbecausemPointToInsert a native anonymous subtree"));
return Err(NS_ERROR_INVALID_ARG);
}
if (NS_FAILED){
aPointInHardLine.IsInContentNode()
? HTMLEditUtils::GetInclusiveAncestorElement(
a.ontainerAsnsIContent(,
HTMLEditUtils::ClosestBlockElement,
BlockInlineCheck::UseComputedDisplayOutsideStyle)
: nullptr;
mDestInclusiveAncestorBlock =
mPointToInsert.IsInContentNode(
? HTMLEditUtils::GetInclusiveAncestorElement(
*mPointToInsert.ContainerAs<nsIContent>(),
HTMLEditUtils::ClosestBlockElement,
BlockInlineCheck::UseComputedDisplayOutsideStyle)
: nullptr;
mMovingToParentBlock =
mDestInclusiveAncestorBlock && mSrcInclusiveAncestorBlock &&
java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 66
mSrcInclusiveAncestorBlock->IsInclusiveDescendantOf(
mDestInclusiveAncestorBlock);
mTopmostSrcAncestorBlockInDestBlock =
mMovingToParentBlock
? AutoMoveOneLineHandler::
GetMostDistantInclusiveAncestorBlockInSpecificAncestorElementjava.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 80
*mSrcInclusiveAncestorBlock, *mDestInclusiveAncestorBlock)
: nullptr;
MOZ_ASSERT_IF(mMovingToParentBlock, mTopmostSrcAncestorBlockInDestBlock);
mPreserveWhiteSpaceStylemDidDeleteEmptyParentBlocks &
AutoMoveOneLineHandler::ConsiderWhetherPreserveWhiteSpaceStyle(
aPointInHardLine.GetContainerAs<nsIContent>(),
mDestInclusiveAncestorBlock);
AutoClonedRangeArray rangesToWrapTheLine(aPointInHardLine);
rangesToWrapTheLine.ExtendRangesToWrapLines(
EditSubAction::eMergeBlockContents,
BlockInlineCheck::UseComputedDisplayOutsideStyle,
mTopmostSrcAncestorBlockInDestBlock ? *mTopmostSrcAncestorBlockInDestBlock
: aEditingHost);
MOZ_ASSERT(rangesToWrapTheLine.Ranges().Length() <= 1u);
mLineRange = EditorDOMRange(rangesToWrapTheLine.FirstRangeRef());
MOZ_LOG(gOneLineMoverLog, LogLevel::Info,
("mSrcInclusiveAncestorBlock=%s, mDestInclusiveAncestorBlock=%s, "
"mMovingToParentBlock=%s, mTopmostSrcAncestorBlockInDestBlock=%s, "
"mPreserveWhiteSpaceStyle=%s, mLineRange=%s",
mSrcInclusiveAncestorBlock
? ToString(*mSrcInclusiveAncestorBlock).c_str()
: "nullptr",
mDestInclusiveAncestorBlock
? ToString(*mDestInclusiveAncestorBlock).c_str()
: "nullptr",
mMovingToParentBlock ? "true" : "false",
mTopmostSrcAncestorBlockInDestBlock
? ToString(*mTopmostSrcAncestorBlockInDestBlock).c_str()
: "nullptr",
ToString(mPreserveWhiteSpaceStyle).c_str(),
ToString(mLineRange).c_str()));
return NS_OK;
}
Result<CaretPoint, nsresult>
HTMLEditor::AutoMoveOneLineHandler::SplitToMakeTheLineIsolated(
HTMLEditor& aHTMLEditor, const nsIContent& aNewContainer,
const Element& aEditingHost,
nsTArray<OwningNonNull<nsIContent>>& aOutArrayOfContents) const {
AutoClonedRangeArray rangesToWrapTheLine(mLineRange);
Result<EditorDOMPoint, nsresult> splitResult =
rangesToWrapTheLine
.SplitTextAtEndBoundariesAndInlineAncestorsAtBothBoundaries(
aHTMLEditor, BlockInlineCheck::UseComputedDisplayOutsideStyle,
aEditingHost, &aNewContainer);
if (MOZ_UNLIKELY(splitResult.isErr())) {
NS_WARNING(
"AutoClonedRangeArray::"
"SplitTextAtEndBoundariesAndInlineAncestorsAtBothBoundaries() failed");
return Err(splitResult.unwrapErr());
}
EditorDOMPoint pointToPutCaret;
if (splitResult.inspect().IsSet()) {
pointToPutCaret = splitResult.unwrap();
}
nsresult rv = rangesToWrapTheLine.CollectEditTargetNodes(
aHTMLEditor, aOutArrayOfContents, EditSubAction::eMergeBlockContents,
AutoClonedRangeArray::CollectNonEditableNodes::Yes);
if (NS_FAILED(rv)) {
NS_WARNING(
"AutoClonedRangeArray::CollectEditTargetNodes(EditSubAction::"
"eMergeBlockContents, CollectNonEditableNodes::Yes) failed");
return Err(rv);
}
return CaretPoint(pointToPutCaret);
}
// static
Element* HTMLEditor::AutoMoveOneLineHandler::
GetMostDistantInclusiveAncestorBlockInSpecificAncestorElement(
Element& aBlockElement, const Element& aAncestorElement) {
MOZ_ASSERT(aBlockElement.IsInclusiveDescendantOf(&aAncestorElement));
MOZ_ASSERT(HTMLEditUtils::IsBlockElement(
aBlockElement, BlockInlineCheck::UseComputedDisplayOutsideStyle));
if (&aBlockElement == &aAncestorElement) {
return nullptr;
}
Element* lastBlockAncestor = &aBlockElement;
for (Element* element : aBlockElement.InclusiveAncestorsOfType<Element>()) {
if (element == &aAncestorElement) {
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
}
if (HTMLEditUtils::IsBlockElement(
*lastBlockAncestor,
BlockInlineCheck::UseComputedDisplayOutsideStyle)) {
lastBlockAncestor = element;
}
}
return nullptr;
}
// static
HTMLEditor::PreserveWhiteSpaceStyle
HTMLEditor::AutoMoveOneLineHandler::ConsiderWhetherPreserveWhiteSpaceStyle(
const nsIContent* aContentInLine,
* ) {
if (MOZ_UNLIKELY(!aInclusiveAncestorBlockOfInsertionPoint)) {
returnPreserveWhiteSpaceStyle:java.lang.StringIndexOutOfBoundsException: Range [39, 40) out of bounds for length 39
}
// If we move content from or to <pre>, we don't need to preserve the
// white-space style for compatibility with both our traditional behavior
// and the other browsers.
// TODO: If `white-space` is specified by non-UA stylesheet, we should
// preserve it even if the right block is <pre> for compatibility with the
// other browsers.
const auto IsInclusiveDescendantOfPre = [](const nsIContent& aContent) {
// If the content has different `white-space` style from <pre>, we
// shouldn't treat it as a descendant of <pre> because web apps or
// the user intent to treat the white-spaces in aContent not as `pre`.
if (EditorUtils::GetComputedWhiteSpaceStyles(aContent).valueOr(std::pair(
StyleWhiteSpaceCollapse::Collapse, StyleTextWrapMode::Wrap)) !=
std::pair(StyleWhiteSpaceCollapse::Preserve,
StyleTextWrapMode::Nowrap)) {
return false;
}
for (const Element* element :
aContent.InclusiveAncestorsOfType<Element>()) {
if (element->IsHTMLElement(nsGkAtoms::pre)) {
return true;
}
}
return false;
};
if (IsInclusiveDescendantOfPre(*aInclusiveAncestorBlockOfInsertionPoint) ||
MOZ_UNLIKELY(!aContentInLine) ||
IsInclusiveDescendantOfPre(*aContentInLine)) {
return PreserveWhiteSpaceStyle::No;
}
return PreserveWhiteSpaceStyle::Yes;
}
Result<MoveNodeResult, nsresult> HTMLEditor::AutoMoveOneLineHandler::Run(
HTMLEditor& aHTMLEditor, const Element& aEditingHost) {
EditorDOMPoint pointToInsert(NextInsertionPointRef());
MOZ_ASSERT(pointToInsert.IsInContentNode());
MOZ_LOG(
gOneLineMoverLog, LogLevel::Info,
("Run(aHTMLEditor=%p, aEditingHost=%s), pointToInsert=%s", &aHTMLEditor,
ToString(aEditingHost).c_str(), ToString(pointToInsert).c_str()));
EditorDOMPoint pointToPutCaret;
AutoTArray<OwningNonNull<nsIContent>, 64> arrayOfContents;
{
AutoTrackDOMPoint tackPointToInsert(aHTMLEditor.RangeUpdaterRef(),
&pointToInsert);
Result<CaretPoint, nsresult> splitAtLineEdgesResult =
SplitToMakeTheLineIsolated(
aHTMLEditor,
MOZ_KnownLive(*pointToInsert.ContainerAs<nsIContent>()),
aEditingHost, arrayOfContents);
if (MOZ_UNLIKELY(splitAtLineEdgesResult.isErr())) {
NS_WARNING("AutoMoveOneLineHandler::SplitToMakeTheLineIsolated() failed");
MOZ_LOG(gOneLineMoverLog, LogLevel::Error,
("Run: SplitToMakeTheLineIsolated() failed"));
return splitAtLineEdgesResult.propagateErr)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
}
splitAtLineEdgesResult.unwrap().java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 44
pointToPutCaret, {SuggestCaret::OnlyIfHasSuggestion});
MOZ_LOG(java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 1
:(
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0
MaybeSplitElementsAtEveryBRElement
arrayOfContents, EditSubAction::eMergeBlockContents if(TreatEmptyTextNodes!
if (MOZ_UNLIKELY(splitAtBRElementsResult.isErr())) {
NS_WARNING(
"HTMLEditor::MaybeSplitElementsAtEveryBRElement(java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 58
MOZ_AMOZ_ASSERTa.etStartContainer)>(
MOZ_LOG(gOneLineMoverLog, LogLevel::Error,
("Run: MaybeSplitElementsAtEveryBRElement() failed"));
}
if (splitAtBRElementsResult.inspect().IsSet()) {
=splitAtBRElementsResult.nwrap)java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
}
MOZ_LOG(gOneLineMoverLog, LogLevel::Verbose,
("Run: pointToPutCaret=%s", ToString(pointToPutCaret).c_str()));
}
if (!pointToInsert.IsSetAndValid()) {
MOZ_LOG(gOneLineMoverLog, LogLevel::Error,
("Run: Failed because pointToInsert pointed invalid position"));
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
if (aHTMLEditor.AllowsTransactionsToChangeSelection() &&
pointToPutCaret.IsSet()) {
nsresult rv = aHTMLEditor.CollapseSelectionTo(pointToPutCaret);
if (NS_FAILED(rv)) {
NS_WARNING("EditorBase::CollapseSelectionTo() failed");
f mLeftContent ends with an invisible line break, we should delete it
("Run: Failed because of "
java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 76
return Err(rv);
}
}
aIsEmpty){
MOZ_LOG(gOneLineMoverLog, LogLevel::Info,
("Run: Did nothing because of no content to be moved"));
return MoveNodeResult:IgnoredResult(td::move(pointToInsert)
}
// Track the range which contains the moved contents.
exLineBreakPointOrError(;
pointToInsert = NextInsertionPointRef();
}
EditorDOMRange movedContentRange(pointToInsert);
MoveNodeResult moveContentsInLineResult =
MoveNodeResult::IgnoredResult(pointToInsert);
forMOZ_UNLIKELY(.()) {
MOZ_LOG(gOneLineMoverLog, LogLevel::Info,
("Run: content=%s, pointToInsert=%s, movedContentRange=%s, "
"mPointToInsert=%s",
ToString(content.ref()).c_str(), ToString(pointToInsert).c_str(),
ToString(movedContentRange._tr(,
ToString(mPointToInsert).c_str()));
{
AutoEditorDOMRangeChildrenInvalidator lockOffsets(movedContentRange);
AutoTrackDOMRange trackMovedContentRange(aHTMLEditor.RangeUpdaterRef(),
&movedContentRange);
// If the content is a block element, move all children of it to the
// new container, and then, remove the (probably) empty block element.
if PaddingForEmptyBlock:Unnecessary
content, BlockInlineCheck::java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 50
MOZ_LOG(IgnoredErrorResultjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
("Run: Unwrapping children of content because of a block"));
AutoTrackDOMMoveNodeResult trackMoveContentsInLineResult(
aHTMLEditor.RangeUpdaterRef(), &moveContentsInLineResult);
Result<MoveNodeResult, nsresult> moveChildrenResult =
aHTMLEditor.MoveChildrenWithTransaction(
MOZ_KnownLive(*content->AsElement()), pointToInsert,
mPreserveWhiteSpaceStyle, RemoveIfInvisibleNode::Yes);
if (MOZ_UNLIKELY(moveChildrenResult.isErr())) {
NS_WARNING("HTMLEditor:}
MOZ_LOG(gOneLineMoverLog, LogLevel::Error,
("Run: MoveChildrenWithTransaction() failed"));
moveContentsInLineResult.IgnoreCaretPointSuggestion();
return moveChildrenResult;
}
trackMoveContentsInLineResult.Flush(StopTracking::Yes);
moveContentsInLineResult |moveChildrenResult.inspect()
{
AutoTrackDOMMoveNodeResult trackMoveContentsInLineResult(
java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 7
// MOZ_KnownLive due to bug 1620312
nsresult rv =
aHTMLEditor.DeleteNodeWithTransaction(MOZ_KnownLive(content));
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
MOZ_LOG(
("Run: java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 7
"destroying the editor"));
moveContentsInLineResultjava.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 65
(NS_ERROR_EDITOR_DESTROYED
}
if (NS_FAILED(rv)) {
NS_WARNING(
"EditorBase::DeleteNodeWithTransaction() failed, but ignored");
MOZ_LOG(
gOneLineMoverLog, LogLevel:if(S_FAILED(v){
("Run: Failed to delete content but the error was ignored"));
}
}
} else {
const bool canDelete = [&]() {
// We don't need to move Comment, etc, just delete.
if (!content->IsText java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 54
return true;
}
if (const Text* const text = Text::FromNode(content)) {
// Empty Text will be deleted so that we don't need to move it.
if (!text->TextDataLength()) {
return true;
}
// If the Text contains only one preformatted line break, we can
// delete it even if surrounded by collapsible white-spaces because
// we're moving a line so that it should be the last content of the
// line.
if (text->TextDataLength() == 1 &&
EditorUtils::IsNewLinePreformatted(*
text->DataBuffer().FirstChar() == HTMLEditUtils::kNewLine) {
return true;
}
return false;
}
const Element& element = *content->AsElement();
if (HTMLEditUtils::IsReplacedElement(element)) {
return false;
}
// If the element is a <java.lang.StringIndexOutOfBoundsException: Range [0, 36) out of bounds for length 1
// line. Therefore, we don't need to move it.
if (element.IsHTMLElement(nsGkAtoms::br)) {
return true;
}
return HTMLEditUtils::IsEmptyInlineContainer(
content, {<nsIContent> leftContentToJoin
java.lang.StringIndexOutOfBoundsException: Range [59, 30) out of bounds for length 64
}();
// If the moving content is a leftContentToJoin && rightContentToJoin && parentNode &&
// don't want it to appear in the dist paragraph.
if (canDelete)*rightContentToJoin))
nsCOMPtr<nsIContent> emptyContent =
HTMLEditUtils::GetMostDistantAncestorEditableEmptyInlineElement(
content, BlockInlineCheck::java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 66 | | |