diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index ff6e206c47c1..c225dd717c63 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -910,6 +910,26 @@ void Window::SetAutoHideCursor(bool auto_hide) { window_->SetAutoHideCursor(auto_hide); } +void Window::SelectPreviousTab() { + window_->SelectPreviousTab(); +} + +void Window::SelectNextTab() { + window_->SelectNextTab(); +} + +void Window::MergeAllWindows() { + window_->MergeAllWindows(); +} + +void Window::MoveTabToNewWindow() { + window_->MoveTabToNewWindow(); +} + +void Window::ToggleTabBar() { + window_->ToggleTabBar(); +} + void Window::SetVibrancy(mate::Arguments* args) { std::string type; @@ -1050,6 +1070,11 @@ void Window::BuildPrototype(v8::Isolate* isolate, &Window::IsVisibleOnAllWorkspaces) #if defined(OS_MACOSX) .SetMethod("setAutoHideCursor", &Window::SetAutoHideCursor) + .SetMethod("mergeAllWindows", &Window::MergeAllWindows) + .SetMethod("selectPreviousTab", &Window::SelectPreviousTab) + .SetMethod("selectNextTab", &Window::SelectNextTab) + .SetMethod("moveTabToNewWindow", &Window::MoveTabToNewWindow) + .SetMethod("toggleTabBar", &Window::ToggleTabBar) #endif .SetMethod("setVibrancy", &Window::SetVibrancy) .SetMethod("_setTouchBarItems", &Window::SetTouchBar) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 3dac635d36a2..5dc5cfa6b577 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -212,6 +212,12 @@ class Window : public mate::TrackableObject, void SetAutoHideCursor(bool auto_hide); + void SelectPreviousTab(); + void SelectNextTab(); + void MergeAllWindows(); + void MoveTabToNewWindow(); + void ToggleTabBar(); + void SetVibrancy(mate::Arguments* args); void SetTouchBar(const std::vector& items); void RefreshTouchBarItem(const std::string& item_id); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index ddb4a030079c..e47a4f7e8ceb 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -336,6 +336,21 @@ void NativeWindow::SetParentWindow(NativeWindow* parent) { void NativeWindow::SetAutoHideCursor(bool auto_hide) { } +void NativeWindow::SelectPreviousTab() { +} + +void NativeWindow::SelectNextTab() { +} + +void NativeWindow::MergeAllWindows() { +} + +void NativeWindow::MoveTabToNewWindow() { +} + +void NativeWindow::ToggleTabBar() { +} + void NativeWindow::SetVibrancy(const std::string& filename) { } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 84d367141102..1ec9417e173e 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -182,6 +182,13 @@ class NativeWindow : public base::SupportsUserData, virtual void RefreshTouchBarItem(const std::string& item_id); virtual void SetEscapeTouchBarItem(const mate::PersistentDictionary& item); + // Native Tab API + virtual void SelectPreviousTab(); + virtual void SelectNextTab(); + virtual void MergeAllWindows(); + virtual void MoveTabToNewWindow(); + virtual void ToggleTabBar(); + // Webview APIs. virtual void FocusOnWebView(); virtual void BlurWebView(); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index bc3992e92615..76f1e8292873 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -101,6 +101,12 @@ class NativeWindowMac : public NativeWindow, void SetAutoHideCursor(bool auto_hide) override; + void SelectPreviousTab() override; + void SelectNextTab() override; + void MergeAllWindows() override; + void MoveTabToNewWindow() override; + void ToggleTabBar() override; + void SetVibrancy(const std::string& type) override; void SetTouchBar( const std::vector& items) override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index d9889f10c00f..9899caeb2bf0 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -469,6 +469,11 @@ enum { @interface NSWindow (SierraSDK) - (void)setTabbingMode:(NSInteger)mode; - (void)setTabbingIdentifier:(NSString*)identifier; +- (IBAction)selectPreviousTab:(id)sender; +- (IBAction)selectNextTab:(id)sender; +- (IBAction)mergeAllWindows:(id)sender; +- (IBAction)moveTabToNewWindow:(id)sender; +- (IBAction)toggleTabBar:(id)sender; @end #endif // MAC_OS_X_VERSION_10_12 @@ -1523,6 +1528,36 @@ void NativeWindowMac::SetAutoHideCursor(bool auto_hide) { [window_ setDisableAutoHideCursor:!auto_hide]; } +void NativeWindowMac::SelectPreviousTab() { + if ([window_ respondsToSelector:@selector(selectPreviousTab:)]) { + [window_ selectPreviousTab:nil]; + } +} + +void NativeWindowMac::SelectNextTab() { + if ([window_ respondsToSelector:@selector(selectNextTab:)]) { + [window_ selectNextTab:nil]; + } +} + +void NativeWindowMac::MergeAllWindows() { + if ([window_ respondsToSelector:@selector(mergeAllWindows:)]) { + [window_ mergeAllWindows:nil]; + } +} + +void NativeWindowMac::MoveTabToNewWindow() { + if ([window_ respondsToSelector:@selector(moveTabToNewWindow:)]) { + [window_ moveTabToNewWindow:nil]; + } +} + +void NativeWindowMac::ToggleTabBar() { + if ([window_ respondsToSelector:@selector(toggleTabBar:)]) { + [window_ toggleTabBar:nil]; + } +} + void NativeWindowMac::SetVibrancy(const std::string& type) { if (!base::mac::IsAtLeastOS10_10()) return; diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 53ed57f0c389..b01e5dc78078 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1363,6 +1363,31 @@ Returns `BrowserWindow[]` - All child windows. Controls whether to hide cursor when typing. +#### `win.selectPreviousTab()` _macOS_ + +Selects the previous tab when native tabs are enabled and there are other +tabs in the window. + +#### `win.selectNextTab()` _macOS_ + +Selects the next tab when native tabs are enabled and there are other +tabs in the window. + +#### `win.mergeAllWindows()` _macOS_ + +Merges all windows into one window with multiple tabs when native tabs +are enabled and there is more than one open window. + +#### `win.moveTabToNewWindow()` _macOS_ + +Moves the current tab into a new window if native tabs are enabled and +there is more than one tab in the current window. + +#### `win.toggleTabBar()` _macOS_ + +Toggles the visibility of the tab bar if native tabs are enabled and +there is only one tab in the current window. + #### `win.setVibrancy(type)` _macOS_ * `type` String - Can be `appearance-based`, `light`, `dark`, `titlebar`, diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 6e19bb62e5dd..1d3075022eb2 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -649,6 +649,66 @@ describe('BrowserWindow module', function () { }) }) + describe('BrowserWindow.selectPreviousTab()', () => { + it('does not throw', () => { + if (process.platform !== 'darwin') { + return + } + + assert.doesNotThrow(() => { + w.selectPreviousTab() + }) + }) + }) + + describe('BrowserWindow.selectNextTab()', () => { + it('does not throw', () => { + if (process.platform !== 'darwin') { + return + } + + assert.doesNotThrow(() => { + w.selectNextTab() + }) + }) + }) + + describe('BrowserWindow.mergeAllWindows()', () => { + it('does not throw', () => { + if (process.platform !== 'darwin') { + return + } + + assert.doesNotThrow(() => { + w.mergeAllWindows() + }) + }) + }) + + describe('BrowserWindow.moveTabToNewWindow()', () => { + it('does not throw', () => { + if (process.platform !== 'darwin') { + return + } + + assert.doesNotThrow(() => { + w.moveTabToNewWindow() + }) + }) + }) + + describe('BrowserWindow.toggleTabBar()', () => { + it('does not throw', () => { + if (process.platform !== 'darwin') { + return + } + + assert.doesNotThrow(() => { + w.toggleTabBar() + }) + }) + }) + describe('BrowserWindow.setVibrancy(type)', function () { it('allows setting, changing, and removing the vibrancy', function () { assert.doesNotThrow(function () {