summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tabs
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-06 00:43:16 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-06 00:43:16 +0000
commitdf72ac7d639a53573b3696dc5174e37a5a32ce07 (patch)
tree24eb66d053f2893da731113a6edaf5ea8366c82a /chrome/browser/tabs
parent0fe52a020563061cc9b354f5a3892080b8500d8f (diff)
downloadchromium_src-df72ac7d639a53573b3696dc5174e37a5a32ce07.zip
chromium_src-df72ac7d639a53573b3696dc5174e37a5a32ce07.tar.gz
chromium_src-df72ac7d639a53573b3696dc5174e37a5a32ce07.tar.bz2
Makes mini-tabs work on the UI side (at least for views). I still have
a handful of things to resolve before I turn on pinning. BUG=32845 TEST=none Review URL: http://codereview.chromium.org/579011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38287 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tabs')
-rw-r--r--chrome/browser/tabs/tab_strip_model.cc30
-rw-r--r--chrome/browser/tabs/tab_strip_model.h27
2 files changed, 33 insertions, 24 deletions
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index 4730f76..167604f 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -108,12 +108,7 @@ void TabStripModel::InsertTabContentsAt(int index,
bool foreground,
bool inherit_group,
bool pinned) {
- // Make sure the index maintains that all app tab occurs before non-app tabs.
- int first_non_mini_tab = IndexOfFirstNonMiniTab();
- if (contents->is_app() || pinned)
- index = std::min(first_non_mini_tab, index);
- else
- index = std::max(first_non_mini_tab, index);
+ index = ConstrainInsertionIndex(index, contents->is_app() || pinned);
// In tab dragging situations, if the last tab in the window was detached
// then the user aborted the drag, we will have the |closing_all_| member
@@ -169,11 +164,11 @@ TabContents* TabStripModel::DetachTabContentsAt(int index) {
DCHECK(ContainsIndex(index));
TabContents* removed_contents = GetContentsAt(index);
- next_selected_index_ =
+ int next_selected_index =
order_controller_->DetermineNewSelectedIndex(index, true);
- next_selected_index_ = IndexOfNextNonPhantomTab(next_selected_index_, -1);
delete contents_data_.at(index);
contents_data_.erase(contents_data_.begin() + index);
+ next_selected_index = IndexOfNextNonPhantomTab(next_selected_index, -1);
if (!HasNonPhantomTabs())
closing_all_ = true;
TabStripModelObservers::Iterator iter(observers_);
@@ -184,15 +179,13 @@ TabContents* TabStripModel::DetachTabContentsAt(int index) {
}
if (HasNonPhantomTabs()) {
if (index == selected_index_) {
- ChangeSelectedContentsFrom(removed_contents, next_selected_index_,
- false);
+ ChangeSelectedContentsFrom(removed_contents, next_selected_index, false);
} else if (index < selected_index_) {
// The selected tab didn't change, but its position shifted; update our
// index to continue to point at it.
--selected_index_;
}
}
- next_selected_index_ = selected_index_;
return removed_contents;
}
@@ -405,6 +398,10 @@ void TabStripModel::SetTabPinned(int index, bool pinned) {
MoveTabContentsAtImpl(index, non_mini_tab_index - 1, false);
return; // Don't send TabPinnedStateChanged notification.
}
+
+ FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
+ TabMiniStateChanged(contents_data_[index]->contents,
+ index));
}
// else: the tab was at the boundary and it's position doesn't need to
@@ -444,6 +441,11 @@ int TabStripModel::IndexOfFirstNonMiniTab() const {
return count();
}
+int TabStripModel::ConstrainInsertionIndex(int index, bool mini_tab) {
+ return mini_tab ? std::min(std::max(0, index), IndexOfFirstNonMiniTab()) :
+ std::min(count(), std::max(index, IndexOfFirstNonMiniTab()));
+}
+
void TabStripModel::AddTabContents(TabContents* contents,
int index,
bool force_index,
@@ -547,8 +549,7 @@ bool TabStripModel::IsContextMenuCommandEnabled(
switch (command_id) {
case CommandNewTab:
case CommandCloseTab:
- // Phantom tabs can't be closed.
- return !IsPhantomTab(context_index);
+ return true;
case CommandReload:
if (TabContents* contents = GetTabContentsAt(context_index)) {
return contents->delegate()->CanReloadContents(contents);
@@ -858,6 +859,9 @@ int TabStripModel::IndexOfNextNonPhantomTab(int index,
bool TabStripModel::ShouldMakePhantomOnClose(int index) {
if (IsTabPinned(index) && !IsPhantomTab(index) && !closing_all_ &&
profile()) {
+ if (!IsAppTab(index))
+ return true; // Always make non-app tabs go phantom.
+
ExtensionsService* extension_service = profile()->GetExtensionsService();
if (!extension_service)
return false;
diff --git a/chrome/browser/tabs/tab_strip_model.h b/chrome/browser/tabs/tab_strip_model.h
index 8c6f546..67a5243 100644
--- a/chrome/browser/tabs/tab_strip_model.h
+++ b/chrome/browser/tabs/tab_strip_model.h
@@ -105,8 +105,17 @@ class TabStripModelObserver {
// Invoked when the mini state of a tab changes. This is not invoked if the
// tab ends up moving as a result of the mini state changing.
+ // See note in TabMiniStateChanged as to how this relates to
+ // TabMiniStateChanged.
virtual void TabPinnedStateChanged(TabContents* contents, int index) {}
+ // Invoked if the mini state of a tab changes. This is not invoked if the
+ // tab ends up moving as a result of the mini state changing.
+ // NOTE: this is sent when the pinned state of a non-app tab changes and is
+ // sent in addition to TabPinnedStateChanged. UI code typically need not care
+ // about TabPinnedStateChanged, but instead this.
+ virtual void TabMiniStateChanged(TabContents* contents, int index) {}
+
// Invoked when the blocked state of a tab changes.
// NOTE: This is invoked when a tab becomes blocked/unblocked by a tab modal
// window.
@@ -294,9 +303,6 @@ class TabStripModel : public NotificationObserver {
// Retrieve the index of the currently selected TabContents.
int selected_index() const { return selected_index_; }
- // See documentation for |next_selected_index_| below.
- int next_selected_index() const { return next_selected_index_; }
-
// Returns true if the tabstrip is currently closing all open tabs (via a
// call to CloseAllTabs). As tabs close, the selection in the tabstrip
// changes which notifies observers, which can use this as an optimization to
@@ -490,6 +496,13 @@ class TabStripModel : public NotificationObserver {
// mini-tabs.
int IndexOfFirstNonMiniTab() const;
+ // Returns a valid index for inserting a new tab into this model. |index| is
+ // the proposed index and |mini_tab| is true if inserting a tab will become
+ // mini (pinned or app). If |mini_tab| is true, the returned index is between
+ // 0 and IndexOfFirstNonMiniTab. If |mini_tab| is false, the returned index
+ // is between IndexOfFirstNonMiniTab and count().
+ int ConstrainInsertionIndex(int index, bool mini_tab);
+
// Command level API /////////////////////////////////////////////////////////
// Adds a TabContents at the best position in the TabStripModel given the
@@ -702,14 +715,6 @@ class TabStripModel : public NotificationObserver {
// The index of the TabContents in |contents_| that is currently selected.
int selected_index_;
- // The index of the TabContnets in |contents_| that will be selected when the
- // current composite operation completes. A Tab Detach is an example of a
- // composite operation - it not only removes a tab from the strip, but also
- // causes the selection to shift. Some code needs to know what the next
- // selected index will be. In other cases, this value is equal to
- // selected_index_.
- int next_selected_index_;
-
// A profile associated with this TabStripModel, used when creating new Tabs.
Profile* profile_;