Bug 1732463 - Make nsIFrame::GetContainingBlockForLine return a pair of nsIFrame*s instead of using an outparam for one of them. r=TYLin

Differential Revision: https://phabricator.services.mozilla.com/D126587
This commit is contained in:
Jonathan Kew 2021-09-25 09:13:02 +00:00
parent 74fb80abc4
commit 1989dbf0ca
3 changed files with 28 additions and 32 deletions

View File

@ -141,17 +141,15 @@ static bool IsLocalAccAtLineStart(LocalAccessible* aAcc) {
return false;
}
nsIFrame::GetLastLeaf(&prevFrame);
nsIFrame* thisLineFrame = nullptr;
nsIFrame* thisBlock = thisFrame->GetContainingBlockForLine(
/* aLockScroll */ false, thisLineFrame);
auto [thisBlock, thisLineFrame] = thisFrame->GetContainingBlockForLine(
/* aLockScroll */ false);
if (!thisBlock) {
// We couldn't get the containing block for this frame. In that case, we
// play it safe and assume this is the beginning of a new line.
return true;
}
nsIFrame* prevLineFrame = nullptr;
nsIFrame* prevBlock = prevFrame->GetContainingBlockForLine(
/* aLockScroll */ false, prevLineFrame);
auto [prevBlock, prevLineFrame] = prevFrame->GetContainingBlockForLine(
/* aLockScroll */ false);
if (thisBlock != prevBlock) {
// If the blocks are different, that means there's nothing before us on the
// same line, so we're at the start.

View File

@ -8728,12 +8728,12 @@ nsresult nsIFrame::PeekOffsetForLine(nsPeekOffsetStruct* aPos) {
nsresult result = NS_ERROR_FAILURE;
while (NS_FAILED(result)) {
nsIFrame* lineFrame;
blockFrame =
blockFrame->GetContainingBlockForLine(aPos->mScrollViewStop, lineFrame);
if (!blockFrame) {
auto [newBlock, lineFrame] =
blockFrame->GetContainingBlockForLine(aPos->mScrollViewStop);
if (!newBlock) {
return NS_ERROR_FAILURE;
}
blockFrame = newBlock;
nsAutoLineIterator iter = blockFrame->GetLineIterator();
int32_t thisLine = iter->FindLineContaining(lineFrame);
MOZ_ASSERT(thisLine >= 0, "Failed to find line!");
@ -8826,12 +8826,11 @@ nsresult nsIFrame::PeekOffsetForLine(nsPeekOffsetStruct* aPos) {
nsresult nsIFrame::PeekOffsetForLineEdge(nsPeekOffsetStruct* aPos) {
// Adjusted so that the caret can't get confused when content changes
nsIFrame* blockFrame = AdjustFrameForSelectionStyles(this);
Element* editingHost = blockFrame->GetContent()->GetEditingHost();
nsIFrame* frame = AdjustFrameForSelectionStyles(this);
Element* editingHost = frame->GetContent()->GetEditingHost();
nsIFrame* lineFrame;
blockFrame =
blockFrame->GetContainingBlockForLine(aPos->mScrollViewStop, lineFrame);
auto [blockFrame, lineFrame] =
frame->GetContainingBlockForLine(aPos->mScrollViewStop);
if (!blockFrame) {
return NS_ERROR_FAILURE;
}
@ -9039,9 +9038,8 @@ nsresult nsIFrame::CheckVisibility(nsPresContext*, int32_t, int32_t, bool,
return NS_ERROR_NOT_IMPLEMENTED;
}
nsIFrame* nsIFrame::GetContainingBlockForLine(bool aLockScroll,
nsIFrame*& aLineFrame) const {
aLineFrame = nullptr;
std::pair<nsIFrame*, nsIFrame*> nsIFrame::GetContainingBlockForLine(
bool aLockScroll) const {
const nsIFrame* parentFrame = this;
const nsIFrame* frame;
while (parentFrame) {
@ -9055,21 +9053,21 @@ nsIFrame* nsIFrame::GetContainingBlockForLine(bool aLockScroll,
}
frame = frame->GetPlaceholderFrame();
if (!frame) {
return nullptr;
return std::pair(nullptr, nullptr);
}
}
parentFrame = frame->GetParent();
if (parentFrame) {
if (aLockScroll && parentFrame->IsScrollFrame()) {
return nullptr;
return std::pair(nullptr, nullptr);
}
if (parentFrame->CanProvideLineIterator()) {
aLineFrame = const_cast<nsIFrame*>(frame);
return const_cast<nsIFrame*>(parentFrame);
return std::pair(const_cast<nsIFrame*>(parentFrame),
const_cast<nsIFrame*>(frame));
}
}
}
return nullptr;
return std::pair(nullptr, nullptr);
}
Result<bool, nsresult> nsIFrame::IsVisuallyAtLineEdge(
@ -9140,9 +9138,8 @@ nsIFrame::SelectablePeekReport nsIFrame::GetFrameFromDirection(
bool selectable = false;
nsIFrame* traversedFrame = this;
while (!selectable) {
nsIFrame* lineFrame;
nsIFrame* blockFrame =
traversedFrame->GetContainingBlockForLine(aScrollViewStop, lineFrame);
auto [blockFrame, lineFrame] =
traversedFrame->GetContainingBlockForLine(aScrollViewStop);
if (!blockFrame) {
return result;
}

View File

@ -3890,14 +3890,15 @@ class nsIFrame : public nsQueryFrame {
SelectablePeekReport GetFrameFromDirection(const nsPeekOffsetStruct& aPos);
/**
* Return the containing block frame for a line; i.e. the frame which
* supports a line iterator.
* Return:
* (1) the containing block frame for a line; i.e. the frame which
* supports a line iterator, or null if none can be found; and
* (2) the frame to use to get a line number, which will be direct child of
* the returned containing block.
* @param aLockScroll true to avoid breaking outside scrollframes.
* @param aLineFrame the frame to use to get a line number, which will be a
* a direct child of the returned containing block.
*/
nsIFrame* GetContainingBlockForLine(bool aLockScroll,
nsIFrame*& aLineFrame) const;
std::pair<nsIFrame*, nsIFrame*> GetContainingBlockForLine(
bool aLockScroll) const;
private:
Result<bool, nsresult> IsVisuallyAtLineEdge(nsILineIterator* aLineIterator,