Add blur method to window ref #4724
authorMax Beatty <max@beatty.me>
Fri, 11 Mar 2016 05:45:51 +0000 (21:45 -0800)
committerMax Beatty <max@beatty.me>
Fri, 11 Mar 2016 05:45:51 +0000 (21:45 -0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
docs/api/browser-window.md
spec/api-browser-window-spec.js

index ea1d95b..fb5f3ed 100644 (file)
@@ -294,6 +294,10 @@ void Window::Focus() {
   window_->Focus(true);
 }
 
+void Window::Blur() {
+  window_->Focus(false);
+}
+
 bool Window::IsFocused() {
   return window_->IsFocused();
 }
@@ -688,6 +692,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .MakeDestroyable()
       .SetMethod("close", &Window::Close)
       .SetMethod("focus", &Window::Focus)
+      .SetMethod("blur", &Window::Blur)
       .SetMethod("isFocused", &Window::IsFocused)
       .SetMethod("show", &Window::Show)
       .SetMethod("showInactive", &Window::ShowInactive)
index 641124f..c984090 100644 (file)
@@ -83,6 +83,7 @@ class Window : public mate::TrackableObject<Window>,
   // APIs for NativeWindow.
   void Close();
   void Focus();
+  void Blur();
   bool IsFocused();
   void Show();
   void ShowInactive();
index 6e1bc99..b214596 100644 (file)
@@ -397,6 +397,10 @@ the [close event](#event-close).
 
 Focus on the window.
 
+### `win.blur()`
+
+Remove focus on the window.
+
 ### `win.isFocused()`
 
 Returns a boolean, whether the window is focused.
index 731ae1c..3474a85 100644 (file)
@@ -145,6 +145,13 @@ describe('browser-window module', function() {
     });
   });
 
+  describe('BrowserWindow.blur()', function() {
+    it('removes focus from window', function() {
+      w.blur();
+      assert(!w.isFocused());
+    });
+  });
+
   describe('BrowserWindow.capturePage(rect, callback)', function() {
     it('calls the callback with a Buffer', function(done) {
       w.capturePage({