| 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" | |
| 30 #include "ui/strings/grit/ui_strings.h" | 26 #include "ui/strings/grit/ui_strings.h" |
| 31 | 27 |
| 32 namespace { | 28 namespace { |
| 33 | 29 |
| 34 // Standard height of one credential item. It can be bigger though in case the | 30 // Standard height of one credential item. It can be bigger though in case the |
| 35 // text needs more vertical space than the avatar. | 31 // text needs more vertical space than the avatar. |
| 36 constexpr CGFloat kCredentialHeight = | 32 constexpr CGFloat kCredentialHeight = |
| 37 kAvatarImageSize + 2 * kVerticalAvatarMargin; | 33 kAvatarImageSize + 2 * kVerticalAvatarMargin; |
| 38 | 34 |
| 39 // 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. |
| 40 constexpr CGFloat kMaxHeightAccounts = 3.5; | 36 constexpr CGFloat kMaxHeightAccounts = 3.5; |
| 41 | 37 |
| 42 } // namespace | 38 } // namespace |
| 43 | 39 |
| 44 // An image view that consumes the mouse click. | |
| 45 @interface InfoImageView : NSImageView | |
| 46 @end | |
| 47 | |
| 48 @implementation InfoImageView | |
| 49 - (void)mouseDown:(NSEvent*)theEvent { | |
| 50 if (theEvent.type != NSLeftMouseDown) { | |
| 51 [super mouseDown:theEvent]; | |
| 52 } | |
| 53 } | |
| 54 @end | |
| 55 | |
| 56 namespace { | |
| 57 | |
| 58 NSImageView* IconForPSL(const NSRect& parentRect, const std::string& tooltip) { | |
| 59 NSImage* image = gfx::NSImageFromImageSkia(gfx::CreateVectorIcon( | |
| 60 gfx::VectorIconId::INFO_OUTLINE, gfx::kChromeIconGrey)); | |
| 61 NSRect rect = NSMakeRect( | |
| 62 base::i18n::IsRTL() ? kFramePadding | |
| 63 : NSMaxX(parentRect) - kInfoIconSize - kFramePadding, | |
| 64 NSMinY(parentRect) + (NSHeight(parentRect) - kInfoIconSize) / 2, | |
| 65 kInfoIconSize, kInfoIconSize); | |
| 66 base::scoped_nsobject<NSImageView> icon( | |
| 67 [[InfoImageView alloc] initWithFrame:rect]); | |
| 68 [icon setImage:image]; | |
| 69 [icon setToolTip:base::SysUTF8ToNSString(tooltip)]; | |
| 70 return icon.autorelease(); | |
| 71 } | |
| 72 | |
| 73 } // namespace | |
| 74 | |
| 75 @interface AccountChooserViewController () { | 40 @interface AccountChooserViewController () { |
| 76 NSButton* cancelButton_; // Weak. | 41 NSButton* cancelButton_; // Weak. |
| 77 NSButton* signInButton_; // Weak. | 42 NSButton* signInButton_; // Weak. |
| 78 NSTextView* titleView_; // Weak. | 43 NSTextView* titleView_; // Weak. |
| 79 base::scoped_nsobject<NSArray> credentialButtons_; | 44 base::scoped_nsobject<NSArray> credentialButtons_; |
| 80 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager_; | 45 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager_; |
| 81 } | 46 } |
| 82 - (void)onCancelClicked:(id)sender; | 47 - (void)onCancelClicked:(id)sender; |
| 83 - (void)onCredentialClicked:(id)sender; | 48 - (void)onCredentialClicked:(id)sender; |
| 84 - (void)onSignInClicked:(id)sender; | 49 - (void)onSignInClicked:(id)sender; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 100 } | 65 } |
| 101 | 66 |
| 102 - (void)loadView { | 67 - (void)loadView { |
| 103 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 68 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
| 104 | 69 |
| 105 // ------------------------------------ | 70 // ------------------------------------ |
| 106 // | | | 71 // | | |
| 107 // | Choose an account etc etc | | 72 // | Choose an account etc etc | |
| 108 // | | | 73 // | | |
| 109 // | ---- | | 74 // | ---- | |
| 110 // | | | credential view | | 75 // | | | credential view (i) | |
| 111 // | ---- | | 76 // | ---- | |
| 112 // | | | credential view | | 77 // | | | credential view (i) | |
| 113 // | ---- | | 78 // | ---- | |
| 114 // | | | 79 // | | |
| 115 // | [ Cancel ] [Sign In] | | 80 // | [ Cancel ] [Sign In] | |
| 116 // ------------------------------------ | 81 // ------------------------------------ |
| 117 | 82 |
| 118 // Create the views. | 83 // Create the views. |
| 119 // Title. | 84 // Title. |
| 120 PasswordDialogController* controller = bridge_->GetDialogController(); | 85 PasswordDialogController* controller = bridge_->GetDialogController(); |
| 121 std::pair<base::string16, gfx::Range> title_text = | 86 std::pair<base::string16, gfx::Range> title_text = |
| 122 controller->GetAccoutChooserTitle(); | 87 controller->GetAccoutChooserTitle(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 const CGFloat buttonWidth = [scrollView contentSize].width; | 135 const CGFloat buttonWidth = [scrollView contentSize].width; |
| 171 CGFloat curY = 0; | 136 CGFloat curY = 0; |
| 172 base::scoped_nsobject<NSView> documentView([[NSView alloc] | 137 base::scoped_nsobject<NSView> documentView([[NSView alloc] |
| 173 initWithFrame:NSZeroRect]); | 138 initWithFrame:NSZeroRect]); |
| 174 for (CredentialItemButton* button in credentialButtons_.get()) { | 139 for (CredentialItemButton* button in credentialButtons_.get()) { |
| 175 [documentView addSubview:button]; | 140 [documentView addSubview:button]; |
| 176 CGFloat cellHeight = [[button cell] cellSize].height; | 141 CGFloat cellHeight = [[button cell] cellSize].height; |
| 177 [button setFrame:NSMakeRect(0, curY, buttonWidth, | 142 [button setFrame:NSMakeRect(0, curY, buttonWidth, |
| 178 cellHeight + 2 * kVerticalAvatarMargin)]; | 143 cellHeight + 2 * kVerticalAvatarMargin)]; |
| 179 if (button.passwordForm->is_public_suffix_match) { | 144 if (button.passwordForm->is_public_suffix_match) { |
| 180 NSImageView* icon = IconForPSL( | 145 NSRect rect = NSMakeRect( |
| 181 [button frame], button.passwordForm->origin.GetOrigin().spec()); | 146 base::i18n::IsRTL() ? kFramePadding |
| 182 [documentView addSubview:icon]; | 147 : buttonWidth - kInfoIconSize - kFramePadding, |
| 148 (NSHeight([button frame]) - kInfoIconSize) / 2, kInfoIconSize, |
| 149 kInfoIconSize); |
| 150 NSView* icon = [button |
| 151 addInfoIcon:base::SysUTF8ToNSString( |
| 152 button.passwordForm->origin.GetOrigin().spec())]; |
| 153 [icon setFrame:rect]; |
| 183 } | 154 } |
| 184 curY = NSMaxY([button frame]); | 155 curY = NSMaxY([button frame]); |
| 185 } | 156 } |
| 186 [documentView setFrameSize:NSMakeSize(buttonWidth, curY)]; | 157 [documentView setFrameSize:NSMakeSize(buttonWidth, curY)]; |
| 187 [scrollView setDocumentView:documentView]; | 158 [scrollView setDocumentView:documentView]; |
| 188 [scrollView setFrameSize:NSMakeSize( | 159 [scrollView setFrameSize:NSMakeSize( |
| 189 kDesiredBubbleWidth, | 160 kDesiredBubbleWidth, |
| 190 [scrollView hasVerticalScroller] ? kMaxHeightAccounts * kCredentialHeight | 161 [scrollView hasVerticalScroller] ? kMaxHeightAccounts * kCredentialHeight |
| 191 : curY)]; | 162 : curY)]; |
| 192 [view addSubview:scrollView]; | 163 [view addSubview:scrollView]; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 271 |
| 301 - (NSArray*)credentialButtons { | 272 - (NSArray*)credentialButtons { |
| 302 return credentialButtons_; | 273 return credentialButtons_; |
| 303 } | 274 } |
| 304 | 275 |
| 305 - (NSTextView*)titleView { | 276 - (NSTextView*)titleView { |
| 306 return titleView_; | 277 return titleView_; |
| 307 } | 278 } |
| 308 | 279 |
| 309 @end | 280 @end |
| OLD | NEW |