Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/authentication/signin_promo_view.h" | 5 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "ios/chrome/browser/ui/authentication/signin_promo_view_delegate.h" | 8 #import "ios/chrome/browser/ui/authentication/signin_promo_view_delegate.h" |
| 9 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 9 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 10 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 10 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 11 #include "ios/chrome/grit/ios_chromium_strings.h" | 11 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 12 #include "ios/chrome/grit/ios_strings.h" | |
| 12 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" | 13 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" |
| 13 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" | 14 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 | 16 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 17 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." | 18 #error "This file requires ARC support." |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 // Horizontal padding for label and buttons. | 22 // Horizontal padding for label and buttons. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 35 NSArray<NSLayoutConstraint*>* _warmStateConstraints; | 36 NSArray<NSLayoutConstraint*>* _warmStateConstraints; |
| 36 signin_metrics::AccessPoint _accessPoint; | 37 signin_metrics::AccessPoint _accessPoint; |
| 37 } | 38 } |
| 38 | 39 |
| 39 @synthesize delegate = _delegate; | 40 @synthesize delegate = _delegate; |
| 40 @synthesize mode = _mode; | 41 @synthesize mode = _mode; |
| 41 @synthesize imageView = _imageView; | 42 @synthesize imageView = _imageView; |
| 42 @synthesize textLabel = _textLabel; | 43 @synthesize textLabel = _textLabel; |
| 43 @synthesize primaryButton = _primaryButton; | 44 @synthesize primaryButton = _primaryButton; |
| 44 @synthesize secondaryButton = _secondaryButton; | 45 @synthesize secondaryButton = _secondaryButton; |
| 46 @synthesize closeButton = _closeButton; | |
| 45 | 47 |
| 46 - (instancetype)initWithFrame:(CGRect)frame { | 48 - (instancetype)initWithFrame:(CGRect)frame { |
| 47 self = [super initWithFrame:frame]; | 49 self = [super initWithFrame:frame]; |
| 48 if (self) { | 50 if (self) { |
| 49 self.isAccessibilityElement = YES; | 51 self.isAccessibilityElement = YES; |
| 50 | 52 |
| 51 // Adding subviews. | 53 // Adding subviews. |
| 52 self.clipsToBounds = YES; | 54 self.clipsToBounds = YES; |
| 53 _imageView = [[UIImageView alloc] init]; | 55 _imageView = [[UIImageView alloc] init]; |
| 54 _imageView.translatesAutoresizingMaskIntoConstraints = NO; | 56 _imageView.translatesAutoresizingMaskIntoConstraints = NO; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 68 [self addSubview:_primaryButton]; | 70 [self addSubview:_primaryButton]; |
| 69 | 71 |
| 70 _secondaryButton = [[MDCFlatButton alloc] init]; | 72 _secondaryButton = [[MDCFlatButton alloc] init]; |
| 71 _secondaryButton.translatesAutoresizingMaskIntoConstraints = NO; | 73 _secondaryButton.translatesAutoresizingMaskIntoConstraints = NO; |
| 72 _secondaryButton.accessibilityIdentifier = @"signin_promo_secondary_button"; | 74 _secondaryButton.accessibilityIdentifier = @"signin_promo_secondary_button"; |
| 73 [_secondaryButton addTarget:self | 75 [_secondaryButton addTarget:self |
| 74 action:@selector(onSecondaryButtonAction:) | 76 action:@selector(onSecondaryButtonAction:) |
| 75 forControlEvents:UIControlEventTouchUpInside]; | 77 forControlEvents:UIControlEventTouchUpInside]; |
| 76 [self addSubview:_secondaryButton]; | 78 [self addSubview:_secondaryButton]; |
| 77 | 79 |
| 80 _closeButton = [[UIButton alloc] init]; | |
| 81 _closeButton.translatesAutoresizingMaskIntoConstraints = NO; | |
| 82 _closeButton.accessibilityIdentifier = @"signin_promo_close_button"; | |
| 83 [self addSubview:_closeButton]; | |
| 84 | |
| 78 // Adding style. | 85 // Adding style. |
| 79 _imageView.contentMode = UIViewContentModeCenter; | 86 _imageView.contentMode = UIViewContentModeCenter; |
| 80 _imageView.layer.masksToBounds = YES; | 87 _imageView.layer.masksToBounds = YES; |
| 81 _imageView.contentMode = UIViewContentModeScaleAspectFit; | 88 _imageView.contentMode = UIViewContentModeScaleAspectFit; |
| 82 | 89 |
| 83 _textLabel.font = [MDCTypography buttonFont]; | 90 _textLabel.font = [MDCTypography buttonFont]; |
| 84 _textLabel.textColor = [[MDCPalette greyPalette] tint900]; | 91 _textLabel.textColor = [[MDCPalette greyPalette] tint900]; |
| 85 _textLabel.numberOfLines = 0; | 92 _textLabel.numberOfLines = 0; |
| 86 _textLabel.textAlignment = NSTextAlignmentCenter; | 93 _textLabel.textAlignment = NSTextAlignmentCenter; |
| 87 | 94 |
| 88 [_primaryButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] | 95 [_primaryButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] |
| 89 forState:UIControlStateNormal]; | 96 forState:UIControlStateNormal]; |
| 90 _primaryButton.customTitleColor = [UIColor whiteColor]; | 97 _primaryButton.customTitleColor = [UIColor whiteColor]; |
| 91 _primaryButton.inkColor = [UIColor colorWithWhite:1 alpha:0.2]; | 98 _primaryButton.inkColor = [UIColor colorWithWhite:1 alpha:0.2]; |
| 92 | 99 |
| 93 _secondaryButton.customTitleColor = [[MDCPalette cr_bluePalette] tint500]; | 100 _secondaryButton.customTitleColor = [[MDCPalette cr_bluePalette] tint500]; |
| 94 _secondaryButton.uppercaseTitle = NO; | 101 _secondaryButton.uppercaseTitle = NO; |
| 95 | 102 |
| 103 [_closeButton setImage:[UIImage imageNamed:@"signin_promo_close_gray"] | |
| 104 forState:UIControlStateNormal]; | |
| 105 // _closeButton.hidden = YES; | |
|
lpromero
2017/05/23 12:06:16
Still needed? Otherwise remove.
jlebel
2017/05/23 12:43:26
Done.
| |
| 106 | |
| 96 // Adding constraints. | 107 // Adding constraints. |
| 97 NSDictionary* metrics = @{ | 108 NSDictionary* metrics = @{ |
| 98 @"kButtonHeight" : @(kButtonHeight), | 109 @"kButtonHeight" : @(kButtonHeight), |
| 99 @"kButtonVerticalPadding" : @(kButtonVerticalPadding), | 110 @"kButtonVerticalPadding" : @(kButtonVerticalPadding), |
| 100 @"kButtonVerticalPaddingx2" : @(kButtonVerticalPadding * 2), | 111 @"kButtonVerticalPaddingx2" : @(kButtonVerticalPadding * 2), |
| 101 @"kHorizontalPadding" : @(kHorizontalPadding), | 112 @"kHorizontalPadding" : @(kHorizontalPadding), |
| 102 @"kVerticalPadding" : @(kVerticalPadding), | 113 @"kVerticalPadding" : @(kVerticalPadding), |
| 103 @"kVerticalPaddingx2" : @(kVerticalPadding * 2), | 114 @"kVerticalPaddingx2" : @(kVerticalPadding * 2), |
| 104 @"kVerticalPaddingkButtonVerticalPadding" : | 115 @"kVerticalPaddingkButtonVerticalPadding" : |
| 105 @(kVerticalPadding + kButtonVerticalPadding), | 116 @(kVerticalPadding + kButtonVerticalPadding), |
| 106 }; | 117 }; |
| 107 NSDictionary* views = @{ | 118 NSDictionary* views = @{ |
| 108 @"imageView" : _imageView, | 119 @"imageView" : _imageView, |
| 109 @"primaryButton" : _primaryButton, | 120 @"primaryButton" : _primaryButton, |
| 110 @"secondaryButton" : _secondaryButton, | 121 @"secondaryButton" : _secondaryButton, |
| 111 @"textLabel" : _textLabel, | 122 @"textLabel" : _textLabel, |
| 112 }; | 123 }; |
| 113 | 124 |
| 114 // Constraints shared between modes. | 125 // Constraints shared between modes. |
| 115 NSString* sharedVerticalConstraints = | 126 NSString* sharedVerticalConstraints = |
| 116 @"V:|-kVerticalPaddingx2-[imageView]-kVerticalPadding-[textLabel]-" | 127 @"V:|-kVerticalPaddingx2-[imageView]-kVerticalPadding-[textLabel]-" |
| 117 @"kVerticalPaddingkButtonVerticalPadding-[primaryButton(kButtonHeight)" | 128 @"kVerticalPaddingkButtonVerticalPadding-[primaryButton(kButtonHeight)" |
| 118 @"]"; | 129 @"]"; |
| 119 NSArray* visualConstraints = @[ | 130 NSArray* visualConstraints = @[ |
| 120 sharedVerticalConstraints, | 131 sharedVerticalConstraints, |
| 121 @"H:|-kHorizontalPadding-[primaryButton]-kHorizontalPadding-|" | 132 @"H:|-kHorizontalPadding-[primaryButton]-kHorizontalPadding-|" |
| 122 ]; | 133 ]; |
| 123 ApplyVisualConstraintsWithMetricsAndOptions( | 134 ApplyVisualConstraintsWithMetricsAndOptions( |
| 124 visualConstraints, views, metrics, NSLayoutFormatAlignAllCenterX); | 135 visualConstraints, views, metrics, NSLayoutFormatAlignAllCenterX); |
| 136 NSArray* buttonVisualConstraints = | |
| 137 @[ @"H:[closeButton]-|", @"V:|-[closeButton]" ]; | |
| 138 ApplyVisualConstraints(buttonVisualConstraints, | |
| 139 @{ @"closeButton" : _closeButton }); | |
| 125 | 140 |
| 126 // Constraints for cold state mode. | 141 // Constraints for cold state mode. |
| 127 NSArray* coldStateVisualConstraints = @[ | 142 NSArray* coldStateVisualConstraints = @[ |
| 128 @"V:[primaryButton]-kVerticalPaddingkButtonVerticalPadding-|", | 143 @"V:[primaryButton]-kVerticalPaddingkButtonVerticalPadding-|", |
| 129 ]; | 144 ]; |
| 130 _coldStateConstraints = VisualConstraintsWithMetrics( | 145 _coldStateConstraints = VisualConstraintsWithMetrics( |
| 131 coldStateVisualConstraints, views, metrics); | 146 coldStateVisualConstraints, views, metrics); |
| 132 | 147 |
| 133 // Constraints for warm state mode. | 148 // Constraints for warm state mode. |
| 134 NSString* warmStateVerticalConstraints = | 149 NSString* warmStateVerticalConstraints = |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 } | 209 } |
| 195 | 210 |
| 196 - (void)accessibilityPrimaryAction:(id)unused { | 211 - (void)accessibilityPrimaryAction:(id)unused { |
| 197 [_primaryButton sendActionsForControlEvents:UIControlEventTouchUpInside]; | 212 [_primaryButton sendActionsForControlEvents:UIControlEventTouchUpInside]; |
| 198 } | 213 } |
| 199 | 214 |
| 200 - (void)accessibilitySecondaryAction:(id)unused { | 215 - (void)accessibilitySecondaryAction:(id)unused { |
| 201 [_secondaryButton sendActionsForControlEvents:UIControlEventTouchUpInside]; | 216 [_secondaryButton sendActionsForControlEvents:UIControlEventTouchUpInside]; |
| 202 } | 217 } |
| 203 | 218 |
| 219 - (void)accessibilityCloseAction:(id)unused { | |
| 220 [_closeButton sendActionsForControlEvents:UIControlEventTouchUpInside]; | |
| 221 } | |
| 222 | |
| 204 - (CGFloat)horizontalPadding { | 223 - (CGFloat)horizontalPadding { |
| 205 return kHorizontalPadding; | 224 return kHorizontalPadding; |
| 206 } | 225 } |
| 207 | 226 |
| 208 - (void)onPrimaryButtonAction:(id)unused { | 227 - (void)onPrimaryButtonAction:(id)unused { |
| 209 switch (_mode) { | 228 switch (_mode) { |
| 210 case SigninPromoViewModeColdState: | 229 case SigninPromoViewModeColdState: |
| 211 [_delegate signinPromoViewDidTapSigninWithNewAccount:self]; | 230 [_delegate signinPromoViewDidTapSigninWithNewAccount:self]; |
| 212 break; | 231 break; |
| 213 case SigninPromoViewModeWarmState: | 232 case SigninPromoViewModeWarmState: |
| 214 [_delegate signinPromoViewDidTapSigninWithDefaultAccount:self]; | 233 [_delegate signinPromoViewDidTapSigninWithDefaultAccount:self]; |
| 215 break; | 234 break; |
| 216 } | 235 } |
| 217 } | 236 } |
| 218 | 237 |
| 219 - (void)onSecondaryButtonAction:(id)unused { | 238 - (void)onSecondaryButtonAction:(id)unused { |
| 220 [_delegate signinPromoViewDidTapSigninWithOtherAccount:self]; | 239 [_delegate signinPromoViewDidTapSigninWithOtherAccount:self]; |
| 221 } | 240 } |
| 222 | 241 |
| 223 #pragma mark - NSObject(Accessibility) | 242 #pragma mark - NSObject(Accessibility) |
| 224 | 243 |
| 225 - (NSArray<UIAccessibilityCustomAction*>*)accessibilityCustomActions { | 244 - (NSArray<UIAccessibilityCustomAction*>*)accessibilityCustomActions { |
| 245 NSMutableArray* actions = [NSMutableArray array]; | |
| 246 | |
| 226 NSString* primaryActionName = | 247 NSString* primaryActionName = |
| 227 [_primaryButton titleForState:UIControlStateNormal]; | 248 [_primaryButton titleForState:UIControlStateNormal]; |
| 228 UIAccessibilityCustomAction* primaryCustomAction = | 249 UIAccessibilityCustomAction* primaryCustomAction = |
| 229 [[UIAccessibilityCustomAction alloc] | 250 [[UIAccessibilityCustomAction alloc] |
| 230 initWithName:primaryActionName | 251 initWithName:primaryActionName |
| 231 target:self | 252 target:self |
| 232 selector:@selector(accessibilityPrimaryAction:)]; | 253 selector:@selector(accessibilityPrimaryAction:)]; |
| 233 if (_mode == SigninPromoViewModeColdState) { | 254 [actions addObject:primaryCustomAction]; |
| 234 return @[ primaryCustomAction ]; | 255 |
| 256 if (_mode == SigninPromoViewModeWarmState) { | |
| 257 NSString* secondaryActionName = | |
| 258 [_secondaryButton titleForState:UIControlStateNormal]; | |
| 259 UIAccessibilityCustomAction* secondaryCustomAction = | |
| 260 [[UIAccessibilityCustomAction alloc] | |
| 261 initWithName:secondaryActionName | |
| 262 target:self | |
| 263 selector:@selector(accessibilitySecondaryAction:)]; | |
| 264 [actions addObject:secondaryCustomAction]; | |
| 235 } | 265 } |
| 236 NSString* secondaryActionName = | 266 |
| 237 [_secondaryButton titleForState:UIControlStateNormal]; | 267 NSString* closeActionName = |
| 238 UIAccessibilityCustomAction* secondaryCustomAction = | 268 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_CLOSE_ACCESSIBILITY); |
| 269 UIAccessibilityCustomAction* closeCustomAction = | |
| 239 [[UIAccessibilityCustomAction alloc] | 270 [[UIAccessibilityCustomAction alloc] |
| 240 initWithName:secondaryActionName | 271 initWithName:closeActionName |
| 241 target:self | 272 target:self |
| 242 selector:@selector(accessibilitySecondaryAction:)]; | 273 selector:@selector(accessibilityCloseAction:)]; |
| 243 return @[ primaryCustomAction, secondaryCustomAction ]; | 274 [actions addObject:closeCustomAction]; |
| 275 | |
| 276 return actions; | |
| 244 } | 277 } |
| 245 | 278 |
| 246 - (NSString*)accessibilityLabel { | 279 - (NSString*)accessibilityLabel { |
| 247 return _textLabel.text; | 280 return _textLabel.text; |
| 248 } | 281 } |
| 249 | 282 |
| 250 @end | 283 @end |
| OLD | NEW |