diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-04 09:40:44 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-04 09:40:44 +0000 |
commit | b1e270b5b771f615ad74c91b2f98007d42a29a91 (patch) | |
tree | 4aada820e2a653ab3776c46c690560b2ea73f8a6 /chrome/browser/ui/cocoa/menu_controller.mm | |
parent | 77da1199b2bc47f750545b3e49abe96754d30e27 (diff) | |
download | chromium_src-b1e270b5b771f615ad74c91b2f98007d42a29a91.zip chromium_src-b1e270b5b771f615ad74c91b2f98007d42a29a91.tar.gz chromium_src-b1e270b5b771f615ad74c91b2f98007d42a29a91.tar.bz2 |
Alternate NTP: Limit width of tab titles in recent tabs menu
This is the Mac version of this CL:
https://chromiumcodereview.appspot.com/11410067
It limits the width of tab titles and window names in the recent tabs menu.
BUG=160844
Review URL: https://chromiumcodereview.appspot.com/11316127
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/cocoa/menu_controller.mm')
-rw-r--r-- | chrome/browser/ui/cocoa/menu_controller.mm | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/chrome/browser/ui/cocoa/menu_controller.mm b/chrome/browser/ui/cocoa/menu_controller.mm index 9563ee2..99c4c14 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:) |