Commit fb2392d5 authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios] Tighten up most visited spacing for ui refresh.

Bug: 805636
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I38c1003c7bf4935bbc1071efad166fb113ba471b
Reviewed-on: https://chromium-review.googlesource.com/957915Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542504}
parent ed5ff53b
......@@ -17,7 +17,8 @@ extern const int kSearchFieldBackgroundColor;
// 4.
NSUInteger numberOfTilesForWidth(CGFloat availableWidth);
// Returns the spacing between tiles, based on the device.
CGFloat spacingBetweenTiles();
CGFloat horizontalSpacingBetweenTiles();
CGFloat verticalSpacingBetweenTiles();
// Returns x-offset in order to have the tiles centered in a view with a
// |width|.
......
......@@ -23,6 +23,9 @@
namespace {
// Spacing between tiles.
const CGFloat kHorizontalSpacingRegularXRegular = 19;
const CGFloat kHorizontalSpacingOther = 9;
const CGFloat kVerticalSpacing = 16;
const CGFloat kSpacingIPhone = 16;
const CGFloat kSpacingIPad = 24;
......@@ -75,7 +78,8 @@ const CGFloat kNonGoogleSearchHeaderHeightIPad = 10;
// Returns the width necessary to fit |numberOfItem| items, with no padding on
// the side.
CGFloat widthForNumberOfItem(NSUInteger numberOfItem) {
return (numberOfItem - 1) * content_suggestions::spacingBetweenTiles() +
return (numberOfItem - 1) *
content_suggestions::horizontalSpacingBetweenTiles() +
numberOfItem * [ContentSuggestionsMostVisitedCell defaultSize].width;
}
}
......@@ -102,24 +106,40 @@ NSUInteger numberOfTilesForWidth(CGFloat availableWidth) {
return 1;
}
CGFloat spacingBetweenTiles() {
return IsIPadIdiom() ? kSpacingIPad : kSpacingIPhone;
CGFloat horizontalSpacingBetweenTiles() {
if (IsUIRefreshPhase1Enabled()) {
return (!IsCompactWidth() && !IsCompactHeight())
? kHorizontalSpacingRegularXRegular
: kHorizontalSpacingOther;
} else {
return IsIPadIdiom() ? kSpacingIPad : kSpacingIPhone;
}
}
CGFloat verticalSpacingBetweenTiles() {
if (IsUIRefreshPhase1Enabled()) {
return kVerticalSpacing;
} else {
return horizontalSpacingBetweenTiles();
}
}
CGFloat centeredTilesMarginForWidth(CGFloat width) {
NSUInteger columns = numberOfTilesForWidth(width - 2 * spacingBetweenTiles());
CGFloat horizontalSpace = horizontalSpacingBetweenTiles();
NSUInteger columns = numberOfTilesForWidth(width - 2 * horizontalSpace);
CGFloat whitespace =
width - columns * [ContentSuggestionsMostVisitedCell defaultSize].width -
(columns - 1) * spacingBetweenTiles();
width -
(columns * [ContentSuggestionsMostVisitedCell defaultSize].width) -
((columns - 1) * horizontalSpace);
CGFloat margin = AlignValueToPixel(whitespace / 2);
if (IsUIRefreshPhase1Enabled()) {
// Allow for less spacing as an edge case on smaller devices.
if (margin < spacingBetweenTiles()) {
if (margin < horizontalSpace) {
DCHECK(width < 400); // For now this is only expected on small widths.
return fmaxf(margin, 0);
}
} else {
DCHECK(margin >= spacingBetweenTiles());
DCHECK(margin > horizontalSpace);
}
return margin;
}
......
......@@ -425,7 +425,7 @@ BOOL ShouldCellsBeFullWidth(UITraitCollection* collection) {
}
contentHeight +=
2 * [ContentSuggestionsMostVisitedCell defaultSize].height;
contentHeight += content_suggestions::spacingBetweenTiles();
contentHeight += content_suggestions::verticalSpacingBetweenTiles();
// The Content Suggestions should idealy be displayed such as only part of
// the first suggestion is displayed. The distance should be capped to not
......@@ -450,7 +450,7 @@ BOOL ShouldCellsBeFullWidth(UITraitCollection* collection) {
collectionViewLayout
minimumLineSpacingForSectionAtIndex:(NSInteger)section {
if ([self.collectionUpdater isMostVisitedSection:section]) {
return content_suggestions::spacingBetweenTiles();
return content_suggestions::verticalSpacingBetweenTiles();
}
return [super collectionView:collectionView
layout:collectionViewLayout
......
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