Make mouse forward option of setIgnoreMouseMessages and update documentation.

This commit is contained in:
Andreas Flöjt 2017-08-14 20:21:00 +02:00
parent 60c0bf1636
commit 3d33da7696
7 changed files with 28 additions and 31 deletions

View file

@ -651,8 +651,11 @@ bool Window::IsDocumentEdited() {
return window_->IsDocumentEdited(); return window_->IsDocumentEdited();
} }
void Window::SetIgnoreMouseEvents(bool ignore) { void Window::SetIgnoreMouseEvents(bool ignore, mate::Arguments* args) {
return window_->SetIgnoreMouseEvents(ignore); mate::Dictionary options;
bool forward = false;
args->GetNext(&options) && options.Get("forward", &forward);
return window_->SetIgnoreMouseEvents(ignore, forward);
} }
void Window::SetContentProtection(bool enable) { void Window::SetContentProtection(bool enable) {
@ -787,10 +790,6 @@ void Window::SetAppDetails(const mate::Dictionary& options) {
relaunch_command, relaunch_display_name, relaunch_command, relaunch_display_name,
window_->GetAcceleratedWidget()); window_->GetAcceleratedWidget());
} }
void Window::SetForwardMouseMessages(bool forward) {
window_->SetForwardMouseMessages(forward);
}
#endif #endif
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
@ -1064,7 +1063,6 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setThumbnailClip", &Window::SetThumbnailClip) .SetMethod("setThumbnailClip", &Window::SetThumbnailClip)
.SetMethod("setThumbnailToolTip", &Window::SetThumbnailToolTip) .SetMethod("setThumbnailToolTip", &Window::SetThumbnailToolTip)
.SetMethod("setAppDetails", &Window::SetAppDetails) .SetMethod("setAppDetails", &Window::SetAppDetails)
.SetMethod("setForwardMouseMessages", &Window::SetForwardMouseMessages)
#endif #endif
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
.SetMethod("setIcon", &Window::SetIcon) .SetMethod("setIcon", &Window::SetIcon)

View file

@ -166,7 +166,7 @@ class Window : public mate::TrackableObject<Window>,
std::string GetRepresentedFilename(); std::string GetRepresentedFilename();
void SetDocumentEdited(bool edited); void SetDocumentEdited(bool edited);
bool IsDocumentEdited(); bool IsDocumentEdited();
void SetIgnoreMouseEvents(bool ignore); void SetIgnoreMouseEvents(bool ignore, mate::Arguments* args);
void SetContentProtection(bool enable); void SetContentProtection(bool enable);
void SetFocusable(bool focusable); void SetFocusable(bool focusable);
void SetProgressBar(double progress, mate::Arguments* args); void SetProgressBar(double progress, mate::Arguments* args);
@ -201,7 +201,6 @@ class Window : public mate::TrackableObject<Window>,
bool SetThumbnailClip(const gfx::Rect& region); bool SetThumbnailClip(const gfx::Rect& region);
bool SetThumbnailToolTip(const std::string& tooltip); bool SetThumbnailToolTip(const std::string& tooltip);
void SetAppDetails(const mate::Dictionary& options); void SetAppDetails(const mate::Dictionary& options);
void SetForwardMouseMessages(bool forward);
#endif #endif
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)

View file

