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/content_suggestions/content_suggestions_collectio n_utils.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_mos t_visited_item.h" | |
| 9 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_mos t_visited_tile.h" | |
| 10 #include "ios/chrome/browser/ui/ui_util.h" | |
| 11 | |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 13 #error "This file requires ARC support." | |
| 14 #endif | |
| 15 | |
| 16 namespace { | |
| 17 const CGFloat kMaxSearchFieldFrameMargin = 200; | |
| 18 const CGFloat kDoodleTopMarginIPadPortrait = 82; | |
| 19 const CGFloat kDoodleTopMarginIPadLandscape = 82; | |
| 20 const CGFloat kNTPSearchFieldBottomPadding = 16; | |
| 21 | |
| 22 // Height for the doodle frame when Google is not the default search engine. | |
| 23 const CGFloat kNonGoogleSearchDoodleHeight = 60; | |
| 24 // Height for the header view on tablet when Google is not the default search | |
| 25 // engine. | |
| 26 const CGFloat kNonGoogleSearchHeaderHeightIPad = 10; | |
| 27 | |
| 28 enum InterfaceOrientation { | |
| 29 ALL, | |
| 30 IPHONE_LANDSCAPE, | |
| 31 }; | |
| 32 } | |
| 33 | |
| 34 namespace content_suggestions { | |
| 35 | |
| 36 CGRect getOrientationFrame(const CGRect frames[], CGFloat width) { | |
| 37 UIInterfaceOrientation orient = | |
|
marq (ping after 24h)
2017/05/04 08:15:00
Rather than having to have two variables that shou
gambard
2017/05/04 15:12:32
Done.
| |
| 38 [[UIApplication sharedApplication] statusBarOrientation]; | |
| 39 InterfaceOrientation inter_orient = | |
|
marq (ping after 24h)
2017/05/04 08:15:00
inter_orient -> orientation
gambard
2017/05/04 15:12:32
Done.
| |
| 40 (IsIPadIdiom() || UIInterfaceOrientationIsPortrait(orient)) | |
| 41 ? ALL | |
| 42 : IPHONE_LANDSCAPE; | |
| 43 | |
| 44 // Calculate width based on screen width and origin x. | |
| 45 CGRect frame = frames[inter_orient]; | |
|
marq (ping after 24h)
2017/05/04 08:15:00
Since this depends on ALL == 0, please add explici
gambard
2017/05/04 15:12:31
Done.
| |
| 46 frame.size.width = fmax(width - 2 * frame.origin.x, 50); | |
| 47 return frame; | |
| 48 } | |
| 49 | |
| 50 CGFloat leftMarginForWidth(CGFloat width) { | |
| 51 NSUInteger columns = [ContentSuggestionsMostVisitedCell | |
| 52 numberOfTilesForWidth:width - | |
| 53 2 * [ContentSuggestionsMostVisitedCell spacing]]; | |
| 54 CGFloat whitespace = | |
| 55 width - columns * [ContentSuggestionsMostVisitedTile width] - | |
| 56 (columns - 1) * [ContentSuggestionsMostVisitedCell spacing]; | |
| 57 CGFloat margin = AlignValueToPixel(whitespace / 2); | |
| 58 DCHECK(margin >= [ContentSuggestionsMostVisitedCell spacing]); | |
| 59 return margin; | |
| 60 } | |
| 61 | |
| 62 CGRect doodleFrame(CGFloat width, BOOL logoIsShowing) { | |
| 63 const CGRect kDoodleFrame[2] = { | |
| 64 {{0, 66}, {0, 120}}, {{0, 56}, {0, 120}}, | |
|
marq (ping after 24h)
2017/05/04 08:15:00
Please use CGRectMake instead of bare struct assig
gambard
2017/05/04 15:12:32
Done.
| |
| 65 }; | |
| 66 CGRect doodleFrame = getOrientationFrame(kDoodleFrame, width); | |
| 67 if (!IsIPadIdiom() && !logoIsShowing) | |
| 68 doodleFrame.size.height = kNonGoogleSearchDoodleHeight; | |
| 69 if (IsIPadIdiom()) { | |
| 70 doodleFrame.origin.y = IsPortrait() ? kDoodleTopMarginIPadPortrait | |
| 71 : kDoodleTopMarginIPadLandscape; | |
| 72 } | |
| 73 return doodleFrame; | |
| 74 } | |
| 75 | |
| 76 CGRect searchFieldFrame(CGFloat width, BOOL logoIsShowing) { | |
| 77 CGFloat y = CGRectGetMaxY(doodleFrame(width, logoIsShowing)); | |
| 78 CGFloat leftMargin = leftMarginForWidth(width); | |
| 79 if (leftMargin > kMaxSearchFieldFrameMargin) | |
| 80 leftMargin = kMaxSearchFieldFrameMargin; | |
| 81 const CGRect kSearchFieldFrame[2] = { | |
| 82 {{leftMargin, y + 32}, {0, 50}}, {{leftMargin, y + 16}, {0, 50}}, | |
|
marq (ping after 24h)
2017/05/04 08:15:00
CGRectMake.
gambard
2017/05/04 15:12:32
Done.
| |
| 83 }; | |
|
marq (ping after 24h)
2017/05/04 08:15:00
This seems like it's broken for RTL? If we don't c
gambard
2017/05/04 15:12:32
The "leftMargin" name was misleading. I corrected
| |
| 84 CGRect searchFieldFrame = getOrientationFrame(kSearchFieldFrame, width); | |
| 85 if (IsIPadIdiom()) { | |
| 86 CGFloat iPadTopMargin = IsPortrait() ? kDoodleTopMarginIPadPortrait | |
| 87 : kDoodleTopMarginIPadLandscape; | |
| 88 searchFieldFrame.origin.y += iPadTopMargin - 32; | |
| 89 } | |
| 90 return searchFieldFrame; | |
| 91 } | |
| 92 | |
| 93 CGFloat heightForLogoHeader(CGFloat width, | |
| 94 BOOL logoIsShowing, | |
| 95 BOOL promoCanShow) { | |
| 96 CGFloat headerHeight = CGRectGetMaxY(searchFieldFrame(width, logoIsShowing)) + | |
| 97 kNTPSearchFieldBottomPadding; | |
| 98 if (IsIPadIdiom()) { | |
| 99 if (logoIsShowing) { | |
| 100 if (!promoCanShow) { | |
| 101 UIInterfaceOrientation orient = | |
| 102 [[UIApplication sharedApplication] statusBarOrientation]; | |
| 103 const CGFloat kTopSpacingMaterialPortrait = 56; | |
| 104 const CGFloat kTopSpacingMaterialLandscape = 32; | |
| 105 headerHeight += UIInterfaceOrientationIsPortrait(orient) | |
| 106 ? kTopSpacingMaterialPortrait | |
| 107 : kTopSpacingMaterialLandscape; | |
| 108 } | |
| 109 } else { | |
| 110 headerHeight = kNonGoogleSearchHeaderHeightIPad; | |
| 111 } | |
| 112 } | |
| 113 return headerHeight; | |
|
marq (ping after 24h)
2017/05/04 08:15:00
Maybe un-nest some of the conditionals here for cl
gambard
2017/05/04 15:12:32
Done.
| |
| 114 } | |
| 115 | |
| 116 } // namespace content_suggestions | |
| OLD | NEW |