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

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

Issue 131018: Add favicons to tabs on the Mac (Closed)
Patch Set: Rebase Created 11 years, 6 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
« no previous file with comments | « chrome/browser/cocoa/cocoa_utils_unittest.mm ('k') | chrome/chrome.gyp » ('j') | 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/tab_strip_controller.h" 5 #import "chrome/browser/cocoa/tab_strip_controller.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/mac_util.h"
8 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
9 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/browser.h" 11 #include "chrome/browser/browser.h"
11 #include "chrome/browser/metrics/user_metrics.h" 12 #include "chrome/browser/metrics/user_metrics.h"
12 #include "chrome/browser/profile.h" 13 #include "chrome/browser/profile.h"
13 #import "chrome/browser/cocoa/tab_strip_view.h" 14 #import "chrome/browser/cocoa/tab_strip_view.h"
14 #import "chrome/browser/cocoa/tab_cell.h" 15 #import "chrome/browser/cocoa/tab_cell.h"
15 #import "chrome/browser/cocoa/tab_contents_controller.h" 16 #import "chrome/browser/cocoa/tab_contents_controller.h"
16 #import "chrome/browser/cocoa/tab_controller.h" 17 #import "chrome/browser/cocoa/tab_controller.h"
17 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" 18 #import "chrome/browser/cocoa/tab_strip_model_observer_bridge.h"
18 #import "chrome/browser/cocoa/tab_view.h" 19 #import "chrome/browser/cocoa/tab_view.h"
19 #import "chrome/browser/cocoa/throbber_view.h" 20 #import "chrome/browser/cocoa/throbber_view.h"
21 #include "chrome/browser/tab_contents/navigation_controller.h"
22 #include "chrome/browser/tab_contents/navigation_entry.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 23 #include "chrome/browser/tab_contents/tab_contents.h"
21 #include "chrome/browser/tab_contents/tab_contents_view.h" 24 #include "chrome/browser/tab_contents/tab_contents_view.h"
22 #include "chrome/browser/tabs/tab_strip_model.h" 25 #include "chrome/browser/tabs/tab_strip_model.h"
23 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
27 #include "skia/ext/skia_utils_mac.h"
24 28
25 NSString* const kTabStripNumberOfTabsChanged = @"kTabStripNumberOfTabsChanged"; 29 NSString* const kTabStripNumberOfTabsChanged = @"kTabStripNumberOfTabsChanged";
26 30
27 // A simple view class that prevents the windowserver from dragging the 31 // A simple view class that prevents the windowserver from dragging the
28 // area behind tabs. Sometimes core animation confuses it. 32 // area behind tabs. Sometimes core animation confuses it.
29 @interface TabStripControllerDragBlockingView : NSView 33 @interface TabStripControllerDragBlockingView : NSView
30 @end 34 @end
31 @implementation TabStripControllerDragBlockingView 35 @implementation TabStripControllerDragBlockingView
32 - (BOOL)mouseDownCanMoveWindow {return NO;} 36 - (BOOL)mouseDownCanMoveWindow {return NO;}
33 - (void)drawRect:(NSRect)rect {} 37 - (void)drawRect:(NSRect)rect {}
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // Send a broadcast that the number of tabs have changed. 417 // Send a broadcast that the number of tabs have changed.
414 [[NSNotificationCenter defaultCenter] 418 [[NSNotificationCenter defaultCenter]
415 postNotificationName:kTabStripNumberOfTabsChanged 419 postNotificationName:kTabStripNumberOfTabsChanged
416 object:self]; 420 object:self];
417 421
418 [self layoutTabs]; 422 [self layoutTabs];
419 } 423 }
420 424
421 // A helper routine for creating an NSImageView to hold the fav icon for 425 // A helper routine for creating an NSImageView to hold the fav icon for
422 // |contents|. 426 // |contents|.
423 // TODO(pinkerton): fill in with code to use the real favicon, not the default
424 // for all cases.
425 - (NSImageView*)favIconImageViewForContents:(TabContents*)contents { 427 - (NSImageView*)favIconImageViewForContents:(TabContents*)contents {
426 NSRect iconFrame = NSMakeRect(0, 0, 16, 16); 428 NSRect iconFrame = NSMakeRect(0, 0, 16, 16);
427 NSImageView* view = [[[NSImageView alloc] initWithFrame:iconFrame] 429 NSImageView* view = [[[NSImageView alloc] initWithFrame:iconFrame]
428 autorelease]; 430 autorelease];
429 [view setImage:[NSImage imageNamed:@"nav"]]; 431
432 NSImage* image = nil;
433
434 NavigationEntry* navEntry = contents->controller().GetLastCommittedEntry();
435 if (navEntry != NULL) {
436 NavigationEntry::FaviconStatus favIcon = navEntry->favicon();
437 const SkBitmap& bitmap = favIcon.bitmap();
438 if (favIcon.is_valid() && !bitmap.isNull())
439 image = gfx::SkBitmapToNSImage(bitmap);
440 }
441
442 // Either we don't have a valid favicon or there was some issue converting it
443 // from an SkBitmap. Either way, just show the default.
444 if (!image) {
445 NSBundle* bundle = mac_util::MainAppBundle();
446 image = [[NSImage alloc] initByReferencingFile:
447 [bundle pathForResource:@"nav" ofType:@"pdf"]];
448 [image autorelease];
449 }
450
451 [view setImage:image];
430 return view; 452 return view;
431 } 453 }
432 454
433 // Called when a notification is received from the model that the given tab 455 // Called when a notification is received from the model that the given tab
434 // has been updated. |loading| will be YES when we only want to update the 456 // has been updated. |loading| will be YES when we only want to update the
435 // throbber state, not anything else about the (partially) loading tab. 457 // throbber state, not anything else about the (partially) loading tab.
436 - (void)tabChangedWithContents:(TabContents*)contents 458 - (void)tabChangedWithContents:(TabContents*)contents
437 atIndex:(NSInteger)index 459 atIndex:(NSInteger)index
438 loadingOnly:(BOOL)loading { 460 loadingOnly:(BOOL)loading {
439 if (!loading) 461 if (!loading)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 selectedIndex = 0; 582 selectedIndex = 0;
561 } 583 }
562 TabContentsController* selectedController = 584 TabContentsController* selectedController =
563 [tabContentsArray_ objectAtIndex:selectedIndex]; 585 [tabContentsArray_ objectAtIndex:selectedIndex];
564 if (!selectedController) 586 if (!selectedController)
565 return NSZeroRect; 587 return NSZeroRect;
566 return [selectedController growBoxRect]; 588 return [selectedController growBoxRect];
567 } 589 }
568 590
569 @end 591 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/cocoa_utils_unittest.mm ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698