| 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_wrapper.h" |
| 8 | 8 |
| 9 /////////////////////////////////////////////////////////////////////////////// | 9 /////////////////////////////////////////////////////////////////////////////// |
| 10 // TabStripModelOrderController, public: | 10 // TabStripModelOrderController, public: |
| 11 | 11 |
| 12 TabStripModelOrderController::TabStripModelOrderController( | 12 TabStripModelOrderController::TabStripModelOrderController( |
| 13 TabStripModel* tabstrip) | 13 TabStripModel* tabstrip) |
| 14 : tabstrip_(tabstrip), | 14 : tabstrip_(tabstrip), |
| 15 insertion_policy_(TabStripModel::INSERT_AFTER) { | 15 insertion_policy_(TabStripModel::INSERT_AFTER) { |
| 16 tabstrip_->AddObserver(this); | 16 tabstrip_->AddObserver(this); |
| 17 } | 17 } |
| 18 | 18 |
| 19 TabStripModelOrderController::~TabStripModelOrderController() { | 19 TabStripModelOrderController::~TabStripModelOrderController() { |
| 20 tabstrip_->RemoveObserver(this); | 20 tabstrip_->RemoveObserver(this); |
| 21 } | 21 } |
| 22 | 22 |
| 23 int TabStripModelOrderController::DetermineInsertionIndex( | 23 int TabStripModelOrderController::DetermineInsertionIndex( |
| 24 TabContents* new_contents, | 24 TabContentsWrapper* new_contents, |
| 25 PageTransition::Type transition, | 25 PageTransition::Type transition, |
| 26 bool foreground) { | 26 bool foreground) { |
| 27 int tab_count = tabstrip_->count(); | 27 int tab_count = tabstrip_->count(); |
| 28 if (!tab_count) | 28 if (!tab_count) |
| 29 return 0; | 29 return 0; |
| 30 | 30 |
| 31 // NOTE: TabStripModel enforces that all non-mini-tabs occur after mini-tabs, | 31 // NOTE: TabStripModel enforces that all non-mini-tabs occur after mini-tabs, |
| 32 // so we don't have to check here too. | 32 // so we don't have to check here too. |
| 33 if (transition == PageTransition::LINK && tabstrip_->selected_index() != -1) { | 33 if (transition == PageTransition::LINK && tabstrip_->selected_index() != -1) { |
| 34 int delta = (insertion_policy_ == TabStripModel::INSERT_AFTER) ? 1 : 0; | 34 int delta = (insertion_policy_ == TabStripModel::INSERT_AFTER) ? 1 : 0; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 97 } |
| 98 | 98 |
| 99 // No opener set, fall through to the default handler... | 99 // No opener set, fall through to the default handler... |
| 100 int selected_index = tabstrip_->selected_index(); | 100 int selected_index = tabstrip_->selected_index(); |
| 101 if (selected_index >= (tab_count - 1)) | 101 if (selected_index >= (tab_count - 1)) |
| 102 return selected_index - 1; | 102 return selected_index - 1; |
| 103 | 103 |
| 104 return selected_index; | 104 return selected_index; |
| 105 } | 105 } |
| 106 | 106 |
| 107 void TabStripModelOrderController::TabSelectedAt(TabContents* old_contents, | 107 void TabStripModelOrderController::TabSelectedAt( |
| 108 TabContents* new_contents, | 108 TabContentsWrapper* old_contents, |
| 109 int index, | 109 TabContentsWrapper* new_contents, |
| 110 bool user_gesture) { | 110 int index, |
| 111 bool user_gesture) { |
| 111 NavigationController* old_opener = NULL; | 112 NavigationController* old_opener = NULL; |
| 112 if (old_contents) { | 113 if (old_contents) { |
| 113 int index = tabstrip_->GetIndexOfTabContents(old_contents); | 114 int index = tabstrip_->GetIndexOfTabContents(old_contents); |
| 114 if (index != TabStripModel::kNoTab) { | 115 if (index != TabStripModel::kNoTab) { |
| 115 old_opener = tabstrip_->GetOpenerOfTabContentsAt(index); | 116 old_opener = tabstrip_->GetOpenerOfTabContentsAt(index); |
| 116 | 117 |
| 117 // Forget any group/opener relationships that need to be reset whenever | 118 // Forget any group/opener relationships that need to be reset whenever |
| 118 // selection changes (see comment in TabStripModel::AddTabContentsAt). | 119 // selection changes (see comment in TabStripModel::AddTabContentsAt). |
| 119 if (tabstrip_->ShouldResetGroupOnSelect(old_contents)) | 120 if (tabstrip_->ShouldResetGroupOnSelect(old_contents)) |
| 120 tabstrip_->ForgetGroup(old_contents); | 121 tabstrip_->ForgetGroup(old_contents); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 131 | 132 |
| 132 /////////////////////////////////////////////////////////////////////////////// | 133 /////////////////////////////////////////////////////////////////////////////// |
| 133 // TabStripModelOrderController, private: | 134 // TabStripModelOrderController, private: |
| 134 | 135 |
| 135 int TabStripModelOrderController::GetValidIndex( | 136 int TabStripModelOrderController::GetValidIndex( |
| 136 int index, int removing_index) const { | 137 int index, int removing_index) const { |
| 137 if (removing_index < index) | 138 if (removing_index < index) |
| 138 index = std::max(0, index - 1); | 139 index = std::max(0, index - 1); |
| 139 return index; | 140 return index; |
| 140 } | 141 } |
| OLD | NEW |