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

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

Issue 2821063002: Convert bookmarks NTP panel to UIViewController. (Closed)
Patch Set: Created 3 years, 8 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 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // Removes |node| corresponding to a |cell| if it's present. 119 // Removes |node| corresponding to a |cell| if it's present.
120 - (void)removeEditNode:(const BookmarkNode*)node 120 - (void)removeEditNode:(const BookmarkNode*)node
121 atIndexPath:(NSIndexPath*)indexPath; 121 atIndexPath:(NSIndexPath*)indexPath;
122 // This method updates the property, and resets the edit nodes. 122 // This method updates the property, and resets the edit nodes.
123 - (void)setEditing:(BOOL)editing animated:(BOOL)animated; 123 - (void)setEditing:(BOOL)editing animated:(BOOL)animated;
124 124
125 #pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController 125 #pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController
126 126
127 // This views holds the primary content of this controller. At any point in 127 // This views holds the primary content of this controller. At any point in
128 // time, it contains exactly one of the BookmarkCollectionView subclasses. 128 // time, it contains exactly one of the BookmarkCollectionView subclasses.
129 @property(nonatomic, strong) ContentView* contentView; 129 @property(nonatomic, readwrite, strong) ContentView* view;
130
130 // The possible views that can be shown from the menu. 131 // The possible views that can be shown from the menu.
131 @property(nonatomic, strong) BookmarkFolderCollectionView* folderView; 132 @property(nonatomic, strong) BookmarkFolderCollectionView* folderView;
132 // This view is created and used if the model is not fully loaded yet by the 133 // This view is created and used if the model is not fully loaded yet by the
133 // time this controller starts. 134 // time this controller starts.
134 @property(nonatomic, strong) BookmarkHomeWaitingView* waitForModelView; 135 @property(nonatomic, strong) BookmarkHomeWaitingView* waitForModelView;
135 136
136 // The menu with all the folders and special entries. 137 // The menu with all the folders and special entries.
137 @property(nonatomic, strong) BookmarkMenuView* menuView; 138 @property(nonatomic, strong) BookmarkMenuView* menuView;
138 // At any point in time, there is exactly one collection view whose view is part 139 // At any point in time, there is exactly one collection view whose view is part
139 // of the view hierarchy. This property determines which collection view is 140 // of the view hierarchy. This property determines which collection view is
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // Called when the back button is pressed on the navigation bar. 266 // Called when the back button is pressed on the navigation bar.
266 - (void)navigationBarBack:(id)sender; 267 - (void)navigationBarBack:(id)sender;
267 268
268 // TODO(crbug.com/450646): This should not be needed but require refactoring of 269 // TODO(crbug.com/450646): This should not be needed but require refactoring of
269 // the BookmarkCollectionViewDelegate. 270 // the BookmarkCollectionViewDelegate.
270 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell; 271 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell;
271 272
272 @end 273 @end
273 274
274 @implementation BookmarkHomeTabletNTPController 275 @implementation BookmarkHomeTabletNTPController
276
277 @dynamic view;
275 @synthesize editing = _editing; 278 @synthesize editing = _editing;
276 @synthesize editIndexPaths = _editIndexPaths; 279 @synthesize editIndexPaths = _editIndexPaths;
277 @synthesize bookmarks = _bookmarks; 280 @synthesize bookmarks = _bookmarks;
278 281
279 @synthesize contentView = _contentView;
280 @synthesize folderView = _folderView; 282 @synthesize folderView = _folderView;
281 @synthesize waitForModelView = _waitForModelView; 283 @synthesize waitForModelView = _waitForModelView;
282 284
283 @synthesize menuView = _menuView; 285 @synthesize menuView = _menuView;
284 @synthesize primaryMenuItem = _primaryMenuItem; 286 @synthesize primaryMenuItem = _primaryMenuItem;
285 @synthesize cachedContentPosition = _cachedContentPosition; 287 @synthesize cachedContentPosition = _cachedContentPosition;
286 @synthesize navigationBar = _navigationBar; 288 @synthesize navigationBar = _navigationBar;
287 @synthesize editingBar = _editingBar; 289 @synthesize editingBar = _editingBar;
288 @synthesize panelView = _panelView; 290 @synthesize panelView = _panelView;
289 291
(...skipping 22 matching lines...) Expand all
312 // It is important to initialize the promo controller with the browser state 314 // It is important to initialize the promo controller with the browser state
313 // passed in, as it could be incognito. 315 // passed in, as it could be incognito.
314 _bookmarkPromoController = 316 _bookmarkPromoController =
315 [[BookmarkPromoController alloc] initWithBrowserState:browserState 317 [[BookmarkPromoController alloc] initWithBrowserState:browserState
316 delegate:self]; 318 delegate:self];
317 } 319 }
318 return self; 320 return self;
319 } 321 }
320 322
321 - (void)dealloc { 323 - (void)dealloc {
322 _contentView.delegate = nil; 324 self.view.delegate = nil;
323 325
324 _folderView.delegate = nil; 326 _folderView.delegate = nil;
325 327
326 _menuView.delegate = nil; 328 _menuView.delegate = nil;
327 329
328 _editViewController.delegate = nil; 330 _editViewController.delegate = nil;
329 _folderSelector.delegate = nil; 331 _folderSelector.delegate = nil;
330 } 332 }
331 333
332 - (ios::ChromeBrowserState*)browserState { 334 - (ios::ChromeBrowserState*)browserState {
(...skipping 15 matching lines...) Expand all
348 [self updatePrimaryMenuItem:item animated:NO]; 350 [self updatePrimaryMenuItem:item animated:NO];
349 } 351 }
350 352
351 [self moveMenuAndPrimaryViewToAdequateParent]; 353 [self moveMenuAndPrimaryViewToAdequateParent];
352 CGFloat leadingMargin = [self primaryViewLeadingMargin]; 354 CGFloat leadingMargin = [self primaryViewLeadingMargin];
353 355
354 // Prevent the panelView from hijacking the gestures so that the 356 // Prevent the panelView from hijacking the gestures so that the
355 // NTPController's scrollview can still scroll with the gestures. 357 // NTPController's scrollview can still scroll with the gestures.
356 [self.panelView enableSideSwiping:NO]; 358 [self.panelView enableSideSwiping:NO];
357 359
358 CGFloat width = self.contentView.bounds.size.width; 360 CGFloat width = self.view.bounds.size.width;
359 LayoutRect navBarLayout = 361 LayoutRect navBarLayout =
360 LayoutRectMake(leadingMargin, width, 0, width - leadingMargin, 362 LayoutRectMake(leadingMargin, width, 0, width - leadingMargin,
361 CGRectGetHeight([self navigationBarFrame])); 363 CGRectGetHeight([self navigationBarFrame]));
362 self.navigationBar.frame = LayoutRectGetRect(navBarLayout); 364 self.navigationBar.frame = LayoutRectGetRect(navBarLayout);
363 [self.editingBar setFrame:[self editingBarFrame]]; 365 [self.editingBar setFrame:[self editingBarFrame]];
364 366
365 UIInterfaceOrientation orient = GetInterfaceOrientation(); 367 UIInterfaceOrientation orient = GetInterfaceOrientation();
366 [self refreshFrameOfPrimaryView]; 368 [self refreshFrameOfPrimaryView];
367 [[self primaryView] changeOrientation:orient]; 369 [[self primaryView] changeOrientation:orient];
368 [self updateNavigationBarWithDuration:0 orientation:orient]; 370 [self updateNavigationBarWithDuration:0 orientation:orient];
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 [_loader loadURL:url 432 [_loader loadURL:url
431 referrer:web::Referrer() 433 referrer:web::Referrer()
432 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK 434 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK
433 rendererInitiated:NO]; 435 rendererInitiated:NO];
434 } 436 }
435 437
436 #pragma mark - Views 438 #pragma mark - Views
437 439
438 - (void)loadWaitingView { 440 - (void)loadWaitingView {
439 DCHECK(!self.waitForModelView); 441 DCHECK(!self.waitForModelView);
440 DCHECK(self.contentView); 442 DCHECK(self.view);
441 443
442 // Present a waiting view. 444 // Present a waiting view.
443 BookmarkHomeWaitingView* waitingView = 445 BookmarkHomeWaitingView* waitingView =
444 [[BookmarkHomeWaitingView alloc] initWithFrame:self.view.bounds]; 446 [[BookmarkHomeWaitingView alloc] initWithFrame:self.view.bounds];
445 self.waitForModelView = waitingView; 447 self.waitForModelView = waitingView;
446 [self.view addSubview:self.waitForModelView]; 448 [self.view addSubview:self.waitForModelView];
447 [self.waitForModelView startWaiting]; 449 [self.waitForModelView startWaiting];
448 } 450 }
449 451
450 - (void)updateMenuViewLayout { 452 - (void)updateMenuViewLayout {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 self.folderView.autoresizingMask = 509 self.folderView.autoresizingMask =
508 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 510 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
509 } 511 }
510 512
511 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem 513 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem
512 animated:(BOOL)animated { 514 animated:(BOOL)animated {
513 DCHECK(menuItem.type == bookmarks::MenuItemFolder); 515 DCHECK(menuItem.type == bookmarks::MenuItemFolder);
514 if ([self.primaryMenuItem isEqual:menuItem]) 516 if ([self.primaryMenuItem isEqual:menuItem])
515 return; 517 return;
516 518
517 if (![self.contentView superview]) 519 if (![self.view superview])
518 return; 520 return;
519 521
520 [[self primaryView] removeFromSuperview]; 522 [[self primaryView] removeFromSuperview];
521 self.primaryMenuItem = menuItem; 523 self.primaryMenuItem = menuItem;
522 524
523 [self ensureFolderViewExists]; 525 [self ensureFolderViewExists];
524 [self.folderView resetFolder:self.primaryMenuItem.folder]; 526 [self.folderView resetFolder:self.primaryMenuItem.folder];
525 [self.folderView promoStateChangedAnimated:NO]; 527 [self.folderView promoStateChangedAnimated:NO];
526 528
527 [[self primaryView] changeOrientation:GetInterfaceOrientation()]; 529 [[self primaryView] changeOrientation:GetInterfaceOrientation()];
528 [[self primaryView] setScrollsToTop:self.scrollToTop]; 530 [[self primaryView] setScrollsToTop:self.scrollToTop];
529 531
530 [self moveMenuAndPrimaryViewToAdequateParent]; 532 [self moveMenuAndPrimaryViewToAdequateParent];
531 533
532 // [self.contentView sendSubviewToBack:primaryView]; 534 // [self.view sendSubviewToBack:primaryView];
533 [self refreshFrameOfPrimaryView]; 535 [self refreshFrameOfPrimaryView];
534 536
535 self.navigationBar.hidden = NO; 537 self.navigationBar.hidden = NO;
536 [self updateNavigationBarAnimated:animated 538 [self updateNavigationBarAnimated:animated
537 orientation:GetInterfaceOrientation()]; 539 orientation:GetInterfaceOrientation()];
538 540
539 [self.menuView updatePrimaryMenuItem:self.primaryMenuItem]; 541 [self.menuView updatePrimaryMenuItem:self.primaryMenuItem];
540 [self updateEditBarShadow]; 542 [self updateEditBarShadow];
541 } 543 }
542 544
(...skipping 28 matching lines...) Expand all
571 [primaryView removeFromSuperview]; 573 [primaryView removeFromSuperview];
572 574
573 if ([self shouldPresentMenuInSlideInPanel]) { 575 if ([self shouldPresentMenuInSlideInPanel]) {
574 // Create (if needed), and add the panelView to the view hierarchy. 576 // Create (if needed), and add the panelView to the view hierarchy.
575 if (!self.panelView) { 577 if (!self.panelView) {
576 self.panelView = 578 self.panelView =
577 [[BookmarkPanelView alloc] initWithFrame:CGRectZero 579 [[BookmarkPanelView alloc] initWithFrame:CGRectZero
578 menuViewWidth:[self menuWidth]]; 580 menuViewWidth:[self menuWidth]];
579 } 581 }
580 [self.view addSubview:self.panelView]; 582 [self.view addSubview:self.panelView];
581 CGSize size = self.contentView.bounds.size; 583 CGSize size = self.view.bounds.size;
582 CGFloat navBarHeight = CGRectGetHeight([self navigationBarFrame]); 584 CGFloat navBarHeight = CGRectGetHeight([self navigationBarFrame]);
583 LayoutRect panelLayout = LayoutRectMake( 585 LayoutRect panelLayout = LayoutRectMake(
584 0, size.width, navBarHeight, size.width, size.height - navBarHeight); 586 0, size.width, navBarHeight, size.width, size.height - navBarHeight);
585 587
586 // Initialize the panelView with the menuView and the primaryView. 588 // Initialize the panelView with the menuView and the primaryView.
587 [self.panelView setFrame:LayoutRectGetRect(panelLayout)]; 589 [self.panelView setFrame:LayoutRectGetRect(panelLayout)];
588 [self.panelView.menuView addSubview:self.menuView]; 590 [self.panelView.menuView addSubview:self.menuView];
589 self.menuView.frame = self.panelView.menuView.bounds; 591 self.menuView.frame = self.panelView.menuView.bounds;
590 [self.panelView.contentView addSubview:primaryView]; 592 [self.panelView.contentView addSubview:primaryView];
591 } else { 593 } else {
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 [self cachePosition]; 1166 [self cachePosition];
1165 } 1167 }
1166 1168
1167 - (void)dismissModals { 1169 - (void)dismissModals {
1168 [self.actionSheetCoordinator stop]; 1170 [self.actionSheetCoordinator stop];
1169 self.actionSheetCoordinator = nil; 1171 self.actionSheetCoordinator = nil;
1170 [self.editViewController dismiss]; 1172 [self.editViewController dismiss];
1171 } 1173 }
1172 1174
1173 - (void)dismissKeyboard { 1175 - (void)dismissKeyboard {
1174 // Uses self.contentView directly instead of going throught self.view to 1176 // Uses self.view directly instead of going throught self.view to
1175 // avoid creating the view hierarchy unnecessarily. 1177 // avoid creating the view hierarchy unnecessarily.
1176 [self.contentView endEditing:YES]; 1178 [self.view endEditing:YES];
1177 } 1179 }
1178 1180
1179 - (void)setScrollsToTop:(BOOL)enabled { 1181 - (void)setScrollsToTop:(BOOL)enabled {
1180 self.scrollToTop = enabled; 1182 self.scrollToTop = enabled;
1181 [[self primaryView] setScrollsToTop:self.scrollToTop]; 1183 [[self primaryView] setScrollsToTop:self.scrollToTop];
1182 } 1184 }
1183 1185
1184 - (UIView*)view { 1186 - (void)loadView {
1185 if (!self.contentView) { 1187 self.view = [[ContentView alloc] initWithFrame:CGRectZero];
rohitrao (ping after 24h) 2017/04/17 16:11:30 I believe that everything except for this line sho
justincohen 2017/04/17 16:19:06 Done.
1186 _contentView = [[ContentView alloc] initWithFrame:CGRectZero]; 1188 self.view.delegate = self;
1187 _contentView.delegate = self; 1189 self.view.backgroundColor = bookmark_utils_ios::mainBackgroundColor();
1188 self.contentView.backgroundColor = 1190 BookmarkNavigationBar* bar =
1189 bookmark_utils_ios::mainBackgroundColor(); 1191 [[BookmarkNavigationBar alloc] initWithFrame:CGRectZero];
1190 BookmarkNavigationBar* bar = 1192 self.navigationBar = bar;
1191 [[BookmarkNavigationBar alloc] initWithFrame:CGRectZero]; 1193 self.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
1192 self.navigationBar = bar;
1193 self.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
1194 1194
1195 [self.navigationBar setEditTarget:self 1195 [self.navigationBar setEditTarget:self
1196 action:@selector(navigationBarWantsEditing:)]; 1196 action:@selector(navigationBarWantsEditing:)];
1197 [self.navigationBar setBackTarget:self 1197 [self.navigationBar setBackTarget:self action:@selector(navigationBarBack:)];
1198 action:@selector(navigationBarBack:)];
1199 1198
1200 [self.navigationBar setMenuTarget:self 1199 [self.navigationBar setMenuTarget:self action:@selector(toggleMenuAnimated)];
1201 action:@selector(toggleMenuAnimated)];
1202 1200
1203 [self.view addSubview:self.navigationBar]; 1201 [self.view addSubview:self.navigationBar];
1204 1202
1205 if (self.bookmarks->loaded()) 1203 if (self.bookmarks->loaded())
1206 [self loadBookmarkViews]; 1204 [self loadBookmarkViews];
1207 else 1205 else
1208 [self loadWaitingView]; 1206 [self loadWaitingView];
1209 }
1210 return self.contentView;
1211 } 1207 }
1212 1208
1213 - (CGFloat)alphaForBottomShadow { 1209 - (CGFloat)alphaForBottomShadow {
1214 return 0; 1210 return 0;
1215 } 1211 }
1216 1212
1217 #pragma mark - BookmarkModelBridgeObserver 1213 #pragma mark - BookmarkModelBridgeObserver
1218 1214
1219 - (void)bookmarkModelLoaded { 1215 - (void)bookmarkModelLoaded {
1220 if (!self.contentView) 1216 if (!self.view)
1221 return; 1217 return;
1222 1218
1223 DCHECK(self.waitForModelView); 1219 DCHECK(self.waitForModelView);
1224 __weak BookmarkHomeTabletNTPController* weakSelf = self; 1220 __weak BookmarkHomeTabletNTPController* weakSelf = self;
1225 [self.waitForModelView stopWaitingWithCompletion:^{ 1221 [self.waitForModelView stopWaitingWithCompletion:^{
1226 BookmarkHomeTabletNTPController* strongSelf = weakSelf; 1222 BookmarkHomeTabletNTPController* strongSelf = weakSelf;
1227 // Early return if the controller has been deallocated. 1223 // Early return if the controller has been deallocated.
1228 if (!strongSelf) 1224 if (!strongSelf)
1229 return; 1225 return;
1230 [UIView animateWithDuration:0.2 1226 [UIView animateWithDuration:0.2
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 } 1273 }
1278 1274
1279 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell { 1275 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell {
1280 DCHECK([self primaryView].collectionView); 1276 DCHECK([self primaryView].collectionView);
1281 NSIndexPath* indexPath = 1277 NSIndexPath* indexPath =
1282 [[self primaryView].collectionView indexPathForCell:cell]; 1278 [[self primaryView].collectionView indexPathForCell:cell];
1283 return indexPath; 1279 return indexPath;
1284 } 1280 }
1285 1281
1286 @end 1282 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698