| 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/first_run/welcome_to_chrome_view.h" | 5 #import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #import "base/ios/weak_nsobject.h" | |
| 9 #include "base/logging.h" | 8 #include "base/logging.h" |
| 10 #import "base/mac/scoped_nsobject.h" | |
| 11 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 12 #import "ios/chrome/browser/ui/UIView+SizeClassSupport.h" | 10 #import "ios/chrome/browser/ui/UIView+SizeClassSupport.h" |
| 13 #include "ios/chrome/browser/ui/fancy_ui/primary_action_button.h" | 11 #include "ios/chrome/browser/ui/fancy_ui/primary_action_button.h" |
| 14 #include "ios/chrome/browser/ui/first_run/first_run_util.h" | 12 #include "ios/chrome/browser/ui/first_run/first_run_util.h" |
| 15 #include "ios/chrome/browser/ui/ui_util.h" | 13 #include "ios/chrome/browser/ui/ui_util.h" |
| 16 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 14 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 17 #import "ios/chrome/browser/ui/util/CRUILabel+AttributeUtils.h" | 15 #import "ios/chrome/browser/ui/util/CRUILabel+AttributeUtils.h" |
| 18 #import "ios/chrome/browser/ui/util/label_link_controller.h" | 16 #import "ios/chrome/browser/ui/util/label_link_controller.h" |
| 19 #include "ios/chrome/common/string_util.h" | 17 #include "ios/chrome/common/string_util.h" |
| 20 #include "ios/chrome/grit/ios_chromium_strings.h" | 18 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 21 #include "ios/chrome/grit/ios_strings.h" | 19 #include "ios/chrome/grit/ios_strings.h" |
| 22 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 20 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 25 | 23 |
| 24 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 25 #error "This file requires ARC support." |
| 26 #endif |
| 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 28 // Accessibility identifier for the checkbox button. | 30 // Accessibility identifier for the checkbox button. |
| 29 NSString* const kUMAMetricsButtonAccessibilityIdentifier = | 31 NSString* const kUMAMetricsButtonAccessibilityIdentifier = |
| 30 @"UMAMetricsButtonAccessibilityIdentifier"; | 32 @"UMAMetricsButtonAccessibilityIdentifier"; |
| 31 | 33 |
| 32 // Color of "Terms of Service" link text. | 34 // Color of "Terms of Service" link text. |
| 33 const int kLinkColorRGB = 0x5D9AFF; | 35 const int kLinkColorRGB = 0x5D9AFF; |
| 34 | 36 |
| 35 // The width of the container view for a REGULAR width size class. | 37 // The width of the container view for a REGULAR width size class. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 63 const CGFloat kAnimationDelay = .5; | 65 const CGFloat kAnimationDelay = .5; |
| 64 | 66 |
| 65 // Image names. | 67 // Image names. |
| 66 NSString* const kAppLogoImageName = @"launchscreen_app_logo"; | 68 NSString* const kAppLogoImageName = @"launchscreen_app_logo"; |
| 67 NSString* const kCheckBoxImageName = @"checkbox"; | 69 NSString* const kCheckBoxImageName = @"checkbox"; |
| 68 NSString* const kCheckBoxCheckedImageName = @"checkbox_checked"; | 70 NSString* const kCheckBoxCheckedImageName = @"checkbox_checked"; |
| 69 | 71 |
| 70 } // namespace | 72 } // namespace |
| 71 | 73 |
| 72 @interface WelcomeToChromeView () { | 74 @interface WelcomeToChromeView () { |
| 73 // Backing objects for properties of the same name. | 75 UIView* _containerView; |
| 74 base::WeakNSProtocol<id<WelcomeToChromeViewDelegate>> _delegate; | 76 UILabel* _titleLabel; |
| 75 base::scoped_nsobject<UIView> _containerView; | 77 UIImageView* _imageView; |
| 76 base::scoped_nsobject<UILabel> _titleLabel; | 78 UILabel* _TOSLabel; |
| 77 base::scoped_nsobject<UIImageView> _imageView; | 79 LabelLinkController* _TOSLabelLinkController; |
| 78 base::scoped_nsobject<UILabel> _TOSLabel; | 80 UIButton* _checkBoxButton; |
| 79 base::scoped_nsobject<LabelLinkController> _TOSLabelLinkController; | 81 UILabel* _optInLabel; |
| 80 base::scoped_nsobject<UIButton> _checkBoxButton; | 82 PrimaryActionButton* _OKButton; |
| 81 base::scoped_nsobject<UILabel> _optInLabel; | |
| 82 base::scoped_nsobject<PrimaryActionButton> _OKButton; | |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Subview properties are lazily instantiated upon their first use. | 85 // Subview properties are lazily instantiated upon their first use. |
| 86 | 86 |
| 87 // A container view used to layout and center subviews. | 87 // A container view used to layout and center subviews. |
| 88 @property(nonatomic, readonly) UIView* containerView; | 88 @property(strong, nonatomic, readonly) UIView* containerView; |
| 89 // The "Welcome to Chrome" label that appears at the top of the view. | 89 // The "Welcome to Chrome" label that appears at the top of the view. |
| 90 @property(nonatomic, readonly) UILabel* titleLabel; | 90 @property(strong, nonatomic, readonly) UILabel* titleLabel; |
| 91 // The Chrome logo image view. | 91 // The Chrome logo image view. |
| 92 @property(nonatomic, readonly) UIImageView* imageView; | 92 @property(strong, nonatomic, readonly) UIImageView* imageView; |
| 93 // The "Terms of Service" label. | 93 // The "Terms of Service" label. |
| 94 @property(nonatomic, readonly) UILabel* TOSLabel; | 94 @property(strong, nonatomic, readonly) UILabel* TOSLabel; |
| 95 // The stats reporting opt-in label. | 95 // The stats reporting opt-in label. |
| 96 @property(nonatomic, readonly) UILabel* optInLabel; | 96 @property(strong, nonatomic, readonly) UILabel* optInLabel; |
| 97 // The stats reporting opt-in checkbox button. | 97 // The stats reporting opt-in checkbox button. |
| 98 @property(nonatomic, readonly) UIButton* checkBoxButton; | 98 @property(strong, nonatomic, readonly) UIButton* checkBoxButton; |
| 99 // The "Accept & Continue" button. | 99 // The "Accept & Continue" button. |
| 100 @property(nonatomic, readonly) PrimaryActionButton* OKButton; | 100 @property(strong, nonatomic, readonly) PrimaryActionButton* OKButton; |
| 101 | 101 |
| 102 // Subview layout methods. They must be called in the order declared here, as | 102 // Subview layout methods. They must be called in the order declared here, as |
| 103 // subsequent subview layouts depend on the layouts that precede them. | 103 // subsequent subview layouts depend on the layouts that precede them. |
| 104 - (void)layoutTitleLabel; | 104 - (void)layoutTitleLabel; |
| 105 - (void)layoutImageView; | 105 - (void)layoutImageView; |
| 106 - (void)layoutTOSLabel; | 106 - (void)layoutTOSLabel; |
| 107 - (void)layoutOptInLabel; | 107 - (void)layoutOptInLabel; |
| 108 - (void)layoutCheckBoxButton; | 108 - (void)layoutCheckBoxButton; |
| 109 - (void)layoutContainerView; | 109 - (void)layoutContainerView; |
| 110 - (void)layoutOKButton; | 110 - (void)layoutOKButton; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 127 - (void)OKButtonWasTapped; | 127 - (void)OKButtonWasTapped; |
| 128 | 128 |
| 129 // The TOS label button was tapped. | 129 // The TOS label button was tapped. |
| 130 // TODO(crbug.com/539961): Remove once link detection is fixed. | 130 // TODO(crbug.com/539961): Remove once link detection is fixed. |
| 131 - (void)TOSLinkWasTapped; | 131 - (void)TOSLinkWasTapped; |
| 132 | 132 |
| 133 @end | 133 @end |
| 134 | 134 |
| 135 @implementation WelcomeToChromeView | 135 @implementation WelcomeToChromeView |
| 136 | 136 |
| 137 @synthesize delegate = _delegate; |
| 138 |
| 137 - (instancetype)initWithFrame:(CGRect)frame { | 139 - (instancetype)initWithFrame:(CGRect)frame { |
| 138 self = [super initWithFrame:frame]; | 140 self = [super initWithFrame:frame]; |
| 139 if (self) { | 141 if (self) { |
| 140 self.backgroundColor = [UIColor whiteColor]; | 142 self.backgroundColor = [UIColor whiteColor]; |
| 141 self.autoresizingMask = | 143 self.autoresizingMask = |
| 142 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 144 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 143 } | 145 } |
| 144 return self; | 146 return self; |
| 145 } | 147 } |
| 146 | 148 |
| 147 - (void)runLaunchAnimation { | 149 - (void)runLaunchAnimation { |
| 148 // Prepare for animation by making views (except for the logo) transparent | 150 // Prepare for animation by making views (except for the logo) transparent |
| 149 // and finding the initial and final location of the logo. | 151 // and finding the initial and final location of the logo. |
| 150 self.titleLabel.alpha = 0.0; | 152 self.titleLabel.alpha = 0.0; |
| 151 self.TOSLabel.alpha = 0.0; | 153 self.TOSLabel.alpha = 0.0; |
| 152 self.optInLabel.alpha = 0.0; | 154 self.optInLabel.alpha = 0.0; |
| 153 self.checkBoxButton.alpha = 0.0; | 155 self.checkBoxButton.alpha = 0.0; |
| 154 self.OKButton.alpha = 0.0; | 156 self.OKButton.alpha = 0.0; |
| 155 | 157 |
| 156 // Get final location of logo based on result from previously run | 158 // Get final location of logo based on result from previously run |
| 157 // layoutSubviews. | 159 // layoutSubviews. |
| 158 CGRect finalLogoFrame = self.imageView.frame; | 160 CGRect finalLogoFrame = self.imageView.frame; |
| 159 // Ensure that frame position is valid and that layoutSubviews ran | 161 // Ensure that frame position is valid and that layoutSubviews ran |
| 160 // before this method. | 162 // before this method. |
| 161 DCHECK(finalLogoFrame.origin.x >= 0 && finalLogoFrame.origin.y >= 0); | 163 DCHECK(finalLogoFrame.origin.x >= 0 && finalLogoFrame.origin.y >= 0); |
| 162 self.imageView.center = CGPointMake(CGRectGetMidX(self.containerView.bounds), | 164 self.imageView.center = CGPointMake(CGRectGetMidX(self.containerView.bounds), |
| 163 CGRectGetMidY(self.containerView.bounds)); | 165 CGRectGetMidY(self.containerView.bounds)); |
| 164 | 166 |
| 165 base::WeakNSObject<WelcomeToChromeView> weakSelf(self); | 167 __weak WelcomeToChromeView* weakSelf = self; |
| 166 [UIView animateWithDuration:kAnimationDuration | 168 [UIView animateWithDuration:kAnimationDuration |
| 167 delay:kAnimationDelay | 169 delay:kAnimationDelay |
| 168 options:UIViewAnimationCurveEaseInOut | 170 options:UIViewAnimationCurveEaseInOut |
| 169 animations:^{ | 171 animations:^{ |
| 170 [weakSelf imageView].frame = finalLogoFrame; | 172 [weakSelf imageView].frame = finalLogoFrame; |
| 171 [weakSelf titleLabel].alpha = 1.0; | 173 [weakSelf titleLabel].alpha = 1.0; |
| 172 [weakSelf TOSLabel].alpha = 1.0; | 174 [weakSelf TOSLabel].alpha = 1.0; |
| 173 [weakSelf optInLabel].alpha = 1.0; | 175 [weakSelf optInLabel].alpha = 1.0; |
| 174 [weakSelf checkBoxButton].alpha = 1.0; | 176 [weakSelf checkBoxButton].alpha = 1.0; |
| 175 [weakSelf OKButton].alpha = 1.0; | 177 [weakSelf OKButton].alpha = 1.0; |
| 176 } | 178 } |
| 177 completion:nil]; | 179 completion:nil]; |
| 178 } | 180 } |
| 179 | 181 |
| 180 #pragma mark - Accessors | 182 #pragma mark - Accessors |
| 181 | 183 |
| 182 - (id<WelcomeToChromeViewDelegate>)delegate { | |
| 183 return _delegate; | |
| 184 } | |
| 185 | |
| 186 - (void)setDelegate:(id<WelcomeToChromeViewDelegate>)delegate { | |
| 187 _delegate.reset(delegate); | |
| 188 } | |
| 189 | |
| 190 - (BOOL)isCheckBoxSelected { | 184 - (BOOL)isCheckBoxSelected { |
| 191 return self.checkBoxButton.selected; | 185 return self.checkBoxButton.selected; |
| 192 } | 186 } |
| 193 | 187 |
| 194 - (void)setCheckBoxSelected:(BOOL)checkBoxSelected { | 188 - (void)setCheckBoxSelected:(BOOL)checkBoxSelected { |
| 195 if (checkBoxSelected != self.checkBoxButton.selected) | 189 if (checkBoxSelected != self.checkBoxButton.selected) |
| 196 [self checkBoxButtonWasTapped]; | 190 [self checkBoxButtonWasTapped]; |
| 197 } | 191 } |
| 198 | 192 |
| 199 - (UIView*)containerView { | 193 - (UIView*)containerView { |
| 200 if (!_containerView) { | 194 if (!_containerView) { |
| 201 _containerView.reset([[UIView alloc] initWithFrame:CGRectZero]); | 195 _containerView = [[UIView alloc] initWithFrame:CGRectZero]; |
| 202 [_containerView setBackgroundColor:[UIColor whiteColor]]; | 196 [_containerView setBackgroundColor:[UIColor whiteColor]]; |
| 203 } | 197 } |
| 204 return _containerView.get(); | 198 return _containerView; |
| 205 } | 199 } |
| 206 | 200 |
| 207 - (UILabel*)titleLabel { | 201 - (UILabel*)titleLabel { |
| 208 if (!_titleLabel) { | 202 if (!_titleLabel) { |
| 209 _titleLabel.reset([[UILabel alloc] initWithFrame:CGRectZero]); | 203 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 210 [_titleLabel setBackgroundColor:[UIColor whiteColor]]; | 204 [_titleLabel setBackgroundColor:[UIColor whiteColor]]; |
| 211 [_titleLabel setNumberOfLines:0]; | 205 [_titleLabel setNumberOfLines:0]; |
| 212 [_titleLabel setLineBreakMode:NSLineBreakByWordWrapping]; | 206 [_titleLabel setLineBreakMode:NSLineBreakByWordWrapping]; |
| 213 [_titleLabel setBaselineAdjustment:UIBaselineAdjustmentAlignBaselines]; | 207 [_titleLabel setBaselineAdjustment:UIBaselineAdjustmentAlignBaselines]; |
| 214 [_titleLabel | 208 [_titleLabel |
| 215 setText:l10n_util::GetNSString(IDS_IOS_FIRSTRUN_WELCOME_TO_CHROME)]; | 209 setText:l10n_util::GetNSString(IDS_IOS_FIRSTRUN_WELCOME_TO_CHROME)]; |
| 216 } | 210 } |
| 217 return _titleLabel.get(); | 211 return _titleLabel; |
| 218 } | 212 } |
| 219 | 213 |
| 220 - (UIImageView*)imageView { | 214 - (UIImageView*)imageView { |
| 221 if (!_imageView) { | 215 if (!_imageView) { |
| 222 UIImage* image = [UIImage imageNamed:kAppLogoImageName]; | 216 UIImage* image = [UIImage imageNamed:kAppLogoImageName]; |
| 223 _imageView.reset([[UIImageView alloc] initWithImage:image]); | 217 _imageView = [[UIImageView alloc] initWithImage:image]; |
| 224 [_imageView setBackgroundColor:[UIColor whiteColor]]; | 218 [_imageView setBackgroundColor:[UIColor whiteColor]]; |
| 225 } | 219 } |
| 226 return _imageView.get(); | 220 return _imageView; |
| 227 } | 221 } |
| 228 | 222 |
| 229 - (UILabel*)TOSLabel { | 223 - (UILabel*)TOSLabel { |
| 230 if (!_TOSLabel) { | 224 if (!_TOSLabel) { |
| 231 _TOSLabel.reset([[UILabel alloc] initWithFrame:CGRectZero]); | 225 _TOSLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 232 [_TOSLabel setNumberOfLines:0]; | 226 [_TOSLabel setNumberOfLines:0]; |
| 233 [_TOSLabel setTextAlignment:NSTextAlignmentCenter]; | 227 [_TOSLabel setTextAlignment:NSTextAlignmentCenter]; |
| 234 } | 228 } |
| 235 return _TOSLabel.get(); | 229 return _TOSLabel; |
| 236 } | 230 } |
| 237 | 231 |
| 238 - (UILabel*)optInLabel { | 232 - (UILabel*)optInLabel { |
| 239 if (!_optInLabel) { | 233 if (!_optInLabel) { |
| 240 _optInLabel.reset([[UILabel alloc] initWithFrame:CGRectZero]); | 234 _optInLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 241 [_optInLabel setNumberOfLines:0]; | 235 [_optInLabel setNumberOfLines:0]; |
| 242 [_optInLabel | 236 [_optInLabel |
| 243 setText:l10n_util::GetNSString(IDS_IOS_FIRSTRUN_NEW_OPT_IN_LABEL)]; | 237 setText:l10n_util::GetNSString(IDS_IOS_FIRSTRUN_NEW_OPT_IN_LABEL)]; |
| 244 [_optInLabel setTextAlignment:NSTextAlignmentNatural]; | 238 [_optInLabel setTextAlignment:NSTextAlignmentNatural]; |
| 245 } | 239 } |
| 246 return _optInLabel.get(); | 240 return _optInLabel; |
| 247 } | 241 } |
| 248 | 242 |
| 249 - (UIButton*)checkBoxButton { | 243 - (UIButton*)checkBoxButton { |
| 250 if (!_checkBoxButton) { | 244 if (!_checkBoxButton) { |
| 251 _checkBoxButton.reset([[UIButton alloc] initWithFrame:CGRectZero]); | 245 _checkBoxButton = [[UIButton alloc] initWithFrame:CGRectZero]; |
| 252 [_checkBoxButton setBackgroundColor:[UIColor clearColor]]; | 246 [_checkBoxButton setBackgroundColor:[UIColor clearColor]]; |
| 253 [_checkBoxButton addTarget:self | 247 [_checkBoxButton addTarget:self |
| 254 action:@selector(checkBoxButtonWasTapped) | 248 action:@selector(checkBoxButtonWasTapped) |
| 255 forControlEvents:UIControlEventTouchUpInside]; | 249 forControlEvents:UIControlEventTouchUpInside]; |
| 256 SetA11yLabelAndUiAutomationName(_checkBoxButton, | 250 SetA11yLabelAndUiAutomationName(_checkBoxButton, |
| 257 IDS_IOS_FIRSTRUN_NEW_OPT_IN_LABEL, | 251 IDS_IOS_FIRSTRUN_NEW_OPT_IN_LABEL, |
| 258 kUMAMetricsButtonAccessibilityIdentifier); | 252 kUMAMetricsButtonAccessibilityIdentifier); |
| 259 [_checkBoxButton | 253 [_checkBoxButton |
| 260 setAccessibilityValue:l10n_util::GetNSString(IDS_IOS_SETTING_OFF)]; | 254 setAccessibilityValue:l10n_util::GetNSString(IDS_IOS_SETTING_OFF)]; |
| 261 [_checkBoxButton setImage:[UIImage imageNamed:kCheckBoxImageName] | 255 [_checkBoxButton setImage:[UIImage imageNamed:kCheckBoxImageName] |
| 262 forState:UIControlStateNormal]; | 256 forState:UIControlStateNormal]; |
| 263 [_checkBoxButton setImage:[UIImage imageNamed:kCheckBoxCheckedImageName] | 257 [_checkBoxButton setImage:[UIImage imageNamed:kCheckBoxCheckedImageName] |
| 264 forState:UIControlStateSelected]; | 258 forState:UIControlStateSelected]; |
| 265 } | 259 } |
| 266 return _checkBoxButton.get(); | 260 return _checkBoxButton; |
| 267 } | 261 } |
| 268 | 262 |
| 269 - (PrimaryActionButton*)OKButton { | 263 - (PrimaryActionButton*)OKButton { |
| 270 if (!_OKButton) { | 264 if (!_OKButton) { |
| 271 _OKButton.reset([[PrimaryActionButton alloc] initWithFrame:CGRectZero]); | 265 _OKButton = [[PrimaryActionButton alloc] initWithFrame:CGRectZero]; |
| 272 [_OKButton addTarget:self | 266 [_OKButton addTarget:self |
| 273 action:@selector(OKButtonWasTapped) | 267 action:@selector(OKButtonWasTapped) |
| 274 forControlEvents:UIControlEventTouchUpInside]; | 268 forControlEvents:UIControlEventTouchUpInside]; |
| 275 NSString* acceptAndContinue = | 269 NSString* acceptAndContinue = |
| 276 l10n_util::GetNSString(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON); | 270 l10n_util::GetNSString(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON); |
| 277 [_OKButton setTitle:acceptAndContinue forState:UIControlStateNormal]; | 271 [_OKButton setTitle:acceptAndContinue forState:UIControlStateNormal]; |
| 278 [_OKButton setTitle:acceptAndContinue forState:UIControlStateHighlighted]; | 272 [_OKButton setTitle:acceptAndContinue forState:UIControlStateHighlighted]; |
| 279 // UIAutomation tests look for the Accept button to skip through the | 273 // UIAutomation tests look for the Accept button to skip through the |
| 280 // First Run UI when it shows up. | 274 // First Run UI when it shows up. |
| 281 SetA11yLabelAndUiAutomationName( | 275 SetA11yLabelAndUiAutomationName( |
| 282 _OKButton, IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON, @"Accept & Continue"); | 276 _OKButton, IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON, @"Accept & Continue"); |
| 283 } | 277 } |
| 284 return _OKButton.get(); | 278 return _OKButton; |
| 285 } | 279 } |
| 286 | 280 |
| 287 #pragma mark - Layout | 281 #pragma mark - Layout |
| 288 | 282 |
| 289 - (void)willMoveToSuperview:(nullable UIView*)newSuperview { | 283 - (void)willMoveToSuperview:(nullable UIView*)newSuperview { |
| 290 [super willMoveToSuperview:newSuperview]; | 284 [super willMoveToSuperview:newSuperview]; |
| 291 | 285 |
| 292 // Early return if the view hierarchy is already built. | 286 // Early return if the view hierarchy is already built. |
| 293 if (self.containerView.superview) { | 287 if (self.containerView.superview) { |
| 294 DCHECK_EQ(self, self.containerView.superview); | 288 DCHECK_EQ(self, self.containerView.superview); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 self.TOSLabel.text = strippedText; | 346 self.TOSLabel.text = strippedText; |
| 353 if (ios_internal::FixOrphanWord(self.TOSLabel)) { | 347 if (ios_internal::FixOrphanWord(self.TOSLabel)) { |
| 354 // If a newline is inserted, check whether it was added mid-link and adjust | 348 // If a newline is inserted, check whether it was added mid-link and adjust |
| 355 // |linkTextRange| accordingly. | 349 // |linkTextRange| accordingly. |
| 356 NSRange newlineRange = | 350 NSRange newlineRange = |
| 357 [self.TOSLabel.text rangeOfString:@"\n" options:0 range:linkTextRange]; | 351 [self.TOSLabel.text rangeOfString:@"\n" options:0 range:linkTextRange]; |
| 358 if (newlineRange.length) | 352 if (newlineRange.length) |
| 359 linkTextRange.length++; | 353 linkTextRange.length++; |
| 360 } | 354 } |
| 361 | 355 |
| 362 base::WeakNSObject<WelcomeToChromeView> weakSelf(self); | 356 __weak WelcomeToChromeView* weakSelf = self; |
| 363 ProceduralBlockWithURL action = ^(const GURL& url) { | 357 ProceduralBlockWithURL action = ^(const GURL& url) { |
| 364 base::scoped_nsobject<WelcomeToChromeView> strongSelf([weakSelf retain]); | 358 WelcomeToChromeView* strongSelf = weakSelf; |
| 365 if (!strongSelf) | 359 if (!strongSelf) |
| 366 return; | 360 return; |
| 367 [[strongSelf delegate] welcomeToChromeViewDidTapTOSLink:strongSelf]; | 361 [[strongSelf delegate] welcomeToChromeViewDidTapTOSLink:strongSelf]; |
| 368 }; | 362 }; |
| 369 | 363 |
| 370 _TOSLabelLinkController.reset( | 364 _TOSLabelLinkController = |
| 371 [[LabelLinkController alloc] initWithLabel:_TOSLabel action:action]); | 365 [[LabelLinkController alloc] initWithLabel:_TOSLabel action:action]; |
| 372 [_TOSLabelLinkController | 366 [_TOSLabelLinkController |
| 373 addLinkWithRange:linkTextRange | 367 addLinkWithRange:linkTextRange |
| 374 url:GURL("internal://terms-of-service")]; | 368 url:GURL("internal://terms-of-service")]; |
| 375 [_TOSLabelLinkController setLinkColor:UIColorFromRGB(kLinkColorRGB)]; | 369 [_TOSLabelLinkController setLinkColor:UIColorFromRGB(kLinkColorRGB)]; |
| 376 | 370 |
| 377 CGSize TOSLabelSize = [self.TOSLabel sizeThatFits:containerSize]; | 371 CGSize TOSLabelSize = [self.TOSLabel sizeThatFits:containerSize]; |
| 378 CGFloat TOSLabelTopPadding = kTOSLabelTopPadding[self.cr_heightSizeClass]; | 372 CGFloat TOSLabelTopPadding = kTOSLabelTopPadding[self.cr_heightSizeClass]; |
| 379 self.TOSLabel.frame = AlignRectOriginAndSizeToPixels( | 373 self.TOSLabel.frame = AlignRectOriginAndSizeToPixels( |
| 380 CGRectMake((containerSize.width - TOSLabelSize.width) / 2.0, | 374 CGRectMake((containerSize.width - TOSLabelSize.width) / 2.0, |
| 381 CGRectGetMaxY(self.imageView.frame) + TOSLabelTopPadding, | 375 CGRectGetMaxY(self.imageView.frame) + TOSLabelTopPadding, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 | 524 |
| 531 - (void)OKButtonWasTapped { | 525 - (void)OKButtonWasTapped { |
| 532 [self.delegate welcomeToChromeViewDidTapOKButton:self]; | 526 [self.delegate welcomeToChromeViewDidTapOKButton:self]; |
| 533 } | 527 } |
| 534 | 528 |
| 535 - (void)TOSLinkWasTapped { | 529 - (void)TOSLinkWasTapped { |
| 536 [self.delegate welcomeToChromeViewDidTapTOSLink:self]; | 530 [self.delegate welcomeToChromeViewDidTapTOSLink:self]; |
| 537 } | 531 } |
| 538 | 532 |
| 539 @end | 533 @end |
| OLD | NEW |