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/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 TabMRUListManager::~TabMRUListManager() { |
| 13 tabs_mru_list_.clear(); |
| 14 } |
| 15 |
| 16 void TabMRUListManager::ActivateContents(TabContentsWrapper* new_contents) { |
| 17 if (!new_contents) |
| 18 return; |
| 19 |
| 20 // Bring the activated tab content to the front of the list |
| 21 std::list<TabContentsWrapper*>::iterator it = |
| 22 std::find(tabs_mru_list_.begin(), |
| 23 tabs_mru_list_.end(), |
| 24 new_contents); |
| 25 if (it != tabs_mru_list_.end()) { |
| 26 tabs_mru_list_.push_front(*it); |
| 27 tabs_mru_list_.erase(it); |
| 28 } else { |
| 29 tabs_mru_list_.push_front(new_contents); |
| 30 } |
| 31 } |
| 32 |
| 33 void TabMRUListManager::AppendContents(TabContentsWrapper* new_contents) { |
| 34 if (!new_contents) |
| 35 return; |
| 36 |
| 37 // Bring the activated tab content to the front of the list |
| 38 std::list<TabContentsWrapper*>::iterator it = |
| 39 std::find(tabs_mru_list_.begin(), |
| 40 tabs_mru_list_.end(), |
| 41 new_contents); |
| 42 // Append only if the content are not present in the list. |
| 43 // This will avoid duplicates. |
| 44 if (it == tabs_mru_list_.end()) { |
| 45 tabs_mru_list_.push_back(new_contents); |
| 46 } |
| 47 } |
| 48 |
| 49 void TabMRUListManager::ClearContents() { |
| 50 tabs_mru_list_.clear(); |
| 51 } |
| 52 |
| 53 TabContentsWrapper* TabMRUListManager::GetNextMRUTab() { |
| 54 std::list<TabContentsWrapper*>::iterator it = tabs_mru_list_.begin(); |
| 55 // Advance to second element in MRU list if there are more than one tabs open. |
| 56 if (tabs_mru_list_.size() > 1) { |
| 57 std::advance(it, 1); |
| 58 } |
| 59 return *it; |
| 60 } |
| 61 |
| 62 void TabMRUListManager::RemoveContents(TabContentsWrapper* removed_contents) { |
| 63 // Remove the contents if found in MRU List |
| 64 std::list<TabContentsWrapper*>::iterator it = |
| 65 std::find(tabs_mru_list_.begin(), |
| 66 tabs_mru_list_.end(), |
| 67 removed_contents); |
| 68 if (it != tabs_mru_list_.end()) { |
| 69 tabs_mru_list_.erase(it); |
| 70 } |
| 71 } |
| 72 |
| 73 void TabMRUListManager::ReplaceContents( |
| 74 TabContentsWrapper* old_contents, TabContentsWrapper* new_contents) { |
| 75 // Replace the tab contents accordingly in the list. If the tab contents are |
| 76 // not found add to the end of the list. |
| 77 std::list<TabContentsWrapper*>::iterator it = |
| 78 std::find(tabs_mru_list_.begin(), |
| 79 tabs_mru_list_.end(), |
| 80 old_contents); |
| 81 if (it != tabs_mru_list_.end()) { |
| 82 tabs_mru_list_.insert(it,new_contents); |
| 83 tabs_mru_list_.erase(it); |
| 84 } |
| 85 } |
OLD | NEW |