Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/tabs/tab_mru_list_manager.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 8 | |
| 9 /////////////////////////////////////////////////////////////////////////////// | |
| 10 // TabMRUListManager, public: | |
| 11 | |
| 12 /////////////////////////////////////////////////////////////////////////////// | |
| 13 // TabMRUListManager, TabStripModelObserver implementation: | |
| 14 | |
| 15 TabMRUListManager::TabMRUListManager() { | |
| 16 } | |
| 17 | |
| 18 TabMRUListManager::~TabMRUListManager() { | |
| 19 tabs_mru_list_.clear(); | |
| 20 } | |
| 21 | |
| 22 void TabMRUListManager::TabInsertedAt(TabContentsWrapper* contents, | |
| 23 int index, | |
| 24 bool foreground) { | |
| 25 tabs_mru_list_.push_front(contents); | |
|
sky
2012/05/29 19:48:28
You only want to add to the front if foreground is
NaveenBobbili (Motorola)
2012/06/05 05:34:16
Done.
| |
| 26 } | |
| 27 | |
| 28 void TabMRUListManager::TabClosingAt(TabStripModel* tab_strip_model, | |
| 29 TabContentsWrapper* contents, | |
| 30 int index) { | |
| 31 // Remove the index if found in MRU List | |
|
sky
2012/05/29 19:48:28
You shouldn't need to override this. Instead put l
NaveenBobbili (Motorola)
2012/06/05 05:34:16
Done.
| |
| 32 std::list<TabContentsWrapper*>::iterator it = | |
| 33 std::find(tabs_mru_list_.begin(), tabs_mru_list_.end(), contents); | |
| 34 if (it != tabs_mru_list_.end()) { | |
| 35 tabs_mru_list_.erase(it); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 void TabMRUListManager::TabDetachedAt(TabContentsWrapper* contents, | |
| 40 int index) { | |
| 41 // Remove the index if found in MRU List | |
| 42 std::list<TabContentsWrapper*>::iterator it = | |
| 43 std::find(tabs_mru_list_.begin(), tabs_mru_list_.end(), contents); | |
| 44 if (it != tabs_mru_list_.end()) { | |
| 45 tabs_mru_list_.erase(it); | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 void TabMRUListManager::ActiveTabChanged(TabContentsWrapper* old_contents, | |
| 50 TabContentsWrapper* new_contents, | |
| 51 int index, | |
| 52 bool user_gesture) { | |
| 53 // Bring the activated tab content to the front of the list | |
| 54 std::list<TabContentsWrapper*>::iterator it = | |
| 55 std::find(tabs_mru_list_.begin(), tabs_mru_list_.end(), new_contents); | |
| 56 if (it != tabs_mru_list_.end()) { | |
| 57 tabs_mru_list_.push_front(*it); | |
| 58 tabs_mru_list_.erase(it); | |
|
sky
2012/05/29 19:48:28
You should always push_front, right?
NaveenBobbili (Motorola)
2012/06/05 05:34:16
This case would arrive if the tab is manually acti
| |
| 59 } | |
| 60 } | |
| 61 | |
| 62 void TabMRUListManager::TabReplacedAt(TabStripModel* tab_strip_model, | |
| 63 TabContentsWrapper* old_contents, | |
| 64 TabContentsWrapper* new_contents, | |
| 65 int index) { | |
| 66 // Replace the tab contents accordingly in the list. If the tab contents are | |
| 67 // not found add to the end of the list. | |
| 68 std::list<TabContentsWrapper*>::iterator it = | |
| 69 std::find(tabs_mru_list_.begin(), tabs_mru_list_.end(), old_contents); | |
| 70 if (it != tabs_mru_list_.end()) { | |
| 71 tabs_mru_list_.insert(it,new_contents); | |
| 72 tabs_mru_list_.erase(it); | |
| 73 } else { | |
| 74 tabs_mru_list_.push_back(new_contents); | |
|
sky
2012/05/29 19:48:28
This should be NOTREACHED
NaveenBobbili (Motorola)
2012/06/05 05:34:16
Done.
NaveenBobbili (Motorola)
2012/06/05 05:34:16
Done.
| |
| 75 } | |
| 76 } | |
| 77 | |
| 78 void TabMRUListManager::TabStripEmpty() { | |
| 79 tabs_mru_list_.clear(); | |
| 80 } | |
| 81 | |
| 82 // Public Methods | |
| 83 TabContentsWrapper* TabMRUListManager::GetNextMRUTab() { | |
| 84 std::list<TabContentsWrapper*>::iterator it = tabs_mru_list_.begin(); | |
| 85 // Advance to second element in MRU list if there are more than one tabs open. | |
| 86 if (tabs_mru_list_.size() > 1) { | |
| 87 std::advance(it, 1); | |
| 88 } | |
| 89 return *it; | |
|
sky
2012/05/29 19:48:28
This will crash if empty.
NaveenBobbili (Motorola)
2012/06/05 05:34:16
Done.
| |
| 90 } | |
| OLD | NEW |