| 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/bookmarks/bookmark_signin_promo_cell.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_signin_promo_cell.h" |
| 6 | 6 |
| 7 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h" | 7 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h" |
| 8 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 8 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 9 #include "ios/chrome/grit/ios_chromium_strings.h" | 9 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| 11 | 11 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | 12 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." | 13 #error "This file requires ARC support." |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 namespace { | |
| 17 // Close button size. | |
| 18 const CGFloat kCloseButtonSize = 24; | |
| 19 } | |
| 20 | |
| 21 @implementation BookmarkSigninPromoCell { | 16 @implementation BookmarkSigninPromoCell { |
| 22 SigninPromoView* _signinPromoView; | 17 SigninPromoView* _signinPromoView; |
| 23 UIButton* _closeButton; | 18 UIButton* _closeButton; |
| 24 } | 19 } |
| 25 | 20 |
| 26 @synthesize signinPromoView = _signinPromoView; | 21 @synthesize signinPromoView = _signinPromoView; |
| 27 @synthesize closeButtonAction = _closeButtonAction; | 22 @synthesize closeButtonAction = _closeButtonAction; |
| 28 | 23 |
| 29 + (NSString*)reuseIdentifier { | 24 + (NSString*)reuseIdentifier { |
| 30 return @"BookmarkSigninPromoCell"; | 25 return @"BookmarkSigninPromoCell"; |
| 31 } | 26 } |
| 32 | 27 |
| 33 + (BOOL)requiresConstraintBasedLayout { | 28 + (BOOL)requiresConstraintBasedLayout { |
| 34 return YES; | 29 return YES; |
| 35 } | 30 } |
| 36 | 31 |
| 37 - (instancetype)initWithFrame:(CGRect)frame { | 32 - (instancetype)initWithFrame:(CGRect)frame { |
| 38 self = [super initWithFrame:frame]; | 33 self = [super initWithFrame:frame]; |
| 39 if (self) { | 34 if (self) { |
| 40 UIView* contentView = self.contentView; | 35 UIView* contentView = self.contentView; |
| 41 _signinPromoView = [[SigninPromoView alloc] initWithFrame:self.bounds]; | 36 _signinPromoView = [[SigninPromoView alloc] initWithFrame:self.bounds]; |
| 42 _signinPromoView.translatesAutoresizingMaskIntoConstraints = NO; | 37 _signinPromoView.translatesAutoresizingMaskIntoConstraints = NO; |
| 43 [contentView addSubview:_signinPromoView]; | 38 [contentView addSubview:_signinPromoView]; |
| 44 AddSameConstraints(_signinPromoView, contentView); | 39 AddSameConstraints(_signinPromoView, contentView); |
| 45 | 40 |
| 46 _closeButton = [[UIButton alloc] | 41 _signinPromoView.closeButton.hidden = NO; |
| 47 initWithFrame:CGRectMake(0, 0, kCloseButtonSize, kCloseButtonSize)]; | 42 [_signinPromoView.closeButton addTarget:self |
| 48 [_closeButton addTarget:self | 43 action:@selector(closeButtonAction:) |
| 49 action:@selector(closeButtonAction:) | 44 forControlEvents:UIControlEventTouchUpInside]; |
| 50 forControlEvents:UIControlEventTouchUpInside]; | |
| 51 _closeButton.translatesAutoresizingMaskIntoConstraints = NO; | |
| 52 [contentView addSubview:_closeButton]; | |
| 53 [_closeButton setImage:[UIImage imageNamed:@"signin_promo_close_gray"] | |
| 54 forState:UIControlStateNormal]; | |
| 55 NSArray* buttonVisualConstraints = | |
| 56 @[ @"H:[closeButton]-|", @"V:|-[closeButton]" ]; | |
| 57 NSDictionary* views = @{ @"closeButton" : _closeButton }; | |
| 58 ApplyVisualConstraints(buttonVisualConstraints, views); | |
| 59 | 45 |
| 60 _signinPromoView.backgroundColor = [UIColor whiteColor]; | 46 _signinPromoView.backgroundColor = [UIColor whiteColor]; |
| 61 _signinPromoView.textLabel.text = | 47 _signinPromoView.textLabel.text = |
| 62 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_BOOKMARKS); | 48 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_BOOKMARKS); |
| 63 } | 49 } |
| 64 return self; | 50 return self; |
| 65 } | 51 } |
| 66 | 52 |
| 67 - (void)layoutSubviews { | 53 - (void)layoutSubviews { |
| 68 // Adjust the text label preferredMaxLayoutWidth according self.frame.width, | 54 // Adjust the text label preferredMaxLayoutWidth according self.frame.width, |
| 69 // so the text will adjust its height and not its width. | 55 // so the text will adjust its height and not its width. |
| 70 CGFloat parentWidth = CGRectGetWidth(self.bounds); | 56 CGFloat parentWidth = CGRectGetWidth(self.bounds); |
| 71 _signinPromoView.textLabel.preferredMaxLayoutWidth = | 57 _signinPromoView.textLabel.preferredMaxLayoutWidth = |
| 72 parentWidth - 2 * _signinPromoView.horizontalPadding; | 58 parentWidth - 2 * _signinPromoView.horizontalPadding; |
| 73 | 59 |
| 74 // Re-layout with the new preferred width to allow the label to adjust its | 60 // Re-layout with the new preferred width to allow the label to adjust its |
| 75 // height. | 61 // height. |
| 76 [super layoutSubviews]; | 62 [super layoutSubviews]; |
| 77 } | 63 } |
| 78 | 64 |
| 79 - (void)prepareForReuse { | 65 - (void)prepareForReuse { |
| 80 _closeButtonAction = nil; | 66 _closeButtonAction = nil; |
| 81 _signinPromoView.delegate = nil; | 67 _signinPromoView.delegate = nil; |
| 82 } | 68 } |
| 83 | 69 |
| 84 - (void)closeButtonAction:(id)sender { | 70 - (void)closeButtonAction:(id)sender { |
| 85 if (_closeButtonAction) { | 71 DCHECK(_closeButtonAction); |
| 86 _closeButtonAction(); | 72 _closeButtonAction(); |
| 87 } | |
| 88 } | 73 } |
| 89 | 74 |
| 90 @end | 75 @end |
| OLD | NEW |