Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Unified Diff: ios/clean/chrome/browser/ui/tab_collection/tab_collection_view_controller.mm

Issue 2904053002: [ios] Active web state observer in tab collection. (Closed)
Patch Set: Update unittest Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/clean/chrome/browser/ui/tab_collection/tab_collection_view_controller.mm
diff --git a/ios/clean/chrome/browser/ui/tab_collection/tab_collection_view_controller.mm b/ios/clean/chrome/browser/ui/tab_collection/tab_collection_view_controller.mm
index 5f64f9d9b6d245fb73e3ca8ef41d491c70632b49..4fa101e93a1d317ae4d4bd0abceaf405f9bde54e 100644
--- a/ios/clean/chrome/browser/ui/tab_collection/tab_collection_view_controller.mm
+++ b/ios/clean/chrome/browser/ui/tab_collection/tab_collection_view_controller.mm
@@ -16,8 +16,11 @@
@interface TabCollectionViewController ()<UICollectionViewDelegate,
SessionCellDelegate>
+// Collection view of tabs.
@property(nonatomic, readwrite) UICollectionView* tabs;
+// The model backing the collection view.
@property(nonatomic, readwrite) NSMutableArray<TabCollectionItem*>* items;
+// Selected index of tab collection.
@property(nonatomic, assign) int selectedIndex;
@end
@@ -50,13 +53,27 @@
[self.tabs.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
]];
- [self selectItemAtIndex:self.selectedIndex];
+ [self.tabs
+ selectItemAtIndexPath:[NSIndexPath indexPathForItem:self.selectedIndex
+ inSection:0]
+ animated:NO
+ scrollPosition:UICollectionViewScrollPositionNone];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
+#pragma mark - Setters
+
+- (void)setSelectedIndex:(int)selectedIndex {
+ [self.tabs selectItemAtIndexPath:[NSIndexPath indexPathForItem:selectedIndex
+ inSection:0]
+ animated:YES
+ scrollPosition:UICollectionViewScrollPositionNone];
+ _selectedIndex = selectedIndex;
+}
+
#pragma mark - Required subclass override
- (UICollectionViewLayout*)collectionViewLayout {
@@ -138,47 +155,55 @@
#pragma mark - TabCollectionConsumer methods
-- (void)insertItem:(TabCollectionItem*)item atIndex:(int)index {
+- (void)insertItem:(TabCollectionItem*)item
+ atIndex:(int)index
+ selectedIndex:(int)selectedIndex {
+ DCHECK_GE(index, 0);
DCHECK_LE(static_cast<NSUInteger>(index), self.items.count);
[self.items insertObject:item atIndex:index];
- [self.tabs insertItemsAtIndexPaths:@[ [self indexPathForIndex:index] ]];
+ [self.tabs insertItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index
+ inSection:0] ]];
+ self.selectedIndex = selectedIndex;
}
-- (void)deleteItemAtIndex:(int)index {
+- (void)deleteItemAtIndex:(int)index selectedIndex:(int)selectedIndex {
+ DCHECK_GE(index, 0);
DCHECK_LT(static_cast<NSUInteger>(index), self.items.count);
[self.items removeObjectAtIndex:index];
- [self.tabs deleteItemsAtIndexPaths:@[ [self indexPathForIndex:index] ]];
+ [self.tabs deleteItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index
+ inSection:0] ]];
+ self.selectedIndex = selectedIndex;
}
-- (void)moveItemFromIndex:(int)fromIndex toIndex:(int)toIndex {
+- (void)moveItemFromIndex:(int)fromIndex
+ toIndex:(int)toIndex
+ selectedIndex:(int)selectedIndex {
TabCollectionItem* item = self.items[fromIndex];
[self.items removeObjectAtIndex:fromIndex];
[self.items insertObject:item atIndex:toIndex];
- [self.tabs moveItemAtIndexPath:[self indexPathForIndex:fromIndex]
- toIndexPath:[self indexPathForIndex:toIndex]];
+ [self.tabs
+ moveItemAtIndexPath:[NSIndexPath indexPathForItem:fromIndex inSection:0]
+ toIndexPath:[NSIndexPath indexPathForItem:toIndex inSection:0]];
+ self.selectedIndex = selectedIndex;
}
- (void)replaceItemAtIndex:(int)index withItem:(TabCollectionItem*)item {
- [self.items removeObjectAtIndex:index];
- [self.items insertObject:item atIndex:index];
-}
-
-- (void)selectItemAtIndex:(int)index {
- self.selectedIndex = index;
- [self.tabs selectItemAtIndexPath:[self indexPathForIndex:index]
- animated:YES
- scrollPosition:UITableViewScrollPositionNone];
+ DCHECK_GE(index, 0);
+ DCHECK_LT(static_cast<NSUInteger>(index), self.items.count);
+ self.items[index] = item;
+ TabCollectionTabCell* cell = base::mac::ObjCCastStrict<TabCollectionTabCell>(
+ [self.tabs cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index
+ inSection:0]]);
+ [cell setAppearanceForTabTitle:self.items[index].title
+ favicon:nil
+ cellSize:CGSizeZero];
}
-- (void)populateItems:(NSArray<TabCollectionItem*>*)items {
+- (void)populateItems:(NSArray<TabCollectionItem*>*)items
+ selectedIndex:(int)selectedIndex {
self.items = [items mutableCopy];
- [self.tabs reloadData];
-}
-
-#pragma mark - Private
-
-- (NSIndexPath*)indexPathForIndex:(int)index {
- return [NSIndexPath indexPathForItem:index inSection:0];
+ [self.tabs reloadItemsAtIndexPaths:[self.tabs indexPathsForVisibleItems]];
+ self.selectedIndex = selectedIndex;
}
@end

Powered by Google App Engine
This is Rietveld 408576698