OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" | 5 #include "chrome/browser/tabs/tab_strip_model_order_controller.h" |
6 | 6 |
7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 8 #include "content/browser/tab_contents/tab_contents.h" |
8 | 9 |
9 /////////////////////////////////////////////////////////////////////////////// | 10 /////////////////////////////////////////////////////////////////////////////// |
10 // TabStripModelOrderController, public: | 11 // TabStripModelOrderController, public: |
11 | 12 |
12 TabStripModelOrderController::TabStripModelOrderController( | 13 TabStripModelOrderController::TabStripModelOrderController( |
13 TabStripModel* tabstrip) | 14 TabStripModel* tabstrip) |
14 : tabstrip_(tabstrip), | 15 : tabstrip_(tabstrip), |
15 insertion_policy_(TabStripModel::INSERT_AFTER) { | 16 insertion_policy_(TabStripModel::INSERT_AFTER) { |
16 tabstrip_->AddObserver(this); | 17 tabstrip_->AddObserver(this); |
17 } | 18 } |
(...skipping 14 matching lines...) Expand all Loading... |
32 // so we don't have to check here too. | 33 // so we don't have to check here too. |
33 if (transition == content::PAGE_TRANSITION_LINK && | 34 if (transition == content::PAGE_TRANSITION_LINK && |
34 tabstrip_->active_index() != -1) { | 35 tabstrip_->active_index() != -1) { |
35 int delta = (insertion_policy_ == TabStripModel::INSERT_AFTER) ? 1 : 0; | 36 int delta = (insertion_policy_ == TabStripModel::INSERT_AFTER) ? 1 : 0; |
36 if (foreground) { | 37 if (foreground) { |
37 // If the page was opened in the foreground by a link click in another | 38 // If the page was opened in the foreground by a link click in another |
38 // tab, insert it adjacent to the tab that opened that link. | 39 // tab, insert it adjacent to the tab that opened that link. |
39 return tabstrip_->active_index() + delta; | 40 return tabstrip_->active_index() + delta; |
40 } | 41 } |
41 NavigationController* opener = | 42 NavigationController* opener = |
42 &tabstrip_->GetActiveTabContents()->controller(); | 43 &tabstrip_->GetActiveTabContents()->tab_contents()->controller(); |
43 // Get the index of the next item opened by this tab, and insert after | 44 // Get the index of the next item opened by this tab, and insert after |
44 // it... | 45 // it... |
45 int index; | 46 int index; |
46 if (insertion_policy_ == TabStripModel::INSERT_AFTER) { | 47 if (insertion_policy_ == TabStripModel::INSERT_AFTER) { |
47 index = tabstrip_->GetIndexOfLastTabContentsOpenedBy( | 48 index = tabstrip_->GetIndexOfLastTabContentsOpenedBy( |
48 opener, tabstrip_->active_index()); | 49 opener, tabstrip_->active_index()); |
49 } else { | 50 } else { |
50 index = tabstrip_->GetIndexOfFirstTabContentsOpenedBy( | 51 index = tabstrip_->GetIndexOfFirstTabContentsOpenedBy( |
51 opener, tabstrip_->active_index()); | 52 opener, tabstrip_->active_index()); |
52 } | 53 } |
(...skipping 14 matching lines...) Expand all Loading... |
67 int TabStripModelOrderController::DetermineNewSelectedIndex( | 68 int TabStripModelOrderController::DetermineNewSelectedIndex( |
68 int removing_index) const { | 69 int removing_index) const { |
69 int tab_count = tabstrip_->count(); | 70 int tab_count = tabstrip_->count(); |
70 DCHECK(removing_index >= 0 && removing_index < tab_count); | 71 DCHECK(removing_index >= 0 && removing_index < tab_count); |
71 NavigationController* parent_opener = | 72 NavigationController* parent_opener = |
72 tabstrip_->GetOpenerOfTabContentsAt(removing_index); | 73 tabstrip_->GetOpenerOfTabContentsAt(removing_index); |
73 // First see if the index being removed has any "child" tabs. If it does, we | 74 // First see if the index being removed has any "child" tabs. If it does, we |
74 // want to select the first in that child group, not the next tab in the same | 75 // want to select the first in that child group, not the next tab in the same |
75 // group of the removed tab. | 76 // group of the removed tab. |
76 NavigationController* removed_controller = | 77 NavigationController* removed_controller = |
77 &tabstrip_->GetTabContentsAt(removing_index)->controller(); | 78 &tabstrip_->GetTabContentsAt(removing_index)-> |
| 79 tab_contents()->controller(); |
78 // The parent opener should never be the same as the controller being removed. | 80 // The parent opener should never be the same as the controller being removed. |
79 DCHECK(parent_opener != removed_controller); | 81 DCHECK(parent_opener != removed_controller); |
80 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(removed_controller, | 82 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(removed_controller, |
81 removing_index, | 83 removing_index, |
82 false); | 84 false); |
83 if (index != TabStripModel::kNoTab) | 85 if (index != TabStripModel::kNoTab) |
84 return GetValidIndex(index, removing_index); | 86 return GetValidIndex(index, removing_index); |
85 | 87 |
86 if (parent_opener) { | 88 if (parent_opener) { |
87 // If the tab was in a group, shift selection to the next tab in the group. | 89 // If the tab was in a group, shift selection to the next tab in the group. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // selection changes (see comment in TabStripModel::AddTabContentsAt). | 124 // selection changes (see comment in TabStripModel::AddTabContentsAt). |
123 if (tabstrip_->ShouldResetGroupOnSelect(old_contents)) | 125 if (tabstrip_->ShouldResetGroupOnSelect(old_contents)) |
124 tabstrip_->ForgetGroup(old_contents); | 126 tabstrip_->ForgetGroup(old_contents); |
125 } | 127 } |
126 } | 128 } |
127 NavigationController* new_opener = | 129 NavigationController* new_opener = |
128 tabstrip_->GetOpenerOfTabContentsAt(index); | 130 tabstrip_->GetOpenerOfTabContentsAt(index); |
129 | 131 |
130 if (user_gesture && new_opener != old_opener && | 132 if (user_gesture && new_opener != old_opener && |
131 ((old_contents == NULL && new_opener == NULL) || | 133 ((old_contents == NULL && new_opener == NULL) || |
132 new_opener != &old_contents->controller()) && | 134 new_opener != &old_contents->tab_contents()->controller()) && |
133 ((new_contents == NULL && old_opener == NULL) || | 135 ((new_contents == NULL && old_opener == NULL) || |
134 old_opener != &new_contents->controller())) { | 136 old_opener != &new_contents->tab_contents()->controller())) { |
135 tabstrip_->ForgetAllOpeners(); | 137 tabstrip_->ForgetAllOpeners(); |
136 } | 138 } |
137 } | 139 } |
138 | 140 |
139 /////////////////////////////////////////////////////////////////////////////// | 141 /////////////////////////////////////////////////////////////////////////////// |
140 // TabStripModelOrderController, private: | 142 // TabStripModelOrderController, private: |
141 | 143 |
142 int TabStripModelOrderController::GetValidIndex( | 144 int TabStripModelOrderController::GetValidIndex( |
143 int index, int removing_index) const { | 145 int index, int removing_index) const { |
144 if (removing_index < index) | 146 if (removing_index < index) |
145 index = std::max(0, index - 1); | 147 index = std::max(0, index - 1); |
146 return index; | 148 return index; |
147 } | 149 } |
OLD | NEW |