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_tablet_ntp_controller.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_tablet_ntp_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/ios/block_types.h" | 9 #include "base/ios/block_types.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
12 #include "base/metrics/user_metrics_action.h" | 12 #include "base/metrics/user_metrics_action.h" |
13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
14 #include "components/bookmarks/browser/bookmark_model.h" | 14 #include "components/bookmarks/browser/bookmark_model.h" |
15 #include "components/strings/grit/components_strings.h" | 15 #include "components/strings/grit/components_strings.h" |
16 #include "google_apis/gaia/google_service_auth_error.h" | 16 #include "google_apis/gaia/google_service_auth_error.h" |
17 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 17 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
18 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" | 18 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" |
19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
20 #import "ios/chrome/browser/metrics/new_tab_page_uma.h" | 20 #import "ios/chrome/browser/metrics/new_tab_page_uma.h" |
21 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" | 21 #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" |
22 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_editing_bar.h" | 22 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_editing_bar.h" |
23 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_navigation_bar.h" | 23 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_navigation_bar.h" |
| 24 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view.h" |
24 #import "ios/chrome/browser/ui/bookmarks/bookmark_edit_view_controller.h" | 25 #import "ios/chrome/browser/ui/bookmarks/bookmark_edit_view_controller.h" |
25 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_collection_view.h" | |
26 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_editor_view_controller.
h" | 26 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_editor_view_controller.
h" |
27 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h" | 27 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h" |
28 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_primary_view.h" | 28 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_primary_view.h" |
29 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_waiting_view.h" | 29 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_waiting_view.h" |
30 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" | 30 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" |
31 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_view.h" | 31 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_view.h" |
32 #include "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h" | 32 #include "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h" |
33 #import "ios/chrome/browser/ui/bookmarks/bookmark_navigation_controller.h" | 33 #import "ios/chrome/browser/ui/bookmarks/bookmark_navigation_controller.h" |
34 #import "ios/chrome/browser/ui/bookmarks/bookmark_panel_view.h" | 34 #import "ios/chrome/browser/ui/bookmarks/bookmark_panel_view.h" |
35 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_controller.h" | 35 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_controller.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 @implementation ContentView | 68 @implementation ContentView |
69 @synthesize delegate = _delegate; | 69 @synthesize delegate = _delegate; |
70 | 70 |
71 - (void)layoutSubviews { | 71 - (void)layoutSubviews { |
72 [self.delegate willLayoutSubviews]; | 72 [self.delegate willLayoutSubviews]; |
73 [super layoutSubviews]; | 73 [super layoutSubviews]; |
74 } | 74 } |
75 @end | 75 @end |
76 | 76 |
77 @interface BookmarkHomeTabletNTPController ()< | 77 @interface BookmarkHomeTabletNTPController ()< |
| 78 BookmarkCollectionViewDelegate, |
78 BookmarkEditViewControllerDelegate, | 79 BookmarkEditViewControllerDelegate, |
79 BookmarkFolderCollectionViewDelegate, | |
80 BookmarkFolderEditorViewControllerDelegate, | 80 BookmarkFolderEditorViewControllerDelegate, |
81 BookmarkFolderViewControllerDelegate, | 81 BookmarkFolderViewControllerDelegate, |
82 BookmarkMenuViewDelegate, | 82 BookmarkMenuViewDelegate, |
83 BookmarkModelBridgeObserver, | 83 BookmarkModelBridgeObserver, |
84 BookmarkPromoControllerDelegate, | 84 BookmarkPromoControllerDelegate, |
85 ContentViewDelegate> { | 85 ContentViewDelegate> { |
86 // Bridge to register for bookmark changes. | 86 // Bridge to register for bookmark changes. |
87 std::unique_ptr<bookmarks::BookmarkModelBridge> _bridge; | 87 std::unique_ptr<bookmarks::BookmarkModelBridge> _bridge; |
88 ios::ChromeBrowserState* _browserState; // Weak. | 88 ios::ChromeBrowserState* _browserState; // Weak. |
89 __weak id<UrlLoader> _loader; | 89 __weak id<UrlLoader> _loader; |
(...skipping 27 matching lines...) Expand all Loading... |
117 - (void)insertEditNode:(const BookmarkNode*)node | 117 - (void)insertEditNode:(const BookmarkNode*)node |
118 atIndexPath:(NSIndexPath*)indexPath; | 118 atIndexPath:(NSIndexPath*)indexPath; |
119 // Removes |node| corresponding to a |cell| if it's present. | 119 // Removes |node| corresponding to a |cell| if it's present. |
120 - (void)removeEditNode:(const BookmarkNode*)node | 120 - (void)removeEditNode:(const BookmarkNode*)node |
121 atIndexPath:(NSIndexPath*)indexPath; | 121 atIndexPath:(NSIndexPath*)indexPath; |
122 // This method updates the property, and resets the edit nodes. | 122 // This method updates the property, and resets the edit nodes. |
123 - (void)setEditing:(BOOL)editing animated:(BOOL)animated; | 123 - (void)setEditing:(BOOL)editing animated:(BOOL)animated; |
124 | 124 |
125 #pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController | 125 #pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController |
126 | 126 |
127 // This views holds the primary content of this controller. At any point in | 127 // This views holds the primary content of this controller. |
128 // time, it contains exactly one of the BookmarkCollectionView subclasses. | |
129 @property(nonatomic, readwrite, strong) ContentView* view; | 128 @property(nonatomic, readwrite, strong) ContentView* view; |
130 | 129 |
131 // The possible views that can be shown from the menu. | 130 // The possible views that can be shown from the menu. |
132 @property(nonatomic, strong) BookmarkFolderCollectionView* folderView; | 131 @property(nonatomic, strong) BookmarkCollectionView* folderView; |
133 // This view is created and used if the model is not fully loaded yet by the | 132 // This view is created and used if the model is not fully loaded yet by the |
134 // time this controller starts. | 133 // time this controller starts. |
135 @property(nonatomic, strong) BookmarkHomeWaitingView* waitForModelView; | 134 @property(nonatomic, strong) BookmarkHomeWaitingView* waitForModelView; |
136 | 135 |
137 // The menu with all the folders and special entries. | 136 // The menu with all the folders and special entries. |
138 @property(nonatomic, strong) BookmarkMenuView* menuView; | 137 @property(nonatomic, strong) BookmarkMenuView* menuView; |
139 // At any point in time, there is exactly one collection view whose view is part | 138 // At any point in time, there is exactly one collection view whose view is part |
140 // of the view hierarchy. This property determines which collection view is | 139 // of the view hierarchy. This property determines which collection view is |
141 // visible. Not by accident, this property also reflects the selected menu item | 140 // visible. Not by accident, this property also reflects the selected menu item |
142 // in the BookmarkMenuView. | 141 // in the BookmarkMenuView. |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 // out. | 492 // out. |
494 self.cachedContentPosition = [NSNumber numberWithFloat:position]; | 493 self.cachedContentPosition = [NSNumber numberWithFloat:position]; |
495 } | 494 } |
496 } | 495 } |
497 } | 496 } |
498 | 497 |
499 - (void)ensureFolderViewExists { | 498 - (void)ensureFolderViewExists { |
500 if (self.folderView) | 499 if (self.folderView) |
501 return; | 500 return; |
502 | 501 |
503 BookmarkFolderCollectionView* view = [[BookmarkFolderCollectionView alloc] | 502 BookmarkCollectionView* view = |
504 initWithBrowserState:self.browserState | 503 [[BookmarkCollectionView alloc] initWithBrowserState:self.browserState |
505 frame:CGRectZero]; | 504 frame:CGRectZero]; |
506 self.folderView = view; | 505 self.folderView = view; |
507 self.folderView.delegate = self; | 506 self.folderView.delegate = self; |
508 [self.folderView setEditing:self.editing animated:NO]; | 507 [self.folderView setEditing:self.editing animated:NO]; |
509 self.folderView.autoresizingMask = | 508 self.folderView.autoresizingMask = |
510 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | 509 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
511 } | 510 } |
512 | 511 |
513 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem | 512 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem |
514 animated:(BOOL)animated { | 513 animated:(BOOL)animated { |
515 DCHECK(menuItem.type == bookmarks::MenuItemFolder); | 514 DCHECK(menuItem.type == bookmarks::MenuItemFolder); |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 animated:YES | 954 animated:YES |
956 completion:NULL]; | 955 completion:NULL]; |
957 } | 956 } |
958 | 957 |
959 - (void)deleteNodes:(const std::set<const BookmarkNode*>&)nodes { | 958 - (void)deleteNodes:(const std::set<const BookmarkNode*>&)nodes { |
960 DCHECK_GE(nodes.size(), 1u); | 959 DCHECK_GE(nodes.size(), 1u); |
961 bookmark_utils_ios::DeleteBookmarksWithUndoToast(nodes, self.bookmarks, | 960 bookmark_utils_ios::DeleteBookmarksWithUndoToast(nodes, self.bookmarks, |
962 self.browserState); | 961 self.browserState); |
963 } | 962 } |
964 | 963 |
965 #pragma mark - BookmarkFolderCollectionViewDelegate | 964 #pragma mark - BookmarkCollectionViewDelegate |
966 | 965 |
967 - (void)bookmarkFolderCollectionView:(BookmarkFolderCollectionView*)view | 966 - (void)bookmarkCollectionView:(BookmarkCollectionView*)view |
968 selectedFolderForNavigation:(const BookmarkNode*)folder { | 967 selectedFolderForNavigation:(const BookmarkNode*)folder { |
969 BookmarkMenuItem* menuItem = nil; | 968 BookmarkMenuItem* menuItem = nil; |
970 if (view == self.folderView) { | 969 if (view == self.folderView) { |
971 const BookmarkNode* parent = RootLevelFolderForNode(folder, self.bookmarks); | 970 const BookmarkNode* parent = RootLevelFolderForNode(folder, self.bookmarks); |
972 menuItem = | 971 menuItem = |
973 [BookmarkMenuItem folderMenuItemForNode:folder rootAncestor:parent]; | 972 [BookmarkMenuItem folderMenuItemForNode:folder rootAncestor:parent]; |
974 } else { | 973 } else { |
975 NOTREACHED(); | 974 NOTREACHED(); |
976 return; | 975 return; |
977 } | 976 } |
978 [self updatePrimaryMenuItem:menuItem animated:YES]; | 977 [self updatePrimaryMenuItem:menuItem animated:YES]; |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 } | 1276 } |
1278 | 1277 |
1279 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell { | 1278 - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell { |
1280 DCHECK([self primaryView].collectionView); | 1279 DCHECK([self primaryView].collectionView); |
1281 NSIndexPath* indexPath = | 1280 NSIndexPath* indexPath = |
1282 [[self primaryView].collectionView indexPathForCell:cell]; | 1281 [[self primaryView].collectionView indexPathForCell:cell]; |
1283 return indexPath; | 1282 return indexPath; |
1284 } | 1283 } |
1285 | 1284 |
1286 @end | 1285 @end |
OLD | NEW |