Merge pull request #343 from gmr/master

Add a `focus` event to BrowserWindow
This commit is contained in:
Cheng Zhao 2014-05-23 22:49:59 +08:00
commit fc1bc78fb9
9 changed files with 27 additions and 0 deletions

View file

@ -95,6 +95,10 @@ void Window::OnWindowBlur() {
Emit("blur");
}
void Window::OnWindowFocus() {
Emit("focus");
}
void Window::OnRendererUnresponsive() {
Emit("unresponsive");
}

View file

@ -53,6 +53,7 @@ class Window : public mate::EventEmitter,
virtual void WillCloseWindow(bool* prevent_default) OVERRIDE;
virtual void OnWindowClosed() OVERRIDE;
virtual void OnWindowBlur() OVERRIDE;
virtual void OnWindowFocus() OVERRIDE;
virtual void OnRendererUnresponsive() OVERRIDE;
virtual void OnRendererResponsive() OVERRIDE;

View file

@ -368,6 +368,10 @@ void NativeWindow::NotifyWindowBlur() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowBlur());
}
void NativeWindow::NotifyWindowFocus() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowFocus());
}
// In atom-shell all reloads and navigations started by renderer process would
// be redirected to this method, so we can have precise control of how we
// would open the url (in our case, is to restart the renderer process). See

View file

@ -177,6 +177,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
// related notifications.
void NotifyWindowClosed();
void NotifyWindowBlur();
void NotifyWindowFocus();
void AddObserver(NativeWindowObserver* obs) {
observers_.AddObserver(obs);

View file

@ -492,6 +492,11 @@ gboolean NativeWindowGtk::OnWindowDeleteEvent(GtkWidget* widget,
return TRUE;
}
gboolean NativeWindowGtk::OnFocusIn(GtkWidget* window, GdkEventFocus*) {
NotifyWindowFocus();
return FALSE;
}
gboolean NativeWindowGtk::OnFocusOut(GtkWidget* window, GdkEventFocus*) {
NotifyWindowBlur();
return FALSE;

View file

@ -101,6 +101,7 @@ class NativeWindowGtk : public NativeWindow,
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnWindowDeleteEvent,
GdkEvent*);
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnFocusIn, GdkEventFocus*);
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnFocusOut, GdkEventFocus*);
CHROMEGTK_CALLBACK_1(NativeWindowGtk, gboolean, OnWindowState,
GdkEventWindowState*);

View file

@ -48,6 +48,10 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
acceptsFirstMouse_ = accept;
}
- (void)windowDidBecomeMain:(NSNotification*)notification {
shell_->NotifyWindowFocus();
}
- (void)windowDidResignMain:(NSNotification*)notification {
shell_->NotifyWindowBlur();
}

View file

@ -26,6 +26,9 @@ class NativeWindowObserver {
// Called when window loses focus.
virtual void OnWindowBlur() {}
// Called when window gains focus.
virtual void OnWindowFocus() {}
// Called when renderer is hung.
virtual void OnRendererUnresponsive() {}

View file

@ -134,6 +134,10 @@ Emitted when the unresponsive web page becomes responsive again.
Emitted when window loses focus.
### Event: 'focus'
Emitted when window gains focus.
### Class Method: BrowserWindow.getAllWindows()
Returns an array of all opened browser windows.