| 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 #include "content/browser/tab_contents/tab_contents.h" |
| 9 | 9 |
| 10 /////////////////////////////////////////////////////////////////////////////// | 10 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // NOTE: TabStripModel enforces that all non-mini-tabs occur after mini-tabs, | 32 // NOTE: TabStripModel enforces that all non-mini-tabs occur after mini-tabs, |
| 33 // so we don't have to check here too. | 33 // so we don't have to check here too. |
| 34 if (transition == content::PAGE_TRANSITION_LINK && | 34 if (transition == content::PAGE_TRANSITION_LINK && |
| 35 tabstrip_->active_index() != -1) { | 35 tabstrip_->active_index() != -1) { |
| 36 int delta = (insertion_policy_ == TabStripModel::INSERT_AFTER) ? 1 : 0; | 36 int delta = (insertion_policy_ == TabStripModel::INSERT_AFTER) ? 1 : 0; |
| 37 if (foreground) { | 37 if (foreground) { |
| 38 // 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 |
| 39 // tab, insert it adjacent to the tab that opened that link. | 39 // tab, insert it adjacent to the tab that opened that link. |
| 40 return tabstrip_->active_index() + delta; | 40 return tabstrip_->active_index() + delta; |
| 41 } | 41 } |
| 42 NavigationController* opener = | 42 content::NavigationController* opener = |
| 43 &tabstrip_->GetActiveTabContents()->tab_contents()->GetController(); | 43 &tabstrip_->GetActiveTabContents()->web_contents()->GetController(); |
| 44 // 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 |
| 45 // it... | 45 // it... |
| 46 int index; | 46 int index; |
| 47 if (insertion_policy_ == TabStripModel::INSERT_AFTER) { | 47 if (insertion_policy_ == TabStripModel::INSERT_AFTER) { |
| 48 index = tabstrip_->GetIndexOfLastTabContentsOpenedBy( | 48 index = tabstrip_->GetIndexOfLastTabContentsOpenedBy( |
| 49 opener, tabstrip_->active_index()); | 49 opener, tabstrip_->active_index()); |
| 50 } else { | 50 } else { |
| 51 index = tabstrip_->GetIndexOfFirstTabContentsOpenedBy( | 51 index = tabstrip_->GetIndexOfFirstTabContentsOpenedBy( |
| 52 opener, tabstrip_->active_index()); | 52 opener, tabstrip_->active_index()); |
| 53 } | 53 } |
| 54 if (index != TabStripModel::kNoTab) | 54 if (index != TabStripModel::kNoTab) |
| 55 return index + delta; | 55 return index + delta; |
| 56 // Otherwise insert adjacent to opener... | 56 // Otherwise insert adjacent to opener... |
| 57 return tabstrip_->active_index() + delta; | 57 return tabstrip_->active_index() + delta; |
| 58 } | 58 } |
| 59 // In other cases, such as Ctrl+T, open at the end of the strip. | 59 // In other cases, such as Ctrl+T, open at the end of the strip. |
| 60 return DetermineInsertionIndexForAppending(); | 60 return DetermineInsertionIndexForAppending(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 int TabStripModelOrderController::DetermineInsertionIndexForAppending() { | 63 int TabStripModelOrderController::DetermineInsertionIndexForAppending() { |
| 64 return (insertion_policy_ == TabStripModel::INSERT_AFTER) ? | 64 return (insertion_policy_ == TabStripModel::INSERT_AFTER) ? |
| 65 tabstrip_->count() : 0; | 65 tabstrip_->count() : 0; |
| 66 } | 66 } |
| 67 | 67 |
| 68 int TabStripModelOrderController::DetermineNewSelectedIndex( | 68 int TabStripModelOrderController::DetermineNewSelectedIndex( |
| 69 int removing_index) const { | 69 int removing_index) const { |
| 70 int tab_count = tabstrip_->count(); | 70 int tab_count = tabstrip_->count(); |
| 71 DCHECK(removing_index >= 0 && removing_index < tab_count); | 71 DCHECK(removing_index >= 0 && removing_index < tab_count); |
| 72 NavigationController* parent_opener = | 72 content::NavigationController* parent_opener = |
| 73 tabstrip_->GetOpenerOfTabContentsAt(removing_index); | 73 tabstrip_->GetOpenerOfTabContentsAt(removing_index); |
| 74 // 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 |
| 75 // 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 |
| 76 // group of the removed tab. | 76 // group of the removed tab. |
| 77 NavigationController* removed_controller = | 77 content::NavigationController* removed_controller = |
| 78 &tabstrip_->GetTabContentsAt(removing_index)-> | 78 &tabstrip_->GetTabContentsAt(removing_index)-> |
| 79 tab_contents()->GetController(); | 79 web_contents()->GetController(); |
| 80 // 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. |
| 81 DCHECK(parent_opener != removed_controller); | 81 DCHECK(parent_opener != removed_controller); |
| 82 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(removed_controller, | 82 int index = tabstrip_->GetIndexOfNextTabContentsOpenedBy(removed_controller, |
| 83 removing_index, | 83 removing_index, |
| 84 false); | 84 false); |
| 85 if (index != TabStripModel::kNoTab) | 85 if (index != TabStripModel::kNoTab) |
| 86 return GetValidIndex(index, removing_index); | 86 return GetValidIndex(index, removing_index); |
| 87 | 87 |
| 88 if (parent_opener) { | 88 if (parent_opener) { |
| 89 // 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 17 matching lines...) Expand all Loading... |
| 107 return selected_index - 1; | 107 return selected_index - 1; |
| 108 | 108 |
| 109 return selected_index; | 109 return selected_index; |
| 110 } | 110 } |
| 111 | 111 |
| 112 void TabStripModelOrderController::ActiveTabChanged( | 112 void TabStripModelOrderController::ActiveTabChanged( |
| 113 TabContentsWrapper* old_contents, | 113 TabContentsWrapper* old_contents, |
| 114 TabContentsWrapper* new_contents, | 114 TabContentsWrapper* new_contents, |
| 115 int index, | 115 int index, |
| 116 bool user_gesture) { | 116 bool user_gesture) { |
| 117 NavigationController* old_opener = NULL; | 117 content::NavigationController* old_opener = NULL; |
| 118 if (old_contents) { | 118 if (old_contents) { |
| 119 int index = tabstrip_->GetIndexOfTabContents(old_contents); | 119 int index = tabstrip_->GetIndexOfTabContents(old_contents); |
| 120 if (index != TabStripModel::kNoTab) { | 120 if (index != TabStripModel::kNoTab) { |
| 121 old_opener = tabstrip_->GetOpenerOfTabContentsAt(index); | 121 old_opener = tabstrip_->GetOpenerOfTabContentsAt(index); |
| 122 | 122 |
| 123 // Forget any group/opener relationships that need to be reset whenever | 123 // Forget any group/opener relationships that need to be reset whenever |
| 124 // selection changes (see comment in TabStripModel::AddTabContentsAt). | 124 // selection changes (see comment in TabStripModel::AddTabContentsAt). |
| 125 if (tabstrip_->ShouldResetGroupOnSelect(old_contents)) | 125 if (tabstrip_->ShouldResetGroupOnSelect(old_contents)) |
| 126 tabstrip_->ForgetGroup(old_contents); | 126 tabstrip_->ForgetGroup(old_contents); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 NavigationController* new_opener = | 129 content::NavigationController* new_opener = |
| 130 tabstrip_->GetOpenerOfTabContentsAt(index); | 130 tabstrip_->GetOpenerOfTabContentsAt(index); |
| 131 | 131 |
| 132 if (user_gesture && new_opener != old_opener && | 132 if (user_gesture && new_opener != old_opener && |
| 133 ((old_contents == NULL && new_opener == NULL) || | 133 ((old_contents == NULL && new_opener == NULL) || |
| 134 new_opener != &old_contents->tab_contents()->GetController()) && | 134 new_opener != &old_contents->tab_contents()->GetController()) && |
| 135 ((new_contents == NULL && old_opener == NULL) || | 135 ((new_contents == NULL && old_opener == NULL) || |
| 136 old_opener != &new_contents->tab_contents()->GetController())) { | 136 old_opener != &new_contents->tab_contents()->GetController())) { |
| 137 tabstrip_->ForgetAllOpeners(); | 137 tabstrip_->ForgetAllOpeners(); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 /////////////////////////////////////////////////////////////////////////////// | 141 /////////////////////////////////////////////////////////////////////////////// |
| 142 // TabStripModelOrderController, private: | 142 // TabStripModelOrderController, private: |
| 143 | 143 |
| 144 int TabStripModelOrderController::GetValidIndex( | 144 int TabStripModelOrderController::GetValidIndex( |
| 145 int index, int removing_index) const { | 145 int index, int removing_index) const { |
| 146 if (removing_index < index) | 146 if (removing_index < index) |
| 147 index = std::max(0, index - 1); | 147 index = std::max(0, index - 1); |
| 148 return index; | 148 return index; |
| 149 } | 149 } |
| OLD | NEW |