| OLD | NEW |
| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 constexpr CGFloat kCredentialHeight = | 31 constexpr CGFloat kCredentialHeight = |
| 32 kAvatarImageSize + 2 * kVerticalAvatarMargin; | 32 kAvatarImageSize + 2 * kVerticalAvatarMargin; |
| 33 | 33 |
| 34 // Maximum height of the credential list. The unit is one row height. | 34 // Maximum height of the credential list. The unit is one row height. |
| 35 constexpr CGFloat kMaxHeightAccounts = 3.5; | 35 constexpr CGFloat kMaxHeightAccounts = 3.5; |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 @interface AccountChooserViewController () { | 39 @interface AccountChooserViewController () { |
| 40 NSButton* cancelButton_; // Weak. | 40 NSButton* cancelButton_; // Weak. |
| 41 NSButton* signInButton_; // Weak. |
| 41 NSTextView* titleView_; // Weak. | 42 NSTextView* titleView_; // Weak. |
| 42 base::scoped_nsobject<NSArray> credentialButtons_; | 43 base::scoped_nsobject<NSArray> credentialButtons_; |
| 43 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager_; | 44 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager_; |
| 44 } | 45 } |
| 45 - (void)onCancelClicked:(id)sender; | 46 - (void)onCancelClicked:(id)sender; |
| 46 - (void)onCredentialClicked:(id)sender; | 47 - (void)onCredentialClicked:(id)sender; |
| 48 - (void)onSignInClicked:(id)sender; |
| 47 - (void)loadCredentialItems; | 49 - (void)loadCredentialItems; |
| 48 @end | 50 @end |
| 49 | 51 |
| 50 @implementation AccountChooserViewController | 52 @implementation AccountChooserViewController |
| 51 @synthesize bridge = bridge_; | 53 @synthesize bridge = bridge_; |
| 52 | 54 |
| 53 - (instancetype)initWithBridge:(PasswordPromptBridgeInterface*)bridge { | 55 - (instancetype)initWithBridge:(PasswordPromptBridgeInterface*)bridge { |
| 54 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager( | 56 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager( |
| 55 [[AccountAvatarFetcherManager alloc] | 57 [[AccountAvatarFetcherManager alloc] |
| 56 initWithRequestContext:bridge->GetRequestContext()]); | 58 initWithRequestContext:bridge->GetRequestContext()]); |
| 57 return [self initWithBridge:bridge avatarManager:avatarManager]; | 59 return [self initWithBridge:bridge avatarManager:avatarManager]; |
| 58 } | 60 } |
| 59 | 61 |
| 62 - (NSButton*)defaultButton { |
| 63 return signInButton_; |
| 64 } |
| 65 |
| 60 - (void)loadView { | 66 - (void)loadView { |
| 61 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 67 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
| 62 | 68 |
| 63 // ------------------------------------ | 69 // ------------------------------------ |
| 64 // | | | 70 // | | |
| 65 // | Choose an account etc etc | | 71 // | Choose an account etc etc | |
| 66 // | | | 72 // | | |
| 67 // | ---- | | 73 // | ---- | |
| 68 // | | | credential view | | 74 // | | | credential view | |
| 69 // | ---- | | 75 // | ---- | |
| 70 // | | | credential view | | 76 // | | | credential view | |
| 71 // | ---- | | 77 // | ---- | |
| 72 // | | | 78 // | | |
| 73 // | [ Cancel ] | | 79 // | [ Cancel ] [Sign In] | |
| 74 // ------------------------------------ | 80 // ------------------------------------ |
| 75 | 81 |
| 76 // Create the views. | 82 // Create the views. |
| 77 // Title. | 83 // Title. |
| 84 PasswordDialogController* controller = bridge_->GetDialogController(); |
| 78 std::pair<base::string16, gfx::Range> title_text = | 85 std::pair<base::string16, gfx::Range> title_text = |
| 79 bridge_->GetDialogController()->GetAccoutChooserTitle(); | 86 controller->GetAccoutChooserTitle(); |
| 80 titleView_ = | 87 titleView_ = |
| 81 TitleDialogLabelWithLink(title_text.first, title_text.second, self); | 88 TitleDialogLabelWithLink(title_text.first, title_text.second, self); |
| 82 // Force the text to wrap to fit in the bubble size. | 89 // Force the text to wrap to fit in the bubble size. |
| 83 [titleView_ setVerticallyResizable:YES]; | 90 [titleView_ setVerticallyResizable:YES]; |
| 84 const CGFloat width = kDesiredBubbleWidth - 2*kFramePadding; | 91 const CGFloat width = kDesiredBubbleWidth - 2*kFramePadding; |
| 85 [titleView_ setFrameSize:NSMakeSize(width, MAXFLOAT)]; | 92 [titleView_ setFrameSize:NSMakeSize(width, MAXFLOAT)]; |
| 86 [titleView_ sizeToFit]; | 93 [titleView_ sizeToFit]; |
| 87 [[titleView_ textContainer] setLineFragmentPadding:0]; | 94 [[titleView_ textContainer] setLineFragmentPadding:0]; |
| 88 [view addSubview:titleView_]; | 95 [view addSubview:titleView_]; |
| 89 | 96 |
| 90 // Credentials list. | 97 // Credentials list. |
| 91 [self loadCredentialItems]; | 98 [self loadCredentialItems]; |
| 92 | 99 |
| 93 // "Cancel" button. | 100 // "Cancel" button. |
| 94 cancelButton_ = DialogButton(l10n_util::GetNSString(IDS_APP_CANCEL)); | 101 cancelButton_ = BiggerDialogButton(l10n_util::GetNSString(IDS_APP_CANCEL)); |
| 95 [cancelButton_ setTarget:self]; | 102 [cancelButton_ setTarget:self]; |
| 96 [cancelButton_ setAction:@selector(onCancelClicked:)]; | 103 [cancelButton_ setAction:@selector(onCancelClicked:)]; |
| 97 [cancelButton_ setKeyEquivalent:kKeyEquivalentEscape]; | 104 [cancelButton_ setKeyEquivalent:kKeyEquivalentEscape]; |
| 98 [view addSubview:cancelButton_]; | 105 [view addSubview:cancelButton_]; |
| 99 | 106 |
| 107 // "Sign In" button. |
| 108 if (controller->ShouldShowSignInButton()) { |
| 109 signInButton_ = BiggerDialogButton( |
| 110 l10n_util::GetNSString(IDS_PASSWORD_MANAGER_ACCOUNT_CHOOSER_SIGN_IN)); |
| 111 [signInButton_ setTarget:self]; |
| 112 [signInButton_ setAction:@selector(onSignInClicked:)]; |
| 113 [signInButton_ setKeyEquivalent:kKeyEquivalentReturn]; |
| 114 [view addSubview:signInButton_]; |
| 115 } |
| 116 |
| 100 // Lay out the views. | 117 // Lay out the views. |
| 118 CGFloat curX = kFramePadding + width; |
| 119 if (signInButton_) { |
| 120 curX -= NSWidth([signInButton_ frame]); |
| 121 [signInButton_ setFrameOrigin:NSMakePoint(curX, kFramePadding)]; |
| 122 } |
| 101 [cancelButton_ setFrameOrigin:NSMakePoint( | 123 [cancelButton_ setFrameOrigin:NSMakePoint( |
| 102 kFramePadding + width - NSWidth([cancelButton_ frame]), | 124 curX - NSWidth([cancelButton_ frame]), |
| 103 kFramePadding)]; | 125 kFramePadding)]; |
| 104 | 126 |
| 105 NSSize buttonsSize = NSMakeSize( | 127 NSSize buttonsSize = NSMakeSize( |
| 106 kDesiredBubbleWidth, | 128 kDesiredBubbleWidth, |
| 107 std::min<CGFloat>([credentialButtons_ count], kMaxHeightAccounts) * | 129 std::min<CGFloat>([credentialButtons_ count], kMaxHeightAccounts) * |
| 108 kCredentialHeight); | 130 kCredentialHeight); |
| 109 base::scoped_nsobject<NSScrollView> scrollView = [[NSScrollView alloc] | 131 base::scoped_nsobject<NSScrollView> scrollView = [[NSScrollView alloc] |
| 110 initWithFrame:NSMakeRect(0, 0, buttonsSize.width, buttonsSize.height)]; | 132 initWithFrame:NSMakeRect(0, 0, buttonsSize.width, buttonsSize.height)]; |
| 111 [scrollView | 133 [scrollView |
| 112 setHasVerticalScroller:[credentialButtons_ count] > kMaxHeightAccounts | 134 setHasVerticalScroller:[credentialButtons_ count] > kMaxHeightAccounts |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 174 |
| 153 - (void)onCredentialClicked:(id)sender { | 175 - (void)onCredentialClicked:(id)sender { |
| 154 CredentialItemButton* button = | 176 CredentialItemButton* button = |
| 155 base::mac::ObjCCastStrict<CredentialItemButton>(sender); | 177 base::mac::ObjCCastStrict<CredentialItemButton>(sender); |
| 156 if (bridge_ && bridge_->GetDialogController()) { | 178 if (bridge_ && bridge_->GetDialogController()) { |
| 157 bridge_->GetDialogController()->OnChooseCredentials(*button.passwordForm, | 179 bridge_->GetDialogController()->OnChooseCredentials(*button.passwordForm, |
| 158 button.credentialType); | 180 button.credentialType); |
| 159 } | 181 } |
| 160 } | 182 } |
| 161 | 183 |
| 184 - (void)onSignInClicked:(id)sender { |
| 185 if (bridge_ && bridge_->GetDialogController()) |
| 186 bridge_->GetDialogController()->OnSignInClicked(); |
| 187 } |
| 188 |
| 162 - (void)loadCredentialItems { | 189 - (void)loadCredentialItems { |
| 163 base::scoped_nsobject<NSMutableArray> items([[NSMutableArray alloc] init]); | 190 base::scoped_nsobject<NSMutableArray> items([[NSMutableArray alloc] init]); |
| 164 PasswordDialogController* controller = self.bridge->GetDialogController(); | 191 PasswordDialogController* controller = self.bridge->GetDialogController(); |
| 165 NSRect rect = NSMakeRect(0, 0, kDesiredBubbleWidth, kCredentialHeight); | 192 NSRect rect = NSMakeRect(0, 0, kDesiredBubbleWidth, kCredentialHeight); |
| 166 for (const auto& form : controller->GetLocalForms()) { | 193 for (const auto& form : controller->GetLocalForms()) { |
| 167 base::scoped_nsobject<CredentialItemButton> item( | 194 base::scoped_nsobject<CredentialItemButton> item( |
| 168 [[CredentialItemButton alloc] | 195 [[CredentialItemButton alloc] |
| 169 initWithFrame:rect | 196 initWithFrame:rect |
| 170 backgroundColor:[NSColor textBackgroundColor] | 197 backgroundColor:[NSColor textBackgroundColor] |
| 171 hoverColor:skia::SkColorToSRGBNSColor(kButtonHoverColor)]); | 198 hoverColor:skia::SkColorToSRGBNSColor(kButtonHoverColor)]); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 bridge_ = bridge; | 245 bridge_ = bridge; |
| 219 avatarManager_.reset([avatarManager retain]); | 246 avatarManager_.reset([avatarManager retain]); |
| 220 } | 247 } |
| 221 return self; | 248 return self; |
| 222 } | 249 } |
| 223 | 250 |
| 224 - (NSButton*)cancelButton { | 251 - (NSButton*)cancelButton { |
| 225 return cancelButton_; | 252 return cancelButton_; |
| 226 } | 253 } |
| 227 | 254 |
| 255 - (NSButton*)signInButton { |
| 256 return signInButton_; |
| 257 } |
| 258 |
| 228 - (NSArray*)credentialButtons { | 259 - (NSArray*)credentialButtons { |
| 229 return credentialButtons_; | 260 return credentialButtons_; |
| 230 } | 261 } |
| 231 | 262 |
| 232 - (NSTextView*)titleView { | 263 - (NSTextView*)titleView { |
| 233 return titleView_; | 264 return titleView_; |
| 234 } | 265 } |
| 235 | 266 |
| 236 @end | 267 @end |
| OLD | NEW |