Bug 1609662: part 18) Remove `RangeMatchesBeginPoint` function in Selection. r=smaug

The name was misleading.

Differential Revision: https://phabricator.services.mozilla.com/D60949

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mirko Brodesser 2020-01-24 13:01:59 +00:00
Родитель a508a8ebc8
Коммит bfba826996
2 изменённых файлов: 27 добавлений и 28 удалений

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

@ -263,6 +263,15 @@ class RangeBoundaryBase {
return *this;
}
bool Equals(const nsINode* aNode, uint32_t aOffset) const {
if (mParent != aNode) {
return false;
}
const Maybe<uint32_t> offset = Offset(OffsetFilter::kValidOffsets);
return offset && (*offset == aOffset);
}
template <typename A, typename B>
bool operator==(const RangeBoundaryBase<A, B>& aOther) const {
return mParent == aOther.mParent &&

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

@ -1095,24 +1095,6 @@ nsresult Selection::Clear(nsPresContext* aPresContext) {
return NS_OK;
}
// RangeMatches*Point
//
// Compares the range beginning or ending point, and returns true if it
// exactly matches the given DOM point.
static inline bool RangeMatchesBeginPoint(const nsRange* aRange,
const nsINode* aNode,
int32_t aOffset) {
return aRange->GetStartContainer() == aNode &&
static_cast<int32_t>(aRange->StartOffset()) == aOffset;
}
static inline bool RangeMatchesEndPoint(const nsRange* aRange,
const nsINode* aNode, int32_t aOffset) {
return aRange->GetEndContainer() == aNode &&
static_cast<int32_t>(aRange->EndOffset()) == aOffset;
}
// Selection::EqualsRangeAtPoint
//
// Utility method for checking equivalence of two ranges.
@ -1123,10 +1105,11 @@ bool Selection::EqualsRangeAtPoint(const nsINode* aBeginNode,
int32_t aRangeIndex) const {
if (aRangeIndex >= 0 && aRangeIndex < (int32_t)mRanges.Length()) {
const nsRange* range = mRanges[aRangeIndex].mRange;
if (RangeMatchesBeginPoint(range, aBeginNode, aBeginOffset) &&
RangeMatchesEndPoint(range, aEndNode, aEndOffset))
if (range->StartRef().Equals(aBeginNode, aBeginOffset) &&
range->EndRef().Equals(aEndNode, aEndOffset)) {
return true;
}
}
return false;
}
@ -1194,7 +1177,9 @@ nsresult Selection::GetIndicesForInterval(
// If the interval is strictly before the range at index 0, we can optimize
// by returning now - all ranges start after the given interval
if (!RangeMatchesBeginPoint(endRange, aEndNode, aEndOffset)) return NS_OK;
if (!endRange->StartRef().Equals(aEndNode, aEndOffset)) {
return NS_OK;
}
// We now know that the start point of mRanges[0].mRange equals the end of
// the interval. Thus, when aAllowadjacent is true, the caller is always
@ -1227,7 +1212,9 @@ nsresult Selection::GetIndicesForInterval(
// first two possibilites hold
while (endsBeforeIndex < (int32_t)mRanges.Length()) {
const nsRange* endRange = mRanges[endsBeforeIndex].mRange;
if (!RangeMatchesBeginPoint(endRange, aEndNode, aEndOffset)) break;
if (!endRange->StartRef().Equals(aEndNode, aEndOffset)) {
break;
}
endsBeforeIndex++;
}
@ -1244,20 +1231,22 @@ nsresult Selection::GetIndicesForInterval(
// adjacent range
const nsRange* beginRange = mRanges[beginsAfterIndex].mRange;
if (beginsAfterIndex > 0 && beginRange->Collapsed() &&
RangeMatchesEndPoint(beginRange, aBeginNode, aBeginOffset)) {
beginRange->EndRef().Equals(aBeginNode, aBeginOffset)) {
beginRange = mRanges[beginsAfterIndex - 1].mRange;
if (RangeMatchesEndPoint(beginRange, aBeginNode, aBeginOffset))
if (beginRange->EndRef().Equals(aBeginNode, aBeginOffset)) {
beginsAfterIndex--;
}
}
} else {
// See above for the possibilities at this point. The only case where we
// need to take action is when the range at beginsAfterIndex ends on
// the given interval's start point, but that range isn't collapsed (a
// collapsed range should be included in the returned results).
const nsRange* beginRange = mRanges[beginsAfterIndex].mRange;
if (RangeMatchesEndPoint(beginRange, aBeginNode, aBeginOffset) &&
!beginRange->Collapsed())
if (beginRange->EndRef().Equals(aBeginNode, aBeginOffset) &&
!beginRange->Collapsed()) {
beginsAfterIndex++;
}
// Again, see above for the meaning of endsBeforeIndex at this point.
// In particular, endsBeforeIndex may point to a collaped range which
@ -1265,11 +1254,12 @@ nsresult Selection::GetIndicesForInterval(
// included
if (endsBeforeIndex < (int32_t)mRanges.Length()) {
const nsRange* endRange = mRanges[endsBeforeIndex].mRange;
if (RangeMatchesBeginPoint(endRange, aEndNode, aEndOffset) &&
endRange->Collapsed())
if (endRange->StartRef().Equals(aEndNode, aEndOffset) &&
endRange->Collapsed()) {
endsBeforeIndex++;
}
}
}
NS_ASSERTION(beginsAfterIndex <= endsBeforeIndex, "Is mRanges not ordered?");
NS_ENSURE_STATE(beginsAfterIndex <= endsBeforeIndex);