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

Unified Diff: chrome/browser/ui/tabs/tab_strip_model.cc

Issue 836223004: Fix tab insertion position after moving tab or nesting openers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add test Created 5 years, 11 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 | « no previous file | chrome/browser/ui/tabs/tab_strip_model_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/tabs/tab_strip_model.cc
diff --git a/chrome/browser/ui/tabs/tab_strip_model.cc b/chrome/browser/ui/tabs/tab_strip_model.cc
index 5fa230a0174e3ee1b4c84045ade31f89bf38709b..d3437a9db90347e45c2f7cd00f84bd7f2ba23195 100644
--- a/chrome/browser/ui/tabs/tab_strip_model.cc
+++ b/chrome/browser/ui/tabs/tab_strip_model.cc
@@ -6,6 +6,7 @@
#include <algorithm>
#include <map>
+#include <set>
#include <string>
#include "base/metrics/histogram.h"
@@ -598,11 +599,19 @@ int TabStripModel::GetIndexOfLastWebContentsOpenedBy(const WebContents* opener,
DCHECK(opener);
DCHECK(ContainsIndex(start_index));
- for (int i = contents_data_.size() - 1; i > start_index; --i) {
- if (contents_data_[i]->opener() == opener)
- return i;
+ std::set<const WebContents*> opener_and_descendants;
+ opener_and_descendants.insert(opener);
+ int last_index = kNoTab;
+
+ for (int i = start_index + 1; i < count(); ++i) {
+ // Test opened by transitively, i.e. include tabs opened by tabs opened by
+ // opener, etc. Stop when we find the first non-descendant.
+ if (!opener_and_descendants.count(contents_data_[i]->opener()))
+ break;
+ opener_and_descendants.insert(contents_data_[i]->web_contents());
+ last_index = i;
}
- return kNoTab;
+ return last_index;
}
void TabStripModel::TabNavigating(WebContents* contents,
« no previous file with comments | « no previous file | chrome/browser/ui/tabs/tab_strip_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698