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

Unified Diff: chrome/browser/ui/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 unit test Created 8 years, 6 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/ui/tabs/tab_mru_list_manager.cc
diff --git a/chrome/browser/ui/tabs/tab_mru_list_manager.cc b/chrome/browser/ui/tabs/tab_mru_list_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9247a2eff765cbf1a8c365db9feb2b02aed39899
--- /dev/null
+++ b/chrome/browser/ui/tabs/tab_mru_list_manager.cc
@@ -0,0 +1,88 @@
+// 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/ui/tabs/tab_mru_list_manager.h"
+
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
+
+///////////////////////////////////////////////////////////////////////////////
+// TabMRUListManager, public:
+
+///////////////////////////////////////////////////////////////////////////////
+// TabMRUListManager, TabStripModelObserver implementation:
+
+TabMRUListManager::TabMRUListManager(TabStripModel* tab_strip_model)
+ : tab_strip_model_(tab_strip_model) {
+ if (tab_strip_model_)
sky 2012/06/11 18:21:51 When would the model ever be NULL?
NaveenBobbili (Motorola) 2012/06/13 06:07:32 Protection code. Unit tests would need this check.
+ tab_strip_model_->AddObserver(this);
+}
+
+TabMRUListManager::~TabMRUListManager() {
+ tabs_mru_list_.clear();
+ if (tab_strip_model_)
+ tab_strip_model_->RemoveObserver(this);
+}
+
+void TabMRUListManager::TabInsertedAt(TabContentsWrapper* contents,
+ int index,
+ bool foreground) {
+ if (foreground)
+ tabs_mru_list_.push_front(contents);
+ else
+ tabs_mru_list_.push_back(contents);
+}
+
+void TabMRUListManager::TabDetachedAt(TabContentsWrapper* contents,
+ int index) {
+ // Remove the index if found in MRU List
+ std::list<TabContentsWrapper*>::iterator it =
+ std::find(tabs_mru_list_.begin(), tabs_mru_list_.end(), contents);
+ if (it != tabs_mru_list_.end()) {
+ tabs_mru_list_.erase(it);
+ }
+}
+
+void TabMRUListManager::ActiveTabChanged(TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
+ int index,
+ bool user_gesture) {
+ // 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);
sky 2012/06/11 18:21:51 Why is the push conditional?
NaveenBobbili (Motorola) 2012/06/13 06:07:32 ActiveTabChanged should ideally be called after Ta
+ tabs_mru_list_.erase(it);
+ }
+}
+
+void TabMRUListManager::TabReplacedAt(TabStripModel* tab_strip_model,
+ TabContentsWrapper* old_contents,
+ TabContentsWrapper* new_contents,
+ int index) {
+ // 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);
sky 2012/06/11 18:21:51 space after ','
NaveenBobbili (Motorola) 2012/06/13 06:07:32 Done.
+ tabs_mru_list_.erase(it);
+ } else {
+ NOTREACHED();
+ }
+}
+
+void TabMRUListManager::TabStripEmpty() {
+ tabs_mru_list_.clear();
+}
+
+// Public Methods
sky 2012/06/11 18:21:51 remove this comment.
NaveenBobbili (Motorola) 2012/06/13 06:07:32 Done.
+TabContentsWrapper* TabMRUListManager::GetNextMRUTab() {
sky 2012/06/11 18:21:51 Order should match header.
NaveenBobbili (Motorola) 2012/06/13 06:07:32 Done.
+ // Only if there are more than one open tab we can switch.
+ if (tabs_mru_list_.size() < 2)
+ return NULL;
+
+ std::list<TabContentsWrapper*>::iterator it = tabs_mru_list_.begin();
+ std::advance(it, 1);
+ return *it;
+}

Powered by Google App Engine
This is Rietveld 408576698