OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/passwords/password_generation_prompt_view.h" | 5 #import "ios/chrome/browser/passwords/password_generation_prompt_view.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/ios/weak_nsobject.h" | 9 #include "base/ios/weak_nsobject.h" |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
13 #import "ios/chrome/browser/passwords/password_generation_prompt_delegate.h" | 13 #import "ios/chrome/browser/passwords/password_generation_prompt_delegate.h" |
14 #import "ios/chrome/browser/ui/rtl_geometry.h" | 14 #import "ios/chrome/browser/ui/rtl_geometry.h" |
15 #include "ios/chrome/browser/ui/ui_util.h" | 15 #include "ios/chrome/browser/ui/ui_util.h" |
16 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 16 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
17 #include "ios/chrome/common/string_util.h" | 17 #include "ios/chrome/common/string_util.h" |
18 #include "ios/chrome/grit/ios_strings.h" | 18 #include "ios/chrome/grit/ios_strings.h" |
19 #include "ios/chrome/grit/ios_theme_resources.h" | 19 #include "ios/chrome/grit/ios_theme_resources.h" |
20 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | 20 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" |
21 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 21 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Material Design Component constraints. | 27 // Material Design Component constraints. |
28 const CGFloat kMDCPadding = 24; | 28 const CGFloat kMDCPadding = 24; |
29 | 29 |
30 // Horizontal and vertical padding for the entire view. | 30 // Horizontal and vertical padding for the entire view. |
31 const CGFloat kPadding = 8.0f; | 31 const CGFloat kPadding = 8.0f; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 177 } |
178 | 178 |
179 - (void)layoutSubviews { | 179 - (void)layoutSubviews { |
180 [super layoutSubviews]; | 180 [super layoutSubviews]; |
181 // Make sure the title is spread on multiple lines if needed. | 181 // Make sure the title is spread on multiple lines if needed. |
182 [_title setPreferredMaxLayoutWidth:[_title frame].size.width]; | 182 [_title setPreferredMaxLayoutWidth:[_title frame].size.width]; |
183 } | 183 } |
184 | 184 |
185 - (UILabel*)titleLabel { | 185 - (UILabel*)titleLabel { |
186 NSMutableDictionary* attrsDictionary = [NSMutableDictionary | 186 NSMutableDictionary* attrsDictionary = [NSMutableDictionary |
187 dictionaryWithObject:[[MDFRobotoFontLoader sharedInstance] | 187 dictionaryWithObject:[[MDCTypography fontLoader] |
188 mediumFontOfSize:kTitleLabelFontSize] | 188 mediumFontOfSize:kTitleLabelFontSize] |
189 forKey:NSFontAttributeName]; | 189 forKey:NSFontAttributeName]; |
190 [attrsDictionary setObject:UIColorFromRGB(kTitleLabelFontColor) | 190 [attrsDictionary setObject:UIColorFromRGB(kTitleLabelFontColor) |
191 forKey:NSForegroundColorAttributeName]; | 191 forKey:NSForegroundColorAttributeName]; |
192 | 192 |
193 NSMutableAttributedString* string = [[[NSMutableAttributedString alloc] | 193 NSMutableAttributedString* string = [[[NSMutableAttributedString alloc] |
194 initWithString:l10n_util::GetNSString( | 194 initWithString:l10n_util::GetNSString( |
195 IDS_IOS_GENERATED_PASSWORD_PROMPT_TITLE) | 195 IDS_IOS_GENERATED_PASSWORD_PROMPT_TITLE) |
196 attributes:attrsDictionary] autorelease]; | 196 attributes:attrsDictionary] autorelease]; |
197 | 197 |
198 base::scoped_nsobject<UILabel> titleLabel([[UILabel alloc] init]); | 198 base::scoped_nsobject<UILabel> titleLabel([[UILabel alloc] init]); |
199 [titleLabel setAttributedText:string]; | 199 [titleLabel setAttributedText:string]; |
200 [titleLabel setNumberOfLines:0]; | 200 [titleLabel setNumberOfLines:0]; |
201 [titleLabel sizeToFit]; | 201 [titleLabel sizeToFit]; |
202 return titleLabel.autorelease(); | 202 return titleLabel.autorelease(); |
203 } | 203 } |
204 | 204 |
205 - (UILabel*)passwordLabel:(NSString*)password { | 205 - (UILabel*)passwordLabel:(NSString*)password { |
206 base::scoped_nsobject<UILabel> passwordLabel([[UILabel alloc] init]); | 206 base::scoped_nsobject<UILabel> passwordLabel([[UILabel alloc] init]); |
207 [passwordLabel setText:password]; | 207 [passwordLabel setText:password]; |
208 [passwordLabel setTextColor:UIColorFromRGB(kPasswordLabelFontColor)]; | 208 [passwordLabel setTextColor:UIColorFromRGB(kPasswordLabelFontColor)]; |
209 [passwordLabel setFont:[[MDFRobotoFontLoader sharedInstance] | 209 [passwordLabel setFont:[[MDCTypography fontLoader] |
210 regularFontOfSize:kPasswordLabelFontSize]]; | 210 regularFontOfSize:kPasswordLabelFontSize]]; |
211 [passwordLabel setNumberOfLines:1]; | 211 [passwordLabel setNumberOfLines:1]; |
212 [passwordLabel sizeToFit]; | 212 [passwordLabel sizeToFit]; |
213 return passwordLabel.autorelease(); | 213 return passwordLabel.autorelease(); |
214 } | 214 } |
215 | 215 |
216 - (UITextView*)description { | 216 - (UITextView*)description { |
217 NSRange linkRange; | 217 NSRange linkRange; |
218 NSString* description = ParseStringWithLink( | 218 NSString* description = ParseStringWithLink( |
219 l10n_util::GetNSString(IDS_IOS_GENERATED_PASSWORD_PROMPT_DESCRIPTION), | 219 l10n_util::GetNSString(IDS_IOS_GENERATED_PASSWORD_PROMPT_DESCRIPTION), |
220 &linkRange); | 220 &linkRange); |
221 | 221 |
222 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( | 222 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( |
223 [[NSMutableParagraphStyle alloc] init]); | 223 [[NSMutableParagraphStyle alloc] init]); |
224 [paragraphStyle setLineSpacing:kDescriptionLabelLineSpacing]; | 224 [paragraphStyle setLineSpacing:kDescriptionLabelLineSpacing]; |
225 | 225 |
226 NSDictionary* attributeDictionary = | 226 NSDictionary* attributeDictionary = |
227 [NSDictionary dictionaryWithObjectsAndKeys: | 227 [NSDictionary dictionaryWithObjectsAndKeys: |
228 UIColorFromRGB(kDescriptionLabelFontColor), | 228 UIColorFromRGB(kDescriptionLabelFontColor), |
229 NSForegroundColorAttributeName, paragraphStyle.get(), | 229 NSForegroundColorAttributeName, paragraphStyle.get(), |
230 NSParagraphStyleAttributeName, | 230 NSParagraphStyleAttributeName, |
231 [[MDFRobotoFontLoader sharedInstance] | 231 [[MDCTypography fontLoader] |
232 regularFontOfSize:kDescriptionLabelFontSize], | 232 regularFontOfSize:kDescriptionLabelFontSize], |
233 NSFontAttributeName, nil]; | 233 NSFontAttributeName, nil]; |
234 | 234 |
235 base::scoped_nsobject<NSMutableAttributedString> attributedString( | 235 base::scoped_nsobject<NSMutableAttributedString> attributedString( |
236 [[NSMutableAttributedString alloc] initWithString:description | 236 [[NSMutableAttributedString alloc] initWithString:description |
237 attributes:attributeDictionary]); | 237 attributes:attributeDictionary]); |
238 | 238 |
239 UITextView* descriptionView = | 239 UITextView* descriptionView = |
240 [[[UITextView alloc] initWithFrame:CGRectZero textContainer:nil] | 240 [[[UITextView alloc] initWithFrame:CGRectZero textContainer:nil] |
241 autorelease]; | 241 autorelease]; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 metrics:metrics | 388 metrics:metrics |
389 views:views]]; | 389 views:views]]; |
390 [self addConstraints:[NSLayoutConstraint | 390 [self addConstraints:[NSLayoutConstraint |
391 constraintsWithVisualFormat:@"H:|[view]|" | 391 constraintsWithVisualFormat:@"H:|[view]|" |
392 options:0 | 392 options:0 |
393 metrics:nil | 393 metrics:nil |
394 views:views]]; | 394 views:views]]; |
395 } | 395 } |
396 | 396 |
397 @end | 397 @end |
OLD | NEW |