Bug 1926031 - Make Selection::ScrollIntoView take ScrollFlags. r=jjaschke,masayuki

Differential Revision: https://phabricator.services.mozilla.com/D226389
This commit is contained in:
Emilio Cobos Álvarez
2024-10-22 09:58:02 +00:00
parent 228997534a
commit 1123d2e75f
7 changed files with 62 additions and 62 deletions

View File

@@ -720,11 +720,11 @@ nsresult nsFrameSelection::MoveCaret(nsDirection aDirection,
return NS_ERROR_NULL_POINTER;
}
int32_t scrollFlags = 0;
auto scrollFlags = ScrollFlags::None;
if (sel->IsEditorSelection()) {
// If caret moves in editor, it should cause scrolling even if it's in
// overflow: hidden;.
scrollFlags |= Selection::SCROLL_OVERFLOW_HIDDEN;
scrollFlags |= ScrollFlags::ScrollOverflowHidden;
}
const bool doCollapse = [&] {
@@ -1628,9 +1628,13 @@ nsresult nsFrameSelection::ScrollSelectionIntoView(SelectionType aSelectionType,
SelectionRegion aRegion,
int16_t aFlags) const {
int8_t index = GetIndexFromSelectionType(aSelectionType);
if (index < 0) return NS_ERROR_INVALID_ARG;
if (index < 0) {
return NS_ERROR_INVALID_ARG;
}
if (!mDomSelections[index]) return NS_ERROR_NULL_POINTER;
if (!mDomSelections[index]) {
return NS_ERROR_NULL_POINTER;
}
const auto vScroll = [&]() -> WhereToScroll {
if (aFlags & nsISelectionController::SCROLL_VERTICAL_START) {
@@ -1644,20 +1648,21 @@ nsresult nsFrameSelection::ScrollSelectionIntoView(SelectionType aSelectionType,
}
return WhereToScroll::Nearest;
}();
int32_t flags = Selection::SCROLL_DO_FLUSH;
if (aFlags & nsISelectionController::SCROLL_SYNCHRONOUS) {
flags |= Selection::SCROLL_SYNCHRONOUS;
} else if (aFlags & nsISelectionController::SCROLL_FIRST_ANCESTOR_ONLY) {
flags |= Selection::SCROLL_FIRST_ANCESTOR_ONLY;
}
auto mode = aFlags & nsISelectionController::SCROLL_SYNCHRONOUS
? SelectionScrollMode::SyncFlush
: SelectionScrollMode::Async;
auto scrollFlags = ScrollFlags::None;
if (aFlags & nsISelectionController::SCROLL_OVERFLOW_HIDDEN) {
flags |= Selection::SCROLL_OVERFLOW_HIDDEN;
scrollFlags |= ScrollFlags::ScrollOverflowHidden;
}
// After ScrollSelectionIntoView(), the pending notifications might be
// flushed and PresShell/PresContext/Frames may be dead. See bug 418470.
RefPtr<Selection> sel = mDomSelections[index];
return sel->ScrollIntoView(aRegion, ScrollAxis(vScroll), ScrollAxis(), flags);
return sel->ScrollIntoView(aRegion, ScrollAxis(vScroll), ScrollAxis(),
scrollFlags, mode);
}
nsresult nsFrameSelection::RepaintSelection(SelectionType aSelectionType) {