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

Side by Side Diff: chrome/browser/ui/cocoa/passwords/signin_promo_view_controller.mm

Issue 2040143006: Implement the Sync promo in the password bubble on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/passwords/signin_promo_view_controller.h"
6
7 #include "base/mac/scoped_nsobject.h"
8 #include "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h"
9 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
10 #include "grit/generated_resources.h"
11 #import "ui/base/cocoa/controls/hyperlink_text_view.h"
12 #include "ui/base/l10n/l10n_util_mac.h"
13
14 @interface SignInPromoViewController () {
15 base::scoped_nsobject<NSButton> _signInButton;
16 base::scoped_nsobject<NSButton> _noButton;
17 }
18
19 // "Sign In" and "No thanks" button handlers.
20 - (void)onSignInClicked:(id)sender;
21 - (void)onNoClicked:(id)sender;
22 @end
23
24 @implementation SignInPromoViewController
25
26 - (instancetype)initWithDelegate:
27 (id<BasePasswordsContentViewDelegate>)delegate {
28 return [super initWithDelegate:delegate];
29 }
30
31 - (NSButton*)defaultButton {
32 return _signInButton;
33 }
34
35 // ------------------------------------
36 // | Sign in to Chrome! |
37 // | |
38 // | [ No ] [ Sign In ] |
39 // ------------------------------------
40 - (void)loadView {
41 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
42 // Title.
43 HyperlinkTextView* titleView = TitleBubbleLabelWithLink(
44 [self.delegate model]->title(), gfx::Range(), nil);
45 // Force the text to wrap to fit in the bubble size.
46 int titleWidth = kDesiredBubbleWidth - 2*kFramePadding;
47 [titleView setVerticallyResizable:YES];
48 [titleView setFrameSize:NSMakeSize(titleWidth, MAXFLOAT)];
49 [titleView sizeToFit];
50 [view addSubview:titleView];
51
52 NSString* signInText =
53 l10n_util::GetNSString(IDS_PASSWORD_MANAGER_SIGNIN_PROMO_SIGN_IN);
54 _signInButton.reset([[self addButton:signInText
55 toView:view
56 target:self
57 action:@selector(onSignInClicked:)] retain]);
58 NSString* noText =
59 l10n_util::GetNSString(IDS_PASSWORD_MANAGER_SIGNIN_PROMO_NO_THANKS);
60 _noButton.reset([[self addButton:noText
61 toView:view
62 target:self
63 action:@selector(onNoClicked:)] retain]);
64
65 // Layout the elements, starting at the bottom and moving up.
66 CGFloat curX =
67 kDesiredBubbleWidth - kFramePadding - NSWidth([_signInButton frame]);
68 CGFloat curY = kFramePadding;
69 [_signInButton setFrameOrigin:NSMakePoint(curX, curY)];
70
71 curX -= kRelatedControlHorizontalPadding;
72 curX -= NSWidth([_noButton frame]);
73 [_noButton setFrameOrigin:NSMakePoint(curX, curY)];
74
75 curY = NSMaxY([_noButton frame]) + kUnrelatedControlVerticalPadding;
76 [titleView setFrameOrigin:NSMakePoint(kFramePadding, curY)];
77 [view setFrame:NSMakeRect(0, 0, kDesiredBubbleWidth,
78 NSMaxY([titleView frame]) + kFramePadding)];
79 [self setView:view];
80 }
81
82 - (void)onSignInClicked:(id)sender {
83 ManagePasswordsBubbleModel* model = [self.delegate model];
84 if (model)
85 model->OnSignInToChromeClicked();
86 [self.delegate viewShouldDismiss];
87 }
88
89 - (void)onNoClicked:(id)sender {
90 ManagePasswordsBubbleModel* model = [self.delegate model];
91 if (model)
92 model->OnSkipSignInClicked();
93 [self.delegate viewShouldDismiss];
94 }
95
96 @end
97
98 @implementation SignInPromoViewController (Testing)
99
100 - (NSButton*)signInButton {
101 return _signInButton.get();
102 }
103
104 - (NSButton*)noButton {
105 return _noButton.get();
106 }
107
108 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698