Commit b1438b5d authored by Ramya Sharma's avatar Ramya Sharma Committed by Commit Bot

Code cleanup of Bookmark view controllers.

This CL:
1. Removes the concept of primary view, since there is only one single
view, the folder view that is shown as content.
2. Removes code that removes and adds primary view to the view hierarchy
on each menu item update. This is not necesary, since the primary
view does not change anymore.

Bug: 705339
Change-Id: I8f73a26a3a315cde48f319bb3a55373dd85c4cbc
Reviewed-on: https://chromium-review.googlesource.com/575305
Commit-Queue: Ramya Sharma <ramyasharma@chromium.org>
Reviewed-by: default avatarEric Noyau <noyau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488589}
parent e9f0d9fa
...@@ -56,38 +56,33 @@ const CGFloat kNavigationBarTopMargin = 8.0; ...@@ -56,38 +56,33 @@ const CGFloat kNavigationBarTopMargin = 8.0;
@interface BookmarkHomeTabletNTPController ()<BookmarkMenuViewDelegate> @interface BookmarkHomeTabletNTPController ()<BookmarkMenuViewDelegate>
#pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController
// When the view is first shown on the screen, this property represents the // When the view is first shown on the screen, this property represents the
// cached value of the y of the content offset of the primary view. This // cached value of the y of the content offset of the primary view. This
// property is set to nil after it is used. // property is set to nil after it is used.
@property(nonatomic, strong) @property(nonatomic, strong)
NSNumber* cachedContentPosition; // FIXME: INACTIVE NSNumber* cachedContentPosition; // FIXME: INACTIVE
#pragma mark Specific to this class. #pragma mark Private methods
// Opens the url. // Opens the url.
- (void)loadURL:(const GURL&)url; - (void)loadURL:(const GURL&)url;
#pragma mark View loading, laying out, and switching. #pragma mark View loading, laying out, and switching.
// This method should be called at most once in the life-cycle of the class.
// It should be called at the soonest possible time after the view has been
// loaded, and the bookmark model is loaded.
- (void)loadBookmarkViews;
// Returns whether the menu should be in a side panel that slides in. // Returns whether the menu should be in a side panel that slides in.
- (BOOL)shouldPresentMenuInSlideInPanel; - (BOOL)shouldPresentMenuInSlideInPanel;
// Returns the leading margin of the primary view. // Returns the leading margin of the folder view.
- (CGFloat)primaryViewLeadingMargin; - (CGFloat)folderViewLeadingMargin;
// Moves the menu and primary view to their correct parent views depending on // Updates the frame of the folder view.
// the layout. - (void)refreshFrameOfFolderView;
- (void)moveMenuAndPrimaryViewToAdequateParent; // Returns the frame of the folder view.
// Updates the frame of the primary view. - (CGRect)frameForFolderView;
- (void)refreshFrameOfPrimaryView;
// Returns the frame of the primary view.
- (CGRect)frameForPrimaryView;
// The menu button is pressed on the editing bar. // The menu button is pressed on the editing bar.
- (void)toggleMenuAnimated; - (void)toggleMenuAnimated;
#pragma mark Navigation bar #pragma mark Navigation bar
- (void)updateNavigationBarWithDuration:(CGFloat)duration - (void)updateNavigationBarWithDuration:(CGFloat)duration
orientation:(UIInterfaceOrientation)orientation; orientation:(UIInterfaceOrientation)orientation;
// Whether the edit button on the navigation bar should be shown. // Whether the edit button on the navigation bar should be shown.
...@@ -96,17 +91,15 @@ const CGFloat kNavigationBarTopMargin = 8.0; ...@@ -96,17 +91,15 @@ const CGFloat kNavigationBarTopMargin = 8.0;
@end @end
@implementation BookmarkHomeTabletNTPController @implementation BookmarkHomeTabletNTPController
@synthesize cachedContentPosition = _cachedContentPosition; @synthesize cachedContentPosition = _cachedContentPosition;
// Property declared in NewTabPagePanelProtocol. // Property declared in NewTabPagePanelProtocol.
@synthesize delegate = _delegate; @synthesize delegate = _delegate;
#pragma mark - UIViewController method. #pragma mark - UIViewController
- (void)viewWillLayoutSubviews { - (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews]; [super viewWillLayoutSubviews];
if (![self primaryView] && ![self primaryMenuItem] && if (!self.folderView && ![self primaryMenuItem] && self.bookmarks->loaded()) {
self.bookmarks->loaded()) {
BookmarkMenuItem* item = nil; BookmarkMenuItem* item = nil;
CGFloat position = 0; CGFloat position = 0;
BOOL found = BOOL found =
...@@ -117,8 +110,10 @@ const CGFloat kNavigationBarTopMargin = 8.0; ...@@ -117,8 +110,10 @@ const CGFloat kNavigationBarTopMargin = 8.0;
[self updatePrimaryMenuItem:item animated:NO]; [self updatePrimaryMenuItem:item animated:NO];
} }
[self moveMenuAndPrimaryViewToAdequateParent]; // Make sure the navigation bar is the frontmost subview.
CGFloat leadingMargin = [self primaryViewLeadingMargin]; [self.view bringSubviewToFront:self.navigationBar];
CGFloat leadingMargin = [self folderViewLeadingMargin];
// Prevent the panelView from hijacking the gestures so that the // Prevent the panelView from hijacking the gestures so that the
// NTPController's scrollview can still scroll with the gestures. // NTPController's scrollview can still scroll with the gestures.
...@@ -132,8 +127,8 @@ const CGFloat kNavigationBarTopMargin = 8.0; ...@@ -132,8 +127,8 @@ const CGFloat kNavigationBarTopMargin = 8.0;
[self.editingBar setFrame:[self editingBarFrame]]; [self.editingBar setFrame:[self editingBarFrame]];
UIInterfaceOrientation orient = GetInterfaceOrientation(); UIInterfaceOrientation orient = GetInterfaceOrientation();
[self refreshFrameOfPrimaryView]; [self refreshFrameOfFolderView];
[[self primaryView] changeOrientation:orient]; [self.folderView changeOrientation:orient];
[self updateNavigationBarWithDuration:0 orientation:orient]; [self updateNavigationBarWithDuration:0 orientation:orient];
if (![self shouldPresentMenuInSlideInPanel]) if (![self shouldPresentMenuInSlideInPanel])
[self updateMenuViewLayout]; [self updateMenuViewLayout];
...@@ -170,7 +165,24 @@ const CGFloat kNavigationBarTopMargin = 8.0; ...@@ -170,7 +165,24 @@ const CGFloat kNavigationBarTopMargin = 8.0;
self.menuView.delegate = self; self.menuView.delegate = self;
[self moveMenuAndPrimaryViewToAdequateParent]; // Set view frames and add them to hierarchy.
if ([self shouldPresentMenuInSlideInPanel]) {
// Add the panelView to the view hierarchy.
[self.view addSubview:self.panelView];
CGSize size = self.view.bounds.size;
CGFloat navBarHeight = CGRectGetHeight([self navigationBarFrame]);
LayoutRect panelLayout = LayoutRectMake(
0, size.width, navBarHeight, size.width, size.height - navBarHeight);
// Initialize the panelView with the menuView and the folderView.
[self.panelView setFrame:LayoutRectGetRect(panelLayout)];
[self.panelView.menuView addSubview:self.menuView];
self.menuView.frame = self.panelView.menuView.bounds;
[self.panelView.contentView addSubview:self.folderView];
} else {
[self.view addSubview:self.menuView];
[self.view addSubview:self.folderView];
}
// Load the last primary menu item which the user had active. // Load the last primary menu item which the user had active.
BookmarkMenuItem* item = nil; BookmarkMenuItem* item = nil;
...@@ -182,13 +194,11 @@ const CGFloat kNavigationBarTopMargin = 8.0; ...@@ -182,13 +194,11 @@ const CGFloat kNavigationBarTopMargin = 8.0;
[self updatePrimaryMenuItem:item animated:NO]; [self updatePrimaryMenuItem:item animated:NO];
[[self primaryView] applyContentPosition:position];
if (found) { if (found) {
// If the view has already been laid out, then immediately apply the content // If the view has already been laid out, then immediately apply the content
// position. // position.
if (self.view.window) { if (self.view.window) {
[[self primaryView] applyContentPosition:position]; [self.folderView applyContentPosition:position];
} else { } else {
// Otherwise, save the position to be applied once the view has been laid // Otherwise, save the position to be applied once the view has been laid
// out. // out.
...@@ -199,15 +209,12 @@ const CGFloat kNavigationBarTopMargin = 8.0; ...@@ -199,15 +209,12 @@ const CGFloat kNavigationBarTopMargin = 8.0;
- (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem
animated:(BOOL)animated { animated:(BOOL)animated {
if (![self.view superview])
return;
[super updatePrimaryMenuItem:menuItem animated:animated]; [super updatePrimaryMenuItem:menuItem animated:animated];
[self moveMenuAndPrimaryViewToAdequateParent]; // Make sure the navigation bar is the frontmost subview.
[self.view bringSubviewToFront:self.navigationBar];
// [self.view sendSubviewToBack:primaryView]; [self refreshFrameOfFolderView];
[self refreshFrameOfPrimaryView];
self.navigationBar.hidden = NO; self.navigationBar.hidden = NO;
[self updateNavigationBarAnimated:animated [self updateNavigationBarAnimated:animated
...@@ -278,7 +285,7 @@ const CGFloat kNavigationBarTopMargin = 8.0; ...@@ -278,7 +285,7 @@ const CGFloat kNavigationBarTopMargin = 8.0;
view:view]; view:view];
} }
#pragma mark - private methods #pragma mark - Private methods
- (void)loadURL:(const GURL&)url { - (void)loadURL:(const GURL&)url {
if (url == GURL() || url.SchemeIs(url::kJavaScriptScheme)) if (url == GURL() || url.SchemeIs(url::kJavaScriptScheme))
...@@ -298,59 +305,27 @@ const CGFloat kNavigationBarTopMargin = 8.0; ...@@ -298,59 +305,27 @@ const CGFloat kNavigationBarTopMargin = 8.0;
return IsCompactTablet(); return IsCompactTablet();
} }
- (CGFloat)primaryViewLeadingMargin { - (CGFloat)folderViewLeadingMargin {
if ([self shouldPresentMenuInSlideInPanel]) if ([self shouldPresentMenuInSlideInPanel])
return 0; return 0;
return [self menuWidth]; return [self menuWidth];
} }
- (void)moveMenuAndPrimaryViewToAdequateParent { - (void)refreshFrameOfFolderView {
// Remove the menuView, panelView, and primaryView from the view hierarchy. self.folderView.frame = [self frameForFolderView];
if ([self.menuView superview])
[self.menuView removeFromSuperview];
if ([self.panelView superview])
[self.panelView removeFromSuperview];
UIView* primaryView = [self primaryView];
if ([primaryView superview])
[primaryView removeFromSuperview];
if ([self shouldPresentMenuInSlideInPanel]) {
// Add the panelView to the view hierarchy.
[self.view addSubview:self.panelView];
CGSize size = self.view.bounds.size;
CGFloat navBarHeight = CGRectGetHeight([self navigationBarFrame]);
LayoutRect panelLayout = LayoutRectMake(
0, size.width, navBarHeight, size.width, size.height - navBarHeight);
// Initialize the panelView with the menuView and the primaryView.
[self.panelView setFrame:LayoutRectGetRect(panelLayout)];
[self.panelView.menuView addSubview:self.menuView];
self.menuView.frame = self.panelView.menuView.bounds;
[self.panelView.contentView addSubview:primaryView];
} else {
[self.view addSubview:self.menuView];
[self.view addSubview:primaryView];
}
// Make sure the navigation bar is the frontmost subview.
[self.view bringSubviewToFront:self.navigationBar];
}
- (void)refreshFrameOfPrimaryView {
[self primaryView].frame = [self frameForPrimaryView];
} }
- (CGRect)frameForPrimaryView { - (CGRect)frameForFolderView {
CGFloat topInset = 0; CGFloat topInset = 0;
if (!IsCompactTablet()) if (!IsCompactTablet())
topInset = CGRectGetHeight([self navigationBarFrame]); topInset = CGRectGetHeight([self navigationBarFrame]);
CGFloat leadingMargin = [self primaryViewLeadingMargin]; CGFloat leadingMargin = [self folderViewLeadingMargin];
CGSize size = self.view.bounds.size; CGSize size = self.view.bounds.size;
LayoutRect primaryViewLayout = LayoutRect folderViewLayout =
LayoutRectMake(leadingMargin, size.width, topInset, LayoutRectMake(leadingMargin, size.width, topInset,
size.width - leadingMargin, size.height - topInset); size.width - leadingMargin, size.height - topInset);
return LayoutRectGetRect(primaryViewLayout); return LayoutRectGetRect(folderViewLayout);
} }
#pragma mark - BookmarkMenuViewDelegate #pragma mark - BookmarkMenuViewDelegate
...@@ -439,7 +414,7 @@ const CGFloat kNavigationBarTopMargin = 8.0; ...@@ -439,7 +414,7 @@ const CGFloat kNavigationBarTopMargin = 8.0;
- (void)setScrollsToTop:(BOOL)enabled { - (void)setScrollsToTop:(BOOL)enabled {
self.scrollToTop = enabled; self.scrollToTop = enabled;
[[self primaryView] setScrollsToTop:self.scrollToTop]; [self.folderView setScrollsToTop:self.scrollToTop];
} }
- (CGFloat)alphaForBottomShadow { - (CGFloat)alphaForBottomShadow {
......
...@@ -150,28 +150,17 @@ const CGFloat kMenuWidth = 264; ...@@ -150,28 +150,17 @@ const CGFloat kMenuWidth = 264;
if ([self.primaryMenuItem isEqual:menuItem]) if ([self.primaryMenuItem isEqual:menuItem])
return; return;
// TODO(crbug.com/705339): Folder view is the only primary view now,
// hence we don't need to remove primary view anymore.
// Simplify this code that removes primary view and adds it back
// in subclasses, once the addition code moves here.
[[self primaryView] removeFromSuperview];
self.primaryMenuItem = menuItem; self.primaryMenuItem = menuItem;
[self.folderView resetFolder:self.primaryMenuItem.folder]; [self.folderView resetFolder:self.primaryMenuItem.folder];
[self.folderView promoStateChangedAnimated:NO]; [self.folderView promoStateChangedAnimated:NO];
[[self primaryView] changeOrientation:GetInterfaceOrientation()]; [self.folderView changeOrientation:GetInterfaceOrientation()];
[[self primaryView] setScrollsToTop:!self.scrollToTop]; [self.folderView setScrollsToTop:!self.scrollToTop];
[self.menuView updatePrimaryMenuItem:self.primaryMenuItem]; [self.menuView updatePrimaryMenuItem:self.primaryMenuItem];
} }
- (UIView<BookmarkHomePrimaryView>*)primaryView {
if (self.primaryMenuItem.type == bookmarks::MenuItemFolder)
return self.folderView;
return nil;
}
- (void)loadWaitingView { - (void)loadWaitingView {
DCHECK(!self.waitForModelView); DCHECK(!self.waitForModelView);
DCHECK(self.view); DCHECK(self.view);
...@@ -189,9 +178,9 @@ const CGFloat kMenuWidth = 264; ...@@ -189,9 +178,9 @@ const CGFloat kMenuWidth = 264;
} }
- (void)cachePosition { - (void)cachePosition {
if ([self primaryView]) { if (self.folderView) {
bookmark_utils_ios::CachePosition( bookmark_utils_ios::CachePosition(
[[self primaryView] contentPositionInPortraitOrientation], [self.folderView contentPositionInPortraitOrientation],
[self primaryMenuItem]); [self primaryMenuItem]);
} }
} }
...@@ -240,8 +229,7 @@ const CGFloat kMenuWidth = 264; ...@@ -240,8 +229,7 @@ const CGFloat kMenuWidth = 264;
#pragma mark - BookmarkPromoControllerDelegate #pragma mark - BookmarkPromoControllerDelegate
- (void)promoStateChanged:(BOOL)promoEnabled { - (void)promoStateChanged:(BOOL)promoEnabled {
[self.folderView [self.folderView promoStateChangedAnimated:YES];
promoStateChangedAnimated:self.folderView == [self primaryView]];
} }
#pragma mark Action sheet callbacks #pragma mark Action sheet callbacks
...@@ -512,7 +500,7 @@ const CGFloat kMenuWidth = 264; ...@@ -512,7 +500,7 @@ const CGFloat kMenuWidth = 264;
[self updateEditingStateAnimated:animated]; [self updateEditingStateAnimated:animated];
if ([[self primaryMenuItem] supportsEditing]) if ([[self primaryMenuItem] supportsEditing])
[[self primaryView] setEditing:editing animated:animated]; [self.folderView setEditing:editing animated:animated];
} }
- (void)updateEditBarShadow { - (void)updateEditBarShadow {
...@@ -744,9 +732,9 @@ const CGFloat kMenuWidth = 264; ...@@ -744,9 +732,9 @@ const CGFloat kMenuWidth = 264;
// Returns NSIndexPath for a given cell. // Returns NSIndexPath for a given cell.
- (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell { - (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell {
DCHECK([self primaryView].collectionView); DCHECK(self.folderView.collectionView);
NSIndexPath* indexPath = NSIndexPath* indexPath =
[[self primaryView].collectionView indexPathForCell:cell]; [self.folderView.collectionView indexPathForCell:cell];
return indexPath; return indexPath;
} }
......
...@@ -109,9 +109,6 @@ class BookmarkNode; ...@@ -109,9 +109,6 @@ class BookmarkNode;
- (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem - (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem
animated:(BOOL)animated; animated:(BOOL)animated;
// The active collection view that corresponds to primaryMenuItem.
- (UIView<BookmarkHomePrimaryView>*)primaryView;
// Caches the position in the collection view. // Caches the position in the collection view.
- (void)cachePosition; - (void)cachePosition;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment