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

Unified Diff: chrome/browser/tabs/tab_strip_model.cc

Issue 10117016: Implementation for switching between recently used tabs using ctrl tilde or quoteleft. Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added tab mru list manager class. Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/tabs/tab_strip_model.cc
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index ad67ca9d3e06ef64b85e00084891a44a4e224680..16270ee28268c7b33340df5dcaf2aa3f1fe43db0 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -164,6 +164,11 @@ void TabStripModel::InsertTabContentsAt(int index,
FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
TabInsertedAt(contents, index, active));
+ if (active)
+ tab_mru_list_manager_.ActivateContents(contents);
+ else
+ tab_mru_list_manager_.AppendContents(contents);
+
if (active) {
TabStripSelectionModel new_model;
new_model.Copy(selection_model_);
@@ -186,6 +191,8 @@ TabContentsWrapper* TabStripModel::ReplaceTabContentsAt(
FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
TabReplacedAt(this, old_contents, new_contents, index));
+ tab_mru_list_manager_.ReplaceContents(old_contents, new_contents);
+
// When the active tab contents is replaced send out selected notification
// too. We do this as nearly all observers need to treat a replace of the
// selected contents as selection changing.
@@ -193,6 +200,7 @@ TabContentsWrapper* TabStripModel::ReplaceTabContentsAt(
FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
ActiveTabChanged(old_contents, new_contents,
active_index(), false));
+ tab_mru_list_manager_.ActivateContents(new_contents);
}
return old_contents;
}
@@ -251,8 +259,10 @@ TabContentsWrapper* TabStripModel::DetachTabContentsAt(int index) {
closing_all_ = true;
FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
TabDetachedAt(removed_contents, index));
+ tab_mru_list_manager_.RemoveContents(removed_contents);
if (empty()) {
selection_model_.Clear();
+ tab_mru_list_manager_.ClearContents();
// TabDetachedAt() might unregister observers, so send |TabStripEmtpy()| in
// a second pass.
FOR_EACH_OBSERVER(TabStripModelObserver, observers_, TabStripEmpty());
@@ -757,6 +767,13 @@ void TabStripModel::SelectLastTab() {
ActivateTabAt(count() - 1, true);
}
+void TabStripModel::SelectNextMRUTab() {
+ TabContentsWrapper* contents = tab_mru_list_manager_.GetNextMRUTab();
+ if (contents) {
+ ActivateTabAt(GetIndexOfTabContents(contents),true);
+ }
+}
+
void TabStripModel::MoveTabNext() {
// TODO: this likely needs to be updated for multi-selection.
int new_index = std::min(active_index() + 1, count() - 1);
@@ -1208,6 +1225,8 @@ void TabStripModel::InternalCloseTab(TabContentsWrapper* contents,
FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
TabClosingAt(this, contents, index));
+ tab_mru_list_manager_.RemoveContents(contents);
+
// Ask the delegate to save an entry for this tab in the historical tab
// database if applicable.
if (create_historical_tabs)
@@ -1240,6 +1259,7 @@ void TabStripModel::NotifyIfActiveTabChanged(
ActiveTabChanged(old_contents, new_contents,
active_index(),
notify_types == NOTIFY_USER_GESTURE));
+ tab_mru_list_manager_.ActivateContents(new_contents);
// Activating a discarded tab reloads it, so it is no longer discarded.
contents_data_[active_index()]->discarded = false;
}

Powered by Google App Engine
This is Rietveld 408576698