diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-08 19:40:37 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-08 19:40:37 +0000 |
commit | f33bc9e999c94c006b3304cc67d901cdbc37abec (patch) | |
tree | 28db274abb6df5091730b3bac84bcfe2f6d7c1c9 | |
parent | 71a63aeccaf5a4ebedaf742de70ba01c8a87bbde (diff) | |
download | chromium_src-f33bc9e999c94c006b3304cc67d901cdbc37abec.zip chromium_src-f33bc9e999c94c006b3304cc67d901cdbc37abec.tar.gz chromium_src-f33bc9e999c94c006b3304cc67d901cdbc37abec.tar.bz2 |
[Mac] Handle TabReplacedAt() notifications in TabStripModelObserverBridge. Adds a new |-tabReplacedWithContents:previousContents:atIndex:| method and calls that if it exists. TabStripController now listens for this notification and replaces the corresponding entry in its |tabContentsArray_|.
BUG=56385
TEST=No visible changes. This notification is not sent on Mac (yet).
Review URL: http://codereview.chromium.org/3606020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62000 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 41 insertions, 4 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index 9300d7d..f2fc066d 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -1371,6 +1371,9 @@ [infoBarContainerController_ changeTabContents:contents]; } +- (void)onReplaceTabWithContents:(TabContents*)contents { +} + - (void)onSelectedTabChange:(TabStripModelObserver::TabChangeType)change { // Update titles if this is the currently selected tab and if it isn't just // the loading state which changed. diff --git a/chrome/browser/cocoa/tab_strip_controller.h b/chrome/browser/cocoa/tab_strip_controller.h index 170d3ac..85de319 100644 --- a/chrome/browser/cocoa/tab_strip_controller.h +++ b/chrome/browser/cocoa/tab_strip_controller.h @@ -38,6 +38,9 @@ class ToolbarModel; // Stripped down version of TabStripModelObserverBridge:selectTabWithContents. - (void)onSelectTabWithContents:(TabContents*)contents; +// Stripped down version of TabStripModelObserverBridge:tabReplacedWithContents. +- (void)onReplaceTabWithContents:(TabContents*)contents; + // Stripped down version of TabStripModelObserverBridge:tabChangedWithContents. - (void)onSelectedTabChange:(TabStripModelObserver::TabChangeType)change; diff --git a/chrome/browser/cocoa/tab_strip_controller.mm b/chrome/browser/cocoa/tab_strip_controller.mm index 15e8515..da93a97 100644 --- a/chrome/browser/cocoa/tab_strip_controller.mm +++ b/chrome/browser/cocoa/tab_strip_controller.mm @@ -971,9 +971,8 @@ private: // 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. - TabContentsController* contentsController = - [[[TabContentsController alloc] initWithContents:contents] - autorelease]; + scoped_nsobject<TabContentsController> contentsController( + [[TabContentsController alloc] initWithContents:contents]); [tabContentsArray_ insertObject:contentsController atIndex:index]; // Make a new tab and add it to the strip. Keep track of its controller. @@ -1068,6 +1067,26 @@ private: } } +- (void)tabReplacedWithContents:(TabContents*)newContents + previousContents:(TabContents*)oldContents + atIndex:(NSInteger)modelIndex { + NSInteger index = [self indexFromModelIndex:modelIndex]; + TabContentsController* oldController = + [tabContentsArray_ objectAtIndex:index]; + DCHECK_EQ(oldContents, [oldController tabContents]); + + // Simply create a new TabContentsController for |newContents| and place it + // into the array, replacing |oldContents|. A TabSelectedAt notification will + // follow, at which point we will install the new view. + scoped_nsobject<TabContentsController> newController( + [[TabContentsController alloc] initWithContents:newContents]); + + // Bye bye, |oldController|. + [tabContentsArray_ replaceObjectAtIndex:index withObject:newController]; + + [delegate_ onReplaceTabWithContents:newContents]; +} + // Remove all knowledge about this tab and its associated controller, and remove // the view from the strip. - (void)removeTab:(TabController*)controller { diff --git a/chrome/browser/cocoa/tab_strip_controller_unittest.mm b/chrome/browser/cocoa/tab_strip_controller_unittest.mm index b4f6c61..04cf539 100644 --- a/chrome/browser/cocoa/tab_strip_controller_unittest.mm +++ b/chrome/browser/cocoa/tab_strip_controller_unittest.mm @@ -23,6 +23,8 @@ @implementation TestTabStripControllerDelegate - (void)onSelectTabWithContents:(TabContents*)contents { } +- (void)onReplaceTabWithContents:(TabContents*)contents { +} - (void)onSelectedTabChange:(TabStripModelObserver::TabChangeType)change { } - (void)onTabDetachedWithContents:(TabContents*)contents { diff --git a/chrome/browser/cocoa/tab_strip_model_observer_bridge.h b/chrome/browser/cocoa/tab_strip_model_observer_bridge.h index 140ccc1..61810c2 100644 --- a/chrome/browser/cocoa/tab_strip_model_observer_bridge.h +++ b/chrome/browser/cocoa/tab_strip_model_observer_bridge.h @@ -71,6 +71,9 @@ class TabStripModelObserverBridge : public TabStripModelObserver { - (void)tabChangedWithContents:(TabContents*)contents atIndex:(NSInteger)index changeType:(TabStripModelObserver::TabChangeType)change; +- (void)tabReplacedWithContents:(TabContents*)newContents + previousContents:(TabContents*)oldContents + atIndex:(NSInteger)index; - (void)tabMiniStateChangedWithContents:(TabContents*)contents atIndex:(NSInteger)index; - (void)tabStripEmpty; diff --git a/chrome/browser/cocoa/tab_strip_model_observer_bridge.mm b/chrome/browser/cocoa/tab_strip_model_observer_bridge.mm index a6a06f9..d1135c9 100644 --- a/chrome/browser/cocoa/tab_strip_model_observer_bridge.mm +++ b/chrome/browser/cocoa/tab_strip_model_observer_bridge.mm @@ -86,7 +86,14 @@ void TabStripModelObserverBridge::TabChangedAt(TabContents* contents, void TabStripModelObserverBridge::TabReplacedAt(TabContents* old_contents, TabContents* new_contents, int index) { - TabChangedAt(new_contents, index, ALL); + if ([controller_ respondsToSelector: + @selector(tabReplacedWithContents:previousContents:atIndex:)]) { + [controller_ tabReplacedWithContents:new_contents + previousContents:old_contents + atIndex:index]; + } else { + TabChangedAt(new_contents, index, ALL); + } } void TabStripModelObserverBridge::TabMiniStateChanged(TabContents* contents, |