UI/AppKit: Normalize pinch magnification updates

NSMagnificationGestureRecognizer exposes magnification as an accumulated
value for the current gesture. Ladybird kept its own previous value in
WebViewBridge and emitted the residual delta when the gesture ended, so
the Web input pipeline did not receive the same per-update shape as the
native changed events.

Reset the recognizer's magnification accumulator after changed updates
and skip begin/end states. This keeps the AppKit side responsible for
delivering concrete scale changes and removes the bridge pinch state.
This commit is contained in:
Aliaksandr Kalenik 2026-05-27 04:02:56 +02:00 committed by Jelle Raaijmakers
parent 3713f3baf2
commit baecb14472
2 changed files with 7 additions and 15 deletions

View file

@ -1376,24 +1376,23 @@ struct HideCursor {
- (void)onPinch:(NSMagnificationGestureRecognizer*)recognizer
{
double scale_delta = 0;
switch (recognizer.state) {
case NSGestureRecognizerStateBegan:
m_web_view_bridge->pinch_state() = { .previous_scale = recognizer.magnification };
break;
recognizer.magnification = 0;
return;
case NSGestureRecognizerStateChanged:
scale_delta = recognizer.magnification - m_web_view_bridge->pinch_state()->previous_scale;
m_web_view_bridge->pinch_state()->previous_scale = recognizer.magnification;
break;
case NSGestureRecognizerStateEnded:
case NSGestureRecognizerStateCancelled:
scale_delta = recognizer.magnification - m_web_view_bridge->pinch_state()->previous_scale;
m_web_view_bridge->pinch_state() = {};
break;
recognizer.magnification = 0;
return;
default:
return;
}
auto scale_delta = recognizer.magnification;
recognizer.magnification = 0;
NSPoint point = [recognizer locationInView:self];
Web::PinchEvent pinch_event;
pinch_event.position = Ladybird::ns_point_to_gfx_point(point).to_type<Web::DevicePixels>() * m_web_view_bridge->device_pixel_ratio();

View file

@ -48,8 +48,6 @@ public:
Function<void()> on_zoom_level_changed;
auto& pinch_state() { return m_pinch_state; }
private:
WebViewBridge(Vector<Web::DevicePixelRect> screen_rects, double device_pixel_ratio, u64 maximum_frames_per_second);
@ -60,11 +58,6 @@ private:
Vector<Web::DevicePixelRect> m_screen_rects;
Gfx::IntSize m_viewport_size;
struct PinchState {
double previous_scale { 1.0 };
};
Optional<PinchState> m_pinch_state;
};
}