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

Side by Side Diff: ios/chrome/browser/ui/bookmarks/bookmark_home_tablet_ntp_controller.mm

Issue 2666833003: Revert of Removing "All Bookmarks" (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_tablet_ntp_controller.h" 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_tablet_ntp_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/ios/block_types.h" 9 #include "base/ios/block_types.h"
10 #import "base/ios/weak_nsobject.h" 10 #import "base/ios/weak_nsobject.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/mac/objc_property_releaser.h" 12 #include "base/mac/objc_property_releaser.h"
13 #include "base/mac/scoped_nsobject.h" 13 #include "base/mac/scoped_nsobject.h"
14 #include "base/metrics/user_metrics.h" 14 #include "base/metrics/user_metrics.h"
15 #include "base/metrics/user_metrics_action.h" 15 #include "base/metrics/user_metrics_action.h"
16 #include "base/strings/sys_string_conversions.h" 16 #include "base/strings/sys_string_conversions.h"
17 #include "components/bookmarks/browser/bookmark_model.h" 17 #include "components/bookmarks/browser/bookmark_model.h"
18 #include "components/strings/grit/components_strings.h" 18 #include "components/strings/grit/components_strings.h"
19 #include "google_apis/gaia/google_service_auth_error.h" 19 #include "google_apis/gaia/google_service_auth_error.h"
20 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" 20 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
21 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" 21 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h"
22 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 22 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
23 #import "ios/chrome/browser/metrics/new_tab_page_uma.h" 23 #import "ios/chrome/browser/metrics/new_tab_page_uma.h"
24 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" 24 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
25 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_editing_bar.h" 25 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_editing_bar.h"
26 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_navigation_bar.h" 26 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_navigation_bar.h"
27 #import "ios/chrome/browser/ui/bookmarks/bookmark_all_collection_view.h"
27 #import "ios/chrome/browser/ui/bookmarks/bookmark_edit_view_controller.h" 28 #import "ios/chrome/browser/ui/bookmarks/bookmark_edit_view_controller.h"
28 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_collection_view.h" 29 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_collection_view.h"
29 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_editor_view_controller. h" 30 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_editor_view_controller. h"
30 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h" 31 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h"
31 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_primary_view.h" 32 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_primary_view.h"
32 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_waiting_view.h" 33 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_waiting_view.h"
33 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" 34 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h"
34 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_view.h" 35 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_view.h"
35 #include "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h" 36 #include "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h"
36 #import "ios/chrome/browser/ui/bookmarks/bookmark_navigation_controller.h" 37 #import "ios/chrome/browser/ui/bookmarks/bookmark_navigation_controller.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 atIndexPath:(NSIndexPath*)indexPath; 124 atIndexPath:(NSIndexPath*)indexPath;
124 // This method updates the property, and resets the edit nodes. 125 // This method updates the property, and resets the edit nodes.
125 - (void)setEditing:(BOOL)editing animated:(BOOL)animated; 126 - (void)setEditing:(BOOL)editing animated:(BOOL)animated;
126 127
127 #pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController 128 #pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController
128 129
129 // This views holds the primary content of this controller. At any point in 130 // This views holds the primary content of this controller. At any point in
130 // time, it contains exactly one of the BookmarkCollectionView subclasses. 131 // time, it contains exactly one of the BookmarkCollectionView subclasses.
131 @property(nonatomic, retain) ContentView* contentView; 132 @property(nonatomic, retain) ContentView* contentView;
132 // The possible views that can be shown from the menu. 133 // The possible views that can be shown from the menu.
134 @property(nonatomic, retain) BookmarkAllCollectionView* allItemsView;
133 @property(nonatomic, retain) BookmarkFolderCollectionView* folderView; 135 @property(nonatomic, retain) BookmarkFolderCollectionView* folderView;
134 // This view is created and used if the model is not fully loaded yet by the 136 // This view is created and used if the model is not fully loaded yet by the
135 // time this controller starts. 137 // time this controller starts.
136 @property(nonatomic, retain) BookmarkHomeWaitingView* waitForModelView; 138 @property(nonatomic, retain) BookmarkHomeWaitingView* waitForModelView;
137 139
138 // The menu with all the folders and special entries. 140 // The menu with all the folders and special entries.
139 @property(nonatomic, retain) BookmarkMenuView* menuView; 141 @property(nonatomic, retain) BookmarkMenuView* menuView;
140 // At any point in time, there is exactly one collection view whose view is part 142 // At any point in time, there is exactly one collection view whose view is part
141 // of the view hierarchy. This property determines which collection view is 143 // of the view hierarchy. This property determines which collection view is
142 // visible. Not by accident, this property also reflects the selected menu item 144 // visible. Not by accident, this property also reflects the selected menu item
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 - (void)loadURL:(const GURL&)url; 178 - (void)loadURL:(const GURL&)url;
177 #pragma mark View loading, laying out, and switching. 179 #pragma mark View loading, laying out, and switching.
178 // This method is called if the view needs to be loaded and the model is not 180 // This method is called if the view needs to be loaded and the model is not
179 // ready yet. 181 // ready yet.
180 - (void)loadWaitingView; 182 - (void)loadWaitingView;
181 // This method should be called at most once in the life-cycle of the class. 183 // This method should be called at most once in the life-cycle of the class.
182 // It should be called at the soonest possible time after the view has been 184 // It should be called at the soonest possible time after the view has been
183 // loaded, and the bookmark model is loaded. 185 // loaded, and the bookmark model is loaded.
184 - (void)loadBookmarkViews; 186 - (void)loadBookmarkViews;
185 // If the view doesn't exist, create it. 187 // If the view doesn't exist, create it.
188 - (void)ensureAllViewExists;
186 - (void)ensureFolderViewExists; 189 - (void)ensureFolderViewExists;
187 // Updates the property 'primaryMenuItem'. 190 // Updates the property 'primaryMenuItem'.
188 // Updates the UI to reflect the new state of 'primaryMenuItem'. 191 // Updates the UI to reflect the new state of 'primaryMenuItem'.
189 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem 192 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem
190 animated:(BOOL)animated; 193 animated:(BOOL)animated;
191 // The active collection view that corresponds to primaryMenuItem. 194 // The active collection view that corresponds to primaryMenuItem.
192 - (UIView<BookmarkHomePrimaryView>*)primaryView; 195 - (UIView<BookmarkHomePrimaryView>*)primaryView;
193 // Returns whether the menu should be in a side panel that slides in. 196 // Returns whether the menu should be in a side panel that slides in.
194 - (BOOL)shouldPresentMenuInSlideInPanel; 197 - (BOOL)shouldPresentMenuInSlideInPanel;
195 // Returns the width of the menu. 198 // Returns the width of the menu.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell; 275 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell;
273 276
274 @end 277 @end
275 278
276 @implementation BookmarkHomeTabletNTPController 279 @implementation BookmarkHomeTabletNTPController
277 @synthesize editing = _editing; 280 @synthesize editing = _editing;
278 @synthesize editIndexPaths = _editIndexPaths; 281 @synthesize editIndexPaths = _editIndexPaths;
279 @synthesize bookmarks = _bookmarks; 282 @synthesize bookmarks = _bookmarks;
280 283
281 @synthesize contentView = _contentView; 284 @synthesize contentView = _contentView;
285 @synthesize allItemsView = _allItemsView;
282 @synthesize folderView = _folderView; 286 @synthesize folderView = _folderView;
283 @synthesize waitForModelView = _waitForModelView; 287 @synthesize waitForModelView = _waitForModelView;
284 288
285 @synthesize menuView = _menuView; 289 @synthesize menuView = _menuView;
286 @synthesize primaryMenuItem = _primaryMenuItem; 290 @synthesize primaryMenuItem = _primaryMenuItem;
287 @synthesize cachedContentPosition = _cachedContentPosition; 291 @synthesize cachedContentPosition = _cachedContentPosition;
288 @synthesize navigationBar = _navigationBar; 292 @synthesize navigationBar = _navigationBar;
289 @synthesize editingBar = _editingBar; 293 @synthesize editingBar = _editingBar;
290 @synthesize panelView = _panelView; 294 @synthesize panelView = _panelView;
291 295
(...skipping 26 matching lines...) Expand all
318 _bookmarkPromoController = 322 _bookmarkPromoController =
319 [[BookmarkPromoController alloc] initWithBrowserState:browserState 323 [[BookmarkPromoController alloc] initWithBrowserState:browserState
320 delegate:self]; 324 delegate:self];
321 } 325 }
322 return self; 326 return self;
323 } 327 }
324 328
325 - (void)dealloc { 329 - (void)dealloc {
326 _contentView.delegate = nil; 330 _contentView.delegate = nil;
327 331
332 _allItemsView.delegate = nil;
328 _folderView.delegate = nil; 333 _folderView.delegate = nil;
329 334
330 _menuView.delegate = nil; 335 _menuView.delegate = nil;
331 336
332 _editViewController.delegate = nil; 337 _editViewController.delegate = nil;
333 _folderSelector.delegate = nil; 338 _folderSelector.delegate = nil;
334 339
335 [super dealloc]; 340 [super dealloc];
336 } 341 }
337 342
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 if (self.view.window) { 499 if (self.view.window) {
495 [[self primaryView] applyContentPosition:position]; 500 [[self primaryView] applyContentPosition:position];
496 } else { 501 } else {
497 // Otherwise, save the position to be applied once the view has been laid 502 // Otherwise, save the position to be applied once the view has been laid
498 // out. 503 // out.
499 self.cachedContentPosition = [NSNumber numberWithFloat:position]; 504 self.cachedContentPosition = [NSNumber numberWithFloat:position];
500 } 505 }
501 } 506 }
502 } 507 }
503 508
509 - (void)ensureAllViewExists {
510 if (self.allItemsView)
511 return;
512
513 base::scoped_nsobject<BookmarkAllCollectionView> view(
514 [[BookmarkAllCollectionView alloc] initWithBrowserState:self.browserState
515 frame:CGRectZero]);
516 self.allItemsView = view;
517 self.allItemsView.delegate = self;
518 [self.allItemsView setEditing:self.editing animated:NO];
519 self.allItemsView.autoresizingMask =
520 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
521 }
522
504 - (void)ensureFolderViewExists { 523 - (void)ensureFolderViewExists {
505 if (self.folderView) 524 if (self.folderView)
506 return; 525 return;
507 526
508 base::scoped_nsobject<BookmarkFolderCollectionView> view( 527 base::scoped_nsobject<BookmarkFolderCollectionView> view(
509 [[BookmarkFolderCollectionView alloc] 528 [[BookmarkFolderCollectionView alloc]
510 initWithBrowserState:self.browserState 529 initWithBrowserState:self.browserState
511 frame:CGRectZero]); 530 frame:CGRectZero]);
512 self.folderView = view; 531 self.folderView = view;
513 self.folderView.delegate = self; 532 self.folderView.delegate = self;
514 [self.folderView setEditing:self.editing animated:NO]; 533 [self.folderView setEditing:self.editing animated:NO];
515 self.folderView.autoresizingMask = 534 self.folderView.autoresizingMask =
516 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 535 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
517 } 536 }
518 537
519 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem 538 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem
520 animated:(BOOL)animated { 539 animated:(BOOL)animated {
521 if ([self.primaryMenuItem isEqual:menuItem]) 540 if ([self.primaryMenuItem isEqual:menuItem])
522 return; 541 return;
523 542
524 if (![self.contentView superview]) 543 if (![self.contentView superview])
525 return; 544 return;
526 545
527 [[self primaryView] removeFromSuperview]; 546 [[self primaryView] removeFromSuperview];
528 self.primaryMenuItem = menuItem; 547 self.primaryMenuItem = menuItem;
529 548
530 switch (self.primaryMenuItem.type) { 549 switch (self.primaryMenuItem.type) {
550 case bookmarks::MenuItemAll:
551 [self ensureAllViewExists];
552 break;
531 case bookmarks::MenuItemFolder: 553 case bookmarks::MenuItemFolder:
532 [self ensureFolderViewExists]; 554 [self ensureFolderViewExists];
533 [self.folderView resetFolder:self.primaryMenuItem.folder]; 555 [self.folderView resetFolder:self.primaryMenuItem.folder];
534 [self.folderView promoStateChangedAnimated:NO]; 556 [self.folderView promoStateChangedAnimated:NO];
535 break; 557 break;
536 case bookmarks::MenuItemDivider: 558 case bookmarks::MenuItemDivider:
537 case bookmarks::MenuItemSectionHeader: 559 case bookmarks::MenuItemSectionHeader:
538 NOTREACHED(); 560 NOTREACHED();
539 break; 561 break;
540 } 562 }
(...skipping 13 matching lines...) Expand all
554 [self.menuView updatePrimaryMenuItem:self.primaryMenuItem]; 576 [self.menuView updatePrimaryMenuItem:self.primaryMenuItem];
555 [self updateEditBarShadow]; 577 [self updateEditBarShadow];
556 } 578 }
557 579
558 - (UIView<BookmarkHomePrimaryView>*)primaryView { 580 - (UIView<BookmarkHomePrimaryView>*)primaryView {
559 if (!self.primaryMenuItem) 581 if (!self.primaryMenuItem)
560 return nil; 582 return nil;
561 DCHECK([self contentView]); 583 DCHECK([self contentView]);
562 584
563 switch (self.primaryMenuItem.type) { 585 switch (self.primaryMenuItem.type) {
586 case bookmarks::MenuItemAll:
587 return self.allItemsView;
564 case bookmarks::MenuItemFolder: 588 case bookmarks::MenuItemFolder:
565 return self.folderView; 589 return self.folderView;
566 case bookmarks::MenuItemDivider: 590 case bookmarks::MenuItemDivider:
567 case bookmarks::MenuItemSectionHeader: 591 case bookmarks::MenuItemSectionHeader:
568 NOTREACHED(); 592 NOTREACHED();
569 return nil; 593 return nil;
570 } 594 }
571 } 595 }
572 596
573 - (BOOL)shouldPresentMenuInSlideInPanel { 597 - (BOOL)shouldPresentMenuInSlideInPanel {
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 } 1317 }
1294 1318
1295 - (void)bookmarkModelRemovedAllNodes { 1319 - (void)bookmarkModelRemovedAllNodes {
1296 // All non-permanent nodes have been removed. 1320 // All non-permanent nodes have been removed.
1297 [self setEditing:NO animated:YES]; 1321 [self setEditing:NO animated:YES];
1298 } 1322 }
1299 1323
1300 #pragma mark - BookmarkPromoControllerDelegate 1324 #pragma mark - BookmarkPromoControllerDelegate
1301 1325
1302 - (void)promoStateChanged:(BOOL)promoEnabled { 1326 - (void)promoStateChanged:(BOOL)promoEnabled {
1327 [self.allItemsView.collectionView reloadData];
1328 // This is required to workaround a crash seen once on iOS 7.1 when
1329 // the collection gets two reloadData without getting a call to layout
1330 // subviews, the collection view will reuse some cached data for the perfoming
1331 // the layout which are invalid after the second call to reloadData.
1332 // Forcing the layout invalidation after each reloadData seems to fix the
1333 // issue.
1334 [self.allItemsView.collectionView.collectionViewLayout invalidateLayout];
1303 [self.folderView 1335 [self.folderView
1304 promoStateChangedAnimated:self.folderView == [self primaryView]]; 1336 promoStateChangedAnimated:self.folderView == [self primaryView]];
1305 } 1337 }
1306 1338
1307 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell { 1339 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell {
1308 DCHECK([self primaryView].collectionView); 1340 DCHECK([self primaryView].collectionView);
1309 NSIndexPath* indexPath = 1341 NSIndexPath* indexPath =
1310 [[self primaryView].collectionView indexPathForCell:cell]; 1342 [[self primaryView].collectionView indexPathForCell:cell];
1311 return indexPath; 1343 return indexPath;
1312 } 1344 }
1313 1345
1314 @end 1346 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698