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

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

Issue 2588323002: Revert "Remove Finch support for PasswordBranding" (Closed)
Patch Set: Created 3 years, 12 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
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 #include <algorithm> 5 #include <algorithm>
6 6
7 #import "chrome/browser/ui/cocoa/passwords/pending_password_view_controller.h" 7 #import "chrome/browser/ui/cocoa/passwords/pending_password_view_controller.h"
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 #include "chrome/browser/ui/cocoa/chrome_style.h" 11 #include "chrome/browser/ui/cocoa/chrome_style.h"
12 #import "chrome/browser/ui/cocoa/hover_close_button.h" 12 #import "chrome/browser/ui/cocoa/hover_close_button.h"
13 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" 13 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h"
14 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 14 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
15 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
16 #include "skia/ext/skia_utils_mac.h" 16 #include "skia/ext/skia_utils_mac.h"
17 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h"
17 #import "ui/base/cocoa/controls/hyperlink_text_view.h" 18 #import "ui/base/cocoa/controls/hyperlink_text_view.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 20
21 constexpr SkColor kWarmWelcomeColor =
22 SkColorSetARGBMacro(0xFF, 0x64, 0x64, 0x64);
23
20 @implementation PendingPasswordViewController 24 @implementation PendingPasswordViewController
21 25
22 - (BOOL)textView:(NSTextView*)textView 26 - (BOOL)textView:(NSTextView*)textView
23 clickedOnLink:(id)link 27 clickedOnLink:(id)link
24 atIndex:(NSUInteger)charIndex { 28 atIndex:(NSUInteger)charIndex {
25 ManagePasswordsBubbleModel* model = [self model]; 29 ManagePasswordsBubbleModel* model = [self model];
26 if (model) 30 if (model)
27 model->OnBrandLinkClicked(); 31 model->OnBrandLinkClicked();
28 [self.delegate viewShouldDismiss]; 32 [self.delegate viewShouldDismiss];
29 return YES; 33 return YES;
30 } 34 }
31 35
32 - (base::scoped_nsobject<NSButton>)newCloseButton { 36 - (base::scoped_nsobject<NSButton>)newCloseButton {
33 const int dimension = chrome_style::GetCloseButtonSize(); 37 const int dimension = chrome_style::GetCloseButtonSize();
34 NSRect frame = NSMakeRect(0, 0, dimension, dimension); 38 NSRect frame = NSMakeRect(0, 0, dimension, dimension);
35 base::scoped_nsobject<NSButton> button( 39 base::scoped_nsobject<NSButton> button(
36 [[WebUIHoverCloseButton alloc] initWithFrame:frame]); 40 [[WebUIHoverCloseButton alloc] initWithFrame:frame]);
37 [button setAction:@selector(viewShouldDismiss)]; 41 [button setAction:@selector(viewShouldDismiss)];
38 [button setTarget:self.delegate]; 42 [button setTarget:self.delegate];
39 return button; 43 return button;
40 } 44 }
41 45
42 - (NSView*)createPasswordView { 46 - (NSView*)createPasswordView {
43 // Empty implementation, it should be implemented in child class. 47 // Empty implementation, it should be implemented in child class.
44 NOTREACHED(); 48 NOTREACHED();
45 return nil; 49 return nil;
46 } 50 }
47 51
52 - (BOOL)shouldShowGoogleSmartLockWelcome {
53 return NO;
54 }
55
48 - (NSArray*)createButtonsAndAddThemToView:(NSView*)view { 56 - (NSArray*)createButtonsAndAddThemToView:(NSView*)view {
49 // Empty implementation, it should be implemented in child class. 57 // Empty implementation, it should be implemented in child class.
50 NOTREACHED(); 58 NOTREACHED();
51 return nil; 59 return nil;
52 } 60 }
53 61
54 - (void)loadView { 62 - (void)loadView {
55 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); 63 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
56 64
57 // ----------------------------------- 65 // -----------------------------------
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 101
94 [view addSubview:titleView]; 102 [view addSubview:titleView];
95 103
96 // Password item. 104 // Password item.
97 // It should be at least as wide as the box without the padding. 105 // It should be at least as wide as the box without the padding.
98 NSView* passwordRow = [self createPasswordView]; 106 NSView* passwordRow = [self createPasswordView];
99 if (passwordRow) { 107 if (passwordRow) {
100 [view addSubview:passwordRow]; 108 [view addSubview:passwordRow];
101 } 109 }
102 110
111 base::scoped_nsobject<NSTextField> warm_welcome;
112 if ([self shouldShowGoogleSmartLockWelcome]) {
113 base::string16 label_text =
114 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK_WELCOME);
115 warm_welcome.reset([[NSTextField alloc] initWithFrame:NSZeroRect]);
116 InitLabel(warm_welcome.get(), label_text);
117 [[warm_welcome cell] setWraps:YES];
118 [warm_welcome setFrameSize:NSMakeSize(kDesiredBubbleWidth - 2*kFramePadding,
119 MAXFLOAT)];
120 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:warm_welcome];
121 NSColor* color = skia::SkColorToSRGBNSColor(kWarmWelcomeColor);
122 [warm_welcome setTextColor:color];
123 [view addSubview:warm_welcome.get()];
124 }
125
103 NSArray* buttons = [self createButtonsAndAddThemToView:view]; 126 NSArray* buttons = [self createButtonsAndAddThemToView:view];
104 127
105 // Compute the bubble width using the password item. 128 // Compute the bubble width using the password item.
106 const CGFloat contentWidth = 129 const CGFloat contentWidth =
107 kFramePadding + NSWidth([titleView frame]) + titleRightPadding; 130 kFramePadding + NSWidth([titleView frame]) + titleRightPadding;
108 const CGFloat width = std::max(kDesiredBubbleWidth, contentWidth); 131 const CGFloat width = std::max(kDesiredBubbleWidth, contentWidth);
109 132
110 // Layout the elements, starting at the bottom and moving up. 133 // Layout the elements, starting at the bottom and moving up.
111 134
112 // Buttons go on the bottom row and are right-aligned. 135 // Buttons go on the bottom row and are right-aligned.
113 // Start with [Save]. 136 // Start with [Save].
114 CGFloat curX = width - kFramePadding + kRelatedControlHorizontalPadding; 137 CGFloat curX = width - kFramePadding + kRelatedControlHorizontalPadding;
115 CGFloat curY = kFramePadding; 138 CGFloat curY = kFramePadding;
116 139
117 for (NSButton* button in buttons) { 140 for (NSButton* button in buttons) {
118 curX -= kRelatedControlHorizontalPadding + NSWidth([button frame]); 141 curX -= kRelatedControlHorizontalPadding + NSWidth([button frame]);
119 [button setFrameOrigin:NSMakePoint(curX, curY)]; 142 [button setFrameOrigin:NSMakePoint(curX, curY)];
120 } 143 }
121 144
122 curX = kFramePadding; 145 curX = kFramePadding;
123 curY = NSMaxY([buttons.firstObject frame]) + kUnrelatedControlVerticalPadding; 146 curY = NSMaxY([buttons.firstObject frame]) + kUnrelatedControlVerticalPadding;
147 // The Smart Lock warm welcome is placed above after some padding.
148 if (warm_welcome) {
149 [warm_welcome setFrameOrigin:NSMakePoint(curX, curY)];
150 curY = NSMaxY([warm_welcome frame]) + kUnrelatedControlVerticalPadding;
151 }
124 152
125 if (passwordRow) { 153 if (passwordRow) {
126 // Password item goes on the next row. 154 // Password item goes on the next row.
127 [passwordRow setFrameOrigin:NSMakePoint(curX, curY)]; 155 [passwordRow setFrameOrigin:NSMakePoint(curX, curY)];
128 156
129 // Title goes at the top after some padding. 157 // Title goes at the top after some padding.
130 curY = NSMaxY([passwordRow frame]) + kUnrelatedControlVerticalPadding; 158 curY = NSMaxY([passwordRow frame]) + kUnrelatedControlVerticalPadding;
131 } 159 }
132 [titleView setFrameOrigin:NSMakePoint(curX, curY)]; 160 [titleView setFrameOrigin:NSMakePoint(curX, curY)];
133 const CGFloat height = NSMaxY([titleView frame]) + kFramePadding; 161 const CGFloat height = NSMaxY([titleView frame]) + kFramePadding;
(...skipping 18 matching lines...) Expand all
152 180
153 @end 181 @end
154 182
155 @implementation PendingPasswordViewController (Testing) 183 @implementation PendingPasswordViewController (Testing)
156 184
157 - (NSButton*)closeButton { 185 - (NSButton*)closeButton {
158 return closeButton_.get(); 186 return closeButton_.get();
159 } 187 }
160 188
161 @end 189 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698