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

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

@ -27,6 +27,15 @@ class nsIFrameEnumerator : public nsISupports {
virtual void Last() = 0; virtual void Last() = 0;
virtual void Prev() = 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) NS_DEFINE_STATIC_IID_ACCESSOR(nsIFrameEnumerator, NS_IFRAMEENUMERATOR_IID)

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

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

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

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