diff options
author | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-17 18:54:23 +0000 |
---|---|---|
committer | pinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-17 18:54:23 +0000 |
commit | 500c9f12f3f90e82ad0108edbfd35fc499d5b21d (patch) | |
tree | 404dbec031f19f4ff608cf6114af9846c09d3a67 /chrome | |
parent | bdd546bcccfecdf50fb6c9becd7fdda1a4d29428 (diff) | |
download | chromium_src-500c9f12f3f90e82ad0108edbfd35fc499d5b21d.zip chromium_src-500c9f12f3f90e82ad0108edbfd35fc499d5b21d.tar.gz chromium_src-500c9f12f3f90e82ad0108edbfd35fc499d5b21d.tar.bz2 |
Unstub some more of the Browser object, including the part that sets it as the delegate of the TabContents object. That allows page-load notifications to make their way through the browser UI layer. Hook up notification to Mac tab strip to set the title as it's changed.
Review URL: http://codereview.chromium.org/20429
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9892 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser.cc | 9 | ||||
-rw-r--r-- | chrome/browser/browser.h | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_contents_controller.h | 4 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_contents_controller.mm | 5 | ||||
-rw-r--r-- | chrome/browser/cocoa/tab_strip_controller.mm | 33 |
5 files changed, 50 insertions, 5 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 59f6267..4c87134 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1378,7 +1378,6 @@ bool Browser::RunUnloadListenerBeforeClosing(TabContents* contents) { return false; } -#if defined(OS_WIN) /////////////////////////////////////////////////////////////////////////////// // Browser, TabStripModelObserver implementation: @@ -1391,6 +1390,7 @@ void Browser::TabInsertedAt(TabContents* contents, SyncHistoryWithTabs(tabstrip_model_.GetIndexOfTabContents(contents)); +#if defined(OS_WIN) // When a tab is dropped into a tab strip we need to make sure that the // associated Find window is moved along with it. We therefore change the // parent of the Find window (if the parent is already correctly set this @@ -1400,6 +1400,7 @@ void Browser::TabInsertedAt(TabContents* contents, WebContents* web_contents = contents->AsWebContents(); if (web_contents) web_contents->view()->ReparentFindWindow(this); +#endif // Make sure the loading state is updated correctly, otherwise the throbber // won't start if the page is loading. @@ -1413,6 +1414,8 @@ void Browser::TabInsertedAt(TabContents* contents, Source<TabContents>(contents)); } +#if defined(OS_WIN) + void Browser::TabClosingAt(TabContents* contents, int index) { NavigationController* controller = contents->controller(); DCHECK(controller); @@ -1799,12 +1802,16 @@ void Browser::ConvertContentsToApplication(TabContents* contents) { browser->window()->Show(); } +#endif // OS_WIN + void Browser::ContentsStateChanged(TabContents* source) { int index = tabstrip_model_.GetIndexOfTabContents(source); if (index != TabStripModel::kNoTab) tabstrip_model_.UpdateTabContentsStateAt(index); } +#if defined(OS_WIN) + bool Browser::ShouldDisplayURLField() { return !IsApplication(); } diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 858d5c4..826c0b4 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -339,11 +339,11 @@ class Browser : public TabStripModelDelegate, virtual void CreateHistoricalTab(TabContents* contents); virtual bool RunUnloadListenerBeforeClosing(TabContents* contents); -#if defined(OS_WIN) // Overridden from TabStripModelObserver: virtual void TabInsertedAt(TabContents* contents, int index, bool foreground); +#if defined(OS_WIN) virtual void TabClosingAt(TabContents* contents, int index); virtual void TabDetachedAt(TabContents* contents, int index); #endif @@ -386,7 +386,9 @@ class Browser : public TabStripModelDelegate, virtual void ContentsZoomChange(bool zoom_in); virtual bool IsApplication() const; virtual void ConvertContentsToApplication(TabContents* source); +#endif virtual void ContentsStateChanged(TabContents* source); +#if defined(OS_WIN) virtual bool ShouldDisplayURLField(); virtual void BeforeUnloadFired(TabContents* source, bool proceed, diff --git a/chrome/browser/cocoa/tab_contents_controller.h b/chrome/browser/cocoa/tab_contents_controller.h index a5dd5dc..4d205bb 100644 --- a/chrome/browser/cocoa/tab_contents_controller.h +++ b/chrome/browser/cocoa/tab_contents_controller.h @@ -57,6 +57,10 @@ class TabStripModel; // enabled. - (void)willBecomeSelectedTab; +// Called when the tab contents is updated in some non-descript way (the +// notification from the model isn't specific). +- (void)tabDidChange; + // Called when any url bar state changes. If |tabForRestoring| is non-NULL, // it points to a TabContents whose state we should restore. - (void)updateToolbarWithContents:(TabContents*)tabForRestoring; diff --git a/chrome/browser/cocoa/tab_contents_controller.mm b/chrome/browser/cocoa/tab_contents_controller.mm index b338745..6aae799 100644 --- a/chrome/browser/cocoa/tab_contents_controller.mm +++ b/chrome/browser/cocoa/tab_contents_controller.mm @@ -166,6 +166,11 @@ class LocationBarBridge : public LocationBar { [self updateToolbarCommandStatus]; } +- (void)tabDidChange { + // TODO(pinkerton): what specificaly do we need to update here? + NOTIMPLEMENTED(); +} + - (NSString*)locationBarString { return [locationBar_ stringValue]; } diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index 0c5b4c6..864ab12 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -4,11 +4,13 @@ #import "chrome/browser/cocoa/tab_strip_controller.h" +#import "base/sys_string_conversions.h" #import "chrome/app/chrome_dll_resource.h" #import "chrome/browser/cocoa/tab_strip_view.h" #import "chrome/browser/cocoa/tab_cell.h" #import "chrome/browser/cocoa/tab_contents_controller.h" #import "chrome/browser/tabs/tab_strip_model.h" +#import "chrome/common/temp_scaffolding_stubs.h" // The amount of overlap tabs have in their button frames. const short kTabOverlap = 16; @@ -24,6 +26,8 @@ const short kTabOverlap = 16; userGesture:(bool)wasUserGesture; - (void)tabDetachedWithContents:(TabContents*)contents atIndex:(NSInteger)index; +- (void)tabChangedWithContents:(TabContents*)contents + atIndex:(NSInteger)index; @end // A C++ bridge class to handle receiving notifications from the C++ tab @@ -181,6 +185,17 @@ class TabStripBridge : public TabStripModelObserver { return NSMakeRect(xOffset, 0, kNewTabWidth, [tabView_ frame].size.height); } +// Handles setting the title of the tab based on the given |contents|. Uses +// a canned string if |contents| is NULL. +- (void)setTabTitle:(NSButton*)tab withContents:(TabContents*)contents { + NSString* titleString = nil; + if (contents) + titleString = base::SysWideToNSString(contents->GetTitle()); + if (![titleString length]) + titleString = NSLocalizedString(@"untitled", nil); + [tab setTitle:titleString]; +} + // Called when a notification is received from the model to insert a new tab // at |index|. - (void)insertTabWithContents:(TabContents*)contents @@ -193,8 +208,6 @@ class TabStripBridge : public TabStripModelObserver { // Make a new tab. Load the contents of this tab from the nib and associate // the new controller with |contents| so it can be looked up later. - // TODO(pinkerton): will eventually need to pass |contents| to the - // controller to complete hooking things up. TabContentsController* contentsController = [[[TabContentsController alloc] initWithNibName:@"TabContents" bundle:nil @@ -214,6 +227,8 @@ class TabStripBridge : public TabStripModelObserver { NSButton* newView = [self newTabWithFrame:newTabFrame]; [tabView_ addSubview:newView]; + [self setTabTitle:newView withContents:contents]; + // Add the new tab button back in to the right of the last tab. const NSInteger kNewTabXOffset = 10; NSRect lastTab = @@ -280,6 +295,18 @@ class TabStripBridge : public TabStripModelObserver { } } +// Called when a notification is received from the model that the given tab +// has been updated. +- (void)tabChangedWithContents:(TabContents*)contents + atIndex:(NSInteger)index { + NSButton* tab = [[tabView_ subviews] objectAtIndex:index]; + [self setTabTitle:tab withContents:contents]; + + TabContentsController* updatedController = + [self controllerWithContents:contents]; + [updatedController tabDidChange]; +} + - (LocationBar*)locationBar { TabContents* selectedContents = model_->GetSelectedTabContents(); TabContentsController* selectedController = @@ -353,7 +380,7 @@ void TabStripBridge::TabMoved(TabContents* contents, } void TabStripBridge::TabChangedAt(TabContents* contents, int index) { - NOTIMPLEMENTED(); + [controller_ tabChangedWithContents:contents atIndex:index]; } void TabStripBridge::TabStripEmpty() { |