Bug 1705598 - part 2: Make the constructor of WSRunScanner take editing host instead of HTMLEditor r=m_kato

I think that it's no matter to make `WSRunScanner` work without editing host.
Therefore, this patch make it take pointer of `Element` rather than reference.

Depends on D112502

Differential Revision: https://phabricator.services.mozilla.com/D112503
This commit is contained in:
Masayuki Nakano 2021-04-19 23:25:45 +00:00
parent 9227d30f9b
commit a7b87b61b1
5 changed files with 23 additions and 21 deletions

View File

@ -1483,7 +1483,7 @@ nsresult HTMLEditor::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
}
} else {
EditorDOMPoint pointToBreak(aPointToBreak);
WSRunScanner wsRunScanner(*this, pointToBreak);
WSRunScanner wsRunScanner(GetActiveEditingHost(), pointToBreak);
WSScanResult backwardScanResult =
wsRunScanner.ScanPreviousVisibleNodeOrBlockBoundaryFrom(pointToBreak);
if (backwardScanResult.Failed()) {
@ -2279,7 +2279,7 @@ nsresult HTMLEditor::InsertBRElementIfHardLineIsEmptyAndEndsWithBlockBoundary(
return NS_OK;
}
WSRunScanner wsRunScanner(*this, aPointToInsert);
WSRunScanner wsRunScanner(GetActiveEditingHost(), aPointToInsert);
// If the point is not start of a hard line, we don't need to put a `<br>`
// element here.
if (!wsRunScanner.StartsFromHardLineBreak()) {
@ -5348,7 +5348,7 @@ nsresult HTMLEditor::MaybeExtendSelectionToHardLineEdgesForBlockEditAction() {
// Is there any intervening visible white-space? If so we can't push
// selection past that, it would visibly change meaning of users selection.
WSRunScanner wsScannerAtEnd(*this, endPoint);
WSRunScanner wsScannerAtEnd(GetActiveEditingHost(), endPoint);
WSScanResult scanResultAtEnd =
wsScannerAtEnd.ScanPreviousVisibleNodeOrBlockBoundaryFrom(endPoint);
if (scanResultAtEnd.Failed()) {
@ -5383,7 +5383,7 @@ nsresult HTMLEditor::MaybeExtendSelectionToHardLineEdgesForBlockEditAction() {
// Is there any intervening visible white-space? If so we can't push
// selection past that, it would visibly change meaning of users selection.
WSRunScanner wsScannerAtStart(*this, startPoint);
WSRunScanner wsScannerAtStart(wsScannerAtEnd.GetEditingHost(), startPoint);
WSScanResult scanResultAtStart =
wsScannerAtStart.ScanNextVisibleNodeOrBlockBoundaryFrom(startPoint);
if (scanResultAtStart.Failed()) {

View File

@ -1636,7 +1636,7 @@ EditorRawDOMPoint HTMLEditor::GetBetterInsertionPointFor(
return pointToInsert;
}
WSRunScanner wsScannerForPointToInsert(*this, pointToInsert);
WSRunScanner wsScannerForPointToInsert(GetActiveEditingHost(), pointToInsert);
// If the insertion position is after the last visible item in a line,
// i.e., the insertion position is just before a visible line break <br>,

View File

@ -337,7 +337,8 @@ class MOZ_STACK_CLASS
HTMLBRElement*
HTMLEditor::HTMLWithContextInserter::GetInvisibleBRElementAtPoint(
const EditorDOMPoint& aPointToInsert) const {
WSRunScanner wsRunScannerAtInsertionPoint(mHTMLEditor, aPointToInsert);
WSRunScanner wsRunScannerAtInsertionPoint(mHTMLEditor.GetActiveEditingHost(),
aPointToInsert);
if (wsRunScannerAtInsertionPoint.GetEndReasonContent() &&
wsRunScannerAtInsertionPoint.GetEndReasonContent()->IsHTMLElement(
nsGkAtoms::br) &&
@ -399,14 +400,15 @@ HTMLEditor::HTMLWithContextInserter::GetNewCaretPointAfterInsertingHTML(
// Make sure we don't end up with selection collapsed after an invisible
// `<br>` element.
WSRunScanner wsRunScannerAtCaret(mHTMLEditor, pointToPutCaret);
Element* editingHost = mHTMLEditor.GetActiveEditingHost();
WSRunScanner wsRunScannerAtCaret(editingHost, pointToPutCaret);
if (wsRunScannerAtCaret
.ScanPreviousVisibleNodeOrBlockBoundaryFrom(pointToPutCaret)
.ReachedBRElement() &&
!mHTMLEditor.IsVisibleBRElement(
wsRunScannerAtCaret.GetStartReasonContent())) {
WSRunScanner wsRunScannerAtStartReason(
mHTMLEditor,
editingHost,
EditorDOMPoint(wsRunScannerAtCaret.GetStartReasonContent()));
WSScanResult backwardScanFromPointToCaretResult =
wsRunScannerAtStartReason.ScanPreviousVisibleNodeOrBlockBoundaryFrom(

View File

@ -1265,7 +1265,7 @@ nsresult HTMLEditor::AutoDeleteRangesHandler::ComputeRangesToDelete(
EditorType::HTML)) {
return NS_SUCCESS_DOM_NO_OPERATION;
}
WSRunScanner wsRunScannerAtCaret(aHTMLEditor, caretPoint);
WSRunScanner wsRunScannerAtCaret(editingHost, caretPoint);
WSScanResult scanFromCaretPointResult =
aDirectionAndAmount == nsIEditor::eNext
? wsRunScannerAtCaret.ScanNextVisibleNodeOrBlockBoundaryFrom(
@ -1540,7 +1540,7 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::Run(
*caretPoint.ref().ContainerAsContent(), EditorType::HTML)) {
return EditActionCanceled();
}
WSRunScanner wsRunScannerAtCaret(aHTMLEditor, caretPoint.ref());
WSRunScanner wsRunScannerAtCaret(editingHost, caretPoint.ref());
WSScanResult scanFromCaretPointResult =
aDirectionAndAmount == nsIEditor::eNext
? wsRunScannerAtCaret.ScanNextVisibleNodeOrBlockBoundaryFrom(
@ -1603,7 +1603,7 @@ EditActionResult HTMLEditor::AutoDeleteRangesHandler::Run(
NS_EVENT_BITS_MUTATION_NODEREMOVEDFROMDOCUMENT)) {
// Let's check whether there is new invisible `<br>` element
// for avoiding infinit recursive calls.
WSRunScanner wsRunScannerAtCaret(aHTMLEditor, caretPoint.ref());
WSRunScanner wsRunScannerAtCaret(editingHost, caretPoint.ref());
WSScanResult scanFromCaretPointResult =
aDirectionAndAmount == nsIEditor::eNext
? wsRunScannerAtCaret
@ -3696,7 +3696,7 @@ HTMLEditor::AutoDeleteRangesHandler::DeleteParentBlocksWithTransactionIfEmpty(
MOZ_ASSERT(aHTMLEditor.mPlaceholderBatch);
// First, check there is visible contents before the point in current block.
WSRunScanner wsScannerForPoint(aHTMLEditor, aPoint);
WSRunScanner wsScannerForPoint(aHTMLEditor.GetActiveEditingHost(), aPoint);
if (!wsScannerForPoint.StartsFromCurrentBlockBoundary()) {
// If there is visible node before the point, we shouldn't remove the
// parent block.
@ -5268,7 +5268,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::ExtendRangeToIncludeInvisibleNodes(
}
// Set up for loops and cache our root element
Element* editingHost = aHTMLEditor.GetActiveEditingHost();
RefPtr<Element> editingHost = aHTMLEditor.GetActiveEditingHost();
if (NS_WARN_IF(!editingHost)) {
return false;
}
@ -5284,7 +5284,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::ExtendRangeToIncludeInvisibleNodes(
break;
}
MOZ_ASSERT(backwardScanFromStartResult.GetContent() ==
WSRunScanner(aHTMLEditor, atStart).GetStartReasonContent());
WSRunScanner(editingHost, atStart).GetStartReasonContent());
// We want to keep looking up. But stop if we are crossing table
// element boundaries, or if we hit the root.
if (HTMLEditUtils::IsAnyTableElement(
@ -5311,7 +5311,7 @@ bool HTMLEditor::AutoDeleteRangesHandler::ExtendRangeToIncludeInvisibleNodes(
atEnd.GetContainer() != editingHost) {
EditorDOMPoint atFirstInvisibleBRElement;
for (;;) {
WSRunScanner wsScannerAtEnd(aHTMLEditor, atEnd);
WSRunScanner wsScannerAtEnd(editingHost, atEnd);
WSScanResult forwardScanFromEndResult =
wsScannerAtEnd.ScanNextVisibleNodeOrBlockBoundaryFrom(atEnd);
if (forwardScanFromEndResult.ReachedBRElement()) {

View File

@ -275,10 +275,10 @@ class MOZ_STACK_CLASS WSRunScanner final {
using WSType = WSScanResult::WSType;
template <typename EditorDOMPointType>
WSRunScanner(const HTMLEditor& aHTMLEditor,
WSRunScanner(dom::Element* aEditingHost,
const EditorDOMPointType& aScanStartPoint)
: mScanStartPoint(aScanStartPoint),
mEditingHost(aHTMLEditor.GetActiveEditingHost()),
mEditingHost(aEditingHost),
mTextFragmentDataAtStart(mScanStartPoint, mEditingHost) {}
// ScanNextVisibleNodeOrBlockBoundaryForwardFrom() returns the first visible
@ -291,7 +291,7 @@ class MOZ_STACK_CLASS WSRunScanner final {
template <typename PT, typename CT>
static WSScanResult ScanNextVisibleNodeOrBlockBoundary(
const HTMLEditor& aHTMLEditor, const EditorDOMPointBase<PT, CT>& aPoint) {
return WSRunScanner(aHTMLEditor, aPoint)
return WSRunScanner(aHTMLEditor.GetActiveEditingHost(), aPoint)
.ScanNextVisibleNodeOrBlockBoundaryFrom(aPoint);
}
@ -305,7 +305,7 @@ class MOZ_STACK_CLASS WSRunScanner final {
template <typename PT, typename CT>
static WSScanResult ScanPreviousVisibleNodeOrBlockBoundary(
const HTMLEditor& aHTMLEditor, const EditorDOMPointBase<PT, CT>& aPoint) {
return WSRunScanner(aHTMLEditor, aPoint)
return WSRunScanner(aHTMLEditor.GetActiveEditingHost(), aPoint)
.ScanPreviousVisibleNodeOrBlockBoundaryFrom(aPoint);
}
@ -321,7 +321,7 @@ class MOZ_STACK_CLASS WSRunScanner final {
HTMLEditUtils::IsSimplyEditableNode(*aPoint.ContainerAsText())) {
return EditorDOMPointInText(aPoint.ContainerAsText(), aPoint.Offset());
}
WSRunScanner scanner(aHTMLEditor, aPoint);
WSRunScanner scanner(aHTMLEditor.GetActiveEditingHost(), aPoint);
return scanner.GetInclusiveNextEditableCharPoint(aPoint);
}
@ -337,7 +337,7 @@ class MOZ_STACK_CLASS WSRunScanner final {
return EditorDOMPointInText(aPoint.ContainerAsText(),
aPoint.Offset() - 1);
}
WSRunScanner scanner(aHTMLEditor, aPoint);
WSRunScanner scanner(aHTMLEditor.GetActiveEditingHost(), aPoint);
return scanner.GetPreviousEditableCharPoint(aPoint);
}