Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.h" | |
| 6 | |
| 7 #include "components/bookmarks/browser/bookmark_model.h" | |
| 8 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | |
| 9 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | |
| 10 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_navigation_bar.h" | |
| 11 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view.h" | |
| 12 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_primary_view.h" | |
| 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_waiting_view.h" | |
| 14 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" | |
| 15 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_view.h" | |
| 16 #import "ios/chrome/browser/ui/bookmarks/bookmark_panel_view.h" | |
| 17 #import "ios/chrome/browser/ui/rtl_geometry.h" | |
| 18 #import "ios/chrome/browser/ui/ui_util.h" | |
| 19 #import "ios/chrome/browser/ui/uikit_ui_util.h" | |
| 20 #import "ios/chrome/browser/ui/url_loader.h" | |
| 21 | |
| 22 using bookmarks::BookmarkNode; | |
| 23 | |
| 24 namespace { | |
| 25 // The width of the bookmark menu, displaying the different sections. | |
| 26 const CGFloat kMenuWidth = 264; | |
| 27 } | |
| 28 | |
| 29 @interface BookmarkHomeViewController () | |
|
noyau (Ping after 24h)
2017/07/07 09:37:23
Please add a comment explaining that those are r/w
ramyasharma
2017/07/10 06:55:58
Done.
| |
| 30 @property(nonatomic, assign) bookmarks::BookmarkModel* bookmarks; | |
| 31 @property(nonatomic, assign) ios::ChromeBrowserState* browserState; | |
| 32 @property(nonatomic, strong) BookmarkCollectionView* folderView; | |
| 33 @property(nonatomic, weak) id<UrlLoader> loader; | |
| 34 @property(nonatomic, strong) BookmarkMenuView* menuView; | |
| 35 @property(nonatomic, strong) BookmarkNavigationBar* navigationBar; | |
| 36 @property(nonatomic, strong) BookmarkPanelView* panelView; | |
| 37 @property(nonatomic, strong) BookmarkMenuItem* primaryMenuItem; | |
| 38 @end | |
| 39 | |
| 40 @implementation BookmarkHomeViewController | |
| 41 | |
| 42 @synthesize bookmarks = _bookmarks; | |
| 43 @synthesize browserState = _browserState; | |
| 44 @synthesize folderView = _folderView; | |
| 45 @synthesize loader = _loader; | |
| 46 @synthesize menuView = _menuView; | |
| 47 @synthesize navigationBar = _navigationBar; | |
| 48 @synthesize panelView = _panelView; | |
| 49 @synthesize primaryMenuItem = _primaryMenuItem; | |
| 50 @synthesize waitForModelView = _waitForModelView; | |
| 51 @synthesize scrollToTop = _scrollToTop; | |
| 52 | |
| 53 #pragma mark - Initializer | |
| 54 | |
| 55 - (instancetype)initWithLoader:(id<UrlLoader>)loader | |
| 56 browserState:(ios::ChromeBrowserState*)browserState { | |
| 57 self = [super init]; | |
| 58 if (self) { | |
| 59 DCHECK(browserState); | |
|
noyau (Ping after 24h)
2017/07/07 09:37:22
Move the DCHECK to the beginning of the method.
ramyasharma
2017/07/10 06:55:59
Done.
| |
| 60 _browserState = browserState->GetOriginalChromeBrowserState(); | |
| 61 _loader = loader; | |
| 62 | |
| 63 _bookmarks = ios::BookmarkModelFactory::GetForBrowserState(browserState); | |
| 64 } | |
| 65 return self; | |
| 66 } | |
| 67 | |
| 68 - (void)dealloc { | |
| 69 _menuView.delegate = nil; | |
| 70 _folderView.delegate = nil; | |
| 71 _panelView.delegate = nil; | |
|
noyau (Ping after 24h)
2017/07/07 09:37:23
Now that we use ARC this should be replaced by wea
ramyasharma
2017/07/10 06:55:58
Just checked the delegates, they have already been
| |
| 72 } | |
| 73 | |
| 74 #pragma mark - UIViewController | |
| 75 | |
| 76 - (void)viewDidLoad { | |
| 77 [super viewDidLoad]; | |
| 78 self.navigationBar = [[BookmarkNavigationBar alloc] initWithFrame:CGRectZero]; | |
| 79 } | |
| 80 | |
| 81 #pragma mark - Public | |
| 82 | |
| 83 - (void)loadBookmarkViews { | |
| 84 LayoutRect menuLayout = | |
| 85 LayoutRectMake(0, self.view.bounds.size.width, 0, self.menuWidth, | |
| 86 self.view.bounds.size.height); | |
| 87 | |
| 88 // The user can swipe the BookmarkPanelView to show the menuView. | |
| 89 // Therefore, it must be created here. | |
|
noyau (Ping after 24h)
2017/07/07 09:37:24
This comment seems specific to iPhone.
ramyasharma
2017/07/10 06:55:58
Acknowledged.
| |
| 90 self.menuView = [[BookmarkMenuView alloc] | |
| 91 initWithBrowserState:_browserState | |
| 92 frame:LayoutRectGetRect(menuLayout)]; | |
| 93 self.menuView.autoresizingMask = | |
| 94 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
| 95 | |
| 96 self.panelView = [[BookmarkPanelView alloc] initWithFrame:CGRectZero | |
| 97 menuViewWidth:self.menuWidth]; | |
| 98 self.panelView.autoresizingMask = | |
| 99 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
| 100 | |
| 101 // Create folder view. | |
| 102 BookmarkCollectionView* view = | |
| 103 [[BookmarkCollectionView alloc] initWithBrowserState:self.browserState | |
| 104 frame:CGRectZero]; | |
| 105 self.folderView = view; | |
| 106 [self.folderView setEditing:self.editing animated:NO]; | |
| 107 self.folderView.autoresizingMask = | |
| 108 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | |
| 109 } | |
| 110 | |
| 111 - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem { | |
| 112 DCHECK(menuItem.type == bookmarks::MenuItemFolder); | |
| 113 if ([self.primaryMenuItem isEqual:menuItem]) | |
| 114 return; | |
| 115 | |
| 116 [[self primaryView] removeFromSuperview]; | |
|
noyau (Ping after 24h)
2017/07/07 09:37:24
The primary view is now always the folder view. I'
ramyasharma
2017/07/10 06:55:59
Thanks, I have added a TODO to take care of this.
| |
| 117 self.primaryMenuItem = menuItem; | |
| 118 | |
| 119 [self.folderView resetFolder:self.primaryMenuItem.folder]; | |
| 120 [self.folderView promoStateChangedAnimated:NO]; | |
| 121 | |
| 122 [[self primaryView] changeOrientation:GetInterfaceOrientation()]; | |
| 123 [[self primaryView] setScrollsToTop:!self.scrollToTop]; | |
| 124 | |
| 125 [self.menuView updatePrimaryMenuItem:self.primaryMenuItem]; | |
| 126 } | |
| 127 | |
| 128 - (UIView<BookmarkHomePrimaryView>*)primaryView { | |
| 129 if (self.primaryMenuItem.type == bookmarks::MenuItemFolder) | |
| 130 return self.folderView; | |
| 131 return nil; | |
| 132 } | |
| 133 | |
| 134 - (void)loadWaitingView { | |
| 135 DCHECK(!self.waitForModelView); | |
| 136 DCHECK(self.view); | |
| 137 | |
| 138 // Present a waiting view. | |
| 139 BookmarkHomeWaitingView* waitingView = | |
| 140 [[BookmarkHomeWaitingView alloc] initWithFrame:self.view.bounds]; | |
| 141 self.waitForModelView = waitingView; | |
| 142 [self.view addSubview:self.waitForModelView]; | |
| 143 [self.waitForModelView startWaiting]; | |
| 144 } | |
| 145 | |
| 146 - (CGFloat)menuWidth { | |
| 147 return kMenuWidth; | |
| 148 } | |
| 149 | |
| 150 @end | |
| OLD | NEW |