Merge pull request #717 from atom/show-inactive

Add BrowserWindow.showInactive()
This commit is contained in:
Cheng Zhao 2014-10-18 11:13:55 +08:00
commit 53b83eba8c
9 changed files with 31 additions and 2 deletions

View file

@ -153,6 +153,10 @@ void Window::Show() {
window_->Show();
}
void Window::ShowInactive() {
window_->ShowInactive();
}
void Window::Hide() {
window_->Hide();
}
@ -388,6 +392,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("focus", &Window::Focus)
.SetMethod("isFocused", &Window::IsFocused)
.SetMethod("show", &Window::Show)
.SetMethod("showInactive", &Window::ShowInactive)
.SetMethod("hide", &Window::Hide)
.SetMethod("isVisible", &Window::IsVisible)
.SetMethod("maximize", &Window::Maximize)

View file

@ -59,6 +59,7 @@ class Window : public mate::EventEmitter,
void Focus();
bool IsFocused();
void Show();
void ShowInactive();
void Hide();
bool IsVisible();
void Maximize();

View file

@ -101,6 +101,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
virtual void Focus(bool focus) = 0;
virtual bool IsFocused() = 0;
virtual void Show() = 0;
virtual void ShowInactive() = 0;
virtual void Hide() = 0;
virtual bool IsVisible() = 0;
virtual void Maximize() = 0;

View file

@ -28,6 +28,7 @@ class NativeWindowMac : public NativeWindow {
virtual void Focus(bool focus) OVERRIDE;
virtual bool IsFocused() OVERRIDE;
virtual void Show() OVERRIDE;
virtual void ShowInactive() OVERRIDE;
virtual void Hide() OVERRIDE;
virtual bool IsVisible() OVERRIDE;
virtual void Maximize() OVERRIDE;

View file

@ -334,6 +334,10 @@ bool NativeWindowMac::IsFocused() {
}
void NativeWindowMac::Show() {
[window_ makeKeyAndOrderFront:nil];
}
void NativeWindowMac::ShowInactive() {
[window_ orderFrontRegardless];
}

View file

@ -232,6 +232,10 @@ bool NativeWindowViews::IsFocused() {
}
void NativeWindowViews::Show() {
window_->Show();
}
void NativeWindowViews::ShowInactive() {
window_->ShowInactive();
}

View file

@ -38,6 +38,7 @@ class NativeWindowViews : public NativeWindow,
virtual void Focus(bool focus) OVERRIDE;
virtual bool IsFocused() OVERRIDE;
virtual void Show() OVERRIDE;
virtual void ShowInactive() OVERRIDE;
virtual void Hide() OVERRIDE;
virtual bool IsVisible() OVERRIDE;
virtual void Maximize() OVERRIDE;

View file

@ -232,7 +232,11 @@ Returns whether the window is focused.
### BrowserWindow.show()
Shows the window.
Shows and gives focus to the window.
### BrowserWindow.showInactive()
Shows the window but doesn't focus on it.
### BrowserWindow.hide()

View file

@ -5,6 +5,8 @@ remote = require 'remote'
BrowserWindow = remote.require 'browser-window'
isCI = remote.process.argv[1] == '--ci'
describe 'browser-window module', ->
fixtures = path.resolve __dirname, 'fixtures'
@ -57,8 +59,14 @@ describe 'browser-window module', ->
w.loadUrl 'about:blank'
describe 'BrowserWindow.show()', ->
it 'should not focus window', ->
it 'should focus on window', ->
return if isCI
w.show()
assert w.isFocused()
describe 'BrowserWindow.showInactive()', ->
it 'should not focus on window', ->
w.showInactive()
assert !w.isFocused()
describe 'BrowserWindow.focus()', ->