Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Unified Diff: ios/chrome/browser/ui/ntp/google_landing_view_controller.mm

Issue 2857123003: Move frame-related methods out of GoogleLandingViewController (Closed)
Patch Set: Address comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/ntp/google_landing_view_controller.mm
diff --git a/ios/chrome/browser/ui/ntp/google_landing_view_controller.mm b/ios/chrome/browser/ui/ntp/google_landing_view_controller.mm
index 689749177cdb3744db2241edbd313f1bc69270c6..bedc75748a8d9583541099ae57161e82e399692c 100644
--- a/ios/chrome/browser/ui/ntp/google_landing_view_controller.mm
+++ b/ios/chrome/browser/ui/ntp/google_landing_view_controller.mm
@@ -13,6 +13,8 @@
#import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
#import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
#include "ios/chrome/browser/ui/commands/ios_command_ids.h"
+#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.h"
+#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_utils.h"
#import "ios/chrome/browser/ui/context_menu/context_menu_coordinator.h"
#import "ios/chrome/browser/ui/ntp/google_landing_data_source.h"
#import "ios/chrome/browser/ui/ntp/most_visited_cell.h"
@@ -44,32 +46,14 @@ enum {
NumberOfCollectionViewSections,
};
-enum InterfaceOrientation {
- ALL,
- IPHONE_LANDSCAPE,
-};
-
const CGFloat kVoiceSearchButtonWidth = 48;
const UIEdgeInsets kSearchBoxStretchInsets = {3, 3, 3, 3};
-// Height for the doodle frame when Google is not the default search engine.
-const CGFloat kNonGoogleSearchDoodleHeight = 60;
-// Height for the header view on tablet when Google is not the default search
-// engine.
-const CGFloat kNonGoogleSearchHeaderHeightIPad = 10;
-
const CGFloat kHintLabelSidePadding = 12;
-const CGFloat kNTPSearchFieldBottomPadding = 16;
const CGFloat kWhatsNewHeaderHiddenHeight = 8;
-const CGFloat kDoodleTopMarginIPadPortrait = 82;
-const CGFloat kDoodleTopMarginIPadLandscape = 82;
const NSInteger kMaxNumMostVisitedFaviconRows = 2;
-const CGFloat kMaxSearchFieldFrameMargin = 200;
const CGFloat kShiftTilesDownAnimationDuration = 0.2;
-const CGFloat kMostVisitedPaddingIPhone = 16;
-const CGFloat kMostVisitedPaddingIPadFavicon = 24;
-
} // namespace
@interface GoogleLandingViewController (UsedByGoogleLandingView)
@@ -204,14 +188,6 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
// pushed into the header view.
@property(nonatomic, assign) BOOL canGoBack;
-// iPhone landscape uses a slightly different layout for the doodle and search
-// field frame. Returns the proper frame from |frames| based on orientation,
-// centered in the view.
-- (CGRect)getOrientationFrame:(const CGRect[])frames;
-// Returns the proper frame for the doodle.
-- (CGRect)doodleFrame;
-// Returns the proper frame for the search field.
-- (CGRect)searchFieldFrame;
// Returns the height to use for the What's New promo view.
- (CGFloat)promoHeaderHeight;
// Add fake search field and voice search microphone.
@@ -246,8 +222,6 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
- (NSInteger)numberOfNonEmptyTilesShown;
// Returns the URL for the mosted visited item in |self.mostVisitedData|.
- (GURL)urlForIndex:(NSUInteger)index;
-// Returns the expected height of the NewTabPageHeaderView.
-- (CGFloat)heightForSectionWithOmnibox;
// Returns the nearest ancestor view that is kind of |aClass|.
- (UIView*)nearestAncestorOfView:(UIView*)view withClass:(Class)aClass;
// Updates the collection view's scroll view offset for the next frame of the
@@ -255,8 +229,6 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
- (void)shiftTilesDownAnimationDidFire:(CADisplayLink*)link;
// Returns the size to use for Most Visited cells in the NTP.
- (CGSize)mostVisitedCellSize;
-// Returns the padding for use between Most Visited cells.
-- (CGFloat)mostVisitedCellPadding;
@end
@@ -362,7 +334,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
CGFloat smallestDimension =
viewSize.height > viewSize.width ? viewSize.width : viewSize.height;
CGFloat cellWidth = AlignValueToPixel(
- (smallestDimension - 3 * [self mostVisitedCellPadding]) / 2);
+ (smallestDimension - 3 * [ContentSuggestionsMostVisitedCell spacing]) /
+ 2);
if (cellWidth < maximumCellSize.width) {
return CGSizeMake(cellWidth, cellWidth);
} else {
@@ -373,90 +346,24 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
}
}
-- (CGFloat)mostVisitedCellPadding {
- return IsIPadIdiom() ? kMostVisitedPaddingIPadFavicon
- : kMostVisitedPaddingIPhone;
-}
-
- (CGFloat)viewWidth {
return [self.view frame].size.width;
}
- (int)numberOfColumns {
CGFloat width = [self viewWidth];
- CGFloat padding = [self mostVisitedCellPadding];
- // Try to fit 4 columns.
- if (width >= 5 * padding + _mostVisitedCellSize.width * 4)
- return 4;
- // Try to fit 3 columns.
- if (width >= 4 * padding + _mostVisitedCellSize.width * 3)
- return 3;
- // Try to fit 2 columns.
- if (width >= 3 * padding + _mostVisitedCellSize.width * 2)
- return 2;
- // We never want to have a layout with only one column, however: At launch,
- // the view's size is initialized to the width of 320, which can only fit
- // one column on iPhone 6 and 6+. TODO(crbug.com/506183): Get rid of the
- // unecessary resize, and add a NOTREACHED() here.
- return 1;
-}
-
-- (CGFloat)leftMargin {
- int columns = [self numberOfColumns];
- CGFloat whitespace = [self viewWidth] - columns * _mostVisitedCellSize.width -
- (columns - 1) * [self mostVisitedCellPadding];
- CGFloat margin = AlignValueToPixel(whitespace / 2);
- DCHECK(margin >= [self mostVisitedCellPadding]);
- return margin;
-}
-
-- (CGRect)doodleFrame {
- const CGRect kDoodleFrame[2] = {
- {{0, 66}, {0, 120}}, {{0, 56}, {0, 120}},
- };
- CGRect doodleFrame = [self getOrientationFrame:kDoodleFrame];
- if (!IsIPadIdiom() && !self.logoIsShowing)
- doodleFrame.size.height = kNonGoogleSearchDoodleHeight;
- if (IsIPadIdiom()) {
- doodleFrame.origin.y = IsPortrait() ? kDoodleTopMarginIPadPortrait
- : kDoodleTopMarginIPadLandscape;
- }
- return doodleFrame;
-}
-- (CGRect)searchFieldFrame {
- CGFloat y = CGRectGetMaxY([self doodleFrame]);
- CGFloat leftMargin = [self leftMargin];
- if (leftMargin > kMaxSearchFieldFrameMargin)
- leftMargin = kMaxSearchFieldFrameMargin;
- const CGRect kSearchFieldFrame[2] = {
- {{leftMargin, y + 32}, {0, 50}}, {{leftMargin, y + 16}, {0, 50}},
- };
- CGRect searchFieldFrame = [self getOrientationFrame:kSearchFieldFrame];
- if (IsIPadIdiom()) {
- CGFloat iPadTopMargin = IsPortrait() ? kDoodleTopMarginIPadPortrait
- : kDoodleTopMarginIPadLandscape;
- searchFieldFrame.origin.y += iPadTopMargin - 32;
- }
- return searchFieldFrame;
-}
-
-- (CGRect)getOrientationFrame:(const CGRect[])frames {
- UIInterfaceOrientation orient =
- [[UIApplication sharedApplication] statusBarOrientation];
- InterfaceOrientation inter_orient =
- (IsIPadIdiom() || UIInterfaceOrientationIsPortrait(orient))
- ? ALL
- : IPHONE_LANDSCAPE;
-
- // Calculate width based on screen width and origin x.
- CGRect frame = frames[inter_orient];
- frame.size.width = fmax(self.view.bounds.size.width - 2 * frame.origin.x, 50);
- return frame;
+ NSUInteger columns = [ContentSuggestionsMostVisitedCell
+ numberOfTilesForWidth:width -
+ 2 * [ContentSuggestionsMostVisitedCell spacing]];
+ DCHECK(columns > 1);
+ return columns;
}
- (CGFloat)promoHeaderHeight {
- CGFloat promoMaxWidth = [self viewWidth] - 2 * [self leftMargin];
+ CGFloat promoMaxWidth =
+ [self viewWidth] -
+ 2 * content_suggestions::centeredTilesMarginForWidth([self viewWidth]);
NSString* text = self.promoText;
return [WhatsNewHeaderView heightToFitText:text inWidth:promoMaxWidth];
}
@@ -470,7 +377,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
// Adjust the height of |_headerView| to fit its content which may have
// been shifted due to the visibility of the doodle.
CGRect headerFrame = [_headerView frame];
- headerFrame.size.height = [self heightForSectionWithOmnibox];
+ headerFrame.size.height = content_suggestions::heightForLogoHeader(
+ [self viewWidth], self.logoIsShowing, self.promoCanShow);
[_headerView setFrame:headerFrame];
// Adjust vertical positioning of |_promoHeaderView|.
@@ -491,7 +399,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
// Initialize and add a search field tap target and a voice search button.
- (void)addSearchField {
- CGRect searchFieldFrame = [self searchFieldFrame];
+ CGRect searchFieldFrame = content_suggestions::searchFieldFrame(
+ [self viewWidth], self.logoIsShowing);
_searchTapTarget.reset([[UIButton alloc] initWithFrame:searchFieldFrame]);
if (IsIPadIdiom()) {
UIImage* searchBoxImage = [[UIImage imageNamed:@"ntp_google_search_box"]
@@ -644,7 +553,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
}
- (void)setFlowLayoutInset:(UICollectionViewFlowLayout*)layout {
- CGFloat leftMargin = [self leftMargin];
+ CGFloat leftMargin =
+ content_suggestions::centeredTilesMarginForWidth([self viewWidth]);
[layout setSectionInset:UIEdgeInsetsMake(0, leftMargin, 0, leftMargin)];
}
@@ -660,11 +570,14 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
base::mac::ObjCCastStrict<UICollectionViewFlowLayout>(
[_mostVisitedView collectionViewLayout]);
[flowLayout setItemSize:_mostVisitedCellSize];
- self.logoVendor.view.frame = [self doodleFrame];
+ self.logoVendor.view.frame =
+ content_suggestions::doodleFrame([self viewWidth], self.logoIsShowing);
[self setFlowLayoutInset:flowLayout];
[flowLayout invalidateLayout];
- [_promoHeaderView setSideMargin:[self leftMargin]];
+ [_promoHeaderView
+ setSideMargin:content_suggestions::centeredTilesMarginForWidth(
+ [self viewWidth])];
// On the iPhone 6 Plus, if the app is started in landscape after a fresh
// install, the UICollectionViewLayout incorrectly sizes the widths of the
@@ -691,7 +604,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
[self updateSearchField];
}
} else {
- [_searchTapTarget setFrame:[self searchFieldFrame]];
+ [_searchTapTarget setFrame:content_suggestions::searchFieldFrame(
+ [self viewWidth], self.logoIsShowing)];
}
if (!_viewLoaded) {
@@ -713,7 +627,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
[flowLayout setItemSize:_mostVisitedCellSize];
[flowLayout setMinimumInteritemSpacing:8];
- [flowLayout setMinimumLineSpacing:[self mostVisitedCellPadding]];
+ [flowLayout
+ setMinimumLineSpacing:[ContentSuggestionsMostVisitedCell spacing]];
DCHECK(!_mostVisitedView);
_mostVisitedView.reset([[UICollectionView alloc]
initWithFrame:mostVisitedFrame
@@ -743,7 +658,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
NSArray* constraints =
@[ _hintLabelLeadingConstraint, _voiceTapTrailingConstraint ];
[_headerView updateSearchField:_searchTapTarget
- withInitialFrame:[self searchFieldFrame]
+ withInitialFrame:content_suggestions::searchFieldFrame(
+ [self viewWidth], self.logoIsShowing)
subviewConstraints:constraints
forOffset:[_mostVisitedView contentOffset].y];
}
@@ -901,27 +817,6 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
[self.view setNeedsLayout];
}
-- (CGFloat)heightForSectionWithOmnibox {
- CGFloat headerHeight =
- CGRectGetMaxY([self searchFieldFrame]) + kNTPSearchFieldBottomPadding;
- if (IsIPadIdiom()) {
- if (self.logoIsShowing) {
- if (!self.promoCanShow) {
- UIInterfaceOrientation orient =
- [[UIApplication sharedApplication] statusBarOrientation];
- const CGFloat kTopSpacingMaterialPortrait = 56;
- const CGFloat kTopSpacingMaterialLandscape = 32;
- headerHeight += UIInterfaceOrientationIsPortrait(orient)
- ? kTopSpacingMaterialPortrait
- : kTopSpacingMaterialLandscape;
- }
- } else {
- headerHeight = kNonGoogleSearchHeaderHeightIPad;
- }
- }
- return headerHeight;
-}
-
#pragma mark - ToolbarOwner
- (ToolbarController*)relinquishedToolbarController {
@@ -940,7 +835,8 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
referenceSizeForHeaderInSection:(NSInteger)section {
CGFloat headerHeight = 0;
if (section == SectionWithOmnibox) {
- headerHeight = [self heightForSectionWithOmnibox];
+ headerHeight = content_suggestions::heightForLogoHeader(
+ [self viewWidth], self.logoIsShowing, self.promoCanShow);
((UICollectionViewFlowLayout*)collectionViewLayout).headerReferenceSize =
CGSizeMake(0, headerHeight);
} else if (section == SectionWithMostVisited) {
@@ -1030,7 +926,9 @@ const CGFloat kMostVisitedPaddingIPadFavicon = 24;
UICollectionElementKindSectionHeader
withReuseIdentifier:@"whatsNew"
forIndexPath:indexPath] retain]);
- [_promoHeaderView setSideMargin:[self leftMargin]];
+ [_promoHeaderView
+ setSideMargin:content_suggestions::centeredTilesMarginForWidth(
+ [self viewWidth])];
[_promoHeaderView setDelegate:self];
if (self.promoCanShow) {
[_promoHeaderView setText:self.promoText];

Powered by Google App Engine
This is Rietveld 408576698