Skip to content

Commit

Permalink
Improve rubber-banding in QT WebEngine Pages
Browse files Browse the repository at this point in the history
- Improved rubber-banding/elastic scroll behavior.

Fixes: QTBUG-67716
Change-Id: Ida0ca19df12f08b78328cf8d8ee5dbd3e492fb16
Reviewed-by: Michael Brüning <[email protected]>
  • Loading branch information
Anu Aliyas committed May 12, 2023
1 parent 8bfe1c2 commit 2d2e7bd
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/core/web_event_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,22 @@ blink::WebMouseWheelEvent::Phase toBlinkPhase(QWheelEvent *ev)
return blink::WebMouseWheelEvent::kPhaseNone;
}

blink::WebMouseWheelEvent::Phase getMomentumPhase(QWheelEvent *ev)
{
switch (ev->phase()) {
case Qt::ScrollMomentum:
return blink::WebMouseWheelEvent::kPhaseBegan;
case Qt::ScrollEnd:
return blink::WebMouseWheelEvent::kPhaseEnded;
case Qt::NoScrollPhase:
case Qt::ScrollBegin:
case Qt::ScrollUpdate:
return blink::WebMouseWheelEvent::kPhaseNone;
}
Q_UNREACHABLE();
return blink::WebMouseWheelEvent::kPhaseNone;
}

blink::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev)
{
WebMouseWheelEvent webEvent;
Expand All @@ -1578,6 +1594,7 @@ blink::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev)
webEvent.phase = toBlinkPhase(ev);
#if defined(Q_OS_DARWIN)
// PrecisePixel is a macOS term meaning it is a system scroll gesture, see qnsview_mouse.mm
webEvent.momentum_phase = getMomentumPhase(ev);
if (ev->source() == Qt::MouseEventSynthesizedBySystem)
webEvent.delta_units = ui::ScrollGranularity::kScrollByPrecisePixel;
#endif
Expand All @@ -1596,6 +1613,9 @@ bool WebEventFactory::coalesceWebWheelEvent(blink::WebMouseWheelEvent &webEvent,
if (toBlinkPhase(ev) != webEvent.phase)
return false;
#if defined(Q_OS_DARWIN)
if (getMomentumPhase(ev) != webEvent.momentum_phase)
return false;

if ((webEvent.delta_units == ui::ScrollGranularity::kScrollByPrecisePixel)
!= (ev->source() == Qt::MouseEventSynthesizedBySystem))
return false;
Expand Down

0 comments on commit 2d2e7bd

Please sign in to comment.