Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 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 menuController:(BookmarkContextMenuCocoaController*)menuController |
| 35 cellText:(NSString*)cellText | 35 text:(NSString*)text |
| 36 cellImage:(NSImage*)cellImage { | 36 image:(NSImage*)image { |
| 37 id buttonCell = | 37 id buttonCell = |
| 38 [[[BookmarkButtonCell alloc] initForNode:node | 38 [[[BookmarkButtonCell alloc] initForNode:node |
| 39 menuController:menuController | 39 menuController:menuController |
| 40 cellText:cellText | 40 text:text |
| 41 cellImage:cellImage] | 41 image:image] |
| 42 autorelease]; | |
| 43 return buttonCell; | |
| 44 } | |
| 45 | |
| 46 + (id)buttonCellWithMenuController:(BookmarkContextMenuCocoaController*)menuCont roller | |
| 47 text:(NSString*)text | |
| 48 image:(NSImage*)image { | |
| 49 id buttonCell = | |
| 50 [[[BookmarkButtonCell alloc] initWithMenuController:menuController | |
| 51 text:text | |
| 52 image:image] | |
| 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 menuController:(BookmarkContextMenuCocoaController*)menuController |
| 48 cellText:(NSString*)cellText | 59 text:(NSString*)text |
| 49 cellImage:(NSImage*)cellImage { | 60 image:(NSImage*)image { |
| 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)initWithMenuController:(BookmarkContextMenuCocoaController*)menuController | |
| 81 text:(NSString*)text | |
| 82 image:(NSImage*)image { | |
| 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 menuController:nil text:string image: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. | |
|
Alexei Svitkine (slow)
2013/03/11 14:31:04
Hmm, my other refactoring CL didn't actually remov
beaudoin
2013/03/11 21:02:51
Done.
| |
| 164 const BookmarkNode* node = [self bookmarkNode]; | 191 const BookmarkNode* node = [self bookmarkNode]; |
| 192 if (!node) | |
| 193 return nil; | |
| 194 | |
| 165 if (node->parent() && node->parent()->type() == BookmarkNode::FOLDER) { | 195 if (node->parent() && node->parent()->type() == BookmarkNode::FOLDER) { |
| 166 content::RecordAction(UserMetricsAction("BookmarkBarFolder_CtxMenu")); | 196 content::RecordAction(UserMetricsAction("BookmarkBarFolder_CtxMenu")); |
| 167 } else { | 197 } else { |
| 168 content::RecordAction(UserMetricsAction("BookmarkBar_CtxMenu")); | 198 content::RecordAction(UserMetricsAction("BookmarkBar_CtxMenu")); |
| 169 } | 199 } |
| 170 return [menuController_ menuForBookmarkNode:node]; | 200 return [menuController_ menuForBookmarkNode:node]; |
| 171 } | 201 } |
| 172 | 202 |
| 173 - (void)setTitle:(NSString*)title { | 203 - (void)setTitle:(NSString*)title { |
| 174 if ([[self title] isEqualTo:title]) | 204 if ([[self title] isEqualTo:title]) |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 respectFlipped:YES | 292 respectFlipped:YES |
| 263 hints:nil]; | 293 hints:nil]; |
| 264 } | 294 } |
| 265 } | 295 } |
| 266 | 296 |
| 267 - (int)verticalTextOffset { | 297 - (int)verticalTextOffset { |
| 268 return 0; | 298 return 0; |
| 269 } | 299 } |
| 270 | 300 |
| 271 @end | 301 @end |
| OLD | NEW |