OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/tabs/tab_strip_model_order_controller.h" | 5 #include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h" |
6 | 6 |
7 #include "content/public/browser/web_contents.h" | 7 #include "content/public/browser/web_contents.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 tabstrip_->AddObserver(this); | 15 tabstrip_->AddObserver(this); |
16 } | 16 } |
17 | 17 |
18 TabStripModelOrderController::~TabStripModelOrderController() { | 18 TabStripModelOrderController::~TabStripModelOrderController() { |
19 tabstrip_->RemoveObserver(this); | 19 tabstrip_->RemoveObserver(this); |
20 } | 20 } |
21 | 21 |
22 int TabStripModelOrderController::DetermineInsertionIndex( | 22 int TabStripModelOrderController::DetermineInsertionIndex( |
23 content::PageTransition transition, | 23 ui::PageTransition transition, |
24 bool foreground) { | 24 bool foreground) { |
25 int tab_count = tabstrip_->count(); | 25 int tab_count = tabstrip_->count(); |
26 if (!tab_count) | 26 if (!tab_count) |
27 return 0; | 27 return 0; |
28 | 28 |
29 // NOTE: TabStripModel enforces that all non-mini-tabs occur after mini-tabs, | 29 // NOTE: TabStripModel enforces that all non-mini-tabs occur after mini-tabs, |
30 // so we don't have to check here too. | 30 // so we don't have to check here too. |
31 if (transition == content::PAGE_TRANSITION_LINK && | 31 if (transition == ui::PAGE_TRANSITION_LINK && |
32 tabstrip_->active_index() != -1) { | 32 tabstrip_->active_index() != -1) { |
33 if (foreground) { | 33 if (foreground) { |
34 // If the page was opened in the foreground by a link click in another | 34 // If the page was opened in the foreground by a link click in another |
35 // tab, insert it adjacent to the tab that opened that link. | 35 // tab, insert it adjacent to the tab that opened that link. |
36 return tabstrip_->active_index() + 1; | 36 return tabstrip_->active_index() + 1; |
37 } | 37 } |
38 content::WebContents* opener = tabstrip_->GetActiveWebContents(); | 38 content::WebContents* opener = tabstrip_->GetActiveWebContents(); |
39 // Get the index of the next item opened by this tab, and insert after | 39 // Get the index of the next item opened by this tab, and insert after |
40 // it... | 40 // it... |
41 int index = tabstrip_->GetIndexOfLastWebContentsOpenedBy( | 41 int index = tabstrip_->GetIndexOfLastWebContentsOpenedBy( |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 /////////////////////////////////////////////////////////////////////////////// | 123 /////////////////////////////////////////////////////////////////////////////// |
124 // TabStripModelOrderController, private: | 124 // TabStripModelOrderController, private: |
125 | 125 |
126 int TabStripModelOrderController::GetValidIndex( | 126 int TabStripModelOrderController::GetValidIndex( |
127 int index, int removing_index) const { | 127 int index, int removing_index) const { |
128 if (removing_index < index) | 128 if (removing_index < index) |
129 index = std::max(0, index - 1); | 129 index = std::max(0, index - 1); |
130 return index; | 130 return index; |
131 } | 131 } |
OLD | NEW |