diff --git a/dom/base/RangeUtils.h b/dom/base/RangeUtils.h index e1fa3ef9394e..98ffc6561444 100644 --- a/dom/base/RangeUtils.h +++ b/dom/base/RangeUtils.h @@ -40,7 +40,8 @@ class RangeUtils final { // If aNode isn't in the child nodes of its parent node, we hit this case. // This may occur when we're called by a mutation observer while aNode is // removed from the parent node. - if (NS_WARN_IF(afterNode.Offset() == 0)) { + if (NS_WARN_IF( + !afterNode.Offset(RawRangeBoundary::OffsetFilter::kValidOffsets))) { return RawRangeBoundary(); } return afterNode; diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp index efb76176fa22..7809b1d5b153 100644 --- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -2123,7 +2123,9 @@ void Selection::Collapse(const RawRangeBoundary& aPoint, ErrorResult& aRv) { aPoint.Container()->IsContent()) { int32_t frameOffset; nsTextFrame* f = do_QueryFrame(nsCaret::GetFrameAndOffset( - this, aPoint.Container(), aPoint.Offset(), &frameOffset)); + this, aPoint.Container(), + *aPoint.Offset(RawRangeBoundary::OffsetFilter::kValidOffsets), + &frameOffset)); if (f && f->IsAtEndOfLine() && f->HasSignificantTerminalNewline()) { // RawRangeBounary::Offset() causes computing offset if it's not been // done yet. However, it's called only when the container is a text @@ -2131,7 +2133,9 @@ void Selection::Collapse(const RawRangeBoundary& aPoint, ErrorResult& aRv) { // any children. So, this doesn't cause computing offset with expensive // method, nsINode::ComputeIndexOf(). if ((aPoint.Container()->AsContent() == f->GetContent() && - f->GetContentEnd() == static_cast(aPoint.Offset())) || + f->GetContentEnd() == + static_cast(*aPoint.Offset( + RawRangeBoundary::OffsetFilter::kValidOffsets))) || (aPoint.Container() == f->GetContent()->GetParentNode() && f->GetContent() == aPoint.GetPreviousSiblingOfChildAtOffset())) { frameSelection->SetHint(CARET_ASSOCIATE_AFTER); diff --git a/dom/base/Selection.h b/dom/base/Selection.h index 43ff763a7107..7e977d5d1c47 100644 --- a/dom/base/Selection.h +++ b/dom/base/Selection.h @@ -231,7 +231,9 @@ class Selection final : public nsSupportsWeakReference, } uint32_t AnchorOffset() const { const RangeBoundary& anchor = AnchorRef(); - return anchor.IsSet() ? anchor.Offset() : 0; + const Maybe offset = + anchor.Offset(RangeBoundary::OffsetFilter::kValidOffsets); + return offset ? *offset : 0; } nsINode* GetFocusNode() const { const RangeBoundary& focus = FocusRef(); @@ -239,7 +241,9 @@ class Selection final : public nsSupportsWeakReference, } uint32_t FocusOffset() const { const RangeBoundary& focus = FocusRef(); - return focus.IsSet() ? focus.Offset() : 0; + const Maybe offset = + focus.Offset(RangeBoundary::OffsetFilter::kValidOffsets); + return offset ? *offset : 0; } nsIContent* GetChildAtAnchorOffset() {