| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ui/base/cocoa/menu_controller.h" | 5 #import "ui/base/cocoa/menu_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "ui/base/accelerators/accelerator.h" | 9 #include "ui/base/accelerators/accelerator.h" |
| 10 #include "ui/base/accelerators/platform_accelerator_cocoa.h" | 10 #include "ui/base/accelerators/platform_accelerator_cocoa.h" |
| 11 #import "ui/base/cocoa/cocoa_event_utils.h" | 11 #import "ui/base/cocoa/cocoa_event_utils.h" |
| 12 #include "ui/base/l10n/l10n_util_mac.h" | 12 #include "ui/base/l10n/l10n_util_mac.h" |
| 13 #include "ui/base/models/simple_menu_model.h" | 13 #include "ui/base/models/simple_menu_model.h" |
| 14 #include "ui/gfx/font.h" | 14 #include "ui/gfx/font.h" |
| 15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 16 #include "ui/gfx/text_elider.h" | 16 #include "ui/gfx/text_elider.h" |
| 17 | 17 |
| 18 @interface MenuController (Private) | 18 @interface MenuController (Private) |
| 19 - (void)addSeparatorToMenu:(NSMenu*)menu | 19 - (void)addSeparatorToMenu:(NSMenu*)menu |
| 20 atIndex:(int)index; | 20 atIndex:(int)index; |
| 21 @end | 21 @end |
| 22 | 22 |
| 23 @implementation MenuController | 23 @implementation MenuController |
| 24 | 24 |
| 25 @synthesize model = model_; | 25 @synthesize model = model_; |
| 26 @synthesize useWithPopUpButtonCell = useWithPopUpButtonCell_; | 26 @synthesize useWithPopUpButtonCell = useWithPopUpButtonCell_; |
| 27 | 27 |
| 28 + (string16)elideMenuTitle:(const string16&)title | 28 + (string16)elideMenuTitle:(const base::string16&)title |
| 29 toWidth:(int)width { | 29 toWidth:(int)width { |
| 30 NSFont* nsfont = [NSFont menuBarFontOfSize:0]; // 0 means "default" | 30 NSFont* nsfont = [NSFont menuBarFontOfSize:0]; // 0 means "default" |
| 31 gfx::Font font(base::SysNSStringToUTF8([nsfont fontName]), | 31 gfx::Font font(base::SysNSStringToUTF8([nsfont fontName]), |
| 32 static_cast<int>([nsfont pointSize])); | 32 static_cast<int>([nsfont pointSize])); |
| 33 return gfx::ElideText(title, font, width, gfx::ELIDE_AT_END); | 33 return gfx::ElideText(title, font, width, gfx::ELIDE_AT_END); |
| 34 } | 34 } |
| 35 | 35 |
| 36 - (id)init { | 36 - (id)init { |
| 37 self = [super init]; | 37 self = [super init]; |
| 38 return self; | 38 return self; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 atIndex:(int)index { | 95 atIndex:(int)index { |
| 96 NSMenuItem* separator = [NSMenuItem separatorItem]; | 96 NSMenuItem* separator = [NSMenuItem separatorItem]; |
| 97 [menu insertItem:separator atIndex:index]; | 97 [menu insertItem:separator atIndex:index]; |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Adds an item or a hierarchical menu to the item at the |index|, | 100 // Adds an item or a hierarchical menu to the item at the |index|, |
| 101 // associated with the entry in the model identified by |modelIndex|. | 101 // associated with the entry in the model identified by |modelIndex|. |
| 102 - (void)addItemToMenu:(NSMenu*)menu | 102 - (void)addItemToMenu:(NSMenu*)menu |
| 103 atIndex:(NSInteger)index | 103 atIndex:(NSInteger)index |
| 104 fromModel:(ui::MenuModel*)model { | 104 fromModel:(ui::MenuModel*)model { |
| 105 string16 label16 = model->GetLabelAt(index); | 105 base::string16 label16 = model->GetLabelAt(index); |
| 106 int maxWidth = [self maxWidthForMenuModel:model modelIndex:index]; | 106 int maxWidth = [self maxWidthForMenuModel:model modelIndex:index]; |
| 107 if (maxWidth != -1) | 107 if (maxWidth != -1) |
| 108 label16 = [MenuController elideMenuTitle:label16 toWidth:maxWidth]; | 108 label16 = [MenuController elideMenuTitle:label16 toWidth:maxWidth]; |
| 109 | 109 |
| 110 NSString* label = l10n_util::FixUpWindowsStyleLabel(label16); | 110 NSString* label = l10n_util::FixUpWindowsStyleLabel(label16); |
| 111 base::scoped_nsobject<NSMenuItem> item( | 111 base::scoped_nsobject<NSMenuItem> item( |
| 112 [[NSMenuItem alloc] initWithTitle:label | 112 [[NSMenuItem alloc] initWithTitle:label |
| 113 action:@selector(itemSelected:) | 113 action:@selector(itemSelected:) |
| 114 keyEquivalent:@""]); | 114 keyEquivalent:@""]); |
| 115 | 115 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 } | 236 } |
| 237 | 237 |
| 238 - (void)menuDidClose:(NSMenu*)menu { | 238 - (void)menuDidClose:(NSMenu*)menu { |
| 239 if (isMenuOpen_) { | 239 if (isMenuOpen_) { |
| 240 model_->MenuClosed(); | 240 model_->MenuClosed(); |
| 241 isMenuOpen_ = NO; | 241 isMenuOpen_ = NO; |
| 242 } | 242 } |
| 243 } | 243 } |
| 244 | 244 |
| 245 @end | 245 @end |
| OLD | NEW |