Skip to content

Commit

Permalink
[iOS] Rename GridViewController in BaseGridViewController
Browse files Browse the repository at this point in the history
This CL renames the grid view controller as it will be the base code
for all grid view controller. As part of refactoring, each grid with
their own specificity will have their own specific file. So for example
incognito lock screen will be only in its own file and not in the same
shared files.

Low-Coverage-Reason: HARD_TO_TEST - Uncovered code lines are mostly "NOTREACHED()" or commentary "// No op.".
Bug: 1457146
Change-Id: Iea4a42ebab9f44ba33f7e3627403bc4345b09cf2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4952553
Commit-Queue: Aliona Dangla <alionadangla@chromium.org>
Reviewed-by: Louis Romero <lpromero@google.com>
Cr-Commit-Position: refs/heads/main@{#1214161}
  • Loading branch information
adangla authored and Chromium LUCI CQ committed Oct 24, 2023
1 parent a4fe003 commit 346bda7
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 145 deletions.
6 changes: 3 additions & 3 deletions ios/chrome/browser/ui/tab_switcher/tab_grid/grid/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ source_set("grid_ui") {
sources = [
"base_grid_container_view_controller.h",
"base_grid_container_view_controller.mm",
"base_grid_view_controller+private.h",
"base_grid_view_controller.h",
"base_grid_view_controller.mm",
"disabled_grid_view_controller.h",
"disabled_grid_view_controller.mm",
"grid_cell.h",
Expand All @@ -79,9 +82,6 @@ source_set("grid_ui") {
"grid_layout.mm",
"grid_shareable_items_provider.h",
"grid_theme.h",
"grid_view_controller+private.h",
"grid_view_controller.h",
"grid_view_controller.mm",
]

deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_GRID_VIEW_CONTROLLER_PRIVATE_H_
#define IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_GRID_VIEW_CONTROLLER_PRIVATE_H_
#ifndef IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_BASE_GRID_VIEW_CONTROLLER_PRIVATE_H_
#define IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_BASE_GRID_VIEW_CONTROLLER_PRIVATE_H_

#import <UIKit/UIKit.h>

@class TabSwitcherItem;

@interface GridViewController (Private)
@interface BaseGridViewController (Private)

@property(nonatomic, readonly) NSMutableArray<TabSwitcherItem*>* items;
@property(nonatomic, readonly) NSUInteger selectedIndex;
@property(nonatomic, readonly) UICollectionView* collectionView;

@end

#endif // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_GRID_VIEW_CONTROLLER_PRIVATE_H_
#endif // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_BASE_GRID_VIEW_CONTROLLER_PRIVATE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_GRID_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_GRID_VIEW_CONTROLLER_H_
#ifndef IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_BASE_GRID_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_BASE_GRID_VIEW_CONTROLLER_H_

#import <UIKit/UIKit.h>

Expand All @@ -20,7 +20,7 @@
@protocol GridEmptyView;
@protocol GridShareableItemsProvider;
@class LegacyGridTransitionLayout;
@class GridViewController;
@class BaseGridViewController;
@protocol IncognitoReauthCommands;
@protocol PriceCardDataSource;
@protocol SuggestedActionsDelegate;
Expand All @@ -33,73 +33,73 @@ class WebStateID;

// Tells the delegate that the item with `itemID` was selected in
// `gridViewController`.
- (void)gridViewController:(GridViewController*)gridViewController
- (void)gridViewController:(BaseGridViewController*)gridViewController
didSelectItemWithID:(web::WebStateID)itemID;
// Tells the delegate that the item with `itemID` was closed in
// `gridViewController`.
- (void)gridViewController:(GridViewController*)gridViewController
- (void)gridViewController:(BaseGridViewController*)gridViewController
didCloseItemWithID:(web::WebStateID)itemID;
// Tells the delegate that the item with `itemID` was moved to
// `destinationIndex`.
- (void)gridViewController:(GridViewController*)gridViewController
- (void)gridViewController:(BaseGridViewController*)gridViewController
didMoveItemWithID:(web::WebStateID)itemID
toIndex:(NSUInteger)destinationIndex;
// Tells the delegate that the the number of items in `gridViewController`
// changed to `count`.
- (void)gridViewController:(GridViewController*)gridViewController
- (void)gridViewController:(BaseGridViewController*)gridViewController
didChangeItemCount:(NSUInteger)count;
// Tells the delegate that the item with `itemID` was removed.
- (void)gridViewController:(GridViewController*)gridViewController
- (void)gridViewController:(BaseGridViewController*)gridViewController
didRemoveItemWIthID:(web::WebStateID)itemID;

// Tells the delegate that the visibility of the last item of the grid changed.
- (void)didChangeLastItemVisibilityInGridViewController:
(GridViewController*)gridViewController;
(BaseGridViewController*)gridViewController;

// Tells the delegate when the currently displayed content is hidden from the
// user until they authenticate. Used for incognito biometric authentication.
- (void)gridViewController:(GridViewController*)gridViewController
- (void)gridViewController:(BaseGridViewController*)gridViewController
contentNeedsAuthenticationChanged:(BOOL)needsAuth;

// Tells the delegate that the grid view controller's scroll view will begin
// dragging.
- (void)gridViewControllerWillBeginDragging:
(GridViewController*)gridViewController;
(BaseGridViewController*)gridViewController;
// Tells the delegate that the grid view controller cells will begin dragging.
- (void)gridViewControllerDragSessionWillBegin:
(GridViewController*)gridViewController;
(BaseGridViewController*)gridViewController;
// Tells the delegate that the grid view controller cells did end dragging.
- (void)gridViewControllerDragSessionDidEnd:
(GridViewController*)gridViewController;
(BaseGridViewController*)gridViewController;
// Tells the delegate that the grid view controller did scroll.
- (void)gridViewControllerScrollViewDidScroll:
(GridViewController*)gridViewController;
(BaseGridViewController*)gridViewController;

// Tells the delegate that a drop animation will begin.
- (void)gridViewControllerDropAnimationWillBegin:
(GridViewController*)gridViewController;
(BaseGridViewController*)gridViewController;
// Tells the delegate that a drop animation did end.
- (void)gridViewControllerDropAnimationDidEnd:
(GridViewController*)gridViewController;
(BaseGridViewController*)gridViewController;

// Tells the delegate that the inactive tabs button was tapped in
// `gridViewController`, i.e., there was an intention to show inactive tabs (in
// TabGridModeNormal).
- (void)didTapInactiveTabsButtonInGridViewController:
(GridViewController*)gridViewController;
(BaseGridViewController*)gridViewController;

// Tells the delegate that the inactive tabs settings link was tapped in
// `gridViewController`, i.e., there was an intention to show inactive tabs
// settings (in TabGridModeInactive).
- (void)didTapInactiveTabsSettingsLinkInGridViewController:
(GridViewController*)gridViewController;
(BaseGridViewController*)gridViewController;

@end

// A view controller that contains a grid of items.
@interface GridViewController : UIViewController <InactiveTabsInfoConsumer,
IncognitoReauthConsumer,
TabCollectionConsumer>
@interface BaseGridViewController : UIViewController <InactiveTabsInfoConsumer,
IncognitoReauthConsumer,
TabCollectionConsumer>
// The gridView is accessible to manage the content inset behavior.
@property(nonatomic, readonly) UIScrollView* gridView;
// The view that is shown when there are no items.
Expand Down Expand Up @@ -180,4 +180,4 @@ class WebStateID;

@end

#endif // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_GRID_VIEW_CONTROLLER_H_
#endif // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_BASE_GRID_VIEW_CONTROLLER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_view_controller.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/base_grid_view_controller.h"

#import "base/apple/foundation_util.h"
#import "base/check_op.h"
Expand All @@ -26,14 +26,14 @@
#import "ios/chrome/browser/ui/menu/menu_histograms.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_collection_drag_drop_handler.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_collection_drag_drop_metrics.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/base_grid_view_controller+private.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_cell.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_constants.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_empty_view.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_header.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_item_identifier.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_layout.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_shareable_items_provider.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_view_controller+private.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/inactive_tabs/inactive_tabs_button_ui_swift.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/inactive_tabs/inactive_tabs_preamble_header.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/suggested_actions/suggested_actions_delegate.h"
Expand Down Expand Up @@ -98,13 +98,13 @@
DiffableDataSource;
typedef NSDiffableDataSourceSnapshot<NSString*, GridItemIdentifier*> Snapshot;

@interface GridViewController () <GridCellDelegate,
SuggestedActionsViewControllerDelegate,
UICollectionViewDelegate,
UICollectionViewDelegateFlowLayout,
UICollectionViewDragDelegate,
UICollectionViewDropDelegate,
UIPointerInteractionDelegate>
@interface BaseGridViewController () <GridCellDelegate,
SuggestedActionsViewControllerDelegate,
UICollectionViewDelegate,
UICollectionViewDelegateFlowLayout,
UICollectionViewDragDelegate,
UICollectionViewDropDelegate,
UIPointerInteractionDelegate>
// A collection view of items in a grid format.
@property(nonatomic, weak) UICollectionView* collectionView;
// The collection view's data source.
Expand Down Expand Up @@ -175,7 +175,7 @@ @interface GridViewController () <GridCellDelegate,
@property(nonatomic) BOOL isClosingAllOrUndoRunning;
@end

@implementation GridViewController {
@implementation BaseGridViewController {
// Tracks when the grid view is scrolling. Create a new instance to start
// timing and reset to stop and log the associated time histogram.
absl::optional<ScopedScrollingTimeLogger> _scopedScrollingTimeLogger;
Expand Down Expand Up @@ -316,8 +316,9 @@ - (UIScrollView*)gridView {
}

- (void)setEmptyStateView:(UIView<GridEmptyView>*)emptyStateView {
if (_emptyStateView)
if (_emptyStateView) {
[_emptyStateView removeFromSuperview];
}
_emptyStateView = emptyStateView;
emptyStateView.scrollViewContentInsets =
self.collectionView.adjustedContentInset;
Expand Down Expand Up @@ -424,8 +425,9 @@ - (BOOL)isSelectedCellVisible {
// The collection view's selected item may not have updated yet, so use the
// selected index.
NSUInteger selectedIndex = self.selectedIndex;
if (selectedIndex == NSNotFound)
if (selectedIndex == NSNotFound) {
return NO;
}
NSIndexPath* selectedIndexPath = CreateIndexPath(selectedIndex);
return [self.collectionView.indexPathsForVisibleItems
containsObject:selectedIndexPath];
Expand All @@ -438,8 +440,9 @@ - (LegacyGridTransitionLayout*)transitionLayout {
LegacyGridTransitionActiveItem* activeItem;
LegacyGridTransitionItem* selectionItem;
for (NSIndexPath* path in self.collectionView.indexPathsForVisibleItems) {
if (path.section != kOpenTabsSectionIndex)
if (path.section != kOpenTabsSectionIndex) {
continue;
}
GridCell* cell = ObjCCastStrict<GridCell>(
[self.collectionView cellForItemAtIndexPath:path]);
UICollectionViewLayoutAttributes* attributes =
Expand Down Expand Up @@ -1275,8 +1278,9 @@ - (void)populateItems:(NSArray<TabSwitcherItem*>*)items
// Whether the view is visible or not, the delegate must be updated.
[self.delegate gridViewController:self didChangeItemCount:self.items.count];
if (_mode == TabGridModeSearch) {
if (_searchText.length)
if (_searchText.length) {
[self updateSearchResultsHeader];
}
[self.collectionView
setContentOffset:CGPointMake(
-self.collectionView.adjustedContentInset.left,
Expand Down Expand Up @@ -1803,8 +1807,9 @@ - (void)tappedItemAtIndexPath:(NSIndexPath*)indexPath {
// Speculative fix for crbug.com/1134663, where this method is called while
// updates from a tab insertion are processing.
// *** Do not add any code before this check. ***
if (self.updating)
if (self.updating) {
return;
}

NSUInteger index = base::checked_cast<NSUInteger>(indexPath.item);
DCHECK_LT(index, self.items.count);
Expand All @@ -1813,8 +1818,9 @@ - (void)tappedItemAtIndexPath:(NSIndexPath*)indexPath {
// might be a case of the UI sending touch events after the model has updated.
// In this case, just no-op; if the user has to tap again to activate a tab,
// that's better than a crash.
if (index >= self.items.count)
if (index >= self.items.count) {
return;
}

web::WebStateID itemID = self.items[index].identifier;
if (_mode == TabGridModeSelection) {
Expand Down Expand Up @@ -1885,8 +1891,9 @@ - (void)updateVisibleCellIdentifiers {
.indexPathsForVisibleItems) {
UICollectionViewCell* cell =
[self.collectionView cellForItemAtIndexPath:indexPath];
if (![cell isKindOfClass:[GridCell class]])
if (![cell isKindOfClass:[GridCell class]]) {
continue;
}
NSUInteger itemIndex = base::checked_cast<NSUInteger>(indexPath.item);
cell.accessibilityIdentifier = GridCellAccessibilityIdentifier(itemIndex);
}
Expand All @@ -1907,8 +1914,9 @@ - (void)updateSearchResultsHeader {
[NSIndexPath
indexPathForRow:0
inSection:kOpenTabsSectionIndex]];
if (!headerView)
if (!headerView) {
return;
}
NSString* resultsCount = [@(self.items.count) stringValue];
headerView.value =
l10n_util::GetNSStringF(IDS_IOS_TABS_SEARCH_OPEN_TABS_COUNT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#import "ios/chrome/browser/ui/tab_switcher/tab_grid/tab_collection_commands.h"

@class GridViewController;
namespace web {
class WebStateID;
} // namespace web
Expand Down
Loading

0 comments on commit 346bda7

Please sign in to comment.