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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.mm

Issue 12550006: Mac: Add a shortcut to open the Apps page from the bookmark bar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: No longer touching model or views. Created 7 years, 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #import "chrome/browser/bookmarks/bookmark_model.h" 9 #import "chrome/browser/bookmarks/bookmark_model.h"
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
(...skipping 25 matching lines...) Expand all
36 cellImage:(NSImage*)cellImage { 36 cellImage:(NSImage*)cellImage {
37 id buttonCell = 37 id buttonCell =
38 [[[BookmarkButtonCell alloc] initForNode:node 38 [[[BookmarkButtonCell alloc] initForNode:node
39 contextMenu:contextMenu 39 contextMenu:contextMenu
40 cellText:cellText 40 cellText:cellText
41 cellImage:cellImage] 41 cellImage:cellImage]
42 autorelease]; 42 autorelease];
43 return buttonCell; 43 return buttonCell;
44 } 44 }
45 45
46 + (id)buttonCellForContextMenu:(NSMenu*)contextMenu
47 cellText:(NSString*)cellText
48 cellImage:(NSImage*)cellImage {
49 id buttonCell =
50 [[[BookmarkButtonCell alloc] initForContextMenu:contextMenu
51 cellText:cellText
52 cellImage:cellImage]
53 autorelease];
54 return buttonCell;
55 }
56
46 - (id)initForNode:(const BookmarkNode*)node 57 - (id)initForNode:(const BookmarkNode*)node
47 contextMenu:(NSMenu*)contextMenu 58 contextMenu:(NSMenu*)contextMenu
48 cellText:(NSString*)cellText 59 cellText:(NSString*)cellText
49 cellImage:(NSImage*)cellImage { 60 cellImage:(NSImage*)cellImage {
50 if ((self = [super initTextCell:cellText])) { 61 if ((self = [super initTextCell:cellText])) {
51 [self configureBookmarkButtonCell]; 62 [self configureBookmarkButtonCell];
52 [self setTextColor:[NSColor blackColor]]; 63 [self setTextColor:[NSColor blackColor]];
53 [self setBookmarkNode:node]; 64 [self setBookmarkNode:node];
54 65
55 if (node) { 66 if (node) {
56 NSString* title = base::SysUTF16ToNSString(node->GetTitle()); 67 NSString* title = base::SysUTF16ToNSString(node->GetTitle());
57 [self setBookmarkCellText:title image:cellImage]; 68 [self setBookmarkCellText:title image:cellImage];
58 [self setMenu:contextMenu]; 69 [self setMenu:contextMenu];
59 } else { 70 } else {
60 [self setEmpty:YES]; 71 [self setEmpty:YES];
61 [self setBookmarkCellText:l10n_util::GetNSString(IDS_MENU_EMPTY_SUBMENU) 72 [self setBookmarkCellText:l10n_util::GetNSString(IDS_MENU_EMPTY_SUBMENU)
62 image:nil]; 73 image:nil];
63 } 74 }
64 } 75 }
65 76
66 return self; 77 return self;
67 } 78 }
68 79
80 - (id)initForContextMenu:(NSMenu*)contextMenu
81 cellText:(NSString*)cellText
Alexei Svitkine (slow) 2013/03/08 19:45:48 Align the :'s
82 cellImage:(NSImage*)cellImage {
83 if ((self = [super initTextCell:cellText])) {
84 [self configureBookmarkButtonCell];
85 [self setTextColor:[NSColor blackColor]];
86 [self setBookmarkNode:NULL];
87 [self setBookmarkCellText:cellText image:cellImage];
88 [self setMenu:contextMenu];
89 // This is a custom button not attached to any node. It is no considered
90 // empty even if its bookmark node is NULL.
91 [self setEmpty:NO];
92 }
93
94 return self;
95 }
96
69 - (id)initTextCell:(NSString*)string { 97 - (id)initTextCell:(NSString*)string {
70 return [self initForNode:nil contextMenu:nil cellText:string cellImage:nil]; 98 return [self initForNode:nil contextMenu:nil cellText:string cellImage:nil];
71 } 99 }
72 100
73 // Used by the off-the-side menu, the only case where a 101 // Used by the off-the-side menu, the only case where a
74 // BookmarkButtonCell is loaded from a nib. 102 // BookmarkButtonCell is loaded from a nib.
75 - (void)awakeFromNib { 103 - (void)awakeFromNib {
76 [self configureBookmarkButtonCell]; 104 [self configureBookmarkButtonCell];
77 } 105 }
78 106
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 pointerValue]); 182 pointerValue]);
155 } 183 }
156 184
157 // We share the context menu among all bookmark buttons. To allow us 185 // We share the context menu among all bookmark buttons. To allow us
158 // to disambiguate when needed (e.g. "open bookmark"), we set the 186 // to disambiguate when needed (e.g. "open bookmark"), we set the
159 // menu's associated bookmark node ID to be our represented object. 187 // menu's associated bookmark node ID to be our represented object.
160 - (NSMenu*)menu { 188 - (NSMenu*)menu {
161 if (empty_) 189 if (empty_)
162 return nil; 190 return nil;
163 BookmarkMenu* menu = (BookmarkMenu*)[super menu]; 191 BookmarkMenu* menu = (BookmarkMenu*)[super menu];
164 const BookmarkNode* node = 192 const BookmarkNode* node = [self bookmarkNode];
165 static_cast<const BookmarkNode*>([[self representedObject] pointerValue]); 193
194 // If node is NULL, this is a custom button, the menu does not represent
195 // anything.
Alexei Svitkine (slow) 2013/03/08 19:45:48 Is this how the Windows implementation works? No c
196 if (!node)
197 return nil;
166 198
167 if (node->parent() && node->parent()->type() == BookmarkNode::FOLDER) { 199 if (node->parent() && node->parent()->type() == BookmarkNode::FOLDER) {
168 content::RecordAction(UserMetricsAction("BookmarkBarFolder_CtxMenu")); 200 content::RecordAction(UserMetricsAction("BookmarkBarFolder_CtxMenu"));
169 } else { 201 } else {
170 content::RecordAction(UserMetricsAction("BookmarkBar_CtxMenu")); 202 content::RecordAction(UserMetricsAction("BookmarkBar_CtxMenu"));
171 } 203 }
172 204
173 [menu setRepresentedObject:[NSNumber numberWithLongLong:node->id()]]; 205 [menu setRepresentedObject:[NSNumber numberWithLongLong:node->id()]];
174 206
175 return menu; 207 return menu;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 respectFlipped:YES 299 respectFlipped:YES
268 hints:nil]; 300 hints:nil];
269 } 301 }
270 } 302 }
271 303
272 - (int)verticalTextOffset { 304 - (int)verticalTextOffset {
273 return 0; 305 return 0;
274 } 306 }
275 307
276 @end 308 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698