Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(611)

Unified Diff: ios/shared/chrome/browser/tabs/web_state_list_order_controller.mm

Issue 2703333006: Move the notion of current Tab from TabModel to WebStateList. (Closed)
Patch Set: Rebase. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/shared/chrome/browser/tabs/web_state_list_order_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/shared/chrome/browser/tabs/web_state_list_order_controller.mm
diff --git a/ios/shared/chrome/browser/tabs/web_state_list_order_controller.mm b/ios/shared/chrome/browser/tabs/web_state_list_order_controller.mm
index cafb8a4a86b9f1fd5e5d38f0df681f429a54a3aa..479224619fed6401e87a2324b73f5f604660b639 100644
--- a/ios/shared/chrome/browser/tabs/web_state_list_order_controller.mm
+++ b/ios/shared/chrome/browser/tabs/web_state_list_order_controller.mm
@@ -40,3 +40,50 @@ int WebStateListOrderController::DetermineInsertionIndex(
DCHECK_LT(reference_index, INT_MAX);
return reference_index + 1;
}
+
+int WebStateListOrderController::DetermineNewActiveIndex(
+ int removing_index) const {
+ DCHECK(web_state_list_->ContainsIndex(removing_index));
+ // First see if the index being removed has any "child" WebState. If it does,
+ // select the first WebState in that child group, not the next in the removed
+ // index group.
+ int index = web_state_list_->GetIndexOfNextWebStateOpenedBy(
+ web_state_list_->GetWebStateAt(removing_index), removing_index, false);
+
+ if (index != WebStateList::kInvalidIndex)
+ return GetValidIndex(index, removing_index);
+
+ web::WebState* opener =
+ web_state_list_->GetOpenerOfWebStateAt(removing_index);
+ if (opener) {
+ // If the WebState was in a group, shift selection to the next WebState in
+ // the group.
+ int index = web_state_list_->GetIndexOfNextWebStateOpenedBy(
+ opener, removing_index, false);
+
+ if (index != WebStateList::kInvalidIndex)
+ return GetValidIndex(index, removing_index);
+
+ // If there is no subsequent group member, just fall back to opener itself.
+ index = web_state_list_->GetIndexOfWebState(opener);
+ return GetValidIndex(index, removing_index);
+ }
+
+ // If this is the last WebState in the WebStateList, clear the selection.
+ if (web_state_list_->count() == 1)
+ return WebStateList::kInvalidIndex;
+
+ // No opener, fall through to the default handler, i.e. returning the previous
+ // WebState if the removed one is the last, otherwise returning the next one.
+ if (removing_index >= web_state_list_->count() - 1)
+ return removing_index - 1;
+
+ return removing_index;
+}
+
+int WebStateListOrderController::GetValidIndex(int index,
+ int removing_index) const {
+ if (removing_index < index)
+ return std::min(0, index - 1);
+ return index;
+}
« no previous file with comments | « ios/shared/chrome/browser/tabs/web_state_list_order_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698