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

Unified Diff: ios/chrome/browser/tabs/tab_model.mm

Issue 2699833004: Add WebStateListOrderController to control WebState insertion. (Closed)
Patch Set: 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
Index: ios/chrome/browser/tabs/tab_model.mm
diff --git a/ios/chrome/browser/tabs/tab_model.mm b/ios/chrome/browser/tabs/tab_model.mm
index 96e8eef16dfcbe91fd34e1314dd67ec9ead3ad3f..7a9a5acb901ab75f10be7a1405637df59b774fd3 100644
--- a/ios/chrome/browser/tabs/tab_model.mm
+++ b/ios/chrome/browser/tabs/tab_model.mm
@@ -549,15 +549,23 @@ web::WebState* GetOpenerForWebState(const WebStateList& web_state_list,
return tab;
}
-- (void)insertTab:(Tab*)tab atIndex:(NSUInteger)index {
+- (void)insertTab:(Tab*)tab
+ atIndex:(NSUInteger)index
+ transition:(ui::PageTransition)transition {
DCHECK(tab);
DCHECK(![_tabRetainer containsObject:tab]);
- DCHECK_LE(index, static_cast<NSUInteger>(INT_MAX));
+
+ int insertion_index;
+ if (index == TabModelConstants::kTabPositionAutomatically) {
+ insertion_index = WebStateList::kInvalidIndex;
+ } else {
+ DCHECK_LE(index, static_cast<NSUInteger>(INT_MAX));
+ insertion_index = static_cast<int>(index);
+ }
[_tabRetainer addObject:tab];
- _webStateList.InsertWebState(
- static_cast<int>(index), tab.webState,
- GetOpenerForWebState(_webStateList, tab.webState));
+ _webStateList.AddWebState(insertion_index, transition, tab.webState,
+ GetOpenerForWebState(_webStateList, tab.webState));
// Persist the session due to a new tab being inserted. If this is a
// background tab (will not become active), saving now will capture the
@@ -568,6 +576,14 @@ web::WebState* GetOpenerForWebState(const WebStateList& web_state_list,
++_newTabCount;
}
+- (void)insertTab:(Tab*)tab atIndex:(NSUInteger)index {
+ DCHECK(tab);
+ DCHECK(![_tabRetainer containsObject:tab]);
+ DCHECK_LE(index, static_cast<NSUInteger>(INT_MAX));
+
+ [self insertTab:tab atIndex:index transition:ui::PAGE_TRANSITION_GENERATED];
+}
+
- (void)moveTab:(Tab*)tab toIndex:(NSUInteger)toIndex {
DCHECK([_tabRetainer containsObject:tab]);
DCHECK_LE(toIndex, static_cast<NSUInteger>(INT_MAX));
@@ -857,39 +873,7 @@ web::WebState* GetOpenerForWebState(const WebStateList& web_state_list,
browserState:_browserState]);
[tab webController].webUsageEnabled = webUsageEnabled_;
- if ((PageTransitionCoreTypeIs(params.transition_type,
- ui::PAGE_TRANSITION_LINK)) &&
- (index == TabModelConstants::kTabPositionAutomatically)) {
- DCHECK(!parentTab || [self indexOfTab:parentTab] != NSNotFound);
- // Assume tabs opened via link clicks are part of the same "task" as their
- // parent and are grouped together.
- TabModelOrderConstants::InsertionAdjacency adjacency =
- inBackground ? TabModelOrderConstants::kAdjacentAfter
- : TabModelOrderConstants::kAdjacentBefore;
- index = [_orderController insertionIndexForTab:tab
- transition:params.transition_type
- opener:parentTab
- adjacency:adjacency];
- } else {
- // For all other types, respect what was passed to us, normalizing values
- // that are too large.
- if (index >= self.count)
- index = [_orderController insertionIndexForAppending];
- }
-
- if (PageTransitionCoreTypeIs(params.transition_type,
- ui::PAGE_TRANSITION_TYPED) &&
- index == self.count) {
- // Also, any tab opened at the end of the TabStrip with a "TYPED"
- // transition inherit group as well. This covers the cases where the user
- // creates a New Tab (e.g. Ctrl+T, or clicks the New Tab button), or types
- // in the address bar and presses Alt+Enter. This allows for opening a new
- // Tab to quickly look up something. When this Tab is closed, the old one
- // is re-selected, not the next-adjacent.
- // TODO(crbug.com/661988): Make this work.
- }
-
- [self insertTab:tab atIndex:index];
+ [self insertTab:tab atIndex:index transition:params.transition_type];
if (!inBackground && _tabUsageRecorder)
_tabUsageRecorder->TabCreatedForSelection(tab);
@@ -1087,7 +1071,7 @@ web::WebState* GetOpenerForWebState(const WebStateList& web_state_list,
referrer:referrer
windowName:windowName
opener:nil
- atIndex:[_orderController insertionIndexForAppending]];
+ atIndex:self.count];
}
- (Tab*)insertTabWithURL:(const GURL&)URL

Powered by Google App Engine
This is Rietveld 408576698