From ed76e0373069570d1825ba0ad91d5470d846bf24 Mon Sep 17 00:00:00 2001 From: Tony Ganch Date: Tue, 21 Mar 2017 10:18:57 +0100 Subject: [PATCH 1/8] Revert "Add forward declaration of NSWindow.allowsAutomaticWindowTabbing" This reverts commit 770a3509cfcd62c958dc2b70bd497585f55b565c. --- atom/browser/mac/atom_application_delegate.mm | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/atom/browser/mac/atom_application_delegate.mm b/atom/browser/mac/atom_application_delegate.mm index 9e245f99078d..74f45e2d2669 100644 --- a/atom/browser/mac/atom_application_delegate.mm +++ b/atom/browser/mac/atom_application_delegate.mm @@ -10,10 +10,6 @@ #include "base/strings/sys_string_conversions.h" #include "base/values.h" -@interface NSWindow (SierraSDK) -@property(class) BOOL allowsAutomaticWindowTabbing; -@end - @implementation AtomApplicationDelegate - (void)setApplicationDockMenu:(atom::AtomMenuModel*)model { @@ -26,8 +22,9 @@ [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"NSFullScreenMenuItemEverywhere"]; // Don't add the "Show Tab Bar" menu item. - if ([NSWindow respondsToSelector:@selector(allowsAutomaticWindowTabbing)]) + if ([NSWindow respondsToSelector:@selector(allowsAutomaticWindowTabbing)]) { NSWindow.allowsAutomaticWindowTabbing = NO; + } atom::Browser::Get()->WillFinishLaunching(); } From 9e02c60e2229d38de47405030a99acdc8830a0af Mon Sep 17 00:00:00 2001 From: Tony Ganch Date: Tue, 21 Mar 2017 10:19:08 +0100 Subject: [PATCH 2/8] Revert "Disable Show Tab Bar menu item on macOS Sierrra" This reverts commit 24b93139581836ea8ec3f88cda0edbb3baba8812. --- atom/browser/mac/atom_application_delegate.mm | 5 ----- 1 file changed, 5 deletions(-) diff --git a/atom/browser/mac/atom_application_delegate.mm b/atom/browser/mac/atom_application_delegate.mm index 74f45e2d2669..4c6a938fba59 100644 --- a/atom/browser/mac/atom_application_delegate.mm +++ b/atom/browser/mac/atom_application_delegate.mm @@ -21,11 +21,6 @@ // Don't add the "Enter Full Screen" menu item automatically. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"NSFullScreenMenuItemEverywhere"]; - // Don't add the "Show Tab Bar" menu item. - if ([NSWindow respondsToSelector:@selector(allowsAutomaticWindowTabbing)]) { - NSWindow.allowsAutomaticWindowTabbing = NO; - } - atom::Browser::Get()->WillFinishLaunching(); } From a7565f0d5704c1c5a12ec24a3ee669358efc413b Mon Sep 17 00:00:00 2001 From: Tony Ganch Date: Mon, 27 Mar 2017 16:15:17 +0200 Subject: [PATCH 3/8] Enable native tabs on macOS --- atom/browser/native_window_mac.h | 2 ++ atom/browser/native_window_mac.mm | 15 ++++++++++++++- atom/common/options_switches.cc | 3 +++ atom/common/options_switches.h | 1 + docs/api/browser-window.md | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index bd34993fb119..066bcc503ea9 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -179,6 +179,8 @@ class NativeWindowMac : public NativeWindow, // The "titleBarStyle" option. TitleBarStyle title_bar_style_; + std::string tabbing_identifier_; + DISALLOW_COPY_AND_ASSIGN(NativeWindowMac); }; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index c88469a9c8a1..f73cda1fd07c 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -656,7 +656,8 @@ NativeWindowMac::NativeWindowMac( was_fullscreen_(false), zoom_to_page_width_(false), attention_request_id_(0), - title_bar_style_(NORMAL) { + title_bar_style_(NORMAL), + tabbing_identifier_(""){ int width = 800, height = 600; options.Get(options::kWidth, &width); options.Get(options::kHeight, &height); @@ -682,6 +683,8 @@ NativeWindowMac::NativeWindowMac( options.Get(options::kTitleBarStyle, &title_bar_style_); + options.Get(options::kTabbingIdentifier, &tabbing_identifier_); + std::string windowType; options.Get(options::kType, &windowType); @@ -754,6 +757,16 @@ NativeWindowMac::NativeWindowMac( [window_ setOpaque:NO]; } + if (base::mac::IsAtLeastOS10_12()) { + // Create a tab only if tabbing identifier is specified and window has + // a native title bar. + if (tabbing_identifier_.empty() || transparent() || !has_frame()) { + [window_ setTabbingMode:NSWindowTabbingModeDisallowed]; + } else { + [window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbing_identifier_)]; + } + } + // We will manage window's lifetime ourselves. [window_ setReleasedWhenClosed:NO]; diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index d040489b9f76..288fcd3a0753 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -51,6 +51,9 @@ const char kZoomToPageWidth[] = "zoomToPageWidth"; // The requested title bar style for the window const char kTitleBarStyle[] = "titleBarStyle"; +// Tabbing identifier for the window if native tabs are enabled on macOS. +const char kTabbingIdentifier[] = "tabbingIdentifier"; + // The menu bar is hidden unless "Alt" is pressed. const char kAutoHideMenuBar[] = "autoHideMenuBar"; diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index dd2824c55c74..9e1a71ca5bda 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -36,6 +36,7 @@ extern const char kAcceptFirstMouse[]; extern const char kUseContentSize[]; extern const char kZoomToPageWidth[]; extern const char kTitleBarStyle[]; +extern const char kTabbingIdentifier[]; extern const char kAutoHideMenuBar[]; extern const char kEnableLargerThanScreen[]; extern const char kDarkTheme[]; diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 182e798158b1..73b7fe9c18b8 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -264,6 +264,9 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. canvas features. Default is `false`. * `scrollBounce` Boolean (optional) - Enables scroll bounce (rubber banding) effect on macOS. Default is `false`. + * `tabbingIdentifier` String (optional) - Tab group name, allows opening the + window as a native tab on macOS 10.12+. Windows with the same tabbing identifier will + be grouped together. * `blinkFeatures` String (optional) - A list of feature strings separated by `,`, like `CSSVariables,KeyboardEventKey` to enable. The full list of supported feature strings can be found in the [RuntimeEnabledFeatures.json5][blink-feature-string] From bd935b213f2c9a9aa1807aefecb33d8c47aaead1 Mon Sep 17 00:00:00 2001 From: Tony Ganch Date: Thu, 30 Mar 2017 15:13:49 +0200 Subject: [PATCH 4/8] Fix compilation against macOS 10.10 SDK --- atom/browser/native_window_mac.mm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index f73cda1fd07c..f006873efd78 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -336,6 +336,14 @@ bool ScopedDisableResize::disable_resize_ = false; @end +enum { + NSWindowTabbingModeDisallowed = 2 +}; +@interface NSWindow (SierraSDK) +- (void)setTabbingMode:(NSInteger)mode; +- (void)setTabbingIdentifier:(NSString *)identifier; +@end + @interface AtomNSWindow : EventDispatchingWindow { @private atom::NativeWindowMac* shell_; @@ -656,8 +664,7 @@ NativeWindowMac::NativeWindowMac( was_fullscreen_(false), zoom_to_page_width_(false), attention_request_id_(0), - title_bar_style_(NORMAL), - tabbing_identifier_(""){ + title_bar_style_(NORMAL) { int width = 800, height = 600; options.Get(options::kWidth, &width); options.Get(options::kHeight, &height); @@ -761,9 +768,13 @@ NativeWindowMac::NativeWindowMac( // Create a tab only if tabbing identifier is specified and window has // a native title bar. if (tabbing_identifier_.empty() || transparent() || !has_frame()) { - [window_ setTabbingMode:NSWindowTabbingModeDisallowed]; + if ([window_ respondsToSelector:@selector(tabbingMode)]) { + [window_ setTabbingMode:NSWindowTabbingModeDisallowed]; + } } else { - [window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbing_identifier_)]; + if ([window_ respondsToSelector:@selector(tabbingIdentifier)]) { + [window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbing_identifier_)]; + } } } From c8b992fa3982ffd880c8c2cc931d5a0c892f56e3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 30 Mar 2017 13:46:34 -0700 Subject: [PATCH 5/8] Remove 10.12 check handled by respondsToSelector --- atom/browser/native_window_mac.mm | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index f006873efd78..077eee52288f 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -764,17 +764,15 @@ NativeWindowMac::NativeWindowMac( [window_ setOpaque:NO]; } - if (base::mac::IsAtLeastOS10_12()) { - // Create a tab only if tabbing identifier is specified and window has - // a native title bar. - if (tabbing_identifier_.empty() || transparent() || !has_frame()) { - if ([window_ respondsToSelector:@selector(tabbingMode)]) { - [window_ setTabbingMode:NSWindowTabbingModeDisallowed]; - } - } else { - if ([window_ respondsToSelector:@selector(tabbingIdentifier)]) { - [window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbing_identifier_)]; - } + // Create a tab only if tabbing identifier is specified and window has + // a native title bar. + if (tabbing_identifier_.empty() || transparent() || !has_frame()) { + if ([window_ respondsToSelector:@selector(tabbingMode)]) { + [window_ setTabbingMode:NSWindowTabbingModeDisallowed]; + } + } else { + if ([window_ respondsToSelector:@selector(tabbingIdentifier)]) { + [window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbing_identifier_)]; } } From e699e88b4caed3929ce8b3e077a08660f0612ccc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 30 Mar 2017 13:46:58 -0700 Subject: [PATCH 6/8] Add initial tabbingIdentifier spec --- spec/api-browser-window-spec.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index b5985e4b7406..d83c173f26f1 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -692,7 +692,7 @@ describe('BrowserWindow module', function () { }) }) - describe('"title-bar-style" option', function () { + describe('"titleBarStyle" option', function () { if (process.platform !== 'darwin') { return } @@ -772,6 +772,20 @@ describe('BrowserWindow module', function () { }) }) + describe('"tabbingIdentifier" option', function () { + it('can be set on a window', function () { + w.destroy() + w = new BrowserWindow({ + tabbingIdentifier: 'group1' + }) + w.destroy() + w = new BrowserWindow({ + tabbingIdentifier: 'group2', + frame: false + }) + }) + }) + describe('"web-preferences" option', function () { afterEach(function () { ipcMain.removeAllListeners('answer') From 42300ae58ef31a911a20828718741275f0fdf067 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 30 Mar 2017 13:47:11 -0700 Subject: [PATCH 7/8] Make tabbing identifier var local --- atom/browser/native_window_mac.h | 2 -- atom/browser/native_window_mac.mm | 7 ++++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 066bcc503ea9..bd34993fb119 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -179,8 +179,6 @@ class NativeWindowMac : public NativeWindow, // The "titleBarStyle" option. TitleBarStyle title_bar_style_; - std::string tabbing_identifier_; - DISALLOW_COPY_AND_ASSIGN(NativeWindowMac); }; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 077eee52288f..2912022bd634 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -690,7 +690,8 @@ NativeWindowMac::NativeWindowMac( options.Get(options::kTitleBarStyle, &title_bar_style_); - options.Get(options::kTabbingIdentifier, &tabbing_identifier_); + std::string tabbingIdentifier; + options.Get(options::kTabbingIdentifier, &tabbingIdentifier); std::string windowType; options.Get(options::kType, &windowType); @@ -766,13 +767,13 @@ NativeWindowMac::NativeWindowMac( // Create a tab only if tabbing identifier is specified and window has // a native title bar. - if (tabbing_identifier_.empty() || transparent() || !has_frame()) { + if (tabbingIdentifier.empty() || transparent() || !has_frame()) { if ([window_ respondsToSelector:@selector(tabbingMode)]) { [window_ setTabbingMode:NSWindowTabbingModeDisallowed]; } } else { if ([window_ respondsToSelector:@selector(tabbingIdentifier)]) { - [window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbing_identifier_)]; + [window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbingIdentifier)]; } } From 6f27d466a508852455d973441f99dbdf77a483ab Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 30 Mar 2017 13:49:00 -0700 Subject: [PATCH 8/8] Move tabbingIdentifier out of webPreferences list --- docs/api/browser-window.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 73b7fe9c18b8..01f5431ecf73 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -211,6 +211,9 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. width of the web page when zoomed, `false` will cause it to zoom to the width of the screen. This will also affect the behavior when calling `maximize()` directly. Default is `false`. + * `tabbingIdentifier` String (optional) - Tab group name, allows opening the + window as a native tab on macOS 10.12+. Windows with the same tabbing + identifier will be grouped together. * `webPreferences` Object (optional) - Settings of web page's features. * `devTools` Boolean (optional) - Whether to enable DevTools. If it is set to `false`, can not use `BrowserWindow.webContents.openDevTools()` to open DevTools. Default is `true`. * `nodeIntegration` Boolean (optional) - Whether node integration is enabled. Default @@ -264,9 +267,6 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. canvas features. Default is `false`. * `scrollBounce` Boolean (optional) - Enables scroll bounce (rubber banding) effect on macOS. Default is `false`. - * `tabbingIdentifier` String (optional) - Tab group name, allows opening the - window as a native tab on macOS 10.12+. Windows with the same tabbing identifier will - be grouped together. * `blinkFeatures` String (optional) - A list of feature strings separated by `,`, like `CSSVariables,KeyboardEventKey` to enable. The full list of supported feature strings can be found in the [RuntimeEnabledFeatures.json5][blink-feature-string]