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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 NSSize size = [super cellSizeForBounds:aRect]; | 107 NSSize size = [super cellSizeForBounds:aRect]; |
108 // Cocoa seems to slightly underestimate how much space we need, so we | 108 // Cocoa seems to slightly underestimate how much space we need, so we |
109 // compensate here to avoid a clipped rendering. | 109 // compensate here to avoid a clipped rendering. |
110 size.width += 2; | 110 size.width += 2; |
111 size.height += 4; | 111 size.height += 4; |
112 return size; | 112 return size; |
113 } | 113 } |
114 | 114 |
115 - (void)setBookmarkCellText:(NSString*)title | 115 - (void)setBookmarkCellText:(NSString*)title |
116 image:(NSImage*)image { | 116 image:(NSImage*)image { |
117 title = [title stringByReplacingOccurrencesOfString:@"\n" | |
118 withString:@" "]; | |
119 title = [title stringByReplacingOccurrencesOfString:@"\r" | |
120 withString:@" "]; | |
Ilya Sherman
2011/12/13 22:35:24
nit: For the sake of clarity when scanning the rev
KushalP
2011/12/13 22:51:31
As in a completely different commit to the repo? S
| |
121 // If there is no title, squeeze things tight by displaying only the image; by | |
122 // default, Cocoa leaves extra space in an attempt to display an empty title. | |
123 if ([title length]) { | 117 if ([title length]) { |
124 [self setImagePosition:NSImageLeft]; | 118 [self setImagePosition:NSImageLeft]; |
125 [self setTitle:title]; | 119 [self setTitle:title]; |
120 } else if ([self isFolderButtonCell]) { | |
121 // Left-align icons for bookmarks within folders, regardless of whether | |
122 // there is a title. | |
123 [self setImagePosition:NSImageLeft]; | |
126 } else { | 124 } else { |
125 // Only show the icon when there is no title and the cell is on the | |
126 // bookmarks bar (directly) and not in a folder. | |
Ilya Sherman
2011/12/13 22:35:24
nit: This comment is a little confusing, because i
| |
127 [self setImagePosition:NSImageOnly]; | 127 [self setImagePosition:NSImageOnly]; |
128 } | 128 } |
129 | 129 |
130 if (image) | 130 if (image) |
131 [self setImage:image]; | 131 [self setImage:image]; |
132 } | 132 } |
133 | 133 |
134 - (void)setBookmarkNode:(const BookmarkNode*)node { | 134 - (void)setBookmarkNode:(const BookmarkNode*)node { |
135 [self setRepresentedObject:[NSValue valueWithPointer:node]]; | 135 [self setRepresentedObject:[NSValue valueWithPointer:node]]; |
136 } | 136 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 NSRect drawRect = NSOffsetRect(imageRect, dX, dY); | 246 NSRect drawRect = NSOffsetRect(imageRect, dX, dY); |
247 [arrowImage_ drawInRect:drawRect | 247 [arrowImage_ drawInRect:drawRect |
248 fromRect:imageRect | 248 fromRect:imageRect |
249 operation:NSCompositeSourceOver | 249 operation:NSCompositeSourceOver |
250 fraction:[self isEnabled] ? 1.0 : 0.5 | 250 fraction:[self isEnabled] ? 1.0 : 0.5 |
251 neverFlipped:YES]; | 251 neverFlipped:YES]; |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 @end | 255 @end |
OLD | NEW |