Commit a8f31fb6 authored by Ewann's avatar Ewann Committed by Commit Bot

[iOS] Fixes issues related to the Close All Tabs Confirmation feature

-On iPad, the actionSheetCoordinator is now anchored to to the "Close All"
button.
-The actionSheetCoordinator is also dismissed when tapping on the
screen.
- The actionSheetCoordinator is now stopped in
-stopChildCoordinatorsWithCompletion:


Bug: 1133304, 1135511
Change-Id: Id780844b7d42b4194e6f750859552ec9ff8b6793
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450279Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Ewann Pellé <ewannpv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815185}
parent de7a1127
......@@ -5,7 +5,7 @@
#ifndef IOS_CHROME_BROWSER_UI_TAB_GRID_GRID_GRID_COMMANDS_H_
#define IOS_CHROME_BROWSER_UI_TAB_GRID_GRID_GRID_COMMANDS_H_
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
// Commands issued to a model backing a grid UI.
@protocol GridCommands
......@@ -35,9 +35,10 @@
// Tells the receiver to discard saved closed items. If the consumer has saved
// closed items, it will discard them. Otherwise, this is a no-op.
- (void)discardSavedClosedItems;
// Shows an action sheet that asks for confirmation when 'Close All' button is
// tapped.
- (void)showCloseAllConfirmationActionSheet;
// Shows an action sheet, anchored to the UIBarButtonItem, that asks for
// confirmation when 'Close All' button is tapped.
- (void)showCloseAllConfirmationActionSheetWithAnchor:
(UIBarButtonItem*)buttonAnchor;
@end
#endif // IOS_CHROME_BROWSER_UI_TAB_GRID_GRID_GRID_COMMANDS_H_
......@@ -148,6 +148,7 @@
- (void)stopChildCoordinatorsWithCompletion:(ProceduralBlock)completion {
// Recent tabs context menu may be presented on top of the tab grid.
[self.baseViewController.remoteTabsViewController dismissModals];
[self.actionSheetCoordinator stop];
// History may be presented on top of the tab grid.
if (self.historyCoordinator) {
[self.historyCoordinator stopWithCompletion:completion];
......@@ -421,7 +422,9 @@
- (void)showCloseAllConfirmationActionSheetWitTabGridMediator:
(TabGridMediator*)tabGridMediator
numberOfTabs:
(NSInteger)numberOfTabs {
(NSInteger)numberOfTabs
anchor:(UIBarButtonItem*)
buttonAnchor {
if (tabGridMediator == self.regularTabsMediator) {
base::RecordAction(base::UserMetricsAction(
"MobileTabGridCloseAllRegularTabsConfirmationPresented"));
......@@ -435,19 +438,9 @@
browser:self.browser
title:nil
message:nil
rect:self.baseViewController.view.frame
view:self.baseViewController.view];
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
barButtonItem:buttonAnchor];
self.actionSheetCoordinator.popoverArrowDirection = 0;
self.actionSheetCoordinator.alertStyle =
IsIPadIdiom() ? UIAlertControllerStyleAlert
: UIAlertControllerStyleActionSheet;
self.actionSheetCoordinator.alertStyle = UIAlertControllerStyleActionSheet;
[self.actionSheetCoordinator
addItemWithTitle:base::SysUTF16ToNSString(
......@@ -496,12 +489,6 @@
focusOmnibox:NO];
}
#pragma mark - Notification callback
- (void)applicationDidEnterBackground:(NSNotification*)notification {
[self.actionSheetCoordinator stop];
}
#pragma mark - HistoryPresentationDelegate
- (void)showActiveRegularTabFromHistory {
......
......@@ -23,12 +23,14 @@ class TabRestoreService;
// for confirmation from the tab grid.
@protocol TabGridMediatorDelegate <NSObject>
// Shows an action sheet that asks for confirmation when 'Close All' button is
// tapped.
// Shows an action sheet, anchored to the UIBarButtonItem, that asks for
// confirmation when 'Close All' button is tapped.
- (void)showCloseAllConfirmationActionSheetWitTabGridMediator:
(TabGridMediator*)tabGridMediator
numberOfTabs:
(NSInteger)numberOfTabs;
(NSInteger)numberOfTabs
anchor:(UIBarButtonItem*)
buttonAnchor;
@end
......
......@@ -366,11 +366,13 @@ web::WebState* GetWebStateWithId(WebStateList* web_state_list,
SnapshotBrowserAgent::FromBrowser(self.browser)->RemoveAllSnapshots();
}
- (void)showCloseAllConfirmationActionSheet {
- (void)showCloseAllConfirmationActionSheetWithAnchor:
(UIBarButtonItem*)buttonAnchor {
[self.delegate
showCloseAllConfirmationActionSheetWitTabGridMediator:self
numberOfTabs:self.webStateList
->count()];
->count()
anchor:buttonAnchor];
}
#pragma mark GridCommands helpers
......
......@@ -1246,13 +1246,15 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
// Shows an action sheet that asks for confirmation when 'Close All' button is
// tapped.
- (void)closeAllButtonTappedShowConfirmation:(id)sender {
- (void)closeAllButtonTappedShowConfirmation:(UIBarButtonItem*)button {
switch (self.currentPage) {
case TabGridPageIncognitoTabs:
[self.incognitoTabsDelegate showCloseAllConfirmationActionSheet];
[self.incognitoTabsDelegate
showCloseAllConfirmationActionSheetWithAnchor:button];
break;
case TabGridPageRegularTabs:
[self.regularTabsDelegate showCloseAllConfirmationActionSheet];
[self.regularTabsDelegate
showCloseAllConfirmationActionSheetWithAnchor:button];
break;
case TabGridPageRemoteTabs:
NOTREACHED() << "It is invalid to call close all tabs on remote tabs.";
......
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