| 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 "base/sys_string_conversions.h" | 5 #include "base/sys_string_conversions.h" |
| 6 #include "chrome/browser/bookmarks/bookmark_model.h" | 6 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/browser/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
| 9 #import "chrome/browser/cocoa/bookmark_bar_bridge.h" | 9 #import "chrome/browser/cocoa/bookmark_bar_bridge.h" |
| 10 #import "chrome/browser/cocoa/bookmark_bar_controller.h" | 10 #import "chrome/browser/cocoa/bookmark_bar_controller.h" |
| 11 #import "chrome/browser/cocoa/bookmark_bar_view.h" | 11 #import "chrome/browser/cocoa/bookmark_bar_view.h" |
| 12 #import "chrome/browser/cocoa/bookmark_button_cell.h" | 12 #import "chrome/browser/cocoa/bookmark_button_cell.h" |
| 13 #import "chrome/browser/cocoa/cocoa_utils.h" | |
| 14 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
| 15 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/common/pref_service.h" | 15 #include "chrome/common/pref_service.h" |
| 17 | 16 #include "skia/ext/skia_utils_mac.h" |
| 18 using namespace CocoaUtils; | |
| 19 | 17 |
| 20 @interface BookmarkBarController(Private) | 18 @interface BookmarkBarController(Private) |
| 21 - (void)applyContentAreaOffset:(BOOL)apply; | 19 - (void)applyContentAreaOffset:(BOOL)apply; |
| 22 - (void)positionBar; | 20 - (void)positionBar; |
| 23 - (void)showBookmarkBar:(BOOL)enable; | 21 - (void)showBookmarkBar:(BOOL)enable; |
| 24 @end | 22 @end |
| 25 | 23 |
| 26 namespace { | 24 namespace { |
| 27 const int kBookmarkBarHeight = 30; | 25 const int kBookmarkBarHeight = 30; |
| 28 // Magic numbers from Cole | 26 // Magic numbers from Cole |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 DCHECK(cell); | 158 DCHECK(cell); |
| 161 [cell setRepresentedObject:[NSValue valueWithPointer:node]]; | 159 [cell setRepresentedObject:[NSValue valueWithPointer:node]]; |
| 162 [cell setButtonType:NSMomentaryPushInButton]; | 160 [cell setButtonType:NSMomentaryPushInButton]; |
| 163 [cell setBezelStyle:NSShadowlessSquareBezelStyle]; | 161 [cell setBezelStyle:NSShadowlessSquareBezelStyle]; |
| 164 [cell setShowsBorderOnlyWhileMouseInside:YES]; | 162 [cell setShowsBorderOnlyWhileMouseInside:YES]; |
| 165 | 163 |
| 166 // The favicon may be NULL if we haven't loaded it yet. Bookmarks | 164 // The favicon may be NULL if we haven't loaded it yet. Bookmarks |
| 167 // (and their icons) are loaded on the IO thread to speed launch. | 165 // (and their icons) are loaded on the IO thread to speed launch. |
| 168 const SkBitmap& favicon = bookmarkModel_->GetFavIcon(node); | 166 const SkBitmap& favicon = bookmarkModel_->GetFavIcon(node); |
| 169 if (!favicon.isNull()) { | 167 if (!favicon.isNull()) { |
| 170 NSImage* image = SkBitmapToNSImage(favicon); | 168 NSImage* image = gfx::SkBitmapToNSImage(favicon); |
| 171 if (image) { | 169 if (image) { |
| 172 [cell setImage:image]; | 170 [cell setImage:image]; |
| 173 [cell setImagePosition:NSImageLeft]; | 171 [cell setImagePosition:NSImageLeft]; |
| 174 } | 172 } |
| 175 } | 173 } |
| 176 | 174 |
| 177 [cell setTitle:title]; | 175 [cell setTitle:title]; |
| 178 [cell setControlSize:NSSmallControlSize]; | 176 [cell setControlSize:NSSmallControlSize]; |
| 179 [cell setAlignment:NSLeftTextAlignment]; | 177 [cell setAlignment:NSLeftTextAlignment]; |
| 180 [cell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 178 [cell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 // TODO(jrg): linear searching is bad. | 286 // TODO(jrg): linear searching is bad. |
| 289 // Need a BookmarkNode-->NSCell mapping. | 287 // Need a BookmarkNode-->NSCell mapping. |
| 290 - (void)nodeFavIconLoaded:(BookmarkModel*)model | 288 - (void)nodeFavIconLoaded:(BookmarkModel*)model |
| 291 node:(BookmarkNode*)node { | 289 node:(BookmarkNode*)node { |
| 292 NSArray* views = [bookmarkBarView_ subviews]; | 290 NSArray* views = [bookmarkBarView_ subviews]; |
| 293 for (NSButton* button in views) { | 291 for (NSButton* button in views) { |
| 294 NSButtonCell* cell = [button cell]; | 292 NSButtonCell* cell = [button cell]; |
| 295 void* pointer = [[cell representedObject] pointerValue]; | 293 void* pointer = [[cell representedObject] pointerValue]; |
| 296 BookmarkNode* cellnode = static_cast<BookmarkNode*>(pointer); | 294 BookmarkNode* cellnode = static_cast<BookmarkNode*>(pointer); |
| 297 if (cellnode == node) { | 295 if (cellnode == node) { |
| 298 NSImage* image = SkBitmapToNSImage(bookmarkModel_->GetFavIcon(node)); | 296 NSImage* image = gfx::SkBitmapToNSImage(bookmarkModel_->GetFavIcon(node)); |
| 299 if (image) { | 297 if (image) { |
| 300 [cell setImage:image]; | 298 [cell setImage:image]; |
| 301 [cell setImagePosition:NSImageLeft]; | 299 [cell setImagePosition:NSImageLeft]; |
| 302 } | 300 } |
| 303 return; | 301 return; |
| 304 } | 302 } |
| 305 } | 303 } |
| 306 } | 304 } |
| 307 | 305 |
| 308 // TODO(jrg): for now this is brute force. | 306 // TODO(jrg): for now this is brute force. |
| 309 - (void)nodeChildrenReordered:(BookmarkModel*)model | 307 - (void)nodeChildrenReordered:(BookmarkModel*)model |
| 310 node:(BookmarkNode*)node { | 308 node:(BookmarkNode*)node { |
| 311 [self loaded:model]; | 309 [self loaded:model]; |
| 312 } | 310 } |
| 313 | 311 |
| 314 - (NSView*)view { | 312 - (NSView*)view { |
| 315 return bookmarkBarView_; | 313 return bookmarkBarView_; |
| 316 } | 314 } |
| 317 | 315 |
| 318 @end | 316 @end |
| OLD | NEW |