Chromium Code Reviews| 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 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #import "ios/chrome/browser/ui/UIView+SizeClassSupport.h" | 10 #import "ios/chrome/browser/ui/UIView+SizeClassSupport.h" |
| 11 #include "ios/chrome/browser/ui/fancy_ui/primary_action_button.h" | 11 #include "ios/chrome/browser/ui/fancy_ui/primary_action_button.h" |
| 12 #include "ios/chrome/browser/ui/first_run/first_run_util.h" | 12 #include "ios/chrome/browser/ui/first_run/first_run_util.h" |
| 13 #include "ios/chrome/browser/ui/ui_util.h" | 13 #include "ios/chrome/browser/ui/ui_util.h" |
| 14 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 14 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 15 #import "ios/chrome/browser/ui/util/CRUILabel+AttributeUtils.h" | 15 #import "ios/chrome/browser/ui/util/CRUILabel+AttributeUtils.h" |
| 16 #import "ios/chrome/browser/ui/util/label_link_controller.h" | 16 #import "ios/chrome/browser/ui/util/label_link_controller.h" |
| 17 #import "ios/chrome/browser/ui/util/label_observer.h" | |
| 17 #include "ios/chrome/common/string_util.h" | 18 #include "ios/chrome/common/string_util.h" |
| 18 #include "ios/chrome/grit/ios_chromium_strings.h" | 19 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 19 #include "ios/chrome/grit/ios_strings.h" | 20 #include "ios/chrome/grit/ios_strings.h" |
| 20 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" | 21 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 23 | 24 |
| 24 #if !defined(__has_feature) || !__has_feature(objc_arc) | 25 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 25 #error "This file requires ARC support." | 26 #error "This file requires ARC support." |
| 26 #endif | 27 #endif |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 // Subview properties are lazily instantiated upon their first use. | 86 // Subview properties are lazily instantiated upon their first use. |
| 86 | 87 |
| 87 // A container view used to layout and center subviews. | 88 // A container view used to layout and center subviews. |
| 88 @property(strong, nonatomic, readonly) UIView* containerView; | 89 @property(strong, nonatomic, readonly) UIView* containerView; |
| 89 // The "Welcome to Chrome" label that appears at the top of the view. | 90 // The "Welcome to Chrome" label that appears at the top of the view. |
| 90 @property(strong, nonatomic, readonly) UILabel* titleLabel; | 91 @property(strong, nonatomic, readonly) UILabel* titleLabel; |
| 91 // The Chrome logo image view. | 92 // The Chrome logo image view. |
| 92 @property(strong, nonatomic, readonly) UIImageView* imageView; | 93 @property(strong, nonatomic, readonly) UIImageView* imageView; |
| 93 // The "Terms of Service" label. | 94 // The "Terms of Service" label. |
| 94 @property(strong, nonatomic, readonly) UILabel* TOSLabel; | 95 @property(strong, nonatomic, readonly) UILabel* TOSLabel; |
| 96 // Observer for setting the size of the TOSLabel; | |
| 97 @property(strong, nonatomic) LabelObserver* TOSObserver; | |
| 95 // The stats reporting opt-in label. | 98 // The stats reporting opt-in label. |
| 96 @property(strong, nonatomic, readonly) UILabel* optInLabel; | 99 @property(strong, nonatomic, readonly) UILabel* optInLabel; |
| 100 // Observer for setting the size of the optInLabel; | |
| 101 @property(strong, nonatomic) LabelObserver* optInObserver; | |
| 97 // The stats reporting opt-in checkbox button. | 102 // The stats reporting opt-in checkbox button. |
| 98 @property(strong, nonatomic, readonly) UIButton* checkBoxButton; | 103 @property(strong, nonatomic, readonly) UIButton* checkBoxButton; |
| 99 // The "Accept & Continue" button. | 104 // The "Accept & Continue" button. |
| 100 @property(strong, nonatomic, readonly) PrimaryActionButton* OKButton; | 105 @property(strong, nonatomic, readonly) PrimaryActionButton* OKButton; |
| 101 | 106 |
| 102 // Subview layout methods. They must be called in the order declared here, as | 107 // Subview layout methods. They must be called in the order declared here, as |
| 103 // subsequent subview layouts depend on the layouts that precede them. | 108 // subsequent subview layouts depend on the layouts that precede them. |
| 104 - (void)layoutTitleLabel; | 109 - (void)layoutTitleLabel; |
| 105 - (void)layoutImageView; | 110 - (void)layoutImageView; |
| 106 - (void)layoutTOSLabel; | 111 - (void)layoutTOSLabel; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 128 | 133 |
| 129 // The TOS label button was tapped. | 134 // The TOS label button was tapped. |
| 130 // TODO(crbug.com/539961): Remove once link detection is fixed. | 135 // TODO(crbug.com/539961): Remove once link detection is fixed. |
| 131 - (void)TOSLinkWasTapped; | 136 - (void)TOSLinkWasTapped; |
| 132 | 137 |
| 133 @end | 138 @end |
| 134 | 139 |
| 135 @implementation WelcomeToChromeView | 140 @implementation WelcomeToChromeView |
| 136 | 141 |
| 137 @synthesize delegate = _delegate; | 142 @synthesize delegate = _delegate; |
| 143 @synthesize TOSObserver = _TOSObserver; | |
| 144 @synthesize optInObserver = _optInObserver; | |
| 138 | 145 |
| 139 - (instancetype)initWithFrame:(CGRect)frame { | 146 - (instancetype)initWithFrame:(CGRect)frame { |
| 140 self = [super initWithFrame:frame]; | 147 self = [super initWithFrame:frame]; |
| 141 if (self) { | 148 if (self) { |
| 142 self.backgroundColor = [UIColor whiteColor]; | 149 self.backgroundColor = [UIColor whiteColor]; |
| 143 self.autoresizingMask = | 150 self.autoresizingMask = |
| 144 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 151 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 145 } | 152 } |
| 146 return self; | 153 return self; |
| 147 } | 154 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 172 [weakSelf imageView].frame = finalLogoFrame; | 179 [weakSelf imageView].frame = finalLogoFrame; |
| 173 [weakSelf titleLabel].alpha = 1.0; | 180 [weakSelf titleLabel].alpha = 1.0; |
| 174 [weakSelf TOSLabel].alpha = 1.0; | 181 [weakSelf TOSLabel].alpha = 1.0; |
| 175 [weakSelf optInLabel].alpha = 1.0; | 182 [weakSelf optInLabel].alpha = 1.0; |
| 176 [weakSelf checkBoxButton].alpha = 1.0; | 183 [weakSelf checkBoxButton].alpha = 1.0; |
| 177 [weakSelf OKButton].alpha = 1.0; | 184 [weakSelf OKButton].alpha = 1.0; |
| 178 } | 185 } |
| 179 completion:nil]; | 186 completion:nil]; |
| 180 } | 187 } |
| 181 | 188 |
| 189 - (void)dealloc { | |
| 190 [self.TOSObserver stopObserving]; | |
| 191 [self.optInObserver stopObserving]; | |
| 192 } | |
| 193 | |
| 182 #pragma mark - Accessors | 194 #pragma mark - Accessors |
| 183 | 195 |
| 184 - (BOOL)isCheckBoxSelected { | 196 - (BOOL)isCheckBoxSelected { |
| 185 return self.checkBoxButton.selected; | 197 return self.checkBoxButton.selected; |
| 186 } | 198 } |
| 187 | 199 |
| 188 - (void)setCheckBoxSelected:(BOOL)checkBoxSelected { | 200 - (void)setCheckBoxSelected:(BOOL)checkBoxSelected { |
| 189 if (checkBoxSelected != self.checkBoxButton.selected) | 201 if (checkBoxSelected != self.checkBoxButton.selected) |
| 190 [self checkBoxButtonWasTapped]; | 202 [self checkBoxButtonWasTapped]; |
| 191 } | 203 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 216 UIImage* image = [UIImage imageNamed:kAppLogoImageName]; | 228 UIImage* image = [UIImage imageNamed:kAppLogoImageName]; |
| 217 _imageView = [[UIImageView alloc] initWithImage:image]; | 229 _imageView = [[UIImageView alloc] initWithImage:image]; |
| 218 [_imageView setBackgroundColor:[UIColor whiteColor]]; | 230 [_imageView setBackgroundColor:[UIColor whiteColor]]; |
| 219 } | 231 } |
| 220 return _imageView; | 232 return _imageView; |
| 221 } | 233 } |
| 222 | 234 |
| 223 - (UILabel*)TOSLabel { | 235 - (UILabel*)TOSLabel { |
| 224 if (!_TOSLabel) { | 236 if (!_TOSLabel) { |
| 225 _TOSLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 237 _TOSLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 238 self.TOSObserver = [LabelObserver observerForLabel:_TOSLabel]; | |
| 239 [self.TOSObserver startObserving]; | |
|
marq (ping after 24h)
2017/04/19 15:25:19
What do these observers do? This CL doesn't add an
gambard
2017/04/19 15:48:18
The actions are added in CRUILabel+AttributeUtils.
marq (ping after 24h)
2017/04/20 11:52:00
Yeah, that's non-obvious and kind of clunky.
| |
| 226 [_TOSLabel setNumberOfLines:0]; | 240 [_TOSLabel setNumberOfLines:0]; |
| 227 [_TOSLabel setTextAlignment:NSTextAlignmentCenter]; | 241 [_TOSLabel setTextAlignment:NSTextAlignmentCenter]; |
| 228 } | 242 } |
| 229 return _TOSLabel; | 243 return _TOSLabel; |
| 230 } | 244 } |
| 231 | 245 |
| 232 - (UILabel*)optInLabel { | 246 - (UILabel*)optInLabel { |
| 233 if (!_optInLabel) { | 247 if (!_optInLabel) { |
| 234 _optInLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 248 _optInLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 249 self.optInObserver = [LabelObserver observerForLabel:_optInLabel]; | |
| 250 [self.optInObserver startObserving]; | |
| 235 [_optInLabel setNumberOfLines:0]; | 251 [_optInLabel setNumberOfLines:0]; |
| 236 [_optInLabel | 252 [_optInLabel |
| 237 setText:l10n_util::GetNSString(IDS_IOS_FIRSTRUN_NEW_OPT_IN_LABEL)]; | 253 setText:l10n_util::GetNSString(IDS_IOS_FIRSTRUN_NEW_OPT_IN_LABEL)]; |
| 238 [_optInLabel setTextAlignment:NSTextAlignmentNatural]; | 254 [_optInLabel setTextAlignment:NSTextAlignmentNatural]; |
| 239 } | 255 } |
| 240 return _optInLabel; | 256 return _optInLabel; |
| 241 } | 257 } |
| 242 | 258 |
| 243 - (UIButton*)checkBoxButton { | 259 - (UIButton*)checkBoxButton { |
| 244 if (!_checkBoxButton) { | 260 if (!_checkBoxButton) { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 | 540 |
| 525 - (void)OKButtonWasTapped { | 541 - (void)OKButtonWasTapped { |
| 526 [self.delegate welcomeToChromeViewDidTapOKButton:self]; | 542 [self.delegate welcomeToChromeViewDidTapOKButton:self]; |
| 527 } | 543 } |
| 528 | 544 |
| 529 - (void)TOSLinkWasTapped { | 545 - (void)TOSLinkWasTapped { |
| 530 [self.delegate welcomeToChromeViewDidTapTOSLink:self]; | 546 [self.delegate welcomeToChromeViewDidTapTOSLink:self]; |
| 531 } | 547 } |
| 532 | 548 |
| 533 @end | 549 @end |
| OLD | NEW |