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

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; 250
251 - (void)loadView {
lpromero 2017/07/07 13:30:09 Not needed anymore as this is no longer a specific
ramyasharma 2017/07/10 06:55:58 Done.
252 self.view = [[UIView alloc] initWithFrame:CGRectZero];
335 } 253 }
336 254
337 #pragma mark - ContentViewDelegate method. 255 - (void)viewWillLayoutSubviews {
338 256 [super viewWillLayoutSubviews];
339 - (void)willLayoutSubviews {
340 if (![self primaryView] && ![self primaryMenuItem] && 257 if (![self primaryView] && ![self primaryMenuItem] &&
341 self.bookmarks->loaded()) { 258 self.bookmarks->loaded()) {
342 BookmarkMenuItem* item = nil; 259 BookmarkMenuItem* item = nil;
343 CGFloat position = 0; 260 CGFloat position = 0;
344 BOOL found = 261 BOOL found =
345 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position); 262 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position);
346 if (!found) 263 if (!found)
347 item = [self.menuView defaultMenuItem]; 264 item = [self.menuView defaultMenuItem];
348 265
349 [self updatePrimaryMenuItem:item animated:NO]; 266 [self updatePrimaryMenuItem:item animated:NO];
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 #pragma mark - private methods 338 #pragma mark - private methods
422 339
423 - (void)loadURL:(const GURL&)url { 340 - (void)loadURL:(const GURL&)url {
424 if (url == GURL() || url.SchemeIs(url::kJavaScriptScheme)) 341 if (url == GURL() || url.SchemeIs(url::kJavaScriptScheme))
425 return; 342 return;
426 343
427 new_tab_page_uma::RecordAction(self.browserState, 344 new_tab_page_uma::RecordAction(self.browserState,
428 new_tab_page_uma::ACTION_OPENED_BOOKMARK); 345 new_tab_page_uma::ACTION_OPENED_BOOKMARK);
429 base::RecordAction( 346 base::RecordAction(
430 base::UserMetricsAction("MobileBookmarkManagerEntryOpened")); 347 base::UserMetricsAction("MobileBookmarkManagerEntryOpened"));
431 [_loader loadURL:url 348 [self.loader loadURL:url
432 referrer:web::Referrer() 349 referrer:web::Referrer()
433 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK 350 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK
434 rendererInitiated:NO]; 351 rendererInitiated:NO];
435 } 352 }
436 353
437 #pragma mark - Views 354 #pragma mark - Views
438 355
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 { 356 - (void)updateMenuViewLayout {
452 LayoutRect menuLayout = 357 LayoutRect menuLayout =
453 LayoutRectMake(0, self.view.bounds.size.width, 0, self.menuWidth, 358 LayoutRectMake(0, self.view.bounds.size.width, 0, self.menuWidth,
454 self.view.bounds.size.height); 359 self.view.bounds.size.height);
455 self.menuView.frame = LayoutRectGetRect(menuLayout); 360 self.menuView.frame = LayoutRectGetRect(menuLayout);
456 } 361 }
457 362
458 - (void)loadBookmarkViews { 363 - (void)loadBookmarkViews {
364 [super loadBookmarkViews];
459 DCHECK(self.bookmarks->loaded()); 365 DCHECK(self.bookmarks->loaded());
460 366
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; 367 self.menuView.delegate = self;
469 self.menuView.autoresizingMask = UIViewAutoresizingFlexibleHeight; 368 self.folderView.delegate = self;
470 369
471 [self moveMenuAndPrimaryViewToAdequateParent]; 370 [self moveMenuAndPrimaryViewToAdequateParent];
472 371
473 // Load the last primary menu item which the user had active. 372 // Load the last primary menu item which the user had active.
474 BookmarkMenuItem* item = nil; 373 BookmarkMenuItem* item = nil;
475 CGFloat position = 0; 374 CGFloat position = 0;
476 BOOL found = 375 BOOL found =
477 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position); 376 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position);
478 if (!found) 377 if (!found)
479 item = [self.menuView defaultMenuItem]; 378 item = [self.menuView defaultMenuItem];
480 379
481 [self updatePrimaryMenuItem:item animated:NO]; 380 [self updatePrimaryMenuItem:item animated:NO];
482 381
483 [[self primaryView] applyContentPosition:position]; 382 [[self primaryView] applyContentPosition:position];
484 383
485 if (found) { 384 if (found) {
486 // If the view has already been laid out, then immediately apply the content 385 // If the view has already been laid out, then immediately apply the content
487 // position. 386 // position.
488 if (self.view.window) { 387 if (self.view.window) {
489 [[self primaryView] applyContentPosition:position]; 388 [[self primaryView] applyContentPosition:position];
490 } else { 389 } else {
491 // Otherwise, save the position to be applied once the view has been laid 390 // Otherwise, save the position to be applied once the view has been laid
492 // out. 391 // out.
493 self.cachedContentPosition = [NSNumber numberWithFloat:position]; 392 self.cachedContentPosition = [NSNumber numberWithFloat:position];
494 } 393 }
495 } 394 }
496 } 395 }
497 396
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 397 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem
513 animated:(BOOL)animated { 398 animated:(BOOL)animated {
514 DCHECK(menuItem.type == bookmarks::MenuItemFolder);
515 if ([self.primaryMenuItem isEqual:menuItem])
516 return;
517
518 if (![self.view superview]) 399 if (![self.view superview])
519 return; 400 return;
520 401
521 [[self primaryView] removeFromSuperview]; 402 [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 403
531 [self moveMenuAndPrimaryViewToAdequateParent]; 404 [self moveMenuAndPrimaryViewToAdequateParent];
532 405
533 // [self.view sendSubviewToBack:primaryView]; 406 // [self.view sendSubviewToBack:primaryView];
534 [self refreshFrameOfPrimaryView]; 407 [self refreshFrameOfPrimaryView];
535 408
536 self.navigationBar.hidden = NO; 409 self.navigationBar.hidden = NO;
537 [self updateNavigationBarAnimated:animated 410 [self updateNavigationBarAnimated:animated
538 orientation:GetInterfaceOrientation()]; 411 orientation:GetInterfaceOrientation()];
539
540 [self.menuView updatePrimaryMenuItem:self.primaryMenuItem];
541 [self updateEditBarShadow]; 412 [self updateEditBarShadow];
542 } 413 }
543 414
544 - (UIView<BookmarkHomePrimaryView>*)primaryView {
545 if (self.primaryMenuItem.type == bookmarks::MenuItemFolder)
546 return self.folderView;
547 return nil;
548 }
549
550 - (BOOL)shouldPresentMenuInSlideInPanel { 415 - (BOOL)shouldPresentMenuInSlideInPanel {
551 return IsCompactTablet(); 416 return IsCompactTablet();
552 } 417 }
553 418
554 - (CGFloat)menuWidth {
555 return kMenuWidth;
556 }
557
558 - (CGFloat)primaryViewLeadingMargin { 419 - (CGFloat)primaryViewLeadingMargin {
559 if ([self shouldPresentMenuInSlideInPanel]) 420 if ([self shouldPresentMenuInSlideInPanel])
560 return 0; 421 return 0;
561 return [self menuWidth]; 422 return [self menuWidth];
562 } 423 }
563 424
564 - (void)moveMenuAndPrimaryViewToAdequateParent { 425 - (void)moveMenuAndPrimaryViewToAdequateParent {
565 // Remove the menuView, panelView, and primaryView from the view hierarchy. 426 // Remove the menuView, panelView, and primaryView from the view hierarchy.
566 if ([self.menuView superview]) 427 if ([self.menuView superview])
567 [self.menuView removeFromSuperview]; 428 [self.menuView removeFromSuperview];
568 if ([self.panelView superview]) 429 if ([self.panelView superview])
569 [self.panelView removeFromSuperview]; 430 [self.panelView removeFromSuperview];
570 UIView* primaryView = [self primaryView]; 431 UIView* primaryView = [self primaryView];
571 if ([primaryView superview]) 432 if ([primaryView superview])
572 [primaryView removeFromSuperview]; 433 [primaryView removeFromSuperview];
573 434
574 if ([self shouldPresentMenuInSlideInPanel]) { 435 if ([self shouldPresentMenuInSlideInPanel]) {
575 // Create (if needed), and add the panelView to the view hierarchy. 436 // add the panelView to the view hierarchy.
lpromero 2017/07/07 13:30:09 Nit: s/add/Add
ramyasharma 2017/07/10 06:55:58 Done.
576 if (!self.panelView) {
577 self.panelView =
578 [[BookmarkPanelView alloc] initWithFrame:CGRectZero
579 menuViewWidth:[self menuWidth]];
580 }
581 [self.view addSubview:self.panelView]; 437 [self.view addSubview:self.panelView];
582 CGSize size = self.view.bounds.size; 438 CGSize size = self.view.bounds.size;
583 CGFloat navBarHeight = CGRectGetHeight([self navigationBarFrame]); 439 CGFloat navBarHeight = CGRectGetHeight([self navigationBarFrame]);
584 LayoutRect panelLayout = LayoutRectMake( 440 LayoutRect panelLayout = LayoutRectMake(
585 0, size.width, navBarHeight, size.width, size.height - navBarHeight); 441 0, size.width, navBarHeight, size.width, size.height - navBarHeight);
586 442
587 // Initialize the panelView with the menuView and the primaryView. 443 // Initialize the panelView with the menuView and the primaryView.
588 [self.panelView setFrame:LayoutRectGetRect(panelLayout)]; 444 [self.panelView setFrame:LayoutRectGetRect(panelLayout)];
589 [self.panelView.menuView addSubview:self.menuView]; 445 [self.panelView.menuView addSubview:self.menuView];
590 self.menuView.frame = self.panelView.menuView.bounds; 446 self.menuView.frame = self.panelView.menuView.bounds;
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 // Uses self.view directly instead of going throught self.view to 1031 // Uses self.view directly instead of going throught self.view to
1176 // avoid creating the view hierarchy unnecessarily. 1032 // avoid creating the view hierarchy unnecessarily.
1177 [self.view endEditing:YES]; 1033 [self.view endEditing:YES];
1178 } 1034 }
1179 1035
1180 - (void)setScrollsToTop:(BOOL)enabled { 1036 - (void)setScrollsToTop:(BOOL)enabled {
1181 self.scrollToTop = enabled; 1037 self.scrollToTop = enabled;
1182 [[self primaryView] setScrollsToTop:self.scrollToTop]; 1038 [[self primaryView] setScrollsToTop:self.scrollToTop];
1183 } 1039 }
1184 1040
1185 - (void)loadView {
1186 self.view = [[ContentView alloc] initWithFrame:CGRectZero];
1187 }
1188
1189 - (void)viewDidLoad { 1041 - (void)viewDidLoad {
1190 [super viewDidLoad]; 1042 [super viewDidLoad];
1191 self.view.delegate = self;
1192 self.view.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); 1043 self.view.backgroundColor = bookmark_utils_ios::mainBackgroundColor();
1193 BookmarkNavigationBar* bar =
1194 [[BookmarkNavigationBar alloc] initWithFrame:CGRectZero];
1195 self.navigationBar = bar;
1196 self.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; 1044 self.navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
1197 1045
1198 [self.navigationBar setEditTarget:self 1046 [self.navigationBar setEditTarget:self
1199 action:@selector(navigationBarWantsEditing:)]; 1047 action:@selector(navigationBarWantsEditing:)];
1200 [self.navigationBar setBackTarget:self action:@selector(navigationBarBack:)]; 1048 [self.navigationBar setBackTarget:self action:@selector(navigationBarBack:)];
1201 1049
1202 [self.navigationBar setMenuTarget:self action:@selector(toggleMenuAnimated)]; 1050 [self.navigationBar setMenuTarget:self action:@selector(toggleMenuAnimated)];
1203 1051
1204 [self.view addSubview:self.navigationBar]; 1052 [self.view addSubview:self.navigationBar];
1205 1053
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1276 } 1124 }
1277 1125
1278 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell { 1126 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell {
1279 DCHECK([self primaryView].collectionView); 1127 DCHECK([self primaryView].collectionView);
1280 NSIndexPath* indexPath = 1128 NSIndexPath* indexPath =
1281 [[self primaryView].collectionView indexPathForCell:cell]; 1129 [[self primaryView].collectionView indexPathForCell:cell];
1282 return indexPath; 1130 return indexPath;
1283 } 1131 }
1284 1132
1285 @end 1133 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698