| 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/ui/tab_contents/tab_contents_wrapper.h" | 7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.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, volatile int* reason) const { | 67 int removing_index) const { |
| 68 int tab_count = tabstrip_->count(); | 68 int tab_count = tabstrip_->count(); |
| 69 DCHECK(removing_index >= 0 && removing_index < tab_count); | 69 DCHECK(removing_index >= 0 && removing_index < tab_count); |
| 70 NavigationController* parent_opener = | 70 NavigationController* parent_opener = |
| 71 tabstrip_->GetOpenerOfTabContentsAt(removing_index); | 71 tabstrip_->GetOpenerOfTabContentsAt(removing_index); |
| 72 // 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 |
| 73 // 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 |
| 74 // group of the removed tab. | 74 // group of the removed tab. |
| 75 NavigationController* removed_controller = | 75 NavigationController* removed_controller = |
| 76 &tabstrip_->GetTabContentsAt(removing_index)->controller(); | 76 &tabstrip_->GetTabContentsAt(removing_index)->controller(); |
| 77 // The parent opener should never be the same as the controller being removed. | 77 // The parent opener should never be the same as the controller being removed. |
| 78 CHECK(parent_opener != removed_controller); | 78 DCHECK(parent_opener != removed_controller); |
| 79 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(removed_controller, | 79 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(removed_controller, |
| 80 removing_index, | 80 removing_index, |
| 81 false); | 81 false); |
| 82 if (index != TabStripModel::kNoTab) { | 82 if (index != TabStripModel::kNoTab) |
| 83 *reason = 1; | |
| 84 return GetValidIndex(index, removing_index); | 83 return GetValidIndex(index, removing_index); |
| 85 } | |
| 86 | 84 |
| 87 if (parent_opener) { | 85 if (parent_opener) { |
| 88 // If the tab was in a group, shift selection to the next tab in the group. | 86 // If the tab was in a group, shift selection to the next tab in the group. |
| 89 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(parent_opener, | 87 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(parent_opener, |
| 90 removing_index, | 88 removing_index, |
| 91 false); | 89 false); |
| 92 if (index != TabStripModel::kNoTab) { | 90 if (index != TabStripModel::kNoTab) |
| 93 *reason = 2; | |
| 94 return GetValidIndex(index, removing_index); | 91 return GetValidIndex(index, removing_index); |
| 95 } | |
| 96 | 92 |
| 97 // If we can't find a subsequent group member, just fall back to the | 93 // If we can't find a subsequent group member, just fall back to the |
| 98 // parent_opener itself. Note that we use "group" here since opener is | 94 // parent_opener itself. Note that we use "group" here since opener is |
| 99 // reset by select operations.. | 95 // reset by select operations.. |
| 100 index = tabstrip_->GetIndexOfController(parent_opener); | 96 index = tabstrip_->GetIndexOfController(parent_opener); |
| 101 if (index != TabStripModel::kNoTab) { | 97 if (index != TabStripModel::kNoTab) |
| 102 *reason = 3; | |
| 103 return GetValidIndex(index, removing_index); | 98 return GetValidIndex(index, removing_index); |
| 104 } | |
| 105 } | 99 } |
| 106 | 100 |
| 107 // No opener set, fall through to the default handler... | 101 // No opener set, fall through to the default handler... |
| 108 int selected_index = tabstrip_->selected_index(); | 102 int selected_index = tabstrip_->selected_index(); |
| 109 if (selected_index >= (tab_count - 1)) { | 103 if (selected_index >= (tab_count - 1)) |
| 110 *reason = 4; | |
| 111 return selected_index - 1; | 104 return selected_index - 1; |
| 112 } | |
| 113 | 105 |
| 114 *reason = 5; | |
| 115 return selected_index; | 106 return selected_index; |
| 116 } | 107 } |
| 117 | 108 |
| 118 void TabStripModelOrderController::TabSelectedAt( | 109 void TabStripModelOrderController::TabSelectedAt( |
| 119 TabContentsWrapper* old_contents, | 110 TabContentsWrapper* old_contents, |
| 120 TabContentsWrapper* new_contents, | 111 TabContentsWrapper* new_contents, |
| 121 int index, | 112 int index, |
| 122 bool user_gesture) { | 113 bool user_gesture) { |
| 123 NavigationController* old_opener = NULL; | 114 NavigationController* old_opener = NULL; |
| 124 if (old_contents) { | 115 if (old_contents) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 143 | 134 |
| 144 /////////////////////////////////////////////////////////////////////////////// | 135 /////////////////////////////////////////////////////////////////////////////// |
| 145 // TabStripModelOrderController, private: | 136 // TabStripModelOrderController, private: |
| 146 | 137 |
| 147 int TabStripModelOrderController::GetValidIndex( | 138 int TabStripModelOrderController::GetValidIndex( |
| 148 int index, int removing_index) const { | 139 int index, int removing_index) const { |
| 149 if (removing_index < index) | 140 if (removing_index < index) |
| 150 index = std::max(0, index - 1); | 141 index = std::max(0, index - 1); |
| 151 return index; | 142 return index; |
| 152 } | 143 } |
| OLD | NEW |