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

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

Issue 2972733002: Creates common super class for bookmark handset and tablet view controllers (Closed)
Patch Set: Created 3 years, 5 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "ui/base/l10n/l10n_util_mac.h" 43 #include "ui/base/l10n/l10n_util_mac.h"
44 #include "ui/base/page_transition_types.h" 44 #include "ui/base/page_transition_types.h"
45 45
46 #if !defined(__has_feature) || !__has_feature(objc_arc) 46 #if !defined(__has_feature) || !__has_feature(objc_arc)
47 #error "This file requires ARC support." 47 #error "This file requires ARC support."
48 #endif 48 #endif
49 49
50 using bookmarks::BookmarkNode; 50 using bookmarks::BookmarkNode;
51 51
52 namespace { 52 namespace {
53 // The width of the bookmark menu, displaying the different sections.
54 const CGFloat kMenuWidth = 264.0;
55 // The margin on top to the navigation bar. 53 // The margin on top to the navigation bar.
56 const CGFloat kNavigationBarTopMargin = 8.0; 54 const CGFloat kNavigationBarTopMargin = 8.0;
57 } // namespace 55 } // namespace
58 56
59 // A simple UIView subclass to pass on relayout information to its delegate.
60 @protocol ContentViewDelegate<NSObject>
61 - (void)willLayoutSubviews;
62 @end
63
64 @interface ContentView : UIView
65 @property(nonatomic, weak) id<ContentViewDelegate> delegate;
66 @end
67
68 @implementation ContentView
69 @synthesize delegate = _delegate;
70
71 - (void)layoutSubviews {
72 [self.delegate willLayoutSubviews];
73 [super layoutSubviews];
74 }
75 @end
76
77 @interface BookmarkHomeTabletNTPController ()< 57 @interface BookmarkHomeTabletNTPController ()<
78 BookmarkCollectionViewDelegate, 58 BookmarkCollectionViewDelegate,
79 BookmarkEditViewControllerDelegate, 59 BookmarkEditViewControllerDelegate,
80 BookmarkFolderEditorViewControllerDelegate, 60 BookmarkFolderEditorViewControllerDelegate,
81 BookmarkFolderViewControllerDelegate, 61 BookmarkFolderViewControllerDelegate,
82 BookmarkMenuViewDelegate, 62 BookmarkMenuViewDelegate,
83 BookmarkModelBridgeObserver, 63 BookmarkModelBridgeObserver,
84 BookmarkPromoControllerDelegate, 64 BookmarkPromoControllerDelegate> {
85 ContentViewDelegate> {
86 // Bridge to register for bookmark changes. 65 // Bridge to register for bookmark changes.
87 std::unique_ptr<bookmarks::BookmarkModelBridge> _bridge; 66 std::unique_ptr<bookmarks::BookmarkModelBridge> _bridge;
88 ios::ChromeBrowserState* _browserState; // Weak.
89 __weak id<UrlLoader> _loader;
90 67
91 // The following 2 ivars both represent the set of nodes being edited. 68 // The following 2 ivars both represent the set of nodes being edited.
92 // The set is for fast lookup. 69 // The set is for fast lookup.
93 // The vector maintains the order that edit nodes were added. 70 // The vector maintains the order that edit nodes were added.
94 // Use the relevant instance methods to modify these two ivars in tandem. 71 // Use the relevant instance methods to modify these two ivars in tandem.
95 // DO NOT modify these two ivars directly. 72 // DO NOT modify these two ivars directly.
96 std::set<const BookmarkNode*> _editNodes; 73 std::set<const BookmarkNode*> _editNodes;
97 std::vector<const BookmarkNode*> _editNodesOrdered; 74 std::vector<const BookmarkNode*> _editNodesOrdered;
98 } 75 }
99 76
100 @property(nonatomic, strong) BookmarkPanelView* panelView;
101
102 #pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController 77 #pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController
103 78
104 // Whether the view controller is in editing mode. 79 // Whether the view controller is in editing mode.
105 @property(nonatomic, assign) BOOL editing; 80 @property(nonatomic, assign) BOOL editing;
106 // The set of edited index paths. 81 // The set of edited index paths.
107 @property(nonatomic, strong) NSMutableArray* editIndexPaths; 82 @property(nonatomic, strong) NSMutableArray* editIndexPaths;
108 // The bookmark model used.
109 @property(nonatomic, assign, readonly) bookmarks::BookmarkModel* bookmarks;
110 // The user's browser state model used.
111 @property(nonatomic, assign, readonly)
112 ios::ChromeBrowserState* browserState; // from superclass.
113 83
114 // Replaces |_editNodes| and |_editNodesOrdered| with new container objects. 84 // Replaces |_editNodes| and |_editNodesOrdered| with new container objects.
115 - (void)resetEditNodes; 85 - (void)resetEditNodes;
116 // Adds |node| corresponding to a |cell| if it isn't already present. 86 // Adds |node| corresponding to a |cell| if it isn't already present.
117 - (void)insertEditNode:(const BookmarkNode*)node 87 - (void)insertEditNode:(const BookmarkNode*)node
118 atIndexPath:(NSIndexPath*)indexPath; 88 atIndexPath:(NSIndexPath*)indexPath;
119 // Removes |node| corresponding to a |cell| if it's present. 89 // Removes |node| corresponding to a |cell| if it's present.
120 - (void)removeEditNode:(const BookmarkNode*)node 90 - (void)removeEditNode:(const BookmarkNode*)node
121 atIndexPath:(NSIndexPath*)indexPath; 91 atIndexPath:(NSIndexPath*)indexPath;
122 // This method updates the property, and resets the edit nodes. 92 // This method updates the property, and resets the edit nodes.
123 - (void)setEditing:(BOOL)editing animated:(BOOL)animated; 93 - (void)setEditing:(BOOL)editing animated:(BOOL)animated;
124 94
125 #pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController 95 #pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController
126
127 // This views holds the primary content of this controller.
128 @property(nonatomic, readwrite, strong) ContentView* view;
129
130 // The possible views that can be shown from the menu.
131 @property(nonatomic, strong) BookmarkCollectionView* folderView;
132 // This view is created and used if the model is not fully loaded yet by the
133 // time this controller starts.
134 @property(nonatomic, strong) BookmarkHomeWaitingView* waitForModelView;
135
136 // The menu with all the folders and special entries.
137 @property(nonatomic, strong) BookmarkMenuView* menuView;
138 // 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 // visible. Not by accident, this property also reflects the selected menu item
141 // in the BookmarkMenuView.
142 @property(nonatomic, strong) BookmarkMenuItem* primaryMenuItem;
143 // When the view is first shown on the screen, this property represents the 96 // When the view is first shown on the screen, this property represents the
144 // cached value of the y of the content offset of the primary view. This 97 // cached value of the y of the content offset of the primary view. This
145 // property is set to nil after it is used. 98 // property is set to nil after it is used.
146 @property(nonatomic, strong) 99 @property(nonatomic, strong)
147 NSNumber* cachedContentPosition; // FIXME: INACTIVE 100 NSNumber* cachedContentPosition; // FIXME: INACTIVE
148 101
149 // The navigation bar sits on top of the main content.
150 @property(nonatomic, strong) BookmarkNavigationBar* navigationBar;
151 // The editing bar present when items are selected. 102 // The editing bar present when items are selected.
152 @property(nonatomic, strong) BookmarkEditingBar* editingBar; 103 @property(nonatomic, strong) BookmarkEditingBar* editingBar;
153 104
154 // The action sheet coordinator used when trying to edit a single bookmark. 105 // The action sheet coordinator used when trying to edit a single bookmark.
155 @property(nonatomic, strong) ActionSheetCoordinator* actionSheetCoordinator; 106 @property(nonatomic, strong) ActionSheetCoordinator* actionSheetCoordinator;
156 // The view controller used to view and edit a single bookmark. 107 // The view controller used to view and edit a single bookmark.
157 @property(nonatomic, strong) BookmarkEditViewController* editViewController; 108 @property(nonatomic, strong) BookmarkEditViewController* editViewController;
158 // The view controller used to pick a folder in which to move the selected 109 // The view controller used to pick a folder in which to move the selected
159 // bookmarks. 110 // bookmarks.
160 @property(nonatomic, strong) BookmarkFolderViewController* folderSelector; 111 @property(nonatomic, strong) BookmarkFolderViewController* folderSelector;
161 // The view controller to present when editing the current folder. 112 // The view controller to present when editing the current folder.
162 @property(nonatomic, strong) 113 @property(nonatomic, strong)
163 BookmarkFolderEditorViewController* folderEditor; // FIX 114 BookmarkFolderEditorViewController* folderEditor; // FIX
164 // The controller managing the display of the promo cell and the promo view 115 // The controller managing the display of the promo cell and the promo view
165 // controller. 116 // controller.
166 @property(nonatomic, strong) BookmarkPromoController* bookmarkPromoController; 117 @property(nonatomic, strong) BookmarkPromoController* bookmarkPromoController;
167 118
168 #pragma mark Specific to this class. 119 #pragma mark Specific to this class.
169 120
170 // Either the menu or the primaryView can scrollToTop.
171 @property(nonatomic, assign) BOOL scrollToTop;
172
173 // Opens the url. 121 // Opens the url.
174 - (void)loadURL:(const GURL&)url; 122 - (void)loadURL:(const GURL&)url;
175 #pragma mark View loading, laying out, and switching. 123 #pragma mark View loading, laying out, and switching.
176 // This method is called if the view needs to be loaded and the model is not
177 // ready yet.
178 - (void)loadWaitingView;
179 // This method should be called at most once in the life-cycle of the class. 124 // This method should be called at most once in the life-cycle of the class.
180 // It should be called at the soonest possible time after the view has been 125 // It should be called at the soonest possible time after the view has been
181 // loaded, and the bookmark model is loaded. 126 // loaded, and the bookmark model is loaded.
182 - (void)loadBookmarkViews; 127 - (void)loadBookmarkViews;
183 // If the view doesn't exist, create it.
184 - (void)ensureFolderViewExists;
185 // Updates the property 'primaryMenuItem'. 128 // Updates the property 'primaryMenuItem'.
186 // Updates the UI to reflect the new state of 'primaryMenuItem'. 129 // Updates the UI to reflect the new state of 'primaryMenuItem'.
187 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem 130 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem
188 animated:(BOOL)animated; 131 animated:(BOOL)animated;
189 // The active collection view that corresponds to primaryMenuItem.
190 - (UIView<BookmarkHomePrimaryView>*)primaryView;
191 // Returns whether the menu should be in a side panel that slides in. 132 // Returns whether the menu should be in a side panel that slides in.
192 - (BOOL)shouldPresentMenuInSlideInPanel; 133 - (BOOL)shouldPresentMenuInSlideInPanel;
193 // Returns the width of the menu.
194 - (CGFloat)menuWidth;
195 // Returns the leading margin of the primary view. 134 // Returns the leading margin of the primary view.
196 - (CGFloat)primaryViewLeadingMargin; 135 - (CGFloat)primaryViewLeadingMargin;
197 // Moves the menu and primary view to their correct parent views depending on 136 // Moves the menu and primary view to their correct parent views depending on
198 // the layout. 137 // the layout.
199 - (void)moveMenuAndPrimaryViewToAdequateParent; 138 - (void)moveMenuAndPrimaryViewToAdequateParent;
200 // Updates the frame of the primary view. 139 // Updates the frame of the primary view.
201 - (void)refreshFrameOfPrimaryView; 140 - (void)refreshFrameOfPrimaryView;
202 // Returns the frame of the primary view. 141 // Returns the frame of the primary view.
203 - (CGRect)frameForPrimaryView; 142 - (CGRect)frameForPrimaryView;
204 143
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 - (void)navigationBarBack:(id)sender; 205 - (void)navigationBarBack:(id)sender;
267 206
268 // TODO(crbug.com/450646): This should not be needed but require refactoring of 207 // TODO(crbug.com/450646): This should not be needed but require refactoring of
269 // the BookmarkCollectionViewDelegate. 208 // the BookmarkCollectionViewDelegate.
270 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell; 209 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell;
271 210
272 @end 211 @end
273 212
274 @implementation BookmarkHomeTabletNTPController 213 @implementation BookmarkHomeTabletNTPController
275 214
276 @dynamic view;
277 @synthesize editing = _editing; 215 @synthesize editing = _editing;
278 @synthesize editIndexPaths = _editIndexPaths; 216 @synthesize editIndexPaths = _editIndexPaths;
279 @synthesize bookmarks = _bookmarks;
280
281 @synthesize folderView = _folderView;
282 @synthesize waitForModelView = _waitForModelView;
283
284 @synthesize menuView = _menuView;
285 @synthesize primaryMenuItem = _primaryMenuItem;
286 @synthesize cachedContentPosition = _cachedContentPosition; 217 @synthesize cachedContentPosition = _cachedContentPosition;
287 @synthesize navigationBar = _navigationBar;
288 @synthesize editingBar = _editingBar; 218 @synthesize editingBar = _editingBar;
289 @synthesize panelView = _panelView;
290 219
291 @synthesize actionSheetCoordinator = _actionSheetCoordinator; 220 @synthesize actionSheetCoordinator = _actionSheetCoordinator;
292 @synthesize editViewController = _editViewController; 221 @synthesize editViewController = _editViewController;
293 @synthesize folderSelector = _folderSelector; 222 @synthesize folderSelector = _folderSelector;
294 @synthesize folderEditor = _folderEditor; 223 @synthesize folderEditor = _folderEditor;
295 @synthesize bookmarkPromoController = _bookmarkPromoController; 224 @synthesize bookmarkPromoController = _bookmarkPromoController;
296 225
297 @synthesize scrollToTop = _scrollToTop;
298
299 // Property declared in NewTabPagePanelProtocol. 226 // Property declared in NewTabPagePanelProtocol.
300 @synthesize delegate = _delegate; 227 @synthesize delegate = _delegate;
301 228
302 - (id)initWithLoader:(id<UrlLoader>)loader 229 - (id)initWithLoader:(id<UrlLoader>)loader
303 browserState:(ios::ChromeBrowserState*)browserState { 230 browserState:(ios::ChromeBrowserState*)browserState {
304 self = [super init]; 231 self = [super initWithLoader:loader browserState:browserState];
305 if (self) { 232 if (self) {
306 DCHECK(browserState); 233 _bridge.reset(new bookmarks::BookmarkModelBridge(self, self.bookmarks));
307 _browserState = browserState->GetOriginalChromeBrowserState();
308 _loader = loader;
309
310 _bookmarks = ios::BookmarkModelFactory::GetForBrowserState(_browserState);
311 _bridge.reset(new bookmarks::BookmarkModelBridge(self, _bookmarks));
312 _editIndexPaths = [[NSMutableArray alloc] init]; 234 _editIndexPaths = [[NSMutableArray alloc] init];
313 // It is important to initialize the promo controller with the browser state 235 // It is important to initialize the promo controller with the browser state
314 // passed in, as it could be incognito. 236 // passed in, as it could be incognito.
315 _bookmarkPromoController = 237 _bookmarkPromoController =
316 [[BookmarkPromoController alloc] initWithBrowserState:browserState 238 [[BookmarkPromoController alloc] initWithBrowserState:browserState
317 delegate:self]; 239 delegate:self];
318 } 240 }
319 return self; 241 return self;
320 } 242 }
321 243
322 - (void)dealloc { 244 - (void)dealloc {
323 self.view.delegate = nil;
324
325 _folderView.delegate = nil;
326
327 _menuView.delegate = nil;
328
329 _editViewController.delegate = nil; 245 _editViewController.delegate = nil;
330 _folderSelector.delegate = nil; 246 _folderSelector.delegate = nil;
331 } 247 }
332 248
333 - (ios::ChromeBrowserState*)browserState { 249 #pragma mark - UIViewController method.
334 return _browserState;
335 }
336 250
337 #pragma mark - ContentViewDelegate method. 251 - (void)viewWillLayoutSubviews {
338 252 [super viewWillLayoutSubviews];
339 - (void)willLayoutSubviews {
340 if (![self primaryView] && ![self primaryMenuItem] && 253 if (![self primaryView] && ![self primaryMenuItem] &&
341 self.bookmarks->loaded()) { 254 self.bookmarks->loaded()) {
342 BookmarkMenuItem* item = nil; 255 BookmarkMenuItem* item = nil;
343 CGFloat position = 0; 256 CGFloat position = 0;
344 BOOL found = 257 BOOL found =
345 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position); 258 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position);
346 if (!found) 259 if (!found)
347 item = [self.menuView defaultMenuItem]; 260 item = [self.menuView defaultMenuItem];
348 261
349 [self updatePrimaryMenuItem:item animated:NO]; 262 [self updatePrimaryMenuItem:item animated:NO];
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 #pragma mark - private methods 334 #pragma mark - private methods
422 335
423 - (void)loadURL:(const GURL&)url { 336 - (void)loadURL:(const GURL&)url {
424 if (url == GURL() || url.SchemeIs(url::kJavaScriptScheme)) 337 if (url == GURL() || url.SchemeIs(url::kJavaScriptScheme))
425 return; 338 return;
426 339
427 new_tab_page_uma::RecordAction(self.browserState, 340 new_tab_page_uma::RecordAction(self.browserState,
428 new_tab_page_uma::ACTION_OPENED_BOOKMARK); 341 new_tab_page_uma::ACTION_OPENED_BOOKMARK);
429 base::RecordAction( 342 base::RecordAction(
430 base::UserMetricsAction("MobileBookmarkManagerEntryOpened")); 343 base::UserMetricsAction("MobileBookmarkManagerEntryOpened"));
431 [_loader loadURL:url 344 [self.loader loadURL:url
432 referrer:web::Referrer() 345 referrer:web::Referrer()
433 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK 346 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK
434 rendererInitiated:NO]; 347 rendererInitiated:NO];
435 } 348 }
436 349
437 #pragma mark - Views 350 #pragma mark - Views
438 351
439 - (void)loadWaitingView {
440 DCHECK(!self.waitForModelView);
441 DCHECK(self.view);
442
443 // Present a waiting view.
444 BookmarkHomeWaitingView* waitingView =
445 [[BookmarkHomeWaitingView alloc] initWithFrame:self.view.bounds];
446 self.waitForModelView = waitingView;
447 [self.view addSubview:self.waitForModelView];
448 [self.waitForModelView startWaiting];
449 }
450
451 - (void)updateMenuViewLayout { 352 - (void)updateMenuViewLayout {
452 LayoutRect menuLayout = 353 LayoutRect menuLayout =
453 LayoutRectMake(0, self.view.bounds.size.width, 0, self.menuWidth, 354 LayoutRectMake(0, self.view.bounds.size.width, 0, self.menuWidth,
454 self.view.bounds.size.height); 355 self.view.bounds.size.height);
455 self.menuView.frame = LayoutRectGetRect(menuLayout); 356 self.menuView.frame = LayoutRectGetRect(menuLayout);
456 } 357 }
457 358
458 - (void)loadBookmarkViews { 359 - (void)loadBookmarkViews {
360 [super loadBookmarkViews];
459 DCHECK(self.bookmarks->loaded()); 361 DCHECK(self.bookmarks->loaded());
460 362
461 // Create the menu.
462 LayoutRect menuLayout =
463 LayoutRectMake(0, self.view.bounds.size.width, 0, self.menuWidth,
464 self.view.bounds.size.height);
465 self.menuView = [[BookmarkMenuView alloc]
466 initWithBrowserState:self.browserState
467 frame:LayoutRectGetRect(menuLayout)];
468 self.menuView.delegate = self; 363 self.menuView.delegate = self;
469 self.menuView.autoresizingMask = UIViewAutoresizingFlexibleHeight; 364 self.folderView.delegate = self;
470 365
471 [self moveMenuAndPrimaryViewToAdequateParent]; 366 [self moveMenuAndPrimaryViewToAdequateParent];
472 367
473 // Load the last primary menu item which the user had active. 368 // Load the last primary menu item which the user had active.
474 BookmarkMenuItem* item = nil; 369 BookmarkMenuItem* item = nil;
475 CGFloat position = 0; 370 CGFloat position = 0;
476 BOOL found = 371 BOOL found =
477 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position); 372 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position);
478 if (!found) 373 if (!found)
479 item = [self.menuView defaultMenuItem]; 374 item = [self.menuView defaultMenuItem];
480 375
481 [self updatePrimaryMenuItem:item animated:NO]; 376 [self updatePrimaryMenuItem:item animated:NO];
482 377
483 [[self primaryView] applyContentPosition:position]; 378 [[self primaryView] applyContentPosition:position];
484 379
485 if (found) { 380 if (found) {
486 // If the view has already been laid out, then immediately apply the content 381 // If the view has already been laid out, then immediately apply the content
487 // position. 382 // position.
488 if (self.view.window) { 383 if (self.view.window) {
489 [[self primaryView] applyContentPosition:position]; 384 [[self primaryView] applyContentPosition:position];
490 } else { 385 } else {
491 // Otherwise, save the position to be applied once the view has been laid 386 // Otherwise, save the position to be applied once the view has been laid
492 // out. 387 // out.
493 self.cachedContentPosition = [NSNumber numberWithFloat:position]; 388 self.cachedContentPosition = [NSNumber numberWithFloat:position];
494 } 389 }
495 } 390 }
496 } 391 }
497 392
498 - (void)ensureFolderViewExists {
499 if (self.folderView)
500 return;
501
502 BookmarkCollectionView* view =
503 [[BookmarkCollectionView alloc] initWithBrowserState:self.browserState
504 frame:CGRectZero];
505 self.folderView = view;
506 self.folderView.delegate = self;
507 [self.folderView setEditing:self.editing animated:NO];
508 self.folderView.autoresizingMask =
509 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
510 }
511
512 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem 393 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem
513 animated:(BOOL)animated { 394 animated:(BOOL)animated {
514 DCHECK(menuItem.type == bookmarks::MenuItemFolder);
515 if ([self.primaryMenuItem isEqual:menuItem])
516 return;
517
518 if (![self.view superview]) 395 if (![self.view superview])
519 return; 396 return;
520 397
521 [[self primaryView] removeFromSuperview]; 398 [super updatePrimaryMenuItem:menuItem];
522 self.primaryMenuItem = menuItem;
523
524 [self ensureFolderViewExists];
525 [self.folderView resetFolder:self.primaryMenuItem.folder];
526 [self.folderView promoStateChangedAnimated:NO];
527
528 [[self primaryView] changeOrientation:GetInterfaceOrientation()];
529 [[self primaryView] setScrollsToTop:self.scrollToTop];
530 399
531 [self moveMenuAndPrimaryViewToAdequateParent]; 400 [self moveMenuAndPrimaryViewToAdequateParent];
532 401
533 // [self.view sendSubviewToBack:primaryView]; 402 // [self.view sendSubviewToBack:primaryView];
534 [self refreshFrameOfPrimaryView]; 403 [self refreshFrameOfPrimaryView];
535 404
536 self.navigationBar.hidden = NO; 405 self.navigationBar.hidden = NO;
537 [self updateNavigationBarAnimated:animated 406 [self updateNavigationBarAnimated:animated
538 orientation:GetInterfaceOrientation()]; 407 orientation:GetInterfaceOrientation()];
539
540 [self.menuView updatePrimaryMenuItem:self.primaryMenuItem];
541 [self updateEditBarShadow]; 408 [self updateEditBarShadow];
542 } 409 }
543 410
544 - (UIView<BookmarkHomePrimaryView>*)primaryView {
545 if (self.primaryMenuItem.type == bookmarks::MenuItemFolder)
546 return self.folderView;
547 return nil;
548 }
549
550 - (BOOL)shouldPresentMenuInSlideInPanel { 411 - (BOOL)shouldPresentMenuInSlideInPanel {
551 return IsCompactTablet(); 412 return IsCompactTablet();
552 } 413 }
553 414
554 - (CGFloat)menuWidth {
555 return kMenuWidth;
556 }
557
558 - (CGFloat)primaryViewLeadingMargin { 415 - (CGFloat)primaryViewLeadingMargin {
559 if ([self shouldPresentMenuInSlideInPanel]) 416 if ([self shouldPresentMenuInSlideInPanel])
560 return 0; 417 return 0;
561 return [self menuWidth]; 418 return [self menuWidth];
562 } 419 }
563 420
564 - (void)moveMenuAndPrimaryViewToAdequateParent { 421 - (void)moveMenuAndPrimaryViewToAdequateParent {
565 // Remove the menuView, panelView, and primaryView from the view hierarchy. 422 // Remove the menuView, panelView, and primaryView from the view hierarchy.
566 if ([self.menuView superview]) 423 if ([self.menuView superview])
567 [self.menuView removeFromSuperview]; 424 [self.menuView removeFromSuperview];
568 if ([self.panelView superview]) 425 if ([self.panelView superview])
569 [self.panelView removeFromSuperview]; 426 [self.panelView removeFromSuperview];
570 UIView* primaryView = [self primaryView]; 427 UIView* primaryView = [self primaryView];
571 if ([primaryView superview]) 428 if ([primaryView superview])
572 [primaryView removeFromSuperview]; 429 [primaryView removeFromSuperview];
573 430
574 if ([self shouldPresentMenuInSlideInPanel]) { 431 if ([self shouldPresentMenuInSlideInPanel]) {
575 // Create (if needed), and add the panelView to the view hierarchy. 432 // Add the panelView to the view hierarchy.
576 if (!self.panelView) {
577 self.panelView =
578 [[BookmarkPanelView alloc] initWithFrame:CGRectZero
579 menuViewWidth:[self menuWidth]];
580 }
581 [self.view addSubview:self.panelView]; 433 [self.view addSubview:self.panelView];
582 CGSize size = self.view.bounds.size; 434 CGSize size = self.view.bounds.size;
583 CGFloat navBarHeight = CGRectGetHeight([self navigationBarFrame]); 435 CGFloat navBarHeight = CGRectGetHeight([self navigationBarFrame]);
584 LayoutRect panelLayout = LayoutRectMake( 436 LayoutRect panelLayout = LayoutRectMake(
585 0, size.width, navBarHeight, size.width, size.height - navBarHeight); 437 0, size.width, navBarHeight, size.width, size.height - navBarHeight);
586 438
587 // Initialize the panelView with the menuView and the primaryView. 439 // Initialize the panelView with the menuView and the primaryView.
588 [self.panelView setFrame:LayoutRectGetRect(panelLayout)]; 440 [self.panelView setFrame:LayoutRectGetRect(panelLayout)];
589 [self.panelView.menuView addSubview:self.menuView]; 441 [self.panelView.menuView addSubview:self.menuView];
590 self.menuView.frame = self.panelView.menuView.bounds; 442 self.menuView.frame = self.panelView.menuView.bounds;
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 rootAncestor:rootAncestor]; 1004 rootAncestor:rootAncestor];
1153 [self updatePrimaryMenuItem:menuItem animated:YES]; 1005 [self updatePrimaryMenuItem:menuItem animated:YES];
1154 } 1006 }
1155 1007
1156 #pragma mark - NewTabPagePanelProtocol 1008 #pragma mark - NewTabPagePanelProtocol
1157 1009
1158 - (void)reload { 1010 - (void)reload {
1159 } 1011 }
1160 1012
1161 - (void)wasShown { 1013 - (void)wasShown {
1162 [_folderView wasShown]; 1014 [self.folderView wasShown];
1163 } 1015 }
1164 1016
1165 - (void)wasHidden { 1017 - (void)wasHidden {
1166 [self cachePosition]; 1018 [self cachePosition];
1167 [_folderView wasHidden]; 1019 [self.folderView wasHidden];
1168 } 1020 }
1169 1021
1170 - (void)dismissModals { 1022 - (void)dismissModals {
1171 [self.actionSheetCoordinator stop]; 1023 [self.actionSheetCoordinator stop];
1172 self.actionSheetCoordinator = nil; 1024 self.actionSheetCoordinator = nil;
1173 [self.editViewController dismiss]; 1025 [self.editViewController dismiss];
1174 } 1026 }
1175 1027
1176 - (void)dismissKeyboard { 1028 - (void)dismissKeyboard {
1177 // Uses self.view directly instead of going throught self.view to 1029 // Uses self.view directly instead of going throught self.view to
1178 // avoid creating the view hierarchy unnecessarily. 1030 // avoid creating the view hierarchy unnecessarily.
1179 [self.view endEditing:YES]; 1031 [self.view endEditing:YES];
1180 } 1032 }
1181 1033
1182 - (void)setScrollsToTop:(BOOL)enabled { 1034 - (void)setScrollsToTop:(BOOL)enabled {
1183 self.scrollToTop = enabled; 1035 self.scrollToTop = enabled;
1184 [[self primaryView] setScrollsToTop:self.scrollToTop]; 1036 [[self primaryView] setScrollsToTop:self.scrollToTop];
1185 } 1037 }
1186 1038
1187 - (void)loadView {
1188 self.view = [[ContentView alloc] initWithFrame:CGRectZero];
1189 }
1190
1191 - (void)viewDidLoad { 1039 - (void)viewDidLoad {
1192 [super viewDidLoad]; 1040 [super viewDidLoad];
1193 self.view.delegate = self;
1194 self.view.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); 1041 self.view.backgroundColor = bookmark_utils_ios::mainBackgroundColor();
1195 BookmarkNavigationBar* bar =
1196 [[BookmarkNavigationBar alloc] initWithFrame:CGRectZero];
1197 self.navigationBar = bar;
1198 self.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; 1042 self.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
1199 1043
1200 [self.navigationBar setEditTarget:self 1044 [self.navigationBar setEditTarget:self
1201 action:@selector(navigationBarWantsEditing:)]; 1045 action:@selector(navigationBarWantsEditing:)];
1202 [self.navigationBar setBackTarget:self action:@selector(navigationBarBack:)]; 1046 [self.navigationBar setBackTarget:self action:@selector(navigationBarBack:)];
1203 1047
1204 [self.navigationBar setMenuTarget:self action:@selector(toggleMenuAnimated)]; 1048 [self.navigationBar setMenuTarget:self action:@selector(toggleMenuAnimated)];
1205 1049
1206 [self.view addSubview:self.navigationBar]; 1050 [self.view addSubview:self.navigationBar];
1207 1051
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 } 1122 }
1279 1123
1280 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell { 1124 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell {
1281 DCHECK([self primaryView].collectionView); 1125 DCHECK([self primaryView].collectionView);
1282 NSIndexPath* indexPath = 1126 NSIndexPath* indexPath =
1283 [[self primaryView].collectionView indexPathForCell:cell]; 1127 [[self primaryView].collectionView indexPathForCell:cell];
1284 return indexPath; 1128 return indexPath;
1285 } 1129 }
1286 1130
1287 @end 1131 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698