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/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 addTarget:self |
|
msarda
2017/05/24 08:47:58
I think we should also make the close button visib
jlebel
2017/05/24 11:20:17
Done.
| |
| 47 initWithFrame:CGRectMake(0, 0, kCloseButtonSize, kCloseButtonSize)]; | 42 action:@selector(closeButtonAction:) |
| 48 [_closeButton addTarget:self | 43 forControlEvents:UIControlEventTouchUpInside]; |
| 49 action:@selector(closeButtonAction:) | |
| 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 | 44 |
| 60 _signinPromoView.backgroundColor = [UIColor whiteColor]; | 45 _signinPromoView.backgroundColor = [UIColor whiteColor]; |
| 61 _signinPromoView.textLabel.text = | 46 _signinPromoView.textLabel.text = |
| 62 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_BOOKMARKS); | 47 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_BOOKMARKS); |
| 63 } | 48 } |
| 64 return self; | 49 return self; |
| 65 } | 50 } |
| 66 | 51 |
| 67 - (void)layoutSubviews { | 52 - (void)layoutSubviews { |
| 68 // Adjust the text label preferredMaxLayoutWidth according self.frame.width, | 53 // Adjust the text label preferredMaxLayoutWidth according self.frame.width, |
| 69 // so the text will adjust its height and not its width. | 54 // so the text will adjust its height and not its width. |
| 70 CGFloat parentWidth = CGRectGetWidth(self.bounds); | 55 CGFloat parentWidth = CGRectGetWidth(self.bounds); |
| 71 _signinPromoView.textLabel.preferredMaxLayoutWidth = | 56 _signinPromoView.textLabel.preferredMaxLayoutWidth = |
| 72 parentWidth - 2 * _signinPromoView.horizontalPadding; | 57 parentWidth - 2 * _signinPromoView.horizontalPadding; |
| 73 | 58 |
| 74 // Re-layout with the new preferred width to allow the label to adjust its | 59 // Re-layout with the new preferred width to allow the label to adjust its |
| 75 // height. | 60 // height. |
| 76 [super layoutSubviews]; | 61 [super layoutSubviews]; |
| 77 } | 62 } |
| 78 | 63 |
| 79 - (void)prepareForReuse { | 64 - (void)prepareForReuse { |
|
msarda
2017/05/24 08:47:58
Just call [self setCloseButtonAction:nil] here.
jlebel
2017/05/24 11:20:17
I guess there is no point for that, |_closeButtonA
| |
| 80 _closeButtonAction = nil; | 65 _closeButtonAction = nil; |
| 66 _signinPromoView.closeButton.hidden = NO; | |
|
msarda
2017/05/24 08:47:58
This should probably be YES (in the header it says
jlebel
2017/05/24 11:20:17
Done.
| |
| 81 _signinPromoView.delegate = nil; | 67 _signinPromoView.delegate = nil; |
| 82 } | 68 } |
| 83 | 69 |
| 70 - (void)setCloseButtonAction:(CloseButtonCallback)closeButtonAction { | |
| 71 _closeButtonAction = [closeButtonAction copy]; | |
| 72 _signinPromoView.closeButton.hidden = _closeButtonAction == nil; | |
|
msarda
2017/05/24 08:47:58
I would remove this setter and _signinPromoView.c
jlebel
2017/05/24 11:20:17
Done.
| |
| 73 } | |
| 74 | |
| 84 - (void)closeButtonAction:(id)sender { | 75 - (void)closeButtonAction:(id)sender { |
| 85 if (_closeButtonAction) { | 76 if (_closeButtonAction) { |
| 86 _closeButtonAction(); | 77 _closeButtonAction(); |
| 87 } | 78 } |
| 88 } | 79 } |
| 89 | 80 |
| 90 @end | 81 @end |
| OLD | NEW |