Skip to content

Commit

Permalink
[tab_grid] Hack-in new tab FAB action.
Browse files Browse the repository at this point in the history
BUG=686770

Review-Url: https://codereview.chromium.org/2699223003
Cr-Commit-Position: refs/heads/master@{#451910}
  • Loading branch information
edx246 authored and Commit bot committed Feb 22, 2017
1 parent a314137 commit 4f7222a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ios/clean/chrome/browser/ui/actions/tab_grid_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
3 changes: 3 additions & 0 deletions ios/clean/chrome/browser/ui/commands/tab_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<web::WebState> webState =
web::WebState::Create(webStateCreateParams);
_webStates.push_back(std::move(webState));
}

#pragma mark - TabGridCommands

- (void)showTabGrid {
Expand Down
13 changes: 13 additions & 0 deletions ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4f7222a

Please sign in to comment.