summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/bookmark_button_cell.mm
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-20 22:33:14 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-20 22:33:14 +0000
commit60123ad4520e5561950d5cc949e1a0451abd4dcc (patch)
tree68035b12a4d0b9b975e87b871c0bd95f083391b0 /chrome/browser/cocoa/bookmark_button_cell.mm
parent6e948a40ee9134cfba48eb6d007378a4f4c11a8d (diff)
downloadchromium_src-60123ad4520e5561950d5cc949e1a0451abd4dcc.zip
chromium_src-60123ad4520e5561950d5cc949e1a0451abd4dcc.tar.gz
chromium_src-60123ad4520e5561950d5cc949e1a0451abd4dcc.tar.bz2
Apply theme color to bookmark button text.
BUG=http://crbug.com/17608 TEST=Add some bookmarks (you must use both folders and marks). Apply a theme and make sure theme color applies bookmark button text for all buttons (including "Other bookmarks"). Create new window and make sure bookmark buttons still fine in new window. Quit and restart Chrome. Make sure theme color still applied to bookmark button text in the same way as before quitting (e.g. same color and still applies to all). Change theme 1 more time and verify color. Review URL: http://codereview.chromium.org/424004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32690 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/bookmark_button_cell.mm')
-rw-r--r--chrome/browser/cocoa/bookmark_button_cell.mm38
1 files changed, 33 insertions, 5 deletions
diff --git a/chrome/browser/cocoa/bookmark_button_cell.mm b/chrome/browser/cocoa/bookmark_button_cell.mm
index 147ae04..cd8e5a8 100644
--- a/chrome/browser/cocoa/bookmark_button_cell.mm
+++ b/chrome/browser/cocoa/bookmark_button_cell.mm
@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/logging.h"
#import "chrome/browser/cocoa/bookmark_button_cell.h"
#import "chrome/browser/cocoa/bookmark_menu.h"
#import "third_party/GTM/AppKit/GTMTheme.h"
@implementation BookmarkButtonCell
-- (id)initTextCell:(NSString *)string {
+- (id)initTextCell:(NSString*)string {
if ((self = [super initTextCell:string])) {
[self setButtonType:NSMomentaryPushInButton];
[self setBezelStyle:NSShadowlessSquareBezelStyle];
@@ -41,15 +42,21 @@
withString:@" "];
title = [title stringByReplacingOccurrencesOfString:@"\r"
withString:@" "];
+ // Center the image if we have a title, or if there already was a
+ // title set.
+ BOOL hasTitle = (([title length] > 0) ||
+ ([[self title] length] > 0));
if (image) {
[self setImage:image];
- if ([title length] < 1) {
- [self setImagePosition:NSImageOnly];
- } else {
+ if (hasTitle) {
[self setImagePosition:NSImageLeft];
+ } else {
+ [self setImagePosition:NSImageOnly];
}
}
- [self setTitle:title];
+
+ if (title)
+ [self setTitle:title];
}
// We share the context menu among all bookmark buttons. To allow us
@@ -61,4 +68,25 @@
return menu;
}
+// Unfortunately, NSCell doesn't already have something like this.
+// TODO(jrg): consider placing in GTM.
+- (void)setTextColor:(NSColor*)color {
+ scoped_nsobject<NSMutableParagraphStyle> style([NSMutableParagraphStyle new]);
+ [style setAlignment:NSCenterTextAlignment];
+ NSDictionary* dict = [NSDictionary
+ dictionaryWithObjectsAndKeys:color,
+ NSForegroundColorAttributeName,
+ [self font], NSFontAttributeName,
+ style.get(), NSParagraphStyleAttributeName,
+ nil];
+ scoped_nsobject<NSAttributedString> ats([[NSAttributedString alloc]
+ initWithString:[self title]
+ attributes:dict]);
+ NSButton* button = static_cast<NSButton*>([self controlView]);
+ if (button) {
+ DCHECK([button isKindOfClass:[NSButton class]]);
+ [button setAttributedTitle:ats.get()];
+ }
+}
+
@end