Skip to content

Commit 10ab870

Browse files
authored
Merge pull request electron#10321 from kaylanm/macos-native-tab-api
🍎 Add macOS native tab methods to window API
2 parents cc9771a + b4428e7 commit 10ab870

File tree

8 files changed

+179
-0
lines changed

8 files changed

+179
-0
lines changed

atom/browser/api/atom_api_window.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,26 @@ void Window::SetAutoHideCursor(bool auto_hide) {
910910
window_->SetAutoHideCursor(auto_hide);
911911
}
912912

913+
void Window::SelectPreviousTab() {
914+
window_->SelectPreviousTab();
915+
}
916+
917+
void Window::SelectNextTab() {
918+
window_->SelectNextTab();
919+
}
920+
921+
void Window::MergeAllWindows() {
922+
window_->MergeAllWindows();
923+
}
924+
925+
void Window::MoveTabToNewWindow() {
926+
window_->MoveTabToNewWindow();
927+
}
928+
929+
void Window::ToggleTabBar() {
930+
window_->ToggleTabBar();
931+
}
932+
913933
void Window::SetVibrancy(mate::Arguments* args) {
914934
std::string type;
915935

@@ -1050,6 +1070,11 @@ void Window::BuildPrototype(v8::Isolate* isolate,
10501070
&Window::IsVisibleOnAllWorkspaces)
10511071
#if defined(OS_MACOSX)
10521072
.SetMethod("setAutoHideCursor", &Window::SetAutoHideCursor)
1073+
.SetMethod("mergeAllWindows", &Window::MergeAllWindows)
1074+
.SetMethod("selectPreviousTab", &Window::SelectPreviousTab)
1075+
.SetMethod("selectNextTab", &Window::SelectNextTab)
1076+
.SetMethod("moveTabToNewWindow", &Window::MoveTabToNewWindow)
1077+
.SetMethod("toggleTabBar", &Window::ToggleTabBar)
10531078
#endif
10541079
.SetMethod("setVibrancy", &Window::SetVibrancy)
10551080
.SetMethod("_setTouchBarItems", &Window::SetTouchBar)

atom/browser/api/atom_api_window.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ class Window : public mate::TrackableObject<Window>,
212212

213213
void SetAutoHideCursor(bool auto_hide);
214214

215+
void SelectPreviousTab();
216+
void SelectNextTab();
217+
void MergeAllWindows();
218+
void MoveTabToNewWindow();
219+
void ToggleTabBar();
220+
215221
void SetVibrancy(mate::Arguments* args);
216222
void SetTouchBar(const std::vector<mate::PersistentDictionary>& items);
217223
void RefreshTouchBarItem(const std::string& item_id);

atom/browser/native_window.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,21 @@ void NativeWindow::SetParentWindow(NativeWindow* parent) {
336336
void NativeWindow::SetAutoHideCursor(bool auto_hide) {
337337
}
338338

339+
void NativeWindow::SelectPreviousTab() {
340+
}
341+
342+
void NativeWindow::SelectNextTab() {
343+
}
344+
345+
void NativeWindow::MergeAllWindows() {
346+
}
347+
348+
void NativeWindow::MoveTabToNewWindow() {
349+
}
350+
351+
void NativeWindow::ToggleTabBar() {
352+
}
353+
339354
void NativeWindow::SetVibrancy(const std::string& filename) {
340355
}
341356

atom/browser/native_window.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ class NativeWindow : public base::SupportsUserData,
182182
virtual void RefreshTouchBarItem(const std::string& item_id);
183183
virtual void SetEscapeTouchBarItem(const mate::PersistentDictionary& item);
184184

185+
// Native Tab API
186+
virtual void SelectPreviousTab();
187+
virtual void SelectNextTab();
188+
virtual void MergeAllWindows();
189+
virtual void MoveTabToNewWindow();
190+
virtual void ToggleTabBar();
191+
185192
// Webview APIs.
186193
virtual void FocusOnWebView();
187194
virtual void BlurWebView();

atom/browser/native_window_mac.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ class NativeWindowMac : public NativeWindow,
101101

102102
void SetAutoHideCursor(bool auto_hide) override;
103103

104+
void SelectPreviousTab() override;
105+
void SelectNextTab() override;
106+
void MergeAllWindows() override;
107+
void MoveTabToNewWindow() override;
108+
void ToggleTabBar() override;
109+
104110
void SetVibrancy(const std::string& type) override;
105111
void SetTouchBar(
106112
const std::vector<mate::PersistentDictionary>& items) override;

atom/browser/native_window_mac.mm

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@ - (id)initWithURL:(NSURL*)url title:(NSString*)title {
469469
@interface NSWindow (SierraSDK)
470470
- (void)setTabbingMode:(NSInteger)mode;
471471
- (void)setTabbingIdentifier:(NSString*)identifier;
472+
- (IBAction)selectPreviousTab:(id)sender;
473+
- (IBAction)selectNextTab:(id)sender;
474+
- (IBAction)mergeAllWindows:(id)sender;
475+
- (IBAction)moveTabToNewWindow:(id)sender;
476+
- (IBAction)toggleTabBar:(id)sender;
472477
@end
473478

474479
#endif // MAC_OS_X_VERSION_10_12
@@ -1523,6 +1528,36 @@ static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
15231528
[window_ setDisableAutoHideCursor:!auto_hide];
15241529
}
15251530

1531+
void NativeWindowMac::SelectPreviousTab() {
1532+
if ([window_ respondsToSelector:@selector(selectPreviousTab:)]) {
1533+
[window_ selectPreviousTab:nil];
1534+
}
1535+
}
1536+
1537+
void NativeWindowMac::SelectNextTab() {
1538+
if ([window_ respondsToSelector:@selector(selectNextTab:)]) {
1539+
[window_ selectNextTab:nil];
1540+
}
1541+
}
1542+
1543+
void NativeWindowMac::MergeAllWindows() {
1544+
if ([window_ respondsToSelector:@selector(mergeAllWindows:)]) {
1545+
[window_ mergeAllWindows:nil];
1546+
}
1547+
}
1548+
1549+
void NativeWindowMac::MoveTabToNewWindow() {
1550+
if ([window_ respondsToSelector:@selector(moveTabToNewWindow:)]) {
1551+
[window_ moveTabToNewWindow:nil];
1552+
}
1553+
}
1554+
1555+
void NativeWindowMac::ToggleTabBar() {
1556+
if ([window_ respondsToSelector:@selector(toggleTabBar:)]) {
1557+
[window_ toggleTabBar:nil];
1558+
}
1559+
}
1560+
15261561
void NativeWindowMac::SetVibrancy(const std::string& type) {
15271562
if (!base::mac::IsAtLeastOS10_10()) return;
15281563

docs/api/browser-window.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,31 @@ Returns `BrowserWindow[]` - All child windows.
13631363

13641364
Controls whether to hide cursor when typing.
13651365

1366+
#### `win.selectPreviousTab()` _macOS_
1367+
1368+
Selects the previous tab when native tabs are enabled and there are other
1369+
tabs in the window.
1370+
1371+
#### `win.selectNextTab()` _macOS_
1372+
1373+
Selects the next tab when native tabs are enabled and there are other
1374+
tabs in the window.
1375+
1376+
#### `win.mergeAllWindows()` _macOS_
1377+
1378+
Merges all windows into one window with multiple tabs when native tabs
1379+
are enabled and there is more than one open window.
1380+
1381+
#### `win.moveTabToNewWindow()` _macOS_
1382+
1383+
Moves the current tab into a new window if native tabs are enabled and
1384+
there is more than one tab in the current window.
1385+
1386+
#### `win.toggleTabBar()` _macOS_
1387+
1388+
Toggles the visibility of the tab bar if native tabs are enabled and
1389+
there is only one tab in the current window.
1390+
13661391
#### `win.setVibrancy(type)` _macOS_
13671392

13681393
* `type` String - Can be `appearance-based`, `light`, `dark`, `titlebar`,

spec/api-browser-window-spec.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,66 @@ describe('BrowserWindow module', function () {
649649
})
650650
})
651651

652+
describe('BrowserWindow.selectPreviousTab()', () => {
653+
it('does not throw', () => {
654+
if (process.platform !== 'darwin') {
655+
return
656+
}
657+
658+
assert.doesNotThrow(() => {
659+
w.selectPreviousTab()
660+
})
661+
})
662+
})
663+
664+
describe('BrowserWindow.selectNextTab()', () => {
665+
it('does not throw', () => {
666+
if (process.platform !== 'darwin') {
667+
return
668+
}
669+
670+
assert.doesNotThrow(() => {
671+
w.selectNextTab()
672+
})
673+
})
674+
})
675+
676+
describe('BrowserWindow.mergeAllWindows()', () => {
677+
it('does not throw', () => {
678+
if (process.platform !== 'darwin') {
679+
return
680+
}
681+
682+
assert.doesNotThrow(() => {
683+
w.mergeAllWindows()
684+
})
685+
})
686+
})
687+
688+
describe('BrowserWindow.moveTabToNewWindow()', () => {
689+
it('does not throw', () => {
690+
if (process.platform !== 'darwin') {
691+
return
692+
}
693+
694+
assert.doesNotThrow(() => {
695+
w.moveTabToNewWindow()
696+
})
697+
})
698+
})
699+
700+
describe('BrowserWindow.toggleTabBar()', () => {
701+
it('does not throw', () => {
702+
if (process.platform !== 'darwin') {
703+
return
704+
}
705+
706+
assert.doesNotThrow(() => {
707+
w.toggleTabBar()
708+
})
709+
})
710+
})
711+
652712
describe('BrowserWindow.setVibrancy(type)', function () {
653713
it('allows setting, changing, and removing the vibrancy', function () {
654714
assert.doesNotThrow(function () {

0 commit comments

Comments
 (0)