Finalized browser-window show & hide events, added tests & fixed os x implementation

This commit is contained in:
Arek Sredzki 2016-03-08 11:11:17 -08:00
Родитель c1267b2320
Коммит fcc1f4d7ed
4 изменённых файлов: 73 добавлений и 9 удалений

Просмотреть файл

@ -428,6 +428,14 @@ void NativeWindow::NotifyWindowFocus() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowFocus()); FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowFocus());
} }
void NativeWindow::NotifyWindowShow() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowShow());
}
void NativeWindow::NotifyWindowHide() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowHide());
}
void NativeWindow::NotifyWindowMaximize() { void NativeWindow::NotifyWindowMaximize() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMaximize()); FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMaximize());
} }

Просмотреть файл

@ -79,6 +79,21 @@ bool ScopedDisableResize::disable_resize_ = false;
return self; return self;
} }
- (void)windowDidChangeOcclusionState:(NSNotification *)notification {
// notification.object is the window that changed its state.
// It's safe to use self.window instead if you don't assign one delegate to many windows
NSWindow *window = notification.object;
// check occlusion binary flag
if (window.occlusionState & NSWindowOcclusionStateVisible) {
// The app is visible
shell_->NotifyWindowShow();
} else {
// The app is not visible
shell_->NotifyWindowHide();
}
}
- (void)windowDidBecomeMain:(NSNotification*)notification { - (void)windowDidBecomeMain:(NSNotification*)notification {
content::WebContents* web_contents = shell_->web_contents(); content::WebContents* web_contents = shell_->web_contents();
if (!web_contents) if (!web_contents)

Просмотреть файл

@ -32,7 +32,7 @@ BrowserWindow.prototype._init = function() {
// window.resizeTo(...) // window.resizeTo(...)
// window.moveTo(...) // window.moveTo(...)
this.webContents.on('move', (event, title) => { this.webContents.on('move', (event, size) => {
return this.setBounds(size); return this.setBounds(size);
}); });
@ -80,16 +80,16 @@ BrowserWindow.prototype._init = function() {
// Evented visibilityState changes // Evented visibilityState changes
this.on('show', () => { this.on('show', () => {
return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', true, this.isMinimized()); return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', this.isVisible(), this.isMinimized());
}); });
this.on('hide', () => { this.on('hide', () => {
return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', false, this.isMinimized()); return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', this.isVisible(), this.isMinimized());
}); });
this.on('minimize', () => { this.on('minimize', () => {
return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', this.isVisible(), true); return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', this.isVisible(), this.isMinimized());
}); });
this.on('restore', () => { this.on('restore', () => {
return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', this.isVisible(), false); return this.webContents.send('ATOM_RENDERER_WINDOW_VISIBILITY_CHANGE', this.isVisible(), this.isMinimized());
}); });
// Notify the creation of the window. // Notify the creation of the window.

Просмотреть файл

@ -120,14 +120,55 @@ describe('browser-window module', function() {
}); });
describe('BrowserWindow.show()', function() { describe('BrowserWindow.show()', function() {
it('should focus on window', function() { if (isCI) {
if (isCI) { return;
return; }
}
it('should focus on window', function() {
w.show(); w.show();
assert(w.isFocused()); assert(w.isFocused());
}); });
it('should make the window visible', function() {
w.show();
assert(w.isVisible());
});
it('emits when window is shown', function(done) {
this.timeout(10000);
w.once('show', function() {
assert.equal(w.isVisible(), true);
done();
});
w.show();
});
});
describe('BrowserWindow.hide()', function() {
if (isCI) {
return;
}
it('should defocus on window', function() {
w.hide();
assert(!w.isFocused());
});
it('should make the window not visible', function() {
w.show();
w.hide();
assert(!w.isVisible());
});
it('emits when window is hidden', function(done) {
this.timeout(10000);
w.show();
w.once('hide', function() {
assert.equal(w.isVisible(), false);
done();
});
w.hide();
});
}); });
describe('BrowserWindow.showInactive()', function() { describe('BrowserWindow.showInactive()', function() {