| 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" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "components/bookmarks/browser/bookmark_model.h" | 12 #include "components/bookmarks/browser/bookmark_model.h" |
| 13 #include "components/strings/grit/components_strings.h" | 13 #include "components/strings/grit/components_strings.h" |
| 14 #include "google_apis/gaia/google_service_auth_error.h" | 14 #include "google_apis/gaia/google_service_auth_error.h" |
| 15 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
| 16 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" | 16 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" |
| 17 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 17 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 18 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" | 18 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" |
| 19 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_editing_bar.h" | 19 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_editing_bar.h" |
| 20 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_navigation_bar.h" | 20 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_navigation_bar.h" |
| 21 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" | 21 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" |
| 22 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view.h" |
| 22 #import "ios/chrome/browser/ui/bookmarks/bookmark_edit_view_controller.h" | 23 #import "ios/chrome/browser/ui/bookmarks/bookmark_edit_view_controller.h" |
| 23 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_collection_view.h" | |
| 24 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_editor_view_controller.
h" | 24 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_editor_view_controller.
h" |
| 25 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h" | 25 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h" |
| 26 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_primary_view.h" | 26 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_primary_view.h" |
| 27 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_waiting_view.h" | 27 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_waiting_view.h" |
| 28 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" | 28 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" |
| 29 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_view.h" | 29 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_view.h" |
| 30 #include "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h" | 30 #include "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h" |
| 31 #import "ios/chrome/browser/ui/bookmarks/bookmark_navigation_controller.h" | 31 #import "ios/chrome/browser/ui/bookmarks/bookmark_navigation_controller.h" |
| 32 #import "ios/chrome/browser/ui/bookmarks/bookmark_panel_view.h" | 32 #import "ios/chrome/browser/ui/bookmarks/bookmark_panel_view.h" |
| 33 #import "ios/chrome/browser/ui/bookmarks/bookmark_position_cache.h" | 33 #import "ios/chrome/browser/ui/bookmarks/bookmark_position_cache.h" |
| 34 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_controller.h" | 34 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_controller.h" |
| 35 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 35 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 36 #include "ios/chrome/browser/ui/ui_util.h" | 36 #include "ios/chrome/browser/ui/ui_util.h" |
| 37 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 37 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 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 { | 48 namespace { |
| 49 const CGFloat kBookmarkMenuWidth = 264; | 49 const CGFloat kBookmarkMenuWidth = 264; |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 @interface BookmarkHomeHandsetViewController ()< | 52 @interface BookmarkHomeHandsetViewController ()< |
| 53 BookmarkCollectionViewDelegate, |
| 53 BookmarkEditViewControllerDelegate, | 54 BookmarkEditViewControllerDelegate, |
| 54 BookmarkFolderCollectionViewDelegate, | |
| 55 BookmarkFolderEditorViewControllerDelegate, | 55 BookmarkFolderEditorViewControllerDelegate, |
| 56 BookmarkFolderViewControllerDelegate, | 56 BookmarkFolderViewControllerDelegate, |
| 57 BookmarkMenuViewDelegate, | 57 BookmarkMenuViewDelegate, |
| 58 BookmarkModelBridgeObserver, | 58 BookmarkModelBridgeObserver, |
| 59 BookmarkPanelViewDelegate, | 59 BookmarkPanelViewDelegate, |
| 60 BookmarkPromoControllerDelegate> { | 60 BookmarkPromoControllerDelegate> { |
| 61 // Bridge to register for bookmark changes. | 61 // Bridge to register for bookmark changes. |
| 62 std::unique_ptr<bookmarks::BookmarkModelBridge> _bridge; | 62 std::unique_ptr<bookmarks::BookmarkModelBridge> _bridge; |
| 63 } | 63 } |
| 64 | 64 |
| 65 // This views holds the primary content of this view controller. |
| 65 // Redefined to be readwrite. | 66 // Redefined to be readwrite. |
| 66 @property(nonatomic, strong, readwrite) NSMutableArray* editIndexPaths; | 67 @property(nonatomic, strong, readwrite) NSMutableArray* editIndexPaths; |
| 67 | 68 |
| 68 // Returns the parent, if all the bookmarks are siblings. | 69 // Returns the parent, if all the bookmarks are siblings. |
| 69 // Otherwise returns the mobile_node. | 70 // Otherwise returns the mobile_node. |
| 70 + (const BookmarkNode*) | 71 + (const BookmarkNode*) |
| 71 defaultMoveFolderFromBookmarks:(const std::set<const BookmarkNode*>&)bookmarks | 72 defaultMoveFolderFromBookmarks:(const std::set<const BookmarkNode*>&)bookmarks |
| 72 model:(bookmarks::BookmarkModel*)model; | 73 model:(bookmarks::BookmarkModel*)model; |
| 73 | 74 |
| 74 // This views holds the primary content of this view controller. At any point in | 75 // This views holds the primary content of this view controller. |
| 75 // time, it contains exactly one of the BookmarkCollectionView subclasses. | |
| 76 @property(nonatomic, strong) UIView* contentView; | 76 @property(nonatomic, strong) UIView* contentView; |
| 77 // The possible views that can be shown from the menu. | 77 // The possible views that can be shown from the menu. |
| 78 @property(nonatomic, strong) BookmarkFolderCollectionView* folderView; | 78 @property(nonatomic, strong) BookmarkCollectionView* folderView; |
| 79 // This view is created and used if the model is not fully loaded yet by the | 79 // This view is created and used if the model is not fully loaded yet by the |
| 80 // time this controller starts. | 80 // time this controller starts. |
| 81 @property(nonatomic, strong) BookmarkHomeWaitingView* waitForModelView; | 81 @property(nonatomic, strong) BookmarkHomeWaitingView* waitForModelView; |
| 82 | 82 |
| 83 // The menu with all the folders and special entries. | 83 // The menu with all the folders and special entries. |
| 84 @property(nonatomic, strong) BookmarkMenuView* menuView; | 84 @property(nonatomic, strong) BookmarkMenuView* menuView; |
| 85 // At any point in time, there is exactly one collection view whose view is part | 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 | 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 | 87 // visible. Not by accident, this property also reflects the selected menu item |
| 88 // in the BookmarkMenuView. | 88 // in the BookmarkMenuView. |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // |duration|. | 210 // |duration|. |
| 211 - (void)updateUIForInterfaceOrientation:(UIInterfaceOrientation)orientation | 211 - (void)updateUIForInterfaceOrientation:(UIInterfaceOrientation)orientation |
| 212 duration:(NSTimeInterval)duration; | 212 duration:(NSTimeInterval)duration; |
| 213 // Shows or hides the menu. | 213 // Shows or hides the menu. |
| 214 - (void)showMenuAnimated:(BOOL)animated; | 214 - (void)showMenuAnimated:(BOOL)animated; |
| 215 - (void)hideMenuAnimated:(BOOL)animated updateNavigationBar:(BOOL)update; | 215 - (void)hideMenuAnimated:(BOOL)animated updateNavigationBar:(BOOL)update; |
| 216 | 216 |
| 217 // Saves the current position and asks the delegate to open the url. | 217 // Saves the current position and asks the delegate to open the url. |
| 218 - (void)delegateDismiss:(const GURL&)url; | 218 - (void)delegateDismiss:(const GURL&)url; |
| 219 | 219 |
| 220 // TODO(crbug.com/450646): This should not be needed but require refactoring of | |
| 221 // the BookmarkCollectionViewDelegate. | |
| 222 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell; | 220 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell; |
| 223 | 221 |
| 224 @end | 222 @end |
| 225 | 223 |
| 226 @implementation BookmarkHomeHandsetViewController | 224 @implementation BookmarkHomeHandsetViewController |
| 227 @synthesize contentView = _contentView; | 225 @synthesize contentView = _contentView; |
| 228 @synthesize folderView = _folderView; | 226 @synthesize folderView = _folderView; |
| 229 @synthesize waitForModelView = _waitForModelView; | 227 @synthesize waitForModelView = _waitForModelView; |
| 230 | 228 |
| 231 @synthesize menuView = _menuView; | 229 @synthesize menuView = _menuView; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 // out. | 436 // out. |
| 439 self.cachedContentPosition = [NSNumber numberWithFloat:position]; | 437 self.cachedContentPosition = [NSNumber numberWithFloat:position]; |
| 440 } | 438 } |
| 441 } | 439 } |
| 442 } | 440 } |
| 443 | 441 |
| 444 - (void)ensureFolderViewExists { | 442 - (void)ensureFolderViewExists { |
| 445 if (self.folderView) | 443 if (self.folderView) |
| 446 return; | 444 return; |
| 447 | 445 |
| 448 BookmarkFolderCollectionView* view = [[BookmarkFolderCollectionView alloc] | 446 BookmarkCollectionView* view = [[BookmarkCollectionView alloc] |
| 449 initWithBrowserState:self.browserState | 447 initWithBrowserState:self.browserState |
| 450 frame:[self frameForPrimaryView]]; | 448 frame:[self frameForPrimaryView]]; |
| 451 self.folderView = view; | 449 self.folderView = view; |
| 452 self.folderView.delegate = self; | 450 self.folderView.delegate = self; |
| 453 [self.folderView setEditing:self.editing animated:NO]; | 451 [self.folderView setEditing:self.editing animated:NO]; |
| 454 self.folderView.autoresizingMask = | 452 self.folderView.autoresizingMask = |
| 455 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | 453 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
| 456 } | 454 } |
| 457 | 455 |
| 458 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem | 456 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 [navController setModalPresentationStyle:UIModalPresentationFormSheet]; | 805 [navController setModalPresentationStyle:UIModalPresentationFormSheet]; |
| 808 [self presentViewController:navController animated:YES completion:NULL]; | 806 [self presentViewController:navController animated:YES completion:NULL]; |
| 809 } | 807 } |
| 810 | 808 |
| 811 - (void)deleteNodes:(const std::set<const BookmarkNode*>&)nodes { | 809 - (void)deleteNodes:(const std::set<const BookmarkNode*>&)nodes { |
| 812 DCHECK_GE(nodes.size(), 1u); | 810 DCHECK_GE(nodes.size(), 1u); |
| 813 bookmark_utils_ios::DeleteBookmarksWithUndoToast(nodes, self.bookmarks, | 811 bookmark_utils_ios::DeleteBookmarksWithUndoToast(nodes, self.bookmarks, |
| 814 self.browserState); | 812 self.browserState); |
| 815 } | 813 } |
| 816 | 814 |
| 817 #pragma mark - BookmarkFolderCollectionViewDelegate | 815 #pragma mark - BookmarkCollectionViewDelegate |
| 818 | 816 |
| 819 - (void)bookmarkFolderCollectionView:(BookmarkFolderCollectionView*)view | 817 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view |
| 820 selectedFolderForNavigation:(const BookmarkNode*)folder { | 818 selectedFolderForNavigation:(const BookmarkNode*)folder { |
| 821 BookmarkMenuItem* menuItem = nil; | 819 BookmarkMenuItem* menuItem = nil; |
| 822 if (view == self.folderView) { | 820 if (view == self.folderView) { |
| 823 const BookmarkNode* parent = RootLevelFolderForNode(folder, self.bookmarks); | 821 const BookmarkNode* parent = RootLevelFolderForNode(folder, self.bookmarks); |
| 824 menuItem = | 822 menuItem = |
| 825 [BookmarkMenuItem folderMenuItemForNode:folder rootAncestor:parent]; | 823 [BookmarkMenuItem folderMenuItemForNode:folder rootAncestor:parent]; |
| 826 } else { | 824 } else { |
| 827 NOTREACHED(); | 825 NOTREACHED(); |
| 828 return; | 826 return; |
| 829 } | 827 } |
| 830 [self updatePrimaryMenuItem:menuItem animated:YES]; | 828 [self updatePrimaryMenuItem:menuItem animated:YES]; |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 | 1221 |
| 1224 - (const std::set<const BookmarkNode*>&)editNodes { | 1222 - (const std::set<const BookmarkNode*>&)editNodes { |
| 1225 return _editNodes; | 1223 return _editNodes; |
| 1226 } | 1224 } |
| 1227 | 1225 |
| 1228 - (void)setEditNodes:(const std::set<const BookmarkNode*>&)editNodes { | 1226 - (void)setEditNodes:(const std::set<const BookmarkNode*>&)editNodes { |
| 1229 _editNodes = editNodes; | 1227 _editNodes = editNodes; |
| 1230 } | 1228 } |
| 1231 | 1229 |
| 1232 @end | 1230 @end |
| OLD | NEW |