Enable native tabs on macOS

This commit is contained in:
Tony Ganch 2017-03-27 16:15:17 +02:00
parent 9e02c60e22
commit a7565f0d57
5 changed files with 23 additions and 1 deletions

View file

@ -179,6 +179,8 @@ class NativeWindowMac : public NativeWindow,
// The "titleBarStyle" option.
TitleBarStyle title_bar_style_;
std::string tabbing_identifier_;
DISALLOW_COPY_AND_ASSIGN(NativeWindowMac);
};

View file

@ -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];

View file

@ -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";

View file

@ -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[];

View file

@ -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]