| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_promo_cell.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "base/mac/objc_property_releaser.h" | 10 |
| 11 #import "base/mac/scoped_nsobject.h" | |
| 12 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 11 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 13 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 12 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 14 #import "ios/chrome/browser/ui/rtl_geometry.h" | 13 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 15 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 14 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 16 #include "ios/chrome/grit/ios_chromium_strings.h" | 15 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 17 #include "ios/chrome/grit/ios_strings.h" | 16 #include "ios/chrome/grit/ios_strings.h" |
| 18 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | 17 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" |
| 19 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 18 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| 20 #import "ui/base/l10n/l10n_util_mac.h" | 19 #import "ui/base/l10n/l10n_util_mac.h" |
| 21 | 20 |
| 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 22 #error "This file requires ARC support." |
| 23 #endif |
| 24 |
| 22 namespace { | 25 namespace { |
| 23 | 26 |
| 24 const CGFloat kPadding = 16; | 27 const CGFloat kPadding = 16; |
| 25 const CGFloat kButtonHeight = 36; | 28 const CGFloat kButtonHeight = 36; |
| 26 const CGFloat kTitleSubtitleSpace = 8; | 29 const CGFloat kTitleSubtitleSpace = 8; |
| 27 const CGFloat kSubtitleButtonsSpace = 8; | 30 const CGFloat kSubtitleButtonsSpace = 8; |
| 28 const CGFloat kButtonsSpace = 8; | 31 const CGFloat kButtonsSpace = 8; |
| 29 | 32 |
| 30 void SetTextWithLineHeight(UILabel* label, NSString* text, CGFloat lineHeight) { | 33 void SetTextWithLineHeight(UILabel* label, NSString* text, CGFloat lineHeight) { |
| 31 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( | 34 NSMutableParagraphStyle* paragraphStyle = |
| 32 [[NSMutableParagraphStyle alloc] init]); | 35 [[NSMutableParagraphStyle alloc] init]; |
| 33 [paragraphStyle setMinimumLineHeight:lineHeight]; | 36 [paragraphStyle setMinimumLineHeight:lineHeight]; |
| 34 [paragraphStyle setMaximumLineHeight:lineHeight]; | 37 [paragraphStyle setMaximumLineHeight:lineHeight]; |
| 35 NSDictionary* attributes = @{NSParagraphStyleAttributeName : paragraphStyle}; | 38 NSDictionary* attributes = @{NSParagraphStyleAttributeName : paragraphStyle}; |
| 36 base::scoped_nsobject<NSAttributedString> attributedString( | 39 NSAttributedString* attributedString = |
| 37 [[NSAttributedString alloc] initWithString:text attributes:attributes]); | 40 [[NSAttributedString alloc] initWithString:text attributes:attributes]; |
| 38 label.attributedText = attributedString; | 41 label.attributedText = attributedString; |
| 39 } | 42 } |
| 40 | 43 |
| 41 } // namespace | 44 } // namespace |
| 42 | 45 |
| 43 // The view that contains the promo UI: the title, the subtitle, the dismiss and | 46 // The view that contains the promo UI: the title, the subtitle, the dismiss and |
| 44 // the sign in buttons. It is common to all size classes, but can be embedded | 47 // the sign in buttons. It is common to all size classes, but can be embedded |
| 45 // differently within the BookmarkPromoCell. | 48 // differently within the BookmarkPromoCell. |
| 46 @interface BookmarkPromoView : UIView | 49 @interface BookmarkPromoView : UIView |
| 47 | 50 |
| 48 @property(nonatomic, assign) UILabel* titleLabel; | 51 @property(nonatomic, weak) UILabel* titleLabel; |
| 49 @property(nonatomic, assign) UILabel* subtitleLabel; | 52 @property(nonatomic, weak) UILabel* subtitleLabel; |
| 50 @property(nonatomic, assign) MDCFlatButton* signInButton; | 53 @property(nonatomic, weak) MDCFlatButton* signInButton; |
| 51 @property(nonatomic, assign) MDCFlatButton* dismissButton; | 54 @property(nonatomic, weak) MDCFlatButton* dismissButton; |
| 52 | 55 |
| 53 @end | 56 @end |
| 54 | 57 |
| 55 @implementation BookmarkPromoView | 58 @implementation BookmarkPromoView |
| 56 | 59 |
| 57 @synthesize titleLabel = _titleLabel; | 60 @synthesize titleLabel = _titleLabel; |
| 58 @synthesize subtitleLabel = _subtitleLabel; | 61 @synthesize subtitleLabel = _subtitleLabel; |
| 59 @synthesize signInButton = _signInButton; | 62 @synthesize signInButton = _signInButton; |
| 60 @synthesize dismissButton = _dismissButton; | 63 @synthesize dismissButton = _dismissButton; |
| 61 | 64 |
| 62 + (BOOL)requiresConstraintBasedLayout { | 65 + (BOOL)requiresConstraintBasedLayout { |
| 63 return YES; | 66 return YES; |
| 64 } | 67 } |
| 65 | 68 |
| 66 - (instancetype)initWithFrame:(CGRect)frame { | 69 - (instancetype)initWithFrame:(CGRect)frame { |
| 67 self = [super initWithFrame:frame]; | 70 self = [super initWithFrame:frame]; |
| 68 if (self) { | 71 if (self) { |
| 69 self.backgroundColor = [UIColor whiteColor]; | 72 self.backgroundColor = [UIColor whiteColor]; |
| 70 self.accessibilityIdentifier = @"promo_view"; | 73 self.accessibilityIdentifier = @"promo_view"; |
| 71 | 74 |
| 72 // The title. | 75 // The title. |
| 73 _titleLabel = [[[UILabel alloc] init] autorelease]; | 76 UILabel* titleLabel = [[UILabel alloc] init]; |
| 77 _titleLabel = titleLabel; |
| 74 _titleLabel.textColor = bookmark_utils_ios::darkTextColor(); | 78 _titleLabel.textColor = bookmark_utils_ios::darkTextColor(); |
| 75 _titleLabel.font = | 79 _titleLabel.font = |
| 76 [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:16]; | 80 [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:16]; |
| 77 _titleLabel.numberOfLines = 0; | 81 _titleLabel.numberOfLines = 0; |
| 78 SetTextWithLineHeight(_titleLabel, | 82 SetTextWithLineHeight(_titleLabel, |
| 79 l10n_util::GetNSString(IDS_IOS_BOOKMARK_PROMO_TITLE), | 83 l10n_util::GetNSString(IDS_IOS_BOOKMARK_PROMO_TITLE), |
| 80 20.f); | 84 20.f); |
| 81 _titleLabel.translatesAutoresizingMaskIntoConstraints = NO; | 85 _titleLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| 82 [self addSubview:_titleLabel]; | 86 [self addSubview:_titleLabel]; |
| 83 | 87 |
| 84 // The subtitle. | 88 // The subtitle. |
| 85 _subtitleLabel = [[[UILabel alloc] init] autorelease]; | 89 UILabel* subtitleLabel = [[UILabel alloc] init]; |
| 90 _subtitleLabel = subtitleLabel; |
| 86 _subtitleLabel.textColor = bookmark_utils_ios::darkTextColor(); | 91 _subtitleLabel.textColor = bookmark_utils_ios::darkTextColor(); |
| 87 _subtitleLabel.font = | 92 _subtitleLabel.font = |
| 88 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14]; | 93 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:14]; |
| 89 _subtitleLabel.numberOfLines = 0; | 94 _subtitleLabel.numberOfLines = 0; |
| 90 SetTextWithLineHeight( | 95 SetTextWithLineHeight( |
| 91 _subtitleLabel, l10n_util::GetNSString(IDS_IOS_BOOKMARK_PROMO_MESSAGE), | 96 _subtitleLabel, l10n_util::GetNSString(IDS_IOS_BOOKMARK_PROMO_MESSAGE), |
| 92 20.f); | 97 20.f); |
| 93 _subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO; | 98 _subtitleLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| 94 [self addSubview:_subtitleLabel]; | 99 [self addSubview:_subtitleLabel]; |
| 95 | 100 |
| 96 // The sign-in button. | 101 // The sign-in button. |
| 97 _signInButton = [[[MDCFlatButton alloc] init] autorelease]; | 102 MDCFlatButton* signInButton = [[MDCFlatButton alloc] init]; |
| 103 _signInButton = signInButton; |
| 98 [_signInButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] | 104 [_signInButton setBackgroundColor:[[MDCPalette cr_bluePalette] tint500] |
| 99 forState:UIControlStateNormal]; | 105 forState:UIControlStateNormal]; |
| 100 _signInButton.customTitleColor = [UIColor whiteColor]; | 106 _signInButton.customTitleColor = [UIColor whiteColor]; |
| 101 _signInButton.inkColor = [UIColor colorWithWhite:1 alpha:0.2]; | 107 _signInButton.inkColor = [UIColor colorWithWhite:1 alpha:0.2]; |
| 102 [_signInButton | 108 [_signInButton |
| 103 setTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_PROMO_SIGN_IN_BUTTON) | 109 setTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_PROMO_SIGN_IN_BUTTON) |
| 104 forState:UIControlStateNormal]; | 110 forState:UIControlStateNormal]; |
| 105 _signInButton.accessibilityIdentifier = @"promo_sign_in_button"; | 111 _signInButton.accessibilityIdentifier = @"promo_sign_in_button"; |
| 106 _signInButton.translatesAutoresizingMaskIntoConstraints = NO; | 112 _signInButton.translatesAutoresizingMaskIntoConstraints = NO; |
| 107 [self addSubview:_signInButton]; | 113 [self addSubview:_signInButton]; |
| 108 | 114 |
| 109 // The dismiss button. | 115 // The dismiss button. |
| 110 _dismissButton = [[[MDCFlatButton alloc] init] autorelease]; | 116 MDCFlatButton* dismissButton = [[MDCFlatButton alloc] init]; |
| 117 _dismissButton = dismissButton; |
| 111 [_dismissButton | 118 [_dismissButton |
| 112 setTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_PROMO_DISMISS_BUTTON) | 119 setTitle:l10n_util::GetNSString(IDS_IOS_BOOKMARK_PROMO_DISMISS_BUTTON) |
| 113 forState:UIControlStateNormal]; | 120 forState:UIControlStateNormal]; |
| 114 _dismissButton.customTitleColor = [[MDCPalette cr_bluePalette] tint500]; | 121 _dismissButton.customTitleColor = [[MDCPalette cr_bluePalette] tint500]; |
| 115 _dismissButton.accessibilityIdentifier = @"promo_no_thanks_button"; | 122 _dismissButton.accessibilityIdentifier = @"promo_no_thanks_button"; |
| 116 _dismissButton.translatesAutoresizingMaskIntoConstraints = NO; | 123 _dismissButton.translatesAutoresizingMaskIntoConstraints = NO; |
| 117 [self addSubview:_dismissButton]; | 124 [self addSubview:_dismissButton]; |
| 118 } | 125 } |
| 119 return self; | 126 return self; |
| 120 } | 127 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 145 ApplyVisualConstraintsWithMetricsAndOptions( | 152 ApplyVisualConstraintsWithMetricsAndOptions( |
| 146 constraints, views, metrics, LayoutOptionForRTLSupport(), self); | 153 constraints, views, metrics, LayoutOptionForRTLSupport(), self); |
| 147 AddSameCenterYConstraint(self, self.signInButton, self.dismissButton); | 154 AddSameCenterYConstraint(self, self.signInButton, self.dismissButton); |
| 148 } | 155 } |
| 149 [super updateConstraints]; | 156 [super updateConstraints]; |
| 150 } | 157 } |
| 151 | 158 |
| 152 @end | 159 @end |
| 153 | 160 |
| 154 @interface BookmarkPromoCell () { | 161 @interface BookmarkPromoCell () { |
| 155 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkPromoCell; | |
| 156 } | 162 } |
| 157 @property(nonatomic, assign) BookmarkPromoView* promoView; | 163 @property(nonatomic, weak) BookmarkPromoView* promoView; |
| 158 @property(nonatomic, retain) NSArray* compactContentViewConstraints; | 164 @property(nonatomic, strong) NSArray* compactContentViewConstraints; |
| 159 @property(nonatomic, retain) NSArray* regularContentViewConstraints; | 165 @property(nonatomic, strong) NSArray* regularContentViewConstraints; |
| 160 @end | 166 @end |
| 161 | 167 |
| 162 @implementation BookmarkPromoCell | 168 @implementation BookmarkPromoCell |
| 163 | 169 |
| 164 @synthesize delegate = _delegate; | 170 @synthesize delegate = _delegate; |
| 165 @synthesize promoView = _promoView; | 171 @synthesize promoView = _promoView; |
| 166 @synthesize compactContentViewConstraints = _compactContentViewConstraints; | 172 @synthesize compactContentViewConstraints = _compactContentViewConstraints; |
| 167 @synthesize regularContentViewConstraints = _regularContentViewConstraints; | 173 @synthesize regularContentViewConstraints = _regularContentViewConstraints; |
| 168 | 174 |
| 169 + (NSString*)reuseIdentifier { | 175 + (NSString*)reuseIdentifier { |
| 170 return @"BookmarkPromoCell"; | 176 return @"BookmarkPromoCell"; |
| 171 } | 177 } |
| 172 | 178 |
| 173 + (BOOL)requiresConstraintBasedLayout { | 179 + (BOOL)requiresConstraintBasedLayout { |
| 174 return YES; | 180 return YES; |
| 175 } | 181 } |
| 176 | 182 |
| 177 - (instancetype)initWithFrame:(CGRect)frame { | 183 - (instancetype)initWithFrame:(CGRect)frame { |
| 178 self = [super initWithFrame:frame]; | 184 self = [super initWithFrame:frame]; |
| 179 if (self) { | 185 if (self) { |
| 180 _propertyReleaser_BookmarkPromoCell.Init(self, [BookmarkPromoCell class]); | |
| 181 self.contentView.translatesAutoresizingMaskIntoConstraints = NO; | 186 self.contentView.translatesAutoresizingMaskIntoConstraints = NO; |
| 182 | 187 |
| 183 _promoView = [[[BookmarkPromoView alloc] initWithFrame:frame] autorelease]; | 188 BookmarkPromoView* promoView = |
| 189 [[BookmarkPromoView alloc] initWithFrame:frame]; |
| 190 _promoView = promoView; |
| 184 [_promoView.signInButton addTarget:self | 191 [_promoView.signInButton addTarget:self |
| 185 action:@selector(signIn:) | 192 action:@selector(signIn:) |
| 186 forControlEvents:UIControlEventTouchUpInside]; | 193 forControlEvents:UIControlEventTouchUpInside]; |
| 187 [_promoView.dismissButton addTarget:self | 194 [_promoView.dismissButton addTarget:self |
| 188 action:@selector(dismiss:) | 195 action:@selector(dismiss:) |
| 189 forControlEvents:UIControlEventTouchUpInside]; | 196 forControlEvents:UIControlEventTouchUpInside]; |
| 190 _promoView.translatesAutoresizingMaskIntoConstraints = NO; | 197 _promoView.translatesAutoresizingMaskIntoConstraints = NO; |
| 191 [self.contentView addSubview:_promoView]; | 198 [self.contentView addSubview:_promoView]; |
| 192 [self updatePromoView]; | 199 [self updatePromoView]; |
| 193 } | 200 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 288 |
| 282 - (void)signIn:(id)sender { | 289 - (void)signIn:(id)sender { |
| 283 [self.delegate bookmarkPromoCellDidTapSignIn:self]; | 290 [self.delegate bookmarkPromoCellDidTapSignIn:self]; |
| 284 } | 291 } |
| 285 | 292 |
| 286 - (void)dismiss:(id)sender { | 293 - (void)dismiss:(id)sender { |
| 287 [self.delegate bookmarkPromoCellDidTapDismiss:self]; | 294 [self.delegate bookmarkPromoCellDidTapDismiss:self]; |
| 288 } | 295 } |
| 289 | 296 |
| 290 @end | 297 @end |
| OLD | NEW |