Commit 2c670dc8 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Keyboard shortcuts in tab grid

This CL adds keyboard shortcuts related to opening tabs to the tab grid.
- Command + n = open new (regular) tab
- Command + Shift + n = open new incognito tab
- Command + t = open new tab in current window

Bug: 818451
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Iae029bf53f5a2d71c2fe569b6481ee9eeec98ef0
Reviewed-on: https://chromium-review.googlesource.com/1116257
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570805}
parent 61c9e430
...@@ -789,6 +789,39 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -789,6 +789,39 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
} }
} }
// Tells the appropriate delegate to create a new item, and then tells the
// presentation delegate to show the new item.
- (void)openNewTabInPage:(TabGridPage)page {
switch (page) {
case TabGridPageIncognitoTabs:
[self.incognitoTabsDelegate addNewItem];
break;
case TabGridPageRegularTabs:
[self.regularTabsDelegate addNewItem];
break;
case TabGridPageRemoteTabs:
// This is intended as NO-OP since the user can ⌘-t while on this page.
break;
}
self.activePage = page;
[self.tabPresentationDelegate showActiveTabInPage:page];
}
// Creates and shows a new regular tab.
- (void)openNewRegularTab {
[self openNewTabInPage:TabGridPageRegularTabs];
}
// Creates and shows a new incognito tab.
- (void)openNewIncognitoTab {
[self openNewTabInPage:TabGridPageIncognitoTabs];
}
// Creates and shows a new tab in the current page.
- (void)openNewTabInCurrentPage {
[self openNewTabInPage:self.currentPage];
}
#pragma mark - GridViewControllerDelegate #pragma mark - GridViewControllerDelegate
- (void)gridViewController:(GridViewController*)gridViewController - (void)gridViewController:(GridViewController*)gridViewController
...@@ -878,19 +911,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -878,19 +911,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
} }
- (void)newTabButtonTapped:(id)sender { - (void)newTabButtonTapped:(id)sender {
switch (self.currentPage) { [self openNewTabInCurrentPage];
case TabGridPageIncognitoTabs:
[self.incognitoTabsDelegate addNewItem];
break;
case TabGridPageRegularTabs:
[self.regularTabsDelegate addNewItem];
break;
case TabGridPageRemoteTabs:
NOTREACHED() << "It is invalid to call insert new tab on remote tabs.";
break;
}
self.activePage = self.currentPage;
[self.tabPresentationDelegate showActiveTabInPage:self.currentPage];
// Record only when a new tab is created through the + button. // Record only when a new tab is created through the + button.
base::RecordAction(base::UserMetricsAction("MobileToolbarStackViewNewTab")); base::RecordAction(base::UserMetricsAction("MobileToolbarStackViewNewTab"));
} }
...@@ -920,4 +941,28 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -920,4 +941,28 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
[self recordActionSwitchingToPage:newPage]; [self recordActionSwitchingToPage:newPage];
} }
#pragma mark - UIResponder
- (NSArray*)keyCommands {
UIKeyCommand* newWindowShortcut =
[UIKeyCommand keyCommandWithInput:@"n"
modifierFlags:UIKeyModifierCommand
action:@selector(openNewRegularTab)
discoverabilityTitle:l10n_util::GetNSStringWithFixup(
IDS_IOS_TOOLS_MENU_NEW_TAB)];
UIKeyCommand* newIncognitoWindowShortcut = [UIKeyCommand
keyCommandWithInput:@"n"
modifierFlags:UIKeyModifierCommand | UIKeyModifierShift
action:@selector(openNewIncognitoTab)
discoverabilityTitle:l10n_util::GetNSStringWithFixup(
IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB)];
UIKeyCommand* newTabShortcut =
[UIKeyCommand keyCommandWithInput:@"t"
modifierFlags:UIKeyModifierCommand
action:@selector(openNewTabInCurrentPage)
discoverabilityTitle:l10n_util::GetNSStringWithFixup(
IDS_IOS_TOOLS_MENU_NEW_TAB)];
return @[ newWindowShortcut, newIncognitoWindowShortcut, newTabShortcut ];
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment