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

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

Issue 1922133002: Change 'const' -> 'constexpr' in cocoa/passwords. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/account_chooser_view_controller_unittest.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/passwords/account_avatar_fetcher_manager.h" 11 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h"
12 #import "chrome/browser/ui/cocoa/passwords/credential_item_button.h" 12 #import "chrome/browser/ui/cocoa/passwords/credential_item_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_view_utils.h" 14 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
15 #include "chrome/browser/ui/passwords/password_dialog_controller.h" 15 #include "chrome/browser/ui/passwords/password_dialog_controller.h"
16 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" 16 #include "chrome/browser/ui/passwords/password_dialog_prompts.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "components/autofill/core/common/password_form.h" 18 #include "components/autofill/core/common/password_form.h"
19 #include "components/password_manager/core/common/credential_manager_types.h" 19 #include "components/password_manager/core/common/credential_manager_types.h"
20 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
21 #include "skia/ext/skia_utils_mac.h" 21 #include "skia/ext/skia_utils_mac.h"
22 #include "ui/base/cocoa/controls/hyperlink_text_view.h" 22 #include "ui/base/cocoa/controls/hyperlink_text_view.h"
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/strings/grit/ui_strings.h" 25 #include "ui/strings/grit/ui_strings.h"
26 26
27 namespace { 27 namespace {
28 28
29 // Returns height of one credential item.
30 constexpr CGFloat kCredentialHeight =
31 kAvatarImageSize + 2 * kVerticalAvatarMargin;
32
29 // Maximum number of accounts displayed before vertical scrolling appears. 33 // Maximum number of accounts displayed before vertical scrolling appears.
30 const size_t kMaxAccounts = 3; 34 constexpr size_t kMaxAccounts = 3;
31
32 // Returns height of one credential item.
33 CGFloat CredentialHeight() {
34 return kAvatarImageSize + 2 * kVerticalAvatarMargin;
35 }
36 35
37 } // namespace 36 } // namespace
38 37
39 @interface AccountChooserViewController () { 38 @interface AccountChooserViewController () {
40 NSButton* cancelButton_; // Weak. 39 NSButton* cancelButton_; // Weak.
41 NSTextView* titleView_; // Weak. 40 NSTextView* titleView_; // Weak.
42 base::scoped_nsobject<NSArray> credentialButtons_; 41 base::scoped_nsobject<NSArray> credentialButtons_;
43 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager_; 42 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager_;
44 } 43 }
45 - (void)onCancelClicked:(id)sender; 44 - (void)onCancelClicked:(id)sender;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 [cancelButton_ setAction:@selector(onCancelClicked:)]; 95 [cancelButton_ setAction:@selector(onCancelClicked:)];
97 [view addSubview:cancelButton_]; 96 [view addSubview:cancelButton_];
98 97
99 // Lay out the views. 98 // Lay out the views.
100 [cancelButton_ setFrameOrigin:NSMakePoint( 99 [cancelButton_ setFrameOrigin:NSMakePoint(
101 kFramePadding + width - NSWidth([cancelButton_ frame]), 100 kFramePadding + width - NSWidth([cancelButton_ frame]),
102 kFramePadding)]; 101 kFramePadding)];
103 102
104 NSSize buttonsSize = NSMakeSize( 103 NSSize buttonsSize = NSMakeSize(
105 kDesiredBubbleWidth, 104 kDesiredBubbleWidth,
106 std::min([credentialButtons_ count], kMaxAccounts) * CredentialHeight()); 105 std::min([credentialButtons_ count], kMaxAccounts) * kCredentialHeight);
107 base::scoped_nsobject<NSScrollView> scrollView = [[NSScrollView alloc] 106 base::scoped_nsobject<NSScrollView> scrollView = [[NSScrollView alloc]
108 initWithFrame:NSMakeRect(0, 0, buttonsSize.width, buttonsSize.height)]; 107 initWithFrame:NSMakeRect(0, 0, buttonsSize.width, buttonsSize.height)];
109 [scrollView setHasVerticalScroller:[credentialButtons_ count] > kMaxAccounts 108 [scrollView setHasVerticalScroller:[credentialButtons_ count] > kMaxAccounts
110 ? YES 109 ? YES
111 : NO]; 110 : NO];
112 [scrollView setBorderType:NSNoBorder]; 111 [scrollView setBorderType:NSNoBorder];
113 CGFloat buttonWidth = [scrollView contentSize].width; 112 CGFloat buttonWidth = [scrollView contentSize].width;
114 CGFloat curY = 0; 113 CGFloat curY = 0;
115 base::scoped_nsobject<NSView> documentView([[NSView alloc] 114 base::scoped_nsobject<NSView> documentView([[NSView alloc]
116 initWithFrame:NSMakeRect(0, 0, buttonWidth, [credentialButtons_ count] * 115 initWithFrame:NSMakeRect(0, 0, buttonWidth, [credentialButtons_ count] *
117 CredentialHeight())]); 116 kCredentialHeight)]);
118 for (CredentialItemButton* button in credentialButtons_.get()) { 117 for (CredentialItemButton* button in credentialButtons_.get()) {
119 [documentView addSubview:button]; 118 [documentView addSubview:button];
120 [button setFrame:NSMakeRect(0, curY, buttonWidth, CredentialHeight())]; 119 [button setFrame:NSMakeRect(0, curY, buttonWidth, kCredentialHeight)];
121 curY = NSMaxY([button frame]); 120 curY = NSMaxY([button frame]);
122 } 121 }
123 [scrollView setDocumentView:documentView]; 122 [scrollView setDocumentView:documentView];
124 [view addSubview:scrollView]; 123 [view addSubview:scrollView];
125 [documentView scrollRectToVisible:NSMakeRect(0, curY, buttonWidth, 0)]; 124 [documentView scrollRectToVisible:NSMakeRect(0, curY, buttonWidth, 0)];
126 curY = NSMaxY([cancelButton_ frame]) + 3 * kRelatedControlVerticalSpacing; 125 curY = NSMaxY([cancelButton_ frame]) + 3 * kRelatedControlVerticalSpacing;
127 [scrollView setFrameOrigin:NSMakePoint(0, curY)]; 126 [scrollView setFrameOrigin:NSMakePoint(0, curY)];
128 curY = NSMaxY([scrollView frame]) + 2 * kRelatedControlVerticalSpacing; 127 curY = NSMaxY([scrollView frame]) + 2 * kRelatedControlVerticalSpacing;
129 128
130 [titleView_ setFrameOrigin:NSMakePoint(kFramePadding, curY)]; 129 [titleView_ setFrameOrigin:NSMakePoint(kFramePadding, curY)];
(...skipping 21 matching lines...) Expand all
152 base::mac::ObjCCastStrict<CredentialItemButton>(sender); 151 base::mac::ObjCCastStrict<CredentialItemButton>(sender);
153 if (bridge_ && bridge_->GetDialogController()) { 152 if (bridge_ && bridge_->GetDialogController()) {
154 bridge_->GetDialogController()->OnChooseCredentials(*button.passwordForm, 153 bridge_->GetDialogController()->OnChooseCredentials(*button.passwordForm,
155 button.credentialType); 154 button.credentialType);
156 } 155 }
157 } 156 }
158 157
159 - (void)loadCredentialItems { 158 - (void)loadCredentialItems {
160 base::scoped_nsobject<NSMutableArray> items([[NSMutableArray alloc] init]); 159 base::scoped_nsobject<NSMutableArray> items([[NSMutableArray alloc] init]);
161 PasswordDialogController* controller = self.bridge->GetDialogController(); 160 PasswordDialogController* controller = self.bridge->GetDialogController();
162 NSRect rect = NSMakeRect(0, 0, kDesiredBubbleWidth, CredentialHeight()); 161 NSRect rect = NSMakeRect(0, 0, kDesiredBubbleWidth, kCredentialHeight);
163 for (const auto& form : controller->GetLocalForms()) { 162 for (const auto& form : controller->GetLocalForms()) {
164 base::scoped_nsobject<CredentialItemButton> item( 163 base::scoped_nsobject<CredentialItemButton> item(
165 [[CredentialItemButton alloc] 164 [[CredentialItemButton alloc]
166 initWithFrame:rect 165 initWithFrame:rect
167 backgroundColor:[NSColor textBackgroundColor] 166 backgroundColor:[NSColor textBackgroundColor]
168 hoverColor:skia::SkColorToSRGBNSColor(kButtonHoverColor)]); 167 hoverColor:skia::SkColorToSRGBNSColor(kButtonHoverColor)]);
169 [item setPasswordForm:form.get()]; 168 [item setPasswordForm:form.get()];
170 [item setCredentialType:password_manager::CredentialType:: 169 [item setCredentialType:password_manager::CredentialType::
171 CREDENTIAL_TYPE_PASSWORD]; 170 CREDENTIAL_TYPE_PASSWORD];
172 std::pair<base::string16, base::string16> labels = 171 std::pair<base::string16, base::string16> labels =
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 223
225 - (NSArray*)credentialButtons { 224 - (NSArray*)credentialButtons {
226 return credentialButtons_; 225 return credentialButtons_;
227 } 226 }
228 227
229 - (NSTextView*)titleView { 228 - (NSTextView*)titleView {
230 return titleView_; 229 return titleView_;
231 } 230 }
232 231
233 @end 232 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/passwords/account_chooser_view_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698