Commit 34992965 authored by Nazerke's avatar Nazerke Committed by Commit Bot

[ios] Refactoring the GridItem.

This CL is renaming the GridItem to be the TabSwitcherItem to make it
usable by the TabStrip as well as by the TabGrid.

Bug: 1128249
Change-Id: Ic7736156f9cff5b6218261ce29f047b37b37253f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536435Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Cr-Commit-Position: refs/heads/master@{#827832}
parent 62fe3e0e
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//ios/public/provider/chrome/browser/build_config.gni")
source_set("tab_switcher") {
sources = [
"tab_switcher_item.h",
"tab_switcher_item.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
deps = [
"//base",
]
}
......@@ -45,6 +45,7 @@ source_set("tab_grid") {
"//ios/chrome/browser/ui/recent_tabs",
"//ios/chrome/browser/ui/recent_tabs:recent_tabs_ui",
"//ios/chrome/browser/ui/sharing",
"//ios/chrome/browser/ui/tab_switcher",
"//ios/chrome/browser/ui/tab_switcher/tab_grid/transitions",
"//ios/chrome/browser/ui/thumb_strip",
"//ios/chrome/browser/ui/thumb_strip:feature_flags",
......@@ -163,6 +164,7 @@ source_set("unit_tests") {
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/tabs:tabs_internal",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/tab_switcher",
"//ios/chrome/browser/web",
"//ios/chrome/browser/web:page_placeholder",
"//ios/chrome/browser/web:test_support",
......
......@@ -23,8 +23,6 @@ source_set("grid_ui") {
"grid_drag_drop_handler.h",
"grid_empty_view.h",
"grid_image_data_source.h",
"grid_item.h",
"grid_item.mm",
"grid_layout.h",
"grid_layout.mm",
"grid_theme.h",
......@@ -55,6 +53,7 @@ source_set("grid_ui") {
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/gestures",
"//ios/chrome/browser/ui/tab_switcher",
"//ios/chrome/browser/ui/tab_switcher/tab_grid/transitions",
"//ios/chrome/browser/ui/thumb_strip:feature_flags",
"//ios/chrome/browser/ui/util",
......@@ -75,6 +74,7 @@ source_set("unit_tests") {
":grid_ui",
"//base",
"//base/test:test_support",
"//ios/chrome/browser/ui/tab_switcher",
"//ios/chrome/test:test_support",
"//testing/gtest",
]
......
......@@ -7,7 +7,7 @@
#import <Foundation/Foundation.h>
@class GridItem;
@class TabSwitcherItem;
// Supports idempotent insert/delete/updates to a grid.
@protocol GridConsumer
......@@ -22,13 +22,13 @@
// Tells the consumer to replace its current set of items with |items| and
// update the selected item ID to be |selectedItemID|. It's an error to pass
// an |items| array containing items without unique IDs.
- (void)populateItems:(NSArray<GridItem*>*)items
- (void)populateItems:(NSArray<TabSwitcherItem*>*)items
selectedItemID:(NSString*)selectedItemID;
// Tells the consumer to insert |item| at |index| and update the selected item
// ID to be |selectedItemID|. It's an error if |item|'s ID duplicates an
// ID already passed to the consumer (and not yet removed).
- (void)insertItem:(GridItem*)item
- (void)insertItem:(TabSwitcherItem*)item
atIndex:(NSUInteger)index
selectedItemID:(NSString*)selectedItemID;
......@@ -43,7 +43,7 @@
// Tells the consumer to replace the item with ID |itemID| with |item|.
// It's an error if |item|'s ID duplicates any other item's ID besides |itemID|.
// The consumer should ignore this call if |itemID| has not yet been inserted.
- (void)replaceItemID:(NSString*)itemID withItem:(GridItem*)item;
- (void)replaceItemID:(NSString*)itemID withItem:(TabSwitcherItem*)item;
// Tells the consumer to move the item with id |itemID| to |toIndex|. Note that
// the ID of the selected item isn't changed by this method, although the index
......
......@@ -20,11 +20,11 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_drag_drop_handler.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_image_data_source.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_item.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_layout.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/horizontal_layout.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/plus_sign_cell.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/transitions/grid_transition_layout.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_item.h"
#import "ios/chrome/browser/ui/thumb_strip/thumb_strip_feature.h"
#include "ios/chrome/browser/ui/ui_feature_flags.h"
#include "ios/chrome/browser/ui/util/rtl_geometry.h"
......@@ -57,7 +57,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
// A collection view of items in a grid format.
@property(nonatomic, weak) UICollectionView* collectionView;
// The local model backing the collection view.
@property(nonatomic, strong) NSMutableArray<GridItem*>* items;
@property(nonatomic, strong) NSMutableArray<TabSwitcherItem*>* items;
// Identifier of the selected item. This value is disregarded if |self.items| is
// empty. This bookkeeping is done to set the correct selection on
// |-viewWillAppear:|.
......@@ -110,7 +110,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
- (instancetype)init {
if (self = [super init]) {
_items = [[NSMutableArray<GridItem*> alloc] init];
_items = [[NSMutableArray<TabSwitcherItem*> alloc] init];
_showsSelectionUpdates = YES;
}
return self;
......@@ -351,7 +351,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
if (itemIndex >= self.items.count)
itemIndex = self.items.count - 1;
GridItem* item = self.items[itemIndex];
TabSwitcherItem* item = self.items[itemIndex];
cell =
[collectionView dequeueReusableCellWithReuseIdentifier:kCellIdentifier
forIndexPath:indexPath];
......@@ -397,7 +397,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
base::checked_cast<NSUInteger>(destinationIndexPath.item);
// Update |items| before informing the delegate, so the state of the UI
// is correctly represented before any updates occur.
GridItem* item = self.items[source];
TabSwitcherItem* item = self.items[source];
[self.items removeObjectAtIndex:source];
[self.items insertObject:item atIndex:destination];
self.hasChangedOrder = YES;
......@@ -466,7 +466,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
// Return an empty array because the plus sign cell should not be dragged.
return @[];
}
GridItem* item = self.items[indexPath.item];
TabSwitcherItem* item = self.items[indexPath.item];
return @[ [self.dragDropHandler dragItemForItemWithID:item.identifier] ];
}
......@@ -610,12 +610,12 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
#pragma mark - GridConsumer
- (void)populateItems:(NSArray<GridItem*>*)items
- (void)populateItems:(NSArray<TabSwitcherItem*>*)items
selectedItemID:(NSString*)selectedItemID {
#ifndef NDEBUG
// Consistency check: ensure no IDs are duplicated.
NSMutableSet<NSString*>* identifiers = [[NSMutableSet alloc] init];
for (GridItem* item in items) {
for (TabSwitcherItem* item in items) {
[identifiers addObject:item.identifier];
}
CHECK_EQ(identifiers.count, items.count);
......@@ -637,7 +637,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
[self updateFractionVisibleOfLastItem];
}
- (void)insertItem:(GridItem*)item
- (void)insertItem:(TabSwitcherItem*)item
atIndex:(NSUInteger)index
selectedItemID:(NSString*)selectedItemID {
// Consistency check: |item|'s ID is not in |items|.
......@@ -729,7 +729,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
scrollPosition:UICollectionViewScrollPositionNone];
}
- (void)replaceItemID:(NSString*)itemID withItem:(GridItem*)item {
- (void)replaceItemID:(NSString*)itemID withItem:(TabSwitcherItem*)item {
if ([self indexOfItemWithID:itemID] == NSNotFound)
return;
// Consistency check: |item|'s ID is either |itemID| or not in |items|.
......@@ -750,7 +750,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
if (fromIndex == toIndex)
return;
auto modelUpdates = ^{
GridItem* item = self.items[fromIndex];
TabSwitcherItem* item = self.items[fromIndex];
[self.items removeObjectAtIndex:fromIndex];
[self.items insertObject:item atIndex:toIndex];
};
......@@ -881,9 +881,10 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
// Returns the index in |self.items| of the first item whose identifier is
// |identifier|.
- (NSUInteger)indexOfItemWithID:(NSString*)identifier {
auto selectedTest = ^BOOL(GridItem* item, NSUInteger index, BOOL* stop) {
return [item.identifier isEqualToString:identifier];
};
auto selectedTest =
^BOOL(TabSwitcherItem* item, NSUInteger index, BOOL* stop) {
return [item.identifier isEqualToString:identifier];
};
return [self.items indexOfObjectPassingTest:selectedTest];
}
......@@ -891,7 +892,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
// asynchronously with information from |item|. Updates the |cell|'s theme to
// this view controller's theme. This view controller becomes the delegate for
// the cell.
- (void)configureCell:(GridCell*)cell withItem:(GridItem*)item {
- (void)configureCell:(GridCell*)cell withItem:(TabSwitcherItem*)item {
DCHECK(cell);
DCHECK(item);
cell.delegate = self;
......
......@@ -7,7 +7,7 @@
#import "base/mac/foundation_util.h"
#import "base/numerics/safe_conversions.h"
#import "base/test/ios/wait_util.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_item.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_item.h"
#import "ios/chrome/test/root_view_controller_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
......@@ -18,7 +18,7 @@
// Test object that exposes the inner state for test verification.
@interface GridViewController (Testing)
@property(nonatomic, readonly) NSMutableArray<GridItem*>* items;
@property(nonatomic, readonly) NSMutableArray<TabSwitcherItem*>* items;
@property(nonatomic, readonly) NSUInteger selectedIndex;
@property(nonatomic, readonly) UICollectionView* collectionView;
@property(nonatomic, assign, getter=isViewAppeared) BOOL viewAppeared;
......@@ -68,8 +68,8 @@ class GridViewControllerTest : public RootViewControllerTest {
view_controller_ = [[GridViewController alloc] init];
[view_controller_ loadView];
NSArray* items = @[
[[GridItem alloc] initWithIdentifier:@"A"],
[[GridItem alloc] initWithIdentifier:@"B"]
[[TabSwitcherItem alloc] initWithIdentifier:@"A"],
[[TabSwitcherItem alloc] initWithIdentifier:@"B"]
];
[view_controller_ populateItems:items selectedItemID:@"A"];
delegate_ = [[FakeGridViewControllerDelegate alloc] init];
......@@ -87,7 +87,8 @@ class GridViewControllerTest : public RootViewControllerTest {
TEST_F(GridViewControllerTest, InitializeItems) {
// Previously: The grid had 2 items and selectedIndex was 0. The delegate had
// an itemCount of 2.
GridItem* item = [[GridItem alloc] initWithIdentifier:@"NEW-ITEM"];
TabSwitcherItem* item =
[[TabSwitcherItem alloc] initWithIdentifier:@"NEW-ITEM"];
[view_controller_ populateItems:@[ item ] selectedItemID:@"NEW-ITEM"];
EXPECT_NSEQ(@"NEW-ITEM", view_controller_.items[0].identifier);
EXPECT_EQ(1U, view_controller_.items.count);
......@@ -99,9 +100,10 @@ TEST_F(GridViewControllerTest, InitializeItems) {
TEST_F(GridViewControllerTest, InsertItem) {
// Previously: The grid had 2 items and selectedIndex was 0. The delegate had
// an itemCount of 2.
[view_controller_ insertItem:[[GridItem alloc] initWithIdentifier:@"NEW-ITEM"]
atIndex:2
selectedItemID:@"NEW-ITEM"];
[view_controller_
insertItem:[[TabSwitcherItem alloc] initWithIdentifier:@"NEW-ITEM"]
atIndex:2
selectedItemID:@"NEW-ITEM"];
EXPECT_EQ(3U, view_controller_.items.count);
EXPECT_EQ(2U, view_controller_.selectedIndex);
EXPECT_EQ(3U, delegate_.itemCount);
......@@ -141,7 +143,8 @@ TEST_F(GridViewControllerTest, SelectNonexistentItem) {
TEST_F(GridViewControllerTest, ReplaceItem) {
// Previously: The grid had 2 items and selectedIndex was 0. The delegate had
// an itemCount of 2.
GridItem* item = [[GridItem alloc] initWithIdentifier:@"NEW-ITEM"];
TabSwitcherItem* item =
[[TabSwitcherItem alloc] initWithIdentifier:@"NEW-ITEM"];
[view_controller_ replaceItemID:@"A" withItem:item];
EXPECT_NSEQ(@"NEW-ITEM", view_controller_.items[0].identifier);
EXPECT_EQ(2U, delegate_.itemCount);
......@@ -151,7 +154,7 @@ TEST_F(GridViewControllerTest, ReplaceItem) {
TEST_F(GridViewControllerTest, ReplaceItemSameIdentifier) {
// Previously: The grid had 2 items and selectedIndex was 0. The delegate had
// an itemCount of 2.
GridItem* item = [[GridItem alloc] initWithIdentifier:@"A"];
TabSwitcherItem* item = [[TabSwitcherItem alloc] initWithIdentifier:@"A"];
item.title = @"NEW-ITEM-TITLE";
[view_controller_ replaceItemID:@"A" withItem:item];
EXPECT_NSEQ(@"A", view_controller_.items[0].identifier);
......@@ -163,7 +166,8 @@ TEST_F(GridViewControllerTest, ReplaceItemSameIdentifier) {
TEST_F(GridViewControllerTest, ReplaceItemNotFound) {
// Previously: The grid had 2 items and selectedIndex was 0. The delegate had
// an itemCount of 2.
GridItem* item = [[GridItem alloc] initWithIdentifier:@"NOT-FOUND"];
TabSwitcherItem* item =
[[TabSwitcherItem alloc] initWithIdentifier:@"NOT-FOUND"];
[view_controller_ replaceItemID:@"NOT-FOUND" withItem:item];
EXPECT_NSNE(@"NOT-FOUND", view_controller_.items[0].identifier);
EXPECT_NSNE(@"NOT-FOUND", view_controller_.items[1].identifier);
......@@ -215,12 +219,14 @@ TEST_F(GridViewControllerTest, DISABLED_ReplaceScrolledOffScreenCell) {
while (visibleCellsCount >= items.count) {
NSString* uniqueID =
[NSString stringWithFormat:@"%d", base::checked_cast<int>(items.count)];
GridItem* item = [[GridItem alloc] initWithIdentifier:uniqueID];
TabSwitcherItem* item =
[[TabSwitcherItem alloc] initWithIdentifier:uniqueID];
[view_controller_ insertItem:item atIndex:0 selectedItemID:@"A"];
visibleCellsCount = view_controller_.collectionView.visibleCells.count;
}
// The last item ("B") is scrolled off screen.
GridItem* item = [[GridItem alloc] initWithIdentifier:@"NEW-ITEM"];
TabSwitcherItem* item =
[[TabSwitcherItem alloc] initWithIdentifier:@"NEW-ITEM"];
// Do not crash due to cell being nil.
[view_controller_ replaceItemID:@"B" withItem:item];
}
......@@ -29,7 +29,7 @@
#include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/tabs/tab_title_util.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_consumer.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_item.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_item.h"
#import "ios/chrome/browser/web/tab_id_tab_helper.h"
#include "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
......@@ -46,10 +46,11 @@
#endif
namespace {
// Constructs a GridItem from a |web_state|.
GridItem* CreateItem(web::WebState* web_state) {
// Constructs a TabSwitcherItem from a |web_state|.
TabSwitcherItem* CreateItem(web::WebState* web_state) {
TabIdTabHelper* tab_helper = TabIdTabHelper::FromWebState(web_state);
GridItem* item = [[GridItem alloc] initWithIdentifier:tab_helper->tab_id()];
TabSwitcherItem* item =
[[TabSwitcherItem alloc] initWithIdentifier:tab_helper->tab_id()];
// chrome://newtab (NTP) tabs have no title.
if (IsURLNtp(web_state->GetVisibleURL())) {
item.hidesTitle = YES;
......@@ -58,7 +59,7 @@ GridItem* CreateItem(web::WebState* web_state) {
return item;
}
// Constructs an array of GridItems from a |web_state_list|.
// Constructs an array of TabSwitcherItems from a |web_state_list|.
NSArray* CreateItems(WebStateList* web_state_list) {
NSMutableArray* items = [[NSMutableArray alloc] init];
for (int i = 0; i < web_state_list->count(); i++) {
......
......@@ -25,7 +25,7 @@
#import "ios/chrome/browser/tabs/closing_web_state_observer_browser_agent.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_commands.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_consumer.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_item.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_item.h"
#import "ios/chrome/browser/web/page_placeholder_tab_helper.h"
#import "ios/chrome/browser/web/tab_id_tab_helper.h"
#include "ios/chrome/browser/web_state_list/fake_web_state_list_delegate.h"
......@@ -161,16 +161,16 @@ std::unique_ptr<KeyedService> BuildFakeTabRestoreService(
@synthesize items = _items;
@synthesize selectedItemID = _selectedItemID;
- (void)populateItems:(NSArray<GridItem*>*)items
- (void)populateItems:(NSArray<TabSwitcherItem*>*)items
selectedItemID:(NSString*)selectedItemID {
self.selectedItemID = selectedItemID;
self.items = [NSMutableArray array];
for (GridItem* item in items) {
for (TabSwitcherItem* item in items) {
[self.items addObject:item.identifier];
}
}
- (void)insertItem:(GridItem*)item
- (void)insertItem:(TabSwitcherItem*)item
atIndex:(NSUInteger)index
selectedItemID:(NSString*)selectedItemID {
[self.items insertObject:item.identifier atIndex:index];
......@@ -187,7 +187,7 @@ std::unique_ptr<KeyedService> BuildFakeTabRestoreService(
self.selectedItemID = selectedItemID;
}
- (void)replaceItemID:(NSString*)itemID withItem:(GridItem*)item {
- (void)replaceItemID:(NSString*)itemID withItem:(TabSwitcherItem*)item {
NSUInteger index = [self.items indexOfObject:itemID];
self.items[index] = item.identifier;
}
......
......@@ -38,7 +38,7 @@ source_set("tab_strip_ui") {
"//ios/chrome/browser",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui/tab_switcher/tab_grid/grid:grid_ui",
"//ios/chrome/browser/ui/tab_switcher",
"//ios/chrome/browser/web:tab_id_tab_helper",
"//ios/chrome/browser/web_state_list",
"//ios/chrome/common/ui/colors",
......
......@@ -7,7 +7,7 @@
#import <Foundation/Foundation.h>
@class GridItem;
@class TabSwitcherItem;
// TabStripConsumer sets the current appearance of the TabStrip.
@protocol TabStripConsumer
......@@ -15,13 +15,13 @@
// Tells the consumer to replace its current set of items with |items| and
// update the selected item ID to be |selectedItemID|. It's an error to pass
// an |items| array containing items without unique IDs.
- (void)populateItems:(NSArray<GridItem*>*)items
- (void)populateItems:(NSArray<TabSwitcherItem*>*)items
selectedItemID:(NSString*)selectedItemID;
// Tells the consumer to replace the item with ID |itemID| with |item|.
// It's an error if |item|'s ID duplicates any other item's ID besides |itemID|.
// The consumer should ignore this call if |itemID| has not yet been inserted.
- (void)replaceItemID:(NSString*)itemID withItem:(GridItem*)item;
- (void)replaceItemID:(NSString*)itemID withItem:(TabSwitcherItem*)item;
@end
......
......@@ -8,8 +8,8 @@
#import "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/chrome_url_util.h"
#import "ios/chrome/browser/tabs/tab_title_util.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_item.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_strip/tab_strip_consumer.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_item.h"
#import "ios/chrome/browser/web/tab_id_tab_helper.h"
#import "ios/chrome/browser/web_state_list/all_web_state_observation_forwarder.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
......@@ -23,10 +23,11 @@
#endif
namespace {
// Constructs a GridItem from a |web_state|.
GridItem* CreateItem(web::WebState* web_state) {
// Constructs a TabSwitcherItem from a |web_state|.
TabSwitcherItem* CreateItem(web::WebState* web_state) {
TabIdTabHelper* tab_helper = TabIdTabHelper::FromWebState(web_state);
GridItem* item = [[GridItem alloc] initWithIdentifier:tab_helper->tab_id()];
TabSwitcherItem* item =
[[TabSwitcherItem alloc] initWithIdentifier:tab_helper->tab_id()];
// chrome://newtab (NTP) tabs have no title.
if (IsURLNtp(web_state->GetVisibleURL())) {
item.hidesTitle = YES;
......@@ -35,7 +36,7 @@ GridItem* CreateItem(web::WebState* web_state) {
return item;
}
// Constructs an array of GridItems from a |web_state_list|.
// Constructs an array of TabSwitcherItems from a |web_state_list|.
NSArray* CreateItems(WebStateList* web_state_list) {
NSMutableArray* items = [[NSMutableArray alloc] init];
for (int i = 0; i < web_state_list->count(); i++) {
......
......@@ -5,10 +5,10 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_strip/tab_strip_view_controller.h"
#import "base/allocator/partition_allocator/partition_alloc.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_item.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_strip/tab_strip_cell.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_strip/tab_strip_mediator.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_strip/tab_strip_view_layout.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_item.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -24,7 +24,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
@interface TabStripViewController ()
// The local model backing the collection view.
@property(nonatomic, strong) NSMutableArray<GridItem*>* items;
@property(nonatomic, strong) NSMutableArray<TabSwitcherItem*>* items;
// Identifier of the selected item. This value is disregarded if |self.items| is
// empty.
@property(nonatomic, copy) NSString* selectedItemID;
......@@ -66,7 +66,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
if (itemIndex >= self.items.count)
itemIndex = self.items.count - 1;
GridItem* item = self.items[itemIndex];
TabSwitcherItem* item = self.items[itemIndex];
TabStripCell* cell = (TabStripCell*)[collectionView
dequeueReusableCellWithReuseIdentifier:kReuseIdentifier
forIndexPath:indexPath];
......@@ -77,12 +77,12 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
#pragma mark - TabStripConsumer
- (void)populateItems:(NSArray<GridItem*>*)items
- (void)populateItems:(NSArray<TabSwitcherItem*>*)items
selectedItemID:(NSString*)selectedItemID {
#ifndef NDEBUG
// Consistency check: ensure no IDs are duplicated.
NSMutableSet<NSString*>* identifiers = [[NSMutableSet alloc] init];
for (GridItem* item in items) {
for (TabSwitcherItem* item in items) {
[identifiers addObject:item.identifier];
}
CHECK_EQ(identifiers.count, items.count);
......@@ -93,7 +93,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
[self.collectionView reloadData];
}
- (void)replaceItemID:(NSString*)itemID withItem:(GridItem*)item {
- (void)replaceItemID:(NSString*)itemID withItem:(TabSwitcherItem*)item {
if ([self indexOfItemWithID:itemID] == NSNotFound)
return;
// Consistency check: |item|'s ID is either |itemID| or not in |items|.
......@@ -113,7 +113,7 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
// Configures |cell|'s title synchronously, and favicon asynchronously with
// information from |item|. Updates the |cell|'s theme to this view controller's
// theme.
- (void)configureCell:(TabStripCell*)cell withItem:(GridItem*)item {
- (void)configureCell:(TabStripCell*)cell withItem:(TabSwitcherItem*)item {
if (item) {
cell.itemIdentifier = item.identifier;
cell.titleLabel.text = item.title;
......@@ -132,9 +132,10 @@ NSIndexPath* CreateIndexPath(NSInteger index) {
// Returns the index in |self.items| of the first item whose identifier is
// |identifier|.
- (NSUInteger)indexOfItemWithID:(NSString*)identifier {
auto selectedTest = ^BOOL(GridItem* item, NSUInteger index, BOOL* stop) {
return [item.identifier isEqualToString:identifier];
};
auto selectedTest =
^BOOL(TabSwitcherItem* item, NSUInteger index, BOOL* stop) {
return [item.identifier isEqualToString:identifier];
};
return [self.items indexOfObjectPassingTest:selectedTest];
}
......
......@@ -2,13 +2,13 @@
// 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_ITEM_H_
#define IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_GRID_ITEM_H_
#ifndef IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_SWITCHER_ITEM_H_
#define IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_SWITCHER_ITEM_H_
#import <Foundation/Foundation.h>
// Model object representing an item in a grid.
@interface GridItem : NSObject
// Model object representing an item in the tab switchers.
@interface TabSwitcherItem : NSObject
// Create an item with |identifier|, which cannot be nil.
- (instancetype)initWithIdentifier:(NSString*)identifier
......@@ -21,4 +21,4 @@
@property(nonatomic, assign) BOOL hidesTitle;
@end
#endif // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_GRID_GRID_GRID_ITEM_H_
#endif // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_SWITCHER_ITEM_H_
......@@ -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_item.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_item.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -10,7 +10,7 @@
#include "base/check.h"
@implementation GridItem
@implementation TabSwitcherItem
- (instancetype)initWithIdentifier:(NSString*)identifier {
DCHECK(identifier);
......
......@@ -18,6 +18,7 @@ source_set("tab_grid") {
deps = [
"//base",
"//ios/chrome/browser/ui/elements",
"//ios/chrome/browser/ui/tab_switcher/",
"//ios/chrome/browser/ui/tab_switcher/tab_grid:tab_grid_ui",
"//ios/chrome/browser/ui/tab_switcher/tab_grid/grid:grid_ui",
"//ios/showcase/common",
......
......@@ -6,8 +6,8 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_drag_drop_handler.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_image_data_source.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_item.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_view_controller.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_item.h"
#import "ios/showcase/common/protocol_alerter.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -38,9 +38,9 @@
gridViewController.imageDataSource = self;
self.alerter.baseViewController = gridViewController;
NSMutableArray<GridItem*>* items = [[NSMutableArray alloc] init];
NSMutableArray<TabSwitcherItem*>* items = [[NSMutableArray alloc] init];
for (int i = 0; i < 20; i++) {
GridItem* item = [[GridItem alloc]
TabSwitcherItem* item = [[TabSwitcherItem alloc]
initWithIdentifier:[NSString stringWithFormat:@"item%d", i]];
item.title = @"The New York Times - Breaking News";
[items addObject:item];
......
......@@ -7,8 +7,8 @@
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_commands.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_consumer.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_drag_drop_handler.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/grid/grid_item.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_grid/tab_grid_view_controller.h"
#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_item.h"
#import "ios/showcase/common/protocol_alerter.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -43,9 +43,9 @@
self.baseViewController.hidesBarsOnSwipe = YES;
[self.baseViewController pushViewController:self.viewController animated:YES];
NSMutableArray<GridItem*>* items = [[NSMutableArray alloc] init];
NSMutableArray<TabSwitcherItem*>* items = [[NSMutableArray alloc] init];
for (int i = 0; i < 10; i++) {
GridItem* item = [[GridItem alloc]
TabSwitcherItem* item = [[TabSwitcherItem alloc]
initWithIdentifier:[NSString stringWithFormat:@"incogitem%d", i]];
item.title = @"YouTube - Cat Videos";
[items addObject:item];
......@@ -54,7 +54,7 @@
selectedItemID:items[0].identifier];
items = [[NSMutableArray alloc] init];
for (int i = 0; i < 10; i++) {
GridItem* item = [[GridItem alloc]
TabSwitcherItem* item = [[TabSwitcherItem alloc]
initWithIdentifier:[NSString stringWithFormat:@"item%d", i]];
item.title = @"The New York Times - Breaking News";
[items addObject:item];
......
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