Merge pull request #6013 from miniak/setIgnoreFocus

Add BrowserWindow.prototype.setIgnoreFocus
This commit is contained in:
Cheng Zhao 2016-06-13 07:18:10 +00:00 committed by GitHub
commit ce00f4a273
8 changed files with 32 additions and 0 deletions

View file

@ -529,6 +529,10 @@ void Window::SetIgnoreMouseEvents(bool ignore) {
return window_->SetIgnoreMouseEvents(ignore);
}
void Window::SetIgnoreFocus(bool ignore) {
return window_->SetIgnoreFocus(ignore);
}
void Window::CapturePage(mate::Arguments* args) {
gfx::Rect rect;
base::Callback<void(const gfx::Image&)> callback;
@ -732,6 +736,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
.SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
.SetMethod("setIgnoreMouseEvents", &Window::SetIgnoreMouseEvents)
.SetMethod("setIgnoreFocus", &Window::SetIgnoreFocus)
.SetMethod("focusOnWebView", &Window::FocusOnWebView)
.SetMethod("blurWebView", &Window::BlurWebView)
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)

View file

@ -146,6 +146,7 @@ class Window : public mate::TrackableObject<Window>,
void SetDocumentEdited(bool edited);
bool IsDocumentEdited();
void SetIgnoreMouseEvents(bool ignore);
void SetIgnoreFocus(bool ignore);
void CapturePage(mate::Arguments* args);
void SetProgressBar(double progress);
void SetOverlayIcon(const gfx::Image& overlay,

View file

@ -155,6 +155,7 @@ class NativeWindow : public base::SupportsUserData,
virtual void SetDocumentEdited(bool edited);
virtual bool IsDocumentEdited();
virtual void SetIgnoreMouseEvents(bool ignore) = 0;
virtual void SetIgnoreFocus(bool ignore) = 0;
virtual void SetMenu(ui::MenuModel* menu);
virtual bool HasModalDialog();
virtual gfx::NativeWindow GetNativeWindow() = 0;

View file

@ -77,6 +77,7 @@ class NativeWindowMac : public NativeWindow {
void SetDocumentEdited(bool edited) override;
bool IsDocumentEdited() override;
void SetIgnoreMouseEvents(bool ignore) override;
void SetIgnoreFocus(bool ignore) override;
bool HasModalDialog() override;
gfx::NativeWindow GetNativeWindow() override;
gfx::AcceleratedWidget GetAcceleratedWidget() override;

View file

@ -883,6 +883,10 @@ void NativeWindowMac::SetIgnoreMouseEvents(bool ignore) {
[window_ setIgnoresMouseEvents:ignore];
}
void NativeWindowMac::SetIgnoreFocus(bool ignore) {
[window_ setDisableKeyOrMainWindow:ignore];
}
bool NativeWindowMac::HasModalDialog() {
return [window_ attachedSheet] != nil;
}

View file

@ -692,6 +692,17 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore) {
#endif
}
void NativeWindowViews::SetIgnoreFocus(bool ignore) {
#if defined(OS_WIN)
LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
if (ignore)
ex_style |= WS_EX_NOACTIVATE;
else
ex_style &= ~WS_EX_NOACTIVATE;
::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style);
#endif
}
void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
if (menu_model == nullptr) {
// Remove accelerators

View file

@ -92,6 +92,7 @@ class NativeWindowViews : public NativeWindow,
void SetHasShadow(bool has_shadow) override;
bool HasShadow() override;
void SetIgnoreMouseEvents(bool ignore) override;
void SetIgnoreFocus(bool ignore) override;
void SetMenu(ui::MenuModel* menu_model) override;
gfx::NativeWindow GetNativeWindow() override;
void SetOverlayIcon(const gfx::Image& overlay,

View file

@ -953,4 +953,12 @@ All mouse events happened in this window will be passed to the window below
this window, but if this window has focus, it will still receive keyboard
events.
### `win.setIgnoreFocus(ignore)` _OS X_ _Windows_
* `ignore` Boolean
Makes the window ignore focus.
On OS X this prevents the window from becoming key and main window.
[blink-feature-string]: https://cs.chromium.org/chromium/src/third_party/WebKit/Source/platform/RuntimeEnabledFeatures.in