| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/autofill/autofill_account_chooser.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h" |
| 6 | 6 |
| 7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 8 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | 8 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" |
| 9 #include "chrome/browser/ui/chrome_style.h" | 9 #include "chrome/browser/ui/chrome_style.h" |
| 10 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" | 10 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" |
| 11 #import "chrome/browser/ui/cocoa/autofill/down_arrow_popup_menu_cell.h" | 11 #import "chrome/browser/ui/cocoa/autofill/down_arrow_popup_menu_cell.h" |
| 12 #import "chrome/browser/ui/cocoa/menu_button.h" | 12 #import "chrome/browser/ui/cocoa/menu_button.h" |
| 13 #include "grit/ui_resources.h" | 13 #include "grit/ui_resources.h" |
| 14 #include "skia/ext/skia_utils_mac.h" | 14 #include "skia/ext/skia_utils_mac.h" |
| 15 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 15 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 16 #include "ui/base/models/menu_model.h" | 16 #include "ui/base/models/menu_model.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 | 18 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 #pragma mark AutofillAccountChooser | 41 #pragma mark AutofillAccountChooser |
| 42 | 42 |
| 43 @interface AutofillAccountChooser (Private) | 43 @interface AutofillAccountChooser (Private) |
| 44 - (void)performLayout; | 44 - (void)performLayout; |
| 45 @end | 45 @end |
| 46 | 46 |
| 47 @implementation AutofillAccountChooser | 47 @implementation AutofillAccountChooser |
| 48 | 48 |
| 49 - (id)initWithFrame:(NSRect)frame | 49 - (id)initWithFrame:(NSRect)frame |
| 50 controller:(autofill::AutofillDialogController*)controller { | 50 delegate:(autofill::AutofillDialogViewDelegate*)delegate { |
| 51 if ((self = [super initWithFrame:frame])) { | 51 if ((self = [super initWithFrame:frame])) { |
| 52 controller_ = controller; | 52 delegate_ = delegate; |
| 53 | 53 |
| 54 icon_.reset([[NSImageView alloc] initWithFrame:NSZeroRect]); | 54 icon_.reset([[NSImageView alloc] initWithFrame:NSZeroRect]); |
| 55 [icon_ setImageFrameStyle:NSImageFrameNone]; | 55 [icon_ setImageFrameStyle:NSImageFrameNone]; |
| 56 | 56 |
| 57 link_.reset([[HyperlinkButtonCell buttonWithString: | 57 link_.reset([[HyperlinkButtonCell buttonWithString: |
| 58 base::SysUTF16ToNSString(controller_->SignInLinkText())] retain]); | 58 base::SysUTF16ToNSString(delegate_->SignInLinkText())] retain]); |
| 59 [link_ setAction:@selector(linkClicked:)]; | 59 [link_ setAction:@selector(linkClicked:)]; |
| 60 [link_ setTarget:self]; | 60 [link_ setTarget:self]; |
| 61 [[link_ cell] setUnderlineOnHover:YES]; | 61 [[link_ cell] setUnderlineOnHover:YES]; |
| 62 [[link_ cell] setTextColor: | 62 [[link_ cell] setTextColor: |
| 63 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; | 63 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; |
| 64 | 64 |
| 65 popup_.reset([[MenuButton alloc] initWithFrame:NSZeroRect]); | 65 popup_.reset([[MenuButton alloc] initWithFrame:NSZeroRect]); |
| 66 base::scoped_nsobject<DownArrowPopupMenuCell> popupCell( | 66 base::scoped_nsobject<DownArrowPopupMenuCell> popupCell( |
| 67 [[DownArrowPopupMenuCell alloc] initTextCell:@""]); | 67 [[DownArrowPopupMenuCell alloc] initTextCell:@""]); |
| 68 [popup_ setCell:popupCell]; | 68 [popup_ setCell:popupCell]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 79 [menu setAutoenablesItems:NO]; | 79 [menu setAutoenablesItems:NO]; |
| 80 [popup_ setAttachedMenu:menu]; | 80 [popup_ setAttachedMenu:menu]; |
| 81 | 81 |
| 82 [self setSubviews:@[link_, popup_, icon_]]; | 82 [self setSubviews:@[link_, popup_, icon_]]; |
| 83 [self update]; | 83 [self update]; |
| 84 } | 84 } |
| 85 return self; | 85 return self; |
| 86 } | 86 } |
| 87 | 87 |
| 88 - (void)optionsMenuChanged:(id)sender { | 88 - (void)optionsMenuChanged:(id)sender { |
| 89 ui::MenuModel* menuModel = controller_->MenuModelForAccountChooser(); | 89 ui::MenuModel* menuModel = delegate_->MenuModelForAccountChooser(); |
| 90 DCHECK(menuModel); | 90 DCHECK(menuModel); |
| 91 menuModel->ActivatedAt([sender tag]); | 91 menuModel->ActivatedAt([sender tag]); |
| 92 } | 92 } |
| 93 | 93 |
| 94 - (void)linkClicked:(id)sender { | 94 - (void)linkClicked:(id)sender { |
| 95 controller_->SignInLinkClicked(); | 95 delegate_->SignInLinkClicked(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 - (void)update { | 98 - (void)update { |
| 99 NSImage* iconImage = controller_->AccountChooserImage().AsNSImage(); | 99 NSImage* iconImage = delegate_->AccountChooserImage().AsNSImage(); |
| 100 [icon_ setImage:iconImage]; | 100 [icon_ setImage:iconImage]; |
| 101 | 101 |
| 102 // Set title. | 102 // Set title. |
| 103 NSString* popupTitle = | 103 NSString* popupTitle = |
| 104 base::SysUTF16ToNSString(controller_->AccountChooserText()); | 104 base::SysUTF16ToNSString(delegate_->AccountChooserText()); |
| 105 [popup_ setTitle:popupTitle]; | 105 [popup_ setTitle:popupTitle]; |
| 106 | 106 |
| 107 NSString* linkTitle = | 107 NSString* linkTitle = |
| 108 base::SysUTF16ToNSString(controller_->SignInLinkText()); | 108 base::SysUTF16ToNSString(delegate_->SignInLinkText()); |
| 109 [link_ setTitle:linkTitle]; | 109 [link_ setTitle:linkTitle]; |
| 110 | 110 |
| 111 // populate menu | 111 // populate menu |
| 112 NSMenu* accountMenu = [popup_ attachedMenu]; | 112 NSMenu* accountMenu = [popup_ attachedMenu]; |
| 113 [accountMenu removeAllItems]; | 113 [accountMenu removeAllItems]; |
| 114 // See menu_button.h for documentation on why this is needed. | 114 // See menu_button.h for documentation on why this is needed. |
| 115 [accountMenu addItemWithTitle:@"" action:nil keyEquivalent:@""]; | 115 [accountMenu addItemWithTitle:@"" action:nil keyEquivalent:@""]; |
| 116 ui::MenuModel* model = controller_->MenuModelForAccountChooser(); | 116 ui::MenuModel* model = delegate_->MenuModelForAccountChooser(); |
| 117 if (model) { | 117 if (model) { |
| 118 for (int i = 0; i < model->GetItemCount(); ++i) { | 118 for (int i = 0; i < model->GetItemCount(); ++i) { |
| 119 AddMenuItem(accountMenu, | 119 AddMenuItem(accountMenu, |
| 120 self, | 120 self, |
| 121 @selector(optionsMenuChanged:), | 121 @selector(optionsMenuChanged:), |
| 122 base::SysUTF16ToNSString(model->GetLabelAt(i)), | 122 base::SysUTF16ToNSString(model->GetLabelAt(i)), |
| 123 model->GetCommandIdAt(i), | 123 model->GetCommandIdAt(i), |
| 124 model->IsEnabledAt(i), | 124 model->IsEnabledAt(i), |
| 125 model->IsItemCheckedAt(i)); | 125 model->IsItemCheckedAt(i)); |
| 126 } | 126 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 142 frame.origin.x = NSMaxX(bounds) - NSWidth(frame); | 142 frame.origin.x = NSMaxX(bounds) - NSWidth(frame); |
| 143 [activeControl setFrame:frame]; | 143 [activeControl setFrame:frame]; |
| 144 | 144 |
| 145 [icon_ setFrameSize:[[icon_ image] size]]; | 145 [icon_ setFrameSize:[[icon_ image] size]]; |
| 146 frame.origin.x -= NSWidth([icon_ frame]) + kAroundTextPadding; | 146 frame.origin.x -= NSWidth([icon_ frame]) + kAroundTextPadding; |
| 147 [icon_ setFrameOrigin:frame.origin]; | 147 [icon_ setFrameOrigin:frame.origin]; |
| 148 } | 148 } |
| 149 | 149 |
| 150 @end | 150 @end |
| 151 | 151 |
| OLD | NEW |