diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-20 22:33:14 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-20 22:33:14 +0000 |
commit | 60123ad4520e5561950d5cc949e1a0451abd4dcc (patch) | |
tree | 68035b12a4d0b9b975e87b871c0bd95f083391b0 /chrome/browser/cocoa/bookmark_bar_controller.mm | |
parent | 6e948a40ee9134cfba48eb6d007378a4f4c11a8d (diff) | |
download | chromium_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_bar_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.mm | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm index d1c9861..7b8bf6a 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller.mm @@ -182,6 +182,13 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; folderImage_.reset([rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER) retain]); defaultImage_.reset([rb.GetNSImageNamed(IDR_DEFAULT_FAVICON) retain]); + // Register for theme changes. + NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; + [defaultCenter addObserver:self + selector:@selector(themeDidChangeNotification:) + name:kGTMThemeDidChangeNotification + object:nil]; + // This call triggers an awakeFromNib, which builds the bar, which // might uses folderImage_. So make sure it happens after // folderImage_ is loaded. @@ -204,6 +211,30 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; [super dealloc]; } +// Adapt appearance of buttons to the current theme. Called after +// theme changes, or when our view is added to the view hierarchy. +// Oddly, the view pings us instead of us pinging our view. This is +// because our trigger is an [NSView viewWillMoveToWindow:], which the +// controller doesn't normally know about. Otherwise we don't have +// access to the theme before we know what window we will be on. +- (void)updateTheme:(GTMTheme*)theme { + if (!theme) + return; + NSColor* color = [theme textColorForStyle:GTMThemeStyleBookmarksBarButton + state:GTMThemeStateActiveWindow]; + for (BookmarkButton* button in buttons_.get()) { + BookmarkButtonCell* cell = [button cell]; + [cell setTextColor:color]; + } + [[otherBookmarksButton_ cell] setTextColor:color]; +} + +// Called after the current theme has changed. +- (void)themeDidChangeNotification:(NSNotification*)aNotification { + GTMTheme* theme = [aNotification object]; + [self updateTheme:theme]; +} + - (void)awakeFromNib { // We default to NOT open, which means height=0. DCHECK([[self view] isHidden]); // Hidden so it's OK to change. @@ -866,7 +897,8 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; - (NSCell*)cellForBookmarkNode:(const BookmarkNode*)node { NSString* title = base::SysWideToNSString(node->GetTitle()); BookmarkButtonCell* cell = - [[[BookmarkButtonCell alloc] initTextCell:nil] autorelease]; + [[[BookmarkButtonCell alloc] initTextCell:nil] + autorelease]; DCHECK(cell); [cell setRepresentedObject:[NSValue valueWithPointer:node]]; @@ -1088,6 +1120,7 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; [self clearBookmarkBar]; [self addNodesToButtonList:node]; [self createOtherBookmarksButton]; + [self updateTheme:[[self view] gtm_theme]]; [self resizeButtons]; [self positionOffTheSideButton]; [self addNonBookmarkButtonsToView]; @@ -1148,7 +1181,7 @@ const NSTimeInterval kBookmarkBarAnimationDuration = 0.12; void* pointer = [[cell representedObject] pointerValue]; const BookmarkNode* cellnode = static_cast<const BookmarkNode*>(pointer); if (cellnode == node) { - [cell setBookmarkCellText:[cell title] + [cell setBookmarkCellText:nil image:[self getFavIconForNode:node]]; // Adding an image means we might need more room for the // bookmark. Test for it by growing the button (if needed) |