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(TabStripModel* tab_strip_model) | |
16 : tab_strip_model_(tab_strip_model) { | |
17 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.
| |
18 tab_strip_model_->AddObserver(this); | |
19 } | |
20 | |
21 TabMRUListManager::~TabMRUListManager() { | |
22 tabs_mru_list_.clear(); | |
23 if (tab_strip_model_) | |
24 tab_strip_model_->RemoveObserver(this); | |
25 } | |
26 | |
27 void TabMRUListManager::TabInsertedAt(TabContentsWrapper* contents, | |
28 int index, | |
29 bool foreground) { | |
30 if (foreground) | |
31 tabs_mru_list_.push_front(contents); | |
32 else | |
33 tabs_mru_list_.push_back(contents); | |
34 } | |
35 | |
36 void TabMRUListManager::TabDetachedAt(TabContentsWrapper* contents, | |
37 int index) { | |
38 // Remove the index if found in MRU List | |
39 std::list<TabContentsWrapper*>::iterator it = | |
40 std::find(tabs_mru_list_.begin(), tabs_mru_list_.end(), contents); | |
41 if (it != tabs_mru_list_.end()) { | |
42 tabs_mru_list_.erase(it); | |
43 } | |
44 } | |
45 | |
46 void TabMRUListManager::ActiveTabChanged(TabContentsWrapper* old_contents, | |
47 TabContentsWrapper* new_contents, | |
48 int index, | |
49 bool user_gesture) { | |
50 // Bring the activated tab content to the front of the list | |
51 std::list<TabContentsWrapper*>::iterator it = | |
52 std::find(tabs_mru_list_.begin(), tabs_mru_list_.end(), new_contents); | |
53 if (it != tabs_mru_list_.end()) { | |
54 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
| |
55 tabs_mru_list_.erase(it); | |
56 } | |
57 } | |
58 | |
59 void TabMRUListManager::TabReplacedAt(TabStripModel* tab_strip_model, | |
60 TabContentsWrapper* old_contents, | |
61 TabContentsWrapper* new_contents, | |
62 int index) { | |
63 // Replace the tab contents accordingly in the list. If the tab contents are | |
64 // not found add to the end of the list. | |
65 std::list<TabContentsWrapper*>::iterator it = | |
66 std::find(tabs_mru_list_.begin(), tabs_mru_list_.end(), old_contents); | |
67 if (it != tabs_mru_list_.end()) { | |
68 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.
| |
69 tabs_mru_list_.erase(it); | |
70 } else { | |
71 NOTREACHED(); | |
72 } | |
73 } | |
74 | |
75 void TabMRUListManager::TabStripEmpty() { | |
76 tabs_mru_list_.clear(); | |
77 } | |
78 | |
79 // Public Methods | |
sky
2012/06/11 18:21:51
remove this comment.
NaveenBobbili (Motorola)
2012/06/13 06:07:32
Done.
| |
80 TabContentsWrapper* TabMRUListManager::GetNextMRUTab() { | |
sky
2012/06/11 18:21:51
Order should match header.
NaveenBobbili (Motorola)
2012/06/13 06:07:32
Done.
| |
81 // Only if there are more than one open tab we can switch. | |
82 if (tabs_mru_list_.size() < 2) | |
83 return NULL; | |
84 | |
85 std::list<TabContentsWrapper*>::iterator it = tabs_mru_list_.begin(); | |
86 std::advance(it, 1); | |
87 return *it; | |
88 } | |
OLD | NEW |