OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/tab_contents/tab_contents.h" | 7 #include "chrome/browser/tab_contents/tab_contents.h" |
8 | 8 |
9 /////////////////////////////////////////////////////////////////////////////// | 9 /////////////////////////////////////////////////////////////////////////////// |
10 // TabStripModelOrderController, public: | 10 // TabStripModelOrderController, public: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // In other cases, such as Ctrl+T, open at the end of the strip. | 57 // In other cases, such as Ctrl+T, open at the end of the strip. |
58 return DetermineInsertionIndexForAppending(); | 58 return DetermineInsertionIndexForAppending(); |
59 } | 59 } |
60 | 60 |
61 int TabStripModelOrderController::DetermineInsertionIndexForAppending() { | 61 int TabStripModelOrderController::DetermineInsertionIndexForAppending() { |
62 return (insertion_policy_ == TabStripModel::INSERT_AFTER) ? | 62 return (insertion_policy_ == TabStripModel::INSERT_AFTER) ? |
63 tabstrip_->count() : 0; | 63 tabstrip_->count() : 0; |
64 } | 64 } |
65 | 65 |
66 int TabStripModelOrderController::DetermineNewSelectedIndex( | 66 int TabStripModelOrderController::DetermineNewSelectedIndex( |
67 int removing_index, | 67 int removing_index) const { |
68 bool is_remove) const { | |
69 int tab_count = tabstrip_->count(); | 68 int tab_count = tabstrip_->count(); |
70 DCHECK(removing_index >= 0 && removing_index < tab_count); | 69 DCHECK(removing_index >= 0 && removing_index < tab_count); |
71 NavigationController* parent_opener = | 70 NavigationController* parent_opener = |
72 tabstrip_->GetOpenerOfTabContentsAt(removing_index); | 71 tabstrip_->GetOpenerOfTabContentsAt(removing_index); |
73 // First see if the index being removed has any "child" tabs. If it does, we | 72 // 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 | 73 // want to select the first in that child group, not the next tab in the same |
75 // group of the removed tab. | 74 // group of the removed tab. |
76 NavigationController* removed_controller = | 75 NavigationController* removed_controller = |
77 &tabstrip_->GetTabContentsAt(removing_index)->controller(); | 76 &tabstrip_->GetTabContentsAt(removing_index)->controller(); |
78 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(removed_controller, | 77 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(removed_controller, |
79 removing_index, | 78 removing_index, |
80 false); | 79 false); |
81 if (index != TabStripModel::kNoTab) | 80 if (index != TabStripModel::kNoTab) |
82 return GetValidIndex(index, removing_index, is_remove); | 81 return GetValidIndex(index, removing_index); |
83 | 82 |
84 if (parent_opener) { | 83 if (parent_opener) { |
85 // If the tab was in a group, shift selection to the next tab in the group. | 84 // If the tab was in a group, shift selection to the next tab in the group. |
86 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(parent_opener, | 85 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(parent_opener, |
87 removing_index, | 86 removing_index, |
88 false); | 87 false); |
89 if (index != TabStripModel::kNoTab) | 88 if (index != TabStripModel::kNoTab) |
90 return GetValidIndex(index, removing_index, is_remove); | 89 return GetValidIndex(index, removing_index); |
91 | 90 |
92 // If we can't find a subsequent group member, just fall back to the | 91 // If we can't find a subsequent group member, just fall back to the |
93 // parent_opener itself. Note that we use "group" here since opener is | 92 // parent_opener itself. Note that we use "group" here since opener is |
94 // reset by select operations.. | 93 // reset by select operations.. |
95 index = tabstrip_->GetIndexOfController(parent_opener); | 94 index = tabstrip_->GetIndexOfController(parent_opener); |
96 if (index != TabStripModel::kNoTab) | 95 if (index != TabStripModel::kNoTab) |
97 return GetValidIndex(index, removing_index, is_remove); | 96 return GetValidIndex(index, removing_index); |
98 } | 97 } |
99 | 98 |
100 // No opener set, fall through to the default handler... | 99 // No opener set, fall through to the default handler... |
101 int selected_index = tabstrip_->selected_index(); | 100 int selected_index = tabstrip_->selected_index(); |
102 if (is_remove && selected_index >= (tab_count - 1)) | 101 if (selected_index >= (tab_count - 1)) |
103 return selected_index - 1; | 102 return selected_index - 1; |
104 return selected_index; | 103 return selected_index; |
105 } | 104 } |
106 | 105 |
107 void TabStripModelOrderController::TabSelectedAt(TabContents* old_contents, | 106 void TabStripModelOrderController::TabSelectedAt(TabContents* old_contents, |
108 TabContents* new_contents, | 107 TabContents* new_contents, |
109 int index, | 108 int index, |
110 bool user_gesture) { | 109 bool user_gesture) { |
111 NavigationController* old_opener = NULL; | 110 NavigationController* old_opener = NULL; |
112 if (old_contents) { | 111 if (old_contents) { |
(...skipping 13 matching lines...) Expand all Loading... |
126 new_opener != &old_contents->controller() && | 125 new_opener != &old_contents->controller() && |
127 old_opener != &new_contents->controller()) { | 126 old_opener != &new_contents->controller()) { |
128 tabstrip_->ForgetAllOpeners(); | 127 tabstrip_->ForgetAllOpeners(); |
129 } | 128 } |
130 } | 129 } |
131 | 130 |
132 /////////////////////////////////////////////////////////////////////////////// | 131 /////////////////////////////////////////////////////////////////////////////// |
133 // TabStripModelOrderController, private: | 132 // TabStripModelOrderController, private: |
134 | 133 |
135 int TabStripModelOrderController::GetValidIndex(int index, | 134 int TabStripModelOrderController::GetValidIndex(int index, |
136 int removing_index, | 135 int removing_index) const { |
137 bool is_remove) const { | 136 return removing_index < index ? std::max(0, index - 1) : index; |
138 if (is_remove && removing_index < index) | |
139 index = std::max(0, index - 1); | |
140 return index; | |
141 } | 137 } |
OLD | NEW |