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

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

Issue 7033048: Multi-tab: Adding new Notification when tab selection changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing comments. Created 9 years, 7 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: chrome/browser/tabs/tab_strip_model.cc
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index ea3977e2999eb562da80c0ac1da047155999f80e..3dc823ef40bb02dcf0fcd0e580062f4e2702ad22 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -569,15 +569,16 @@ int TabStripModel::ConstrainInsertionIndex(int index, bool mini_tab) {
void TabStripModel::ExtendSelectionTo(int index) {
DCHECK(ContainsIndex(index));
- int old_active = active_index();
+ TabStripSelectionModel old_selection_model;
+ old_selection_model.Copy(selection_model());
selection_model_.SetSelectionFromAnchorTo(index);
- // This may not have resulted in a change, but we assume it did.
- NotifyActiveTabChanged(old_active);
+ NotifyIfActiveOrSelectionChanged(old_selection_model);
}
void TabStripModel::ToggleSelectionAt(int index) {
DCHECK(ContainsIndex(index));
- int old_active = active_index();
+ TabStripSelectionModel old_selection_model;
+ old_selection_model.Copy(selection_model());
if (selection_model_.IsSelected(index)) {
if (selection_model_.size() == 1) {
// One tab must be selected and this tab is currently selected so we can't
@@ -593,13 +594,14 @@ void TabStripModel::ToggleSelectionAt(int index) {
selection_model_.set_anchor(index);
selection_model_.set_active(index);
}
- NotifyActiveTabChanged(old_active);
+ NotifyIfActiveOrSelectionChanged(old_selection_model);
}
void TabStripModel::AddSelectionFromAnchorTo(int index) {
- int old_active = active_index();
+ TabStripSelectionModel old_selection_model;
+ old_selection_model.Copy(selection_model());
selection_model_.AddSelectionFromAnchorTo(index);
- NotifyActiveTabChanged(old_active);
+ NotifyIfActiveOrSelectionChanged(old_selection_model);
}
bool TabStripModel::IsTabSelected(int index) const {
@@ -610,10 +612,10 @@ bool TabStripModel::IsTabSelected(int index) const {
void TabStripModel::SetSelectionFromModel(
const TabStripSelectionModel& source) {
DCHECK_NE(TabStripSelectionModel::kUnselectedIndex, source.active());
- int old_active_index = active_index();
+ TabStripSelectionModel old_selection_model;
+ old_selection_model.Copy(selection_model());
selection_model_.Copy(source);
- // This may not have resulted in a change, but we assume it did.
- NotifyActiveTabChanged(old_active_index);
+ NotifyIfActiveOrSelectionChanged(old_selection_model);
}
void TabStripModel::AddTabContents(TabContentsWrapper* contents,
@@ -1236,6 +1238,20 @@ void TabStripModel::NotifyActiveTabChanged(int old_active_index) {
ActiveTabChanged(old_tab, new_tab, active_index(), true));
}
+void TabStripModel::NotifySelectionChanged(
+ const TabStripSelectionModel& old_selection_model) {
+ FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
+ TabSelectionChanged(old_selection_model));
+}
+
+void TabStripModel::NotifyIfActiveOrSelectionChanged(
+ const TabStripSelectionModel& old_selection_model) {
+ if (old_selection_model.active() != active_index())
+ NotifyActiveTabChanged(old_selection_model.active());
+ if (!selection_model().Equals(old_selection_model))
+ NotifySelectionChanged(old_selection_model);
+}
+
void TabStripModel::SelectRelativeTab(bool next) {
// This may happen during automated testing or if a user somehow buffers
// many key accelerators.

Powered by Google App Engine
This is Rietveld 408576698