diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 1ea09c269295..ff6e206c47c1 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -651,8 +651,11 @@ bool Window::IsDocumentEdited() { return window_->IsDocumentEdited(); } -void Window::SetIgnoreMouseEvents(bool ignore) { - return window_->SetIgnoreMouseEvents(ignore); +void Window::SetIgnoreMouseEvents(bool ignore, mate::Arguments* args) { + mate::Dictionary options; + bool forward = false; + args->GetNext(&options) && options.Get("forward", &forward); + return window_->SetIgnoreMouseEvents(ignore, forward); } void Window::SetContentProtection(bool enable) { @@ -787,10 +790,6 @@ void Window::SetAppDetails(const mate::Dictionary& options) { relaunch_command, relaunch_display_name, window_->GetAcceleratedWidget()); } - -void Window::SetForwardMouseMessages(bool forward) { - window_->SetForwardMouseMessages(forward); -} #endif #if defined(TOOLKIT_VIEWS) @@ -1064,7 +1063,6 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("setThumbnailClip", &Window::SetThumbnailClip) .SetMethod("setThumbnailToolTip", &Window::SetThumbnailToolTip) .SetMethod("setAppDetails", &Window::SetAppDetails) - .SetMethod("setForwardMouseMessages", &Window::SetForwardMouseMessages) #endif #if defined(TOOLKIT_VIEWS) .SetMethod("setIcon", &Window::SetIcon) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index c47cb196941c..3dac635d36a2 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -166,7 +166,7 @@ class Window : public mate::TrackableObject, std::string GetRepresentedFilename(); void SetDocumentEdited(bool edited); bool IsDocumentEdited(); - void SetIgnoreMouseEvents(bool ignore); + void SetIgnoreMouseEvents(bool ignore, mate::Arguments* args); void SetContentProtection(bool enable); void SetFocusable(bool focusable); void SetProgressBar(double progress, mate::Arguments* args); @@ -201,7 +201,6 @@ class Window : public mate::TrackableObject, bool SetThumbnailClip(const gfx::Rect& region); bool SetThumbnailToolTip(const std::string& tooltip); void SetAppDetails(const mate::Dictionary& options); - void SetForwardMouseMessages(bool forward); #endif #if defined(TOOLKIT_VIEWS) diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index f8df7ac62e13..84d367141102 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -143,7 +143,7 @@ class NativeWindow : public base::SupportsUserData, virtual std::string GetRepresentedFilename(); virtual void SetDocumentEdited(bool edited); virtual bool IsDocumentEdited(); - virtual void SetIgnoreMouseEvents(bool ignore) = 0; + virtual void SetIgnoreMouseEvents(bool ignore, bool forward) = 0; virtual void SetContentProtection(bool enable) = 0; virtual void SetFocusable(bool focusable); virtual void SetMenu(AtomMenuModel* menu); @@ -152,9 +152,6 @@ class NativeWindow : public base::SupportsUserData, virtual gfx::NativeView GetNativeView() const = 0; virtual gfx::NativeWindow GetNativeWindow() const = 0; virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0; -#if defined(OS_WIN) - virtual void SetForwardMouseMessages(bool forward) = 0; -#endif // Taskbar/Dock APIs. enum ProgressState { diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 94e2f09c964a..0dfb25e5a47c 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -790,7 +790,7 @@ bool NativeWindowViews::HasShadow() { != wm::ShadowElevation::NONE; } -void NativeWindowViews::SetIgnoreMouseEvents(bool ignore) { +void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) { #if defined(OS_WIN) LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE); if (ignore) @@ -798,6 +798,13 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore) { else ex_style &= ~(WS_EX_TRANSPARENT | WS_EX_LAYERED); ::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style); + + // Forwarding is always disabled when not ignoring mouse messages. + if (!ignore) { + SetForwardMouseMessages(false); + } else { + SetForwardMouseMessages(forward); + } #elif defined(USE_X11) if (ignore) { XRectangle r = {0, 0, 1, 1}; diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index fa2de5e1f1ed..fe493918117d 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -7,7 +7,7 @@ #include "atom/browser/native_window.h" -#include +#include #include #include @@ -102,7 +102,7 @@ class NativeWindowViews : public NativeWindow, void SetBackgroundColor(const std::string& color_name) override; void SetHasShadow(bool has_shadow) override; bool HasShadow() override; - void SetIgnoreMouseEvents(bool ignore) override; + void SetIgnoreMouseEvents(bool ignore, bool forward) override; void SetContentProtection(bool enable) override; void SetFocusable(bool focusable) override; void SetMenu(AtomMenuModel* menu_model) override; @@ -134,7 +134,6 @@ class NativeWindowViews : public NativeWindow, #if defined(OS_WIN) TaskbarHost& taskbar_host() { return taskbar_host_; } - void SetForwardMouseMessages(bool forward) override; #endif private: @@ -171,6 +170,7 @@ class NativeWindowViews : public NativeWindow, bool PreHandleMSG( UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) override; void HandleSizeEvent(WPARAM w_param, LPARAM l_param); + void SetForwardMouseMessages(bool forward); static LRESULT CALLBACK SubclassProc( HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param, UINT_PTR subclass_id, DWORD_PTR ref_data); diff --git a/atom/browser/native_window_views_win.cc b/atom/browser/native_window_views_win.cc index a9211c1232c4..8973ccb92434 100644 --- a/atom/browser/native_window_views_win.cc +++ b/atom/browser/native_window_views_win.cc @@ -221,10 +221,8 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) { } void NativeWindowViews::SetForwardMouseMessages(bool forward) { - forwarding_mouse_messages_ = forward; - SetIgnoreMouseEvents(forward); - - if (forward) { + if (forward && !forwarding_mouse_messages_) { + forwarding_mouse_messages_ = true; forwarding_windows_.insert(this); // Subclassing is used to fix some issues when forwarding mouse messages; @@ -235,7 +233,8 @@ void NativeWindowViews::SetForwardMouseMessages(bool forward) { if (!mouse_hook_) { mouse_hook_ = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0); } - } else { + } else if (!forward && forwarding_mouse_messages_) { + forwarding_mouse_messages_ = false; forwarding_windows_.erase(this); RemoveWindowSubclass(legacy_window_, SubclassProc, 1); diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 7cdd6407791c..2ff8c7dfe731 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1283,9 +1283,14 @@ Returns `Boolean` - Whether the window is visible on all workspaces. **Note:** This API always returns false on Windows. -#### `win.setIgnoreMouseEvents(ignore)` +#### `win.setIgnoreMouseEvents(ignore[, options])` * `ignore` Boolean +* `options` Object (optional) + * `forward` Boolean (optional) _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. Makes the window ignore all mouse events. @@ -1356,14 +1361,6 @@ removed in future Electron releases. **Note:** The BrowserView API is currently experimental and may change or be removed in future Electron releases. -#### `win.setForwardMouseMessages(forward)` _Windows_ - -* `forward` Boolean - -Forward mouse messages to the window below this one. This is similar to -`setIgnoreMouseEvents`, but additionally allows users to listen to events -related to mouse movement such as `mouseleave`. - [blink-feature-string]: https://cs.chromium.org/chromium/src/third_party/WebKit/Source/platform/RuntimeEnabledFeatures.json5?l=62 [page-visibility-api]: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API [quick-look]: https://en.wikipedia.org/wiki/Quick_Look