Bug 1649931 - Part 3: Add nsIFrameEnumerator::Traverse() r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D81954
This commit is contained in:
Kagami Sascha Rosylight 2020-07-03 00:48:59 +00:00
Родитель a76fa900a0
Коммит f92968ee05
4 изменённых файлов: 22 добавлений и 34 удалений

Просмотреть файл

@ -3901,20 +3901,14 @@ nsresult nsFocusManager::GetNextTabbableContent(
} else if (aRootContent->IsFocusable()) {
frameTraversal->Next();
}
frame = static_cast<nsIFrame*>(frameTraversal->CurrentItem());
frame = frameTraversal->CurrentItem();
} else if (getNextFrame &&
(!iterStartContent ||
!iterStartContent->IsHTMLElement(nsGkAtoms::area))) {
// Need to do special check in case we're in an imagemap which has
// multiple content nodes per frame, so don't skip over the starting
// frame.
if (aForward) {
frameTraversal->Next();
} else {
frameTraversal->Prev();
}
frame = static_cast<nsIFrame*>(frameTraversal->CurrentItem());
frame = frameTraversal->Traverse(aForward);
}
}

Просмотреть файл

@ -27,6 +27,15 @@ class nsIFrameEnumerator : public nsISupports {
virtual void Last() = 0;
virtual void Prev() = 0;
inline nsIFrame* Traverse(bool aForward) {
if (aForward) {
Next();
} else {
Prev();
}
return CurrentItem();
};
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIFrameEnumerator, NS_IFRAMEENUMERATOR_IID)

Просмотреть файл

@ -8111,8 +8111,7 @@ nsresult nsIFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext,
if (aPos->mDirection == eDirNext && (resultFrame == nearStoppingFrame))
break;
// always try previous on THAT line if that fails go the other way
frameTraversal->Prev();
resultFrame = frameTraversal->CurrentItem();
resultFrame = frameTraversal->Traverse(/* aForward = */ false);
if (!resultFrame) return NS_ERROR_FAILURE;
}
@ -8151,8 +8150,7 @@ nsresult nsIFrame::GetNextPrevLineFromeBlockFrame(nsPresContext* aPresContext,
if (aPos->mDirection == eDirNext && (resultFrame == farStoppingFrame))
break;
// previous didnt work now we try "next"
frameTraversal->Next();
nsIFrame* tempFrame = frameTraversal->CurrentItem();
nsIFrame* tempFrame = frameTraversal->Traverse(/* aForward = */ true);
if (!tempFrame) break;
resultFrame = tempFrame;
}
@ -8871,9 +8869,15 @@ nsresult nsIFrame::GetFrameFromDirection(
*aOutJumpedLine = false;
*aOutMovedOverNonSelectableText = false;
nsresult result;
nsPresContext* presContext = PresContext();
bool needsVisualTraversal = aVisual && presContext->BidiEnabled();
nsCOMPtr<nsIFrameEnumerator> frameTraversal;
MOZ_TRY(NS_NewFrameTraversal(getter_AddRefs(frameTraversal), presContext,
this, eLeaf, needsVisualTraversal,
aScrollViewStop,
true, // aFollowOOFs
false // aSkipPopupChecks
));
// Find the prev/next selectable frame
bool selectable = false;
@ -8899,21 +8903,7 @@ nsresult nsIFrame::GetFrameFromDirection(
return NS_ERROR_FAILURE; // we are done. cannot jump lines
}
nsCOMPtr<nsIFrameEnumerator> frameTraversal;
result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal), presContext,
traversedFrame, eLeaf, needsVisualTraversal,
aScrollViewStop,
true, // aFollowOOFs
false // aSkipPopupChecks
);
if (NS_FAILED(result)) return result;
if (aDirection == eDirNext)
frameTraversal->Next();
else
frameTraversal->Prev();
traversedFrame = frameTraversal->CurrentItem();
traversedFrame = frameTraversal->Traverse(aDirection == eDirNext);
if (!traversedFrame) {
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -1032,12 +1032,7 @@ nsresult nsFrameSelection::GetFrameFromLevel(nsIFrame* aFrameIn,
do {
*aFrameOut = foundFrame;
if (aDirection == eDirNext)
frameTraversal->Next();
else
frameTraversal->Prev();
foundFrame = frameTraversal->CurrentItem();
foundFrame = frameTraversal->Traverse(aDirection == eDirNext);
if (!foundFrame) return NS_ERROR_FAILURE;
foundLevel = foundFrame->GetEmbeddingLevel();