OLD | NEW |
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 #include "app/l10n_util_mac.h" | 5 #include "app/l10n_util_mac.h" |
6 #include "app/resource_bundle.h" | 6 #include "app/resource_bundle.h" |
7 #include "base/mac_util.h" | 7 #include "base/mac_util.h" |
8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
9 #include "chrome/browser/bookmarks/bookmark_editor.h" | 9 #include "chrome/browser/bookmarks/bookmark_editor.h" |
10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 - (void)clearBookmarkBar { | 587 - (void)clearBookmarkBar { |
588 [buttons_ makeObjectsPerformSelector:@selector(removeFromSuperview)]; | 588 [buttons_ makeObjectsPerformSelector:@selector(removeFromSuperview)]; |
589 [buttons_ removeAllObjects]; | 589 [buttons_ removeAllObjects]; |
590 [self clearMenuTagMap]; | 590 [self clearMenuTagMap]; |
591 } | 591 } |
592 | 592 |
593 // Return an autoreleased NSCell suitable for a bookmark button. | 593 // Return an autoreleased NSCell suitable for a bookmark button. |
594 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. | 594 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. |
595 - (NSCell*)cellForBookmarkNode:(const BookmarkNode*)node { | 595 - (NSCell*)cellForBookmarkNode:(const BookmarkNode*)node { |
596 NSString* title = base::SysWideToNSString(node->GetTitle()); | 596 NSString* title = base::SysWideToNSString(node->GetTitle()); |
597 NSButtonCell *cell = [[[BookmarkButtonCell alloc] initTextCell:nil] | 597 BookmarkButtonCell* cell = |
598 autorelease]; | 598 [[[BookmarkButtonCell alloc] initTextCell:nil] autorelease]; |
599 DCHECK(cell); | 599 DCHECK(cell); |
600 [cell setRepresentedObject:[NSValue valueWithPointer:node]]; | 600 [cell setRepresentedObject:[NSValue valueWithPointer:node]]; |
601 | 601 |
602 [cell setImage:[self getFavIconForNode:node]]; | 602 NSImage* image = [self getFavIconForNode:node]; |
603 [cell setImagePosition:NSImageLeft]; | 603 [cell setBookmarkCellText:title image:image]; |
604 [cell setTitle:title]; | |
605 [cell setMenu:buttonContextMenu_]; | 604 [cell setMenu:buttonContextMenu_]; |
606 return cell; | 605 return cell; |
607 } | 606 } |
608 | 607 |
609 // Return an appropriate width for the given bookmark button cell. | 608 // Return an appropriate width for the given bookmark button cell. |
610 // The "+2" is needed because, sometimes, Cocoa is off by a tad. | 609 // The "+2" is needed because, sometimes, Cocoa is off by a tad. |
611 // Example: for a bookmark named "Moma" or "SFGate", it is one pixel | 610 // Example: for a bookmark named "Moma" or "SFGate", it is one pixel |
612 // too small. For "FBL" it is 2 pixels too small. | 611 // too small. For "FBL" it is 2 pixels too small. |
613 // For a bookmark named "SFGateFooWoo", it is just fine. | 612 // For a bookmark named "SFGateFooWoo", it is just fine. |
614 - (CGFloat)widthForBookmarkButtonCell:(NSCell*)cell { | 613 - (CGFloat)widthForBookmarkButtonCell:(NSCell*)cell { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 // Need a BookmarkNode-->NSCell mapping. | 854 // Need a BookmarkNode-->NSCell mapping. |
856 // | 855 // |
857 // TODO(jrg): if the bookmark bar is open on launch, we see the | 856 // TODO(jrg): if the bookmark bar is open on launch, we see the |
858 // buttons all placed, then "scooted over" as the favicons load. If | 857 // buttons all placed, then "scooted over" as the favicons load. If |
859 // this looks bad I may need to change widthForBookmarkButtonCell to | 858 // this looks bad I may need to change widthForBookmarkButtonCell to |
860 // add space for an image even if not there on the assumption that | 859 // add space for an image even if not there on the assumption that |
861 // favicons will eventually load. | 860 // favicons will eventually load. |
862 - (void)nodeFavIconLoaded:(BookmarkModel*)model | 861 - (void)nodeFavIconLoaded:(BookmarkModel*)model |
863 node:(const BookmarkNode*)node { | 862 node:(const BookmarkNode*)node { |
864 for (NSButton* button in buttons_.get()) { | 863 for (NSButton* button in buttons_.get()) { |
865 NSButtonCell* cell = [button cell]; | 864 BookmarkButtonCell* cell = [button cell]; |
866 void* pointer = [[cell representedObject] pointerValue]; | 865 void* pointer = [[cell representedObject] pointerValue]; |
867 const BookmarkNode* cellnode = static_cast<const BookmarkNode*>(pointer); | 866 const BookmarkNode* cellnode = static_cast<const BookmarkNode*>(pointer); |
868 if (cellnode == node) { | 867 if (cellnode == node) { |
869 [cell setImage:[self getFavIconForNode:node]]; | 868 [cell setBookmarkCellText:[cell title] |
870 [cell setImagePosition:NSImageLeft]; | 869 image:[self getFavIconForNode:node]]; |
871 // Adding an image means we might need more room for the | 870 // Adding an image means we might need more room for the |
872 // bookmark. Test for it by growing the button (if needed) | 871 // bookmark. Test for it by growing the button (if needed) |
873 // and shifting everything else over. | 872 // and shifting everything else over. |
874 [self checkForBookmarkButtonGrowth:button]; | 873 [self checkForBookmarkButtonGrowth:button]; |
875 } | 874 } |
876 } | 875 } |
877 } | 876 } |
878 | 877 |
879 // TODO(jrg): for now this is brute force. | 878 // TODO(jrg): for now this is brute force. |
880 - (void)nodeChildrenReordered:(BookmarkModel*)model | 879 - (void)nodeChildrenReordered:(BookmarkModel*)model |
(...skipping 22 matching lines...) Expand all Loading... |
903 return folderImage_; | 902 return folderImage_; |
904 | 903 |
905 const SkBitmap& favIcon = bookmarkModel_->GetFavIcon(node); | 904 const SkBitmap& favIcon = bookmarkModel_->GetFavIcon(node); |
906 if (!favIcon.isNull()) | 905 if (!favIcon.isNull()) |
907 return gfx::SkBitmapToNSImage(favIcon); | 906 return gfx::SkBitmapToNSImage(favIcon); |
908 | 907 |
909 return defaultImage_; | 908 return defaultImage_; |
910 } | 909 } |
911 | 910 |
912 @end | 911 @end |
OLD | NEW |