diff --git a/dom/base/AbstractRange.cpp b/dom/base/AbstractRange.cpp index e5454b4b1a1e..e362ad1fb73e 100644 --- a/dom/base/AbstractRange.cpp +++ b/dom/base/AbstractRange.cpp @@ -107,7 +107,10 @@ nsresult AbstractRange::SetStartAndEndInternal( // XXX: Offsets - handle this more efficiently. // If the end offset is less than the start offset, this should be // collapsed at the end offset. - if (aStartBoundary.Offset() > aEndBoundary.Offset()) { + if (*aStartBoundary.Offset( + RangeBoundaryBase::OffsetFilter::kValidOffsets) > + *aEndBoundary.Offset( + RangeBoundaryBase::OffsetFilter::kValidOffsets)) { aRange->DoSetRange(aEndBoundary, aEndBoundary, newStartRoot); } else { aRange->DoSetRange(aStartBoundary, aEndBoundary, newStartRoot); diff --git a/dom/base/AbstractRange.h b/dom/base/AbstractRange.h index 2eec3350b8a7..6d0c4efe6d85 100644 --- a/dom/base/AbstractRange.h +++ b/dom/base/AbstractRange.h @@ -50,17 +50,21 @@ class AbstractRange : public nsISupports, public nsWrapperCache { nsINode* GetStartContainer() const { return mStart.Container(); } nsINode* GetEndContainer() const { return mEnd.Container(); } + + // FYI: Returns 0 if it's not positioned. uint32_t StartOffset() const { - // FYI: Returns 0 if it's not positioned. - return static_cast(mStart.Offset()); + return static_cast( + *mStart.Offset(RangeBoundary::OffsetFilter::kValidOrInvalidOffsets)); } + + // FYI: Returns 0 if it's not positioned. uint32_t EndOffset() const { - // FYI: Returns 0 if it's not positioned. - return static_cast(mEnd.Offset()); + return static_cast( + *mEnd.Offset(RangeBoundary::OffsetFilter::kValidOrInvalidOffsets)); } bool Collapsed() const { return !mIsPositioned || (mStart.Container() == mEnd.Container() && - mStart.Offset() == mEnd.Offset()); + StartOffset() == EndOffset()); } nsINode* GetParentObject() const { return mOwner; } diff --git a/dom/base/RangeBoundary.h b/dom/base/RangeBoundary.h index b39e9e50c833..35a8e5125916 100644 --- a/dom/base/RangeBoundary.h +++ b/dom/base/RangeBoundary.h @@ -100,10 +100,12 @@ class RangeBoundaryBase { return nullptr; } if (!mRef) { - MOZ_ASSERT(Offset() == 0, "invalid RangeBoundary"); + MOZ_ASSERT(*Offset(OffsetFilter::kValidOrInvalidOffsets) == 0, + "invalid RangeBoundary"); return mParent->GetFirstChild(); } - MOZ_ASSERT(mParent->GetChildAt_Deprecated(Offset()) == + MOZ_ASSERT(mParent->GetChildAt_Deprecated( + *Offset(OffsetFilter::kValidOrInvalidOffsets)) == mRef->GetNextSibling()); return mRef->GetNextSibling(); } @@ -204,7 +206,8 @@ class RangeBoundaryBase { if (Ref()) { return Ref()->GetParentNode() == Container(); } - return Offset() <= Container()->Length(); + return *Offset(OffsetFilter::kValidOrInvalidOffsets) <= + Container()->Length(); } bool IsStartOfContainer() const {