OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/chrome/browser/ui/ntp/whats_new_header_view.h" | 5 #import "ios/chrome/browser/ui/ntp/whats_new_header_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 9 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
10 #include "ios/chrome/common/string_util.h" | 10 #include "ios/chrome/common/string_util.h" |
11 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 11 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
12 #include "ios/public/provider/chrome/browser/images/branded_image_provider.h" | 12 #include "ios/public/provider/chrome/browser/images/branded_image_provider.h" |
13 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 13 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 const CGFloat kLabelTopMargin = 16; | 17 const CGFloat kLabelTopMargin = 16; |
18 const CGFloat kLabelBottomMargin = 24; | 18 const CGFloat kLabelBottomMargin = 24; |
19 const CGFloat kLabelLineSpacing = 4; | 19 const CGFloat kLabelLineSpacing = 4; |
20 const CGFloat kLabelLeftMargin = 8; | 20 const CGFloat kLabelLeftMargin = 8; |
21 const CGFloat kLabelFontSize = 14; | 21 const CGFloat kLabelFontSize = 14; |
22 const CGFloat kInfoIconSize = 24; | 22 const CGFloat kInfoIconSize = 24; |
23 const CGFloat kInfoIconTopMargin = 12; | 23 const CGFloat kInfoIconTopMargin = 12; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 [attributedText addAttribute:NSParagraphStyleAttributeName | 176 [attributedText addAttribute:NSParagraphStyleAttributeName |
177 value:style | 177 value:style |
178 range:NSMakeRange(0, strLength)]; | 178 range:NSMakeRange(0, strLength)]; |
179 | 179 |
180 [promoLabel setAttributedText:attributedText]; | 180 [promoLabel setAttributedText:attributedText]; |
181 } | 181 } |
182 | 182 |
183 + (UILabel*)promoLabel { | 183 + (UILabel*)promoLabel { |
184 base::scoped_nsobject<UILabel> promoLabel( | 184 base::scoped_nsobject<UILabel> promoLabel( |
185 [[UILabel alloc] initWithFrame:CGRectZero]); | 185 [[UILabel alloc] initWithFrame:CGRectZero]); |
186 [promoLabel setFont:[[MDFRobotoFontLoader sharedInstance] | 186 [promoLabel |
187 regularFontOfSize:kLabelFontSize]]; | 187 setFont:[[MDCTypography fontLoader] regularFontOfSize:kLabelFontSize]]; |
188 [promoLabel setTextColor:UIColorFromRGB(kTextColorRgb, 1.0)]; | 188 [promoLabel setTextColor:UIColorFromRGB(kTextColorRgb, 1.0)]; |
189 [promoLabel setNumberOfLines:0]; | 189 [promoLabel setNumberOfLines:0]; |
190 [promoLabel setTextAlignment:NSTextAlignmentNatural]; | 190 [promoLabel setTextAlignment:NSTextAlignmentNatural]; |
191 [promoLabel setLineBreakMode:NSLineBreakByWordWrapping]; | 191 [promoLabel setLineBreakMode:NSLineBreakByWordWrapping]; |
192 return promoLabel.autorelease(); | 192 return promoLabel.autorelease(); |
193 } | 193 } |
194 | 194 |
195 + (int)heightToFitText:(NSString*)text inWidth:(CGFloat)width { | 195 + (int)heightToFitText:(NSString*)text inWidth:(CGFloat)width { |
196 CGFloat maxWidthForLabel = width - kInfoIconSize - kLabelLeftMargin; | 196 CGFloat maxWidthForLabel = width - kInfoIconSize - kLabelLeftMargin; |
197 base::scoped_nsobject<UILabel> promoLabel([[self promoLabel] retain]); | 197 base::scoped_nsobject<UILabel> promoLabel([[self promoLabel] retain]); |
198 [[self class] setText:text inPromoLabel:promoLabel.get()]; | 198 [[self class] setText:text inPromoLabel:promoLabel.get()]; |
199 CGFloat promoLabelHeight = | 199 CGFloat promoLabelHeight = |
200 [promoLabel sizeThatFits:CGSizeMake(maxWidthForLabel, CGFLOAT_MAX)] | 200 [promoLabel sizeThatFits:CGSizeMake(maxWidthForLabel, CGFLOAT_MAX)] |
201 .height; | 201 .height; |
202 return promoLabelHeight + kLabelTopMargin + kLabelBottomMargin; | 202 return promoLabelHeight + kLabelTopMargin + kLabelBottomMargin; |
203 } | 203 } |
204 | 204 |
205 @end | 205 @end |
OLD | NEW |