From 6b5e09478c8fa48ad0ce114409b22a35f1f7be75 Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 9 Apr 2018 12:35:05 +0200 Subject: [PATCH] Mouse forward on macOS (#12281) * Accept mouse events according to the forward parameter on macOS. * Update BrowserWindow docs: mouse forward is available on macOS --- atom/browser/native_window_mac.h | 4 +++- atom/browser/native_window_mac.mm | 12 +++++++++++- docs/api/browser-window.md | 6 +++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 8323a6b0c7c7..cb89aa24c13d 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -89,7 +89,7 @@ class NativeWindowMac : public NativeWindow { std::string GetRepresentedFilename() override; void SetDocumentEdited(bool edited) override; bool IsDocumentEdited() override; - void SetIgnoreMouseEvents(bool ignore, bool) override; + void SetIgnoreMouseEvents(bool ignore, bool forward) override; void SetContentProtection(bool enable) override; void SetBrowserView(NativeBrowserView* browser_view) override; void SetParentWindow(NativeWindow* parent) override; @@ -143,6 +143,8 @@ class NativeWindowMac : public NativeWindow { void InstallView(NSView* view); + void SetForwardMouseMessages(bool forward); + base::scoped_nsobject window_; base::scoped_nsobject window_delegate_; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index c513cb6572a4..844bde3e0954 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -1485,8 +1485,14 @@ bool NativeWindowMac::IsDocumentEdited() { return [window_ isDocumentEdited]; } -void NativeWindowMac::SetIgnoreMouseEvents(bool ignore, bool) { +void NativeWindowMac::SetIgnoreMouseEvents(bool ignore, bool forward) { [window_ setIgnoresMouseEvents:ignore]; + + if (!ignore) { + SetForwardMouseMessages(NO); + } else { + SetForwardMouseMessages(forward); + } } void NativeWindowMac::SetContentProtection(bool enable) { @@ -1823,6 +1829,10 @@ void NativeWindowMac::InstallView(NSView* view) { } } +void NativeWindowMac::SetForwardMouseMessages(bool forward) { + [window_ setAcceptsMouseMovedEvents:forward]; +} + void NativeWindowMac::SetStyleMask(bool on, NSUInteger flag) { // Changing the styleMask of a frameless windows causes it to change size so // we explicitly disable resizing while setting it. diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index ae379f5348c7..38d7af939d73 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1382,10 +1382,10 @@ Returns `Boolean` - Whether the window is visible on all workspaces. * `ignore` Boolean * `options` Object (optional) - * `forward` Boolean (optional) _Windows_ - If true, forwards mouse move + * `forward` Boolean (optional) _macOS_ _Windows_ - If true, forwards mouse move messages to Chromium, enabling mouse related events such as `mouseleave`. - Only used when `ignore` is true. If `ignore` is false, forwarding is always - disabled regardless of this value. + Only used when `ignore` is true. If `ignore` is false, forwarding is always + disabled regardless of this value. Makes the window ignore all mouse events.