Skip to content

Commit

Permalink
Bug 1831580 - Post a Transform notification for instant scrolls. r=hiro
Browse files Browse the repository at this point in the history
Keyboard scrolls and any other non-script driven instant scrolls handled
by APZ, should post TransformBegin and TransformEnd notifications.

Depends on D187051

Differential Revision: https://phabricator.services.mozilla.com/D188519
  • Loading branch information
dlrobertson committed Oct 16, 2023
1 parent 58fa315 commit 3811da4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
23 changes: 23 additions & 0 deletions gfx/layers/apz/src/AsyncPanZoomController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5532,6 +5532,7 @@ void AsyncPanZoomController::NotifyLayersUpdated(
}
}

bool instantScrollMayTriggerTransform = false;
bool scrollOffsetUpdated = false;
bool smoothScrollRequested = false;
bool didCancelAnimation = false;
Expand Down Expand Up @@ -5609,6 +5610,11 @@ void AsyncPanZoomController::NotifyLayersUpdated(
MOZ_ASSERT(scrollUpdate.GetMode() == ScrollMode::Instant ||
scrollUpdate.GetMode() == ScrollMode::Normal);

instantScrollMayTriggerTransform =
scrollUpdate.GetMode() == ScrollMode::Instant &&
scrollUpdate.GetScrollTriggeredByScript() ==
ScrollTriggeredByScript::No;

// If the layout update is of a higher priority than the visual update, then
// we don't want to apply the visual update.
// If the layout update is of a clobbering type (or a smooth scroll request,
Expand Down Expand Up @@ -5741,6 +5747,15 @@ void AsyncPanZoomController::NotifyLayersUpdated(
// Since the main-thread scroll offset changed we should trigger a
// recomposite to make sure it becomes user-visible.
ScheduleComposite();

// If the scroll offset was updated, we're not in a transforming state,
// and we are scrolling by a non-zero delta, we should ensure
// TransformBegin and TransformEnd notifications are sent.
if (!IsTransformingState(mState) && instantScrollMayTriggerTransform &&
cumulativeRelativeDelta && *cumulativeRelativeDelta != CSSPoint() &&
!didCancelAnimation) {
SendTransformBeginAndEnd();
}
}

// If our scroll range changed (for example, because the page dynamically
Expand Down Expand Up @@ -6264,6 +6279,14 @@ void AsyncPanZoomController::DispatchStateChangeNotification(
}
}
}
void AsyncPanZoomController::SendTransformBeginAndEnd() {
RefPtr<GeckoContentController> controller = GetGeckoContentController();
if (controller) {
controller->NotifyAPZStateChange(GetGuid(),
APZStateChange::eTransformBegin);
controller->NotifyAPZStateChange(GetGuid(), APZStateChange::eTransformEnd);
}
}

bool AsyncPanZoomController::IsInTransformingState() const {
RecursiveMutexAutoLock lock(mRecursiveMutex);
Expand Down
7 changes: 7 additions & 0 deletions gfx/layers/apz/src/AsyncPanZoomController.h
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,13 @@ class AsyncPanZoomController {
*/
void DispatchStateChangeNotification(PanZoomState aOldState,
PanZoomState aNewState);

/**
* Send a TransformBegin notification followed by a TransformEnd
* notification.
*/
void SendTransformBeginAndEnd();

/**
* Internal helpers for checking general state of this apzc.
*/
Expand Down
5 changes: 2 additions & 3 deletions gfx/layers/apz/test/mochitest/test_group_scrollend.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@
"prefs": smoothScrollEnabled},
{"file": "helper_keyboard_scrollend.html?direction=down&flush-before-key",
"prefs": smoothScrollDisabled},
// FIXME(dlrobertson): When bug 1831580 is fixed, add additional tests
// for scrollend events following keyboard scrolls that do change the
// scroll position without being handled by a APZC on-keyboard scroll.
{"file": "helper_keyboard_scrollend.html?direction=down",
"prefs": smoothScrollDisabled},
];

if (isApzEnabled()) {
Expand Down

0 comments on commit 3811da4

Please sign in to comment.