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;
@interface BookmarkHomeTabletNTPController ()<BookmarkMenuViewDelegate>
#pragma mark - Properties and methods akin to BookmarkHomeHandsetViewController
// 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
// property is set to nil after it is used.
@property(nonatomic, strong)
NSNumber* cachedContentPosition; // FIXME: INACTIVE
#pragma mark Specific to this class.
#pragma mark Private methods
// Opens the url.
- (void)loadURL:(const GURL&)url;
#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.
- (BOOL)shouldPresentMenuInSlideInPanel;
// Returns the leading margin of the primary view.
- (CGFloat)primaryViewLeadingMargin;
// Moves the menu and primary view to their correct parent views depending on
// the layout.
- (void)moveMenuAndPrimaryViewToAdequateParent;
// Updates the frame of the primary view.
- (void)refreshFrameOfPrimaryView;
// Returns the frame of the primary view.
- (CGRect)frameForPrimaryView;
// Returns the leading margin of the folder view.
- (CGFloat)folderViewLeadingMargin;
// Updates the frame of the folder view.
- (void)refreshFrameOfFolderView;
// Returns the frame of the folder view.
- (CGRect)frameForFolderView;
// The menu button is pressed on the editing bar.
- (void)toggleMenuAnimated;
#pragma mark Navigation bar
- (void)updateNavigationBarWithDuration:(CGFloat)duration
orientation:(UIInterfaceOrientation)orientation;
// Whether the edit button on the navigation bar should be shown.
......@@ -96,17 +91,15 @@ const CGFloat kNavigationBarTopMargin = 8.0;
@end
@implementation BookmarkHomeTabletNTPController
@synthesize cachedContentPosition = _cachedContentPosition;
// Property declared in NewTabPagePanelProtocol.
@synthesize delegate = _delegate;
#pragma mark - UIViewController method.
#pragma mark - UIViewController
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
if (![self primaryView] && ![self primaryMenuItem] &&
self.bookmarks->loaded()) {
if (!self.folderView && ![self primaryMenuItem] && self.bookmarks->loaded()) {
BookmarkMenuItem* item = nil;
CGFloat position = 0;
BOOL found =
......@@ -117,8 +110,10 @@ const CGFloat kNavigationBarTopMargin = 8.0;
[self updatePrimaryMenuItem:item animated:NO];
}
[self moveMenuAndPrimaryViewToAdequateParent];
CGFloat leadingMargin = [self primaryViewLeadingMargin];
// Make sure the navigation bar is the frontmost subview.
[self.view bringSubviewToFront:self.navigationBar];
CGFloat leadingMargin = [self folderViewLeadingMargin];
// Prevent the panelView from hijacking the gestures so that the
// NTPController's scrollview can still scroll with the gestures.
......@@ -132,8 +127,8 @@ const CGFloat kNavigationBarTopMargin = 8.0;
[self.editingBar setFrame:[self editingBarFrame]];
UIInterfaceOrientation orient = GetInterfaceOrientation();
[self refreshFrameOfPrimaryView];
[[self primaryView] changeOrientation:orient];
[self refreshFrameOfFolderView];
[self.folderView changeOrientation:orient];
[self updateNavigationBarWithDuration:0 orientation:orient];
if (![self shouldPresentMenuInSlideInPanel])
[self updateMenuViewLayout];
......@@ -170,7 +165,24 @@ const CGFloat kNavigationBarTopMargin = 8.0;
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.
BookmarkMenuItem* item = nil;
......@@ -182,13 +194,11 @@ const CGFloat kNavigationBarTopMargin = 8.0;
[self updatePrimaryMenuItem:item animated:NO];
[[self primaryView] applyContentPosition:position];
if (found) {
// If the view has already been laid out, then immediately apply the content
// position.
if (self.view.window) {
[[self primaryView] applyContentPosition:position];
[self.folderView applyContentPosition:position];
} else {
// Otherwise, save the position to be applied once the view has been laid
// out.
......@@ -199,15 +209,12 @@ const CGFloat kNavigationBarTopMargin = 8.0;
- (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem
animated:(BOOL)animated {
if (![self.view superview])
return;
[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 refreshFrameOfPrimaryView];
[self refreshFrameOfFolderView];
self.navigationBar.hidden = NO;
[self updateNavigationBarAnimated:animated
......@@ -278,7 +285,7 @@ const CGFloat kNavigationBarTopMargin = 8.0;
view:view];
}
#pragma mark - private methods
#pragma mark - Private methods
- (void)loadURL:(const GURL&)url {
if (url == GURL() || url.SchemeIs(url::kJavaScriptScheme))
......@@ -298,59 +305,27 @@ const CGFloat kNavigationBarTopMargin = 8.0;
return IsCompactTablet();
}
- (CGFloat)primaryViewLeadingMargin {
- (CGFloat)folderViewLeadingMargin {
if ([self shouldPresentMenuInSlideInPanel])
return 0;
return [self menuWidth];
}
- (void)moveMenuAndPrimaryViewToAdequateParent {
// Remove the menuView, panelView, and primaryView from the view hierarchy.
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];
- (void)refreshFrameOfFolderView {
self.folderView.frame = [self frameForFolderView];
}
- (CGRect)frameForPrimaryView {
- (CGRect)frameForFolderView {
CGFloat topInset = 0;
if (!IsCompactTablet())
topInset = CGRectGetHeight([self navigationBarFrame]);
CGFloat leadingMargin = [self primaryViewLeadingMargin];
CGFloat leadingMargin = [self folderViewLeadingMargin];
CGSize size = self.view.bounds.size;
LayoutRect primaryViewLayout =
LayoutRect folderViewLayout =
LayoutRectMake(leadingMargin, size.width, topInset,
size.width - leadingMargin, size.height - topInset);
return LayoutRectGetRect(primaryViewLayout);
return LayoutRectGetRect(folderViewLayout);
}
#pragma mark - BookmarkMenuViewDelegate
......@@ -439,7 +414,7 @@ const CGFloat kNavigationBarTopMargin = 8.0;
- (void)setScrollsToTop:(BOOL)enabled {
self.scrollToTop = enabled;
[[self primaryView] setScrollsToTop:self.scrollToTop];
[self.folderView setScrollsToTop:self.scrollToTop];
}
- (CGFloat)alphaForBottomShadow {
......
......@@ -150,28 +150,17 @@ const CGFloat kMenuWidth = 264;
if ([self.primaryMenuItem isEqual:menuItem])
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.folderView resetFolder:self.primaryMenuItem.folder];
[self.folderView promoStateChangedAnimated:NO];
[[self primaryView] changeOrientation:GetInterfaceOrientation()];
[[self primaryView] setScrollsToTop:!self.scrollToTop];
[self.folderView changeOrientation:GetInterfaceOrientation()];
[self.folderView setScrollsToTop:!self.scrollToTop];
[self.menuView updatePrimaryMenuItem:self.primaryMenuItem];
}
- (UIView<BookmarkHomePrimaryView>*)primaryView {
if (self.primaryMenuItem.type == bookmarks::MenuItemFolder)
return self.folderView;
return nil;
}
- (void)loadWaitingView {
DCHECK(!self.waitForModelView);
DCHECK(self.view);
......@@ -189,9 +178,9 @@ const CGFloat kMenuWidth = 264;
}
- (void)cachePosition {
if ([self primaryView]) {
if (self.folderView) {
bookmark_utils_ios::CachePosition(
[[self primaryView] contentPositionInPortraitOrientation],
[self.folderView contentPositionInPortraitOrientation],
[self primaryMenuItem]);
}
}
......@@ -240,8 +229,7 @@ const CGFloat kMenuWidth = 264;
#pragma mark - BookmarkPromoControllerDelegate
- (void)promoStateChanged:(BOOL)promoEnabled {
[self.folderView
promoStateChangedAnimated:self.folderView == [self primaryView]];
[self.folderView promoStateChangedAnimated:YES];
}
#pragma mark Action sheet callbacks
......@@ -512,7 +500,7 @@ const CGFloat kMenuWidth = 264;
[self updateEditingStateAnimated:animated];
if ([[self primaryMenuItem] supportsEditing])
[[self primaryView] setEditing:editing animated:animated];
[self.folderView setEditing:editing animated:animated];
}
- (void)updateEditBarShadow {
......@@ -744,9 +732,9 @@ const CGFloat kMenuWidth = 264;
// Returns NSIndexPath for a given cell.
- (NSIndexPath*)indexPathForCell:(UICollectionViewCell*)cell {
DCHECK([self primaryView].collectionView);
DCHECK(self.folderView.collectionView);
NSIndexPath* indexPath =
[[self primaryView].collectionView indexPathForCell:cell];
[self.folderView.collectionView indexPathForCell:cell];
return indexPath;
}
......
......@@ -109,9 +109,6 @@ class BookmarkNode;
- (void)updatePrimaryMenuItem:(BookmarkMenuItem*)menuItem
animated:(BOOL)animated;
// The active collection view that corresponds to primaryMenuItem.
- (UIView<BookmarkHomePrimaryView>*)primaryView;
// Caches the position in the collection view.
- (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