OLD | NEW |
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_handset_view_controller.h
" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_handset_view_controller.h
" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/user_metrics_action.h" | 10 #include "base/metrics/user_metrics_action.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "ios/chrome/grit/ios_strings.h" | 38 #include "ios/chrome/grit/ios_strings.h" |
39 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
40 #include "ui/base/l10n/l10n_util_mac.h" | 40 #include "ui/base/l10n/l10n_util_mac.h" |
41 | 41 |
42 #if !defined(__has_feature) || !__has_feature(objc_arc) | 42 #if !defined(__has_feature) || !__has_feature(objc_arc) |
43 #error "This file requires ARC support." | 43 #error "This file requires ARC support." |
44 #endif | 44 #endif |
45 | 45 |
46 using bookmarks::BookmarkNode; | 46 using bookmarks::BookmarkNode; |
47 | 47 |
48 namespace { | |
49 const CGFloat kBookmarkMenuWidth = 264; | |
50 } // namespace | |
51 | |
52 @interface BookmarkHomeHandsetViewController ()< | 48 @interface BookmarkHomeHandsetViewController ()< |
53 BookmarkCollectionViewDelegate, | 49 BookmarkCollectionViewDelegate, |
54 BookmarkEditViewControllerDelegate, | 50 BookmarkEditViewControllerDelegate, |
55 BookmarkFolderEditorViewControllerDelegate, | 51 BookmarkFolderEditorViewControllerDelegate, |
56 BookmarkFolderViewControllerDelegate, | 52 BookmarkFolderViewControllerDelegate, |
57 BookmarkMenuViewDelegate, | 53 BookmarkMenuViewDelegate, |
58 BookmarkModelBridgeObserver, | 54 BookmarkModelBridgeObserver, |
59 BookmarkPanelViewDelegate, | 55 BookmarkPanelViewDelegate, |
60 BookmarkPromoControllerDelegate> { | 56 BookmarkPromoControllerDelegate> { |
61 // Bridge to register for bookmark changes. | 57 // Bridge to register for bookmark changes. |
62 std::unique_ptr<bookmarks::BookmarkModelBridge> _bridge; | 58 std::unique_ptr<bookmarks::BookmarkModelBridge> _bridge; |
63 } | 59 } |
64 | 60 |
65 // This views holds the primary content of this view controller. | 61 // This views holds the primary content of this view controller. |
66 // Redefined to be readwrite. | 62 // Redefined to be readwrite. |
67 @property(nonatomic, strong, readwrite) NSMutableArray* editIndexPaths; | 63 @property(nonatomic, strong, readwrite) NSMutableArray* editIndexPaths; |
68 | 64 |
69 // Returns the parent, if all the bookmarks are siblings. | 65 // Returns the parent, if all the bookmarks are siblings. |
70 // Otherwise returns the mobile_node. | 66 // Otherwise returns the mobile_node. |
71 + (const BookmarkNode*) | 67 + (const BookmarkNode*) |
72 defaultMoveFolderFromBookmarks:(const std::set<const BookmarkNode*>&)bookmarks | 68 defaultMoveFolderFromBookmarks:(const std::set<const BookmarkNode*>&)bookmarks |
73 model:(bookmarks::BookmarkModel*)model; | 69 model:(bookmarks::BookmarkModel*)model; |
74 | 70 |
75 // This views holds the primary content of this view controller. | 71 // This views holds the primary content of this view controller. |
76 @property(nonatomic, strong) UIView* contentView; | 72 @property(nonatomic, strong) UIView* contentView; |
77 // The possible views that can be shown from the menu. | |
78 @property(nonatomic, strong) BookmarkCollectionView* folderView; | |
79 // This view is created and used if the model is not fully loaded yet by the | |
80 // time this controller starts. | |
81 @property(nonatomic, strong) BookmarkHomeWaitingView* waitForModelView; | |
82 | 73 |
83 // The menu with all the folders and special entries. | |
84 @property(nonatomic, strong) BookmarkMenuView* menuView; | |
85 // At any point in time, there is exactly one collection view whose view is part | |
86 // of the view hierarchy. This property determine which collection view is | |
87 // visible. Not by accident, this property also reflects the selected menu item | |
88 // in the BookmarkMenuView. | |
89 @property(nonatomic, strong) BookmarkMenuItem* primaryMenuItem; | |
90 // When the view is first shown on the screen, this property represents the | 74 // When the view is first shown on the screen, this property represents the |
91 // cached value of the y of the content offset of the primary view. This | 75 // cached value of the y of the content offset of the primary view. This |
92 // property is set to nil after it is used. | 76 // property is set to nil after it is used. |
93 @property(nonatomic, strong) NSNumber* cachedContentPosition; | 77 @property(nonatomic, strong) NSNumber* cachedContentPosition; |
94 | 78 |
95 // The navigation bar sits on top of the main content. | |
96 @property(nonatomic, strong) BookmarkNavigationBar* navigationBar; | |
97 // The layout code in this class relies on the assumption that the editingBar | 79 // The layout code in this class relies on the assumption that the editingBar |
98 // has the same frame as the navigationBar. | 80 // has the same frame as the navigationBar. |
99 @property(nonatomic, strong) BookmarkEditingBar* editingBar; | 81 @property(nonatomic, strong) BookmarkEditingBar* editingBar; |
100 | 82 |
101 // The action sheet coordinator used when trying to edit a single bookmark. | 83 // The action sheet coordinator used when trying to edit a single bookmark. |
102 @property(nonatomic, strong) ActionSheetCoordinator* actionSheetCoordinator; | 84 @property(nonatomic, strong) ActionSheetCoordinator* actionSheetCoordinator; |
103 // The view controller used to view and edit a single bookmark. | 85 // The view controller used to view and edit a single bookmark. |
104 @property(nonatomic, strong) BookmarkEditViewController* editViewController; | 86 @property(nonatomic, strong) BookmarkEditViewController* editViewController; |
105 // The view controller used to pick a folder in which to move the selected | 87 // The view controller used to pick a folder in which to move the selected |
106 // bookmarks. | 88 // bookmarks. |
107 @property(nonatomic, strong) BookmarkFolderViewController* folderSelector; | 89 @property(nonatomic, strong) BookmarkFolderViewController* folderSelector; |
108 // The view controller to present when editing the current folder. | 90 // The view controller to present when editing the current folder. |
109 @property(nonatomic, strong) BookmarkFolderEditorViewController* folderEditor; | 91 @property(nonatomic, strong) BookmarkFolderEditorViewController* folderEditor; |
110 #pragma mark Specific to this class. | 92 #pragma mark Specific to this class. |
111 | 93 |
112 // The panel view slides on top of the content to display the menu. | |
113 @property(nonatomic, strong) BookmarkPanelView* panelView; | |
114 | |
115 // Either the menu or the primaryView can scrollToTop. | |
116 @property(nonatomic, assign) BOOL scrollingMenuToTop; | |
117 // The controller managing the display of the promo cell and the promo view | 94 // The controller managing the display of the promo cell and the promo view |
118 // controller. | 95 // controller. |
119 @property(nonatomic, strong) BookmarkPromoController* bookmarkPromoController; | 96 @property(nonatomic, strong) BookmarkPromoController* bookmarkPromoController; |
120 | 97 |
121 #pragma mark View loading and switching | 98 #pragma mark View loading and switching |
122 // This method is called if the view needs to be loaded and the model is not | |
123 // ready yet. | |
124 - (void)loadWaitingView; | |
125 // This method should be called at most once in the life-cycle of the | 99 // This method should be called at most once in the life-cycle of the |
126 // class. It should be called at the soonest possible time after the | 100 // class. It should be called at the soonest possible time after the |
127 // view has been loaded, and the bookmark model is loaded. | 101 // view has been loaded, and the bookmark model is loaded. |
128 - (void)loadBookmarkViews; | 102 - (void)loadBookmarkViews; |
129 // If the view doesn't exist, create it. | |
130 - (void)ensureFolderViewExists; | |
131 // Updates the property 'primaryMenuItem'. | 103 // Updates the property 'primaryMenuItem'. |
132 // Updates the UI to reflect the new state of 'primaryMenuItem'. | 104 // Updates the UI to reflect the new state of 'primaryMenuItem'. |
133 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem | 105 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem |
134 animated:(BOOL)animated; | 106 animated:(BOOL)animated; |
135 | 107 |
136 #pragma mark Editing related methods | 108 #pragma mark Editing related methods |
137 // This method statelessly updates the editing top bar from |_editNodes| and | 109 // This method statelessly updates the editing top bar from |_editNodes| and |
138 // |editing|. | 110 // |editing|. |
139 - (void)updateEditingStateAnimated:(BOOL)animated; | 111 - (void)updateEditingStateAnimated:(BOOL)animated; |
140 // Shows or hides the editing bar. | 112 // Shows or hides the editing bar. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // Called when the edit button is pressed on the navigation bar. | 166 // Called when the edit button is pressed on the navigation bar. |
195 - (void)navigationBarWantsEditing:(id)sender; | 167 - (void)navigationBarWantsEditing:(id)sender; |
196 // Called when the cancel button is pressed on the navigation bar. | 168 // Called when the cancel button is pressed on the navigation bar. |
197 - (void)navigationBarCancel:(id)sender; | 169 - (void)navigationBarCancel:(id)sender; |
198 // Called when the menu button is pressed on the navigation bar. | 170 // Called when the menu button is pressed on the navigation bar. |
199 - (void)navigationBarToggledMenu:(id)sender; | 171 - (void)navigationBarToggledMenu:(id)sender; |
200 // Called when the back button is pressed on the navigation bar. | 172 // Called when the back button is pressed on the navigation bar. |
201 - (void)navigationBarBack:(id)sender; | 173 - (void)navigationBarBack:(id)sender; |
202 | 174 |
203 #pragma mark private methods | 175 #pragma mark private methods |
204 // The active collection view that corresponds to primaryMenuItem. | |
205 // This must be implemented by subclass. | |
206 - (UIView<BookmarkHomePrimaryView>*)primaryView; | |
207 // Returns the size of the primary view. | 176 // Returns the size of the primary view. |
208 - (CGRect)frameForPrimaryView; | 177 - (CGRect)frameForPrimaryView; |
209 // Updates the UI to reflect the given orientation, with an animation lasting | 178 // Updates the UI to reflect the given orientation, with an animation lasting |
210 // |duration|. | 179 // |duration|. |
211 - (void)updateUIForInterfaceOrientation:(UIInterfaceOrientation)orientation | 180 - (void)updateUIForInterfaceOrientation:(UIInterfaceOrientation)orientation |
212 duration:(NSTimeInterval)duration; | 181 duration:(NSTimeInterval)duration; |
213 // Shows or hides the menu. | 182 // Shows or hides the menu. |
214 - (void)showMenuAnimated:(BOOL)animated; | 183 - (void)showMenuAnimated:(BOOL)animated; |
215 - (void)hideMenuAnimated:(BOOL)animated updateNavigationBar:(BOOL)update; | 184 - (void)hideMenuAnimated:(BOOL)animated updateNavigationBar:(BOOL)update; |
216 | 185 |
217 // Saves the current position and asks the delegate to open the url. | 186 // Saves the current position and asks the delegate to open the url. |
218 - (void)delegateDismiss:(const GURL&)url; | 187 - (void)delegateDismiss:(const GURL&)url; |
219 | 188 |
220 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell; | 189 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell; |
221 | 190 |
222 @end | 191 @end |
223 | 192 |
224 @implementation BookmarkHomeHandsetViewController | 193 @implementation BookmarkHomeHandsetViewController |
225 @synthesize contentView = _contentView; | 194 @synthesize contentView = _contentView; |
226 @synthesize folderView = _folderView; | |
227 @synthesize waitForModelView = _waitForModelView; | |
228 | 195 |
229 @synthesize menuView = _menuView; | |
230 @synthesize primaryMenuItem = _primaryMenuItem; | |
231 @synthesize cachedContentPosition = _cachedContentPosition; | 196 @synthesize cachedContentPosition = _cachedContentPosition; |
232 @synthesize navigationBar = _navigationBar; | |
233 @synthesize editingBar = _editingBar; | 197 @synthesize editingBar = _editingBar; |
234 | 198 |
235 @synthesize actionSheetCoordinator = _actionSheetCoordinator; | 199 @synthesize actionSheetCoordinator = _actionSheetCoordinator; |
236 @synthesize editViewController = _editViewController; | 200 @synthesize editViewController = _editViewController; |
237 @synthesize folderSelector = _folderSelector; | 201 @synthesize folderSelector = _folderSelector; |
238 @synthesize folderEditor = _folderEditor; | 202 @synthesize folderEditor = _folderEditor; |
239 | 203 |
240 @synthesize panelView = _panelView; | |
241 @synthesize scrollingMenuToTop = _scrollingMenuToTop; | |
242 @synthesize bookmarkPromoController = _bookmarkPromoController; | 204 @synthesize bookmarkPromoController = _bookmarkPromoController; |
243 | 205 |
244 @synthesize delegate = _delegate; | 206 @synthesize delegate = _delegate; |
245 @synthesize editIndexPaths = _editIndexPaths; | 207 @synthesize editIndexPaths = _editIndexPaths; |
246 @synthesize editing = _editing; | 208 @synthesize editing = _editing; |
247 @synthesize bookmarks = _bookmarks; | |
248 @synthesize loader = _loader; | |
249 @synthesize browserState = _browserState; | |
250 | 209 |
251 - (instancetype)initWithLoader:(id<UrlLoader>)loader | 210 - (instancetype)initWithLoader:(id<UrlLoader>)loader |
252 browserState:(ios::ChromeBrowserState*)browserState { | 211 browserState:(ios::ChromeBrowserState*)browserState { |
253 DCHECK(browserState); | 212 self = [super initWithLoader:loader browserState:browserState]; |
254 self = [super initWithNibName:nil bundle:nil]; | |
255 if (self) { | 213 if (self) { |
256 _browserState = browserState->GetOriginalChromeBrowserState(); | |
257 _loader = loader; | |
258 | |
259 _bookmarks = ios::BookmarkModelFactory::GetForBrowserState(_browserState); | |
260 _editIndexPaths = [[NSMutableArray alloc] init]; | 214 _editIndexPaths = [[NSMutableArray alloc] init]; |
261 | 215 |
262 [self resetEditNodes]; | 216 [self resetEditNodes]; |
263 | 217 |
264 _bridge.reset(new bookmarks::BookmarkModelBridge(self, self.bookmarks)); | 218 _bridge.reset(new bookmarks::BookmarkModelBridge(self, self.bookmarks)); |
265 // It is important to initialize the promo controller with the browser state | 219 // It is important to initialize the promo controller with the browser state |
266 // passed in, as it could be incognito. | 220 // passed in, as it could be incognito. |
267 _bookmarkPromoController = | 221 _bookmarkPromoController = |
268 [[BookmarkPromoController alloc] initWithBrowserState:browserState | 222 [[BookmarkPromoController alloc] initWithBrowserState:browserState |
269 delegate:self]; | 223 delegate:self]; |
270 } | 224 } |
271 return self; | 225 return self; |
272 } | 226 } |
273 | 227 |
274 - (void)dealloc { | 228 - (void)dealloc { |
275 _folderView.delegate = nil; | |
276 | |
277 _menuView.delegate = nil; | |
278 | |
279 _editViewController.delegate = nil; | 229 _editViewController.delegate = nil; |
280 _folderSelector.delegate = nil; | 230 _folderSelector.delegate = nil; |
281 | |
282 _panelView.delegate = nil; | |
283 } | |
284 | |
285 - (void)loadView { | |
286 CGRect frame = [[UIScreen mainScreen] bounds]; | |
287 self.view = [[UIView alloc] initWithFrame:frame]; | |
288 } | 231 } |
289 | 232 |
290 - (void)resetEditNodes { | 233 - (void)resetEditNodes { |
291 _editNodes = std::set<const BookmarkNode*>(); | 234 _editNodes = std::set<const BookmarkNode*>(); |
292 _editNodesOrdered = std::vector<const BookmarkNode*>(); | 235 _editNodesOrdered = std::vector<const BookmarkNode*>(); |
293 [self.editIndexPaths removeAllObjects]; | 236 [self.editIndexPaths removeAllObjects]; |
294 } | 237 } |
295 | 238 |
296 - (void)insertEditNode:(const BookmarkNode*)node | 239 - (void)insertEditNode:(const BookmarkNode*)node |
297 atIndexPath:(NSIndexPath*)indexPath { | 240 atIndexPath:(NSIndexPath*)indexPath { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 [self setEditing:NO animated:YES]; | 279 [self setEditing:NO animated:YES]; |
337 else | 280 else |
338 [self updateEditingStateAnimated:YES]; | 281 [self updateEditingStateAnimated:YES]; |
339 } | 282 } |
340 | 283 |
341 #pragma mark - UIViewController methods | 284 #pragma mark - UIViewController methods |
342 | 285 |
343 - (void)viewDidLoad { | 286 - (void)viewDidLoad { |
344 [super viewDidLoad]; | 287 [super viewDidLoad]; |
345 | 288 |
346 BookmarkNavigationBar* bar = | 289 self.navigationBar.frame = [self navigationBarFrame]; |
347 [[BookmarkNavigationBar alloc] initWithFrame:[self navigationBarFrame]]; | |
348 self.navigationBar = bar; | |
349 [self.navigationBar setEditTarget:self | 290 [self.navigationBar setEditTarget:self |
350 action:@selector(navigationBarWantsEditing:)]; | 291 action:@selector(navigationBarWantsEditing:)]; |
351 [self.navigationBar setMenuTarget:self | 292 [self.navigationBar setMenuTarget:self |
352 action:@selector(navigationBarToggledMenu:)]; | 293 action:@selector(navigationBarToggledMenu:)]; |
353 [self.navigationBar setBackTarget:self action:@selector(navigationBarBack:)]; | 294 [self.navigationBar setBackTarget:self action:@selector(navigationBarBack:)]; |
354 [self.navigationBar setCancelTarget:self | 295 [self.navigationBar setCancelTarget:self |
355 action:@selector(navigationBarCancel:)]; | 296 action:@selector(navigationBarCancel:)]; |
356 | 297 |
357 [self.view addSubview:self.navigationBar]; | 298 [self.view addSubview:self.navigationBar]; |
358 [self.view bringSubviewToFront:self.navigationBar]; | 299 [self.view bringSubviewToFront:self.navigationBar]; |
(...skipping 10 matching lines...) Expand all Loading... |
369 | 310 |
370 #pragma mark - Accessibility | 311 #pragma mark - Accessibility |
371 | 312 |
372 - (BOOL)accessibilityPerformEscape { | 313 - (BOOL)accessibilityPerformEscape { |
373 [self delegateDismiss:GURL()]; | 314 [self delegateDismiss:GURL()]; |
374 return YES; | 315 return YES; |
375 } | 316 } |
376 | 317 |
377 #pragma mark - Methods duplicated from BookmarkHomeTabletNTPController. | 318 #pragma mark - Methods duplicated from BookmarkHomeTabletNTPController. |
378 | 319 |
379 - (void)loadWaitingView { | |
380 DCHECK(!self.waitForModelView); | |
381 DCHECK([self isViewLoaded]); | |
382 | |
383 // Present a waiting view. | |
384 BookmarkHomeWaitingView* waitingView = | |
385 [[BookmarkHomeWaitingView alloc] initWithFrame:self.view.bounds]; | |
386 self.waitForModelView = waitingView; | |
387 [self.view addSubview:self.waitForModelView]; | |
388 [self.waitForModelView startWaiting]; | |
389 } | |
390 | |
391 - (void)loadBookmarkViews { | 320 - (void)loadBookmarkViews { |
| 321 [super loadBookmarkViews]; |
392 DCHECK(self.bookmarks->loaded()); | 322 DCHECK(self.bookmarks->loaded()); |
393 DCHECK([self isViewLoaded]); | 323 DCHECK([self isViewLoaded]); |
394 | 324 |
395 self.panelView = | 325 self.folderView.delegate = self; |
396 [[BookmarkPanelView alloc] initWithFrame:[self frameForPrimaryView] | 326 [self.folderView setFrame:[self frameForPrimaryView]]; |
397 menuViewWidth:kBookmarkMenuWidth]; | 327 |
398 self.panelView.autoresizingMask = | 328 [self.panelView setFrame:[self frameForPrimaryView]]; |
399 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
400 self.panelView.delegate = self; | 329 self.panelView.delegate = self; |
401 [self.view insertSubview:self.panelView atIndex:0]; | 330 [self.view insertSubview:self.panelView atIndex:0]; |
402 | 331 |
403 self.contentView = [[UIView alloc] init]; | 332 self.contentView = [[UIView alloc] init]; |
404 self.contentView.frame = self.panelView.contentView.bounds; | 333 self.contentView.frame = self.panelView.contentView.bounds; |
405 self.contentView.autoresizingMask = | 334 self.contentView.autoresizingMask = |
406 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 335 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
407 [self.panelView.contentView addSubview:self.contentView]; | 336 [self.panelView.contentView addSubview:self.contentView]; |
408 | 337 |
409 // The user can swipe the BookmarkPanelView to show the menuView. | |
410 // Therefore, it must be created here. | |
411 self.menuView = [[BookmarkMenuView alloc] | |
412 initWithBrowserState:self.browserState | |
413 frame:self.panelView.menuView.bounds]; | |
414 self.menuView.delegate = self; | 338 self.menuView.delegate = self; |
415 [self.panelView.menuView addSubview:self.menuView]; | 339 [self.panelView.menuView addSubview:self.menuView]; |
416 self.menuView.autoresizingMask = | |
417 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
418 | 340 |
419 // Load the last primary menu item which the user had active. | 341 // Load the last primary menu item which the user had active. |
420 BookmarkMenuItem* item = nil; | 342 BookmarkMenuItem* item = nil; |
421 CGFloat position = 0; | 343 CGFloat position = 0; |
422 BOOL found = | 344 BOOL found = |
423 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position); | 345 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position); |
424 if (!found) | 346 if (!found) |
425 item = [self.menuView defaultMenuItem]; | 347 item = [self.menuView defaultMenuItem]; |
426 | 348 |
427 [self updatePrimaryMenuItem:item animated:NO]; | 349 [self updatePrimaryMenuItem:item animated:NO]; |
428 | 350 |
429 if (found) { | 351 if (found) { |
430 // If the view has already been laid out, then immediately apply the content | 352 // If the view has already been laid out, then immediately apply the content |
431 // position. | 353 // position. |
432 if (self.view.window) { | 354 if (self.view.window) { |
433 [[self primaryView] applyContentPosition:position]; | 355 [[self primaryView] applyContentPosition:position]; |
434 } else { | 356 } else { |
435 // Otherwise, save the position to be applied once the view has been laid | 357 // Otherwise, save the position to be applied once the view has been laid |
436 // out. | 358 // out. |
437 self.cachedContentPosition = [NSNumber numberWithFloat:position]; | 359 self.cachedContentPosition = [NSNumber numberWithFloat:position]; |
438 } | 360 } |
439 } | 361 } |
440 } | 362 } |
441 | 363 |
442 - (void)ensureFolderViewExists { | |
443 if (self.folderView) | |
444 return; | |
445 | |
446 BookmarkCollectionView* view = [[BookmarkCollectionView alloc] | |
447 initWithBrowserState:self.browserState | |
448 frame:[self frameForPrimaryView]]; | |
449 self.folderView = view; | |
450 self.folderView.delegate = self; | |
451 [self.folderView setEditing:self.editing animated:NO]; | |
452 self.folderView.autoresizingMask = | |
453 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | |
454 } | |
455 | |
456 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem | 364 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem |
457 animated:(BOOL)animated { | 365 animated:(BOOL)animated { |
458 DCHECK(menuItem.type == bookmarks::MenuItemFolder); | 366 [super updatePrimaryMenuItem:menuItem]; |
459 if ([self.primaryMenuItem isEqual:menuItem]) | |
460 return; | |
461 | 367 |
462 // Disable editing on previous primary view before dismissing it. No need to | 368 // Disable editing on previous primary view before dismissing it. No need to |
463 // animate because this view is immediately removed from hierarchy. | 369 // animate because this view is immediately removed from hierarchy. |
464 if ([[self primaryMenuItem] supportsEditing]) | 370 if ([[self primaryMenuItem] supportsEditing]) |
465 [self.primaryView setEditing:NO animated:NO]; | 371 [self.primaryView setEditing:NO animated:NO]; |
466 | 372 |
467 [[self primaryView] removeFromSuperview]; | |
468 self.primaryMenuItem = menuItem; | |
469 | |
470 [self ensureFolderViewExists]; | |
471 [self.folderView resetFolder:self.primaryMenuItem.folder]; | |
472 [self.folderView promoStateChangedAnimated:NO]; | |
473 | |
474 UIView* primaryView = [self primaryView]; | 373 UIView* primaryView = [self primaryView]; |
475 [[self primaryView] changeOrientation:GetInterfaceOrientation()]; | |
476 [[self primaryView] setScrollsToTop:!self.scrollingMenuToTop]; | |
477 | |
478 [self.contentView insertSubview:primaryView atIndex:0]; | 374 [self.contentView insertSubview:primaryView atIndex:0]; |
479 primaryView.frame = self.contentView.bounds; | 375 primaryView.frame = self.contentView.bounds; |
480 | 376 |
481 [self updateNavigationBarAnimated:animated | 377 [self updateNavigationBarAnimated:animated |
482 orientation:GetInterfaceOrientation()]; | 378 orientation:GetInterfaceOrientation()]; |
483 | |
484 [self.menuView updatePrimaryMenuItem:self.primaryMenuItem]; | |
485 } | |
486 | |
487 - (UIView<BookmarkHomePrimaryView>*)primaryView { | |
488 if (self.primaryMenuItem.type == bookmarks::MenuItemFolder) | |
489 return self.folderView; | |
490 return nil; | |
491 } | 379 } |
492 | 380 |
493 #pragma mark - Editing bar methods. | 381 #pragma mark - Editing bar methods. |
494 | 382 |
495 - (void)updateEditingStateAnimated:(BOOL)animated { | 383 - (void)updateEditingStateAnimated:(BOOL)animated { |
496 if (!self.editing) { | 384 if (!self.editing) { |
497 [self hideEditingBarAnimated:animated]; | 385 [self hideEditingBarAnimated:animated]; |
498 [self updateEditBarShadow]; | 386 [self updateEditBarShadow]; |
499 [self.panelView enableSideSwiping:YES]; | 387 [self.panelView enableSideSwiping:YES]; |
500 return; | 388 return; |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 | 904 |
1017 - (void)updateUIForInterfaceOrientation:(UIInterfaceOrientation)orientation | 905 - (void)updateUIForInterfaceOrientation:(UIInterfaceOrientation)orientation |
1018 duration:(NSTimeInterval)duration { | 906 duration:(NSTimeInterval)duration { |
1019 [[self primaryView] changeOrientation:orientation]; | 907 [[self primaryView] changeOrientation:orientation]; |
1020 [self updateNavigationBarWithDuration:duration orientation:orientation]; | 908 [self updateNavigationBarWithDuration:duration orientation:orientation]; |
1021 } | 909 } |
1022 | 910 |
1023 - (void)showMenuAnimated:(BOOL)animated { | 911 - (void)showMenuAnimated:(BOOL)animated { |
1024 [self.menuView setScrollsToTop:YES]; | 912 [self.menuView setScrollsToTop:YES]; |
1025 [[self primaryView] setScrollsToTop:NO]; | 913 [[self primaryView] setScrollsToTop:NO]; |
1026 self.scrollingMenuToTop = YES; | 914 self.scrollToTop = YES; |
1027 [self.panelView showMenuAnimated:animated]; | 915 [self.panelView showMenuAnimated:animated]; |
1028 [self updateNavigationBarAnimated:animated | 916 [self updateNavigationBarAnimated:animated |
1029 orientation:GetInterfaceOrientation()]; | 917 orientation:GetInterfaceOrientation()]; |
1030 } | 918 } |
1031 | 919 |
1032 - (void)hideMenuAnimated:(BOOL)animated updateNavigationBar:(BOOL)update { | 920 - (void)hideMenuAnimated:(BOOL)animated updateNavigationBar:(BOOL)update { |
1033 [self.menuView setScrollsToTop:NO]; | 921 [self.menuView setScrollsToTop:NO]; |
1034 [[self primaryView] setScrollsToTop:YES]; | 922 [[self primaryView] setScrollsToTop:YES]; |
1035 self.scrollingMenuToTop = NO; | 923 self.scrollToTop = NO; |
1036 [self.panelView hideMenuAnimated:animated]; | 924 [self.panelView hideMenuAnimated:animated]; |
1037 if (update) { | 925 if (update) { |
1038 UIInterfaceOrientation orient = GetInterfaceOrientation(); | 926 UIInterfaceOrientation orient = GetInterfaceOrientation(); |
1039 [self updateNavigationBarAnimated:animated orientation:orient]; | 927 [self updateNavigationBarAnimated:animated orientation:orient]; |
1040 } | 928 } |
1041 } | 929 } |
1042 | 930 |
1043 - (void)dismissModals:(BOOL)animated { | 931 - (void)dismissModals:(BOOL)animated { |
1044 [self.actionSheetCoordinator stop]; | 932 [self.actionSheetCoordinator stop]; |
1045 self.actionSheetCoordinator = nil; | 933 self.actionSheetCoordinator = nil; |
1046 } | 934 } |
1047 | 935 |
1048 #pragma mark - BookmarkPanelViewDelegate | 936 #pragma mark - BookmarkPanelViewDelegate |
1049 | 937 |
1050 - (void)bookmarkPanelView:(BookmarkPanelView*)view | 938 - (void)bookmarkPanelView:(BookmarkPanelView*)view |
1051 willShowMenu:(BOOL)showMenu | 939 willShowMenu:(BOOL)showMenu |
1052 withAnimationDuration:(CGFloat)duration { | 940 withAnimationDuration:(CGFloat)duration { |
1053 if (showMenu) { | 941 if (showMenu) { |
1054 [self.menuView setScrollsToTop:YES]; | 942 [self.menuView setScrollsToTop:YES]; |
1055 [[self primaryView] setScrollsToTop:NO]; | 943 [[self primaryView] setScrollsToTop:NO]; |
1056 self.scrollingMenuToTop = YES; | 944 self.scrollToTop = YES; |
1057 } else { | 945 } else { |
1058 [self.menuView setScrollsToTop:NO]; | 946 [self.menuView setScrollsToTop:NO]; |
1059 [[self primaryView] setScrollsToTop:YES]; | 947 [[self primaryView] setScrollsToTop:YES]; |
1060 self.scrollingMenuToTop = NO; | 948 self.scrollToTop = NO; |
1061 } | 949 } |
1062 | 950 |
1063 if ([self shouldShowEditButtonWithMenuVisibility:showMenu]) | 951 if ([self shouldShowEditButtonWithMenuVisibility:showMenu]) |
1064 [self.navigationBar showEditButtonWithAnimationDuration:duration]; | 952 [self.navigationBar showEditButtonWithAnimationDuration:duration]; |
1065 else | 953 else |
1066 [self.navigationBar hideEditButtonWithAnimationDuration:duration]; | 954 [self.navigationBar hideEditButtonWithAnimationDuration:duration]; |
1067 } | 955 } |
1068 | 956 |
1069 - (void)bookmarkPanelView:(BookmarkPanelView*)view | 957 - (void)bookmarkPanelView:(BookmarkPanelView*)view |
1070 updatedMenuVisibility:(CGFloat)visibility { | 958 updatedMenuVisibility:(CGFloat)visibility { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 | 1109 |
1222 - (const std::set<const BookmarkNode*>&)editNodes { | 1110 - (const std::set<const BookmarkNode*>&)editNodes { |
1223 return _editNodes; | 1111 return _editNodes; |
1224 } | 1112 } |
1225 | 1113 |
1226 - (void)setEditNodes:(const std::set<const BookmarkNode*>&)editNodes { | 1114 - (void)setEditNodes:(const std::set<const BookmarkNode*>&)editNodes { |
1227 _editNodes = editNodes; | 1115 _editNodes = editNodes; |
1228 } | 1116 } |
1229 | 1117 |
1230 @end | 1118 @end |
OLD | NEW |