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

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

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

Powered by Google App Engine
This is Rietveld 408576698