@ -143,7 +143,7 @@ class NativeWindow : public base::SupportsUserData,
virtual std::string GetRepresentedFilename(); virtual std::string GetRepresentedFilename();
virtual void SetDocumentEdited(bool edited); virtual void SetDocumentEdited(bool edited);
virtual bool IsDocumentEdited(); 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 SetContentProtection(bool enable) = 0;
virtual void SetFocusable(bool focusable); virtual void SetFocusable(bool focusable);
virtual void SetMenu(AtomMenuModel* menu); virtual void SetMenu(AtomMenuModel* menu);
@ -152,9 +152,6 @@ class NativeWindow : public base::SupportsUserData,
virtual gfx::NativeView GetNativeView() const = 0; virtual gfx::NativeView GetNativeView() const = 0;
virtual gfx::NativeWindow GetNativeWindow() const = 0; virtual gfx::NativeWindow GetNativeWindow() const = 0;
virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0; virtual gfx::AcceleratedWidget GetAcceleratedWidget() const = 0;
#if defined(OS_WIN)
virtual void SetForwardMouseMessages(bool forward) = 0;
#endif
// Taskbar/Dock APIs. // Taskbar/Dock APIs.
enum ProgressState { enum ProgressState {

View file

@ -790,7 +790,7 @@ bool NativeWindowViews::HasShadow() {
!= wm::ShadowElevation::NONE; != wm::ShadowElevation::NONE;
} }
void NativeWindowViews::SetIgnoreMouseEvents(bool ignore) { void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) {
#if defined(OS_WIN) #if defined(OS_WIN)
LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE); LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
if (ignore) if (ignore)
@ -798,6 +798,13 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore) {
else else
ex_style &= ~(WS_EX_TRANSPARENT | WS_EX_LAYERED); ex_style &= ~(WS_EX_TRANSPARENT | WS_EX_LAYERED);
::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style); ::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) #elif defined(USE_X11)
if (ignore) { if (ignore) {
XRectangle r = {0, 0, 1, 1}; XRectangle r = {0, 0, 1, 1};

View file

@ -7,7 +7,7 @@
#include "atom/browser/native_window.h" #include "atom/browser/native_window.h"
#include <map> #include <set>
#include <string> #include <string>
#include <vector> #include <vector>
@ -102,7 +102,7 @@ class NativeWindowViews : public NativeWindow,
void SetBackgroundColor(const std::string& color_name) override; void SetBackgroundColor(const std::string& color_name) override;
void SetHasShadow(bool has_shadow) override; void SetHasShadow(bool has_shadow) override;
bool HasShadow() override; bool HasShadow() override;
void SetIgnoreMouseEvents(bool ignore) override; void SetIgnoreMouseEvents(bool ignore, bool forward) override;
void SetContentProtection(bool enable) override; void SetContentProtection(bool enable) override;
void SetFocusable(bool focusable) override; void SetFocusable(bool focusable) override;
void SetMenu(AtomMenuModel* menu_model) override; void SetMenu(AtomMenuModel* menu_model) override;
@ -134,7 +134,6 @@ class NativeWindowViews : public NativeWindow,
#if defined(OS_WIN) #if defined(OS_WIN)
TaskbarHost& taskbar_host() { return taskbar_host_; } TaskbarHost& taskbar_host() { return taskbar_host_; }
void SetForwardMouseMessages(bool forward) override;
#endif #endif
private: private:
@ -171,6 +170,7 @@ class NativeWindowViews : public NativeWindow,
bool PreHandleMSG( bool PreHandleMSG(
UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) override; UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) override;
void HandleSizeEvent(WPARAM w_param, LPARAM l_param); void HandleSizeEvent(WPARAM w_param, LPARAM l_param);
void SetForwardMouseMessages(bool forward);
static LRESULT CALLBACK SubclassProc( static LRESULT CALLBACK SubclassProc(
HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param, UINT_PTR subclass_id, HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param, UINT_PTR subclass_id,
DWORD_PTR ref_data); DWORD_PTR ref_data);

View file

@ -221,10 +221,8 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
} }
void NativeWindowViews::SetForwardMouseMessages(bool forward) { void NativeWindowViews::SetForwardMouseMessages(bool forward) {
forwarding_mouse_messages_ = forward; if (forward && !forwarding_mouse_messages_) {
SetIgnoreMouseEvents(forward); forwarding_mouse_messages_ = true;
if (forward) {
forwarding_windows_.insert(this); forwarding_windows_.insert(this);
// Subclassing is used to fix some issues when forwarding mouse messages; // Subclassing is used to fix some issues when forwarding mouse messages;
@ -235,7 +233,8 @@ void NativeWindowViews::SetForwardMouseMessages(bool forward) {
if (!mouse_hook_) { if (!mouse_hook_) {
mouse_hook_ = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0); mouse_hook_ = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0);
} }
} else { } else if (!forward && forwarding_mouse_messages_) {
forwarding_mouse_messages_ = false;
forwarding_windows_.erase(this); forwarding_windows_.erase(this);
RemoveWindowSubclass(legacy_window_, SubclassProc, 1); RemoveWindowSubclass(legacy_window_, SubclassProc, 1);

View file

@ -1283,9 +1283,14 @@ Returns `Boolean` - Whether the window is visible on all workspaces.
**Note:** This API always returns false on Windows. **Note:** This API always returns false on Windows.
#### `win.setIgnoreMouseEvents(ignore)` #### `win.setIgnoreMouseEvents(ignore[, options])`
* `ignore` Boolean * `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. 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 **Note:** The BrowserView API is currently experimental and may change or be
removed in future Electron releases. 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 [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 [page-visibility-api]: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
[quick-look]: https://en.wikipedia.org/wiki/Quick_Look [quick-look]: https://en.wikipedia.org/wiki/Quick_Look