Browse Source

Mouse forward on macOS (#12281)

* Accept mouse events according to the forward parameter on macOS.

* Update BrowserWindow docs: mouse forward is available on macOS
Andreas 7 years ago
parent
commit
6b5e09478c
3 changed files with 17 additions and 5 deletions
  1. 3 1
      atom/browser/native_window_mac.h
  2. 11 1
      atom/browser/native_window_mac.mm
  3. 3 3
      docs/api/browser-window.md

+ 3 - 1
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<AtomNSWindow> window_;
   base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
 

+ 11 - 1
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.

+ 3 - 3
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.