🍎 Add macOS native tab methods to window API

This commit is contained in:
Michael Kaylan 2017-08-21 00:46:10 -04:00
parent 796664ef1c
commit b4428e7e41
8 changed files with 179 additions and 0 deletions

View file

@ -907,6 +907,26 @@ void Window::SetAutoHideCursor(bool auto_hide) {
window_->SetAutoHideCursor(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) { void Window::SetVibrancy(mate::Arguments* args) {
std::string type; std::string type;
@ -1047,6 +1067,11 @@ void Window::BuildPrototype(v8::Isolate* isolate,
&Window::IsVisibleOnAllWorkspaces) &Window::IsVisibleOnAllWorkspaces)
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
.SetMethod("setAutoHideCursor", &Window::SetAutoHideCursor) .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 #endif
.SetMethod("setVibrancy", &Window::SetVibrancy) .SetMethod("setVibrancy", &Window::SetVibrancy)
.SetMethod("_setTouchBarItems", &Window::SetTouchBar) .SetMethod("_setTouchBarItems", &Window::SetTouchBar)

View file

@ -212,6 +212,12 @@ class Window : public mate::TrackableObject<Window>,
void SetAutoHideCursor(bool auto_hide); void SetAutoHideCursor(bool auto_hide);
void SelectPreviousTab();
void SelectNextTab();
void MergeAllWindows();
void MoveTabToNewWindow();
void ToggleTabBar();
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);
void RefreshTouchBarItem(const std::string& item_id); void RefreshTouchBarItem(const std::string& item_id);

View file

@ -336,6 +336,21 @@ void NativeWindow::SetParentWindow(NativeWindow* parent) {
void NativeWindow::SetAutoHideCursor(bool auto_hide) { 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) { void NativeWindow::SetVibrancy(const std::string& filename) {
} }

View file

@ -182,6 +182,13 @@ class NativeWindow : public base::SupportsUserData,
virtual void RefreshTouchBarItem(const std::string& item_id); virtual void RefreshTouchBarItem(const std::string& item_id);
virtual void SetEscapeTouchBarItem(const mate::PersistentDictionary& item); 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. // Webview APIs.
virtual void FocusOnWebView(); virtual void FocusOnWebView();
virtual void BlurWebView(); virtual void BlurWebView();

View file

@ -101,6 +101,12 @@ class NativeWindowMac : public NativeWindow,
void SetAutoHideCursor(bool auto_hide) override; 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 SetVibrancy(const std::string& type) override;
void SetTouchBar( void SetTouchBar(
const std::vector<mate::PersistentDictionary>& items) override; const std::vector<mate::PersistentDictionary>& items) override;

View file

@ -469,6 +469,11 @@ enum {
@interface NSWindow (SierraSDK) @interface NSWindow (SierraSDK)
- (void)setTabbingMode:(NSInteger)mode; - (void)setTabbingMode:(NSInteger)mode;
- (void)setTabbingIdentifier:(NSString*)identifier; - (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 @end
#endif // MAC_OS_X_VERSION_10_12 #endif // MAC_OS_X_VERSION_10_12
@ -1523,6 +1528,36 @@ void NativeWindowMac::SetAutoHideCursor(bool auto_hide) {
[window_ setDisableAutoHideCursor:!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) { void NativeWindowMac::SetVibrancy(const std::string& type) {
if (!base::mac::IsAtLeastOS10_10()) return; if (!base::mac::IsAtLeastOS10_10()) return;

View file

@ -1357,6 +1357,31 @@ Returns `BrowserWindow[]` - All child windows.
Controls whether to hide cursor when typing. 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_ #### `win.setVibrancy(type)` _macOS_
* `type` String - Can be `appearance-based`, `light`, `dark`, `titlebar`, * `type` String - Can be `appearance-based`, `light`, `dark`, `titlebar`,

View file

@ -648,6 +648,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 () { 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 () {