diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-11 04:03:57 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-11 04:03:57 +0000 |
commit | fd2b9cec9b6eed50f8fc1fcdf72866733fe57f45 (patch) | |
tree | 620a3ff359c4007f30c54f292de5a546739a570a /chrome/browser/tabs | |
parent | 7ab36c4f07b585449febcc6f2c59a9f5a0a40eed (diff) | |
download | chromium_src-fd2b9cec9b6eed50f8fc1fcdf72866733fe57f45.zip chromium_src-fd2b9cec9b6eed50f8fc1fcdf72866733fe57f45.tar.gz chromium_src-fd2b9cec9b6eed50f8fc1fcdf72866733fe57f45.tar.bz2 |
Adds support for showing the match preview on views. It's behind the
flag --enable-match-preview. There is still a lot of details to get it
working good enough, but this is a good point to check some stuff in.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3105004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55665 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tabs')
-rw-r--r-- | chrome/browser/tabs/tab_strip_model.cc | 43 | ||||
-rw-r--r-- | chrome/browser/tabs/tab_strip_model.h | 37 |
2 files changed, 71 insertions, 9 deletions
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc index 8ac8fc4..269de35 100644 --- a/chrome/browser/tabs/tab_strip_model.cc +++ b/chrome/browser/tabs/tab_strip_model.cc @@ -82,6 +82,13 @@ void TabStripModelObserver::TabReplacedAt(TabContents* old_contents, int index) { } +void TabStripModelObserver::TabReplacedAt(TabContents* old_contents, + TabContents* new_contents, + int index, + TabReplaceType type) { + TabReplacedAt(old_contents, new_contents, index); +} + void TabStripModelObserver::TabPinnedStateChanged(TabContents* contents, int index) { } @@ -233,6 +240,13 @@ void TabStripModel::InsertTabContentsAt(int index, ChangeSelectedContentsFrom(selected_contents, index, false); } +void TabStripModel::ReplaceTabContentsAt( + int index, + TabContents* new_contents, + TabStripModelObserver::TabReplaceType type) { + delete ReplaceTabContentsAtImpl(index, new_contents, type); +} + void TabStripModel::ReplaceNavigationControllerAt( int index, NavigationController* controller) { // This appears to be OK with no flicker since no redraw event @@ -1043,14 +1057,10 @@ bool TabStripModel::ShouldMakePhantomOnClose(int index) { } void TabStripModel::MakePhantom(int index) { - TabContents* old_contents = GetContentsAt(index); - TabContents* new_contents = old_contents->CloneAndMakePhantom(); - - contents_data_[index]->contents = new_contents; - - // And notify observers. - FOR_EACH_OBSERVER(TabStripModelObserver, observers_, - TabReplacedAt(old_contents, new_contents, index)); + // MakePhantom is called when the TabContents is being destroyed so we don't + // need to do anything with the returned value from ReplaceTabContentsAtImpl. + ReplaceTabContentsAtImpl(index, GetContentsAt(index)->CloneAndMakePhantom(), + TabStripModelObserver::REPLACE_MADE_PHANTOM); if (selected_index_ == index && HasNonPhantomTabs()) { // Change the selection, otherwise we're going to force the phantom tab @@ -1095,3 +1105,20 @@ bool TabStripModel::OpenerMatches(const TabContentsData* data, bool use_group) { return data->opener == opener || (use_group && data->group == opener); } + +TabContents* TabStripModel::ReplaceTabContentsAtImpl( + int index, + TabContents* new_contents, + TabStripModelObserver::TabReplaceType type) { + // TODO: this should reset group/opener of any tabs that point at + // old_contents. + DCHECK(ContainsIndex(index)); + + TabContents* old_contents = GetContentsAt(index); + + contents_data_[index]->contents = new_contents; + + FOR_EACH_OBSERVER(TabStripModelObserver, observers_, + TabReplacedAt(old_contents, new_contents, index, type)); + return old_contents; +} diff --git a/chrome/browser/tabs/tab_strip_model.h b/chrome/browser/tabs/tab_strip_model.h index f26af59..542b27f 100644 --- a/chrome/browser/tabs/tab_strip_model.h +++ b/chrome/browser/tabs/tab_strip_model.h @@ -54,6 +54,18 @@ class TabStripModelObserver { ALL }; + // Enum used by ReplaceTabContentsAt. + // TODO(sky): TabReplaceType should be declared outside the scope of + // the observer. I need to put all the enums in a namespace and cleanup this + // file. + enum TabReplaceType { + // The replace is the result of the tab being made phantom. + REPLACE_MADE_PHANTOM, + + // The replace is the result of the match preview being committed. + REPLACE_MATCH_PREVIEW + }; + // A new TabContents was inserted into the TabStripModel at the specified // index. |foreground| is whether or not it was opened in the foreground // (selected). @@ -100,8 +112,18 @@ class TabStripModelObserver { // The tab contents was replaced at the specified index. This is invoked when // a tab becomes phantom. See description of phantom tabs in class description // of TabStripModel for details. + // TODO(sky): nuke this in favor of the 4 arg variant. + virtual void TabReplacedAt(TabContents* old_contents, + TabContents* new_contents, + int index); + + // The tab contents was replaced at the specified index. |type| describes + // the type of replace. + // This invokes TabReplacedAt with three args. virtual void TabReplacedAt(TabContents* old_contents, - TabContents* new_contents, int index); + TabContents* new_contents, + int index, + TabReplaceType type); // Invoked when the pinned state of a tab changes. This is not invoked if the // tab ends up moving as a result of the mini state changing. @@ -433,6 +455,12 @@ class TabStripModel : public NotificationObserver { void ReplaceNavigationControllerAt(int index, NavigationController* controller); + // Replaces the tab contents at |index| with |new_contents|. |type| is passed + // to the observer. This deletes the TabContents currently at |index|. + void ReplaceTabContentsAt(int index, + TabContents* new_contents, + TabStripModelObserver::TabReplaceType type); + // Detaches the TabContents at the specified index from this strip. The // TabContents is not destroyed, just removed from display. The caller is // responsible for doing something with it (e.g. stuffing it into another @@ -725,6 +753,13 @@ class TabStripModel : public NotificationObserver { const NavigationController* opener, bool use_group); + // Does the work for ReplaceTabContentsAt returning the old TabContents. + // The caller owns the returned TabContents. + TabContents* ReplaceTabContentsAtImpl( + int index, + TabContents* new_contents, + TabStripModelObserver::TabReplaceType type); + // Our delegate. TabStripModelDelegate* delegate_; |