Bug 1646296 - part 1: Make WSRunScanner::FindNearestRun() return const WSFragment* instead of WSFragment* r=m_kato

The result should never be modified so that it should return `const`-pointer.

Differential Revision: https://phabricator.services.mozilla.com/D79964
This commit is contained in:
Masayuki Nakano 2020-06-18 06:02:47 +00:00
parent a0179d273f
commit a852a50071
2 changed files with 16 additions and 15 deletions

View File

@ -206,8 +206,8 @@ already_AddRefed<Element> WSRunObject::InsertBreak(
// meanwhile, the pre case is handled in HandleInsertText() in
// HTMLEditSubActionHandler.cpp
WSFragment* beforeRun = FindNearestRun(aPointToInsert, false);
WSFragment* afterRun = FindNearestRun(aPointToInsert, true);
const WSFragment* beforeRun = FindNearestFragment(aPointToInsert, false);
const WSFragment* afterRun = FindNearestFragment(aPointToInsert, true);
EditorDOMPoint pointToInsert(aPointToInsert);
{
@ -310,13 +310,14 @@ nsresult WSRunObject::InsertText(Document& aDocument,
return NS_OK;
}
WSFragment* beforeRun = FindNearestRun(mScanStartPoint, false);
const WSFragment* beforeRun = FindNearestFragment(mScanStartPoint, false);
// If mScanStartPoint isn't equal to mScanEndPoint, it will replace text (i.e.
// committing composition). And afterRun will be end point of replaced range.
// So we want to know this white-space type (trailing white-space etc) of
// this end point, not inserted (start) point, so we re-scan white-space type.
WSRunObject afterRunObject(MOZ_KnownLive(mHTMLEditor), mScanEndPoint);
WSFragment* afterRun = afterRunObject.FindNearestRun(mScanEndPoint, true);
const WSFragment* afterRun =
afterRunObject.FindNearestFragment(mScanEndPoint, true);
EditorDOMPoint pointToInsert(mScanStartPoint);
nsAutoString theString(aStringToInsert);
@ -614,7 +615,7 @@ WSScanResult WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundaryFrom(
// anything return start of ws.
MOZ_ASSERT(aPoint.IsSet());
WSFragment* run = FindNearestRun(aPoint, false);
const WSFragment* run = FindNearestFragment(aPoint, false);
// Is there a visible run there or earlier?
for (; run; run = run->mLeft) {
@ -650,7 +651,7 @@ WSScanResult WSRunScanner::ScanNextVisibleNodeOrBlockBoundaryFrom(
// anything return end of ws.
MOZ_ASSERT(aPoint.IsSet());
WSFragment* run = FindNearestRun(aPoint, true);
const WSFragment* run = FindNearestFragment(aPoint, true);
// Is there a visible run there or later?
for (; run; run = run->mRight) {
@ -1143,9 +1144,9 @@ nsresult WSRunObject::PrepareToDeleteRangePriv(WSRunObject* aEndObject) {
}
// get the runs before and after selection
WSFragment* beforeRun = FindNearestRun(mScanStartPoint, false);
WSFragment* afterRun =
aEndObject->FindNearestRun(aEndObject->mScanStartPoint, true);
const WSFragment* beforeRun = FindNearestFragment(mScanStartPoint, false);
const WSFragment* afterRun =
aEndObject->FindNearestFragment(aEndObject->mScanStartPoint, true);
if (!beforeRun && !afterRun) {
return NS_OK;
@ -1251,8 +1252,8 @@ nsresult WSRunObject::PrepareToSplitAcrossBlocksPriv() {
// leading or trailing ws after the split.
// get the runs before and after selection
WSFragment* beforeRun = FindNearestRun(mScanStartPoint, false);
WSFragment* afterRun = FindNearestRun(mScanStartPoint, true);
const WSFragment* beforeRun = FindNearestFragment(mScanStartPoint, false);
const WSFragment* afterRun = FindNearestFragment(mScanStartPoint, true);
// adjust normal ws in afterRun if needed
if (afterRun && afterRun->IsVisibleAndMiddleOfHardLine()) {
@ -1614,7 +1615,7 @@ nsresult WSRunObject::ReplaceASCIIWhiteSpacesWithOneNBSP(
}
template <typename PT, typename CT>
WSRunScanner::WSFragment* WSRunScanner::FindNearestRun(
const WSRunScanner::WSFragment* WSRunScanner::FindNearestFragment(
const EditorDOMPointBase<PT, CT>& aPoint, bool aForward) const {
MOZ_ASSERT(aPoint.IsSetAndValid());

View File

@ -552,7 +552,7 @@ class MOZ_STACK_CLASS WSRunScanner {
};
/**
* FindNearestRun() looks for a WSFragment which is closest to specified
* FindNearestFragment() looks for a WSFragment which is closest to specified
* direction from aPoint.
*
* @param aPoint The point to start to look for.
@ -573,8 +573,8 @@ class MOZ_STACK_CLASS WSRunScanner {
* if aPoint is after the last run, returns the last run.
*/
template <typename PT, typename CT>
WSFragment* FindNearestRun(const EditorDOMPointBase<PT, CT>& aPoint,
bool aForward) const;
const WSFragment* FindNearestFragment(
const EditorDOMPointBase<PT, CT>& aPoint, bool aForward) const;
/**
* GetInclusiveNextEditableCharPoint() returns aPoint if it points a character