feat(NativeWindowMac): addTabbedWindow

Add support for the [`NSWindow addTabbedWindow`][nsw] method on MacOSX

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

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

[nsw]: 1855947-addtabbedwindow
[c]: 79f06591df
This commit is contained in:
Daniel Ma 2017-09-13 12:15:14 -07:00 committed by Cheng Zhao
parent 68d35dbeb1
commit 1bb042a661
8 changed files with 46 additions and 0 deletions

View file

@ -938,6 +938,10 @@ void Window::ToggleTabBar() {
window_->ToggleTabBar(); window_->ToggleTabBar();
} }
void Window::AddTabbedWindow(NativeWindow* window) {
window_->AddTabbedWindow(window);
}
void Window::SetVibrancy(mate::Arguments* args) { void Window::SetVibrancy(mate::Arguments* args) {
std::string type; std::string type;
@ -1085,6 +1089,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("selectNextTab", &Window::SelectNextTab) .SetMethod("selectNextTab", &Window::SelectNextTab)
.SetMethod("moveTabToNewWindow", &Window::MoveTabToNewWindow) .SetMethod("moveTabToNewWindow", &Window::MoveTabToNewWindow)
.SetMethod("toggleTabBar", &Window::ToggleTabBar) .SetMethod("toggleTabBar", &Window::ToggleTabBar)
.SetMethod("addTabbedWindow", &Window::AddTabbedWindow)
#endif #endif
.SetMethod("setVibrancy", &Window::SetVibrancy) .SetMethod("setVibrancy", &Window::SetVibrancy)
.SetMethod("_setTouchBarItems", &Window::SetTouchBar) .SetMethod("_setTouchBarItems", &Window::SetTouchBar)

View file

@ -219,6 +219,7 @@ class Window : public mate::TrackableObject<Window>,
void MergeAllWindows(); void MergeAllWindows();
void MoveTabToNewWindow(); void MoveTabToNewWindow();
void ToggleTabBar(); void ToggleTabBar();
void AddTabbedWindow(NativeWindow* window);
void SetVibrancy(mate::Arguments* args); void SetVibrancy(mate::Arguments* args);
void SetTouchBar(const std::vector<mate::PersistentDictionary>& items); void SetTouchBar(const std::vector<mate::PersistentDictionary>& items);

View file

@ -351,6 +351,9 @@ void NativeWindow::MoveTabToNewWindow() {
void NativeWindow::ToggleTabBar() { void NativeWindow::ToggleTabBar() {
} }
void NativeWindow::AddTabbedWindow(NativeWindow* window) {
}
void NativeWindow::SetVibrancy(const std::string& filename) { void NativeWindow::SetVibrancy(const std::string& filename) {
} }

View file

@ -190,6 +190,7 @@ class NativeWindow : public base::SupportsUserData,
virtual void MergeAllWindows(); virtual void MergeAllWindows();
virtual void MoveTabToNewWindow(); virtual void MoveTabToNewWindow();
virtual void ToggleTabBar(); virtual void ToggleTabBar();
virtual void AddTabbedWindow(NativeWindow* window);
// Webview APIs. // Webview APIs.
virtual void FocusOnWebView(); virtual void FocusOnWebView();

View file

@ -108,6 +108,7 @@ class NativeWindowMac : public NativeWindow,
void MergeAllWindows() override; void MergeAllWindows() override;
void MoveTabToNewWindow() override; void MoveTabToNewWindow() override;
void ToggleTabBar() override; void ToggleTabBar() override;
void AddTabbedWindow(NativeWindow* window) override;
void SetVibrancy(const std::string& type) override; void SetVibrancy(const std::string& type) override;
void SetTouchBar( void SetTouchBar(

View file

@ -474,6 +474,7 @@ enum {
@interface NSWindow (SierraSDK) @interface NSWindow (SierraSDK)
- (void)setTabbingMode:(NSInteger)mode; - (void)setTabbingMode:(NSInteger)mode;
- (void)setTabbingIdentifier:(NSString*)identifier; - (void)setTabbingIdentifier:(NSString*)identifier;
- (void)addTabbedWindow:(NSWindow*)window ordered:(NSWindowOrderingMode)ordered;
- (IBAction)selectPreviousTab:(id)sender; - (IBAction)selectPreviousTab:(id)sender;
- (IBAction)selectNextTab:(id)sender; - (IBAction)selectNextTab:(id)sender;
- (IBAction)mergeAllWindows:(id)sender; - (IBAction)mergeAllWindows:(id)sender;
@ -1649,6 +1650,12 @@ void NativeWindowMac::ToggleTabBar() {
} }
} }
void NativeWindowMac::AddTabbedWindow(NativeWindow* window) {
if ([window_ respondsToSelector:@selector(addTabbedWindow:ordered:)]) {
[window_ addTabbedWindow:window->GetNativeWindow() ordered:NSWindowAbove];
}
}
void NativeWindowMac::SetVibrancy(const std::string& type) { void NativeWindowMac::SetVibrancy(const std::string& type) {
if (!base::mac::IsAtLeastOS10_10()) return; if (!base::mac::IsAtLeastOS10_10()) return;

View file

@ -1401,6 +1401,22 @@ there is more than one tab in the current window.
Toggles the visibility of the tab bar if native tabs are enabled and Toggles the visibility of the tab bar if native tabs are enabled and
there is only one tab in the current window. there is only one tab in the current window.
#### `win.addTabbedWindow(browserWindow)` _macOS_
* `browserWindow` BrowserWindow
Adds a window as a tab on this window, after the tab for the window instance.
```js
// in main.js
BrowserWindow.getFocusedWindow().addTabbedWindow(new BrowserWindow({}))
// in renderer.js
remote.getCurrentWindow().addTabbedWindow(new BrowserWindow({}))
```
#### `win.setVibrancy(type)` _macOS_ #### `win.setVibrancy(type)` _macOS_
* `type` String - Can be `appearance-based`, `light`, `dark`, `titlebar`, * `type` String - Can be `appearance-based`, `light`, `dark`, `titlebar`,

View file

@ -709,6 +709,18 @@ describe('BrowserWindow module', function () {
}) })
}) })
describe('BrowserWindow.addTabbedWindow()', function () {
it('does not throw', function () {
if (process.platform !== 'darwin') {
return
}
assert.doesNotThrow(() => {
w.addTabbedWindow(new BrowserWindow({}))
})
})
})
describe('BrowserWindow.setVibrancy(type)', function () { describe('BrowserWindow.setVibrancy(type)', function () {
it('allows setting, changing, and removing the vibrancy', function () { it('allows setting, changing, and removing the vibrancy', function () {
assert.doesNotThrow(function () { assert.doesNotThrow(function () {