diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 09d88edb9b7b..ef38490d8f7b 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -227,6 +227,14 @@ void Window::OnWindowLeaveFullScreen() { Emit("leave-full-screen"); } +void Window::OnWindowScrollTouchUp() { + Emit("scroll-touch-up"); +} + +void Window::OnWindowScrollTouchDown() { + Emit("scroll-touch-down"); +} + void Window::OnWindowEnterHtmlFullScreen() { Emit("enter-html-full-screen"); } diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index d8e25965d898..12eec04680f5 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -65,6 +65,8 @@ class Window : public mate::TrackableObject, void OnWindowResize() override; void OnWindowMove() override; void OnWindowMoved() override; + void OnWindowScrollTouchUp() override; + void OnWindowScrollTouchDown() override; void OnWindowEnterFullScreen() override; void OnWindowLeaveFullScreen() override; void OnWindowEnterHtmlFullScreen() override; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 4df4b4916963..89354381bead 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -442,6 +442,16 @@ void NativeWindow::NotifyWindowEnterFullScreen() { OnWindowEnterFullScreen()); } +void NativeWindow::NotifyWindowScrollTouchUp() { + FOR_EACH_OBSERVER(NativeWindowObserver, observers_, + OnWindowScrollTouchUp()); +} + +void NativeWindow::NotifyWindowScrollTouchDown() { + FOR_EACH_OBSERVER(NativeWindowObserver, observers_, + OnWindowScrollTouchDown()); +} + void NativeWindow::NotifyWindowLeaveFullScreen() { FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowLeaveFullScreen()); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 0ccf3dfbc2ec..f1dac26650c7 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -205,6 +205,8 @@ class NativeWindow : public base::SupportsUserData, void NotifyWindowMove(); void NotifyWindowResize(); void NotifyWindowMoved(); + void NotifyWindowScrollTouchUp(); + void NotifyWindowScrollTouchDown(); void NotifyWindowEnterFullScreen(); void NotifyWindowLeaveFullScreen(); void NotifyWindowEnterHtmlFullScreen(); diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index f128f3b2cb71..198a78e3f594 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -490,6 +490,25 @@ NativeWindowMac::NativeWindowMac( NSView* view = inspectable_web_contents()->GetView()->GetNativeView(); [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + BOOL __block down = NO; + [NSEvent addLocalMonitorForEventsMatchingMask:NSScrollWheelMask handler:^NSEvent * _Nullable(NSEvent * event) { + if (![window_ isKeyWindow]) + return event; + + if (!web_contents) + return event; + + if (!down && (([event phase] == NSEventPhaseMayBegin) || ([event phase] == NSEventPhaseBegan))) { + this->NotifyWindowScrollTouchDown(); + down = YES; + } + if (down && (([event phase] == NSEventPhaseEnded) || ([event phase] == NSEventPhaseCancelled))) { + this->NotifyWindowScrollTouchUp(); + down = NO; + } + return event; + }]; + InstallView(); } diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index ce2d41c6fad6..b7ba9d756f11 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -50,6 +50,8 @@ class NativeWindowObserver { virtual void OnWindowResize() {} virtual void OnWindowMove() {} virtual void OnWindowMoved() {} + virtual void OnWindowScrollTouchUp() {} + virtual void OnWindowScrollTouchDown() {} virtual void OnWindowEnterFullScreen() {} virtual void OnWindowLeaveFullScreen() {} virtual void OnWindowEnterHtmlFullScreen() {}