Bug 1926483 - part 4: Make WSRunScanner::Scan(InclusiveNext|Previous)VisibleNodeOrBlockBoundary take WSRunScanner::Scan and ancestor limiter r=m_kato

Note that this removes a lot of `aEditingHost` params.  This may cause odd
behavior if editing host is changed by a legacy mutation event listener.
However, it'll be completely deleted soon and even if we meet some regressions,
we can just restore the param to set `aAncestorLimiter`.

Differential Revision: https://phabricator.services.mozilla.com/D233794
This commit is contained in:
Masayuki Nakano
2025-01-24 05:00:48 +00:00
parent 649fa91881
commit b67e405f29
12 changed files with 194 additions and 182 deletions

View File

@@ -284,6 +284,11 @@ class EditorDOMPointBase final {
*/ */
bool IsContainerElement() const { return mParent && mParent->IsElement(); } bool IsContainerElement() const { return mParent && mParent->IsElement(); }
/**
* Returns true if the container node is an editing host.
*/
[[nodiscard]] bool IsContainerEditableRoot() const;
/** /**
* IsContainerHTMLElement() returns true if the container node is an HTML * IsContainerHTMLElement() returns true if the container node is an HTML
* element node and its node name is aTag. * element node and its node name is aTag.

View File

@@ -352,6 +352,15 @@ bool EditorDOMPointBase<
EditorUtils::IsOnlyNewLinePreformatted(*ContainerAs<Text>()); EditorUtils::IsOnlyNewLinePreformatted(*ContainerAs<Text>());
} }
template <typename PT, typename CT>
bool EditorDOMPointBase<PT, CT>::IsContainerEditableRoot() const {
if (MOZ_UNLIKELY(!mParent) || MOZ_UNLIKELY(!mParent->IsEditable()) ||
NS_WARN_IF(mParent->IsInNativeAnonymousSubtree())) {
return false;
}
return HTMLEditUtils::ElementIsEditableRoot(*mParent);
}
/****************************************************************************** /******************************************************************************
* mozilla::EditorDOMRangeBase * mozilla::EditorDOMRangeBase
*****************************************************************************/ *****************************************************************************/

View File

@@ -486,29 +486,26 @@ nsresult HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal() {
NS_WARNING("There was no selection range"); NS_WARNING("There was no selection range");
return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE; return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE;
} }
if (const RefPtr<Element> editingHost = Result<CreateLineBreakResult, nsresult>
ComputeEditingHost(LimitInBodyElement::No)) { insertPaddingBRElementResultOrError =
Result<CreateLineBreakResult, nsresult> InsertPaddingBRElementToMakeEmptyLineVisibleIfNeeded(
insertPaddingBRElementResultOrError = newCaretPosition);
InsertPaddingBRElementToMakeEmptyLineVisibleIfNeeded( if (MOZ_UNLIKELY(insertPaddingBRElementResultOrError.isErr())) {
newCaretPosition, *editingHost); NS_WARNING(
if (MOZ_UNLIKELY(insertPaddingBRElementResultOrError.isErr())) { "HTMLEditor::"
NS_WARNING( "InsertPaddingBRElementToMakeEmptyLineVisibleIfNeeded() failed");
"HTMLEditor::" return insertPaddingBRElementResultOrError.unwrapErr();
"InsertPaddingBRElementToMakeEmptyLineVisibleIfNeeded() failed");
return insertPaddingBRElementResultOrError.unwrapErr();
}
nsresult rv =
insertPaddingBRElementResultOrError.unwrap().SuggestCaretPointTo(
*this, {SuggestCaret::OnlyIfHasSuggestion});
if (NS_FAILED(rv)) {
NS_WARNING("CaretPoint::SuggestCaretPointTo() failed");
return rv;
}
NS_WARNING_ASSERTION(
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
"CaretPoint::SuggestCaretPointTo() failed, but ignored");
} }
nsresult rv =
insertPaddingBRElementResultOrError.unwrap().SuggestCaretPointTo(
*this, {SuggestCaret::OnlyIfHasSuggestion});
if (NS_FAILED(rv)) {
NS_WARNING("CaretPoint::SuggestCaretPointTo() failed");
return rv;
}
NS_WARNING_ASSERTION(
rv != NS_SUCCESS_EDITOR_BUT_IGNORED_TRIVIAL_ERROR,
"CaretPoint::SuggestCaretPointTo() failed, but ignored");
} }
// add in any needed <br>s, and remove any unneeded ones. // add in any needed <br>s, and remove any unneeded ones.
@@ -1208,7 +1205,7 @@ Result<EditActionResult, nsresult> HTMLEditor::HandleInsertText(
const InsertTextResult insertEmptyTextResult = const InsertTextResult insertEmptyTextResult =
insertEmptyTextResultOrError.unwrap(); insertEmptyTextResultOrError.unwrap();
nsresult rv = EnsureNoFollowingUnnecessaryLineBreak( nsresult rv = EnsureNoFollowingUnnecessaryLineBreak(
insertEmptyTextResult.EndOfInsertedTextRef(), *editingHost); insertEmptyTextResult.EndOfInsertedTextRef());
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING( NS_WARNING(
"HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed"); "HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
@@ -1257,7 +1254,7 @@ Result<EditActionResult, nsresult> HTMLEditor::HandleInsertText(
} }
InsertTextResult unwrappedReplacedTextResult = replaceTextResult.unwrap(); InsertTextResult unwrappedReplacedTextResult = replaceTextResult.unwrap();
nsresult rv = EnsureNoFollowingUnnecessaryLineBreak( nsresult rv = EnsureNoFollowingUnnecessaryLineBreak(
unwrappedReplacedTextResult.EndOfInsertedTextRef(), *editingHost); unwrappedReplacedTextResult.EndOfInsertedTextRef());
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed"); NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv); return Err(rv);
@@ -1532,8 +1529,7 @@ Result<EditActionResult, nsresult> HTMLEditor::HandleInsertText(
mLastCollapsibleWhiteSpaceAppendedTextNode = mLastCollapsibleWhiteSpaceAppendedTextNode =
currentPoint.ContainerAs<Text>(); currentPoint.ContainerAs<Text>();
} }
nsresult rv = nsresult rv = EnsureNoFollowingUnnecessaryLineBreak(currentPoint);
EnsureNoFollowingUnnecessaryLineBreak(currentPoint, *editingHost);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed"); NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv); return Err(rv);
@@ -1661,7 +1657,8 @@ nsresult HTMLEditor::InsertLineBreakAsSubAction() {
} }
const WSScanResult backwardScanFromBeforeBRElementResult = const WSScanResult backwardScanFromBeforeBRElementResult =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
editingHost, insertLineBreakResult.AtLineBreak<EditorDOMPoint>(), WSRunScanner::Scan::EditableNodes,
insertLineBreakResult.AtLineBreak<EditorDOMPoint>(),
BlockInlineCheck::UseComputedDisplayStyle); BlockInlineCheck::UseComputedDisplayStyle);
if (MOZ_UNLIKELY(backwardScanFromBeforeBRElementResult.Failed())) { if (MOZ_UNLIKELY(backwardScanFromBeforeBRElementResult.Failed())) {
NS_WARNING( NS_WARNING(
@@ -1671,7 +1668,7 @@ nsresult HTMLEditor::InsertLineBreakAsSubAction() {
const WSScanResult forwardScanFromAfterBRElementResult = const WSScanResult forwardScanFromAfterBRElementResult =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
editingHost, pointToPutCaret, WSRunScanner::Scan::EditableNodes, pointToPutCaret,
BlockInlineCheck::UseComputedDisplayStyle); BlockInlineCheck::UseComputedDisplayStyle);
if (MOZ_UNLIKELY(forwardScanFromAfterBRElementResult.Failed())) { if (MOZ_UNLIKELY(forwardScanFromAfterBRElementResult.Failed())) {
NS_WARNING("WSRunScanner::ScanNextVisibleNodeOrBlockBoundary() failed"); NS_WARNING("WSRunScanner::ScanNextVisibleNodeOrBlockBoundary() failed");
@@ -1901,7 +1898,7 @@ HTMLEditor::InsertParagraphSeparatorAsSubAction(const Element& aEditingHost) {
// table cell boundaries? // table cell boundaries?
Result<CaretPoint, nsresult> caretPointOrError = Result<CaretPoint, nsresult> caretPointOrError =
HandleInsertParagraphInMailCiteElement(*mailCiteElement, HandleInsertParagraphInMailCiteElement(*mailCiteElement,
pointToInsert, aEditingHost); pointToInsert);
if (MOZ_UNLIKELY(caretPointOrError.isErr())) { if (MOZ_UNLIKELY(caretPointOrError.isErr())) {
NS_WARNING( NS_WARNING(
"HTMLEditor::HandleInsertParagraphInMailCiteElement() failed"); "HTMLEditor::HandleInsertParagraphInMailCiteElement() failed");
@@ -2472,7 +2469,7 @@ Result<CreateElementResult, nsresult> HTMLEditor::HandleInsertBRElement(
const WSScanResult forwardScanFromAfterBRElementResult = const WSScanResult forwardScanFromAfterBRElementResult =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, afterBRElement, WSRunScanner::Scan::EditableNodes, afterBRElement,
BlockInlineCheck::UseComputedDisplayStyle); BlockInlineCheck::UseComputedDisplayStyle);
if (MOZ_UNLIKELY(forwardScanFromAfterBRElementResult.Failed())) { if (MOZ_UNLIKELY(forwardScanFromAfterBRElementResult.Failed())) {
NS_WARNING("WSRunScanner::ScanNextVisibleNodeOrBlockBoundary() failed"); NS_WARNING("WSRunScanner::ScanNextVisibleNodeOrBlockBoundary() failed");
@@ -2687,8 +2684,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::HandleInsertLinefeed(
} }
Result<CaretPoint, nsresult> HTMLEditor::HandleInsertParagraphInMailCiteElement( Result<CaretPoint, nsresult> HTMLEditor::HandleInsertParagraphInMailCiteElement(
Element& aMailCiteElement, const EditorDOMPoint& aPointToSplit, Element& aMailCiteElement, const EditorDOMPoint& aPointToSplit) {
const Element& aEditingHost) {
MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(aPointToSplit.IsSet()); MOZ_ASSERT(aPointToSplit.IsSet());
NS_ASSERTION(!HTMLEditUtils::IsEmptyNode( NS_ASSERTION(!HTMLEditUtils::IsEmptyNode(
@@ -2711,7 +2707,8 @@ Result<CaretPoint, nsresult> HTMLEditor::HandleInsertParagraphInMailCiteElement(
// mailquote may affect wrapping behavior, or font color, etc. // mailquote may affect wrapping behavior, or font color, etc.
const WSScanResult forwardScanFromPointToSplitResult = const WSScanResult forwardScanFromPointToSplitResult =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, pointToSplit, BlockInlineCheck::UseHTMLDefaultStyle); WSRunScanner::Scan::EditableNodes, pointToSplit,
BlockInlineCheck::UseHTMLDefaultStyle);
if (forwardScanFromPointToSplitResult.Failed()) { if (forwardScanFromPointToSplitResult.Failed()) {
return Err(NS_ERROR_FAILURE); return Err(NS_ERROR_FAILURE);
} }
@@ -2831,7 +2828,7 @@ Result<CaretPoint, nsresult> HTMLEditor::HandleInsertParagraphInMailCiteElement(
// resultOfInsertingBRElement.inspect()? // resultOfInsertingBRElement.inspect()?
const WSScanResult backwardScanFromPointToCreateNewBRElementResult = const WSScanResult backwardScanFromPointToCreateNewBRElementResult =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
&aEditingHost, pointToCreateNewBRElement, WSRunScanner::Scan::EditableNodes, pointToCreateNewBRElement,
BlockInlineCheck::UseHTMLDefaultStyle); BlockInlineCheck::UseHTMLDefaultStyle);
if (MOZ_UNLIKELY( if (MOZ_UNLIKELY(
backwardScanFromPointToCreateNewBRElementResult.Failed())) { backwardScanFromPointToCreateNewBRElementResult.Failed())) {
@@ -2848,7 +2845,7 @@ Result<CaretPoint, nsresult> HTMLEditor::HandleInsertParagraphInMailCiteElement(
} }
const WSScanResult forwardScanFromPointAfterNewBRElementResult = const WSScanResult forwardScanFromPointAfterNewBRElementResult =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint::After(pointToCreateNewBRElement), EditorRawDOMPoint::After(pointToCreateNewBRElement),
BlockInlineCheck::UseHTMLDefaultStyle); BlockInlineCheck::UseHTMLDefaultStyle);
if (MOZ_UNLIKELY(forwardScanFromPointAfterNewBRElementResult.Failed())) { if (MOZ_UNLIKELY(forwardScanFromPointAfterNewBRElementResult.Failed())) {
@@ -3407,8 +3404,7 @@ HTMLEditor::DeleteTextAndNormalizeSurroundingWhiteSpaces(
{ {
AutoTrackDOMPoint trackPointToPutCaret(RangeUpdaterRef(), AutoTrackDOMPoint trackPointToPutCaret(RangeUpdaterRef(),
&newCaretPosition); &newCaretPosition);
nsresult rv = nsresult rv = EnsureNoFollowingUnnecessaryLineBreak(newCaretPosition);
EnsureNoFollowingUnnecessaryLineBreak(newCaretPosition, aEditingHost);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed"); NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv); return Err(rv);
@@ -3464,7 +3460,7 @@ bool HTMLEditor::CanInsertLineBreak(LineBreakType aLineBreakType,
Result<CreateLineBreakResult, nsresult> Result<CreateLineBreakResult, nsresult>
HTMLEditor::InsertPaddingBRElementToMakeEmptyLineVisibleIfNeeded( HTMLEditor::InsertPaddingBRElementToMakeEmptyLineVisibleIfNeeded(
const EditorDOMPoint& aPointToInsert, const Element& aEditingHost) { const EditorDOMPoint& aPointToInsert) {
MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(aPointToInsert.IsSet()); MOZ_ASSERT(aPointToInsert.IsSet());
@@ -3487,7 +3483,7 @@ HTMLEditor::InsertPaddingBRElementToMakeEmptyLineVisibleIfNeeded(
// here. // here.
const WSScanResult previousThing = const WSScanResult previousThing =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
&aEditingHost, aPointToInsert, WSRunScanner::Scan::EditableNodes, aPointToInsert,
BlockInlineCheck::UseComputedDisplayStyle); BlockInlineCheck::UseComputedDisplayStyle);
if (!previousThing.ReachedLineBoundary()) { if (!previousThing.ReachedLineBoundary()) {
return CreateLineBreakResult::NotHandled(); return CreateLineBreakResult::NotHandled();
@@ -3497,7 +3493,7 @@ HTMLEditor::InsertPaddingBRElementToMakeEmptyLineVisibleIfNeeded(
// line break here. // line break here.
const WSScanResult nextThing = const WSScanResult nextThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, aPointToInsert, WSRunScanner::Scan::EditableNodes, aPointToInsert,
BlockInlineCheck::UseComputedDisplayStyle); BlockInlineCheck::UseComputedDisplayStyle);
if (!nextThing.ReachedBlockBoundary()) { if (!nextThing.ReachedBlockBoundary()) {
return CreateLineBreakResult::NotHandled(); return CreateLineBreakResult::NotHandled();
@@ -7043,8 +7039,7 @@ Result<EditorDOMPoint, nsresult> HTMLEditor::CreateStyleForInsertText(
NS_WARNING("AutoClonedRangeArray::AutoClonedRangeArray() failed"); NS_WARNING("AutoClonedRangeArray::AutoClonedRangeArray() failed");
return Err(NS_ERROR_FAILURE); return Err(NS_ERROR_FAILURE);
} }
nsresult rv = nsresult rv = SetInlinePropertiesAroundRanges(ranges, stylesToSet);
SetInlinePropertiesAroundRanges(ranges, stylesToSet, aEditingHost);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::SetInlinePropertiesAroundRanges() failed"); NS_WARNING("HTMLEditor::SetInlinePropertiesAroundRanges() failed");
return Err(rv); return Err(rv);
@@ -9177,7 +9172,8 @@ HTMLEditor::HandleInsertParagraphInListItemElement(
// the element is proper position. // the element is proper position.
const WSScanResult forwardScanFromStartOfListItemResult = const WSScanResult forwardScanFromStartOfListItemResult =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, EditorRawDOMPoint(&rightListItemElement, 0u), WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint(&rightListItemElement, 0u),
BlockInlineCheck::UseComputedDisplayStyle); BlockInlineCheck::UseComputedDisplayStyle);
if (MOZ_UNLIKELY(forwardScanFromStartOfListItemResult.Failed())) { if (MOZ_UNLIKELY(forwardScanFromStartOfListItemResult.Failed())) {
NS_WARNING("WSRunScanner::ScanNextVisibleNodeOrBlockBoundary() failed"); NS_WARNING("WSRunScanner::ScanNextVisibleNodeOrBlockBoundary() failed");
@@ -11212,7 +11208,7 @@ HTMLEditor::InsertPaddingBRElementIfNeeded(
if (IsPlaintextMailComposer()) { if (IsPlaintextMailComposer()) {
const WSScanResult nextVisibleThing = const WSScanResult nextVisibleThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, aPoint, WSRunScanner::Scan::EditableNodes, aPoint,
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (nextVisibleThing.ReachedBlockBoundary() && if (nextVisibleThing.ReachedBlockBoundary() &&
HTMLEditUtils::IsMailCite(*nextVisibleThing.ElementPtr()) && HTMLEditUtils::IsMailCite(*nextVisibleThing.ElementPtr()) &&

View File

@@ -41,6 +41,7 @@
#include "nsError.h" // for NS_SUCCEEDED #include "nsError.h" // for NS_SUCCEEDED
#include "nsGkAtoms.h" // for nsGkAtoms, nsGkAtoms::a, etc. #include "nsGkAtoms.h" // for nsGkAtoms, nsGkAtoms::a, etc.
#include "nsHTMLTags.h" #include "nsHTMLTags.h"
#include "nsIContentInlines.h" // for nsIContent::IsInDesignMode(), etc.
#include "nsIFrameInlines.h" // for nsIFrame::IsFlexOrGridItem() #include "nsIFrameInlines.h" // for nsIFrame::IsFlexOrGridItem()
#include "nsLiteralString.h" // for NS_LITERAL_STRING #include "nsLiteralString.h" // for NS_LITERAL_STRING
#include "nsNameSpaceManager.h" // for kNameSpaceID_None #include "nsNameSpaceManager.h" // for kNameSpaceID_None
@@ -125,13 +126,13 @@ template EditorRawDOMPoint HTMLEditUtils::GetBetterInsertionPointFor(
const nsIContent& aContentToInsert, const EditorDOMPoint& aPointToInsert); const nsIContent& aContentToInsert, const EditorDOMPoint& aPointToInsert);
template EditorDOMPoint HTMLEditUtils::GetBetterCaretPositionToInsertText( template EditorDOMPoint HTMLEditUtils::GetBetterCaretPositionToInsertText(
const EditorDOMPoint& aPoint, const Element& aEditingHost); const EditorDOMPoint& aPoint);
template EditorDOMPoint HTMLEditUtils::GetBetterCaretPositionToInsertText( template EditorDOMPoint HTMLEditUtils::GetBetterCaretPositionToInsertText(
const EditorRawDOMPoint& aPoint, const Element& aEditingHost); const EditorRawDOMPoint& aPoint);
template EditorRawDOMPoint HTMLEditUtils::GetBetterCaretPositionToInsertText( template EditorRawDOMPoint HTMLEditUtils::GetBetterCaretPositionToInsertText(
const EditorDOMPoint& aPoint, const Element& aEditingHost); const EditorDOMPoint& aPoint);
template EditorRawDOMPoint HTMLEditUtils::GetBetterCaretPositionToInsertText( template EditorRawDOMPoint HTMLEditUtils::GetBetterCaretPositionToInsertText(
const EditorRawDOMPoint& aPoint, const Element& aEditingHost); const EditorRawDOMPoint& aPoint);
template Result<EditorDOMPoint, nsresult> template Result<EditorDOMPoint, nsresult>
HTMLEditUtils::ComputePointToPutCaretInElementIfOutside( HTMLEditUtils::ComputePointToPutCaretInElementIfOutside(
@@ -152,48 +153,54 @@ template bool HTMLEditUtils::IsSameCSSColorValue(const nsACString& aColorA,
const nsACString& aColorB); const nsACString& aColorB);
template Maybe<EditorLineBreak> HTMLEditUtils::GetFollowingUnnecessaryLineBreak( template Maybe<EditorLineBreak> HTMLEditUtils::GetFollowingUnnecessaryLineBreak(
const EditorDOMPoint& aPoint, const Element& aEditingHost); const EditorDOMPoint& aPoint);
template Maybe<EditorLineBreak> HTMLEditUtils::GetFollowingUnnecessaryLineBreak( template Maybe<EditorLineBreak> HTMLEditUtils::GetFollowingUnnecessaryLineBreak(
const EditorRawDOMPoint& aPoint, const Element& aEditingHost); const EditorRawDOMPoint& aPoint);
template Maybe<EditorLineBreak> HTMLEditUtils::GetFollowingUnnecessaryLineBreak( template Maybe<EditorLineBreak> HTMLEditUtils::GetFollowingUnnecessaryLineBreak(
const EditorDOMPointInText& aPoint, const Element& aEditingHost); const EditorDOMPointInText& aPoint);
template Maybe<EditorLineBreak> HTMLEditUtils::GetFollowingUnnecessaryLineBreak( template Maybe<EditorLineBreak> HTMLEditUtils::GetFollowingUnnecessaryLineBreak(
const EditorRawDOMPointInText& aPoint, const Element& aEditingHost); const EditorRawDOMPointInText& aPoint);
template Maybe<EditorRawLineBreak> template Maybe<EditorRawLineBreak>
HTMLEditUtils::GetFollowingUnnecessaryLineBreak(const EditorDOMPoint& aPoint, HTMLEditUtils::GetFollowingUnnecessaryLineBreak(const EditorDOMPoint& aPoint);
const Element& aEditingHost);
template Maybe<EditorRawLineBreak>
HTMLEditUtils::GetFollowingUnnecessaryLineBreak(const EditorRawDOMPoint& aPoint,
const Element& aEditingHost);
template Maybe<EditorRawLineBreak> template Maybe<EditorRawLineBreak>
HTMLEditUtils::GetFollowingUnnecessaryLineBreak( HTMLEditUtils::GetFollowingUnnecessaryLineBreak(
const EditorDOMPointInText& aPoint, const Element& aEditingHost); const EditorRawDOMPoint& aPoint);
template Maybe<EditorRawLineBreak> template Maybe<EditorRawLineBreak>
HTMLEditUtils::GetFollowingUnnecessaryLineBreak( HTMLEditUtils::GetFollowingUnnecessaryLineBreak(
const EditorRawDOMPointInText& aPoint, const Element& aEditingHost); const EditorDOMPointInText& aPoint);
template Maybe<EditorRawLineBreak>
HTMLEditUtils::GetFollowingUnnecessaryLineBreak(
const EditorRawDOMPointInText& aPoint);
template bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary( template bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary(
const EditorDOMPoint& aPoint, const EditorDOMPoint& aPoint,
IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak, IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak);
const Element& aEditingHost);
template bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary( template bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary(
const EditorRawDOMPoint& aPoint, const EditorRawDOMPoint& aPoint,
IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak, IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak);
const Element& aEditingHost);
template bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary( template bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary(
const EditorDOMPointInText& aPoint, const EditorDOMPointInText& aPoint,
IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak, IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak);
const Element& aEditingHost);
template bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary( template bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary(
const EditorRawDOMPointInText& aPoint, const EditorRawDOMPointInText& aPoint,
IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak, IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak);
const Element& aEditingHost);
template Maybe<EditorLineBreak> HTMLEditUtils::GetUnnecessaryLineBreak( template Maybe<EditorLineBreak> HTMLEditUtils::GetUnnecessaryLineBreak(
const Element& aBlockElement, ScanLineBreak aScanLineBreak); const Element& aBlockElement, ScanLineBreak aScanLineBreak);
template Maybe<EditorRawLineBreak> HTMLEditUtils::GetUnnecessaryLineBreak( template Maybe<EditorRawLineBreak> HTMLEditUtils::GetUnnecessaryLineBreak(
const Element& aBlockElement, ScanLineBreak aScanLineBreak); const Element& aBlockElement, ScanLineBreak aScanLineBreak);
bool HTMLEditUtils::ElementIsEditableRoot(const Element& aElement) {
MOZ_ASSERT(!aElement.IsInNativeAnonymousSubtree());
if (NS_WARN_IF(!aElement.IsEditable()) ||
NS_WARN_IF(!aElement.IsInComposedDoc())) {
return false;
}
return !aElement.GetParent() || // root element
!aElement.GetParent()->IsEditable() || // editing host
aElement.OwnerDoc()->GetBody() == &aElement; // the <body>
}
bool HTMLEditUtils::CanContentsBeJoined(const nsIContent& aLeftContent, bool HTMLEditUtils::CanContentsBeJoined(const nsIContent& aLeftContent,
const nsIContent& aRightContent) { const nsIContent& aRightContent) {
if (aLeftContent.NodeInfo()->NameAtom() != if (aLeftContent.NodeInfo()->NameAtom() !=
@@ -809,7 +816,7 @@ EditorDOMPoint HTMLEditUtils::LineRequiresPaddingLineBreakToBeVisible(
} }
const WSScanResult nextThing = const WSScanResult nextThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, point, WSRunScanner::Scan::EditableNodes, point,
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (nextThing.ReachedBlockBoundary()) { if (nextThing.ReachedBlockBoundary()) {
if (nextThing.ReachedCurrentBlockBoundary()) { if (nextThing.ReachedCurrentBlockBoundary()) {
@@ -831,7 +838,7 @@ EditorDOMPoint HTMLEditUtils::LineRequiresPaddingLineBreakToBeVisible(
} }
const WSScanResult previousThing = const WSScanResult previousThing =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
&aEditingHost, preferredPaddingLineBreakPoint, WSRunScanner::Scan::EditableNodes, preferredPaddingLineBreakPoint,
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (previousThing.ContentIsText()) { if (previousThing.ContentIsText()) {
if (MOZ_UNLIKELY(!previousThing.TextPtr()->TextDataLength())) { if (MOZ_UNLIKELY(!previousThing.TextPtr()->TextDataLength())) {
@@ -982,16 +989,15 @@ Element* HTMLEditUtils::GetElementOfImmediateBlockBoundary(
template <typename PT, typename CT> template <typename PT, typename CT>
bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary( bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary(
const EditorDOMPointBase<PT, CT>& aPoint, const EditorDOMPointBase<PT, CT>& aPoint,
IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak, IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak) {
const Element& aEditingHost) {
MOZ_ASSERT(aPoint.IsSetAndValidInComposedDoc()); MOZ_ASSERT(aPoint.IsSetAndValidInComposedDoc());
if (MOZ_UNLIKELY(!aPoint.IsInContentNode())) { if (MOZ_UNLIKELY(!aPoint.IsInContentNode())) {
return false; return false;
} }
WSScanResult nextThing = const WSScanResult nextThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, aPoint, WSRunScanner::Scan::EditableNodes, aPoint,
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (nextThing.ReachedCurrentBlockBoundary()) { if (nextThing.ReachedCurrentBlockBoundary()) {
return true; return true;
@@ -1000,9 +1006,9 @@ bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary(
if (aIgnoreInvisibleLineBreak == IgnoreInvisibleLineBreak::No) { if (aIgnoreInvisibleLineBreak == IgnoreInvisibleLineBreak::No) {
return false; return false;
} }
WSScanResult afterInvisibleBRThing = const WSScanResult afterInvisibleBRThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
nextThing.PointAfterReachedContent<EditorRawDOMPoint>(), nextThing.PointAfterReachedContent<EditorRawDOMPoint>(),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
return afterInvisibleBRThing.ReachedCurrentBlockBoundary(); return afterInvisibleBRThing.ReachedCurrentBlockBoundary();
@@ -1011,9 +1017,9 @@ bool HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary(
if (aIgnoreInvisibleLineBreak == IgnoreInvisibleLineBreak::No) { if (aIgnoreInvisibleLineBreak == IgnoreInvisibleLineBreak::No) {
return false; return false;
} }
WSScanResult afterPreformattedLineBreakThing = const WSScanResult afterPreformattedLineBreakThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
nextThing.PointAfterReachedContent<EditorRawDOMPoint>(), nextThing.PointAfterReachedContent<EditorRawDOMPoint>(),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
return afterPreformattedLineBreakThing.ReachedCurrentBlockBoundary(); return afterPreformattedLineBreakThing.ReachedCurrentBlockBoundary();
@@ -1192,22 +1198,23 @@ Maybe<EditorLineBreakType> HTMLEditUtils::GetUnnecessaryLineBreak(
template <typename EditorLineBreakType, typename EditorDOMPointType> template <typename EditorLineBreakType, typename EditorDOMPointType>
Maybe<EditorLineBreakType> HTMLEditUtils::GetFollowingUnnecessaryLineBreak( Maybe<EditorLineBreakType> HTMLEditUtils::GetFollowingUnnecessaryLineBreak(
const EditorDOMPointType& aPoint, const Element& aEditingHost) { const EditorDOMPointType& aPoint) {
MOZ_ASSERT(aPoint.IsSetAndValid()); MOZ_ASSERT(aPoint.IsSetAndValid());
MOZ_ASSERT(aPoint.IsInContentNode()); MOZ_ASSERT(aPoint.IsInContentNode());
WSScanResult nextThing = const WSScanResult nextThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, aPoint, BlockInlineCheck::UseComputedDisplayStyle); WSRunScanner::Scan::EditableNodes, aPoint,
BlockInlineCheck::UseComputedDisplayStyle);
if (!nextThing.ReachedBRElement() && if (!nextThing.ReachedBRElement() &&
!(nextThing.ReachedPreformattedLineBreak() && !(nextThing.ReachedPreformattedLineBreak() &&
nextThing.PointAtReachedContent<EditorRawDOMPoint>() nextThing.PointAtReachedContent<EditorRawDOMPoint>()
.IsAtLastContent())) { .IsAtLastContent())) {
return Nothing(); // no line break next to aPoint return Nothing(); // no line break next to aPoint
} }
WSScanResult nextThingOfLineBreak = const WSScanResult nextThingOfLineBreak =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
nextThing.PointAfterReachedContent<EditorRawDOMPoint>(), nextThing.PointAfterReachedContent<EditorRawDOMPoint>(),
BlockInlineCheck::UseComputedDisplayStyle); BlockInlineCheck::UseComputedDisplayStyle);
const Element* const blockElement = const Element* const blockElement =
@@ -2540,12 +2547,12 @@ nsIContent* HTMLEditUtils::GetContentToPreserveInlineStyles(
for (auto point = aPoint.template To<EditorRawDOMPoint>(); point.IsSet();) { for (auto point = aPoint.template To<EditorRawDOMPoint>(); point.IsSet();) {
const WSScanResult nextVisibleThing = const WSScanResult nextVisibleThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, point, WSRunScanner::Scan::EditableNodes, point,
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (nextVisibleThing.InVisibleOrCollapsibleCharacters()) { if (nextVisibleThing.InVisibleOrCollapsibleCharacters()) {
return nextVisibleThing.TextPtr(); return nextVisibleThing.TextPtr();
} }
if (nextVisibleThing.GetContent() == &aEditingHost) { if (nextVisibleThing.IsContentEditableRoot()) {
break; break;
} }
// Ignore empty inline container elements because it's not visible for // Ignore empty inline container elements because it's not visible for
@@ -2631,10 +2638,9 @@ EditorDOMPointType HTMLEditUtils::GetBetterInsertionPointFor(
// static // static
template <typename EditorDOMPointType, typename EditorDOMPointTypeInput> template <typename EditorDOMPointType, typename EditorDOMPointTypeInput>
EditorDOMPointType HTMLEditUtils::GetBetterCaretPositionToInsertText( EditorDOMPointType HTMLEditUtils::GetBetterCaretPositionToInsertText(
const EditorDOMPointTypeInput& aPoint, const Element& aEditingHost) { const EditorDOMPointTypeInput& aPoint) {
MOZ_ASSERT(aPoint.IsSetAndValid()); MOZ_ASSERT(aPoint.IsSetAndValid());
MOZ_ASSERT( MOZ_ASSERT(HTMLEditUtils::IsSimplyEditableNode(*aPoint.GetContainer()));
aPoint.GetContainer()->IsInclusiveFlatTreeDescendantOf(&aEditingHost));
if (aPoint.IsInTextNode()) { if (aPoint.IsInTextNode()) {
return aPoint.template To<EditorDOMPointType>(); return aPoint.template To<EditorDOMPointType>();
@@ -2646,7 +2652,8 @@ EditorDOMPointType HTMLEditUtils::GetBetterCaretPositionToInsertText(
if (aPoint.IsEndOfContainer()) { if (aPoint.IsEndOfContainer()) {
const WSScanResult previousThing = const WSScanResult previousThing =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
&aEditingHost, aPoint, BlockInlineCheck::UseComputedDisplayStyle); WSRunScanner::Scan::EditableNodes, aPoint,
BlockInlineCheck::UseComputedDisplayStyle);
if (previousThing.InVisibleOrCollapsibleCharacters()) { if (previousThing.InVisibleOrCollapsibleCharacters()) {
return EditorDOMPointType::AtEndOf(*previousThing.TextPtr()); return EditorDOMPointType::AtEndOf(*previousThing.TextPtr());
} }
@@ -2655,7 +2662,7 @@ EditorDOMPointType HTMLEditUtils::GetBetterCaretPositionToInsertText(
*nsGkAtoms::textTagName)) { *nsGkAtoms::textTagName)) {
return aPoint.template To<EditorDOMPointType>(); return aPoint.template To<EditorDOMPointType>();
} }
if (MOZ_UNLIKELY(aPoint.GetContainer() == &aEditingHost || if (MOZ_UNLIKELY(aPoint.GetContainer()->IsEditingHost() ||
!aPoint.template GetContainerParentAs<nsIContent>() || !aPoint.template GetContainerParentAs<nsIContent>() ||
!HTMLEditUtils::CanNodeContain( !HTMLEditUtils::CanNodeContain(
*aPoint.template ContainerParentAs<nsIContent>(), *aPoint.template ContainerParentAs<nsIContent>(),

View File

@@ -76,6 +76,14 @@ class HTMLEditUtils final {
return aNode.IsEditable(); return aNode.IsEditable();
} }
/**
* Return true if aElement is an editing host which is either:
* - the root element
* - parent is not editable
* - the <body> element of the document
*/
[[nodiscard]] static bool ElementIsEditableRoot(const Element& aElement);
/** /**
* Return true if inclusive flat tree ancestor has `inert` state. * Return true if inclusive flat tree ancestor has `inert` state.
*/ */
@@ -540,8 +548,7 @@ class HTMLEditUtils final {
template <typename PT, typename CT> template <typename PT, typename CT>
[[nodiscard]] static bool PointIsImmediatelyBeforeCurrentBlockBoundary( [[nodiscard]] static bool PointIsImmediatelyBeforeCurrentBlockBoundary(
const EditorDOMPointBase<PT, CT>& aPoint, const EditorDOMPointBase<PT, CT>& aPoint,
IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak, IgnoreInvisibleLineBreak aIgnoreInvisibleLineBreak);
const Element& aEditingHost);
/** /**
* Return true if aRange crosses the inclusive ancestor block element at * Return true if aRange crosses the inclusive ancestor block element at
@@ -2071,8 +2078,7 @@ class HTMLEditUtils final {
*/ */
template <typename EditorLineBreakType, typename EditorDOMPointType> template <typename EditorLineBreakType, typename EditorDOMPointType>
[[nodiscard]] static Maybe<EditorLineBreakType> [[nodiscard]] static Maybe<EditorLineBreakType>
GetFollowingUnnecessaryLineBreak(const EditorDOMPointType& aPoint, GetFollowingUnnecessaryLineBreak(const EditorDOMPointType& aPoint);
const Element& aEditingHost);
/** /**
* IsInTableCellSelectionMode() returns true when Gecko's editor thinks that * IsInTableCellSelectionMode() returns true when Gecko's editor thinks that
@@ -2382,7 +2388,7 @@ class HTMLEditUtils final {
*/ */
template <typename EditorDOMPointType, typename EditorDOMPointTypeInput> template <typename EditorDOMPointType, typename EditorDOMPointTypeInput>
static EditorDOMPointType GetBetterCaretPositionToInsertText( static EditorDOMPointType GetBetterCaretPositionToInsertText(
const EditorDOMPointTypeInput& aPoint, const Element& aEditingHost); const EditorDOMPointTypeInput& aPoint);
/** /**
* ComputePointToPutCaretInElementIfOutside() returns a good point in aElement * ComputePointToPutCaretInElementIfOutside() returns a good point in aElement

View File

@@ -1194,7 +1194,7 @@ nsresult HTMLEditor::MaybeCollapseSelectionAtFirstEditableNode(
// the visible character. // the visible character.
const WSScanResult scanResultInTextNode = const WSScanResult scanResultInTextNode =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
editingHost, EditorRawDOMPoint(text, 0), WSRunScanner::Scan::EditableNodes, EditorRawDOMPoint(text, 0),
BlockInlineCheck::UseComputedDisplayStyle); BlockInlineCheck::UseComputedDisplayStyle);
if ((scanResultInTextNode.InVisibleOrCollapsibleCharacters() || if ((scanResultInTextNode.InVisibleOrCollapsibleCharacters() ||
scanResultInTextNode.ReachedPreformattedLineBreak()) && scanResultInTextNode.ReachedPreformattedLineBreak()) &&
@@ -2295,8 +2295,7 @@ nsresult HTMLEditor::InsertElementAtSelectionAsAction(
if (MOZ_LIKELY(aElement->IsInComposedDoc())) { if (MOZ_LIKELY(aElement->IsInComposedDoc())) {
const auto afterElement = EditorDOMPoint::After(*aElement); const auto afterElement = EditorDOMPoint::After(*aElement);
if (MOZ_LIKELY(afterElement.IsInContentNode())) { if (MOZ_LIKELY(afterElement.IsInContentNode())) {
nsresult rv = nsresult rv = EnsureNoFollowingUnnecessaryLineBreak(afterElement);
EnsureNoFollowingUnnecessaryLineBreak(afterElement, *editingHost);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING( NS_WARNING(
"HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed"); "HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
@@ -4519,8 +4518,7 @@ Result<CreateLineBreakResult, nsresult> HTMLEditor::InsertLineBreak(
} }
nsresult HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak( nsresult HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak(
const EditorDOMPoint& aNextOrAfterModifiedPoint, const EditorDOMPoint& aNextOrAfterModifiedPoint) {
const Element& aEditingHost) {
MOZ_ASSERT(aNextOrAfterModifiedPoint.IsInContentNode()); MOZ_ASSERT(aNextOrAfterModifiedPoint.IsInContentNode());
// If the point is in a mailcite in plaintext mail composer (it is a <span> // If the point is in a mailcite in plaintext mail composer (it is a <span>
@@ -4548,7 +4546,7 @@ nsresult HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak(
const Maybe<EditorLineBreak> unnecessaryLineBreak = const Maybe<EditorLineBreak> unnecessaryLineBreak =
HTMLEditUtils::GetFollowingUnnecessaryLineBreak<EditorLineBreak>( HTMLEditUtils::GetFollowingUnnecessaryLineBreak<EditorLineBreak>(
aNextOrAfterModifiedPoint, aEditingHost); aNextOrAfterModifiedPoint);
if (MOZ_LIKELY(unnecessaryLineBreak.isNothing())) { if (MOZ_LIKELY(unnecessaryLineBreak.isNothing())) {
return NS_OK; return NS_OK;
} }
@@ -7847,7 +7845,7 @@ nsresult HTMLEditor::OnModifyDocument(const DocumentModifiedEvent& aRunner) {
} }
const WSScanResult nextThing = const WSScanResult nextThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
editingHost, WSRunScanner::Scan::EditableNodes,
atCollapsibleWhiteSpace.AfterContainer<EditorRawDOMPoint>(), atCollapsibleWhiteSpace.AfterContainer<EditorRawDOMPoint>(),
BlockInlineCheck::UseComputedDisplayStyle); BlockInlineCheck::UseComputedDisplayStyle);
if (!nextThing.ReachedBlockBoundary()) { if (!nextThing.ReachedBlockBoundary()) {
@@ -7909,21 +7907,18 @@ void HTMLEditor::DocumentModifiedEvent::MaybeAppendNewInvisibleWhiteSpace(
!aContentWillBeRemoved->IsHTMLElement(nsGkAtoms::br)) { !aContentWillBeRemoved->IsHTMLElement(nsGkAtoms::br)) {
return; return;
} }
const Element* const editingHost =
const_cast<nsIContent*>(aContentWillBeRemoved)->GetEditingHost();
if (MOZ_UNLIKELY(!editingHost)) {
return;
}
const WSScanResult nextThing = const WSScanResult nextThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
editingHost, EditorRawDOMPoint::After(*aContentWillBeRemoved), WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint::After(*aContentWillBeRemoved),
BlockInlineCheck::UseComputedDisplayStyle); BlockInlineCheck::UseComputedDisplayStyle);
if (!nextThing.ReachedBlockBoundary()) { if (!nextThing.ReachedBlockBoundary()) {
return; return;
} }
const WSScanResult previousThing = const WSScanResult previousThing =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
editingHost, EditorRawDOMPoint(aContentWillBeRemoved), WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint(aContentWillBeRemoved),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (!previousThing.ContentIsText() || !previousThing.IsContentEditable()) { if (!previousThing.ContentIsText() || !previousThing.IsContentEditable()) {
return; return;

View File

@@ -1213,14 +1213,12 @@ class HTMLEditor final : public EditorBase,
* *
* @param aMailCiteElement The mail-cite element which should be split. * @param aMailCiteElement The mail-cite element which should be split.
* @param aPointToSplit The point to split. * @param aPointToSplit The point to split.
* @param aEditingHost The editing host.
* @return Candidate caret position where is at inserted * @return Candidate caret position where is at inserted
* <br> element into the split point. * <br> element into the split point.
*/ */
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<CaretPoint, nsresult> [[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<CaretPoint, nsresult>
HandleInsertParagraphInMailCiteElement(Element& aMailCiteElement, HandleInsertParagraphInMailCiteElement(Element& aMailCiteElement,
const EditorDOMPoint& aPointToSplit, const EditorDOMPoint& aPointToSplit);
const Element& aEditingHost);
/** /**
* HandleInsertBRElement() inserts a <br> element into aPointToBreak. * HandleInsertBRElement() inserts a <br> element into aPointToBreak.
@@ -1657,7 +1655,7 @@ class HTMLEditor final : public EditorBase,
*/ */
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<CreateLineBreakResult, nsresult> [[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<CreateLineBreakResult, nsresult>
InsertPaddingBRElementToMakeEmptyLineVisibleIfNeeded( InsertPaddingBRElementToMakeEmptyLineVisibleIfNeeded(
const EditorDOMPoint& aPointToInsert, const Element& aEditingHost); const EditorDOMPoint& aPointToInsert);
/** /**
* Insert a padding <br> if aPoint is in an empty block. * Insert a padding <br> if aPoint is in an empty block.
@@ -3400,12 +3398,10 @@ class HTMLEditor final : public EditorBase,
* content. * content.
* If you deleted something, this should be * If you deleted something, this should be
* end of the deleted range. * end of the deleted range.
* @param aEditingHost The editing host.
*/ */
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
EnsureNoFollowingUnnecessaryLineBreak( EnsureNoFollowingUnnecessaryLineBreak(
const EditorDOMPoint& aNextOrAfterModifiedPoint, const EditorDOMPoint& aNextOrAfterModifiedPoint);
const Element& aEditingHost);
/** /**
* IndentAsSubAction() indents the content around Selection. * IndentAsSubAction() indents the content around Selection.
@@ -3455,8 +3451,7 @@ class HTMLEditor final : public EditorBase,
template <size_t N> template <size_t N>
[[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SetInlinePropertiesAroundRanges( [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult SetInlinePropertiesAroundRanges(
AutoClonedRangeArray& aRanges, AutoClonedRangeArray& aRanges,
const AutoTArray<EditorInlineStyleAndValue, N>& aStylesToSet, const AutoTArray<EditorInlineStyleAndValue, N>& aStylesToSet);
const Element& aEditingHost);
/** /**
* RemoveInlinePropertiesAsSubAction() removes specified styles from * RemoveInlinePropertiesAsSubAction() removes specified styles from

View File

@@ -903,7 +903,7 @@ Result<EditActionResult, nsresult> HTMLEditor::HTMLWithContextInserter::Run(
lastInsertedPoint.inspect().NextPointOrAfterContainer(); lastInsertedPoint.inspect().NextPointOrAfterContainer();
if (MOZ_LIKELY(afterLastInsertedContent.IsInContentNode())) { if (MOZ_LIKELY(afterLastInsertedContent.IsInContentNode())) {
nsresult rv = mHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak( nsresult rv = mHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak(
afterLastInsertedContent, mEditingHost); afterLastInsertedContent);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING( NS_WARNING(
"HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed"); "HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");

View File

@@ -2373,8 +2373,8 @@ Result<CaretPoint, nsresult> HTMLEditor::AutoDeleteRangesHandler::
if (MOZ_LIKELY(pointToPutCaret.IsInContentNode())) { if (MOZ_LIKELY(pointToPutCaret.IsInContentNode())) {
AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(), AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(),
&pointToPutCaret); &pointToPutCaret);
nsresult rv = aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak( nsresult rv =
pointToPutCaret, aEditingHost); aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak(pointToPutCaret);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed"); NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv); return Err(rv);
@@ -2581,8 +2581,8 @@ Result<CaretPoint, nsresult> HTMLEditor::AutoDeleteRangesHandler::
if (MOZ_LIKELY(pointToPutCaret.IsInContentNode())) { if (MOZ_LIKELY(pointToPutCaret.IsInContentNode())) {
AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(), AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(),
&pointToPutCaret); &pointToPutCaret);
nsresult rv = aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak( nsresult rv =
pointToPutCaret, aEditingHost); aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak(pointToPutCaret);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed"); NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv); return Err(rv);
@@ -2756,8 +2756,8 @@ HTMLEditor::AutoDeleteRangesHandler::HandleDeleteAtomicContent(
if (MOZ_LIKELY(pointToPutCaret.IsInContentNode())) { if (MOZ_LIKELY(pointToPutCaret.IsInContentNode())) {
AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(), AutoTrackDOMPoint trackPointToPutCaret(aHTMLEditor.RangeUpdaterRef(),
&pointToPutCaret); &pointToPutCaret);
nsresult rv = aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak( nsresult rv =
pointToPutCaret, aEditingHost); aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak(pointToPutCaret);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed"); NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv); return Err(rv);
@@ -3586,7 +3586,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
} }
const WSScanResult prevVisibleThingBeforeCurrentBlock = const WSScanResult prevVisibleThingBeforeCurrentBlock =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint( EditorRawDOMPoint(
inclusiveAncestorOfRightChildBlockOrError.inspect()), inclusiveAncestorOfRightChildBlockOrError.inspect()),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
@@ -3605,7 +3605,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
MOZ_ASSERT(atPrecedingLineBreak.IsSet()); MOZ_ASSERT(atPrecedingLineBreak.IsSet());
const WSScanResult prevVisibleThingBeforeLineBreak = const WSScanResult prevVisibleThingBeforeLineBreak =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
&aEditingHost, atPrecedingLineBreak, WSRunScanner::Scan::EditableNodes, atPrecedingLineBreak,
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (prevVisibleThingBeforeLineBreak.ReachedBRElement() || if (prevVisibleThingBeforeLineBreak.ReachedBRElement() ||
prevVisibleThingBeforeLineBreak.ReachedPreformattedLineBreak() || prevVisibleThingBeforeLineBreak.ReachedPreformattedLineBreak() ||
@@ -4214,7 +4214,8 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
// rough check. // rough check.
const WSScanResult nextVisibleThingOfEndBoundary = const WSScanResult nextVisibleThingOfEndBoundary =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, EditorRawDOMPoint(aRangeToDelete.EndRef()), WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint(aRangeToDelete.EndRef()),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (!nextVisibleThingOfEndBoundary.ReachedCurrentBlockBoundary()) { if (!nextVisibleThingOfEndBoundary.ReachedCurrentBlockBoundary()) {
MOZ_ASSERT(mLeftContent->IsElement()); MOZ_ASSERT(mLeftContent->IsElement());
@@ -4227,7 +4228,8 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
if (MOZ_LIKELY(mostDistantBlockOrError.inspect())) { if (MOZ_LIKELY(mostDistantBlockOrError.inspect())) {
const WSScanResult prevVisibleThingOfStartBoundary = const WSScanResult prevVisibleThingOfStartBoundary =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
&aEditingHost, EditorRawDOMPoint(aRangeToDelete.StartRef()), WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint(aRangeToDelete.StartRef()),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (prevVisibleThingOfStartBoundary.ReachedBRElement()) { if (prevVisibleThingOfStartBoundary.ReachedBRElement()) {
// If the range start after a <br> followed by the block boundary, // If the range start after a <br> followed by the block boundary,
@@ -4235,7 +4237,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
// not a part of empty line like `<div>abc<br>{<div>]def`. // not a part of empty line like `<div>abc<br>{<div>]def`.
const WSScanResult nextVisibleThingOfBR = const WSScanResult nextVisibleThingOfBR =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint::After( EditorRawDOMPoint::After(
*prevVisibleThingOfStartBoundary.GetContent()), *prevVisibleThingOfStartBoundary.GetContent()),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
@@ -4249,7 +4251,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
} }
const WSScanResult prevVisibleThingOfBR = const WSScanResult prevVisibleThingOfBR =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint( EditorRawDOMPoint(
prevVisibleThingOfStartBoundary.GetContent()), prevVisibleThingOfStartBoundary.GetContent()),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
@@ -4264,7 +4266,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
.ReachedPreformattedLineBreak()) { .ReachedPreformattedLineBreak()) {
const WSScanResult nextVisibleThingOfLineBreak = const WSScanResult nextVisibleThingOfLineBreak =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
prevVisibleThingOfStartBoundary prevVisibleThingOfStartBoundary
.PointAfterReachedContent<EditorRawDOMPoint>(), .PointAfterReachedContent<EditorRawDOMPoint>(),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
@@ -4279,7 +4281,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
} }
const WSScanResult prevVisibleThingOfLineBreak = const WSScanResult prevVisibleThingOfLineBreak =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
prevVisibleThingOfStartBoundary prevVisibleThingOfStartBoundary
.PointAtReachedContent<EditorRawDOMPoint>(), .PointAtReachedContent<EditorRawDOMPoint>(),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
@@ -4296,7 +4298,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
mLeftContent); mLeftContent);
const WSScanResult firstVisibleThingInBlock = const WSScanResult firstVisibleThingInBlock =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint( EditorRawDOMPoint(
prevVisibleThingOfStartBoundary.ElementPtr(), 0), prevVisibleThingOfStartBoundary.ElementPtr(), 0),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
@@ -4309,7 +4311,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
} else if (prevVisibleThingOfStartBoundary.ReachedOtherBlockElement()) { } else if (prevVisibleThingOfStartBoundary.ReachedOtherBlockElement()) {
const WSScanResult firstVisibleThingAfterBlock = const WSScanResult firstVisibleThingAfterBlock =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint::After( EditorRawDOMPoint::After(
*prevVisibleThingOfStartBoundary.ElementPtr()), *prevVisibleThingOfStartBoundary.ElementPtr()),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
@@ -4903,8 +4905,8 @@ Result<Element*, nsresult> HTMLEditor::AutoDeleteRangesHandler::
const WSScanResult prevVisibleThing = const WSScanResult prevVisibleThing =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
aAncestorLimiter, aPoint, WSRunScanner::Scan::EditableNodes, aPoint,
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle, aAncestorLimiter);
if (!ReachedCurrentBlockBoundaryWhichWeCanCross(prevVisibleThing)) { if (!ReachedCurrentBlockBoundaryWhichWeCanCross(prevVisibleThing)) {
return nullptr; return nullptr;
} }
@@ -4914,8 +4916,8 @@ Result<Element*, nsresult> HTMLEditor::AutoDeleteRangesHandler::
for (Element* ancestorBlock = prevVisibleThing.ElementPtr(); ancestorBlock;) { for (Element* ancestorBlock = prevVisibleThing.ElementPtr(); ancestorBlock;) {
const WSScanResult prevVisibleThing = const WSScanResult prevVisibleThing =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
aAncestorLimiter, EditorRawDOMPoint(ancestorBlock), WSRunScanner::Scan::EditableNodes, EditorRawDOMPoint(ancestorBlock),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle, aAncestorLimiter);
if (!ReachedCurrentBlockBoundaryWhichWeCanCross(prevVisibleThing)) { if (!ReachedCurrentBlockBoundaryWhichWeCanCross(prevVisibleThing)) {
return ancestorBlock; return ancestorBlock;
} }
@@ -4981,7 +4983,8 @@ void HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
const WSScanResult prevVisibleThingOfStartBoundary = const WSScanResult prevVisibleThingOfStartBoundary =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
&aEditingHost, EditorRawDOMPoint(aRangeToDelete.StartRef()), WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint(aRangeToDelete.StartRef()),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
// If the range starts after an invisible <br> of empty line immediately // If the range starts after an invisible <br> of empty line immediately
// before the most distant inclusive ancestor of the right block like // before the most distant inclusive ancestor of the right block like
@@ -4991,13 +4994,13 @@ void HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
prevVisibleThingOfStartBoundary.ReachedPreformattedLineBreak()) { prevVisibleThingOfStartBoundary.ReachedPreformattedLineBreak()) {
const WSScanResult prevVisibleThingOfPreviousLineBreak = const WSScanResult prevVisibleThingOfPreviousLineBreak =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
prevVisibleThingOfStartBoundary prevVisibleThingOfStartBoundary
.PointAtReachedContent<EditorRawDOMPoint>(), .PointAtReachedContent<EditorRawDOMPoint>(),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
const WSScanResult nextVisibleThingOfPreviousBR = const WSScanResult nextVisibleThingOfPreviousBR =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
prevVisibleThingOfStartBoundary prevVisibleThingOfStartBoundary
.PointAfterReachedContent<EditorRawDOMPoint>(), .PointAfterReachedContent<EditorRawDOMPoint>(),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
@@ -5028,8 +5031,9 @@ void HTMLEditor::AutoDeleteRangesHandler::AutoBlockElementsJoiner::
while (true) { while (true) {
WSScanResult scanResult = WSScanResult scanResult =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
mLeftContent->AsElement(), scanStartPoint, WSRunScanner::Scan::EditableNodes, scanStartPoint,
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle,
mLeftContent->AsElement());
if (scanResult.ReachedBlockBoundary() || if (scanResult.ReachedBlockBoundary() ||
scanResult.ReachedInlineEditingHostBoundary()) { scanResult.ReachedInlineEditingHostBoundary()) {
return lastScanResult; return lastScanResult;
@@ -5181,7 +5185,7 @@ Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
mMode != Mode::DeletePrecedingLinesAndContentInRange && mMode != Mode::DeletePrecedingLinesAndContentInRange &&
HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary( HTMLEditUtils::PointIsImmediatelyBeforeCurrentBlockBoundary(
EditorRawDOMPoint(aRangeToDelete.StartRef()), EditorRawDOMPoint(aRangeToDelete.StartRef()),
HTMLEditUtils::IgnoreInvisibleLineBreak::Yes, aEditingHost); HTMLEditUtils::IgnoreInvisibleLineBreak::Yes);
const PutCaretTo putCaretTo = [&]() { const PutCaretTo putCaretTo = [&]() {
// When we delete only preceding lines of the right child block, we should // When we delete only preceding lines of the right child block, we should
// put caret into start of the right block. // put caret into start of the right block.
@@ -5405,8 +5409,8 @@ Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
aHTMLEditor.RangeUpdaterRef(), &moveFirstLineResult); aHTMLEditor.RangeUpdaterRef(), &moveFirstLineResult);
AutoTrackDOMPoint trackPointToPutCaret( AutoTrackDOMPoint trackPointToPutCaret(
aHTMLEditor.RangeUpdaterRef(), &pointToPutCaret); aHTMLEditor.RangeUpdaterRef(), &pointToPutCaret);
nsresult rv = aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak( nsresult rv =
aPoint, aEditingHost); aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak(aPoint);
NS_WARNING_ASSERTION( NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), NS_SUCCEEDED(rv),
"HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed"); "HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
@@ -5496,7 +5500,7 @@ Result<EditActionResult, nsresult> HTMLEditor::AutoDeleteRangesHandler::
} }
WSScanResult nextThing = WSScanResult nextThing =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, WSRunScanner::Scan::EditableNodes,
deleteContentResult.DeleteRangeRef().EndRef(), deleteContentResult.DeleteRangeRef().EndRef(),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
return nextThing.ReachedBRElement() || return nextThing.ReachedBRElement() ||
@@ -5645,8 +5649,8 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::DeleteUnnecessaryNodes(
if (MOZ_LIKELY(range.EndRef().IsInContentNode())) { if (MOZ_LIKELY(range.EndRef().IsInContentNode())) {
AutoTrackDOMRange trackRange(aHTMLEditor.RangeUpdaterRef(), &range); AutoTrackDOMRange trackRange(aHTMLEditor.RangeUpdaterRef(), &range);
nsresult rv = aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak( nsresult rv =
range.EndRef(), aEditingHost); aHTMLEditor.EnsureNoFollowingUnnecessaryLineBreak(range.EndRef());
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed"); NS_WARNING("HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv); return Err(rv);
@@ -5737,7 +5741,7 @@ HTMLEditor::AutoDeleteRangesHandler::DeleteParentBlocksWithTransactionIfEmpty(
if (wsScannerForPoint.GetEndReasonContent()->GetNextSibling()) { if (wsScannerForPoint.GetEndReasonContent()->GetNextSibling()) {
const WSScanResult scanResult = const WSScanResult scanResult =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
editingHost, WSRunScanner::Scan::EditableNodes,
EditorRawDOMPoint::After( EditorRawDOMPoint::After(
*wsScannerForPoint.GetEndReasonContent()), *wsScannerForPoint.GetEndReasonContent()),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
@@ -8349,7 +8353,7 @@ HTMLEditor::AutoDeleteRangesHandler::ExtendOrShrinkRangeToDelete(
for (;;) { for (;;) {
const WSScanResult backwardScanFromStartResult = const WSScanResult backwardScanFromStartResult =
WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary( WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary(
closestEditingHost, rangeToDelete.StartRef(), WSRunScanner::Scan::EditableNodes, rangeToDelete.StartRef(),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (!backwardScanFromStartResult.ReachedCurrentBlockBoundary() && if (!backwardScanFromStartResult.ReachedCurrentBlockBoundary() &&
!backwardScanFromStartResult.ReachedInlineEditingHostBoundary()) { !backwardScanFromStartResult.ReachedInlineEditingHostBoundary()) {

View File

@@ -78,8 +78,7 @@ class MOZ_STACK_CLASS HTMLEditor::AutoInlineStyleSetter final
* See comments in the definition what this does. * See comments in the definition what this does.
*/ */
Result<EditorRawDOMRange, nsresult> ExtendOrShrinkRangeToApplyTheStyle( Result<EditorRawDOMRange, nsresult> ExtendOrShrinkRangeToApplyTheStyle(
const HTMLEditor& aHTMLEditor, const EditorDOMRange& aRange, const HTMLEditor& aHTMLEditor, const EditorDOMRange& aRange) const;
const Element& aEditingHost) const;
/** /**
* Returns next/previous sibling of aContent or an ancestor of it if it's * Returns next/previous sibling of aContent or an ancestor of it if it's
@@ -104,7 +103,6 @@ class MOZ_STACK_CLASS HTMLEditor::AutoInlineStyleSetter final
* @param aHTMLEditor The editor. * @param aHTMLEditor The editor.
* @param aCandidatePointToInsert The point where the caller wants to * @param aCandidatePointToInsert The point where the caller wants to
* insert new text. * insert new text.
* @param aEditingHost The editing host.
* @return If this creates new empty text node returns it. * @return If this creates new empty text node returns it.
* If this couldn't create new empty text node due to * If this couldn't create new empty text node due to
* the point or aEditingHost cannot have text node, * the point or aEditingHost cannot have text node,
@@ -112,9 +110,8 @@ class MOZ_STACK_CLASS HTMLEditor::AutoInlineStyleSetter final
* Otherwise, returns error. * Otherwise, returns error.
*/ */
[[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<RefPtr<Text>, nsresult> [[nodiscard]] MOZ_CAN_RUN_SCRIPT static Result<RefPtr<Text>, nsresult>
GetEmptyTextNodeToApplyNewStyle(HTMLEditor& aHTMLEditor, GetEmptyTextNodeToApplyNewStyle(
const EditorDOMPoint& aCandidatePointToInsert, HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCandidatePointToInsert);
const Element& aEditingHost);
private: private:
[[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<CaretPoint, nsresult> ApplyStyle( [[nodiscard]] MOZ_CAN_RUN_SCRIPT Result<CaretPoint, nsresult> ApplyStyle(

View File

@@ -75,12 +75,10 @@ template nsresult HTMLEditor::SetInlinePropertiesAsSubAction(
template nsresult HTMLEditor::SetInlinePropertiesAroundRanges( template nsresult HTMLEditor::SetInlinePropertiesAroundRanges(
AutoClonedRangeArray& aRanges, AutoClonedRangeArray& aRanges,
const AutoTArray<EditorInlineStyleAndValue, 1>& aStylesToSet, const AutoTArray<EditorInlineStyleAndValue, 1>& aStylesToSet);
const Element& aEditingHost);
template nsresult HTMLEditor::SetInlinePropertiesAroundRanges( template nsresult HTMLEditor::SetInlinePropertiesAroundRanges(
AutoClonedRangeArray& aRanges, AutoClonedRangeArray& aRanges,
const AutoTArray<EditorInlineStyleAndValue, 32>& aStylesToSet, const AutoTArray<EditorInlineStyleAndValue, 32>& aStylesToSet);
const Element& aEditingHost);
nsresult HTMLEditor::SetInlinePropertyAsAction(nsStaticAtom& aProperty, nsresult HTMLEditor::SetInlinePropertyAsAction(nsStaticAtom& aProperty,
nsStaticAtom* aAttribute, nsStaticAtom* aAttribute,
@@ -310,8 +308,7 @@ nsresult HTMLEditor::SetInlinePropertiesAsSubAction(
AutoTransactionsConserveSelection dontChangeMySelection(*this); AutoTransactionsConserveSelection dontChangeMySelection(*this);
AutoClonedSelectionRangeArray selectionRanges(SelectionRef()); AutoClonedSelectionRangeArray selectionRanges(SelectionRef());
nsresult rv = SetInlinePropertiesAroundRanges(selectionRanges, aStylesToSet, nsresult rv = SetInlinePropertiesAroundRanges(selectionRanges, aStylesToSet);
aEditingHost);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::SetInlinePropertiesAroundRanges() failed"); NS_WARNING("HTMLEditor::SetInlinePropertiesAroundRanges() failed");
return rv; return rv;
@@ -329,8 +326,7 @@ nsresult HTMLEditor::SetInlinePropertiesAsSubAction(
template <size_t N> template <size_t N>
nsresult HTMLEditor::SetInlinePropertiesAroundRanges( nsresult HTMLEditor::SetInlinePropertiesAroundRanges(
AutoClonedRangeArray& aRanges, AutoClonedRangeArray& aRanges,
const AutoTArray<EditorInlineStyleAndValue, N>& aStylesToSet, const AutoTArray<EditorInlineStyleAndValue, N>& aStylesToSet) {
const Element& aEditingHost) {
MOZ_ASSERT(!aRanges.HasSavedRanges()); MOZ_ASSERT(!aRanges.HasSavedRanges());
for (const EditorInlineStyleAndValue& styleToSet : aStylesToSet) { for (const EditorInlineStyleAndValue& styleToSet : aStylesToSet) {
AutoInlineStyleSetter inlineStyleSetter(styleToSet); AutoInlineStyleSetter inlineStyleSetter(styleToSet);
@@ -371,8 +367,7 @@ nsresult HTMLEditor::SetInlinePropertiesAroundRanges(
} }
} }
Result<EditorRawDOMRange, nsresult> rangeOrError = Result<EditorRawDOMRange, nsresult> rangeOrError =
inlineStyleSetter.ExtendOrShrinkRangeToApplyTheStyle(*this, range, inlineStyleSetter.ExtendOrShrinkRangeToApplyTheStyle(*this, range);
aEditingHost);
if (MOZ_UNLIKELY(rangeOrError.isErr())) { if (MOZ_UNLIKELY(rangeOrError.isErr())) {
NS_WARNING( NS_WARNING(
"HTMLEditor::ExtendOrShrinkRangeToApplyTheStyle() failed, but " "HTMLEditor::ExtendOrShrinkRangeToApplyTheStyle() failed, but "
@@ -394,7 +389,7 @@ nsresult HTMLEditor::SetInlinePropertiesAroundRanges(
if (range.Collapsed()) { if (range.Collapsed()) {
Result<RefPtr<Text>, nsresult> emptyTextNodeOrError = Result<RefPtr<Text>, nsresult> emptyTextNodeOrError =
AutoInlineStyleSetter::GetEmptyTextNodeToApplyNewStyle( AutoInlineStyleSetter::GetEmptyTextNodeToApplyNewStyle(
*this, range.StartRef(), aEditingHost); *this, range.StartRef());
if (MOZ_UNLIKELY(emptyTextNodeOrError.isErr())) { if (MOZ_UNLIKELY(emptyTextNodeOrError.isErr())) {
NS_WARNING( NS_WARNING(
"AutoInlineStyleSetter::GetEmptyTextNodeToApplyNewStyle() " "AutoInlineStyleSetter::GetEmptyTextNodeToApplyNewStyle() "
@@ -579,11 +574,10 @@ nsresult HTMLEditor::SetInlinePropertiesAroundRanges(
// static // static
Result<RefPtr<Text>, nsresult> Result<RefPtr<Text>, nsresult>
HTMLEditor::AutoInlineStyleSetter::GetEmptyTextNodeToApplyNewStyle( HTMLEditor::AutoInlineStyleSetter::GetEmptyTextNodeToApplyNewStyle(
HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCandidatePointToInsert, HTMLEditor& aHTMLEditor, const EditorDOMPoint& aCandidatePointToInsert) {
const Element& aEditingHost) {
auto pointToInsertNewText = auto pointToInsertNewText =
HTMLEditUtils::GetBetterCaretPositionToInsertText<EditorDOMPoint>( HTMLEditUtils::GetBetterCaretPositionToInsertText<EditorDOMPoint>(
aCandidatePointToInsert, aEditingHost); aCandidatePointToInsert);
if (MOZ_UNLIKELY(!pointToInsertNewText.IsSet())) { if (MOZ_UNLIKELY(!pointToInsertNewText.IsSet())) {
return RefPtr<Text>(); // cannot insert text there return RefPtr<Text>(); // cannot insert text there
} }
@@ -1925,8 +1919,7 @@ EditorRawDOMRange HTMLEditor::AutoInlineStyleSetter::
Result<EditorRawDOMRange, nsresult> Result<EditorRawDOMRange, nsresult>
HTMLEditor::AutoInlineStyleSetter::ExtendOrShrinkRangeToApplyTheStyle( HTMLEditor::AutoInlineStyleSetter::ExtendOrShrinkRangeToApplyTheStyle(
const HTMLEditor& aHTMLEditor, const EditorDOMRange& aRange, const HTMLEditor& aHTMLEditor, const EditorDOMRange& aRange) const {
const Element& aEditingHost) const {
if (NS_WARN_IF(!aRange.IsPositioned())) { if (NS_WARN_IF(!aRange.IsPositioned())) {
return Err(NS_ERROR_FAILURE); return Err(NS_ERROR_FAILURE);
} }
@@ -1945,7 +1938,7 @@ HTMLEditor::AutoInlineStyleSetter::ExtendOrShrinkRangeToApplyTheStyle(
if (range.EndRef().IsInContentNode()) { if (range.EndRef().IsInContentNode()) {
const WSScanResult nextContentData = const WSScanResult nextContentData =
WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary( WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary(
&aEditingHost, range.EndRef(), WSRunScanner::Scan::EditableNodes, range.EndRef(),
BlockInlineCheck::UseComputedDisplayOutsideStyle); BlockInlineCheck::UseComputedDisplayOutsideStyle);
if (nextContentData.ReachedInvisibleBRElement() && if (nextContentData.ReachedInvisibleBRElement() &&
nextContentData.BRElementPtr()->GetParentElement() && nextContentData.BRElementPtr()->GetParentElement() &&

View File

@@ -238,6 +238,11 @@ class MOZ_STACK_CLASS WSScanResult final {
*/ */
bool IsContentEditable() const { return mContent && mContent->IsEditable(); } bool IsContentEditable() const { return mContent && mContent->IsEditable(); }
[[nodiscard]] bool IsContentEditableRoot() const {
return mContent && mContent->IsElement() &&
HTMLEditUtils::ElementIsEditableRoot(*mContent->AsElement());
}
/** /**
* Offset_Deprecated() returns meaningful value only when * Offset_Deprecated() returns meaningful value only when
* InVisibleOrCollapsibleCharacters() returns true or the scanner reached to * InVisibleOrCollapsibleCharacters() returns true or the scanner reached to
@@ -455,10 +460,10 @@ class MOZ_STACK_CLASS WSRunScanner final {
const EditorDOMPointBase<PT, CT>& aPoint) const; const EditorDOMPointBase<PT, CT>& aPoint) const;
template <typename PT, typename CT> template <typename PT, typename CT>
static WSScanResult ScanInclusiveNextVisibleNodeOrBlockBoundary( static WSScanResult ScanInclusiveNextVisibleNodeOrBlockBoundary(
const Element* aEditingHost, const EditorDOMPointBase<PT, CT>& aPoint, Scan aScanMode, const EditorDOMPointBase<PT, CT>& aPoint,
BlockInlineCheck aBlockInlineCheck) { BlockInlineCheck aBlockInlineCheck,
return WSRunScanner(Scan::EditableNodes, aPoint, aBlockInlineCheck, const Element* aAncestorLimiter = nullptr) {
aEditingHost) return WSRunScanner(aScanMode, aPoint, aBlockInlineCheck, aAncestorLimiter)
.ScanInclusiveNextVisibleNodeOrBlockBoundaryFrom(aPoint); .ScanInclusiveNextVisibleNodeOrBlockBoundaryFrom(aPoint);
} }
@@ -473,10 +478,10 @@ class MOZ_STACK_CLASS WSRunScanner final {
const EditorDOMPointBase<PT, CT>& aPoint) const; const EditorDOMPointBase<PT, CT>& aPoint) const;
template <typename PT, typename CT> template <typename PT, typename CT>
static WSScanResult ScanPreviousVisibleNodeOrBlockBoundary( static WSScanResult ScanPreviousVisibleNodeOrBlockBoundary(
const Element* aEditingHost, const EditorDOMPointBase<PT, CT>& aPoint, Scan aScanMode, const EditorDOMPointBase<PT, CT>& aPoint,
BlockInlineCheck aBlockInlineCheck) { BlockInlineCheck aBlockInlineCheck,
return WSRunScanner(Scan::EditableNodes, aPoint, aBlockInlineCheck, const Element* aAncestorLimiter = nullptr) {
aEditingHost) return WSRunScanner(aScanMode, aPoint, aBlockInlineCheck, aAncestorLimiter)
.ScanPreviousVisibleNodeOrBlockBoundaryFrom(aPoint); .ScanPreviousVisibleNodeOrBlockBoundaryFrom(aPoint);
} }