| 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/today_extension/physical_web_optin_footer.h" | 5 #import "ios/chrome/today_extension/physical_web_optin_footer.h" |
| 6 | 6 |
| 7 #import "base/mac/scoped_block.h" | 7 #import "base/mac/scoped_block.h" |
| 8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #include "ios/chrome/today_extension/interactive_label.h" | 9 #include "ios/chrome/today_extension/interactive_label.h" |
| 10 #include "ios/chrome/today_extension/lock_screen_state.h" | 10 #include "ios/chrome/today_extension/lock_screen_state.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 base::scoped_nsobject<TransparentButton> _dismissButton; | 52 base::scoped_nsobject<TransparentButton> _dismissButton; |
| 53 // Physical Web logo. | 53 // Physical Web logo. |
| 54 base::scoped_nsobject<UIImageView> _imageView; | 54 base::scoped_nsobject<UIImageView> _imageView; |
| 55 // Outer horizontal padding. | 55 // Outer horizontal padding. |
| 56 CGFloat _horizontalPadding; | 56 CGFloat _horizontalPadding; |
| 57 // Physical Web logo size. | 57 // Physical Web logo size. |
| 58 CGSize _imageSize; | 58 CGSize _imageSize; |
| 59 // Distance between the icon and the title. | 59 // Distance between the icon and the title. |
| 60 CGFloat _imageTextSeparator; | 60 CGFloat _imageTextSeparator; |
| 61 // Opt-in action block. | 61 // Opt-in action block. |
| 62 base::mac::ScopedBlock<EnableDisableBlock> _optinAction; | 62 EnableDisableBlock _optinAction; |
| 63 // Dismiss action block. | 63 // Dismiss action block. |
| 64 base::mac::ScopedBlock<EnableDisableBlock> _dismissAction; | 64 EnableDisableBlock _dismissAction; |
| 65 // Whether the screen is locked. | 65 // Whether the screen is locked. |
| 66 BOOL _locked; | 66 BOOL _locked; |
| 67 } | 67 } |
| 68 | 68 |
| 69 - (id)initWithLeftInset:(CGFloat)leftInset | 69 - (id)initWithLeftInset:(CGFloat)leftInset |
| 70 learnMoreBlock:(LearnMoreBlock)learnMoreBlock | 70 learnMoreBlock:(LearnMoreBlock)learnMoreBlock |
| 71 optinAction:(EnableDisableBlock)optinAction | 71 optinAction:(EnableDisableBlock)optinAction |
| 72 dismissAction:(EnableDisableBlock)dismissAction { | 72 dismissAction:(EnableDisableBlock)dismissAction { |
| 73 self = [super init]; | 73 self = [super init]; |
| 74 if (self) { | 74 if (self) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 initWithFrame:CGRectZero | 109 initWithFrame:CGRectZero |
| 110 labelString:description | 110 labelString:description |
| 111 fontSize:kDescriptionFontSize | 111 fontSize:kDescriptionFontSize |
| 112 labelAlignment:ui_util::IsRTL() ? NSTextAlignmentRight | 112 labelAlignment:ui_util::IsRTL() ? NSTextAlignmentRight |
| 113 : NSTextAlignmentLeft | 113 : NSTextAlignmentLeft |
| 114 insets:UIEdgeInsetsZero | 114 insets:UIEdgeInsetsZero |
| 115 buttonString:nil | 115 buttonString:nil |
| 116 linkBlock:learnMoreBlock | 116 linkBlock:learnMoreBlock |
| 117 buttonBlock:NULL]); | 117 buttonBlock:NULL]); |
| 118 [_descriptionLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; | 118 [_descriptionLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 119 UIStackView* textStack = [[[UIStackView alloc] | 119 UIStackView* textStack = [[UIStackView alloc] |
| 120 initWithArrangedSubviews:@[ _titleView, _descriptionLabel ]] | 120 initWithArrangedSubviews:@[ _titleView, _descriptionLabel ]]; |
| 121 autorelease]; | |
| 122 | 121 |
| 123 [textStack setAxis:UILayoutConstraintAxisVertical]; | 122 [textStack setAxis:UILayoutConstraintAxisVertical]; |
| 124 [textStack setDistribution:UIStackViewDistributionEqualSpacing]; | 123 [textStack setDistribution:UIStackViewDistributionEqualSpacing]; |
| 125 [textStack setSpacing:kTitleVerticalMargin]; | 124 [textStack setSpacing:kTitleVerticalMargin]; |
| 126 [textStack setTranslatesAutoresizingMaskIntoConstraints:NO]; | 125 [textStack setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 127 | 126 |
| 128 [_mainView addSubview:textStack]; | 127 [_mainView addSubview:textStack]; |
| 129 [_mainView addSubview:_imageView]; | 128 [_mainView addSubview:_imageView]; |
| 130 | 129 |
| 131 _horizontalPadding = leftInset + ui_util::ChromeIconOffset(); | 130 _horizontalPadding = leftInset + ui_util::ChromeIconOffset(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 forState:UIControlStateNormal]; | 176 forState:UIControlStateNormal]; |
| 178 [_dismissButton | 177 [_dismissButton |
| 179 setTitle:l10n_util::GetNSString( | 178 setTitle:l10n_util::GetNSString( |
| 180 IDS_IOS_PYSICAL_WEB_TODAY_EXTENSION_OPTIN_DISMISS) | 179 IDS_IOS_PYSICAL_WEB_TODAY_EXTENSION_OPTIN_DISMISS) |
| 181 forState:UIControlStateNormal]; | 180 forState:UIControlStateNormal]; |
| 182 [_dismissButton setBorderWidth:1.0]; | 181 [_dismissButton setBorderWidth:1.0]; |
| 183 [_dismissButton setBorderColor:ui_util::TitleColor()]; | 182 [_dismissButton setBorderColor:ui_util::TitleColor()]; |
| 184 [_dismissButton addTarget:self | 183 [_dismissButton addTarget:self |
| 185 action:@selector(dismissButtonPressed:) | 184 action:@selector(dismissButtonPressed:) |
| 186 forControlEvents:UIControlEventTouchUpInside]; | 185 forControlEvents:UIControlEventTouchUpInside]; |
| 187 _dismissAction.reset(dismissAction, base::scoped_policy::RETAIN); | 186 _dismissAction = [dismissAction copy]; |
| 188 [_dismissButton setTranslatesAutoresizingMaskIntoConstraints:NO]; | 187 [_dismissButton setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 189 | 188 |
| 190 _optInButton.reset([[TransparentButton alloc] initWithFrame:CGRectZero]); | 189 _optInButton.reset([[TransparentButton alloc] initWithFrame:CGRectZero]); |
| 191 [_optInButton setCornerRadius:ui_util::kUIButtonCornerRadius]; | 190 [_optInButton setCornerRadius:ui_util::kUIButtonCornerRadius]; |
| 192 [[_optInButton titleLabel] setFont:buttonFont]; | 191 [[_optInButton titleLabel] setFont:buttonFont]; |
| 193 [_optInButton setInkColor:ui_util::InkColor()]; | 192 [_optInButton setInkColor:ui_util::InkColor()]; |
| 194 [_optInButton setBackgroundColor:ui_util::BackgroundColor()]; | 193 [_optInButton setBackgroundColor:ui_util::BackgroundColor()]; |
| 195 [_optInButton setTitleColor:[UIColor blackColor] | 194 [_optInButton setTitleColor:[UIColor blackColor] |
| 196 forState:UIControlStateNormal]; | 195 forState:UIControlStateNormal]; |
| 197 [_optInButton setTitle:l10n_util::GetNSString( | 196 [_optInButton setTitle:l10n_util::GetNSString( |
| 198 IDS_IOS_PYSICAL_WEB_TODAY_EXTENSION_OPTIN_ACCEPT) | 197 IDS_IOS_PYSICAL_WEB_TODAY_EXTENSION_OPTIN_ACCEPT) |
| 199 forState:UIControlStateNormal]; | 198 forState:UIControlStateNormal]; |
| 200 [_optInButton addTarget:self | 199 [_optInButton addTarget:self |
| 201 action:@selector(optInButtonPressed:) | 200 action:@selector(optInButtonPressed:) |
| 202 forControlEvents:UIControlEventTouchUpInside]; | 201 forControlEvents:UIControlEventTouchUpInside]; |
| 203 [_optInButton setTranslatesAutoresizingMaskIntoConstraints:NO]; | 202 [_optInButton setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 204 | 203 |
| 205 [[_optInButton heightAnchor] constraintEqualToConstant:kButtonHeight]; | 204 [[_optInButton heightAnchor] constraintEqualToConstant:kButtonHeight]; |
| 206 [[_dismissButton heightAnchor] constraintEqualToConstant:kButtonHeight]; | 205 [[_dismissButton heightAnchor] constraintEqualToConstant:kButtonHeight]; |
| 207 [[_optInButton widthAnchor] | 206 [[_optInButton widthAnchor] |
| 208 constraintEqualToAnchor:[_dismissButton widthAnchor]]; | 207 constraintEqualToAnchor:[_dismissButton widthAnchor]]; |
| 209 | 208 |
| 210 _optinAction.reset(optinAction, base::scoped_policy::RETAIN); | 209 _optinAction = [optinAction copy]; |
| 211 UIStackView* buttonStack = [[UIStackView alloc] | 210 UIStackView* buttonStack = [[UIStackView alloc] |
| 212 initWithArrangedSubviews:@[ _dismissButton, _optInButton ]]; | 211 initWithArrangedSubviews:@[ _dismissButton, _optInButton ]]; |
| 213 [buttonStack setUserInteractionEnabled:YES]; | 212 [buttonStack setUserInteractionEnabled:YES]; |
| 214 [buttonStack setAxis:UILayoutConstraintAxisHorizontal]; | 213 [buttonStack setAxis:UILayoutConstraintAxisHorizontal]; |
| 215 [buttonStack setSpacing:kButtonSpacing]; | 214 [buttonStack setSpacing:kButtonSpacing]; |
| 216 [buttonStack setTranslatesAutoresizingMaskIntoConstraints:NO]; | 215 [buttonStack setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 217 | 216 |
| 218 [[_optInButton heightAnchor] constraintEqualToConstant:kButtonHeight].active = | 217 [[_optInButton heightAnchor] constraintEqualToConstant:kButtonHeight].active = |
| 219 YES; | 218 YES; |
| 220 [[_dismissButton heightAnchor] constraintEqualToConstant:kButtonHeight] | 219 [[_dismissButton heightAnchor] constraintEqualToConstant:kButtonHeight] |
| 221 .active = YES; | 220 .active = YES; |
| 222 | 221 |
| 223 [_optInButton setContentEdgeInsets:UIEdgeInsetsMake(0, kButtonPadding, 0, | 222 [_optInButton setContentEdgeInsets:UIEdgeInsetsMake(0, kButtonPadding, 0, |
| 224 kButtonPadding)]; | 223 kButtonPadding)]; |
| 225 [_dismissButton setContentEdgeInsets:UIEdgeInsetsMake(0, kButtonPadding, 0, | 224 [_dismissButton setContentEdgeInsets:UIEdgeInsetsMake(0, kButtonPadding, 0, |
| 226 kButtonPadding)]; | 225 kButtonPadding)]; |
| 227 | 226 |
| 228 [[_optInButton widthAnchor] | 227 [[_optInButton widthAnchor] |
| 229 constraintEqualToAnchor:[_dismissButton widthAnchor]] | 228 constraintEqualToAnchor:[_dismissButton widthAnchor]] |
| 230 .active = YES; | 229 .active = YES; |
| 231 return [buttonStack autorelease]; | 230 return buttonStack; |
| 232 } | 231 } |
| 233 | 232 |
| 234 - (CGFloat)heightForWidth:(CGFloat)width { | 233 - (CGFloat)heightForWidth:(CGFloat)width { |
| 235 CGFloat height = ui_util::kSecondLineVerticalPadding + | 234 CGFloat height = ui_util::kSecondLineVerticalPadding + |
| 236 [_titleView frame].size.height + kTitleVerticalMargin + | 235 [_titleView frame].size.height + kTitleVerticalMargin + |
| 237 [_descriptionLabel | 236 [_descriptionLabel |
| 238 sizeThatFits:CGSizeMake(width - (_horizontalPadding * 2 + | 237 sizeThatFits:CGSizeMake(width - (_horizontalPadding * 2 + |
| 239 _imageTextSeparator), | 238 _imageTextSeparator), |
| 240 CGFLOAT_MAX)] | 239 CGFLOAT_MAX)] |
| 241 .height + | 240 .height + |
| 242 ui_util::kSecondLineVerticalPadding; | 241 ui_util::kSecondLineVerticalPadding; |
| 243 | 242 |
| 244 if (!_locked) { | 243 if (!_locked) { |
| 245 height += kButtonVerticalMargin + kButtonHeight; | 244 height += kButtonVerticalMargin + kButtonHeight; |
| 246 } | 245 } |
| 247 return height; | 246 return height; |
| 248 } | 247 } |
| 249 | 248 |
| 250 - (UIView*)view { | 249 - (UIView*)view { |
| 251 return _mainView; | 250 return _mainView; |
| 252 } | 251 } |
| 253 | 252 |
| 254 - (void)optInButtonPressed:(id)sender { | 253 - (void)optInButtonPressed:(id)sender { |
| 255 _optinAction.get()(); | 254 if (_optinAction) |
| 255 _optinAction(); |
| 256 } | 256 } |
| 257 | 257 |
| 258 - (void)dismissButtonPressed:(id)sender { | 258 - (void)dismissButtonPressed:(id)sender { |
| 259 _dismissAction.get()(); | 259 if (_dismissAction) |
| 260 _dismissAction(); |
| 260 } | 261 } |
| 261 | 262 |
| 262 @end | 263 @end |
| OLD | NEW |