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