Bug 1646296 - part 7: Make `WSRunScanner::InitializeRange*()` template methods r=m_kato

Depends on D79971

Differential Revision: https://phabricator.services.mozilla.com/D79972
This commit is contained in:
Masayuki Nakano 2020-06-22 08:12:37 +00:00
Родитель b9b9e38dd9
Коммит 8243db7082
2 изменённых файлов: 31 добавлений и 20 удалений

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

@ -755,9 +755,11 @@ nsresult WSRunScanner::GetWSNodes() {
return NS_OK;
}
template <typename EditorDOMPointType>
bool WSRunScanner::InitializeRangeStartWithTextNode(
const EditorDOMPointInText& aPoint) {
const EditorDOMPointType& aPoint) {
MOZ_ASSERT(aPoint.IsSetAndValid());
MOZ_DIAGNOSTIC_ASSERT(aPoint.IsInTextNode());
const nsTextFragment& textFragment = aPoint.ContainerAsText()->TextFragment();
for (uint32_t i = std::min(aPoint.Offset(), textFragment.GetLength()); i;
@ -787,15 +789,15 @@ bool WSRunScanner::InitializeRangeStartWithTextNode(
return false;
}
template <typename EditorDOMPointType>
void WSRunScanner::InitializeRangeStart(
const EditorDOMPoint& aPoint,
const EditorDOMPointType& aPoint,
const nsIContent& aEditableBlockParentOrTopmostEditableInlineContent) {
MOZ_ASSERT(aPoint.IsSetAndValid());
// first look backwards to find preceding ws nodes
if (aPoint.IsInTextNode() && !aPoint.IsStartOfContainer()) {
if (InitializeRangeStartWithTextNode(
EditorDOMPointInText(aPoint.ContainerAsText(), aPoint.Offset()))) {
if (InitializeRangeStartWithTextNode(aPoint)) {
return;
}
// The text node does not have visible character, let's keep scanning
@ -848,7 +850,7 @@ void WSRunScanner::InitializeRangeStart(
// Zero length text node. Set start point to it
// so we can get past it!
InitializeRangeStart(
EditorDOMPoint(previousLeafContentOrBlock->AsText(), 0),
EditorDOMPointInText(previousLeafContentOrBlock->AsText(), 0),
aEditableBlockParentOrTopmostEditableInlineContent);
return;
}
@ -860,13 +862,16 @@ void WSRunScanner::InitializeRangeStart(
// The text node does not have visible character, let's keep scanning
// preceding nodes.
InitializeRangeStart(EditorDOMPoint(previousLeafContentOrBlock->AsText(), 0),
aEditableBlockParentOrTopmostEditableInlineContent);
InitializeRangeStart(
EditorDOMPointInText(previousLeafContentOrBlock->AsText(), 0),
aEditableBlockParentOrTopmostEditableInlineContent);
}
template <typename EditorDOMPointType>
bool WSRunScanner::InitializeRangeEndWithTextNode(
const EditorDOMPointInText& aPoint) {
const EditorDOMPointType& aPoint) {
MOZ_ASSERT(aPoint.IsSetAndValid());
MOZ_DIAGNOSTIC_ASSERT(aPoint.IsInTextNode());
const nsTextFragment& textFragment = aPoint.ContainerAsText()->TextFragment();
for (uint32_t i = aPoint.Offset(); i < textFragment.GetLength(); i++) {
@ -895,19 +900,19 @@ bool WSRunScanner::InitializeRangeEndWithTextNode(
return false;
}
template <typename EditorDOMPointType>
void WSRunScanner::InitializeRangeEnd(
const EditorDOMPoint& aPoint,
const EditorDOMPointType& aPoint,
const nsIContent& aEditableBlockParentOrTopmostEditableInlineContent) {
MOZ_ASSERT(aPoint.IsSetAndValid());
if (aPoint.IsInTextNode() && !aPoint.IsEndOfContainer()) {
if (InitializeRangeEndWithTextNode(
EditorDOMPointInText(aPoint.ContainerAsText(), aPoint.Offset()))) {
if (InitializeRangeEndWithTextNode(aPoint)) {
return;
}
// The text node does not have visible character, let's keep scanning
// following nodes.
InitializeRangeEnd(EditorDOMPoint::AtEndOf(*aPoint.ContainerAsText()),
InitializeRangeEnd(EditorDOMPointInText::AtEndOf(*aPoint.ContainerAsText()),
aEditableBlockParentOrTopmostEditableInlineContent);
return;
}
@ -956,8 +961,9 @@ void WSRunScanner::InitializeRangeEnd(
if (!nextLeafContentOrBlock->AsText()->TextFragment().GetLength()) {
// Zero length text node. Set end point to it
// so we can get past it!
InitializeRangeEnd(EditorDOMPoint(nextLeafContentOrBlock->AsText(), 0),
aEditableBlockParentOrTopmostEditableInlineContent);
InitializeRangeEnd(
EditorDOMPointInText(nextLeafContentOrBlock->AsText(), 0),
aEditableBlockParentOrTopmostEditableInlineContent);
return;
}
@ -968,8 +974,9 @@ void WSRunScanner::InitializeRangeEnd(
// The text node does not have visible character, let's keep scanning
// following nodes.
InitializeRangeEnd(EditorDOMPoint::AtEndOf(*nextLeafContentOrBlock->AsText()),
aEditableBlockParentOrTopmostEditableInlineContent);
InitializeRangeEnd(
EditorDOMPointInText::AtEndOf(*nextLeafContentOrBlock->AsText()),
aEditableBlockParentOrTopmostEditableInlineContent);
}
void WSRunScanner::GetRuns() {

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

@ -638,14 +638,18 @@ class MOZ_STACK_CLASS WSRunScanner {
WSFragment::Visible aIsVisible,
WSFragment::StartOfHardLine aIsStartOfHardLine,
WSFragment::EndOfHardLine aIsEndOfHardLine);
template <typename EditorDOMPointType>
void InitializeRangeStart(
const EditorDOMPoint& aPoint,
const EditorDOMPointType& aPoint,
const nsIContent& aEditableBlockParentOrTopmostEditableInlineContent);
template <typename EditorDOMPointType>
void InitializeRangeEnd(
const EditorDOMPoint& aPoint,
const EditorDOMPointType& aPoint,
const nsIContent& aEditableBlockParentOrTopmostEditableInlineContent);
bool InitializeRangeStartWithTextNode(const EditorDOMPointInText& aPoint);
bool InitializeRangeEndWithTextNode(const EditorDOMPointInText& aPoint);
template <typename EditorDOMPointType>
bool InitializeRangeStartWithTextNode(const EditorDOMPointType& aPoint);
template <typename EditorDOMPointType>
bool InitializeRangeEndWithTextNode(const EditorDOMPointType& aPoint);
// The node passed to our constructor.
EditorDOMPoint mScanStartPoint;