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

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

Issue 2259533006: Tune the account chooser on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 4 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 | « no previous file | chrome/browser/ui/cocoa/passwords/credential_item_button.mm » ('j') | 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 "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h" 5 #import "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" 11 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h"
12 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h" 12 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h"
13 #import "chrome/browser/ui/cocoa/passwords/credential_item_button.h" 13 #import "chrome/browser/ui/cocoa/passwords/credential_item_button.h"
14 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" 14 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h"
15 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" 15 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
16 #include "chrome/browser/ui/passwords/password_dialog_controller.h" 16 #include "chrome/browser/ui/passwords/password_dialog_controller.h"
17 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" 17 #include "chrome/browser/ui/passwords/password_dialog_prompts.h"
18 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
19 #include "components/autofill/core/common/password_form.h" 19 #include "components/autofill/core/common/password_form.h"
20 #include "components/password_manager/core/common/credential_manager_types.h" 20 #include "components/password_manager/core/common/credential_manager_types.h"
21 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
22 #include "skia/ext/skia_utils_mac.h" 22 #include "skia/ext/skia_utils_mac.h"
23 #include "ui/base/cocoa/controls/hyperlink_text_view.h" 23 #include "ui/base/cocoa/controls/hyperlink_text_view.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/strings/grit/ui_strings.h" 26 #include "ui/strings/grit/ui_strings.h"
27 27
28 namespace { 28 namespace {
29 29
30 // Returns height of one credential item. 30 // Standard height of one credential item. It can be bigger though in case the
31 // text needs more vertical space than the avatar.
31 constexpr CGFloat kCredentialHeight = 32 constexpr CGFloat kCredentialHeight =
32 kAvatarImageSize + 2 * kVerticalAvatarMargin; 33 kAvatarImageSize + 2 * kVerticalAvatarMargin;
33 34
34 // Maximum height of the credential list. The unit is one row height. 35 // Maximum height of the credential list. The unit is one row height.
35 constexpr CGFloat kMaxHeightAccounts = 3.5; 36 constexpr CGFloat kMaxHeightAccounts = 3.5;
36 37
37 } // namespace 38 } // namespace
38 39
39 @interface AccountChooserViewController () { 40 @interface AccountChooserViewController () {
40 NSButton* cancelButton_; // Weak. 41 NSButton* cancelButton_; // Weak.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // Lay out the views. 118 // Lay out the views.
118 CGFloat curX = kFramePadding + width; 119 CGFloat curX = kFramePadding + width;
119 if (signInButton_) { 120 if (signInButton_) {
120 curX -= NSWidth([signInButton_ frame]); 121 curX -= NSWidth([signInButton_ frame]);
121 [signInButton_ setFrameOrigin:NSMakePoint(curX, kFramePadding)]; 122 [signInButton_ setFrameOrigin:NSMakePoint(curX, kFramePadding)];
122 } 123 }
123 [cancelButton_ setFrameOrigin:NSMakePoint( 124 [cancelButton_ setFrameOrigin:NSMakePoint(
124 curX - NSWidth([cancelButton_ frame]), 125 curX - NSWidth([cancelButton_ frame]),
125 kFramePadding)]; 126 kFramePadding)];
126 127
127 NSSize buttonsSize = NSMakeSize(
128 kDesiredBubbleWidth,
129 std::min<CGFloat>([credentialButtons_ count], kMaxHeightAccounts) *
130 kCredentialHeight);
131 base::scoped_nsobject<NSScrollView> scrollView([[NSScrollView alloc] 128 base::scoped_nsobject<NSScrollView> scrollView([[NSScrollView alloc]
132 initWithFrame:NSMakeRect(0, 0, buttonsSize.width, buttonsSize.height)]); 129 initWithFrame:NSMakeRect(0, 0, kDesiredBubbleWidth, kCredentialHeight)]);
133 [scrollView 130 [scrollView
134 setHasVerticalScroller:[credentialButtons_ count] > kMaxHeightAccounts 131 setHasVerticalScroller:[credentialButtons_ count] > kMaxHeightAccounts
135 ? YES 132 ? YES
136 : NO]; 133 : NO];
137 [scrollView setBorderType:NSNoBorder]; 134 [scrollView setBorderType:NSNoBorder];
138 CGFloat buttonWidth = [scrollView contentSize].width; 135 const CGFloat buttonWidth = [scrollView contentSize].width;
139 CGFloat curY = 0; 136 CGFloat curY = 0;
140 base::scoped_nsobject<NSView> documentView([[NSView alloc] 137 base::scoped_nsobject<NSView> documentView([[NSView alloc]
141 initWithFrame:NSMakeRect(0, 0, buttonWidth, [credentialButtons_ count] * 138 initWithFrame:NSZeroRect]);
142 kCredentialHeight)]);
143 for (CredentialItemButton* button in credentialButtons_.get()) { 139 for (CredentialItemButton* button in credentialButtons_.get()) {
144 [documentView addSubview:button]; 140 [documentView addSubview:button];
145 [button setFrame:NSMakeRect(0, curY, buttonWidth, kCredentialHeight)]; 141 CGFloat cellHeight = [[button cell] cellSize].height;
142 [button setFrame:NSMakeRect(0, curY, buttonWidth,
143 cellHeight + 2 * kVerticalAvatarMargin)];
146 curY = NSMaxY([button frame]); 144 curY = NSMaxY([button frame]);
147 } 145 }
146 [documentView setFrameSize:NSMakeSize(buttonWidth, curY)];
148 [scrollView setDocumentView:documentView]; 147 [scrollView setDocumentView:documentView];
148 [scrollView setFrameSize:NSMakeSize(
149 kDesiredBubbleWidth,
150 [scrollView hasVerticalScroller] ? kMaxHeightAccounts * kCredentialHeight
151 : curY)];
149 [view addSubview:scrollView]; 152 [view addSubview:scrollView];
150 [documentView scrollRectToVisible:NSMakeRect(0, curY, buttonWidth, 0)]; 153 [documentView scrollRectToVisible:NSMakeRect(0, curY, buttonWidth, 0)];
151 curY = NSMaxY([cancelButton_ frame]) + 3 * kRelatedControlVerticalSpacing; 154 curY = NSMaxY([cancelButton_ frame]) + 3 * kRelatedControlVerticalSpacing;
152 [scrollView setFrameOrigin:NSMakePoint(0, curY)]; 155 [scrollView setFrameOrigin:NSMakePoint(0, curY)];
153 curY = NSMaxY([scrollView frame]) + 2 * kRelatedControlVerticalSpacing; 156 curY = NSMaxY([scrollView frame]) + 2 * kRelatedControlVerticalSpacing;
154 157
155 [titleView_ setFrameOrigin:NSMakePoint(kFramePadding, curY)]; 158 [titleView_ setFrameOrigin:NSMakePoint(kFramePadding, curY)];
156 159
157 const CGFloat frameHeight = NSMaxY([titleView_ frame]) + kFramePadding; 160 const CGFloat frameHeight = NSMaxY([titleView_ frame]) + kFramePadding;
158 [view setFrame:NSMakeRect(0, 0, kDesiredBubbleWidth, frameHeight)]; 161 [view setFrame:NSMakeRect(0, 0, kDesiredBubbleWidth, frameHeight)];
(...skipping 23 matching lines...) Expand all
182 } 185 }
183 186
184 - (void)onSignInClicked:(id)sender { 187 - (void)onSignInClicked:(id)sender {
185 if (bridge_ && bridge_->GetDialogController()) 188 if (bridge_ && bridge_->GetDialogController())
186 bridge_->GetDialogController()->OnSignInClicked(); 189 bridge_->GetDialogController()->OnSignInClicked();
187 } 190 }
188 191
189 - (void)loadCredentialItems { 192 - (void)loadCredentialItems {
190 base::scoped_nsobject<NSMutableArray> items([[NSMutableArray alloc] init]); 193 base::scoped_nsobject<NSMutableArray> items([[NSMutableArray alloc] init]);
191 PasswordDialogController* controller = self.bridge->GetDialogController(); 194 PasswordDialogController* controller = self.bridge->GetDialogController();
192 NSRect rect = NSMakeRect(0, 0, kDesiredBubbleWidth, kCredentialHeight);
193 for (const auto& form : controller->GetLocalForms()) { 195 for (const auto& form : controller->GetLocalForms()) {
194 base::scoped_nsobject<CredentialItemButton> item( 196 base::scoped_nsobject<CredentialItemButton> item(
195 [[CredentialItemButton alloc] 197 [[CredentialItemButton alloc]
196 initWithFrame:rect 198 initWithFrame:NSZeroRect
197 backgroundColor:[NSColor textBackgroundColor] 199 backgroundColor:[NSColor textBackgroundColor]
198 hoverColor:skia::SkColorToSRGBNSColor(kButtonHoverColor)]); 200 hoverColor:skia::SkColorToSRGBNSColor(kButtonHoverColor)]);
199 [item setPasswordForm:form.get()]; 201 [item setPasswordForm:form.get()];
200 [item setCredentialType:password_manager::CredentialType:: 202 [item setCredentialType:password_manager::CredentialType::
201 CREDENTIAL_TYPE_PASSWORD]; 203 CREDENTIAL_TYPE_PASSWORD];
202 std::pair<base::string16, base::string16> labels = 204 std::pair<base::string16, base::string16> labels =
203 GetCredentialLabelsForAccountChooser(*form); 205 GetCredentialLabelsForAccountChooser(*form);
204 if (labels.second.empty()) { 206 if (labels.second.empty()) {
205 [item setTitle:base::SysUTF16ToNSString(labels.first)]; 207 [item setTitle:base::SysUTF16ToNSString(labels.first)];
206 } else { 208 } else {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 260
259 - (NSArray*)credentialButtons { 261 - (NSArray*)credentialButtons {
260 return credentialButtons_; 262 return credentialButtons_;
261 } 263 }
262 264
263 - (NSTextView*)titleView { 265 - (NSTextView*)titleView {
264 return titleView_; 266 return titleView_;
265 } 267 }
266 268
267 @end 269 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/passwords/credential_item_button.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698