| 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 } | 231 } |
| 284 | 232 |
| 285 - (void)loadView { | 233 - (void)loadView { |
| 286 CGRect frame = [[UIScreen mainScreen] bounds]; | 234 CGRect frame = [[UIScreen mainScreen] bounds]; |
| 287 self.view = [[UIView alloc] initWithFrame:frame]; | 235 self.view = [[UIView alloc] initWithFrame:frame]; |
| 288 } | 236 } |
| 289 | 237 |
| 290 - (void)resetEditNodes { | 238 - (void)resetEditNodes { |
| 291 _editNodes = std::set<const BookmarkNode*>(); | 239 _editNodes = std::set<const BookmarkNode*>(); |
| 292 _editNodesOrdered = std::vector<const BookmarkNode*>(); | 240 _editNodesOrdered = std::vector<const BookmarkNode*>(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 [self setEditing:NO animated:YES]; | 284 [self setEditing:NO animated:YES]; |
| 337 else | 285 else |
| 338 [self updateEditingStateAnimated:YES]; | 286 [self updateEditingStateAnimated:YES]; |
| 339 } | 287 } |
| 340 | 288 |
| 341 #pragma mark - UIViewController methods | 289 #pragma mark - UIViewController methods |
| 342 | 290 |
| 343 - (void)viewDidLoad { | 291 - (void)viewDidLoad { |
| 344 [super viewDidLoad]; | 292 [super viewDidLoad]; |
| 345 | 293 |
| 346 BookmarkNavigationBar* bar = | 294 self.navigationBar.frame = [self navigationBarFrame]; |
| 347 [[BookmarkNavigationBar alloc] initWithFrame:[self navigationBarFrame]]; | |
| 348 self.navigationBar = bar; | |
| 349 [self.navigationBar setEditTarget:self | 295 [self.navigationBar setEditTarget:self |
| 350 action:@selector(navigationBarWantsEditing:)]; | 296 action:@selector(navigationBarWantsEditing:)]; |
| 351 [self.navigationBar setMenuTarget:self | 297 [self.navigationBar setMenuTarget:self |
| 352 action:@selector(navigationBarToggledMenu:)]; | 298 action:@selector(navigationBarToggledMenu:)]; |
| 353 [self.navigationBar setBackTarget:self action:@selector(navigationBarBack:)]; | 299 [self.navigationBar setBackTarget:self action:@selector(navigationBarBack:)]; |
| 354 [self.navigationBar setCancelTarget:self | 300 [self.navigationBar setCancelTarget:self |
| 355 action:@selector(navigationBarCancel:)]; | 301 action:@selector(navigationBarCancel:)]; |
| 356 | 302 |
| 357 [self.view addSubview:self.navigationBar]; | 303 [self.view addSubview:self.navigationBar]; |
| 358 [self.view bringSubviewToFront:self.navigationBar]; | 304 [self.view bringSubviewToFront:self.navigationBar]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 369 | 315 |
| 370 #pragma mark - Accessibility | 316 #pragma mark - Accessibility |
| 371 | 317 |
| 372 - (BOOL)accessibilityPerformEscape { | 318 - (BOOL)accessibilityPerformEscape { |
| 373 [self delegateDismiss:GURL()]; | 319 [self delegateDismiss:GURL()]; |
| 374 return YES; | 320 return YES; |
| 375 } | 321 } |
| 376 | 322 |
| 377 #pragma mark - Methods duplicated from BookmarkHomeTabletNTPController. | 323 #pragma mark - Methods duplicated from BookmarkHomeTabletNTPController. |
| 378 | 324 |
| 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 { | 325 - (void)loadBookmarkViews { |
| 326 [super loadBookmarkViews]; |
| 392 DCHECK(self.bookmarks->loaded()); | 327 DCHECK(self.bookmarks->loaded()); |
| 393 DCHECK([self isViewLoaded]); | 328 DCHECK([self isViewLoaded]); |
| 394 | 329 |
| 395 self.panelView = | 330 self.folderView.delegate = self; |
| 396 [[BookmarkPanelView alloc] initWithFrame:[self frameForPrimaryView] | 331 [self.folderView setFrame:[self frameForPrimaryView]]; |
| 397 menuViewWidth:kBookmarkMenuWidth]; | 332 |
| 398 self.panelView.autoresizingMask = | 333 [self.panelView setFrame:[self frameForPrimaryView]]; |
| 399 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
| 400 self.panelView.delegate = self; | 334 self.panelView.delegate = self; |
| 401 [self.view insertSubview:self.panelView atIndex:0]; | 335 [self.view insertSubview:self.panelView atIndex:0]; |
| 402 | 336 |
| 403 self.contentView = [[UIView alloc] init]; | 337 self.contentView = [[UIView alloc] init]; |
| 404 self.contentView.frame = self.panelView.contentView.bounds; | 338 self.contentView.frame = self.panelView.contentView.bounds; |
| 405 self.contentView.autoresizingMask = | 339 self.contentView.autoresizingMask = |
| 406 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 340 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 407 [self.panelView.contentView addSubview:self.contentView]; | 341 [self.panelView.contentView addSubview:self.contentView]; |
| 408 | 342 |
| 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; | 343 self.menuView.delegate = self; |
| 415 [self.panelView.menuView addSubview:self.menuView]; | 344 [self.panelView.menuView addSubview:self.menuView]; |
| 416 self.menuView.autoresizingMask = | |
| 417 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
| 418 | 345 |
| 419 // Load the last primary menu item which the user had active. | 346 // Load the last primary menu item which the user had active. |
| 420 BookmarkMenuItem* item = nil; | 347 BookmarkMenuItem* item = nil; |
| 421 CGFloat position = 0; | 348 CGFloat position = 0; |
| 422 BOOL found = | 349 BOOL found = |
| 423 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position); | 350 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position); |
| 424 if (!found) | 351 if (!found) |
| 425 item = [self.menuView defaultMenuItem]; | 352 item = [self.menuView defaultMenuItem]; |
| 426 | 353 |
| 427 [self updatePrimaryMenuItem:item animated:NO]; | 354 [self updatePrimaryMenuItem:item animated:NO]; |
| 428 | 355 |
| 429 if (found) { | 356 if (found) { |
| 430 // If the view has already been laid out, then immediately apply the content | 357 // If the view has already been laid out, then immediately apply the content |
| 431 // position. | 358 // position. |
| 432 if (self.view.window) { | 359 if (self.view.window) { |
| 433 [[self primaryView] applyContentPosition:position]; | 360 [[self primaryView] applyContentPosition:position]; |
| 434 } else { | 361 } else { |
| 435 // Otherwise, save the position to be applied once the view has been laid | 362 // Otherwise, save the position to be applied once the view has been laid |
| 436 // out. | 363 // out. |
| 437 self.cachedContentPosition = [NSNumber numberWithFloat:position]; | 364 self.cachedContentPosition = [NSNumber numberWithFloat:position]; |
| 438 } | 365 } |
| 439 } | 366 } |
| 440 } | 367 } |
| 441 | 368 |
| 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 | 369 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem |
| 457 animated:(BOOL)animated { | 370 animated:(BOOL)animated { |
| 458 DCHECK(menuItem.type == bookmarks::MenuItemFolder); | 371 [super updatePrimaryMenuItem:menuItem]; |
| 459 if ([self.primaryMenuItem isEqual:menuItem]) | |
| 460 return; | |
| 461 | 372 |
| 462 // Disable editing on previous primary view before dismissing it. No need to | 373 // Disable editing on previous primary view before dismissing it. No need to |
| 463 // animate because this view is immediately removed from hierarchy. | 374 // animate because this view is immediately removed from hierarchy. |
| 464 if ([[self primaryMenuItem] supportsEditing]) | 375 if ([[self primaryMenuItem] supportsEditing]) |
| 465 [self.primaryView setEditing:NO animated:NO]; | 376 [self.primaryView setEditing:NO animated:NO]; |
| 466 | 377 |
| 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]; | 378 UIView* primaryView = [self primaryView]; |
| 475 [[self primaryView] changeOrientation:GetInterfaceOrientation()]; | |
| 476 [[self primaryView] setScrollsToTop:!self.scrollingMenuToTop]; | |
| 477 | |
| 478 [self.contentView insertSubview:primaryView atIndex:0]; | 379 [self.contentView insertSubview:primaryView atIndex:0]; |
| 479 primaryView.frame = self.contentView.bounds; | 380 primaryView.frame = self.contentView.bounds; |
| 480 | 381 |
| 481 [self updateNavigationBarAnimated:animated | 382 [self updateNavigationBarAnimated:animated |
| 482 orientation:GetInterfaceOrientation()]; | 383 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 } | 384 } |
| 492 | 385 |
| 493 #pragma mark - Editing bar methods. | 386 #pragma mark - Editing bar methods. |
| 494 | 387 |
| 495 - (void)updateEditingStateAnimated:(BOOL)animated { | 388 - (void)updateEditingStateAnimated:(BOOL)animated { |
| 496 if (!self.editing) { | 389 if (!self.editing) { |
| 497 [self hideEditingBarAnimated:animated]; | 390 [self hideEditingBarAnimated:animated]; |
| 498 [self updateEditBarShadow]; | 391 [self updateEditBarShadow]; |
| 499 [self.panelView enableSideSwiping:YES]; | 392 [self.panelView enableSideSwiping:YES]; |
| 500 return; | 393 return; |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 | 909 |
| 1017 - (void)updateUIForInterfaceOrientation:(UIInterfaceOrientation)orientation | 910 - (void)updateUIForInterfaceOrientation:(UIInterfaceOrientation)orientation |
| 1018 duration:(NSTimeInterval)duration { | 911 duration:(NSTimeInterval)duration { |
| 1019 [[self primaryView] changeOrientation:orientation]; | 912 [[self primaryView] changeOrientation:orientation]; |
| 1020 [self updateNavigationBarWithDuration:duration orientation:orientation]; | 913 [self updateNavigationBarWithDuration:duration orientation:orientation]; |
| 1021 } | 914 } |
| 1022 | 915 |
| 1023 - (void)showMenuAnimated:(BOOL)animated { | 916 - (void)showMenuAnimated:(BOOL)animated { |
| 1024 [self.menuView setScrollsToTop:YES]; | 917 [self.menuView setScrollsToTop:YES]; |
| 1025 [[self primaryView] setScrollsToTop:NO]; | 918 [[self primaryView] setScrollsToTop:NO]; |
| 1026 self.scrollingMenuToTop = YES; | 919 self.scrollToTop = YES; |
| 1027 [self.panelView showMenuAnimated:animated]; | 920 [self.panelView showMenuAnimated:animated]; |
| 1028 [self updateNavigationBarAnimated:animated | 921 [self updateNavigationBarAnimated:animated |
| 1029 orientation:GetInterfaceOrientation()]; | 922 orientation:GetInterfaceOrientation()]; |
| 1030 } | 923 } |
| 1031 | 924 |
| 1032 - (void)hideMenuAnimated:(BOOL)animated updateNavigationBar:(BOOL)update { | 925 - (void)hideMenuAnimated:(BOOL)animated updateNavigationBar:(BOOL)update { |
| 1033 [self.menuView setScrollsToTop:NO]; | 926 [self.menuView setScrollsToTop:NO]; |
| 1034 [[self primaryView] setScrollsToTop:YES]; | 927 [[self primaryView] setScrollsToTop:YES]; |
| 1035 self.scrollingMenuToTop = NO; | 928 self.scrollToTop = NO; |
| 1036 [self.panelView hideMenuAnimated:animated]; | 929 [self.panelView hideMenuAnimated:animated]; |
| 1037 if (update) { | 930 if (update) { |
| 1038 UIInterfaceOrientation orient = GetInterfaceOrientation(); | 931 UIInterfaceOrientation orient = GetInterfaceOrientation(); |
| 1039 [self updateNavigationBarAnimated:animated orientation:orient]; | 932 [self updateNavigationBarAnimated:animated orientation:orient]; |
| 1040 } | 933 } |
| 1041 } | 934 } |
| 1042 | 935 |
| 1043 - (void)dismissModals:(BOOL)animated { | 936 - (void)dismissModals:(BOOL)animated { |
| 1044 [self.actionSheetCoordinator stop]; | 937 [self.actionSheetCoordinator stop]; |
| 1045 self.actionSheetCoordinator = nil; | 938 self.actionSheetCoordinator = nil; |
| 1046 } | 939 } |
| 1047 | 940 |
| 1048 #pragma mark - BookmarkPanelViewDelegate | 941 #pragma mark - BookmarkPanelViewDelegate |
| 1049 | 942 |
| 1050 - (void)bookmarkPanelView:(BookmarkPanelView*)view | 943 - (void)bookmarkPanelView:(BookmarkPanelView*)view |
| 1051 willShowMenu:(BOOL)showMenu | 944 willShowMenu:(BOOL)showMenu |
| 1052 withAnimationDuration:(CGFloat)duration { | 945 withAnimationDuration:(CGFloat)duration { |
| 1053 if (showMenu) { | 946 if (showMenu) { |
| 1054 [self.menuView setScrollsToTop:YES]; | 947 [self.menuView setScrollsToTop:YES]; |
| 1055 [[self primaryView] setScrollsToTop:NO]; | 948 [[self primaryView] setScrollsToTop:NO]; |
| 1056 self.scrollingMenuToTop = YES; | 949 self.scrollToTop = YES; |
| 1057 } else { | 950 } else { |
| 1058 [self.menuView setScrollsToTop:NO]; | 951 [self.menuView setScrollsToTop:NO]; |
| 1059 [[self primaryView] setScrollsToTop:YES]; | 952 [[self primaryView] setScrollsToTop:YES]; |
| 1060 self.scrollingMenuToTop = NO; | 953 self.scrollToTop = NO; |
| 1061 } | 954 } |
| 1062 | 955 |
| 1063 if ([self shouldShowEditButtonWithMenuVisibility:showMenu]) | 956 if ([self shouldShowEditButtonWithMenuVisibility:showMenu]) |
| 1064 [self.navigationBar showEditButtonWithAnimationDuration:duration]; | 957 [self.navigationBar showEditButtonWithAnimationDuration:duration]; |
| 1065 else | 958 else |
| 1066 [self.navigationBar hideEditButtonWithAnimationDuration:duration]; | 959 [self.navigationBar hideEditButtonWithAnimationDuration:duration]; |
| 1067 } | 960 } |
| 1068 | 961 |
| 1069 - (void)bookmarkPanelView:(BookmarkPanelView*)view | 962 - (void)bookmarkPanelView:(BookmarkPanelView*)view |
| 1070 updatedMenuVisibility:(CGFloat)visibility { | 963 updatedMenuVisibility:(CGFloat)visibility { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 | 1114 |
| 1222 - (const std::set<const BookmarkNode*>&)editNodes { | 1115 - (const std::set<const BookmarkNode*>&)editNodes { |
| 1223 return _editNodes; | 1116 return _editNodes; |
| 1224 } | 1117 } |
| 1225 | 1118 |
| 1226 - (void)setEditNodes:(const std::set<const BookmarkNode*>&)editNodes { | 1119 - (void)setEditNodes:(const std::set<const BookmarkNode*>&)editNodes { |
| 1227 _editNodes = editNodes; | 1120 _editNodes = editNodes; |
| 1228 } | 1121 } |
| 1229 | 1122 |
| 1230 @end | 1123 @end |
| OLD | NEW |