diff --git a/ios/clean/chrome/browser/ui/actions/tab_grid_actions.h b/ios/clean/chrome/browser/ui/actions/tab_grid_actions.h index a9ebbcc68aa775..280a4451e2e668 100644 --- a/ios/clean/chrome/browser/ui/actions/tab_grid_actions.h +++ b/ios/clean/chrome/browser/ui/actions/tab_grid_actions.h @@ -18,6 +18,9 @@ @optional // Dismisses whatever UI is currently active and shows the tab grid. - (void)showTabGrid:(id)sender; + +// Create new tab and display. +- (void)createNewTab:(id)sender; @end #endif // IOS_CLEAN_CHROME_BROWSER_UI_ACTIONS_TAB_GRID_ACTIONS_H_ diff --git a/ios/clean/chrome/browser/ui/commands/tab_commands.h b/ios/clean/chrome/browser/ui/commands/tab_commands.h index 6094c6caac2c6c..fc578aa74054be 100644 --- a/ios/clean/chrome/browser/ui/commands/tab_commands.h +++ b/ios/clean/chrome/browser/ui/commands/tab_commands.h @@ -18,6 +18,9 @@ // Remove tab from the tab model(s) the receiver knows about. - (void)closeTabAtIndexPath:(NSIndexPath*)indexPath; + +// Create new tab in a tab model the receiver knows about. +- (void)createNewTabAtIndexPath:(NSIndexPath*)indexPath; @end #endif // IOS_CLEAN_CHROME_BROWSER_UI_COMMANDS_TAB_COMMANDS_H_ diff --git a/ios/clean/chrome/browser/ui/tab_grid/mdc_floating_button+cr_tab_grid.mm b/ios/clean/chrome/browser/ui/tab_grid/mdc_floating_button+cr_tab_grid.mm index 91f8724a3274f1..0138e67d25a45d 100644 --- a/ios/clean/chrome/browser/ui/tab_grid/mdc_floating_button+cr_tab_grid.mm +++ b/ios/clean/chrome/browser/ui/tab_grid/mdc_floating_button+cr_tab_grid.mm @@ -7,6 +7,7 @@ #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" #include "ios/chrome/browser/ui/rtl_geometry.h" #include "ios/chrome/grit/ios_strings.h" +#import "ios/clean/chrome/browser/ui/actions/tab_grid_actions.h" #import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h" #include "ui/base/l10n/l10n_util.h" @@ -42,6 +43,9 @@ + (instancetype)cr_tabGridNewTabButton { forState:UIControlStateDisabled]; [button setAccessibilityLabel:l10n_util::GetNSString( IDS_IOS_TAB_SWITCHER_CREATE_NEW_TAB)]; + [button addTarget:nil + action:@selector(createNewTab:) + forControlEvents:UIControlEventTouchUpInside]; } return button; } diff --git a/ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm b/ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm index 8fd156fa5e16cb..ce8e600a284e8c 100644 --- a/ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm +++ b/ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm @@ -114,6 +114,13 @@ - (void)closeTabAtIndexPath:(NSIndexPath*)indexPath { _webStates.erase(_webStates.begin() + index); } +- (void)createNewTabAtIndexPath:(NSIndexPath*)indexPath { + web::WebState::CreateParams webStateCreateParams(self.browserState); + std::unique_ptr webState = + web::WebState::Create(webStateCreateParams); + _webStates.push_back(std::move(webState)); +} + #pragma mark - TabGridCommands - (void)showTabGrid { diff --git a/ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm b/ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm index 6296bbe1925abe..7c365fbcb7998a 100644 --- a/ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm +++ b/ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm @@ -145,6 +145,19 @@ - (void)showTabGrid:(id)sender { [self.tabGridCommandHandler showTabGrid]; } +- (void)createNewTab:(id)sender { + // PLACEHOLDER: The new WebStateList data structure will have implications + // on how new tabs are created. + NSInteger index = [self.grid numberOfItemsInSection:0]; + NSIndexPath* indexPath = [NSIndexPath indexPathForItem:index inSection:0]; + auto updateBlock = ^{ + [self.tabCommandHandler createNewTabAtIndexPath:indexPath]; + [self.tabCommandHandler showTabAtIndexPath:indexPath]; + [self.grid insertItemsAtIndexPaths:@[ indexPath ]]; + }; + [self.grid performBatchUpdates:updateBlock completion:nil]; +} + #pragma mark - SessionCellDelegate - (TabSwitcherCache*)tabSwitcherCache {