diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 4d86ec337748..93d03e4c157c 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -126,7 +126,9 @@ class NativeWindowMac : public NativeWindow { base::scoped_nsobject window_; base::scoped_nsobject window_delegate_; - base::scoped_nsobject event_monitor_; + + // Event monitor for scroll wheel event. + id wheel_event_monitor_; // The view that will fill the whole frameless window. base::scoped_nsobject content_view_; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index f69292e06074..7967a1771735 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -499,32 +499,34 @@ NativeWindowMac::NativeWindowMac( NSView* view = inspectable_web_contents()->GetView()->GetNativeView(); [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; - BOOL __block down = NO; - event_monitor_.reset([[NSEvent + // Use an NSEvent monitor to listen for the wheel event. + BOOL __block began = NO; + wheel_event_monitor_ = [NSEvent addLocalMonitorForEventsMatchingMask:NSScrollWheelMask - handler:^NSEvent * _Nullable(NSEvent * event) { + handler:^(NSEvent* event) { if ([[event window] windowNumber] != [window_ windowNumber]) return event; if (!web_contents) return event; - if (!down && (([event phase] == NSEventPhaseMayBegin) || ([event phase] == NSEventPhaseBegan))) { + if (!began && (([event phase] == NSEventPhaseMayBegin) || + ([event phase] == NSEventPhaseBegan))) { this->NotifyWindowScrollTouchBegin(); - down = YES; - } - if (down && (([event phase] == NSEventPhaseEnded) || ([event phase] == NSEventPhaseCancelled))) { + began = YES; + } else if (began && (([event phase] == NSEventPhaseEnded) || + ([event phase] == NSEventPhaseCancelled))) { this->NotifyWindowScrollTouchEnd(); - down = NO; + began = NO; } return event; - }] retain]); + }]; InstallView(); } NativeWindowMac::~NativeWindowMac() { - [NSEvent removeMonitor: event_monitor_.get()]; + [NSEvent removeMonitor:wheel_event_monitor_]; Observe(nullptr); } diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 6b8474662d7c..edda572e9ac6 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -307,6 +307,14 @@ someWindow.on('app-command', function(e, cmd) { }); ``` +### Event: 'scroll-touch-begin' _OS X_ + +Emitted when scroll wheel event phase has begun. + +### Event: 'scroll-touch-end' _OS X_ + +Emitted when scroll wheel event phase has ended. + ## Methods The `BrowserWindow` object has the following methods: