]> khamidou — GitHub mirrors - electron.git/commitdiff
Implements #2734 “New API to configure BrowserWindow title bar on Mac”
authorjaanus <jaanus@gmail.com>
Mon, 14 Sep 2015 12:15:41 +0000 (14:15 +0200)
committerjaanus <jaanus@gmail.com>
Mon, 14 Sep 2015 14:50:00 +0000 (16:50 +0200)
New API supported on Yosemite 10.10 and newer.

atom/browser/native_window_mac.mm
atom/common/options_switches.cc
atom/common/options_switches.h
docs/api/browser-window.md
docs/api/frameless-window.md
spec/api-browser-window-spec.coffee

index 64f7c11f997b2e995a2740949bce0a9a117d67cd..9555914c899d82a806b77f7113758e081e79b9ef 100644 (file)
@@ -357,6 +357,17 @@ NativeWindowMac::NativeWindowMac(
     styleMask |= NSTexturedBackgroundWindowMask;
   }
 
+  std::string titleBarStyle = "default";
+  options.Get(switches::kTitleBarStyle, &titleBarStyle);
+
+  if (base::mac::IsOSYosemiteOrLater()) {
+    // New title bar styles are available in Yosemite or newer
+    if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
+      styleMask |= NSFullSizeContentViewWindowMask;
+      styleMask |= NSUnifiedTitleAndToolbarWindowMask;
+    }
+  }
+
   window_.reset([[AtomNSWindow alloc]
       initWithContentRect:cocoa_bounds
                 styleMask:styleMask
@@ -382,6 +393,20 @@ NativeWindowMac::NativeWindowMac(
   // We will manage window's lifetime ourselves.
   [window_ setReleasedWhenClosed:NO];
 
+  // Configure title bar look on Yosemite or newer
+  if (base::mac::IsOSYosemiteOrLater()) {
+    if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
+      [window_ setTitlebarAppearsTransparent:YES];
+      [window_ setTitleVisibility:NSWindowTitleHidden];
+      if (titleBarStyle == "hidden-inset") {
+        NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"];
+        toolbar.showsBaselineSeparator = NO;
+        [window_ setToolbar:toolbar];
+        [toolbar release];
+      }
+    }
+  }
+
   // On OS X the initial window size doesn't include window frame.
   bool use_content_size = false;
   options.Get(switches::kUseContentSize, &use_content_size);
index ce5398e447f64c050eeb2a209ba3ae30aa4cf025..c70e1ba4afa6e362ca9605a5bae9feb01e62ef0e 100644 (file)
@@ -42,6 +42,9 @@ const char kAcceptFirstMouse[] = "accept-first-mouse";
 // Whether window size should include window frame.
 const char kUseContentSize[] = "use-content-size";
 
+// The requested title bar style for the window
+const char kTitleBarStyle[] = "title-bar-style";
+
 // The WebPreferences.
 const char kWebPreferences[] = "web-preferences";
 
index c9298618bdfbd8dbf96b69afc2e7af681c868595..e62f3116661aaba12a60cca1a3255e2120da0c6c 100644 (file)
@@ -30,6 +30,7 @@ extern const char kAlwaysOnTop[];
 extern const char kNodeIntegration[];
 extern const char kAcceptFirstMouse[];
 extern const char kUseContentSize[];
+extern const char kTitleBarStyle[];
 extern const char kWebPreferences[];
 extern const char kZoomFactor[];
 extern const char kAutoHideMenuBar[];
index 785980f08082e828e023deee4367344837113d27..a9f046774af61048e5207e3081255aed09984817 100644 (file)
@@ -70,6 +70,16 @@ Properties `width` and `height` are required.
   Linux.
 * `standard-window` Boolean - Uses the OS X's standard window instead of the
   textured window. Defaults to `true`.
+* `title-bar-style` String, OS X - specifies the style of window title bar.
+  This option is supported on OS X 10.10 Yosemite and newer. There are three
+  possible values:
+  * `default` or not specified results in the standard gray opaque Mac title
+  bar.
+  * `hidden` results in a hidden title bar and a full size content window, yet
+  the title bar still has the standard window controls ("traffic lights") in
+  the top left.
+  * `hidden-inset` results in a hidden title bar with an alternative look
+  where the traffic light buttons are slightly more inset from the window edge.
 * `web-preferences` Object - Settings of web page's features, properties:
   * `node-integration` Boolean - Whether node integration is enabled. Default
     is `true`.
index a326bbd8c1965bea02a3b159dc256089d8c4f81d..8d64a6fcd7c8e64a93dced433d3bf53fd13b6ca2 100644 (file)
@@ -13,6 +13,20 @@ var BrowserWindow = require('browser-window');
 var win = new BrowserWindow({ width: 800, height: 600, frame: false });
 ```
 
+### Alternatives on Mac
+
+On Mac OS X 10.10 Yosemite and newer, there's an alternative way to specify
+a chromeless window. Instead of setting `frame` to `false` which disables
+both the titlebar and window controls, you may want to have the title bar
+hidden and your content extend to the full window size, yet still preserve
+the window controls ("traffic lights") for standard window actions.
+You can do so by specifying the new `title-bar-style` option:
+
+```javascript
+var BrowserWindow = require('browser-window');
+var win = new BrowserWindow({ width: 800, height: 600, 'title-bar-style': 'hidden' });
+```
+
 ## Transparent window
 
 By setting the `transparent` option to `true`, you can also make the frameless
index 15cd621ba27172967e5e9f70f7d849bfac693473..3e4e2d5db5e263c5b5954515a9917f7496f33dc7 100644 (file)
@@ -4,6 +4,7 @@ path   = require 'path'
 remote = require 'remote'
 http   = require 'http'
 url    = require 'url'
+os     = require 'os'
 
 BrowserWindow = remote.require 'browser-window'
 
@@ -160,6 +161,22 @@ describe 'browser-window module', ->
       assert.equal size[0], 400
       assert.equal size[1], 400
 
+  describe '"title-bar-style" option', ->
+    return if process.platform isnt 'darwin'
+    return if parseInt(os.release().split('.')[0]) < 14 # only run these tests on Yosemite or newer
+
+    it 'creates browser window with hidden title bar', ->
+      w.destroy()
+      w = new BrowserWindow(show: false, width: 400, height: 400, 'title-bar-style': 'hidden')
+      contentSize = w.getContentSize()
+      assert.equal contentSize[1], 400
+
+    it 'creates browser window with hidden inset title bar', ->
+      w.destroy()
+      w = new BrowserWindow(show: false, width: 400, height: 400, 'title-bar-style': 'hidden-inset')
+      contentSize = w.getContentSize()
+      assert.equal contentSize[1], 400
+
   describe '"enable-larger-than-screen" option', ->
     return if process.platform is 'linux'