diff --git a/tests/cefclient/cefclient_osr_widget_mac.h b/tests/cefclient/cefclient_osr_widget_mac.h index afaea346e..6e9c0c6a6 100644 --- a/tests/cefclient/cefclient_osr_widget_mac.h +++ b/tests/cefclient/cefclient_osr_widget_mac.h @@ -29,6 +29,9 @@ class OSRBrowserProvider { bool rotating_; bool was_last_mouse_down_on_view_; + + // Event monitor for scroll wheel end event. + id endWheelMonitor_; } - (id)initWithFrame:(NSRect)frame andTransparency:(bool)transparency; diff --git a/tests/cefclient/cefclient_osr_widget_mac.mm b/tests/cefclient/cefclient_osr_widget_mac.mm index 860bc1538..fd9ec6960 100644 --- a/tests/cefclient/cefclient_osr_widget_mac.mm +++ b/tests/cefclient/cefclient_osr_widget_mac.mm @@ -271,6 +271,7 @@ void ClientOSRHandler::SetLoading(bool isLoading) { if (self) { renderer_ = new ClientOSRenderer(transparency); rotating_ = false; + endWheelMonitor_ = nil; tracking_area_ = [[NSTrackingArea alloc] initWithRect:frame @@ -467,7 +468,38 @@ void ClientOSRHandler::SetLoading(bool isLoading) { [self keyDown:event]; } +- (void) shortCircuitScrollWheelEvent:(NSEvent*)event { + if ([event phase] != NSEventPhaseEnded && + [event phase] != NSEventPhaseCancelled) + return; + + [self sendScrollWheelEvet:event]; + + if (endWheelMonitor_) { + [NSEvent removeMonitor:endWheelMonitor_]; + endWheelMonitor_ = nil; + } +} + - (void)scrollWheel:(NSEvent *)event { + // Use an NSEvent monitor to listen for the wheel-end end. This ensures that + // the event is received even when the mouse cursor is no longer over the + // view when the scrolling ends. Also it avoids sending duplicate scroll + // events to the renderer. + if ([event respondsToSelector:@selector(phase)] && + [event phase] == NSEventPhaseBegan && !endWheelMonitor_) { + endWheelMonitor_ = + [NSEvent addLocalMonitorForEventsMatchingMask:NSScrollWheelMask + handler:^(NSEvent* blockEvent) { + [self shortCircuitScrollWheelEvent:blockEvent]; + return blockEvent; + }]; + } + + [self sendScrollWheelEvet:event]; +} + +- (void)sendScrollWheelEvet:(NSEvent *)event { CefRefPtr browser = [self getBrowser]; if (!browser) return;