Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(300)

Unified Diff: chrome/browser/ui/cocoa/menu_controller.mm

Issue 11316127: Alternate NTP: Limit width of tab titles in recent tabs menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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:)
« no previous file with comments | « chrome/browser/ui/cocoa/menu_controller.h ('k') | chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698