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

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

Issue 174074: Check the favicon and loading state when a tab is created in case its TabCont... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 4 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 | « no previous file | 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/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/mac_util.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 - (BOOL)mouseDownCanMoveWindow {return NO;} 45 - (BOOL)mouseDownCanMoveWindow {return NO;}
46 - (void)drawRect:(NSRect)rect {} 46 - (void)drawRect:(NSRect)rect {}
47 @end 47 @end
48 48
49 @interface TabStripController(Private) 49 @interface TabStripController(Private)
50 - (void)installTrackingArea; 50 - (void)installTrackingArea;
51 - (BOOL)useFullWidthForLayout; 51 - (BOOL)useFullWidthForLayout;
52 - (void)addSubviewToPermanentList:(NSView*)aView; 52 - (void)addSubviewToPermanentList:(NSView*)aView;
53 - (void)regenerateSubviewList; 53 - (void)regenerateSubviewList;
54 - (NSInteger)indexForContentsView:(NSView*)view; 54 - (NSInteger)indexForContentsView:(NSView*)view;
55 - (void)updateFavIconForContents:(TabContents*)contents
56 atIndex:(NSInteger)index;
55 @end 57 @end
56 58
57 @implementation TabStripController 59 @implementation TabStripController
58 60
59 - (id)initWithView:(TabStripView*)view 61 - (id)initWithView:(TabStripView*)view
60 switchView:(NSView*)switchView 62 switchView:(NSView*)switchView
61 browser:(Browser*)browser { 63 browser:(Browser*)browser {
62 DCHECK(view && switchView && browser); 64 DCHECK(view && switchView && browser);
63 if ((self = [super init])) { 65 if ((self = [super init])) {
64 tabView_ = view; 66 tabView_ = view;
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // for layout. 487 // for layout.
486 availableResizeWidth_ = kUseFullAvailableWidth; 488 availableResizeWidth_ = kUseFullAvailableWidth;
487 489
488 // We don't need to call |-layoutTabs| if the tab will be in the foreground 490 // We don't need to call |-layoutTabs| if the tab will be in the foreground
489 // because it will get called when the new tab is selected by the tab model. 491 // because it will get called when the new tab is selected by the tab model.
490 // Whenever |-layoutTabs| is called, it'll also add the new subview. 492 // Whenever |-layoutTabs| is called, it'll also add the new subview.
491 if (!inForeground) { 493 if (!inForeground) {
492 [self layoutTabs]; 494 [self layoutTabs];
493 } 495 }
494 496
497 // During normal loading, we won't yet have a favicon and we'll get
498 // subsequent state change notifications to show the throbber, but when we're
499 // dragging a tab out into a new window, we have to put the tab's favicon
500 // into the right state up front as we won't be told to do it from anywhere
501 // else.
502 [self updateFavIconForContents:contents atIndex:index];
503
495 // Send a broadcast that the number of tabs have changed. 504 // Send a broadcast that the number of tabs have changed.
496 [[NSNotificationCenter defaultCenter] 505 [[NSNotificationCenter defaultCenter]
497 postNotificationName:kTabStripNumberOfTabsChanged 506 postNotificationName:kTabStripNumberOfTabsChanged
498 object:self]; 507 object:self];
499 } 508 }
500 509
501 // Called when a notification is received from the model to select a particular 510 // Called when a notification is received from the model to select a particular
502 // tab. Swaps in the toolbar and content area associated with |newContents|. 511 // tab. Swaps in the toolbar and content area associated with |newContents|.
503 - (void)selectTabWithContents:(TabContents*)newContents 512 - (void)selectTabWithContents:(TabContents*)newContents
504 previousContents:(TabContents*)oldContents 513 previousContents:(TabContents*)oldContents
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 NSBundle* bundle = mac_util::MainAppBundle(); 600 NSBundle* bundle = mac_util::MainAppBundle();
592 image = [[NSImage alloc] initByReferencingFile: 601 image = [[NSImage alloc] initByReferencingFile:
593 [bundle pathForResource:@"nav" ofType:@"pdf"]]; 602 [bundle pathForResource:@"nav" ofType:@"pdf"]];
594 [image autorelease]; 603 [image autorelease];
595 } 604 }
596 605
597 [view setImage:image]; 606 [view setImage:image];
598 return view; 607 return view;
599 } 608 }
600 609
610 // Update the current loading state, replacing the favicon with a throbber, or
611 // vice versa. This will get called repeatedly with the same state during a
612 // load, so we need to make sure we're not creating the throbber view over and
613 // over. However, when the page is done, every state change is important.
614 - (void)updateFavIconForContents:(TabContents*)contents
615 atIndex:(NSInteger)index {
616 static NSImage* throbberWaitingImage =
617 [nsimage_cache::ImageNamed(@"throbber_waiting.png") retain];
618 static NSImage* throbberLoadingImage =
619 [nsimage_cache::ImageNamed(@"throbber.png") retain];
620 static NSImage* sadFaviconImage =
621 [nsimage_cache::ImageNamed(@"sadfavicon.png") retain];
622
623 if (!contents) return;
Mark Mentovai 2009/08/19 20:43:28 I'd put the return on a line by itself. I'd put i
624
625 TabController* tabController = [tabArray_ objectAtIndex:index];
626 TabLoadingState oldState = [tabController loadingState];
627
628 TabLoadingState newState = kTabDone;
629 NSImage* throbberImage = nil;
630 if (contents->waiting_for_response()) {
631 newState = kTabWaiting;
632 throbberImage = throbberWaitingImage;
633 } else if (contents->is_loading()) {
634 newState = kTabLoading;
635 throbberImage = throbberLoadingImage;
636 } else if (contents->is_crashed()) {
637 newState = kTabCrashed;
638 }
639
640 if (oldState != newState || newState == kTabDone) {
641 NSView* iconView = nil;
642 if (newState == kTabDone) {
643 iconView = [self favIconImageViewForContents:contents];
644 } else if (newState == kTabCrashed) {
645 NSImage* oldImage = [[self favIconImageViewForContents:contents] image];
646 NSRect frame = NSMakeRect(0, 0, 16, 16);
647 iconView = [ThrobberView toastThrobberViewWithFrame:frame
648 beforeImage:oldImage
649 afterImage:sadFaviconImage];
650 } else {
651 NSRect frame = NSMakeRect(0, 0, 16, 16);
652 iconView = [ThrobberView filmstripThrobberViewWithFrame:frame
653 image:throbberImage];
654 }
655
656 [tabController setLoadingState:newState];
657 [tabController setIconView:iconView];
658 }
659 }
660
601 // Called when a notification is received from the model that the given tab 661 // Called when a notification is received from the model that the given tab
602 // has been updated. |loading| will be YES when we only want to update the 662 // has been updated. |loading| will be YES when we only want to update the
603 // throbber state, not anything else about the (partially) loading tab. 663 // throbber state, not anything else about the (partially) loading tab.
604 - (void)tabChangedWithContents:(TabContents*)contents 664 - (void)tabChangedWithContents:(TabContents*)contents
605 atIndex:(NSInteger)index 665 atIndex:(NSInteger)index
606 loadingOnly:(BOOL)loading { 666 loadingOnly:(BOOL)loading {
607 if (!loading) 667 if (!loading)
608 [self setTabTitle:[tabArray_ objectAtIndex:index] withContents:contents]; 668 [self setTabTitle:[tabArray_ objectAtIndex:index] withContents:contents];
609 669
610 // Update the current loading state, replacing the icon with a throbber, or 670 [self updateFavIconForContents:contents atIndex:index];
611 // vice versa. This will get called repeatedly with the same state during a
612 // load, so we need to make sure we're not creating the throbber view over and
613 // over. However, when the page is done, every state change is important.
614 if (contents) {
615 static NSImage* throbberWaitingImage =
616 [nsimage_cache::ImageNamed(@"throbber_waiting.png") retain];
617 static NSImage* throbberLoadingImage =
618 [nsimage_cache::ImageNamed(@"throbber.png") retain];
619 static NSImage* sadFaviconImage =
620 [nsimage_cache::ImageNamed(@"sadfavicon.png") retain];
621
622 TabController* tabController = [tabArray_ objectAtIndex:index];
623
624 TabLoadingState oldState = [tabController loadingState];
625
626 TabLoadingState newState = kTabDone;
627 NSImage* throbberImage = nil;
628 if (contents->waiting_for_response()) {
629 newState = kTabWaiting;
630 throbberImage = throbberWaitingImage;
631 } else if (contents->is_loading()) {
632 newState = kTabLoading;
633 throbberImage = throbberLoadingImage;
634 } else if (contents->is_crashed()) {
635 newState = kTabCrashed;
636 }
637
638 if (oldState != newState || newState == kTabDone) {
639 NSView* iconView = nil;
640 if (newState == kTabDone) {
641 iconView = [self favIconImageViewForContents:contents];
642 } else if (newState == kTabCrashed) {
643 NSImage* oldImage = [[self favIconImageViewForContents:contents] image];
644 NSRect frame = NSMakeRect(0, 0, 16, 16);
645 iconView = [ThrobberView toastThrobberViewWithFrame:frame
646 beforeImage:oldImage
647 afterImage:sadFaviconImage];
648 } else {
649 NSRect frame = NSMakeRect(0, 0, 16, 16);
650 iconView = [ThrobberView filmstripThrobberViewWithFrame:frame
651 image:throbberImage];
652 }
653
654 [tabController setLoadingState:newState];
655 [tabController setIconView:iconView];
656 }
657 }
658 671
659 TabContentsController* updatedController = 672 TabContentsController* updatedController =
660 [tabContentsArray_ objectAtIndex:index]; 673 [tabContentsArray_ objectAtIndex:index];
661 [updatedController tabDidChange:contents]; 674 [updatedController tabDidChange:contents];
662 } 675 }
663 676
664 // Called when a tab is moved (usually by drag&drop). Keep our parallel arrays 677 // Called when a tab is moved (usually by drag&drop). Keep our parallel arrays
665 // in sync with the tab strip model. 678 // in sync with the tab strip model.
666 - (void)tabMovedWithContents:(TabContents*)contents 679 - (void)tabMovedWithContents:(TabContents*)contents
667 fromIndex:(NSInteger)from 680 fromIndex:(NSInteger)from
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 BrowserWindowController* controller = 891 BrowserWindowController* controller =
879 (BrowserWindowController*)[[switchView_ window] windowController]; 892 (BrowserWindowController*)[[switchView_ window] windowController];
880 DCHECK(index >= 0); 893 DCHECK(index >= 0);
881 if (index >= 0) { 894 if (index >= 0) {
882 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; 895 [controller setTab:[self viewAtIndex:index] isDraggable:YES];
883 } 896 }
884 } 897 }
885 898
886 899
887 @end 900 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698