Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.mm

Issue 2885943002: Implementing sign-in promo for "Other Devices" on the iPad (Closed)
Patch Set: Merge Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ui/tab_switcher/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h" 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h"
6 6
7 #include "base/metrics/user_metrics.h" 7 #include "base/metrics/user_metrics.h"
8 #include "base/metrics/user_metrics_action.h" 8 #include "base/metrics/user_metrics_action.h"
9 #include "components/signin/core/browser/signin_metrics.h"
10 #include "ios/chrome/browser/experimental_flags.h"
11 #import "ios/chrome/browser/ui/authentication/signin_promo_view.h"
12 #import "ios/chrome/browser/ui/authentication/signin_promo_view_configurator.h"
13 #import "ios/chrome/browser/ui/authentication/signin_promo_view_consumer.h"
14 #import "ios/chrome/browser/ui/authentication/signin_promo_view_mediator.h"
9 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 15 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
10 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" 16 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
11 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 17 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
12 #import "ios/chrome/browser/ui/commands/show_signin_command.h" 18 #import "ios/chrome/browser/ui/commands/show_signin_command.h"
13 #import "ios/chrome/browser/ui/material_components/activity_indicator.h" 19 #import "ios/chrome/browser/ui/material_components/activity_indicator.h"
14 #import "ios/chrome/browser/ui/sync/sync_util.h" 20 #import "ios/chrome/browser/ui/sync/sync_util.h"
15 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_model.h" 21 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_model.h"
16 #import "ios/chrome/browser/ui/uikit_ui_util.h" 22 #import "ios/chrome/browser/ui/uikit_ui_util.h"
17 #include "ios/chrome/grit/ios_chromium_strings.h" 23 #include "ios/chrome/grit/ios_chromium_strings.h"
18 #include "ios/chrome/grit/ios_strings.h" 24 #include "ios/chrome/grit/ios_strings.h"
(...skipping 26 matching lines...) Expand all
45 } 51 }
46 } 52 }
47 53
48 namespace { 54 namespace {
49 const CGFloat kContainerOriginYOffset = -58.0; 55 const CGFloat kContainerOriginYOffset = -58.0;
50 const CGFloat kContainerWidth = 400.0; 56 const CGFloat kContainerWidth = 400.0;
51 const CGFloat kTitleMinimumLineHeight = 32.0; 57 const CGFloat kTitleMinimumLineHeight = 32.0;
52 const CGFloat kSubtitleMinimunLineHeight = 24.0; 58 const CGFloat kSubtitleMinimunLineHeight = 24.0;
53 } 59 }
54 60
55 @interface TabSwitcherPanelOverlayView () 61 @interface TabSwitcherPanelOverlayView ()<SigninPromoViewConsumer>
56 62
57 // Updates the texts of labels and button according to the current 63 // Updates the texts of labels and button according to the current
58 // |overlayType|. 64 // |overlayType|.
59 - (void)updateText; 65 - (void)updateText;
60 // Updates the button target and tag according to the current |overlayType|. 66 // Updates the button target and tag according to the current |overlayType|.
61 - (void)updateButtonTarget; 67 - (void)updateButtonTarget;
62 // Sends a SignIn chrome command. 68 // Sends a SignIn chrome command.
63 - (void)showSignIn; 69 - (void)showSignIn;
64 70
65 @end 71 @end
66 72
67 @implementation TabSwitcherPanelOverlayView { 73 @implementation TabSwitcherPanelOverlayView {
68 ios::ChromeBrowserState* _browserState; // Weak. 74 ios::ChromeBrowserState* _browserState; // Weak.
69 UIView* _container; 75 UIView* _container;
70 UILabel* _titleLabel; 76 UILabel* _titleLabel;
71 UILabel* _subtitleLabel; 77 UILabel* _subtitleLabel;
72 MDCButton* _textButton; 78 MDCButton* _textButton;
73 MDCButton* _floatingButton; 79 MDCButton* _floatingButton;
74 MDCActivityIndicator* _activityIndicator; 80 MDCActivityIndicator* _activityIndicator;
75 std::string _recordedMetricString; 81 std::string _recordedMetricString;
82 SigninPromoViewMediator* _signinPromoViewMediator;
83 SigninPromoView* _signinPromoView;
76 } 84 }
77 85
78 @synthesize overlayType = _overlayType; 86 @synthesize overlayType = _overlayType;
79 87
80 - (instancetype)initWithFrame:(CGRect)frame 88 - (instancetype)initWithFrame:(CGRect)frame
81 browserState:(ios::ChromeBrowserState*)browserState { 89 browserState:(ios::ChromeBrowserState*)browserState {
82 self = [super initWithFrame:frame]; 90 self = [super initWithFrame:frame];
83 if (self) { 91 if (self) {
84 _browserState = browserState; 92 _browserState = browserState;
85 // Create and add container. Will be vertically and horizontally centered. 93 // Create and add container. Will be vertically and horizontally centered.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 @"H:|-[subtitle]-|", @"H:[button(>=180)]", @"H:[floatingButton(==48)]" 168 @"H:|-[subtitle]-|", @"H:[button(>=180)]", @"H:[floatingButton(==48)]"
161 ]; 169 ];
162 ApplyVisualConstraints(constraints, viewsDictionary, _container); 170 ApplyVisualConstraints(constraints, viewsDictionary, _container);
163 171
164 // Sets the container's width relative to the parent. 172 // Sets the container's width relative to the parent.
165 ApplyVisualConstraintsWithMetrics( 173 ApplyVisualConstraintsWithMetrics(
166 @[ 174 @[
167 @"H:|-(>=0)-[container(==containerWidth@999)]-(>=0)-|", 175 @"H:|-(>=0)-[container(==containerWidth@999)]-(>=0)-|",
168 ], 176 ],
169 @{ @"container" : _container }, 177 @{ @"container" : _container },
170 @{ @"containerWidth" : @(kContainerWidth) }, self); 178 @{ @"containerWidth" : @(kContainerWidth) });
179
180 // Adding sign-in promo view.
msarda 2017/05/23 12:55:54 It looks like the sign-in promo view is created ev
jlebel 2017/05/23 14:34:15 Done.
181 _signinPromoView = [[SigninPromoView alloc] initWithFrame:CGRectZero];
182 _signinPromoView.translatesAutoresizingMaskIntoConstraints = NO;
183 _signinPromoView.textLabel.text =
184 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_SETTINGS);
msarda 2017/05/23 12:55:55 Why are we using the settings promo string in the
jlebel 2017/05/23 14:34:15 Done.
185 _signinPromoView.textLabel.textColor = [UIColor whiteColor];
186 _signinPromoView.textLabel.font = [MDCTypography headlineFont];
187 _signinPromoView.textLabel.preferredMaxLayoutWidth =
188 kContainerWidth - (2 * _signinPromoView.horizontalPadding);
189 [self addSubview:_signinPromoView];
190 ApplyVisualConstraintsWithMetrics(
191 @[ @"H:[signinPromoView(containerWidth)]" ],
192 @{ @"signinPromoView" : _signinPromoView },
193 @{ @"containerWidth" : @(kContainerWidth) });
194 AddSameCenterXConstraint(_signinPromoView, self);
195 [_signinPromoView.centerYAnchor
196 constraintEqualToAnchor:self.centerYAnchor
197 constant:kContainerOriginYOffset]
198 .active = YES;
199 _signinPromoView.hidden = YES;
200 _signinPromoViewMediator = [[SigninPromoViewMediator alloc] init];
201 _signinPromoViewMediator.accessPoint =
202 signin_metrics::AccessPoint::ACCESS_POINT_RECENT_TABS;
203 _signinPromoView.delegate = _signinPromoViewMediator;
204 _signinPromoViewMediator.consumer = self;
205 [[_signinPromoViewMediator createConfigurator]
206 configureSigninPromoView:_signinPromoView];
207 [_signinPromoView setNeedsLayout];
msarda 2017/05/23 12:55:55 Why should the sign-in promo view be layed out if
jlebel 2017/05/23 14:34:15 I've done it just to make sure the layout is corre
171 } 208 }
172 return self; 209 return self;
173 } 210 }
174 211
175 - (void)layoutSubviews { 212 - (void)layoutSubviews {
176 [super layoutSubviews]; 213 [super layoutSubviews];
177 CGRect containerFrame = [_container frame]; 214 CGRect containerFrame = [_container frame];
178 containerFrame.origin.x = 215 containerFrame.origin.x =
179 (self.frame.size.width - containerFrame.size.width) / 2; 216 (self.frame.size.width - containerFrame.size.width) / 2;
180 containerFrame.origin.y = 217 containerFrame.origin.y =
181 (self.frame.size.height - containerFrame.size.height) / 2 + 218 (self.frame.size.height - containerFrame.size.height) / 2 +
182 kContainerOriginYOffset; 219 kContainerOriginYOffset;
183 [_container setFrame:containerFrame]; 220 [_container setFrame:containerFrame];
184 } 221 }
185 222
186 - (void)setOverlayType:(TabSwitcherPanelOverlayType)overlayType { 223 - (void)setOverlayType:(TabSwitcherPanelOverlayType)overlayType {
187 _overlayType = overlayType; 224 _overlayType = overlayType;
188 [self updateText]; 225 if (experimental_flags::IsSigninPromoEnabled() &&
189 [self updateButtonTarget]; 226 _overlayType ==
227 TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_OUT) {
228 _container.hidden = YES;
229 _signinPromoView.hidden = NO;
230 } else {
231 _container.hidden = NO;
232 _signinPromoView.hidden = YES;
233 [self updateText];
msarda 2017/05/23 12:55:55 When the promo is enabled, it looks like we do not
jlebel 2017/05/23 14:34:15 In this overlay view, I can't use the current UI e
234 [self updateButtonTarget];
235 }
190 } 236 }
191 237
192 #pragma mark - Private 238 #pragma mark - Private
193 239
194 - (void)updateText { 240 - (void)updateText {
195 NSMutableAttributedString* titleString = nil; 241 NSMutableAttributedString* titleString = nil;
196 NSMutableAttributedString* subtitleString = nil; 242 NSMutableAttributedString* subtitleString = nil;
197 243
198 NSString* buttonTitle = nil; 244 NSString* buttonTitle = nil;
199 UIImage* buttonImage = nil; 245 UIImage* buttonImage = nil;
200 NSString* buttonAccessibilityLabel = nil; 246 NSString* buttonAccessibilityLabel = nil;
201 UIColor* floatingButtonNormalBackgroundColor = nil; 247 UIColor* floatingButtonNormalBackgroundColor = nil;
202 UIColor* floatingButtonDisabledBackgroundColor = nil; 248 UIColor* floatingButtonDisabledBackgroundColor = nil;
203 UIColor* floatingButtonInkColor = nil; 249 UIColor* floatingButtonInkColor = nil;
204 BOOL spinnerIsHidden = YES; 250 BOOL spinnerIsHidden = YES;
205 switch (self.overlayType) { 251 switch (self.overlayType) {
206 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_EMPTY: 252 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_EMPTY:
207 break; 253 break;
208 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_OUT: 254 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_OUT:
msarda 2017/05/23 12:55:55 Maybe: DCHECK(!experimental_flags::IsSigninPromoEn
jlebel 2017/05/23 14:34:15 Done.
209 titleString = [[NSMutableAttributedString alloc] 255 titleString = [[NSMutableAttributedString alloc]
210 initWithString:l10n_util::GetNSString( 256 initWithString:l10n_util::GetNSString(
211 IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_TITLE)]; 257 IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_TITLE)];
212 subtitleString = [[NSMutableAttributedString alloc] 258 subtitleString = [[NSMutableAttributedString alloc]
213 initWithString:l10n_util::GetNSString( 259 initWithString:l10n_util::GetNSString(
214 IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_PROMO)]; 260 IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_PROMO)];
215 buttonTitle = 261 buttonTitle =
216 l10n_util::GetNSString(IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_BUTTON); 262 l10n_util::GetNSString(IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_BUTTON);
217 break; 263 break;
218 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_IN_SYNC_OFF: 264 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_IN_SYNC_OFF:
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 - (void)rootViewControllerChromeCommand:(id)command { 449 - (void)rootViewControllerChromeCommand:(id)command {
404 [self chromeExecuteCommand:command]; 450 [self chromeExecuteCommand:command];
405 } 451 }
406 452
407 - (void)recordMetrics { 453 - (void)recordMetrics {
408 if (!_recordedMetricString.length()) 454 if (!_recordedMetricString.length())
409 return; 455 return;
410 base::RecordAction(base::UserMetricsAction(_recordedMetricString.c_str())); 456 base::RecordAction(base::UserMetricsAction(_recordedMetricString.c_str()));
411 } 457 }
412 458
459 #pragma mark - SigninPromoViewConsumer
460
461 - (void)configureSigninPromoViewWithNewIdentity:(BOOL)newIdentity
462 configurator:(SigninPromoViewConfigurator*)
463 configurator {
464 [configurator configureSigninPromoView:_signinPromoView];
465 }
466
413 @end 467 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/tab_switcher/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698