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

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

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

Powered by Google App Engine
This is Rietveld 408576698