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

Side by Side Diff: chrome/browser/cocoa/bookmark_bar_controller.mm

Issue 2958016: Give imported bookmarks the properly themed button text.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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
« no previous file with comments | « chrome/browser/cocoa/bookmark_bar_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/cocoa/bookmark_bar_controller.h" 5 #import "chrome/browser/cocoa/bookmark_bar_controller.h"
6 #include "app/l10n_util_mac.h" 6 #include "app/l10n_util_mac.h"
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/mac_util.h" 8 #include "base/mac_util.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/browser/bookmarks/bookmark_editor.h" 10 #include "chrome/browser/bookmarks/bookmark_editor.h"
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 const BookmarkNode* child = node->GetChild(i); 984 const BookmarkNode* child = node->GetChild(i);
985 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; 985 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset];
986 if (NSMinX([button frame]) >= maxViewX) 986 if (NSMinX([button frame]) >= maxViewX)
987 break; 987 break;
988 [buttons_ addObject:button]; 988 [buttons_ addObject:button];
989 } 989 }
990 } 990 }
991 991
992 - (BookmarkButton*)buttonForNode:(const BookmarkNode*)node 992 - (BookmarkButton*)buttonForNode:(const BookmarkNode*)node
993 xOffset:(int*)xOffset { 993 xOffset:(int*)xOffset {
994 NSCell* cell = [self cellForBookmarkNode:node]; 994 BookmarkButtonCell* cell = [self cellForBookmarkNode:node];
995 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:xOffset]; 995 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:xOffset];
996 996
997 scoped_nsobject<BookmarkButton> 997 scoped_nsobject<BookmarkButton>
998 button([[BookmarkButton alloc] initWithFrame:frame]); 998 button([[BookmarkButton alloc] initWithFrame:frame]);
999 DCHECK(button.get()); 999 DCHECK(button.get());
1000 1000
1001 // [NSButton setCell:] warns to NOT use setCell: other than in the 1001 // [NSButton setCell:] warns to NOT use setCell: other than in the
1002 // initializer of a control. However, we are using a basic 1002 // initializer of a control. However, we are using a basic
1003 // NSButton whose initializer does not take an NSCell as an 1003 // NSButton whose initializer does not take an NSCell as an
1004 // object. To honor the assumed semantics, we do nothing with 1004 // object. To honor the assumed semantics, we do nothing with
1005 // NSButton between alloc/init and setCell:. 1005 // NSButton between alloc/init and setCell:.
1006 [button setCell:cell]; 1006 [button setCell:cell];
1007 [button setDelegate:self]; 1007 [button setDelegate:self];
1008 1008
1009 // We cannot set the button cell's text color until it is placed in
1010 // the button (e.g. the [button setCell:cell] call right above). We
1011 // also cannot set the cell's text color until the view is added to
1012 // the hierarchy. If that second part is now true, set the color.
1013 // (If not we'll set the color on the 1st themeChanged:
1014 // notification.)
1015 ThemeProvider* themeProvider = [[[self view] window] themeProvider];
1016 if (themeProvider) {
1017 NSColor* color =
1018 themeProvider->GetNSColor(BrowserThemeProvider::COLOR_BOOKMARK_TEXT,
1019 true);
1020 [cell setTextColor:color];
1021 }
1022
1009 if (node->is_folder()) { 1023 if (node->is_folder()) {
1010 [button setTarget:self]; 1024 [button setTarget:self];
1011 [button setAction:@selector(openBookmarkFolderFromButton:)]; 1025 [button setAction:@selector(openBookmarkFolderFromButton:)];
1012 } else { 1026 } else {
1013 // Make the button do something 1027 // Make the button do something
1014 [button setTarget:self]; 1028 [button setTarget:self];
1015 [button setAction:@selector(openBookmark:)]; 1029 [button setAction:@selector(openBookmark:)];
1016 // Add a tooltip. 1030 // Add a tooltip.
1017 NSString* title = base::SysWideToNSString(node->GetTitle()); 1031 NSString* title = base::SysWideToNSString(node->GetTitle());
1018 std::string url_string = node->GetURL().possibly_invalid_spec(); 1032 std::string url_string = node->GetURL().possibly_invalid_spec();
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 // Unfortunately the clearContents selector is 10.6 only. The best 1376 // Unfortunately the clearContents selector is 10.6 only. The best
1363 // we can do is make sure something else is present in place of the 1377 // we can do is make sure something else is present in place of the
1364 // stale bookmark. 1378 // stale bookmark.
1365 NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; 1379 NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
1366 [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self]; 1380 [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self];
1367 [pboard setString:@"" forType:NSStringPboardType]; 1381 [pboard setString:@"" forType:NSStringPboardType];
1368 } 1382 }
1369 1383
1370 // Return an autoreleased NSCell suitable for a bookmark button. 1384 // Return an autoreleased NSCell suitable for a bookmark button.
1371 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. 1385 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class.
1372 - (NSCell*)cellForBookmarkNode:(const BookmarkNode*)node { 1386 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)node {
1373 NSImage* image = node ? [self favIconForNode:node] : nil; 1387 NSImage* image = node ? [self favIconForNode:node] : nil;
1374 NSMenu* menu = node && node->is_folder() ? buttonFolderContextMenu_ : 1388 NSMenu* menu = node && node->is_folder() ? buttonFolderContextMenu_ :
1375 buttonContextMenu_; 1389 buttonContextMenu_;
1376 BookmarkButtonCell* cell = [BookmarkButtonCell buttonCellForNode:node 1390 BookmarkButtonCell* cell = [BookmarkButtonCell buttonCellForNode:node
1377 contextMenu:menu 1391 contextMenu:menu
1378 cellText:nil 1392 cellText:nil
1379 cellImage:image]; 1393 cellImage:image];
1380 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; 1394 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
1381 1395
1382 // Note: a quirk of setting a cell's text color is that it won't work 1396 // Note: a quirk of setting a cell's text color is that it won't work
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 // to minimize touching the object passed in (likely a mock). 2354 // to minimize touching the object passed in (likely a mock).
2341 - (void)setButtonContextMenu:(id)menu { 2355 - (void)setButtonContextMenu:(id)menu {
2342 buttonContextMenu_ = menu; 2356 buttonContextMenu_ = menu;
2343 } 2357 }
2344 2358
2345 - (void)setIgnoreAnimations:(BOOL)ignore { 2359 - (void)setIgnoreAnimations:(BOOL)ignore {
2346 ignoreAnimations_ = ignore; 2360 ignoreAnimations_ = ignore;
2347 } 2361 }
2348 2362
2349 @end 2363 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_bar_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698