Bug 1649980 - part 10: Get rid of `WSRunScanner::mScanEndPoint` r=m_kato

Now, `mScanEndPoint` is not used.  This patch removes it and clean up the
constructors of `WSRunScanner` and `WSRunObject`.

Differential Revision: https://phabricator.services.mozilla.com/D82703
This commit is contained in:
Masayuki Nakano 2020-07-13 14:57:38 +00:00
Родитель 1d08048cd9
Коммит 55c0146bd3
5 изменённых файлов: 40 добавлений и 124 удалений

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

@ -8061,7 +8061,7 @@ Element* HTMLEditor::GetInvisibleBRElementAt(
return nullptr;
}
WSRunScanner wsScannerForPoint(this, aPoint);
WSRunScanner wsScannerForPoint(*this, aPoint);
return wsScannerForPoint.StartsFromBRElement()
? wsScannerForPoint.StartReasonBRElementPtr()
: nullptr;
@ -8134,7 +8134,7 @@ HTMLEditor::GetRangeExtendedToIncludeInvisibleNodes(
break;
}
MOZ_ASSERT(backwardScanFromStartResult.GetContent() ==
WSRunScanner(this, atStart).GetStartReasonContent());
WSRunScanner(*this, 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(
@ -8156,7 +8156,7 @@ HTMLEditor::GetRangeExtendedToIncludeInvisibleNodes(
atEnd.GetContainer() != editingHost) {
EditorDOMPoint atFirstInvisibleBRElement;
for (;;) {
WSRunScanner wsScannerAtEnd(this, atEnd);
WSRunScanner wsScannerAtEnd(*this, atEnd);
WSScanResult forwardScanFromEndResult =
wsScannerAtEnd.ScanNextVisibleNodeOrBlockBoundaryFrom(atEnd);
if (forwardScanFromEndResult.ReachedBRElement()) {
@ -8272,7 +8272,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(*this, endPoint);
if (wsScannerAtEnd.ScanPreviousVisibleNodeOrBlockBoundaryFrom(endPoint)
.ReachedSomething()) {
// eThisBlock and eOtherBlock conveniently distinguish cases
@ -8301,7 +8301,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(*this, startPoint);
if (wsScannerAtStart.ScanNextVisibleNodeOrBlockBoundaryFrom(startPoint)
.ReachedSomething()) {
// eThisBlock and eOtherBlock conveniently distinguish cases

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

@ -1547,7 +1547,7 @@ EditorRawDOMPoint HTMLEditor::GetBetterInsertionPointFor(
return pointToInsert;
}
WSRunScanner wsScannerForPointToInsert(this, pointToInsert);
WSRunScanner wsScannerForPointToInsert(*this, 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>,
@ -3143,7 +3143,7 @@ nsresult HTMLEditor::DeleteParentBlocksWithTransactionIfEmpty(
MOZ_ASSERT(mPlaceholderBatch);
// First, check there is visible contents before the point in current block.
WSRunScanner wsScannerForPoint(this, aPoint);
WSRunScanner wsScannerForPoint(*this, aPoint);
if (!wsScannerForPoint.StartsFromCurrentBlockBoundary()) {
// If there is visible node before the point, we shouldn't remove the
// parent block.

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

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

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

@ -39,24 +39,6 @@ using ChildBlockBoundary = HTMLEditUtils::ChildBlockBoundary;
const char16_t kNBSP = 160;
template WSRunScanner::WSRunScanner(const HTMLEditor* aHTMLEditor,
const EditorDOMPoint& aScanStartPoint,
const EditorDOMPoint& aScanEndPoint);
template WSRunScanner::WSRunScanner(const HTMLEditor* aHTMLEditor,
const EditorRawDOMPoint& aScanStartPoint,
const EditorRawDOMPoint& aScanEndPoint);
template WSRunScanner::WSRunScanner(const HTMLEditor* aHTMLEditor,
const EditorDOMPointInText& aScanStartPoint,
const EditorDOMPointInText& aScanEndPoint);
template WSRunObject::WSRunObject(HTMLEditor& aHTMLEditor,
const EditorDOMPoint& aScanStartPoint,
const EditorDOMPoint& aScanEndPoint);
template WSRunObject::WSRunObject(HTMLEditor& aHTMLEditor,
const EditorRawDOMPoint& aScanStartPoint,
const EditorRawDOMPoint& aScanEndPoint);
template WSRunObject::WSRunObject(HTMLEditor& aHTMLEditor,
const EditorDOMPointInText& aScanStartPoint,
const EditorDOMPointInText& aScanEndPoint);
template WSScanResult WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundaryFrom(
const EditorDOMPoint& aPoint) const;
template WSScanResult WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundaryFrom(
@ -65,6 +47,7 @@ template WSScanResult WSRunScanner::ScanNextVisibleNodeOrBlockBoundaryFrom(
const EditorDOMPoint& aPoint) const;
template WSScanResult WSRunScanner::ScanNextVisibleNodeOrBlockBoundaryFrom(
const EditorRawDOMPoint& aPoint) const;
template nsresult WSRunObject::NormalizeWhiteSpacesAround(
HTMLEditor& aHTMLEditor, const EditorDOMPoint& aScanStartPoint);
template nsresult WSRunObject::NormalizeWhiteSpacesAround(
@ -72,26 +55,12 @@ template nsresult WSRunObject::NormalizeWhiteSpacesAround(
template nsresult WSRunObject::NormalizeWhiteSpacesAround(
HTMLEditor& aHTMLEditor, const EditorDOMPointInText& aScanStartPoint);
template <typename PT, typename CT>
WSRunScanner::WSRunScanner(const HTMLEditor* aHTMLEditor,
const EditorDOMPointBase<PT, CT>& aScanStartPoint,
const EditorDOMPointBase<PT, CT>& aScanEndPoint)
: mScanStartPoint(aScanStartPoint),
mScanEndPoint(aScanEndPoint),
mEditingHost(aHTMLEditor->GetActiveEditingHost()),
mHTMLEditor(aHTMLEditor),
mTextFragmentDataAtStart(mScanStartPoint, mEditingHost) {
MOZ_ASSERT(
*nsContentUtils::ComparePoints(aScanStartPoint.ToRawRangeBoundary(),
aScanEndPoint.ToRawRangeBoundary()) <= 0);
}
template <typename PT, typename CT>
WSRunObject::WSRunObject(HTMLEditor& aHTMLEditor,
const EditorDOMPointBase<PT, CT>& aScanStartPoint,
const EditorDOMPointBase<PT, CT>& aScanEndPoint)
: WSRunScanner(&aHTMLEditor, aScanStartPoint, aScanEndPoint),
mHTMLEditor(aHTMLEditor) {}
template WSRunScanner::TextFragmentData::TextFragmentData(
const EditorDOMPoint& aPoint, const Element* aEditingHost);
template WSRunScanner::TextFragmentData::TextFragmentData(
const EditorRawDOMPoint& aPoint, const Element* aEditingHost);
template WSRunScanner::TextFragmentData::TextFragmentData(
const EditorDOMPointInText& aPoint, const Element* aEditingHost);
// static
nsresult WSRunObject::DeleteInvisibleASCIIWhiteSpaces(
@ -178,7 +147,7 @@ nsresult WSRunObject::PrepareToSplitAcrossBlocks(HTMLEditor& aHTMLEditor,
AutoTrackDOMPoint tracker(aHTMLEditor.RangeUpdaterRef(), aSplitNode,
aSplitOffset);
WSRunObject wsObj(aHTMLEditor, MOZ_KnownLive(*aSplitNode), *aSplitOffset);
WSRunObject wsObj(aHTMLEditor, EditorRawDOMPoint(*aSplitNode, *aSplitOffset));
nsresult rv = wsObj.PrepareToSplitAcrossBlocksPriv();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),

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

@ -269,37 +269,14 @@ class MOZ_STACK_CLASS WSScanResult final {
class MOZ_STACK_CLASS WSRunScanner {
public:
using WSType = WSScanResult::WSType;
/**
* The constructors take 2 DOM points. They represent a range in an editing
* host. aScanEndPoint (aScanEndNode and aScanEndOffset) must be later
* point from aScanStartPoint (aScanStartNode and aScanStartOffset).
* The end point is currently used only with InsertText(). Therefore,
* currently, this assumes that the range does not cross block boundary.
*
* Actually, WSRunScanner scans white-space type at mScanStartPoint position
* only.
*
* If you use aScanEndPoint newly, please test enough.
*/
template <typename PT, typename CT>
WSRunScanner(const HTMLEditor* aHTMLEditor,
const EditorDOMPointBase<PT, CT>& aScanStartPoint,
const EditorDOMPointBase<PT, CT>& aScanEndPoint);
template <typename PT, typename CT>
WSRunScanner(const HTMLEditor* aHTMLEditor,
const EditorDOMPointBase<PT, CT>& aScanStartPoint)
: WSRunScanner(aHTMLEditor, aScanStartPoint, aScanStartPoint) {}
WSRunScanner(const HTMLEditor* aHTMLEditor, nsINode* aScanStartNode,
int32_t aScanStartOffset, nsINode* aScanEndNode,
int32_t aScanEndOffset)
: WSRunScanner(aHTMLEditor,
EditorRawDOMPoint(aScanStartNode, aScanStartOffset),
EditorRawDOMPoint(aScanEndNode, aScanEndOffset)) {}
WSRunScanner(const HTMLEditor* aHTMLEditor, nsINode* aScanStartNode,
int32_t aScanStartOffset)
: WSRunScanner(aHTMLEditor,
EditorRawDOMPoint(aScanStartNode, aScanStartOffset),
EditorRawDOMPoint(aScanStartNode, aScanStartOffset)) {}
template <typename EditorDOMPointType>
WSRunScanner(const HTMLEditor& aHTMLEditor,
const EditorDOMPointType& aScanStartPoint)
: mScanStartPoint(aScanStartPoint),
mEditingHost(aHTMLEditor.GetActiveEditingHost()),
mHTMLEditor(&aHTMLEditor),
mTextFragmentDataAtStart(mScanStartPoint, mEditingHost) {}
// ScanNextVisibleNodeOrBlockBoundaryForwardFrom() returns the first visible
// node after aPoint. If there is no visible nodes after aPoint, returns
@ -311,7 +288,7 @@ class MOZ_STACK_CLASS WSRunScanner {
template <typename PT, typename CT>
static WSScanResult ScanNextVisibleNodeOrBlockBoundary(
const HTMLEditor& aHTMLEditor, const EditorDOMPointBase<PT, CT>& aPoint) {
return WSRunScanner(&aHTMLEditor, aPoint)
return WSRunScanner(aHTMLEditor, aPoint)
.ScanNextVisibleNodeOrBlockBoundaryFrom(aPoint);
}
@ -325,7 +302,7 @@ class MOZ_STACK_CLASS WSRunScanner {
template <typename PT, typename CT>
static WSScanResult ScanPreviousVisibleNodeOrBlockBoundary(
const HTMLEditor& aHTMLEditor, const EditorDOMPointBase<PT, CT>& aPoint) {
return WSRunScanner(&aHTMLEditor, aPoint)
return WSRunScanner(aHTMLEditor, aPoint)
.ScanPreviousVisibleNodeOrBlockBoundaryFrom(aPoint);
}
@ -341,7 +318,7 @@ class MOZ_STACK_CLASS WSRunScanner {
HTMLEditUtils::IsSimplyEditableNode(*aPoint.ContainerAsText())) {
return EditorDOMPointInText(aPoint.ContainerAsText(), aPoint.Offset());
}
WSRunScanner scanner(&aHTMLEditor, aPoint);
WSRunScanner scanner(aHTMLEditor, aPoint);
return scanner.GetInclusiveNextEditableCharPoint(aPoint);
}
@ -357,19 +334,19 @@ class MOZ_STACK_CLASS WSRunScanner {
return EditorDOMPointInText(aPoint.ContainerAsText(),
aPoint.Offset() - 1);
}
WSRunScanner scanner(&aHTMLEditor, aPoint);
WSRunScanner scanner(aHTMLEditor, aPoint);
return scanner.GetPreviousEditableCharPoint(aPoint);
}
/**
* GetStartReasonContent() and GetEndReasonContent() return a node which
* was found by scanning from mScanStartPoint backward or mScanEndPoint
* forward. If there was white-spaces or text from the point, returns the
* text node. Otherwise, returns an element which is explained by the
* following methods. Note that when the reason is
* WSType::CurrentBlockBoundary, In most cases, it's current block element
* which is editable, but also may be non-element and/or non-editable. See
* MOZ_ASSERT_IF()s in WSScanResult::AssertIfInvalidData() for the detail.
* was found by scanning from mScanStartPoint backward or forward. If there
* was white-spaces or text from the point, returns the text node. Otherwise,
* returns an element which is explained by the following methods. Note that
* when the reason is WSType::CurrentBlockBoundary, In most cases, it's
* current block element which is editable, but also may be non-element and/or
* non-editable. See MOZ_ASSERT_IF()s in WSScanResult::AssertIfInvalidData()
* for the detail.
*/
nsIContent* GetStartReasonContent() const {
return TextFragmentDataAtStart().GetStartReasonContent();
@ -1083,7 +1060,6 @@ class MOZ_STACK_CLASS WSRunScanner {
// The node passed to our constructor.
EditorDOMPoint mScanStartPoint;
EditorDOMPoint mScanEndPoint;
// Together, the above represent the point at which we are building up ws
// info.
@ -1105,39 +1081,10 @@ class MOZ_STACK_CLASS WSRunObject final : public WSRunScanner {
public:
enum BlockBoundary { kBeforeBlock, kBlockStart, kBlockEnd, kAfterBlock };
/**
* The constructors take 2 DOM points. They represent a range in an editing
* host. aScanEndPoint (aScanEndNode and aScanEndOffset) must be later
* point from aScanStartPoint (aScanStartNode and aScanStartOffset).
* The end point is currently used only with InsertText(). Therefore,
* currently, this assumes that the range does not cross block boundary. If
* you use aScanEndPoint newly, please test enough.
* TODO: PrepareToJoinBlocks(), PrepareToDeleteRange() and
* PrepareToDeleteNode() should be redesigned with aScanEndPoint.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT WSRunObject(
HTMLEditor& aHTMLEditor,
const EditorDOMPointBase<PT, CT>& aScanStartPoint,
const EditorDOMPointBase<PT, CT>& aScanEndPoint);
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT WSRunObject(
HTMLEditor& aHTMLEditor,
const EditorDOMPointBase<PT, CT>& aScanStartPoint)
: WSRunObject(aHTMLEditor, aScanStartPoint, aScanStartPoint) {}
template <typename EditorDOMPointType>
MOZ_CAN_RUN_SCRIPT WSRunObject(HTMLEditor& aHTMLEditor,
nsINode* aScanStartNode,
int32_t aScanStartOffset,
nsINode* aScanEndNode, int32_t aScanEndOffset)
: WSRunObject(aHTMLEditor,
EditorRawDOMPoint(aScanStartNode, aScanStartOffset),
EditorRawDOMPoint(aScanEndNode, aScanEndOffset)) {}
MOZ_CAN_RUN_SCRIPT WSRunObject(HTMLEditor& aHTMLEditor,
nsINode* aScanStartNode,
int32_t aScanStartOffset)
: WSRunObject(aHTMLEditor,
EditorRawDOMPoint(aScanStartNode, aScanStartOffset),
EditorRawDOMPoint(aScanStartNode, aScanStartOffset)) {}
const EditorDOMPointType& aScanStartPoint)
: WSRunScanner(aHTMLEditor, aScanStartPoint), mHTMLEditor(aHTMLEditor) {}
/**
* DeleteInvisibleASCIIWhiteSpaces() removes invisible leading white-spaces