Skip to content

Commit

Permalink
[iOS] Enable edit button when no active but inactive tabs
Browse files Browse the repository at this point in the history
When a user is in the regular tab grid, the "Close All" option should be
available if there is inactive tab to close even if there is no actives.
This CL add dynamic update to the Edit button in the following scenario:
* When the regular tab grid is empty but there is inactive tabs then
"Edit" button is available and only have "Close All" options
See video:
https://drive.google.com/file/d/1yDpOQjaMNaqyLbCOTlFTT68ctFWZHpMl/view?usp=share_link
* When there is no active nor inactive then "Edit" is not available
See screenshot:
https://drive.google.com/file/d/1U_6s-UQBYjYZgte_6GbN0rukRz29qAGC/view?usp=share_link
* For incognito, the "Edit" button should behave as before
See video:
https://drive.google.com/file/d/1Z7EJnpHT4X9G8KcrtrYursPPcfj0MGDC/view?usp=share_link

(cherry picked from commit 9bee1ec)

Fixed: 1434217
Change-Id: I8e14eff68554f1252647f67f685339fc6e46b467
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4481598
Reviewed-by: Louis Romero <lpromero@google.com>
Reviewed-by: Gauthier Ambard <gambard@chromium.org>
Commit-Queue: Aliona Dangla <alionadangla@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1137170}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4498428
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Auto-Submit: Aliona Dangla <alionadangla@chromium.org>
Cr-Commit-Position: refs/branch-heads/5735@{chromium#145}
Cr-Branched-From: 2f562e4-refs/heads/main@{#1135570}
  • Loading branch information
adangla authored and Chromium LUCI CQ committed May 2, 2023
1 parent 621d5f2 commit 9649237
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
@property(nonatomic, strong) UIView<GridEmptyView>* emptyStateView;
// Returns YES if the grid has no items.
@property(nonatomic, readonly, getter=isGridEmpty) BOOL gridEmpty;
// Returns YES if the inactive grid has no items.
@property(nonatomic, readonly, getter=isInactiveGridEmpty)
BOOL inactiveGridEmpty;
// The visual look of the grid.
@property(nonatomic, assign) GridTheme theme;
// The current mode for the grid.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ - (BOOL)isGridEmpty {
return self.items.count == 0;
}

- (BOOL)isInactiveGridEmpty {
return self.inactiveTabsCount == 0;
}

// Returns the items whose associated cell is visible.
- (NSSet<TabSwitcherItem*>*)visibleGridItems {
NSArray<NSIndexPath*>* visibleItemsIndexPaths =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@ - (void)setCurrentPage:(TabGridPage)currentPage {
[self.pinnedTabsViewController pinnedTabsAvailable:pinnedTabsAvailable];
}
[self updateToolbarsAppearance];
[self setupEditButton];
// Make sure the current page becomes the first responder, so that it can
// register and handle key commands.
[self.currentPageViewController becomeFirstResponder];
Expand Down Expand Up @@ -1575,14 +1576,21 @@ - (void)setupEditButton API_AVAILABLE(ios(14.0)) {
ActionFactory* actionFactory = [[ActionFactory alloc]
initWithScenario:MenuScenarioHistogram::kTabGridEdit];
__weak TabGridViewController* weakSelf = self;
NSArray<UIMenuElement*>* menuElements = @[
[actionFactory actionToCloseAllTabsWithBlock:^{
[weakSelf closeAllButtonTapped:nil];
}],
[actionFactory actionToSelectTabsWithBlock:^{
[weakSelf selectTabsButtonTapped:nil];
}]
];
NSMutableArray<UIMenuElement*>* menuElements =
[@[ [actionFactory actionToCloseAllTabsWithBlock:^{
[weakSelf closeAllButtonTapped:nil];
}] ] mutableCopy];
// Disable the "Select All" option from the edit button when there is no tabs
// in the regular tab grid. "Close All" can still be called if there is
// element in inactive tabs.
BOOL disabledSelectAll = self.currentPage == TabGridPageRegularTabs &&
self.regularTabsViewController.isGridEmpty;
if (!disabledSelectAll) {
[menuElements addObject:[actionFactory actionToSelectTabsWithBlock:^{
[weakSelf selectTabsButtonTapped:nil];
}]];
}

UIMenu* menu = [UIMenu menuWithChildren:menuElements];
[self.topToolbar setEditButtonMenu:menu];
[self.bottomToolbar setEditButtonMenu:menu];
Expand Down Expand Up @@ -1857,7 +1865,11 @@ - (void)configureCloseAllButtonForCurrentPageAndUndoAvailability {
GridViewController* gridViewController =
[self gridViewControllerForPage:self.currentPage];

BOOL enabled = gridViewController && ![gridViewController isGridEmpty];
// "Close all" can be called if there is element in regular tab grid or in
// inactive tabs.
BOOL enabled =
gridViewController && (![gridViewController isGridEmpty] ||
![gridViewController isInactiveGridEmpty]);
BOOL incognitoTabsNeedsAuth =
(self.currentPage == TabGridPageIncognitoTabs &&
self.incognitoTabsViewController.contentNeedsAuthentication);
Expand Down Expand Up @@ -2591,11 +2603,11 @@ - (void)gridViewController:(GridViewController*)gridViewController

crash_keys::SetRegularTabCount(totalTabCount);
[self handleTabCountChangeWithTabCount:totalTabCount];

} else if (gridViewController == self.incognitoTabsViewController) {
crash_keys::SetIncognitoTabCount(count);
[self handleTabCountChangeWithTabCount:count];
}
[self setupEditButton];
}

- (void)gridViewController:(GridViewController*)gridViewController
Expand Down Expand Up @@ -2775,7 +2787,8 @@ - (void)closeAllButtonTapped:(id)sender {

- (void)handleCloseAllButtonForRegularTabsWithAnchor:(UIBarButtonItem*)anchor {
DCHECK_EQ(self.undoCloseAllAvailable,
self.regularTabsViewController.gridEmpty);
(self.regularTabsViewController.gridEmpty &&
self.regularTabsViewController.inactiveGridEmpty));

if (self.undoCloseAllAvailable) {
[self undoCloseAllItemsForRegularTabs];
Expand Down

0 comments on commit 9649237

Please sign in to comment.