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

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: . 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) });
171 } 179 }
172 return self; 180 return self;
173 } 181 }
174 182
175 - (void)layoutSubviews { 183 - (void)layoutSubviews {
176 [super layoutSubviews]; 184 [super layoutSubviews];
177 CGRect containerFrame = [_container frame]; 185 CGRect containerFrame = [_container frame];
178 containerFrame.origin.x = 186 containerFrame.origin.x =
179 (self.frame.size.width - containerFrame.size.width) / 2; 187 (self.frame.size.width - containerFrame.size.width) / 2;
180 containerFrame.origin.y = 188 containerFrame.origin.y =
181 (self.frame.size.height - containerFrame.size.height) / 2 + 189 (self.frame.size.height - containerFrame.size.height) / 2 +
182 kContainerOriginYOffset; 190 kContainerOriginYOffset;
183 [_container setFrame:containerFrame]; 191 [_container setFrame:containerFrame];
184 } 192 }
185 193
186 - (void)setOverlayType:(TabSwitcherPanelOverlayType)overlayType { 194 - (void)setOverlayType:(TabSwitcherPanelOverlayType)overlayType {
187 _overlayType = overlayType; 195 _overlayType = overlayType;
188 [self updateText]; 196 if (experimental_flags::IsSigninPromoEnabled() &&
189 [self updateButtonTarget]; 197 _overlayType ==
198 TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_OUT) {
199 [self createSigninPromoviewIfNeeded];
200 _container.hidden = YES;
201 } else {
202 _container.hidden = NO;
203 [_signinPromoView removeFromSuperview];
204 _signinPromoView = nil;
205 _signinPromoViewMediator.consumer = nil;
206 _signinPromoViewMediator = nil;
207 [self updateText];
208 [self updateButtonTarget];
209 }
190 } 210 }
191 211
192 #pragma mark - Private 212 #pragma mark - Private
193 213
214 // Creates the sign-in view and its mediator if it doesn't exist.
215 - (void)createSigninPromoviewIfNeeded {
216 if (_signinPromoView) {
217 DCHECK(_signinPromoViewMediator);
218 return;
219 }
220 _signinPromoView = [[SigninPromoView alloc] initWithFrame:CGRectZero];
221 _signinPromoView.translatesAutoresizingMaskIntoConstraints = NO;
222 _signinPromoView.textLabel.text =
223 l10n_util::GetNSString(IDS_IOS_SIGNIN_PROMO_RECENT_TABS);
224 _signinPromoView.textLabel.textColor = [UIColor whiteColor];
225 _signinPromoView.textLabel.font = [MDCTypography headlineFont];
226 _signinPromoView.textLabel.preferredMaxLayoutWidth =
227 kContainerWidth - (2 * _signinPromoView.horizontalPadding);
228 [self addSubview:_signinPromoView];
229 ApplyVisualConstraintsWithMetrics(
230 @[ @"H:[signinPromoView(containerWidth)]" ],
231 @{ @"signinPromoView" : _signinPromoView },
232 @{ @"containerWidth" : @(kContainerWidth) });
233 AddSameCenterXConstraint(_signinPromoView, self);
234 [_signinPromoView.centerYAnchor
235 constraintEqualToAnchor:self.centerYAnchor
236 constant:kContainerOriginYOffset]
237 .active = YES;
238 _signinPromoViewMediator = [[SigninPromoViewMediator alloc] init];
239 _signinPromoViewMediator.accessPoint =
240 signin_metrics::AccessPoint::ACCESS_POINT_RECENT_TABS;
241 _signinPromoView.delegate = _signinPromoViewMediator;
242 _signinPromoViewMediator.consumer = self;
243 [[_signinPromoViewMediator createConfigurator]
244 configureSigninPromoView:_signinPromoView];
245 }
246
194 - (void)updateText { 247 - (void)updateText {
248 DCHECK(_signinPromoView == nil && _signinPromoViewMediator == nil);
195 NSMutableAttributedString* titleString = nil; 249 NSMutableAttributedString* titleString = nil;
196 NSMutableAttributedString* subtitleString = nil; 250 NSMutableAttributedString* subtitleString = nil;
197 251
198 NSString* buttonTitle = nil; 252 NSString* buttonTitle = nil;
199 UIImage* buttonImage = nil; 253 UIImage* buttonImage = nil;
200 NSString* buttonAccessibilityLabel = nil; 254 NSString* buttonAccessibilityLabel = nil;
201 UIColor* floatingButtonNormalBackgroundColor = nil; 255 UIColor* floatingButtonNormalBackgroundColor = nil;
202 UIColor* floatingButtonDisabledBackgroundColor = nil; 256 UIColor* floatingButtonDisabledBackgroundColor = nil;
203 UIColor* floatingButtonInkColor = nil; 257 UIColor* floatingButtonInkColor = nil;
204 BOOL spinnerIsHidden = YES; 258 BOOL spinnerIsHidden = YES;
205 switch (self.overlayType) { 259 switch (self.overlayType) {
206 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_EMPTY: 260 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_EMPTY:
207 break; 261 break;
208 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_OUT: 262 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_OUT:
263 DCHECK(!experimental_flags::IsSigninPromoEnabled());
209 titleString = [[NSMutableAttributedString alloc] 264 titleString = [[NSMutableAttributedString alloc]
210 initWithString:l10n_util::GetNSString( 265 initWithString:l10n_util::GetNSString(
211 IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_TITLE)]; 266 IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_TITLE)];
212 subtitleString = [[NSMutableAttributedString alloc] 267 subtitleString = [[NSMutableAttributedString alloc]
213 initWithString:l10n_util::GetNSString( 268 initWithString:l10n_util::GetNSString(
214 IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_PROMO)]; 269 IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_PROMO)];
215 buttonTitle = 270 buttonTitle =
216 l10n_util::GetNSString(IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_BUTTON); 271 l10n_util::GetNSString(IDS_IOS_TAB_SWITCHER_SIGN_IN_ACCOUNT_BUTTON);
217 break; 272 break;
218 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_IN_SYNC_OFF: 273 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_IN_SYNC_OFF:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 [_floatingButton setAccessibilityLabel:buttonAccessibilityLabel]; 373 [_floatingButton setAccessibilityLabel:buttonAccessibilityLabel];
319 [_activityIndicator setHidden:spinnerIsHidden]; 374 [_activityIndicator setHidden:spinnerIsHidden];
320 if (spinnerIsHidden) { 375 if (spinnerIsHidden) {
321 [_activityIndicator stopAnimating]; 376 [_activityIndicator stopAnimating];
322 } else { 377 } else {
323 [_activityIndicator startAnimating]; 378 [_activityIndicator startAnimating];
324 } 379 }
325 } 380 }
326 381
327 - (void)updateButtonTarget { 382 - (void)updateButtonTarget {
383 DCHECK(_signinPromoView == nil && _signinPromoViewMediator == nil);
328 NSInteger tag = 0; 384 NSInteger tag = 0;
329 SEL selector = nil; 385 SEL selector = nil;
330 _recordedMetricString = ""; 386 _recordedMetricString = "";
331 387
332 BOOL shouldShowTextButton = YES; 388 BOOL shouldShowTextButton = YES;
333 BOOL shouldShowFloatingButton = NO; 389 BOOL shouldShowFloatingButton = NO;
334 switch (self.overlayType) { 390 switch (self.overlayType) {
335 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_EMPTY: 391 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_EMPTY:
336 shouldShowTextButton = NO; 392 shouldShowTextButton = NO;
337 break; 393 break;
338 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_OUT: 394 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_OUT:
395 DCHECK(!experimental_flags::IsSigninPromoEnabled());
339 selector = @selector(showSignIn); 396 selector = @selector(showSignIn);
340 _recordedMetricString = "MobileTabSwitcherSignIn"; 397 _recordedMetricString = "MobileTabSwitcherSignIn";
341 break; 398 break;
342 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_IN_SYNC_OFF: 399 case TabSwitcherPanelOverlayType::OVERLAY_PANEL_USER_SIGNED_IN_SYNC_OFF:
343 selector = @selector(showSyncSettings); 400 selector = @selector(showSyncSettings);
344 _recordedMetricString = "MobileTabSwitcherEnableSync"; 401 _recordedMetricString = "MobileTabSwitcherEnableSync";
345 break; 402 break;
346 case TabSwitcherPanelOverlayType:: 403 case TabSwitcherPanelOverlayType::
347 OVERLAY_PANEL_USER_SIGNED_IN_SYNC_ON_NO_SESSIONS: 404 OVERLAY_PANEL_USER_SIGNED_IN_SYNC_ON_NO_SESSIONS:
348 shouldShowTextButton = NO; 405 shouldShowTextButton = NO;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 - (void)rootViewControllerChromeCommand:(id)command { 458 - (void)rootViewControllerChromeCommand:(id)command {
402 [self chromeExecuteCommand:command]; 459 [self chromeExecuteCommand:command];
403 } 460 }
404 461
405 - (void)recordMetrics { 462 - (void)recordMetrics {
406 if (!_recordedMetricString.length()) 463 if (!_recordedMetricString.length())
407 return; 464 return;
408 base::RecordAction(base::UserMetricsAction(_recordedMetricString.c_str())); 465 base::RecordAction(base::UserMetricsAction(_recordedMetricString.c_str()));
409 } 466 }
410 467
468 #pragma mark - SigninPromoViewConsumer
469
470 - (void)configureSigninPromoViewWithNewIdentity:(BOOL)newIdentity
471 configurator:(SigninPromoViewConfigurator*)
472 configurator {
473 DCHECK(_signinPromoView);
474 DCHECK(_signinPromoViewMediator);
475 [configurator configureSigninPromoView:_signinPromoView];
476 }
477
411 @end 478 @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