diff --git a/accessible/generic/HyperTextAccessible.cpp b/accessible/generic/HyperTextAccessible.cpp index 5a83b0b8e678..2294b04c1004 100644 --- a/accessible/generic/HyperTextAccessible.cpp +++ b/accessible/generic/HyperTextAccessible.cpp @@ -236,7 +236,8 @@ nsIntRect HyperTextAccessible::GetBoundsInFrame(nsIFrame* aFrame, nsRect frameScreenRect = frame->GetScreenRectInAppUnits(); // Get the length of the substring in this frame that we want the bounds for - auto [startFrameTextOffset, endFrameTextOffset] = frame->GetOffsets(); + int32_t startFrameTextOffset, endFrameTextOffset; + frame->GetOffsets(startFrameTextOffset, endFrameTextOffset); int32_t frameTotalTextLength = endFrameTextOffset - startFrameTextOffset; int32_t seekLength = endContentOffset - startContentOffset; int32_t frameSubStringLength = diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp index 3071c7879401..6ae94b967c0e 100644 --- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -3470,7 +3470,8 @@ nsresult Selection::SelectionLanguageChange(bool aLangRTL) { return NS_ERROR_FAILURE; } - auto [frameStart, frameEnd] = focusFrame->GetOffsets(); + int32_t frameStart, frameEnd; + focusFrame->GetOffsets(frameStart, frameEnd); RefPtr context = GetPresContext(); nsBidiLevel levelBefore, levelAfter; if (!context) { diff --git a/dom/events/ContentEventHandler.cpp b/dom/events/ContentEventHandler.cpp index 1bfa23b6772e..eeda7a846089 100644 --- a/dom/events/ContentEventHandler.cpp +++ b/dom/events/ContentEventHandler.cpp @@ -966,7 +966,9 @@ nsresult ContentEventHandler::ExpandToClusterBoundary(nsIContent* aContent, nsIFrame* frame = nsFrameSelection::GetFrameForNodeOffset( aContent, int32_t(*aXPOffset), hint, &offsetInFrame); if (frame) { - auto [startOffset, endOffset] = frame->GetOffsets(); + int32_t startOffset, endOffset; + nsresult rv = frame->GetOffsets(startOffset, endOffset); + NS_ENSURE_SUCCESS(rv, rv); if (*aXPOffset == static_cast(startOffset) || *aXPOffset == static_cast(endOffset)) { return NS_OK; @@ -1626,7 +1628,10 @@ ContentEventHandler::GetLastFrameInRangeForTextRect(const RawRange& aRawRange) { *nodePosition.Offset(NodePosition::OffsetFilter::kValidOffsets)); } - auto [start, end] = lastFrame->GetOffsets(); + int32_t start, end; + if (NS_WARN_IF(NS_FAILED(lastFrame->GetOffsets(start, end)))) { + return FrameAndNodeOffset(); + } // If the start offset in the node is same as the computed offset in the // node and it's not 0, the frame shouldn't be added to the text rect. So, diff --git a/layout/base/PresShell.cpp b/layout/base/PresShell.cpp index a6c44a5997b3..ed3f3dc077c6 100644 --- a/layout/base/PresShell.cpp +++ b/layout/base/PresShell.cpp @@ -4646,7 +4646,8 @@ nsRect PresShell::ClipListToRange(nsDisplayListBuilder* aBuilder, bool atStart = (content == aRange->GetStartContainer()); bool atEnd = (content == aRange->GetEndContainer()); if ((atStart || atEnd) && frame->IsTextFrame()) { - auto [frameStartOffset, frameEndOffset] = frame->GetOffsets(); + int32_t frameStartOffset, frameEndOffset; + frame->GetOffsets(frameStartOffset, frameEndOffset); int32_t hilightStart = atStart ? std::max(static_cast(aRange->StartOffset()), diff --git a/layout/base/nsBidiPresUtils.cpp b/layout/base/nsBidiPresUtils.cpp index 8a1567e2dbc1..3849f0998baa 100644 --- a/layout/base/nsBidiPresUtils.cpp +++ b/layout/base/nsBidiPresUtils.cpp @@ -966,7 +966,8 @@ nsresult nsBidiPresUtils::ResolveParagraph(BidiParagraphData* aBpd) { break; } contentTextLength = content->TextLength(); - auto [start, end] = frame->GetOffsets(); + int32_t start, end; + frame->GetOffsets(start, end); NS_ASSERTION(!(contentTextLength < end - start), "Frame offsets don't fit in content"); fragmentLength = std::min(contentTextLength, end - start); @@ -1245,7 +1246,8 @@ void nsBidiPresUtils::TraverseFrames(nsIFrame* aCurrentFrame, do { next = nullptr; - auto [start, end] = frame->GetOffsets(); + int32_t start, end; + frame->GetOffsets(start, end); int32_t endLine = text.FindChar('\n', start); if (endLine == -1) { /* @@ -1277,7 +1279,7 @@ void nsBidiPresUtils::TraverseFrames(nsIFrame* aCurrentFrame, aBpd->AdvanceAndAppendFrame(&frame, aBpd->mCurrentTraverseLine, &nextSibling); NS_ASSERTION(frame, "Premature end of continuation chain"); - std::tie(start, end) = frame->GetOffsets(); + frame->GetOffsets(start, end); aBpd->AppendString( Substring(text, start, std::min(end, endLine) - start)); } diff --git a/layout/base/nsCaret.cpp b/layout/base/nsCaret.cpp index 9ddae5a596a9..60c734266773 100644 --- a/layout/base/nsCaret.cpp +++ b/layout/base/nsCaret.cpp @@ -486,11 +486,11 @@ nsIFrame* nsCaret::GetPaintGeometry(nsRect* aRect) { } // If the offset falls outside of the frame, then don't paint the caret. - if (frame->IsTextFrame()) { - auto [startOffset, endOffset] = frame->GetOffsets(); - if (startOffset > frameOffset || endOffset < frameOffset) { - return nullptr; - } + int32_t startOffset, endOffset; + if (frame->IsTextFrame() && + (NS_FAILED(frame->GetOffsets(startOffset, endOffset)) || + startOffset > frameOffset || endOffset < frameOffset)) { + return nullptr; } nsRect caretRect; @@ -659,12 +659,14 @@ nsIFrame* nsCaret::GetCaretFrameForNodeOffset( aBidiLevel = theFrame->GetEmbeddingLevel(); } + int32_t start; + int32_t end; nsIFrame* frameBefore; nsIFrame* frameAfter; nsBidiLevel levelBefore; // Bidi level of the character before the caret nsBidiLevel levelAfter; // Bidi level of the character after the caret - auto [start, end] = theFrame->GetOffsets(); + theFrame->GetOffsets(start, end); if (start == 0 || end == 0 || start == theFrameOffset || end == theFrameOffset) { nsPrevNextBidiLevels levels = @@ -692,7 +694,7 @@ nsIFrame* nsCaret::GetCaretFrameForNodeOffset( if (theFrame != frameBefore) { if (frameBefore) { // if there is a frameBefore, move into it theFrame = frameBefore; - std::tie(start, end) = theFrame->GetOffsets(); + theFrame->GetOffsets(start, end); theFrameOffset = end; } else { // if there is no frameBefore, we must be at the beginning of @@ -722,7 +724,7 @@ nsIFrame* nsCaret::GetCaretFrameForNodeOffset( if (frameAfter) { // if there is a frameAfter, move into it theFrame = frameAfter; - std::tie(start, end) = theFrame->GetOffsets(); + theFrame->GetOffsets(start, end); theFrameOffset = start; } else { // if there is no frameAfter, we must be at the end of the line @@ -751,7 +753,7 @@ nsIFrame* nsCaret::GetCaretFrameForNodeOffset( !IS_SAME_DIRECTION(aBidiLevel, levelAfter)) { if (NS_SUCCEEDED(aFrameSelection->GetFrameFromLevel( frameAfter, eDirNext, aBidiLevel, &theFrame))) { - std::tie(start, end) = theFrame->GetOffsets(); + theFrame->GetOffsets(start, end); levelAfter = theFrame->GetEmbeddingLevel(); if (IS_LEVEL_RTL(aBidiLevel)) // c8: caret to the right of the // rightmost character @@ -767,7 +769,7 @@ nsIFrame* nsCaret::GetCaretFrameForNodeOffset( !IS_SAME_DIRECTION(aBidiLevel, levelAfter)) { if (NS_SUCCEEDED(aFrameSelection->GetFrameFromLevel( frameBefore, eDirPrevious, aBidiLevel, &theFrame))) { - std::tie(start, end) = theFrame->GetOffsets(); + theFrame->GetOffsets(start, end); levelBefore = theFrame->GetEmbeddingLevel(); if (IS_LEVEL_RTL(aBidiLevel)) // c12: caret to the left of the // leftmost character diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index c55029dd4465..f953975c8787 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -7486,7 +7486,9 @@ void nsLayoutUtils::AssertTreeOnlyEmptyNextInFlows(nsIFrame* aSubtreeRoot) { "frame tree not empty, but caller reported complete status"); // Also assert that text frames map no text. - auto [start, end] = aSubtreeRoot->GetOffsets(); + int32_t start, end; + nsresult rv = aSubtreeRoot->GetOffsets(start, end); + NS_ASSERTION(NS_SUCCEEDED(rv), "GetOffsets failed"); // In some cases involving :first-letter, we'll partially unlink a // continuation in the middle of a continuation chain from its // previous and next continuations before destroying it, presumably so diff --git a/layout/generic/nsFrameSelection.cpp b/layout/generic/nsFrameSelection.cpp index 37f315243e41..25db694914f9 100644 --- a/layout/generic/nsFrameSelection.cpp +++ b/layout/generic/nsFrameSelection.cpp @@ -805,7 +805,7 @@ nsresult nsFrameSelection::MoveCaret(nsDirection aDirection, // hint to ASSOCIATE_BEFORE to indicate that we want the caret displayed // at the end of this frame, not at the beginning of the next one. theFrame = pos.mResultFrame; - std::tie(frameStart, frameEnd) = theFrame->GetOffsets(); + theFrame->GetOffsets(frameStart, frameEnd); currentOffset = pos.mContentOffset; if (frameEnd == currentOffset && !(frameStart == 0 && frameEnd == 0)) tHint = CARET_ASSOCIATE_BEFORE; @@ -820,7 +820,7 @@ nsresult nsFrameSelection::MoveCaret(nsDirection aDirection, tHint, ¤tOffset); if (!theFrame) return NS_ERROR_FAILURE; - std::tie(frameStart, frameEnd) = theFrame->GetOffsets(); + theFrame->GetOffsets(frameStart, frameEnd); } if (context->BidiEnabled()) { @@ -933,26 +933,25 @@ nsPrevNextBidiLevels nsFrameSelection::GetPrevNextBidiLevels( // Get the level of the frames on each side nsIFrame* currentFrame; int32_t currentOffset; + int32_t frameStart, frameEnd; nsDirection direction; - nsPrevNextBidiLevels levels{}; + nsPrevNextBidiLevels levels; levels.SetData(nullptr, nullptr, 0, 0); - currentFrame = GetFrameForNodeOffset( - aNode, static_cast(aContentOffset), aHint, ¤tOffset); - if (!currentFrame) { - return levels; - } + currentFrame = + GetFrameForNodeOffset(aNode, aContentOffset, aHint, ¤tOffset); + if (!currentFrame) return levels; - auto [frameStart, frameEnd] = currentFrame->GetOffsets(); + currentFrame->GetOffsets(frameStart, frameEnd); - if (0 == frameStart && 0 == frameEnd) { + if (0 == frameStart && 0 == frameEnd) direction = eDirPrevious; - } else if (frameStart == currentOffset) { + else if (frameStart == currentOffset) direction = eDirPrevious; - } else if (frameEnd == currentOffset) { + else if (frameEnd == currentOffset) direction = eDirNext; - } else { + else { // we are neither at the beginning nor at the end of the frame, so we have // no worries nsBidiLevel currentLevel = currentFrame->GetEmbeddingLevel(); @@ -1612,7 +1611,9 @@ bool nsFrameSelection::AdjustFrameForLineStart(nsIFrame*& aFrame, return false; } - auto [start, end] = aFrame->GetOffsets(); + int32_t start; + int32_t end; + aFrame->GetOffsets(start, end); if (aFrameOffset != end) { return false; } @@ -1623,7 +1624,7 @@ bool nsFrameSelection::AdjustFrameForLineStart(nsIFrame*& aFrame, } aFrame = nextSibling; - std::tie(start, end) = aFrame->GetOffsets(); + aFrame->GetOffsets(start, end); aFrameOffset = start; return true; } diff --git a/layout/generic/nsIFrame.cpp b/layout/generic/nsIFrame.cpp index dc72ade34885..83c9195c67ee 100644 --- a/layout/generic/nsIFrame.cpp +++ b/layout/generic/nsIFrame.cpp @@ -939,8 +939,10 @@ void nsIFrame::DestroyFrom(nsIFrame* aDestructRoot, presShell->FreeFrame(id, this); } -std::pair nsIFrame::GetOffsets() const { - return std::make_pair(0, 0); +nsresult nsIFrame::GetOffsets(int32_t& aStart, int32_t& aEnd) const { + aStart = 0; + aEnd = 0; + return NS_OK; } static void CompareLayers( @@ -5214,7 +5216,8 @@ static FrameContentRange GetRangeForFrame(const nsIFrame* aFrame) { LayoutFrameType type = aFrame->Type(); if (type == LayoutFrameType::Text) { - auto [offset, offsetEnd] = aFrame->GetOffsets(); + int32_t offset, offsetEnd; + aFrame->GetOffsets(offset, offsetEnd); return FrameContentRange(content, offset, offsetEnd); } @@ -8475,7 +8478,8 @@ static nsContentAndOffset FindLineBreakInText(nsIFrame* aFrame, return result; } - auto [startOffset, endOffset] = aFrame->GetOffsets(); + int32_t startOffset, endOffset; + aFrame->GetOffsets(startOffset, endOffset); result.mContent = aFrame->GetContent(); result.mOffset = endOffset - (aDirection == eDirPrevious ? 0 : 1); return result; @@ -8692,7 +8696,8 @@ nsresult nsIFrame::PeekOffsetForCharacter(nsPeekOffsetStruct* aPos, // selection, this doesn't matter. if (peekSearchState == FOUND && current.mMovedOverNonSelectableText && (!aPos->mExtend || current.mHasSelectableFrame)) { - auto [start, end] = current.mFrame->GetOffsets(); + int32_t start, end; + current.mFrame->GetOffsets(start, end); current.mOffset = aPos->mDirection == eDirNext ? 0 : end - start; } } diff --git a/layout/generic/nsIFrame.h b/layout/generic/nsIFrame.h index 8c49102c0cdc..24aade433a14 100644 --- a/layout/generic/nsIFrame.h +++ b/layout/generic/nsIFrame.h @@ -851,7 +851,7 @@ class nsIFrame : public nsQueryFrame { * Get the offsets of the frame. most will be 0,0 * */ - virtual std::pair GetOffsets() const; + virtual nsresult GetOffsets(int32_t& start, int32_t& end) const; /** * Reset the offsets when splitting frames during Bidi reordering diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index ce7a1d47ab31..3573d3b689a4 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -8144,8 +8144,10 @@ nsresult nsTextFrame::CheckVisibility(nsPresContext* aContext, return NS_OK; } -std::pair nsTextFrame::GetOffsets() const { - return std::make_pair(GetContentOffset(), GetContentEnd()); +nsresult nsTextFrame::GetOffsets(int32_t& start, int32_t& end) const { + start = GetContentOffset(); + end = GetContentEnd(); + return NS_OK; } static int32_t FindEndOfPunctuationRun(const nsTextFragment* aFrag, diff --git a/layout/generic/nsTextFrame.h b/layout/generic/nsTextFrame.h index db32d074fc22..cdce30ce8fb2 100644 --- a/layout/generic/nsTextFrame.h +++ b/layout/generic/nsTextFrame.h @@ -348,7 +348,7 @@ class nsTextFrame : public nsIFrame { void SetLength(int32_t aLength, nsLineLayout* aLineLayout, uint32_t aSetLengthFlags = 0); - std::pair GetOffsets() const final; + nsresult GetOffsets(int32_t& start, int32_t& end) const final; void AdjustOffsetsForBidi(int32_t start, int32_t end) final;