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_controller.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/hyperlink_button_cell.h" | 12 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" |
13 #import "chrome/browser/ui/cocoa/menu_button.h" | 13 #import "chrome/browser/ui/cocoa/menu_button.h" |
14 #include "grit/ui_resources.h" | 14 #include "grit/ui_resources.h" |
15 #include "skia/ext/skia_utils_mac.h" | 15 #include "skia/ext/skia_utils_mac.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 |
19 #pragma mark Helper functions | 19 #pragma mark Helper functions |
20 | 20 |
21 // Adds an item with the specified properties to |menu|. | 21 // Adds an item with the specified properties to |menu|. |
22 void AddMenuItem(NSMenu *menu, id target, SEL selector, NSString* title, | 22 void AddMenuItem(NSMenu *menu, id target, SEL selector, NSString* title, |
23 int tag, bool enabled, bool checked) { | 23 int tag, bool enabled, bool checked) { |
24 if (tag == -1) { | 24 if (tag == -1) { |
25 [menu addItem:[NSMenuItem separatorItem]]; | 25 [menu addItem:[NSMenuItem separatorItem]]; |
26 return; | 26 return; |
27 } | 27 } |
28 | 28 |
29 scoped_nsobject<NSMenuItem> item([[NSMenuItem alloc] | 29 base::scoped_nsobject<NSMenuItem> item( |
30 initWithTitle:title | 30 [[NSMenuItem alloc] initWithTitle:title |
31 action:selector | 31 action:selector |
32 keyEquivalent:@""]); | 32 keyEquivalent:@""]); |
33 [item setTag:tag]; | 33 [item setTag:tag]; |
34 [menu addItem:item]; | 34 [menu addItem:item]; |
35 [item setTarget:target]; | 35 [item setTarget:target]; |
36 if (checked) | 36 if (checked) |
37 [item setState:NSOnState]; | 37 [item setState:NSOnState]; |
38 [item setEnabled:enabled]; | 38 [item setEnabled:enabled]; |
39 } | 39 } |
40 | 40 |
41 #pragma mark AutofillAccountChooser | 41 #pragma mark AutofillAccountChooser |
42 | 42 |
(...skipping 13 matching lines...) Expand all Loading... |
56 | 56 |
57 link_.reset([[HyperlinkButtonCell buttonWithString: | 57 link_.reset([[HyperlinkButtonCell buttonWithString: |
58 base::SysUTF16ToNSString(controller_->SignInLinkText())] retain]); | 58 base::SysUTF16ToNSString(controller_->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 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]; |
69 | 69 |
70 [popup_ setOpenMenuOnClick:YES]; | 70 [popup_ setOpenMenuOnClick:YES]; |
71 [popup_ setBordered:NO]; | 71 [popup_ setBordered:NO]; |
72 [popup_ setShowsBorderOnlyWhileMouseInside:NO]; | 72 [popup_ setShowsBorderOnlyWhileMouseInside:NO]; |
73 NSImage* popupImage = ui::ResourceBundle::GetSharedInstance(). | 73 NSImage* popupImage = ui::ResourceBundle::GetSharedInstance(). |
74 GetNativeImageNamed(IDR_MENU_DROPARROW).ToNSImage(); | 74 GetNativeImageNamed(IDR_MENU_DROPARROW).ToNSImage(); |
75 [popupCell setImage:popupImage | 75 [popupCell setImage:popupImage |
76 forButtonState:image_button_cell::kDefaultState]; | 76 forButtonState:image_button_cell::kDefaultState]; |
77 | 77 |
78 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); | 78 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); |
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 { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |