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

Side by Side Diff: chrome/browser/ui/tabs/tab_strip_model.cc

Issue 11364196: Remove TabContents from TabStripModelObserver::ActiveTabChanged. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h" 5 #include "chrome/browser/ui/tabs/tab_strip_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 contents_data_[index]->contents = new_contents->web_contents(); 185 contents_data_[index]->contents = new_contents->web_contents();
186 186
187 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 187 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
188 TabReplacedAt(this, old_contents, new_contents, index)); 188 TabReplacedAt(this, old_contents, new_contents, index));
189 189
190 // When the active tab contents is replaced send out a selection notification 190 // When the active tab contents is replaced send out a selection notification
191 // too. We do this as nearly all observers need to treat a replacement of the 191 // too. We do this as nearly all observers need to treat a replacement of the
192 // selected contents as the selection changing. 192 // selected contents as the selection changing.
193 if (active_index() == index) { 193 if (active_index() == index) {
194 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 194 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
195 ActiveTabChanged(old_contents, new_contents, 195 ActiveTabChanged(old_contents->web_contents(),
196 new_contents->web_contents(),
196 active_index(), false)); 197 active_index(), false));
197 } 198 }
198 return old_contents; 199 return old_contents;
199 } 200 }
200 201
201 TabContents* TabStripModel::DiscardTabContentsAt(int index) { 202 TabContents* TabStripModel::DiscardTabContentsAt(int index) {
202 DCHECK(ContainsIndex(index)); 203 DCHECK(ContainsIndex(index));
203 // Do not discard active tab. 204 // Do not discard active tab.
204 if (active_index() == index) 205 if (active_index() == index)
205 return NULL; 206 return NULL;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 if (!selection_model_.empty()) { 258 if (!selection_model_.empty()) {
258 // The active tab was removed, but there is still something selected. 259 // The active tab was removed, but there is still something selected.
259 // Move the active and anchor to the first selected index. 260 // Move the active and anchor to the first selected index.
260 selection_model_.set_active(selection_model_.selected_indices()[0]); 261 selection_model_.set_active(selection_model_.selected_indices()[0]);
261 selection_model_.set_anchor(selection_model_.active()); 262 selection_model_.set_anchor(selection_model_.active());
262 } else { 263 } else {
263 // The active tab was removed and nothing is selected. Reset the 264 // The active tab was removed and nothing is selected. Reset the
264 // selection and send out notification. 265 // selection and send out notification.
265 selection_model_.SetSelectedIndex(next_selected_index); 266 selection_model_.SetSelectedIndex(next_selected_index);
266 } 267 }
267 NotifyIfActiveTabChanged(removed_contents, NOTIFY_DEFAULT); 268 NotifyIfActiveTabChanged(removed_contents->web_contents(),
269 NOTIFY_DEFAULT);
268 } 270 }
269 271
270 // Sending notification in case the detached tab was selected. Using 272 // Sending notification in case the detached tab was selected. Using
271 // NotifyIfActiveOrSelectionChanged() here would not guarantee that a 273 // NotifyIfActiveOrSelectionChanged() here would not guarantee that a
272 // notification is sent even though the tab selection has changed because 274 // notification is sent even though the tab selection has changed because
273 // |old_model| is stored after calling DecrementFrom(). 275 // |old_model| is stored after calling DecrementFrom().
274 if (was_selected) { 276 if (was_selected) {
275 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 277 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
276 TabSelectionChanged(this, old_model)); 278 TabSelectionChanged(this, old_model));
277 } 279 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // tab to do a quick look-up of something while viewing a tab earlier in 480 // tab to do a quick look-up of something while viewing a tab earlier in
479 // the strip). We can make this heuristic more permissive if need be. 481 // the strip). We can make this heuristic more permissive if need be.
480 if (!IsNewTabAtEndOfTabStrip(contents)) { 482 if (!IsNewTabAtEndOfTabStrip(contents)) {
481 // If the user navigates the current tab to another page in any way 483 // If the user navigates the current tab to another page in any way
482 // other than by clicking a link, we want to pro-actively forget all 484 // other than by clicking a link, we want to pro-actively forget all
483 // TabStrip opener relationships since we assume they're beginning a 485 // TabStrip opener relationships since we assume they're beginning a
484 // different task by reusing the current tab. 486 // different task by reusing the current tab.
485 ForgetAllOpeners(); 487 ForgetAllOpeners();
486 // In this specific case we also want to reset the group relationship, 488 // In this specific case we also want to reset the group relationship,
487 // since it is now technically invalid. 489 // since it is now technically invalid.
488 ForgetGroup(contents); 490 ForgetGroup(contents->web_contents());
489 } 491 }
490 } 492 }
491 } 493 }
492 494
493 void TabStripModel::ForgetAllOpeners() { 495 void TabStripModel::ForgetAllOpeners() {
494 // Forget all opener memories so we don't do anything weird with tab 496 // Forget all opener memories so we don't do anything weird with tab
495 // re-selection ordering. 497 // re-selection ordering.
496 for (WebContentsDataVector::const_iterator iter = contents_data_.begin(); 498 for (WebContentsDataVector::const_iterator iter = contents_data_.begin();
497 iter != contents_data_.end(); ++iter) 499 iter != contents_data_.end(); ++iter)
498 (*iter)->ForgetOpener(); 500 (*iter)->ForgetOpener();
499 } 501 }
500 502
501 void TabStripModel::ForgetGroup(TabContents* contents) { 503 void TabStripModel::ForgetGroup(WebContents* contents) {
502 int index = GetIndexOfTabContents(contents); 504 int index = GetIndexOfWebContents(contents);
503 DCHECK(ContainsIndex(index)); 505 DCHECK(ContainsIndex(index));
504 contents_data_[index]->SetGroup(NULL); 506 contents_data_[index]->SetGroup(NULL);
505 contents_data_[index]->ForgetOpener(); 507 contents_data_[index]->ForgetOpener();
506 } 508 }
507 509
508 bool TabStripModel::ShouldResetGroupOnSelect(TabContents* contents) const { 510 bool TabStripModel::ShouldResetGroupOnSelect(WebContents* contents) const {
509 int index = GetIndexOfTabContents(contents); 511 int index = GetIndexOfWebContents(contents);
510 DCHECK(ContainsIndex(index)); 512 DCHECK(ContainsIndex(index));
511 return contents_data_[index]->reset_group_on_select; 513 return contents_data_[index]->reset_group_on_select;
512 } 514 }
513 515
514 void TabStripModel::SetTabBlocked(int index, bool blocked) { 516 void TabStripModel::SetTabBlocked(int index, bool blocked) {
515 DCHECK(ContainsIndex(index)); 517 DCHECK(ContainsIndex(index));
516 if (contents_data_[index]->blocked == blocked) 518 if (contents_data_[index]->blocked == blocked)
517 return; 519 return;
518 contents_data_[index]->blocked = blocked; 520 contents_data_[index]->blocked = blocked;
519 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 521 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 return contents_data_[index]->contents; 1182 return contents_data_[index]->contents;
1181 } 1183 }
1182 1184
1183 void TabStripModel::NotifyIfTabDeactivated(WebContents* contents) { 1185 void TabStripModel::NotifyIfTabDeactivated(WebContents* contents) {
1184 if (contents) { 1186 if (contents) {
1185 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 1187 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
1186 TabDeactivated(contents)); 1188 TabDeactivated(contents));
1187 } 1189 }
1188 } 1190 }
1189 1191
1190 void TabStripModel::NotifyIfActiveTabChanged(TabContents* old_contents, 1192 void TabStripModel::NotifyIfActiveTabChanged(WebContents* old_contents,
1191 NotifyTypes notify_types) { 1193 NotifyTypes notify_types) {
1192 TabContents* new_contents = GetTabContentsAtImpl(active_index()); 1194 WebContents* new_contents = GetWebContentsAtImpl(active_index());
1193 if (old_contents != new_contents) { 1195 if (old_contents != new_contents) {
1194 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 1196 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
1195 ActiveTabChanged(old_contents, new_contents, 1197 ActiveTabChanged(old_contents, new_contents,
1196 active_index(), 1198 active_index(),
1197 notify_types == NOTIFY_USER_GESTURE)); 1199 notify_types == NOTIFY_USER_GESTURE));
1198 // Activating a discarded tab reloads it, so it is no longer discarded. 1200 // Activating a discarded tab reloads it, so it is no longer discarded.
1199 contents_data_[active_index()]->discarded = false; 1201 contents_data_[active_index()]->discarded = false;
1200 } 1202 }
1201 } 1203 }
1202 1204
1203 void TabStripModel::NotifyIfActiveOrSelectionChanged( 1205 void TabStripModel::NotifyIfActiveOrSelectionChanged(
1204 TabContents* old_contents, 1206 TabContents* old_contents,
1205 NotifyTypes notify_types, 1207 NotifyTypes notify_types,
1206 const TabStripSelectionModel& old_model) { 1208 const TabStripSelectionModel& old_model) {
1207 NotifyIfActiveTabChanged(old_contents, notify_types); 1209 NotifyIfActiveTabChanged(old_contents ? old_contents->web_contents() : NULL,
1210 notify_types);
1208 1211
1209 if (!selection_model().Equals(old_model)) { 1212 if (!selection_model().Equals(old_model)) {
1210 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 1213 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
1211 TabSelectionChanged(this, old_model)); 1214 TabSelectionChanged(this, old_model));
1212 } 1215 }
1213 } 1216 }
1214 1217
1215 void TabStripModel::SetSelection( 1218 void TabStripModel::SetSelection(
1216 const TabStripSelectionModel& new_model, 1219 const TabStripSelectionModel& new_model,
1217 NotifyTypes notify_types) { 1220 NotifyTypes notify_types) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 void TabStripModel::ForgetOpenersAndGroupsReferencing( 1304 void TabStripModel::ForgetOpenersAndGroupsReferencing(
1302 const WebContents* tab) { 1305 const WebContents* tab) {
1303 for (WebContentsDataVector::const_iterator i = contents_data_.begin(); 1306 for (WebContentsDataVector::const_iterator i = contents_data_.begin();
1304 i != contents_data_.end(); ++i) { 1307 i != contents_data_.end(); ++i) {
1305 if ((*i)->group == tab) 1308 if ((*i)->group == tab)
1306 (*i)->group = NULL; 1309 (*i)->group = NULL;
1307 if ((*i)->opener == tab) 1310 if ((*i)->opener == tab)
1308 (*i)->opener = NULL; 1311 (*i)->opener = NULL;
1309 } 1312 }
1310 } 1313 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tabs/tab_strip_model.h ('k') | chrome/browser/ui/tabs/tab_strip_model_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698