| 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 #import "base/ios/weak_nsobject.h" | |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "base/mac/objc_property_releaser.h" | |
| 12 #include "base/mac/scoped_nsobject.h" | |
| 13 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| 14 #include "base/metrics/user_metrics_action.h" | 11 #include "base/metrics/user_metrics_action.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 16 #include "components/bookmarks/browser/bookmark_model.h" | 13 #include "components/bookmarks/browser/bookmark_model.h" |
| 17 #include "components/strings/grit/components_strings.h" | 14 #include "components/strings/grit/components_strings.h" |
| 18 #include "google_apis/gaia/google_service_auth_error.h" | 15 #include "google_apis/gaia/google_service_auth_error.h" |
| 19 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" | 16 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" |
| 20 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 17 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 21 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" | 18 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" |
| 22 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_editing_bar.h" | 19 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_editing_bar.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 35 #import "ios/chrome/browser/ui/bookmarks/bookmark_panel_view.h" | 32 #import "ios/chrome/browser/ui/bookmarks/bookmark_panel_view.h" |
| 36 #import "ios/chrome/browser/ui/bookmarks/bookmark_position_cache.h" | 33 #import "ios/chrome/browser/ui/bookmarks/bookmark_position_cache.h" |
| 37 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_controller.h" | 34 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_controller.h" |
| 38 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 35 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 39 #include "ios/chrome/browser/ui/ui_util.h" | 36 #include "ios/chrome/browser/ui/ui_util.h" |
| 40 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 37 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 41 #include "ios/chrome/grit/ios_strings.h" | 38 #include "ios/chrome/grit/ios_strings.h" |
| 42 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 43 #include "ui/base/l10n/l10n_util_mac.h" | 40 #include "ui/base/l10n/l10n_util_mac.h" |
| 44 | 41 |
| 42 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 43 #error "This file requires ARC support." |
| 44 #endif |
| 45 |
| 45 using bookmarks::BookmarkNode; | 46 using bookmarks::BookmarkNode; |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| 48 const CGFloat kBookmarkMenuWidth = 264; | 49 const CGFloat kBookmarkMenuWidth = 264; |
| 49 } // namespace | 50 } // namespace |
| 50 | 51 |
| 51 @interface BookmarkHomeHandsetViewController ()< | 52 @interface BookmarkHomeHandsetViewController ()< |
| 52 BookmarkEditViewControllerDelegate, | 53 BookmarkEditViewControllerDelegate, |
| 53 BookmarkFolderCollectionViewDelegate, | 54 BookmarkFolderCollectionViewDelegate, |
| 54 BookmarkFolderEditorViewControllerDelegate, | 55 BookmarkFolderEditorViewControllerDelegate, |
| 55 BookmarkFolderViewControllerDelegate, | 56 BookmarkFolderViewControllerDelegate, |
| 56 BookmarkMenuViewDelegate, | 57 BookmarkMenuViewDelegate, |
| 57 BookmarkModelBridgeObserver, | 58 BookmarkModelBridgeObserver, |
| 58 BookmarkPanelViewDelegate, | 59 BookmarkPanelViewDelegate, |
| 59 BookmarkPromoControllerDelegate> { | 60 BookmarkPromoControllerDelegate> { |
| 60 // Bridge to register for bookmark changes. | 61 // Bridge to register for bookmark changes. |
| 61 std::unique_ptr<bookmarks::BookmarkModelBridge> _bridge; | 62 std::unique_ptr<bookmarks::BookmarkModelBridge> _bridge; |
| 62 base::mac::ObjCPropertyReleaser | |
| 63 _propertyReleaser_BookmarkHomeHandsetViewController; | |
| 64 } | 63 } |
| 65 | 64 |
| 66 // This views holds the primary content of this view controller. At any point in | 65 // This views holds the primary content of this view controller. At any point in |
| 67 // time, it contains exactly one of the BookmarkCollectionView subclasses. | 66 // time, it contains exactly one of the BookmarkCollectionView subclasses. |
| 68 @property(nonatomic, retain) UIView* contentView; | 67 @property(nonatomic, strong) UIView* contentView; |
| 69 // The possible views that can be shown from the menu. | 68 // The possible views that can be shown from the menu. |
| 70 @property(nonatomic, retain) BookmarkFolderCollectionView* folderView; | 69 @property(nonatomic, strong) BookmarkFolderCollectionView* folderView; |
| 71 // This view is created and used if the model is not fully loaded yet by the | 70 // This view is created and used if the model is not fully loaded yet by the |
| 72 // time this controller starts. | 71 // time this controller starts. |
| 73 @property(nonatomic, retain) BookmarkHomeWaitingView* waitForModelView; | 72 @property(nonatomic, strong) BookmarkHomeWaitingView* waitForModelView; |
| 74 | 73 |
| 75 // The menu with all the folders and special entries. | 74 // The menu with all the folders and special entries. |
| 76 @property(nonatomic, retain) BookmarkMenuView* menuView; | 75 @property(nonatomic, strong) BookmarkMenuView* menuView; |
| 77 // At any point in time, there is exactly one collection view whose view is part | 76 // At any point in time, there is exactly one collection view whose view is part |
| 78 // of the view hierarchy. This property determine which collection view is | 77 // of the view hierarchy. This property determine which collection view is |
| 79 // visible. Not by accident, this property also reflects the selected menu item | 78 // visible. Not by accident, this property also reflects the selected menu item |
| 80 // in the BookmarkMenuView. | 79 // in the BookmarkMenuView. |
| 81 @property(nonatomic, retain) BookmarkMenuItem* primaryMenuItem; | 80 @property(nonatomic, strong) BookmarkMenuItem* primaryMenuItem; |
| 82 // When the view is first shown on the screen, this property represents the | 81 // When the view is first shown on the screen, this property represents the |
| 83 // cached value of the y of the content offset of the primary view. This | 82 // cached value of the y of the content offset of the primary view. This |
| 84 // property is set to nil after it is used. | 83 // property is set to nil after it is used. |
| 85 @property(nonatomic, retain) NSNumber* cachedContentPosition; | 84 @property(nonatomic, strong) NSNumber* cachedContentPosition; |
| 86 | 85 |
| 87 // The navigation bar sits on top of the main content. | 86 // The navigation bar sits on top of the main content. |
| 88 @property(nonatomic, retain) BookmarkNavigationBar* navigationBar; | 87 @property(nonatomic, strong) BookmarkNavigationBar* navigationBar; |
| 89 // The layout code in this class relies on the assumption that the editingBar | 88 // The layout code in this class relies on the assumption that the editingBar |
| 90 // has the same frame as the navigationBar. | 89 // has the same frame as the navigationBar. |
| 91 @property(nonatomic, retain) BookmarkEditingBar* editingBar; | 90 @property(nonatomic, strong) BookmarkEditingBar* editingBar; |
| 92 | 91 |
| 93 // The action sheet coordinator used when trying to edit a single bookmark. | 92 // The action sheet coordinator used when trying to edit a single bookmark. |
| 94 @property(nonatomic, retain) ActionSheetCoordinator* actionSheetCoordinator; | 93 @property(nonatomic, strong) ActionSheetCoordinator* actionSheetCoordinator; |
| 95 // The view controller used to view and edit a single bookmark. | 94 // The view controller used to view and edit a single bookmark. |
| 96 @property(nonatomic, retain) BookmarkEditViewController* editViewController; | 95 @property(nonatomic, strong) BookmarkEditViewController* editViewController; |
| 97 // The view controller used to pick a folder in which to move the selected | 96 // The view controller used to pick a folder in which to move the selected |
| 98 // bookmarks. | 97 // bookmarks. |
| 99 @property(nonatomic, retain) BookmarkFolderViewController* folderSelector; | 98 @property(nonatomic, strong) BookmarkFolderViewController* folderSelector; |
| 100 // The view controller to present when editing the current folder. | 99 // The view controller to present when editing the current folder. |
| 101 @property(nonatomic, retain) BookmarkFolderEditorViewController* folderEditor; | 100 @property(nonatomic, strong) BookmarkFolderEditorViewController* folderEditor; |
| 102 #pragma mark Specific to this class. | 101 #pragma mark Specific to this class. |
| 103 | 102 |
| 104 // The panel view slides on top of the content to display the menu. | 103 // The panel view slides on top of the content to display the menu. |
| 105 @property(nonatomic, retain) BookmarkPanelView* panelView; | 104 @property(nonatomic, strong) BookmarkPanelView* panelView; |
| 106 | 105 |
| 107 // Either the menu or the primaryView can scrollToTop. | 106 // Either the menu or the primaryView can scrollToTop. |
| 108 @property(nonatomic, assign) BOOL scrollingMenuToTop; | 107 @property(nonatomic, assign) BOOL scrollingMenuToTop; |
| 109 // The controller managing the display of the promo cell and the promo view | 108 // The controller managing the display of the promo cell and the promo view |
| 110 // controller. | 109 // controller. |
| 111 @property(nonatomic, retain) BookmarkPromoController* bookmarkPromoController; | 110 @property(nonatomic, strong) BookmarkPromoController* bookmarkPromoController; |
| 112 | 111 |
| 113 #pragma mark View loading and switching | 112 #pragma mark View loading and switching |
| 114 // This method is called if the view needs to be loaded and the model is not | 113 // This method is called if the view needs to be loaded and the model is not |
| 115 // ready yet. | 114 // ready yet. |
| 116 - (void)loadWaitingView; | 115 - (void)loadWaitingView; |
| 117 // This method should be called at most once in the life-cycle of the | 116 // This method should be called at most once in the life-cycle of the |
| 118 // class. It should be called at the soonest possible time after the | 117 // class. It should be called at the soonest possible time after the |
| 119 // view has been loaded, and the bookmark model is loaded. | 118 // view has been loaded, and the bookmark model is loaded. |
| 120 - (void)loadBookmarkViews; | 119 - (void)loadBookmarkViews; |
| 121 // If the view doesn't exist, create it. | 120 // If the view doesn't exist, create it. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 @synthesize folderEditor = _folderEditor; | 231 @synthesize folderEditor = _folderEditor; |
| 233 | 232 |
| 234 @synthesize panelView = _panelView; | 233 @synthesize panelView = _panelView; |
| 235 @synthesize scrollingMenuToTop = _scrollingMenuToTop; | 234 @synthesize scrollingMenuToTop = _scrollingMenuToTop; |
| 236 @synthesize bookmarkPromoController = _bookmarkPromoController; | 235 @synthesize bookmarkPromoController = _bookmarkPromoController; |
| 237 | 236 |
| 238 - (instancetype)initWithLoader:(id<UrlLoader>)loader | 237 - (instancetype)initWithLoader:(id<UrlLoader>)loader |
| 239 browserState:(ios::ChromeBrowserState*)browserState { | 238 browserState:(ios::ChromeBrowserState*)browserState { |
| 240 self = [super initWithLoader:loader browserState:browserState]; | 239 self = [super initWithLoader:loader browserState:browserState]; |
| 241 if (self) { | 240 if (self) { |
| 242 _propertyReleaser_BookmarkHomeHandsetViewController.Init( | |
| 243 self, [BookmarkHomeHandsetViewController class]); | |
| 244 | |
| 245 _bridge.reset(new bookmarks::BookmarkModelBridge(self, self.bookmarks)); | 241 _bridge.reset(new bookmarks::BookmarkModelBridge(self, self.bookmarks)); |
| 246 // It is important to initialize the promo controller with the browser state | 242 // It is important to initialize the promo controller with the browser state |
| 247 // passed in, as it could be incognito. | 243 // passed in, as it could be incognito. |
| 248 _bookmarkPromoController = | 244 _bookmarkPromoController = |
| 249 [[BookmarkPromoController alloc] initWithBrowserState:browserState | 245 [[BookmarkPromoController alloc] initWithBrowserState:browserState |
| 250 delegate:self]; | 246 delegate:self]; |
| 251 } | 247 } |
| 252 return self; | 248 return self; |
| 253 } | 249 } |
| 254 | 250 |
| 255 - (void)dealloc { | 251 - (void)dealloc { |
| 256 _folderView.delegate = nil; | 252 _folderView.delegate = nil; |
| 257 | 253 |
| 258 _menuView.delegate = nil; | 254 _menuView.delegate = nil; |
| 259 | 255 |
| 260 _editViewController.delegate = nil; | 256 _editViewController.delegate = nil; |
| 261 _folderSelector.delegate = nil; | 257 _folderSelector.delegate = nil; |
| 262 | 258 |
| 263 _panelView.delegate = nil; | 259 _panelView.delegate = nil; |
| 264 [super dealloc]; | |
| 265 } | 260 } |
| 266 | 261 |
| 267 - (void)removeEditNode:(const BookmarkNode*)node | 262 - (void)removeEditNode:(const BookmarkNode*)node |
| 268 cell:(UICollectionViewCell*)cell { | 263 cell:(UICollectionViewCell*)cell { |
| 269 [super removeEditNode:node atIndexPath:[self indexPathForCell:cell]]; | 264 [super removeEditNode:node atIndexPath:[self indexPathForCell:cell]]; |
| 270 if (_editNodes.size() == 0) | 265 if (_editNodes.size() == 0) |
| 271 [self setEditing:NO animated:YES]; | 266 [self setEditing:NO animated:YES]; |
| 272 else | 267 else |
| 273 [self updateEditingStateAnimated:YES]; | 268 [self updateEditingStateAnimated:YES]; |
| 274 } | 269 } |
| 275 | 270 |
| 276 #pragma mark - UIViewController methods | 271 #pragma mark - UIViewController methods |
| 277 | 272 |
| 278 - (void)viewDidLoad { | 273 - (void)viewDidLoad { |
| 279 [super viewDidLoad]; | 274 [super viewDidLoad]; |
| 280 | 275 |
| 281 base::scoped_nsobject<BookmarkNavigationBar> bar( | 276 BookmarkNavigationBar* bar = |
| 282 [[BookmarkNavigationBar alloc] initWithFrame:[self navigationBarFrame]]); | 277 [[BookmarkNavigationBar alloc] initWithFrame:[self navigationBarFrame]]; |
| 283 self.navigationBar = bar; | 278 self.navigationBar = bar; |
| 284 [self.navigationBar setEditTarget:self | 279 [self.navigationBar setEditTarget:self |
| 285 action:@selector(navigationBarWantsEditing:)]; | 280 action:@selector(navigationBarWantsEditing:)]; |
| 286 [self.navigationBar setMenuTarget:self | 281 [self.navigationBar setMenuTarget:self |
| 287 action:@selector(navigationBarToggledMenu:)]; | 282 action:@selector(navigationBarToggledMenu:)]; |
| 288 [self.navigationBar setBackTarget:self action:@selector(navigationBarBack:)]; | 283 [self.navigationBar setBackTarget:self action:@selector(navigationBarBack:)]; |
| 289 [self.navigationBar setCancelTarget:self | 284 [self.navigationBar setCancelTarget:self |
| 290 action:@selector(navigationBarCancel:)]; | 285 action:@selector(navigationBarCancel:)]; |
| 291 | 286 |
| 292 [self.view addSubview:self.navigationBar]; | 287 [self.view addSubview:self.navigationBar]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 309 return YES; | 304 return YES; |
| 310 } | 305 } |
| 311 | 306 |
| 312 #pragma mark - Methods duplicated from BookmarkHomeTabletNTPController. | 307 #pragma mark - Methods duplicated from BookmarkHomeTabletNTPController. |
| 313 | 308 |
| 314 - (void)loadWaitingView { | 309 - (void)loadWaitingView { |
| 315 DCHECK(!self.waitForModelView); | 310 DCHECK(!self.waitForModelView); |
| 316 DCHECK([self isViewLoaded]); | 311 DCHECK([self isViewLoaded]); |
| 317 | 312 |
| 318 // Present a waiting view. | 313 // Present a waiting view. |
| 319 base::scoped_nsobject<BookmarkHomeWaitingView> waitingView( | 314 BookmarkHomeWaitingView* waitingView = |
| 320 [[BookmarkHomeWaitingView alloc] initWithFrame:self.view.bounds]); | 315 [[BookmarkHomeWaitingView alloc] initWithFrame:self.view.bounds]; |
| 321 self.waitForModelView = waitingView; | 316 self.waitForModelView = waitingView; |
| 322 [self.view addSubview:self.waitForModelView]; | 317 [self.view addSubview:self.waitForModelView]; |
| 323 [self.waitForModelView startWaiting]; | 318 [self.waitForModelView startWaiting]; |
| 324 } | 319 } |
| 325 | 320 |
| 326 - (void)loadBookmarkViews { | 321 - (void)loadBookmarkViews { |
| 327 DCHECK(self.bookmarks->loaded()); | 322 DCHECK(self.bookmarks->loaded()); |
| 328 DCHECK([self isViewLoaded]); | 323 DCHECK([self isViewLoaded]); |
| 329 | 324 |
| 330 self.panelView = base::scoped_nsobject<BookmarkPanelView>( | 325 self.panelView = |
| 331 [[BookmarkPanelView alloc] initWithFrame:[self frameForPrimaryView] | 326 [[BookmarkPanelView alloc] initWithFrame:[self frameForPrimaryView] |
| 332 menuViewWidth:kBookmarkMenuWidth]); | 327 menuViewWidth:kBookmarkMenuWidth]; |
| 333 self.panelView.autoresizingMask = | 328 self.panelView.autoresizingMask = |
| 334 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 329 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 335 self.panelView.delegate = self; | 330 self.panelView.delegate = self; |
| 336 [self.view insertSubview:self.panelView atIndex:0]; | 331 [self.view insertSubview:self.panelView atIndex:0]; |
| 337 | 332 |
| 338 self.contentView = base::scoped_nsobject<UIView>([[UIView alloc] init]); | 333 self.contentView = [[UIView alloc] init]; |
| 339 self.contentView.frame = self.panelView.contentView.bounds; | 334 self.contentView.frame = self.panelView.contentView.bounds; |
| 340 self.contentView.autoresizingMask = | 335 self.contentView.autoresizingMask = |
| 341 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 336 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 342 [self.panelView.contentView addSubview:self.contentView]; | 337 [self.panelView.contentView addSubview:self.contentView]; |
| 343 | 338 |
| 344 // The user can swipe the BookmarkPanelView to show the menuView. | 339 // The user can swipe the BookmarkPanelView to show the menuView. |
| 345 // Therefore, it must be created here. | 340 // Therefore, it must be created here. |
| 346 self.menuView = | 341 self.menuView = [[BookmarkMenuView alloc] |
| 347 base::scoped_nsobject<BookmarkMenuView>([[BookmarkMenuView alloc] | 342 initWithBrowserState:self.browserState |
| 348 initWithBrowserState:self.browserState | 343 frame:self.panelView.menuView.bounds]; |
| 349 frame:self.panelView.menuView.bounds]); | |
| 350 self.menuView.delegate = self; | 344 self.menuView.delegate = self; |
| 351 [self.panelView.menuView addSubview:self.menuView]; | 345 [self.panelView.menuView addSubview:self.menuView]; |
| 352 self.menuView.autoresizingMask = | 346 self.menuView.autoresizingMask = |
| 353 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 347 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 354 | 348 |
| 355 // Load the last primary menu item which the user had active. | 349 // Load the last primary menu item which the user had active. |
| 356 BookmarkMenuItem* item = nil; | 350 BookmarkMenuItem* item = nil; |
| 357 CGFloat position = 0; | 351 CGFloat position = 0; |
| 358 BOOL found = | 352 BOOL found = |
| 359 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position); | 353 bookmark_utils_ios::GetPositionCache(self.bookmarks, &item, &position); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 372 // out. | 366 // out. |
| 373 self.cachedContentPosition = [NSNumber numberWithFloat:position]; | 367 self.cachedContentPosition = [NSNumber numberWithFloat:position]; |
| 374 } | 368 } |
| 375 } | 369 } |
| 376 } | 370 } |
| 377 | 371 |
| 378 - (void)ensureFolderViewExists { | 372 - (void)ensureFolderViewExists { |
| 379 if (self.folderView) | 373 if (self.folderView) |
| 380 return; | 374 return; |
| 381 | 375 |
| 382 base::scoped_nsobject<BookmarkFolderCollectionView> view( | 376 BookmarkFolderCollectionView* view = [[BookmarkFolderCollectionView alloc] |
| 383 [[BookmarkFolderCollectionView alloc] | 377 initWithBrowserState:self.browserState |
| 384 initWithBrowserState:self.browserState | 378 frame:[self frameForPrimaryView]]; |
| 385 frame:[self frameForPrimaryView]]); | |
| 386 self.folderView = view; | 379 self.folderView = view; |
| 387 self.folderView.delegate = self; | 380 self.folderView.delegate = self; |
| 388 [self.folderView setEditing:self.editing animated:NO]; | 381 [self.folderView setEditing:self.editing animated:NO]; |
| 389 self.folderView.autoresizingMask = | 382 self.folderView.autoresizingMask = |
| 390 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | 383 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
| 391 } | 384 } |
| 392 | 385 |
| 393 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem | 386 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem |
| 394 animated:(BOOL)animated { | 387 animated:(BOOL)animated { |
| 395 DCHECK(menuItem.type == bookmarks::MenuItemFolder); | 388 DCHECK(menuItem.type == bookmarks::MenuItemFolder); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 424 |
| 432 - (void)updateEditingStateAnimated:(BOOL)animated { | 425 - (void)updateEditingStateAnimated:(BOOL)animated { |
| 433 if (!self.editing) { | 426 if (!self.editing) { |
| 434 [self hideEditingBarAnimated:animated]; | 427 [self hideEditingBarAnimated:animated]; |
| 435 [self updateEditBarShadow]; | 428 [self updateEditBarShadow]; |
| 436 [self.panelView enableSideSwiping:YES]; | 429 [self.panelView enableSideSwiping:YES]; |
| 437 return; | 430 return; |
| 438 } | 431 } |
| 439 | 432 |
| 440 if (!self.editingBar) { | 433 if (!self.editingBar) { |
| 441 self.editingBar = base::scoped_nsobject<BookmarkEditingBar>( | 434 self.editingBar = |
| 442 [[BookmarkEditingBar alloc] initWithFrame:self.navigationBar.frame]); | 435 [[BookmarkEditingBar alloc] initWithFrame:self.navigationBar.frame]; |
| 443 [self.editingBar setCancelTarget:self action:@selector(editingBarCancel)]; | 436 [self.editingBar setCancelTarget:self action:@selector(editingBarCancel)]; |
| 444 [self.editingBar setDeleteTarget:self action:@selector(editingBarDelete)]; | 437 [self.editingBar setDeleteTarget:self action:@selector(editingBarDelete)]; |
| 445 [self.editingBar setMoveTarget:self action:@selector(editingBarMove)]; | 438 [self.editingBar setMoveTarget:self action:@selector(editingBarMove)]; |
| 446 [self.editingBar setEditTarget:self action:@selector(editingBarEdit)]; | 439 [self.editingBar setEditTarget:self action:@selector(editingBarEdit)]; |
| 447 | 440 |
| 448 [self.view addSubview:self.editingBar]; | 441 [self.view addSubview:self.editingBar]; |
| 449 self.editingBar.alpha = 0; | 442 self.editingBar.alpha = 0; |
| 450 } | 443 } |
| 451 | 444 |
| 452 int bookmarkCount = 0; | 445 int bookmarkCount = 0; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 selectedUrlForNavigation:(const GURL&)url { | 588 selectedUrlForNavigation:(const GURL&)url { |
| 596 [self delegateDismiss:url]; | 589 [self delegateDismiss:url]; |
| 597 } | 590 } |
| 598 | 591 |
| 599 - (void)bookmarkCollectionView:(BookmarkCollectionView*)collectionView | 592 - (void)bookmarkCollectionView:(BookmarkCollectionView*)collectionView |
| 600 wantsMenuForBookmark:(const BookmarkNode*)node | 593 wantsMenuForBookmark:(const BookmarkNode*)node |
| 601 onView:(UIView*)view | 594 onView:(UIView*)view |
| 602 forCell:(BookmarkItemCell*)cell { | 595 forCell:(BookmarkItemCell*)cell { |
| 603 DCHECK(!self.editViewController); | 596 DCHECK(!self.editViewController); |
| 604 DCHECK(!self.actionSheetCoordinator); | 597 DCHECK(!self.actionSheetCoordinator); |
| 605 self.actionSheetCoordinator = [[[ActionSheetCoordinator alloc] | 598 self.actionSheetCoordinator = |
| 606 initWithBaseViewController:self | 599 [[ActionSheetCoordinator alloc] initWithBaseViewController:self |
| 607 title:nil | 600 title:nil |
| 608 message:nil | 601 message:nil |
| 609 rect:CGRectZero | 602 rect:CGRectZero |
| 610 view:nil] autorelease]; | 603 view:nil]; |
| 611 base::WeakNSObject<BookmarkHomeHandsetViewController> weakSelf(self); | 604 __weak BookmarkHomeHandsetViewController* weakSelf = self; |
| 612 | 605 |
| 613 // Select action. | 606 // Select action. |
| 614 [self.actionSheetCoordinator | 607 [self.actionSheetCoordinator |
| 615 addItemWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_ACTION_SELECT) | 608 addItemWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_ACTION_SELECT) |
| 616 action:^{ | 609 action:^{ |
| 617 [weakSelf selectFirstNode:node withCell:cell]; | 610 [weakSelf selectFirstNode:node withCell:cell]; |
| 618 weakSelf.get().actionSheetCoordinator = nil; | 611 weakSelf.actionSheetCoordinator = nil; |
| 619 } | 612 } |
| 620 style:UIAlertActionStyleDefault]; | 613 style:UIAlertActionStyleDefault]; |
| 621 | 614 |
| 622 // Edit action. | 615 // Edit action. |
| 623 [self.actionSheetCoordinator | 616 [self.actionSheetCoordinator |
| 624 addItemWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_ACTION_EDIT) | 617 addItemWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_ACTION_EDIT) |
| 625 action:^{ | 618 action:^{ |
| 626 [weakSelf editNode:node]; | 619 [weakSelf editNode:node]; |
| 627 weakSelf.get().actionSheetCoordinator = nil; | 620 weakSelf.actionSheetCoordinator = nil; |
| 628 } | 621 } |
| 629 style:UIAlertActionStyleDefault]; | 622 style:UIAlertActionStyleDefault]; |
| 630 | 623 |
| 631 // Move action. | 624 // Move action. |
| 632 [self.actionSheetCoordinator | 625 [self.actionSheetCoordinator |
| 633 addItemWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_ACTION_MOVE) | 626 addItemWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_ACTION_MOVE) |
| 634 action:^{ | 627 action:^{ |
| 635 std::set<const BookmarkNode*> nodes; | 628 std::set<const BookmarkNode*> nodes; |
| 636 nodes.insert(node); | 629 nodes.insert(node); |
| 637 [weakSelf moveNodes:nodes]; | 630 [weakSelf moveNodes:nodes]; |
| 638 weakSelf.get().actionSheetCoordinator = nil; | 631 weakSelf.actionSheetCoordinator = nil; |
| 639 } | 632 } |
| 640 style:UIAlertActionStyleDefault]; | 633 style:UIAlertActionStyleDefault]; |
| 641 | 634 |
| 642 // Delete action. | 635 // Delete action. |
| 643 [self.actionSheetCoordinator | 636 [self.actionSheetCoordinator |
| 644 addItemWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_ACTION_DELETE) | 637 addItemWithTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_ACTION_DELETE) |
| 645 action:^{ | 638 action:^{ |
| 646 std::set<const BookmarkNode*> nodes; | 639 std::set<const BookmarkNode*> nodes; |
| 647 nodes.insert(node); | 640 nodes.insert(node); |
| 648 [weakSelf deleteNodes:nodes]; | 641 [weakSelf deleteNodes:nodes]; |
| 649 weakSelf.get().actionSheetCoordinator = nil; | 642 weakSelf.actionSheetCoordinator = nil; |
| 650 } | 643 } |
| 651 style:UIAlertActionStyleDestructive]; | 644 style:UIAlertActionStyleDestructive]; |
| 652 | 645 |
| 653 // Cancel action. | 646 // Cancel action. |
| 654 [self.actionSheetCoordinator | 647 [self.actionSheetCoordinator |
| 655 addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL) | 648 addItemWithTitle:l10n_util::GetNSString(IDS_CANCEL) |
| 656 action:^{ | 649 action:^{ |
| 657 weakSelf.get().actionSheetCoordinator = nil; | 650 weakSelf.actionSheetCoordinator = nil; |
| 658 } | 651 } |
| 659 style:UIAlertActionStyleCancel]; | 652 style:UIAlertActionStyleCancel]; |
| 660 | 653 |
| 661 [self.actionSheetCoordinator start]; | 654 [self.actionSheetCoordinator start]; |
| 662 } | 655 } |
| 663 | 656 |
| 664 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view | 657 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view |
| 665 didLongPressCell:(UICollectionViewCell*)cell | 658 didLongPressCell:(UICollectionViewCell*)cell |
| 666 forBookmark:(const BookmarkNode*)node { | 659 forBookmark:(const BookmarkNode*)node { |
| 667 [self selectFirstNode:node withCell:cell]; | 660 [self selectFirstNode:node withCell:cell]; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 696 if (node->is_folder()) { | 689 if (node->is_folder()) { |
| 697 BookmarkFolderEditorViewController* folderEditor = | 690 BookmarkFolderEditorViewController* folderEditor = |
| 698 [BookmarkFolderEditorViewController | 691 [BookmarkFolderEditorViewController |
| 699 folderEditorWithBookmarkModel:self.bookmarks | 692 folderEditorWithBookmarkModel:self.bookmarks |
| 700 folder:node | 693 folder:node |
| 701 browserState:self.browserState]; | 694 browserState:self.browserState]; |
| 702 folderEditor.delegate = self; | 695 folderEditor.delegate = self; |
| 703 self.folderEditor = folderEditor; | 696 self.folderEditor = folderEditor; |
| 704 editorController = folderEditor; | 697 editorController = folderEditor; |
| 705 } else { | 698 } else { |
| 706 base::scoped_nsobject<BookmarkEditViewController> controller([ | 699 BookmarkEditViewController* controller = |
| 707 [BookmarkEditViewController alloc] initWithBookmark:node | 700 [[BookmarkEditViewController alloc] initWithBookmark:node |
| 708 browserState:self.browserState]); | 701 browserState:self.browserState]; |
| 709 self.editViewController = controller; | 702 self.editViewController = controller; |
| 710 self.editViewController.delegate = self; | 703 self.editViewController.delegate = self; |
| 711 editorController = self.editViewController; | 704 editorController = self.editViewController; |
| 712 } | 705 } |
| 713 DCHECK(editorController); | 706 DCHECK(editorController); |
| 714 base::scoped_nsobject<UINavigationController> navController( | 707 UINavigationController* navController = [[BookmarkNavigationController alloc] |
| 715 [[BookmarkNavigationController alloc] | 708 initWithRootViewController:editorController]; |
| 716 initWithRootViewController:editorController]); | |
| 717 [navController setModalPresentationStyle:UIModalPresentationFormSheet]; | 709 [navController setModalPresentationStyle:UIModalPresentationFormSheet]; |
| 718 [self presentViewController:navController animated:YES completion:NULL]; | 710 [self presentViewController:navController animated:YES completion:NULL]; |
| 719 } | 711 } |
| 720 | 712 |
| 721 - (void)moveNodes:(const std::set<const BookmarkNode*>&)nodes { | 713 - (void)moveNodes:(const std::set<const BookmarkNode*>&)nodes { |
| 722 DCHECK(!self.folderSelector); | 714 DCHECK(!self.folderSelector); |
| 723 DCHECK(nodes.size() > 0); | 715 DCHECK(nodes.size() > 0); |
| 724 const BookmarkNode* editedNode = *(nodes.begin()); | 716 const BookmarkNode* editedNode = *(nodes.begin()); |
| 725 const BookmarkNode* selectedFolder = editedNode->parent(); | 717 const BookmarkNode* selectedFolder = editedNode->parent(); |
| 726 self.folderSelector = base::scoped_nsobject<BookmarkFolderViewController>( | 718 self.folderSelector = [[BookmarkFolderViewController alloc] |
| 727 [[BookmarkFolderViewController alloc] | 719 initWithBookmarkModel:self.bookmarks |
| 728 initWithBookmarkModel:self.bookmarks | 720 allowsNewFolders:YES |
| 729 allowsNewFolders:YES | 721 editedNodes:nodes |
| 730 editedNodes:nodes | 722 allowsCancel:YES |
| 731 allowsCancel:YES | 723 selectedFolder:selectedFolder]; |
| 732 selectedFolder:selectedFolder]); | |
| 733 self.folderSelector.delegate = self; | 724 self.folderSelector.delegate = self; |
| 734 base::scoped_nsobject<UINavigationController> navController( | 725 UINavigationController* navController = [[BookmarkNavigationController alloc] |
| 735 [[BookmarkNavigationController alloc] | 726 initWithRootViewController:self.folderSelector]; |
| 736 initWithRootViewController:self.folderSelector]); | |
| 737 [navController setModalPresentationStyle:UIModalPresentationFormSheet]; | 727 [navController setModalPresentationStyle:UIModalPresentationFormSheet]; |
| 738 [self presentViewController:navController animated:YES completion:NULL]; | 728 [self presentViewController:navController animated:YES completion:NULL]; |
| 739 } | 729 } |
| 740 | 730 |
| 741 - (void)deleteNodes:(const std::set<const BookmarkNode*>&)nodes { | 731 - (void)deleteNodes:(const std::set<const BookmarkNode*>&)nodes { |
| 742 DCHECK_GE(nodes.size(), 1u); | 732 DCHECK_GE(nodes.size(), 1u); |
| 743 bookmark_utils_ios::DeleteBookmarksWithUndoToast(nodes, self.bookmarks, | 733 bookmark_utils_ios::DeleteBookmarksWithUndoToast(nodes, self.bookmarks, |
| 744 self.browserState); | 734 self.browserState); |
| 745 } | 735 } |
| 746 | 736 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 DCHECK(self.primaryMenuItem.type == bookmarks::MenuItemFolder); | 881 DCHECK(self.primaryMenuItem.type == bookmarks::MenuItemFolder); |
| 892 const BookmarkNode* folder = self.primaryMenuItem.folder; | 882 const BookmarkNode* folder = self.primaryMenuItem.folder; |
| 893 BookmarkFolderEditorViewController* folderEditor = | 883 BookmarkFolderEditorViewController* folderEditor = |
| 894 [BookmarkFolderEditorViewController | 884 [BookmarkFolderEditorViewController |
| 895 folderEditorWithBookmarkModel:self.bookmarks | 885 folderEditorWithBookmarkModel:self.bookmarks |
| 896 folder:folder | 886 folder:folder |
| 897 browserState:self.browserState]; | 887 browserState:self.browserState]; |
| 898 folderEditor.delegate = self; | 888 folderEditor.delegate = self; |
| 899 self.folderEditor = folderEditor; | 889 self.folderEditor = folderEditor; |
| 900 | 890 |
| 901 base::scoped_nsobject<BookmarkNavigationController> navController( | 891 BookmarkNavigationController* navController = |
| 902 [[BookmarkNavigationController alloc] | 892 [[BookmarkNavigationController alloc] |
| 903 initWithRootViewController:self.folderEditor]); | 893 initWithRootViewController:self.folderEditor]; |
| 904 [navController setModalPresentationStyle:UIModalPresentationFormSheet]; | 894 [navController setModalPresentationStyle:UIModalPresentationFormSheet]; |
| 905 [self presentViewController:navController animated:YES completion:NULL]; | 895 [self presentViewController:navController animated:YES completion:NULL]; |
| 906 } | 896 } |
| 907 | 897 |
| 908 - (void)navigationBarCancel:(id)sender { | 898 - (void)navigationBarCancel:(id)sender { |
| 909 [self delegateDismiss:GURL()]; | 899 [self delegateDismiss:GURL()]; |
| 910 } | 900 } |
| 911 | 901 |
| 912 - (void)navigationBarToggledMenu:(id)sender { | 902 - (void)navigationBarToggledMenu:(id)sender { |
| 913 if ([self.panelView userDrivenAnimationInProgress]) | 903 if ([self.panelView userDrivenAnimationInProgress]) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 [self.navigationBar updateEditButtonVisibility:0]; | 999 [self.navigationBar updateEditButtonVisibility:0]; |
| 1010 } | 1000 } |
| 1011 | 1001 |
| 1012 #pragma mark - BookmarkModelBridgeObserver | 1002 #pragma mark - BookmarkModelBridgeObserver |
| 1013 | 1003 |
| 1014 - (void)bookmarkModelLoaded { | 1004 - (void)bookmarkModelLoaded { |
| 1015 if (![self isViewLoaded]) | 1005 if (![self isViewLoaded]) |
| 1016 return; | 1006 return; |
| 1017 | 1007 |
| 1018 DCHECK(self.waitForModelView); | 1008 DCHECK(self.waitForModelView); |
| 1019 base::WeakNSObject<BookmarkHomeHandsetViewController> weakSelf(self); | 1009 __weak BookmarkHomeHandsetViewController* weakSelf = self; |
| 1020 [self.waitForModelView stopWaitingWithCompletion:^{ | 1010 [self.waitForModelView stopWaitingWithCompletion:^{ |
| 1021 base::scoped_nsobject<BookmarkHomeHandsetViewController> strongSelf( | 1011 BookmarkHomeHandsetViewController* strongSelf = weakSelf; |
| 1022 [weakSelf retain]); | |
| 1023 // Early return if the controller has been deallocated. | 1012 // Early return if the controller has been deallocated. |
| 1024 if (!strongSelf) | 1013 if (!strongSelf) |
| 1025 return; | 1014 return; |
| 1026 [UIView animateWithDuration:0.2 | 1015 [UIView animateWithDuration:0.2 |
| 1027 animations:^{ | 1016 animations:^{ |
| 1028 strongSelf.get().waitForModelView.alpha = 0.0; | 1017 strongSelf.waitForModelView.alpha = 0.0; |
| 1029 } | 1018 } |
| 1030 completion:^(BOOL finished) { | 1019 completion:^(BOOL finished) { |
| 1031 [strongSelf.get().waitForModelView removeFromSuperview]; | 1020 [strongSelf.waitForModelView removeFromSuperview]; |
| 1032 strongSelf.get().waitForModelView = nil; | 1021 strongSelf.waitForModelView = nil; |
| 1033 }]; | 1022 }]; |
| 1034 [strongSelf loadBookmarkViews]; | 1023 [strongSelf loadBookmarkViews]; |
| 1035 }]; | 1024 }]; |
| 1036 } | 1025 } |
| 1037 | 1026 |
| 1038 - (void)bookmarkNodeChanged:(const BookmarkNode*)node { | 1027 - (void)bookmarkNodeChanged:(const BookmarkNode*)node { |
| 1039 // The title of the folder may have changed. | 1028 // The title of the folder may have changed. |
| 1040 if (self.primaryMenuItem.type == bookmarks::MenuItemFolder && | 1029 if (self.primaryMenuItem.type == bookmarks::MenuItemFolder && |
| 1041 self.primaryMenuItem.folder == node) { | 1030 self.primaryMenuItem.folder == node) { |
| 1042 UIInterfaceOrientation orient = GetInterfaceOrientation(); | 1031 UIInterfaceOrientation orient = GetInterfaceOrientation(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 } | 1115 } |
| 1127 | 1116 |
| 1128 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell { | 1117 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell { |
| 1129 DCHECK([self primaryView].collectionView); | 1118 DCHECK([self primaryView].collectionView); |
| 1130 NSIndexPath* indexPath = | 1119 NSIndexPath* indexPath = |
| 1131 [[self primaryView].collectionView indexPathForCell:cell]; | 1120 [[self primaryView].collectionView indexPathForCell:cell]; |
| 1132 return indexPath; | 1121 return indexPath; |
| 1133 } | 1122 } |
| 1134 | 1123 |
| 1135 @end | 1124 @end |
| OLD | NEW |