]> khamidou — GitHub mirrors - electron.git/commitdiff
Add a `focus` event to BrowserWindow
authorGavin M. Roy <gavinr@aweber.com>
Wed, 21 May 2014 17:46:13 +0000 (13:46 -0400)
committerGavin M. Roy <gavinr@aweber.com>
Wed, 21 May 2014 17:46:13 +0000 (13:46 -0400)
- Tested in OSX
- Untested in GTK, but I expect it should work
- Did not see any similar constructs for notifications in Windows

atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_gtk.cc
atom/browser/native_window_gtk.h
atom/browser/native_window_mac.mm
atom/browser/native_window_observer.h
docs/api/browser-window.md

index 401cc66c73cc9a8459f158a0e1b8bf8cdb73301e..869ce7571fab75797526fa64eeaa461a143c50df 100644 (file)
@@ -95,6 +95,10 @@ void Window::OnWindowBlur() {
   Emit("blur");
 }
 
+void Window::OnWindowFocus() {
+  Emit("focus");
+}
+
 void Window::OnRendererUnresponsive() {
   Emit("unresponsive");
 }
index 239673672d2b653559b5a454698d38332d3fb949..be74f14b95a3c238c095ac18f11360832debe1c9 100644 (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;
 
index 558778029e5b72bfa038f62f0a1e40d1bc7de833..3fe3cb4d380a2f2437340083af341a38fef29786 100644 (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
index 7c2b60806713316bc2b39460e803b67e88c0005e..26fe94abd1a3a7fc6a5e706d9bb3a6092864eecf 100644 (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);
index 0b49b0420c7f8f192d0a86b7dbd7aef3353d2dd6..364947ec493f788dff3523f88f7201ab79401f93 100644 (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;
index d73381de3382ff74203fb8130cf0fe377e8f7b68..be5ff6914c0bbb17d96a10e69e12e3f69dfc4a60 100644 (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*);
index e8da6b523e112d3030a99d9951767d3ab7c04b9a..a34ec9c7df9c97f014bc8de351d8f7eff4b80fd9 100644 (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();
 }
index 422d7d72577ecaa48047f06bef51823400c9d747..33a1505a99b3420b7e701b7380dd3d21373ea0d7 100644 (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() {}
 
index 7b143b8cca60ebb985458d84447e568ccc46ba05..fac123058be1cd2692cfb1c3f723bde90f355e09 100644 (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.