summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bookmark_menu_bridge.mm
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-23 01:18:13 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-23 01:18:13 +0000
commitf6314009810a5ee6c606328c41c8ff4e1dacd05e (patch)
tree3c530eb3c209f23e369f0a8f35849a94e502cbc8 /chrome/browser/cocoa/bookmark_menu_bridge.mm
parentec85e6880806202737a4d32c94817f0ecad4ca8b (diff)
downloadchromium_src-f6314009810a5ee6c606328c41c8ff4e1dacd05e.zip
chromium_src-f6314009810a5ee6c606328c41c8ff4e1dacd05e.tar.gz
chromium_src-f6314009810a5ee6c606328c41c8ff4e1dacd05e.tar.bz2
Fix problem with bookmark bar introduced by window sharing; pref
change needs to change all open windows with the same preferences, not just the current one). Improve unit testing. Limit bookmark menu size width (1st pass). Cleanup/delete of code which no longer does much. Review URL: http://codereview.chromium.org/79068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14282 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_menu_bridge.mm')
-rw-r--r--chrome/browser/cocoa/bookmark_menu_bridge.mm39
1 files changed, 32 insertions, 7 deletions
diff --git a/chrome/browser/cocoa/bookmark_menu_bridge.mm b/chrome/browser/cocoa/bookmark_menu_bridge.mm
index f2754a0..eea9b413 100644
--- a/chrome/browser/cocoa/bookmark_menu_bridge.mm
+++ b/chrome/browser/cocoa/bookmark_menu_bridge.mm
@@ -145,24 +145,49 @@ void BookmarkMenuBridge::ClearBookmarkMenu(NSMenu* menu) {
}
}
+namespace {
+
+// Menus more than this many chars long will get trimmed
+const NSUInteger kMaximumMenuWidthInChars = 65;
+
+// When trimming, use this many chars from each side
+const NSUInteger kMenuTrimSizeInChars = 30;
+
+}
+
void BookmarkMenuBridge::AddNodeToMenu(BookmarkNode* node, NSMenu* menu) {
for (int i = 0; i < node->GetChildCount(); i++) {
BookmarkNode* child = node->GetChild(i);
- // TODO(jrg): Should we limit the title length?
- // For the Bookmark Bar under windows, items appear trimmed to ~19
- // chars (looks like a pixel width limit).
- NSString* title = base::SysWideToNSString(child->GetTitle());
+ NSString* full_title = base::SysWideToNSString(child->GetTitle());
+ NSString* title = full_title;
+ if ([title length] > kMaximumMenuWidthInChars) {
+ // TODO(jrg): add a better heuristic? I'd really like to trim this
+ // by pixels, not by chars (font is not fixed width).
+ // For Safari, it appears that menu names >60 chars get split up to
+ // 30char + "..." + 30char.
+ title = [NSString stringWithFormat:@"%@…%@",
+ [title substringToIndex:kMenuTrimSizeInChars],
+ [title substringFromIndex:([title length] -
+ kMenuTrimSizeInChars)]];
+ }
NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title
action:nil
keyEquivalent:@""] autorelease];
- [item setTarget:controller_];
- [item setAction:@selector(openBookmarkMenuItem:)];
- [item setTag:child->id()];
[menu addItem:item];
if (child->is_folder()) {
NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease];
[menu setSubmenu:submenu forItem:item];
AddNodeToMenu(child, submenu); // recursive call
+ } else {
+ [item setTarget:controller_];
+ [item setAction:@selector(openBookmarkMenuItem:)];
+ [item setTag:child->id()];
+ // Add a tooltip
+ std::string url_string = child->GetURL().possibly_invalid_spec();
+ NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", full_title,
+ url_string.c_str()];
+ [item setToolTip:tooltip];
+
}
}
}