| 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" |
| 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 "chrome/grit/theme_resources.h" | 19 #include "chrome/grit/theme_resources.h" |
| 20 #include "components/autofill/core/common/password_form.h" | 20 #include "components/autofill/core/common/password_form.h" |
| 21 #include "components/password_manager/core/common/credential_manager_types.h" | 21 #include "components/password_manager/core/common/credential_manager_types.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/gfx/color_palette.h" |
| 27 #include "ui/gfx/image/image_skia_util_mac.h" |
| 28 #include "ui/gfx/paint_vector_icon.h" |
| 29 #include "ui/gfx/vector_icons_public.h" |
| 26 #include "ui/strings/grit/ui_strings.h" | 30 #include "ui/strings/grit/ui_strings.h" |
| 27 | 31 |
| 28 namespace { | 32 namespace { |
| 29 | 33 |
| 30 // Standard height of one credential item. It can be bigger though in case the | 34 // Standard height of one credential item. It can be bigger though in case the |
| 31 // text needs more vertical space than the avatar. | 35 // text needs more vertical space than the avatar. |
| 32 constexpr CGFloat kCredentialHeight = | 36 constexpr CGFloat kCredentialHeight = |
| 33 kAvatarImageSize + 2 * kVerticalAvatarMargin; | 37 kAvatarImageSize + 2 * kVerticalAvatarMargin; |
| 34 | 38 |
| 35 // Maximum height of the credential list. The unit is one row height. | 39 // Maximum height of the credential list. The unit is one row height. |
| 36 constexpr CGFloat kMaxHeightAccounts = 3.5; | 40 constexpr CGFloat kMaxHeightAccounts = 3.5; |
| 37 | 41 |
| 42 NSImageView* IconForPSL(const NSRect& parentRect, const std::string& tooltip) { |
| 43 NSImage* image = gfx::NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 44 gfx::VectorIconId::INFO_OUTLINE, gfx::kChromeIconGrey)); |
| 45 NSRect rect = NSMakeRect( |
| 46 base::i18n::IsRTL() ? kFramePadding |
| 47 : NSMaxX(parentRect) - kInfoIconSize - kFramePadding, |
| 48 NSMinY(parentRect) + (NSHeight(parentRect) - kInfoIconSize) / 2, |
| 49 kInfoIconSize, kInfoIconSize); |
| 50 base::scoped_nsobject<NSImageView> icon( |
| 51 [[NSImageView alloc] initWithFrame:rect]); |
| 52 [icon setImage:image]; |
| 53 [icon setToolTip:base::SysUTF8ToNSString(tooltip)]; |
| 54 return icon.autorelease(); |
| 55 } |
| 56 |
| 38 } // namespace | 57 } // namespace |
| 39 | 58 |
| 40 @interface AccountChooserViewController () { | 59 @interface AccountChooserViewController () { |
| 41 NSButton* cancelButton_; // Weak. | 60 NSButton* cancelButton_; // Weak. |
| 42 NSButton* signInButton_; // Weak. | 61 NSButton* signInButton_; // Weak. |
| 43 NSTextView* titleView_; // Weak. | 62 NSTextView* titleView_; // Weak. |
| 44 base::scoped_nsobject<NSArray> credentialButtons_; | 63 base::scoped_nsobject<NSArray> credentialButtons_; |
| 45 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager_; | 64 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager_; |
| 46 } | 65 } |
| 47 - (void)onCancelClicked:(id)sender; | 66 - (void)onCancelClicked:(id)sender; |
| 48 - (void)onCredentialClicked:(id)sender; | 67 - (void)onCredentialClicked:(id)sender; |
| 49 - (void)onSignInClicked:(id)sender; | 68 - (void)onSignInClicked:(id)sender; |
| 50 - (void)loadCredentialItems; | 69 - (void)loadCredentialItems; |
| 51 @end | 70 @end |
| 52 | 71 |
| 53 @implementation AccountChooserViewController | 72 @implementation AccountChooserViewController |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 [scrollView setBorderType:NSNoBorder]; | 153 [scrollView setBorderType:NSNoBorder]; |
| 135 const CGFloat buttonWidth = [scrollView contentSize].width; | 154 const CGFloat buttonWidth = [scrollView contentSize].width; |
| 136 CGFloat curY = 0; | 155 CGFloat curY = 0; |
| 137 base::scoped_nsobject<NSView> documentView([[NSView alloc] | 156 base::scoped_nsobject<NSView> documentView([[NSView alloc] |
| 138 initWithFrame:NSZeroRect]); | 157 initWithFrame:NSZeroRect]); |
| 139 for (CredentialItemButton* button in credentialButtons_.get()) { | 158 for (CredentialItemButton* button in credentialButtons_.get()) { |
| 140 [documentView addSubview:button]; | 159 [documentView addSubview:button]; |
| 141 CGFloat cellHeight = [[button cell] cellSize].height; | 160 CGFloat cellHeight = [[button cell] cellSize].height; |
| 142 [button setFrame:NSMakeRect(0, curY, buttonWidth, | 161 [button setFrame:NSMakeRect(0, curY, buttonWidth, |
| 143 cellHeight + 2 * kVerticalAvatarMargin)]; | 162 cellHeight + 2 * kVerticalAvatarMargin)]; |
| 163 if (button.passwordForm->is_public_suffix_match) { |
| 164 NSImageView* icon = IconForPSL( |
| 165 [button frame], button.passwordForm->origin.GetOrigin().spec()); |
| 166 [documentView addSubview:icon]; |
| 167 } |
| 144 curY = NSMaxY([button frame]); | 168 curY = NSMaxY([button frame]); |
| 145 } | 169 } |
| 146 [documentView setFrameSize:NSMakeSize(buttonWidth, curY)]; | 170 [documentView setFrameSize:NSMakeSize(buttonWidth, curY)]; |
| 147 [scrollView setDocumentView:documentView]; | 171 [scrollView setDocumentView:documentView]; |
| 148 [scrollView setFrameSize:NSMakeSize( | 172 [scrollView setFrameSize:NSMakeSize( |
| 149 kDesiredBubbleWidth, | 173 kDesiredBubbleWidth, |
| 150 [scrollView hasVerticalScroller] ? kMaxHeightAccounts * kCredentialHeight | 174 [scrollView hasVerticalScroller] ? kMaxHeightAccounts * kCredentialHeight |
| 151 : curY)]; | 175 : curY)]; |
| 152 [view addSubview:scrollView]; | 176 [view addSubview:scrollView]; |
| 153 [documentView scrollRectToVisible:NSMakeRect(0, curY, buttonWidth, 0)]; | 177 [documentView scrollRectToVisible:NSMakeRect(0, curY, buttonWidth, 0)]; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 284 |
| 261 - (NSArray*)credentialButtons { | 285 - (NSArray*)credentialButtons { |
| 262 return credentialButtons_; | 286 return credentialButtons_; |
| 263 } | 287 } |
| 264 | 288 |
| 265 - (NSTextView*)titleView { | 289 - (NSTextView*)titleView { |
| 266 return titleView_; | 290 return titleView_; |
| 267 } | 291 } |
| 268 | 292 |
| 269 @end | 293 @end |
| OLD | NEW |