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

Unified Diff: chrome/browser/tabs/tab_mru_list_manager.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_mru_list_manager.cc
diff --git a/chrome/browser/tabs/tab_mru_list_manager.cc b/chrome/browser/tabs/tab_mru_list_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..661d98c3b34703d0865f370c7c2be646fc2fb5b9
--- /dev/null
+++ b/chrome/browser/tabs/tab_mru_list_manager.cc
@@ -0,0 +1,85 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/tabs/tab_mru_list_manager.h"
+
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+
+///////////////////////////////////////////////////////////////////////////////
+// TabMRUListManager, public:
+
+TabMRUListManager::~TabMRUListManager() {
+ tabs_mru_list_.clear();
+}
+
+void TabMRUListManager::ActivateContents(TabContentsWrapper* new_contents) {
+ if (!new_contents)
+ return;
+
+ // Bring the activated tab content to the front of the list
+ std::list<TabContentsWrapper*>::iterator it =
+ std::find(tabs_mru_list_.begin(),
+ tabs_mru_list_.end(),
+ new_contents);
+ if (it != tabs_mru_list_.end()) {
+ tabs_mru_list_.push_front(*it);
+ tabs_mru_list_.erase(it);
+ } else {
+ tabs_mru_list_.push_front(new_contents);
+ }
+}
+
+void TabMRUListManager::AppendContents(TabContentsWrapper* new_contents) {
+ if (!new_contents)
+ return;
+
+ // Bring the activated tab content to the front of the list
+ std::list<TabContentsWrapper*>::iterator it =
+ std::find(tabs_mru_list_.begin(),
+ tabs_mru_list_.end(),
+ new_contents);
+ // Append only if the content are not present in the list.
+ // This will avoid duplicates.
+ if (it == tabs_mru_list_.end()) {
+ tabs_mru_list_.push_back(new_contents);
+ }
+}
+
+void TabMRUListManager::ClearContents() {
+ tabs_mru_list_.clear();
+}
+
+TabContentsWrapper* TabMRUListManager::GetNextMRUTab() {
+ std::list<TabContentsWrapper*>::iterator it = tabs_mru_list_.begin();
+ // Advance to second element in MRU list if there are more than one tabs open.
+ if (tabs_mru_list_.size() > 1) {
+ std::advance(it, 1);
+ }
+ return *it;
+}
+
+void TabMRUListManager::RemoveContents(TabContentsWrapper* removed_contents) {
+ // Remove the contents if found in MRU List
+ std::list<TabContentsWrapper*>::iterator it =
+ std::find(tabs_mru_list_.begin(),
+ tabs_mru_list_.end(),
+ removed_contents);
+ if (it != tabs_mru_list_.end()) {
+ tabs_mru_list_.erase(it);
+ }
+}
+
+void TabMRUListManager::ReplaceContents(
+ TabContentsWrapper* old_contents, TabContentsWrapper* new_contents) {
+ // Replace the tab contents accordingly in the list. If the tab contents are
+ // not found add to the end of the list.
+ std::list<TabContentsWrapper*>::iterator it =
+ std::find(tabs_mru_list_.begin(),
+ tabs_mru_list_.end(),
+ old_contents);
+ if (it != tabs_mru_list_.end()) {
+ tabs_mru_list_.insert(it,new_contents);
+ tabs_mru_list_.erase(it);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698