Bug 1587433: part 7.2) Adapt callers of `RangeBoundaryBase::Offset()`. r=smaug
☠☠ backed out by c0c22dbdd5b8 ☠ ☠
authorMirko Brodesser <mbrodesser@mozilla.com>
Mon, 16 Dec 2019 11:04:01 +0000
changeset 507073 50a798e664a1d32b734b47b68c0213d149abe604
parent 507072 b225586edea68a05b2b3d94888c01aff69bed460
child 507074 f9255884980fc6a89687af026785c672b702aed2
push id36922
push userncsoregi@mozilla.com
push dateMon, 16 Dec 2019 17:21:47 +0000
treeherdermozilla-central@27d0d6cc2131 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1587433
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1587433: part 7.2) Adapt callers of `RangeBoundaryBase::Offset()`. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D54459
dom/base/RangeUtils.h
dom/base/Selection.cpp
dom/base/Selection.h
--- a/dom/base/RangeUtils.h
+++ b/dom/base/RangeUtils.h
@@ -35,17 +35,18 @@ class RangeUtils final {
     nsINode* parentNode = aNode->GetParentNode();
     if (!parentNode) {
       return RawRangeBoundary();
     }
     RawRangeBoundary afterNode(parentNode, aNode->AsContent());
     // 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;
   }
 
   static const RawRangeBoundary GetRawRangeBoundaryBefore(nsINode* aNode) {
     MOZ_ASSERT(aNode);
 
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -2118,25 +2118,29 @@ void Selection::Collapse(const RawRangeB
   // Turn off signal for table selection
   frameSelection->ClearTableCellSelection();
 
   // Hack to display the caret on the right line (bug 1237236).
   if (frameSelection->GetHint() != CARET_ASSOCIATE_AFTER &&
       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
       // node.  In such case, offset has always been set since it cannot have
       // any children.  So, this doesn't cause computing offset with expensive
       // method, nsINode::ComputeIndexOf().
       if ((aPoint.Container()->AsContent() == f->GetContent() &&
-           f->GetContentEnd() == static_cast<int32_t>(aPoint.Offset())) ||
+           f->GetContentEnd() ==
+               static_cast<int32_t>(*aPoint.Offset(
+                   RawRangeBoundary::OffsetFilter::kValidOffsets))) ||
           (aPoint.Container() == f->GetContent()->GetParentNode() &&
            f->GetContent() == aPoint.GetPreviousSiblingOfChildAtOffset())) {
         frameSelection->SetHint(CARET_ASSOCIATE_AFTER);
       }
     }
   }
 
   RefPtr<nsRange> range;
--- a/dom/base/Selection.h
+++ b/dom/base/Selection.h
@@ -226,25 +226,29 @@ class Selection final : public nsSupport
 
   // WebIDL methods
   nsINode* GetAnchorNode() const {
     const RangeBoundary& anchor = AnchorRef();
     return anchor.IsSet() ? anchor.Container() : nullptr;
   }
   uint32_t AnchorOffset() const {
     const RangeBoundary& anchor = AnchorRef();
-    return anchor.IsSet() ? anchor.Offset() : 0;
+    const Maybe<uint32_t> offset =
+        anchor.Offset(RangeBoundary::OffsetFilter::kValidOffsets);
+    return offset ? *offset : 0;
   }
   nsINode* GetFocusNode() const {
     const RangeBoundary& focus = FocusRef();
     return focus.IsSet() ? focus.Container() : nullptr;
   }
   uint32_t FocusOffset() const {
     const RangeBoundary& focus = FocusRef();
-    return focus.IsSet() ? focus.Offset() : 0;
+    const Maybe<uint32_t> offset =
+        focus.Offset(RangeBoundary::OffsetFilter::kValidOffsets);
+    return offset ? *offset : 0;
   }
 
   nsIContent* GetChildAtAnchorOffset() {
     const RangeBoundary& anchor = AnchorRef();
     return anchor.IsSet() ? anchor.GetChildAtOffset() : nullptr;
   }
   nsIContent* GetChildAtFocusOffset() {
     const RangeBoundary& focus = FocusRef();