Mouse forward on macOS (#12281)

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

* Update BrowserWindow docs: mouse forward is available on macOS
This commit is contained in:
Andreas 2018-04-09 12:35:05 +02:00 committed by Cheng Zhao
parent 0e5aaab0b5
commit 6b5e09478c
3 changed files with 17 additions and 5 deletions

View file

@ -89,7 +89,7 @@ class NativeWindowMac : public NativeWindow {
std::string GetRepresentedFilename() override; std::string GetRepresentedFilename() override;
void SetDocumentEdited(bool edited) override; void SetDocumentEdited(bool edited) override;
bool IsDocumentEdited() override; bool IsDocumentEdited() override;
void SetIgnoreMouseEvents(bool ignore, bool) override; void SetIgnoreMouseEvents(bool ignore, bool forward) override;
void SetContentProtection(bool enable) override; void SetContentProtection(bool enable) override;
void SetBrowserView(NativeBrowserView* browser_view) override; void SetBrowserView(NativeBrowserView* browser_view) override;
void SetParentWindow(NativeWindow* parent) override; void SetParentWindow(NativeWindow* parent) override;
@ -143,6 +143,8 @@ class NativeWindowMac : public NativeWindow {
void InstallView(NSView* view); void InstallView(NSView* view);
void SetForwardMouseMessages(bool forward);
base::scoped_nsobject<AtomNSWindow> window_; base::scoped_nsobject<AtomNSWindow> window_;
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_; base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;

View file

@ -1485,8 +1485,14 @@ bool NativeWindowMac::IsDocumentEdited() {
return [window_ isDocumentEdited]; return [window_ isDocumentEdited];
} }
void NativeWindowMac::SetIgnoreMouseEvents(bool ignore, bool) { void NativeWindowMac::SetIgnoreMouseEvents(bool ignore, bool forward) {
[window_ setIgnoresMouseEvents:ignore]; [window_ setIgnoresMouseEvents:ignore];
if (!ignore) {
SetForwardMouseMessages(NO);
} else {
SetForwardMouseMessages(forward);
}
} }
void NativeWindowMac::SetContentProtection(bool enable) { 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) { void NativeWindowMac::SetStyleMask(bool on, NSUInteger flag) {
// Changing the styleMask of a frameless windows causes it to change size so // Changing the styleMask of a frameless windows causes it to change size so
// we explicitly disable resizing while setting it. // we explicitly disable resizing while setting it.

View file

@ -1382,10 +1382,10 @@ Returns `Boolean` - Whether the window is visible on all workspaces.
* `ignore` Boolean * `ignore` Boolean
* `options` Object (optional) * `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`. messages to Chromium, enabling mouse related events such as `mouseleave`.
Only used when `ignore` is true. If `ignore` is false, forwarding is always Only used when `ignore` is true. If `ignore` is false, forwarding is always
disabled regardless of this value. disabled regardless of this value.
Makes the window ignore all mouse events. Makes the window ignore all mouse events.