| 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 aae1dcb321fb91373d9d97aa23becf8ce828c221..302164d10c76092e65dc658829d936ee3260fb47 100644
|
| --- a/chrome/browser/ui/cocoa/menu_controller.mm
|
| +++ b/chrome/browser/ui/cocoa/menu_controller.mm
|
| @@ -10,6 +10,7 @@
|
| #include "ui/base/accelerators/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)
|
| @@ -22,6 +23,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;
|
| @@ -82,6 +91,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.
|
| @@ -97,8 +111,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:)
|
|
|