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

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

Issue 7326043: The text color for BookmarkButton sometimes doesn't get updated. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 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) 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 28 matching lines...) Expand all
39 return buttonCell; 39 return buttonCell;
40 } 40 }
41 41
42 - (id)initForNode:(const BookmarkNode*)node 42 - (id)initForNode:(const BookmarkNode*)node
43 contextMenu:(NSMenu*)contextMenu 43 contextMenu:(NSMenu*)contextMenu
44 cellText:(NSString*)cellText 44 cellText:(NSString*)cellText
45 cellImage:(NSImage*)cellImage { 45 cellImage:(NSImage*)cellImage {
46 if ((self = [super initTextCell:cellText])) { 46 if ((self = [super initTextCell:cellText])) {
47 [self configureBookmarkButtonCell]; 47 [self configureBookmarkButtonCell];
48 48
49 [self setTextColor:[NSColor redColor]];
50
49 [self setBookmarkNode:node]; 51 [self setBookmarkNode:node];
50 52
51 if (node) { 53 if (node) {
52 NSString* title = base::SysUTF16ToNSString(node->GetTitle()); 54 NSString* title = base::SysUTF16ToNSString(node->GetTitle());
53 [self setBookmarkCellText:title image:cellImage]; 55 [self setBookmarkCellText:title image:cellImage];
54 [self setMenu:contextMenu]; 56 [self setMenu:contextMenu];
55 } else { 57 } else {
56 [self setEmpty:YES]; 58 [self setEmpty:YES];
57 [self setBookmarkCellText:l10n_util::GetNSString(IDS_MENU_EMPTY_SUBMENU) 59 [self setBookmarkCellText:l10n_util::GetNSString(IDS_MENU_EMPTY_SUBMENU)
58 image:nil]; 60 image:nil];
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 UserMetrics::RecordAction(UserMetricsAction("BookmarkBarFolder_CtxMenu")); 155 UserMetrics::RecordAction(UserMetricsAction("BookmarkBarFolder_CtxMenu"));
154 } else { 156 } else {
155 UserMetrics::RecordAction(UserMetricsAction("BookmarkBar_CtxMenu")); 157 UserMetrics::RecordAction(UserMetricsAction("BookmarkBar_CtxMenu"));
156 } 158 }
157 159
158 [menu setRepresentedObject:[NSNumber numberWithLongLong:node->id()]]; 160 [menu setRepresentedObject:[NSNumber numberWithLongLong:node->id()]];
159 161
160 return menu; 162 return menu;
161 } 163 }
162 164
163 // Unfortunately, NSCell doesn't already have something like this. 165 - (void)setTitle:(NSString*)title {
164 // TODO(jrg): consider placing in GTM. 166 if ([[self title] isEqualTo:title])
167 return;
168 [super setTitle:title];
169 [self applyTextColor];
170 }
171
165 - (void)setTextColor:(NSColor*)color { 172 - (void)setTextColor:(NSColor*)color {
173 if ([textColor_ isEqualTo:color])
174 return;
175 textColor_.reset([color copy]);
176 [self applyTextColor];
177 }
166 178
167 // We can't properly set the cell's text color without a control. 179 - (void)applyTextColor {
168 // In theory we could just save the next for later and wait until
169 // the cell is moved to a control, but there is no obvious way to
170 // accomplish that (e.g. no "cellDidMoveToControl" notification.)
171 DCHECK([self controlView]);
172
173 scoped_nsobject<NSMutableParagraphStyle> style([NSMutableParagraphStyle new]); 180 scoped_nsobject<NSMutableParagraphStyle> style([NSMutableParagraphStyle new]);
174 [style setAlignment:NSLeftTextAlignment]; 181 [style setAlignment:NSLeftTextAlignment];
175 NSDictionary* dict = [NSDictionary 182 NSDictionary* dict = [NSDictionary
176 dictionaryWithObjectsAndKeys:color, 183 dictionaryWithObjectsAndKeys:textColor_,
177 NSForegroundColorAttributeName, 184 NSForegroundColorAttributeName,
178 [self font], NSFontAttributeName, 185 [self font], NSFontAttributeName,
179 style.get(), NSParagraphStyleAttributeName, 186 style.get(), NSParagraphStyleAttributeName,
180 nil]; 187 nil];
181 scoped_nsobject<NSAttributedString> ats([[NSAttributedString alloc] 188 scoped_nsobject<NSAttributedString> ats([[NSAttributedString alloc]
182 initWithString:[self title] 189 initWithString:[self title]
183 attributes:dict]); 190 attributes:dict]);
184 NSButton* button = static_cast<NSButton*>([self controlView]); 191 [self setAttributedTitle:ats.get()];
185 if (button) {
186 DCHECK([button isKindOfClass:[NSButton class]]);
187 [button setAttributedTitle:ats.get()];
188 }
189 } 192 }
190 193
191 // To implement "hover open a bookmark button to open the folder" 194 // To implement "hover open a bookmark button to open the folder"
192 // which feels like menus, we override NSButtonCell's mouseEntered: 195 // which feels like menus, we override NSButtonCell's mouseEntered:
193 // and mouseExited:, then and pass them along to our owning control. 196 // and mouseExited:, then and pass them along to our owning control.
194 // Note: as verified in a debugger, mouseEntered: does NOT increase 197 // Note: as verified in a debugger, mouseEntered: does NOT increase
195 // the retainCount of the cell or its owning control. 198 // the retainCount of the cell or its owning control.
196 - (void)mouseEntered:(NSEvent*)event { 199 - (void)mouseEntered:(NSEvent*)event {
197 [super mouseEntered:event]; 200 [super mouseEntered:event];
198 [[self controlView] mouseEntered:event]; 201 [[self controlView] mouseEntered:event];
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 NSRect drawRect = NSOffsetRect(imageRect, dX, dY); 245 NSRect drawRect = NSOffsetRect(imageRect, dX, dY);
243 [arrowImage_ drawInRect:drawRect 246 [arrowImage_ drawInRect:drawRect
244 fromRect:imageRect 247 fromRect:imageRect
245 operation:NSCompositeSourceOver 248 operation:NSCompositeSourceOver
246 fraction:[self isEnabled] ? 1.0 : 0.5 249 fraction:[self isEnabled] ? 1.0 : 0.5
247 neverFlipped:YES]; 250 neverFlipped:YES];
248 } 251 }
249 } 252 }
250 253
251 @end 254 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698