8000 Native tabs on macOS by tonyganch · Pull Request #9052 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Native tabs on macOS #9052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 30, 2017
Merged

Native tabs on macOS #9052

merged 8 commits into from
Mar 30, 2017

Conversation

tonyganch
Copy link
Contributor

Should fix #6124.
Testing app: https://github.com/tonyganch/electron-quick-start/tree/native-tabs
Video: https://yadi.sk/i/vzAhnDkd3GTC5b

The idea is to make windows not tabbable by default.
That will allow existing applications to save user experience as they have it right now.
In order to open a window as a native tab, tabbingIdentifier option should be passed, like:
new BrowserWindow({tabbingIdentifier: 'mainGroup'}).
If tabbing identifier is missing/empty, or a window has custom/no title bar (is frameless/transparent), such window will not be tabbed.

/cc @alespergl @bpasero

@bpasero
Copy link
Contributor
bpasero commented Mar 29, 2017

@tonyganch very cool!

@@ -656,7 +656,8 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
was_fullscreen_(false),
zoom_to_page_width_(false),
attention_request_id_(0),
title_bar_style_(NORMAL) {
title_bar_style_(NORMAL),
tabbing_identifier_(""){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8000

Space needed before {, perhaps we don't even need the tabbing_identifier_ initializer here since it will be an empty string by default.

// 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];
Copy link
Contributor
@kevinsawicki kevinsawicki Mar 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added in 10.12 and so this does not compile against the 10.10 SDK which Electron builds against.

Will probably need forward declarations and/or some respondsToSelector checks.

https://developer.apple.com/reference/appkit/nswindow/1644729-tabbingmode?language=objc

https://travis-ci.org/electron/electron/jobs/216322601

../../atom/browser/native_window_mac.mm:764:16: error: instance method '-setTabbingMode:' not found (return type defaults to 'id') [-Werror,-Wobjc-method-access]
      [window_ setTabbingMode:NSWindowTabbingModeDisallowed];
               ^~~~~~~~~~~~~~
../../atom/browser/native_window_mac.mm:339:12: note: receiver is instance of class declared here
@interface AtomNSWindow : EventDispatchingWindow<QLPreviewPanelDataSource, QLPreviewPanelDelegate, NSTouchBarDelegate> {
           ^
../../atom/browser/native_window_mac.mm:764:31: error: use of undeclared identifier 'NSWindowTabbingModeDisallowed'
      [window_ setTabbingMode:NSWindowTabbingModeDisallowed];
                              ^
../../atom/browser/native_window_mac.mm:766:16: error: instance method '-setTabbingIdentifier:' not found (return type defaults to 'id') [-Werror,-Wobjc-method-access]
      [window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbing_identifier_)];

10000
if (tabbing_identifier_.empty() || transparent() || !has_frame()) {
[window_ setTabbingMode:NSWindowTabbingModeDisallowed];
} else {
[window_ setTabbingIdentifier:base::SysUTF8ToNSString(tabbing_identifier_)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinsawicki kevinsawicki self-assigned this Mar 29, 2017
@tonyganch
Copy link
Contributor Author

@kevinsawicki, thank you for helpful review!
I added declarations for the methods that I use plus added checks with respondsToSelector.
I checked the changes locally with older SDK and ran the build on Travis, it's green now:
https://travis-ci.org/electron/electron/jobs/216753155

Do you think I should leave base::mac::IsAtLeastOS10_12 check or it's not necessary anymore because of respondsToSelector and I'd better remove it?

@tonyganch tonyganch closed this Mar 30, 2017
@tonyganch tonyganch reopened this Mar 30, 2017
@kevinsawicki
Copy link
Contributor

Do you think I should leave base::mac::IsAtLeastOS10_12 check or it's not necessary anymore because of respondsToSelector and I'd better remove it?

I think we should be good without the IsAtLeastOS10_12 check.

I'll add a test that exercises it and remove the check and we'll see if it passes on CI which is pre-10.12

@@ -682,6 +690,8 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,

options.Get(options::kTitleBarStyle, &title_bar_style_);

options.Get(options::kTabbingIdentifier, &tabbing_identifier_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like tabbing_identifier_ is only used in this method so it could be local variable here instead of an instance variable.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it is under the webPreferences outer list but it isn't a web preference.

Perhaps it should go after zoomToPageWidth instead.

@kevinsawicki kevinsawicki merged commit a2588c1 into electron:master Mar 30, 2017
@kevinsawicki
Copy link
Contributor

Thanks for this @tonyganch, awesome work 👍 📑 🎆

@bpasero
Copy link
Contributor
bpasero commented Mar 31, 2017

@tonyganch seems to work nicely!

One thing I am wondering is: if you have a window with tab bar to the top and you open a new window, it will open as separate window. But if you are in fullscreen mode, that new window will be attached as tab. Would it make sense to have API to force a window to open into an existing tab group or not? This would make it possible to give the user the choice of wether a window should open as tab or not independent from being in fullscreen mode or not.

Not even sure such API exists on macOS though.

Update: extracted this into #9094

@russelldc
Copy link
russelldc commented May 4, 2017

@tonyganch The video looks great, but when I try your sample locally (with Electron 1.6.6) on MacOS 10.12.4, all of the buttons open new windows rather than tabs.

Edit: I tried downgrading to Electron 1.6.3 and matching the Node version in your video, but it's still not working.

danielma pushed a commit to danielma/electron that referenced this pull request Sep 13, 2017
Add support for the `NSWindow addTabbedWindow` method on MacOSX

This plays nicely with the changes from electron#9052 and electron#9725

Usage samples available in [this commit][c] in my fork of
`electron-quick-start`

[c]: danielma/electron-quick-start@79f0659
danielma pushed a commit to danielma/electron that referenced this pull request Sep 13, 2017
Add support for the [`NSWindow addTabbedWindow`][nsw] method on MacOSX

This plays nicely with the changes from electron#9052 and electron#9725

Usage samples available in [this commit][c] in my fork of
`electron-quick-start`

[nsw]: https://developer.apple.com/documentation/appkit/nswindow/1855947-addtabbedwindow
[c]: danielma/electron-quick-start@79f0659
danielma pushed a commit to danielma/electron that referenced this pull request Sep 13, 2017
Add support for the [`NSWindow addTabbedWindow`][nsw] method on MacOSX

This plays nicely with the changes from electron#9052 and electron#9725

Usage samples available in [this commit][c] in my fork of
`electron-quick-start`

[nsw]: https://developer.apple.com/documentation/appkit/nswindow/1855947-addtabbedwindow
[c]: danielma/electron-quick-start@79f0659
danielma pushed a commit to danielma/electron that referenced this pull request Sep 13, 2017
Add support for the [`NSWindow addTabbedWindow`][nsw] method on MacOSX

This plays nicely with the changes from electron#9052 and electron#9725

Usage samples available in [this commit][c] in my fork of
`electron-quick-start`

[nsw]: https://developer.apple.com/documentation/appkit/nswindow/1855947-addtabbedwindow
[c]: danielma/electron-quick-start@79f0659
zcbenz pushed a commit to danielma/electron that referenced this pull request Oct 3, 2017
Add support for the [`NSWindow addTabbedWindow`][nsw] method on MacOSX

This plays nicely with the changes from electron#9052 and electron#9725

Usage samples available in [this commit][c] in my fork of
`electron-quick-start`

[nsw]: https://developer.apple.com/documentation/appkit/nswindow/1855947-addtabbedwindow
[c]: danielma/electron-quick-start@79f0659
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for macOS Sierra's native tabs
4 participants
0