Bug 1762874. Make sure to draw swipe to nav ui element opaque if velocity pushes us over success threshold. r=hiro

Both the velocity and displacement contribute to the success but we only pass the displacement in the swipe events which browser-gestureSupport.js uses to draw the opacity of the ui element. Usually that is what we want, but if the velocity is large we might draw the ui element only very faintly but still navigate the page. We should make sure to draw the ui element so it's well visible.

Differential Revision: https://phabricator.services.mozilla.com/D142819
This commit is contained in:
Timothy Nikkel 2022-05-26 02:29:10 +00:00
Родитель 2d5de179cb
Коммит 5cb82a0f2a
2 изменённых файлов: 34 добавлений и 10 удалений

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

@ -55,7 +55,7 @@ SwipeTracker::SwipeTracker(nsIWidget& aWidget,
mEventsHaveStartedNewGesture(false),
mRegisteredWithRefreshDriver(false) {
SendSwipeEvent(eSwipeGestureStart, 0, 0.0, aSwipeStartEvent.mTimeStamp);
ProcessEvent(aSwipeStartEvent);
ProcessEvent(aSwipeStartEvent, /* aProcessingFirstEvent = */ true);
}
void SwipeTracker::Destroy() { UnregisterFromRefreshDriver(); }
@ -101,7 +101,8 @@ bool SwipeTracker::ComputeSwipeSuccess() const {
kSwipeSuccessThreshold;
}
nsEventStatus SwipeTracker::ProcessEvent(const PanGestureInput& aEvent) {
nsEventStatus SwipeTracker::ProcessEvent(
const PanGestureInput& aEvent, bool aProcessingFirstEvent /* = false */) {
// If the fingers have already been lifted or the swipe direction is where
// navigation is impossible, don't process this event for swiping.
if (!mEventsAreControllingSwipe || !SwipingInAllowedDirection()) {
@ -119,16 +120,38 @@ nsEventStatus SwipeTracker::ProcessEvent(const PanGestureInput& aEvent) {
mWidget.GetDefaultScaleInternal() /
StaticPrefs::widget_swipe_whole_page_pixel_size();
mGestureAmount = ClampToAllowedRange(mGestureAmount + delta);
SendSwipeEvent(eSwipeGestureUpdate, 0, mGestureAmount, aEvent.mTimeStamp);
if (aEvent.mType != PanGestureInput::PANGESTURE_END) {
double elapsedSeconds =
std::max(0.008, (aEvent.mTimeStamp - mLastEventTimeStamp).ToSeconds());
mCurrentVelocity = delta / elapsedSeconds;
if (!aProcessingFirstEvent) {
double elapsedSeconds = std::max(
0.008, (aEvent.mTimeStamp - mLastEventTimeStamp).ToSeconds());
mCurrentVelocity = delta / elapsedSeconds;
}
mLastEventTimeStamp = aEvent.mTimeStamp;
} else {
}
const bool computedSwipeSuccess = ComputeSwipeSuccess();
// The velocity component might push us over the success threshold, in which
// case we want to pass the success threshold in the event we send so that the
// UI draws as 100% opacity to indicate such. We don't want to include the
// velocity in the amount we put on the event if we aren't over the success
// threshold because that would lead to the opacity decreasing even if the
// user continues to increase the swipe distance. If we do compute swipe
// success here and the user does not lift their fingers and then decreases
// the total swipe so that we go below the success threshold the opacity would
// also decrease in that case but that seems okay.
double eventAmount = mGestureAmount;
if (computedSwipeSuccess) {
eventAmount = kSwipeSuccessThreshold;
if (mGestureAmount < 0.f) {
eventAmount = -eventAmount;
}
}
SendSwipeEvent(eSwipeGestureUpdate, 0, eventAmount, aEvent.mTimeStamp);
if (aEvent.mType == PanGestureInput::PANGESTURE_END) {
mEventsAreControllingSwipe = false;
if (ComputeSwipeSuccess()) {
if (computedSwipeSuccess) {
// Let's use same timestamp as previous event because this is caused by
// the preceding event.
SendSwipeEvent(eSwipeGesture, mSwipeDirection, 0.0, aEvent.mTimeStamp);

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

@ -54,7 +54,8 @@ class SwipeTracker final : public nsARefreshObserver {
void Destroy();
nsEventStatus ProcessEvent(const PanGestureInput& aEvent);
nsEventStatus ProcessEvent(const PanGestureInput& aEvent,
bool aProcessingFirstEvent = false);
void CancelSwipe(const TimeStamp& aTimeStamp);
static WidgetSimpleGestureEvent CreateSwipeGestureEvent(