Bug 1719330 - Limit line-scrolling to one page in scrollable elements with a short viewport. r=botond

Differential Revision: https://phabricator.services.mozilla.com/D159662
This commit is contained in:
Razvan Cojocaru 2022-10-21 18:31:46 +00:00
Родитель 15cc45b65a
Коммит 605f03838c
4 изменённых файлов: 82 добавлений и 6 удалений

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

@ -2143,6 +2143,7 @@ CSSPoint AsyncPanZoomController::GetKeyboardDestination(
CSSSize pageScrollSize;
CSSPoint scrollOffset;
CSSRect scrollRect;
ParentLayerRect compositionBounds;
{
// Grab the lock to access the frame metrics.
@ -2157,6 +2158,7 @@ CSSPoint AsyncPanZoomController::GetKeyboardDestination(
Metrics().GetVisualScrollOffset());
scrollRect = Metrics().GetScrollableRect();
compositionBounds = Metrics().GetCompositionBounds();
}
// Calculate the scroll destination based off of the scroll type and direction
@ -2177,13 +2179,16 @@ CSSPoint AsyncPanZoomController::GetKeyboardDestination(
case KeyboardScrollAction::eScrollLine: {
int32_t scrollDistance =
StaticPrefs::toolkit_scrollbox_verticalScrollDistance();
if (aAction.mForward) {
scrollDestination.y += scrollDistance * lineScrollSize.height;
} else {
scrollDestination.y -= scrollDistance * lineScrollSize.height;
if (scrollDistance * lineScrollSize.height <=
compositionBounds.Height()) {
if (aAction.mForward) {
scrollDestination.y += scrollDistance * lineScrollSize.height;
} else {
scrollDestination.y -= scrollDistance * lineScrollSize.height;
}
break;
}
break;
[[fallthrough]];
}
case KeyboardScrollAction::eScrollPage: {
if (aAction.mForward) {

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

@ -0,0 +1,65 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tests that the arrow down key does not scroll by more than 1 element</title>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="apz_test_utils.js"></script>
<script type="application/javascript" src="apz_test_native_event_utils.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<style>
.time-column {
width: 68px;
height: 28px;
overflow-y: scroll;
scroll-snap-type: y mandatory;
border-radius: 4px;
border: 1px solid red;
}
.time-item {
scroll-snap-align: center;
height: 100%;
}
</style>
</head>
<body>
<div class="time-column"></div>
<script type="application/javascript">
function waitForScrollEvent(target) {
return new Promise(resolve => {
target.addEventListener("scroll", resolve, { once: true });
});
}
async function test() {
const timeCol = document.querySelector('.time-column');
for (let i = 0; i < 60; i++) {
let item = document.createElement('div');
item.classList.add('time-item');
item.textContent = i;
timeCol.appendChild(item);
}
is(timeCol.scrollTop, 0, "should begin with no scroll (1)");
let waitForScroll = waitForScrollEvent(timeCol);
timeCol.focus();
window.synthesizeKey("KEY_ArrowDown");
await waitForScroll;
ok(timeCol.scrollTop > 0, "should have scrolled (2)");
ok(timeCol.scrollTop < 30, "should have not scrolled too far (3)");
}
waitUntilApzStable().then(test).then(subtestDone, subtestFailed);
</script>
</body>
</html>

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

@ -26,6 +26,7 @@ var subtests = [
{"file": "helper_key_scroll.html", prefs: [["apz.test.logging_enabled", true],
["test.events.async.enabled", true]]},
{"file": "helper_bug1674935.html", prefs: []},
{"file": "helper_bug1719330.html", prefs: [["general.smoothScroll", false]]},
{"file": "helper_relative_scroll_smoothness.html?input-type=key&scroll-method=scrollBy",
prefs: smoothness_prefs },
{"file": "helper_relative_scroll_smoothness.html?input-type=native-key&scroll-method=scrollBy",

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

@ -2432,7 +2432,12 @@ PresShell::ScrollLine(bool aForward) {
GetScrollableFrameToScroll(VerticalScrollDirection);
ScrollMode scrollMode = apz::GetScrollModeForOrigin(ScrollOrigin::Lines);
if (scrollFrame) {
nsRect scrollPort = scrollFrame->GetScrollPortRect();
nsSize lineSize = scrollFrame->GetLineScrollAmount();
int32_t lineCount = StaticPrefs::toolkit_scrollbox_verticalScrollDistance();
if (lineCount * lineSize.height > scrollPort.Height()) {
return ScrollPage(aForward);
}
scrollFrame->ScrollBy(
nsIntPoint(0, aForward ? lineCount : -lineCount), ScrollUnit::LINES,
scrollMode, nullptr, mozilla::ScrollOrigin::NotSpecified,