Add focusable option
authorCheng Zhao <zcbenz@gmail.com>
Mon, 13 Jun 2016 08:10:28 +0000 (17:10 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 13 Jun 2016 08:10:28 +0000 (17:10 +0900)
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_mac.h
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/browser/native_window_views.h
atom/common/options_switches.cc
atom/common/options_switches.h
docs/api/browser-window.md

index 0ce3e0e77a2ac50157534b12f6130eaa8a72a6c2..5a93f27d2de0aeb7d03d7f5d9bf8fdd989868414 100644 (file)
@@ -529,8 +529,8 @@ void Window::SetIgnoreMouseEvents(bool ignore) {
   return window_->SetIgnoreMouseEvents(ignore);
 }
 
-void Window::SetIgnoreFocus(bool ignore) {
-  return window_->SetIgnoreFocus(ignore);
+void Window::SetFocusable(bool focusable) {
+  return window_->SetFocusable(focusable);
 }
 
 void Window::CapturePage(mate::Arguments* args) {
@@ -736,7 +736,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
       .SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
       .SetMethod("setIgnoreMouseEvents", &Window::SetIgnoreMouseEvents)
-      .SetMethod("setIgnoreFocus", &Window::SetIgnoreFocus)
+      .SetMethod("setFocusable", &Window::SetFocusable)
       .SetMethod("focusOnWebView", &Window::FocusOnWebView)
       .SetMethod("blurWebView", &Window::BlurWebView)
       .SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
index e84e850a19666d67374df8a7be11870bbd87a03e..286b47262159f028dae4cabee09d63a5d8f93276 100644 (file)
@@ -146,7 +146,7 @@ class Window : public mate::TrackableObject<Window>,
   void SetDocumentEdited(bool edited);
   bool IsDocumentEdited();
   void SetIgnoreMouseEvents(bool ignore);
-  void SetIgnoreFocus(bool ignore);
+  void SetFocusable(bool focusable);
   void CapturePage(mate::Arguments* args);
   void SetProgressBar(double progress);
   void SetOverlayIcon(const gfx::Image& overlay,
index e0224836dacefdbdc95528cb159a2414c429459b..e3c2ff99c55cf5f63fa5c5e4f575ce7091e2eacc 100644 (file)
@@ -282,6 +282,9 @@ bool NativeWindow::IsDocumentEdited() {
   return false;
 }
 
+void NativeWindow::SetFocusable(bool focusable) {
+}
+
 void NativeWindow::SetMenu(ui::MenuModel* menu) {
 }
 
index a321bc41543de666e44ce2fdf482ed28c5fc5519..ffcdcc4da2772f2bb395ac60d409a86724562462 100644 (file)
@@ -155,7 +155,7 @@ class NativeWindow : public base::SupportsUserData,
   virtual void SetDocumentEdited(bool edited);
   virtual bool IsDocumentEdited();
   virtual void SetIgnoreMouseEvents(bool ignore) = 0;
-  virtual void SetIgnoreFocus(bool ignore) = 0;
+  virtual void SetFocusable(bool focusable);
   virtual void SetMenu(ui::MenuModel* menu);
   virtual bool HasModalDialog();
   virtual gfx::NativeWindow GetNativeWindow() = 0;
index 2cbdbc851dab3e5beff6830d24d49cc66a9fb560..27857239e8c878bdee973331468bd2b5ec97c9c3 100644 (file)
@@ -77,7 +77,6 @@ class NativeWindowMac : public NativeWindow {
   void SetDocumentEdited(bool edited) override;
   bool IsDocumentEdited() override;
   void SetIgnoreMouseEvents(bool ignore) override;
-  void SetIgnoreFocus(bool ignore) override;
   bool HasModalDialog() override;
   gfx::NativeWindow GetNativeWindow() override;
   gfx::AcceleratedWidget GetAcceleratedWidget() override;
index de02033b6ff8ae52a9b69adadc02883825b11fbd..9035d5e62d5a56fc8ee25b4d6b5740ba31b3dea9 100644 (file)
@@ -490,6 +490,10 @@ NativeWindowMac::NativeWindowMac(
          NSWindowCollectionBehaviorIgnoresCycle)];
   }
 
+  bool focusable;
+  if (options.Get(options::kFocusable, &focusable) && !focusable)
+    [window_ setDisableKeyOrMainWindow:YES];
+
   // Remove non-transparent corners, see http://git.io/vfonD.
   if (!has_frame())
     [window_ setOpaque:NO];
@@ -883,10 +887,6 @@ void NativeWindowMac::SetIgnoreMouseEvents(bool ignore) {
   [window_ setIgnoresMouseEvents:ignore];
 }
 
-void NativeWindowMac::SetIgnoreFocus(bool ignore) {
-  [window_ setDisableKeyOrMainWindow:ignore];
-}
-
 bool NativeWindowMac::HasModalDialog() {
   return [window_ attachedSheet] != nil;
 }
index 845e08a07de052e66c1d7fe310267dc1a142df38..aa64156b143d5a2289f683c4bbb3248f518e3293 100644 (file)
@@ -692,10 +692,10 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore) {
 #endif
 }
 
-void NativeWindowViews::SetIgnoreFocus(bool ignore) {
+void NativeWindowViews::SetFocusable(bool focusable) {
 #if defined(OS_WIN)
   LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
-  if (ignore)
+  if (focusable)
     ex_style |= WS_EX_NOACTIVATE;
   else
     ex_style &= ~WS_EX_NOACTIVATE;
index 826b3fce7617a5f171881a162ccf02d1fe158c52..53774203742c306b7d1a69a3c34efe1369e41a52 100644 (file)
@@ -92,7 +92,7 @@ class NativeWindowViews : public NativeWindow,
   void SetHasShadow(bool has_shadow) override;
   bool HasShadow() override;
   void SetIgnoreMouseEvents(bool ignore) override;
-  void SetIgnoreFocus(bool ignore) override;
+  void SetFocusable(bool focusable) override;
   void SetMenu(ui::MenuModel* menu_model) override;
   gfx::NativeWindow GetNativeWindow() override;
   void SetOverlayIcon(const gfx::Image& overlay,
index d370f0ef859fb0f5780a117b1ceda56f75bc5c0b..04e268c66e2e2f3bc9cb463a52b6f37279a9aa75 100644 (file)
@@ -75,6 +75,9 @@ const char kBackgroundColor[] = "backgroundColor";
 // Whether the window should have a shadow.
 const char kHasShadow[] = "hasShadow";
 
+// Whether the window can be activated.
+const char kFocusable[] = "focusable";
+
 // The WebPreferences.
 const char kWebPreferences[] = "webPreferences";
 
index 5924c054911920df8ca93fbec5133067223dd547..29fbc0e40f847301afb3bb647cdadff148e713b0 100644 (file)
@@ -44,6 +44,7 @@ extern const char kDisableAutoHideCursor[];
 extern const char kStandardWindow[];
 extern const char kBackgroundColor[];
 extern const char kHasShadow[];
+extern const char kFocusable[];
 extern const char kWebPreferences[];
 
 // WebPreferences.
index 95b76019e3f3ecedb63817c467cbb41af0938b1b..1000d0c787bea2a509eca4ef126f2e0fafb5f41a 100644 (file)
@@ -54,6 +54,8 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
     implemented on Linux. Default is `true`.
   * `closable` Boolean - Whether window is closable. This is not implemented
     on Linux. Default is `true`.
+  * `focusable` Boolean - Whether the window can be focused. Default is
+    `true`.
   * `alwaysOnTop` Boolean - Whether the window should always stay on top of
     other windows. Default is `false`.
   * `fullscreen` Boolean - Whether the window should show in fullscreen. When
@@ -953,17 +955,10 @@ All mouse events happened in this window will be passed to the window below
 this window, but if this window has focus, it will still receive keyboard
 events.
 
-### `win.setIgnoreFocus(ignore)` _OS X_ _Windows_
-
-* `ignore` Boolean
-
-Prevents the window from getting focus.
+### `win.setActivatable(activatable)` _Windows_
 
-On OS X this API has to be called before the window shows:
+* `activatable` Boolean
 
-```javascript
-let win = new BrowserWindow({show: false})
-win.setIgnoreFocus(true)
-```
+Changes whether the window can be activated.
 
 [blink-feature-string]: https://cs.chromium.org/chromium/src/third_party/WebKit/Source/platform/RuntimeEnabledFeatures.in