OLD | NEW |
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 13 matching lines...) Expand all Loading... |
24 - (void)applyTextColor; | 24 - (void)applyTextColor; |
25 @end | 25 @end |
26 | 26 |
27 | 27 |
28 @implementation BookmarkButtonCell | 28 @implementation BookmarkButtonCell |
29 | 29 |
30 @synthesize startingChildIndex = startingChildIndex_; | 30 @synthesize startingChildIndex = startingChildIndex_; |
31 @synthesize drawFolderArrow = drawFolderArrow_; | 31 @synthesize drawFolderArrow = drawFolderArrow_; |
32 | 32 |
33 + (id)buttonCellForNode:(const BookmarkNode*)node | 33 + (id)buttonCellForNode:(const BookmarkNode*)node |
34 menuController:(BookmarkContextMenuCocoaController*)menuController | 34 text:(NSString*)text |
35 cellText:(NSString*)cellText | 35 image:(NSImage*)image |
36 cellImage:(NSImage*)cellImage { | 36 menuController:(BookmarkContextMenuCocoaController*)menuController { |
37 id buttonCell = | 37 id buttonCell = |
38 [[[BookmarkButtonCell alloc] initForNode:node | 38 [[[BookmarkButtonCell alloc] initForNode:node |
39 menuController:menuController | 39 text:text |
40 cellText:cellText | 40 image:image |
41 cellImage:cellImage] | 41 menuController:menuController] |
| 42 autorelease]; |
| 43 return buttonCell; |
| 44 } |
| 45 |
| 46 + (id)buttonCellWithText:(NSString*)text |
| 47 image:(NSImage*)image |
| 48 menuController:(BookmarkContextMenuCocoaController*)menuController { |
| 49 id buttonCell = |
| 50 [[[BookmarkButtonCell alloc] initWithText:text |
| 51 image:image |
| 52 menuController:menuController] |
42 autorelease]; | 53 autorelease]; |
43 return buttonCell; | 54 return buttonCell; |
44 } | 55 } |
45 | 56 |
46 - (id)initForNode:(const BookmarkNode*)node | 57 - (id)initForNode:(const BookmarkNode*)node |
47 menuController:(BookmarkContextMenuCocoaController*)menuController | 58 text:(NSString*)text |
48 cellText:(NSString*)cellText | 59 image:(NSImage*)image |
49 cellImage:(NSImage*)cellImage { | 60 menuController:(BookmarkContextMenuCocoaController*)menuController { |
50 if ((self = [super initTextCell:cellText])) { | 61 if ((self = [super initTextCell:text])) { |
51 menuController_ = menuController; | 62 menuController_ = menuController; |
52 [self configureBookmarkButtonCell]; | 63 [self configureBookmarkButtonCell]; |
53 [self setTextColor:[NSColor blackColor]]; | 64 [self setTextColor:[NSColor blackColor]]; |
54 [self setBookmarkNode:node]; | 65 [self setBookmarkNode:node]; |
55 | 66 |
56 if (node) { | 67 if (node) { |
57 NSString* title = base::SysUTF16ToNSString(node->GetTitle()); | 68 NSString* title = base::SysUTF16ToNSString(node->GetTitle()); |
58 [self setBookmarkCellText:title image:cellImage]; | 69 [self setBookmarkCellText:title image:image]; |
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)initWithText:(NSString*)text |
| 81 image:(NSImage*)image |
| 82 menuController:(BookmarkContextMenuCocoaController*)menuController { |
| 83 if ((self = [super initTextCell:text])) { |
| 84 menuController_ = menuController; |
| 85 [self configureBookmarkButtonCell]; |
| 86 [self setTextColor:[NSColor blackColor]]; |
| 87 [self setBookmarkNode:NULL]; |
| 88 [self setBookmarkCellText:text image:image]; |
| 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 | 98 return [self initForNode:nil text:string image:nil menuController:nil]; |
71 menuController:nil | |
72 cellText:string | |
73 cellImage:nil]; | |
74 } | 99 } |
75 | 100 |
76 // 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 |
77 // BookmarkButtonCell is loaded from a nib. | 102 // BookmarkButtonCell is loaded from a nib. |
78 - (void)awakeFromNib { | 103 - (void)awakeFromNib { |
79 [self configureBookmarkButtonCell]; | 104 [self configureBookmarkButtonCell]; |
80 } | 105 } |
81 | 106 |
82 - (BOOL)isFolderButtonCell { | 107 - (BOOL)isFolderButtonCell { |
83 return NO; | 108 return NO; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 179 |
155 - (const BookmarkNode*)bookmarkNode { | 180 - (const BookmarkNode*)bookmarkNode { |
156 return static_cast<const BookmarkNode*>([[self representedObject] | 181 return static_cast<const BookmarkNode*>([[self representedObject] |
157 pointerValue]); | 182 pointerValue]); |
158 } | 183 } |
159 | 184 |
160 - (NSMenu*)menu { | 185 - (NSMenu*)menu { |
161 if (empty_) | 186 if (empty_) |
162 return nil; | 187 return nil; |
163 | 188 |
| 189 // If node is NULL, this is a custom button, the menu does not represent |
| 190 // anything. |
164 const BookmarkNode* node = [self bookmarkNode]; | 191 const BookmarkNode* node = [self bookmarkNode]; |
165 if (node->parent() && node->parent()->type() == BookmarkNode::FOLDER) { | 192 |
| 193 if (node && node->parent() && |
| 194 node->parent()->type() == BookmarkNode::FOLDER) { |
166 content::RecordAction(UserMetricsAction("BookmarkBarFolder_CtxMenu")); | 195 content::RecordAction(UserMetricsAction("BookmarkBarFolder_CtxMenu")); |
167 } else { | 196 } else { |
168 content::RecordAction(UserMetricsAction("BookmarkBar_CtxMenu")); | 197 content::RecordAction(UserMetricsAction("BookmarkBar_CtxMenu")); |
169 } | 198 } |
170 return [menuController_ menuForBookmarkNode:node]; | 199 return [menuController_ menuForBookmarkNode:node]; |
171 } | 200 } |
172 | 201 |
173 - (void)setTitle:(NSString*)title { | 202 - (void)setTitle:(NSString*)title { |
174 if ([[self title] isEqualTo:title]) | 203 if ([[self title] isEqualTo:title]) |
175 return; | 204 return; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 respectFlipped:YES | 291 respectFlipped:YES |
263 hints:nil]; | 292 hints:nil]; |
264 } | 293 } |
265 } | 294 } |
266 | 295 |
267 - (int)verticalTextOffset { | 296 - (int)verticalTextOffset { |
268 return 0; | 297 return 0; |
269 } | 298 } |
270 | 299 |
271 @end | 300 @end |
OLD | NEW |