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