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

Side by Side Diff: chrome/browser/cocoa/bookmark_menu_bridge.mm

Issue 159286: Added menus for bookmark bar folders. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/cocoa/bookmark_menu_bridge.h" 5 #include "chrome/browser/cocoa/bookmark_menu_bridge.h"
6 #import <AppKit/AppKit.h> 6 #import <AppKit/AppKit.h>
7 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #include "chrome/app/chrome_dll_resource.h" // IDC_BOOKMARK_MENU 8 #include "chrome/app/chrome_dll_resource.h" // IDC_BOOKMARK_MENU
9 #import "chrome/browser/app_controller_mac.h" 9 #import "chrome/browser/app_controller_mac.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 ([item hasSubmenu])) { 162 ([item hasSubmenu])) {
163 // This will eventually [obj release] all its kids, if it has 163 // This will eventually [obj release] all its kids, if it has
164 // any. 164 // any.
165 [menu removeItem:item]; 165 [menu removeItem:item];
166 } else { 166 } else {
167 // Not a bookmark or item with submenu, so leave it alone. 167 // Not a bookmark or item with submenu, so leave it alone.
168 } 168 }
169 } 169 }
170 } 170 }
171 171
172 namespace {
173
174 // Menus more than this many chars long will get trimmed
175 const NSUInteger kMaximumMenuWidthInChars = 65;
176
177 // When trimming, use this many chars from each side
178 const NSUInteger kMenuTrimSizeInChars = 30;
179
180 }
181
182 void BookmarkMenuBridge::AddNodeToMenu(const BookmarkNode* node, NSMenu* menu) { 172 void BookmarkMenuBridge::AddNodeToMenu(const BookmarkNode* node, NSMenu* menu) {
183 for (int i = 0; i < node->GetChildCount(); i++) { 173 for (int i = 0; i < node->GetChildCount(); i++) {
184 const BookmarkNode* child = node->GetChild(i); 174 const BookmarkNode* child = node->GetChild(i);
185 NSString* full_title = base::SysWideToNSString(child->GetTitle()); 175 NSString* title = [BookmarkMenuCocoaController menuTitleForNode:child];
186 NSString* title = full_title;
187 if ([title length] > kMaximumMenuWidthInChars) {
188 // TODO(jrg): add a better heuristic? I'd really like to trim this
189 // by pixels, not by chars (font is not fixed width).
190 // For Safari, it appears that menu names >60 chars get split up to
191 // 30char + "..." + 30char.
192 title = [NSString stringWithFormat:@"%@…%@",
193 [title substringToIndex:kMenuTrimSizeInChars],
194 [title substringFromIndex:([title length] -
195 kMenuTrimSizeInChars)]];
196 }
197 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title 176 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title
198 action:nil 177 action:nil
199 keyEquivalent:@""] autorelease]; 178 keyEquivalent:@""] autorelease];
200 [menu addItem:item]; 179 [menu addItem:item];
201 if (child->is_folder()) { 180 if (child->is_folder()) {
202 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease]; 181 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease];
203 [menu setSubmenu:submenu forItem:item]; 182 [menu setSubmenu:submenu forItem:item];
204 AddNodeToMenu(child, submenu); // recursive call 183 AddNodeToMenu(child, submenu); // recursive call
205 } else { 184 } else {
206 [item setTarget:controller_]; 185 [item setTarget:controller_];
207 [item setAction:@selector(openBookmarkMenuItem:)]; 186 [item setAction:@selector(openBookmarkMenuItem:)];
208 [item setTag:child->id()]; 187 [item setTag:child->id()];
209 // Add a tooltip 188 // Add a tooltip
210 std::string url_string = child->GetURL().possibly_invalid_spec(); 189 std::string url_string = child->GetURL().possibly_invalid_spec();
211 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s", full_title, 190 NSString* tooltip = [NSString stringWithFormat:@"%@\n%s",
191 base::SysWideToNSString(child->GetTitle()),
212 url_string.c_str()]; 192 url_string.c_str()];
213 [item setToolTip:tooltip]; 193 [item setToolTip:tooltip];
214 194
215 } 195 }
216 } 196 }
217 } 197 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_bar_view_unittest.mm ('k') | chrome/browser/cocoa/bookmark_menu_cocoa_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698