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]