Index: chrome/browser/ui/cocoa/menu_controller.mm |
diff --git a/chrome/browser/ui/cocoa/menu_controller.mm b/chrome/browser/ui/cocoa/menu_controller.mm |
index 9563ee24b736583f4e22791dfda3ecdfe797a6e6..99c4c14c8bdbbb608ab37832449cabe944378291 100644 |
--- a/chrome/browser/ui/cocoa/menu_controller.mm |
+++ b/chrome/browser/ui/cocoa/menu_controller.mm |
@@ -11,6 +11,7 @@ |
#include "ui/base/accelerators/platform_accelerator_cocoa.h" |
#include "ui/base/l10n/l10n_util_mac.h" |
#include "ui/base/models/simple_menu_model.h" |
+#include "ui/base/text/text_elider.h" |
#include "ui/gfx/image/image.h" |
@interface MenuController (Private) |
@@ -23,6 +24,14 @@ |
@synthesize model = model_; |
@synthesize useWithPopUpButtonCell = useWithPopUpButtonCell_; |
++ (string16)elideMenuTitle:(const string16&)title |
+ toWidth:(int)width { |
+ NSFont* nsfont = [NSFont menuBarFontOfSize:0]; // 0 means "default" |
+ gfx::Font font(base::SysNSStringToUTF8([nsfont fontName]), |
+ static_cast<int>([nsfont pointSize])); |
+ return ui::ElideText(title, font, width, ui::ELIDE_AT_END); |
+} |
+ |
- (id)init { |
self = [super init]; |
return self; |
@@ -83,6 +92,11 @@ |
return menu; |
} |
+- (int)maxWidthForMenuModel:(ui::MenuModel*)model |
+ modelIndex:(int)modelIndex { |
+ return -1; |
+} |
+ |
// Adds a separator item at the given index. As the separator doesn't need |
// anything from the model, this method doesn't need the model index as the |
// other method below does. |
@@ -98,8 +112,12 @@ |
atIndex:(NSInteger)index |
fromModel:(ui::MenuModel*)model |
modelIndex:(int)modelIndex { |
- NSString* label = |
- l10n_util::FixUpWindowsStyleLabel(model->GetLabelAt(modelIndex)); |
+ string16 label16 = model->GetLabelAt(modelIndex); |
+ int maxWidth = [self maxWidthForMenuModel:model modelIndex:modelIndex]; |
+ if (maxWidth != -1) |
+ label16 = [MenuController elideMenuTitle:label16 toWidth:maxWidth]; |
+ |
+ NSString* label = l10n_util::FixUpWindowsStyleLabel(label16); |
scoped_nsobject<NSMenuItem> item( |
[[NSMenuItem alloc] initWithTitle:label |
action:@selector(itemSelected:) |