summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-17 21:53:52 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-17 21:53:52 +0000
commite1337b08c312de212bcea1f40137a391f6f6794c (patch)
treecb3e97ca6d72276817cf67b28e82a60906ccffd7 /chrome
parent34d1d1d43e1552c547e4592817579200a69ed99f (diff)
downloadchromium_src-e1337b08c312de212bcea1f40137a391f6f6794c.zip
chromium_src-e1337b08c312de212bcea1f40137a391f6f6794c.tar.gz
chromium_src-e1337b08c312de212bcea1f40137a391f6f6794c.tar.bz2
Tweaks selected tab rendering to look better when multiple tabs are
selected. Also converts a handful of things to use active instead of selected. I need to rename a bunch of things, but will do that separately. BUG=76077 TEST=see bug, also covered by test Review URL: http://codereview.chromium.org/6665061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78608 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/ui/views/tabs/base_tab.cc4
-rw-r--r--chrome/browser/ui/views/tabs/base_tab.h3
-rw-r--r--chrome/browser/ui/views/tabs/base_tab_strip.cc6
-rw-r--r--chrome/browser/ui/views/tabs/base_tab_strip.h1
-rw-r--r--chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc4
-rw-r--r--chrome/browser/ui/views/tabs/browser_tab_strip_controller.h1
-rw-r--r--chrome/browser/ui/views/tabs/side_tab.cc1
-rw-r--r--chrome/browser/ui/views/tabs/tab.cc28
-rw-r--r--chrome/browser/ui/views/tabs/tab_controller.h6
-rw-r--r--chrome/browser/ui/views/tabs/tab_strip.cc57
-rw-r--r--chrome/browser/ui/views/tabs/tab_strip_controller.h6
11 files changed, 86 insertions, 31 deletions
diff --git a/chrome/browser/ui/views/tabs/base_tab.cc b/chrome/browser/ui/views/tabs/base_tab.cc
index e2ee6a3..cef7d9c 100644
--- a/chrome/browser/ui/views/tabs/base_tab.cc
+++ b/chrome/browser/ui/views/tabs/base_tab.cc
@@ -269,6 +269,10 @@ bool BaseTab::IsCloseable() const {
return controller() ? controller()->IsTabCloseable(this) : true;
}
+bool BaseTab::IsActive() const {
+ return controller() ? controller()->IsActiveTab(this) : true;
+}
+
bool BaseTab::IsSelected() const {
return controller() ? controller()->IsTabSelected(this) : true;
}
diff --git a/chrome/browser/ui/views/tabs/base_tab.h b/chrome/browser/ui/views/tabs/base_tab.h
index c096f58..e735fef 100644
--- a/chrome/browser/ui/views/tabs/base_tab.h
+++ b/chrome/browser/ui/views/tabs/base_tab.h
@@ -76,6 +76,9 @@ class BaseTab : public ui::AnimationDelegate,
// Returns true if the tab is closeable.
bool IsCloseable() const;
+ // Returns true if this tab is the active tab.
+ bool IsActive() const;
+
// Returns true if the tab is selected.
virtual bool IsSelected() const;
diff --git a/chrome/browser/ui/views/tabs/base_tab_strip.cc b/chrome/browser/ui/views/tabs/base_tab_strip.cc
index baa3b36..c222aff 100644
--- a/chrome/browser/ui/views/tabs/base_tab_strip.cc
+++ b/chrome/browser/ui/views/tabs/base_tab_strip.cc
@@ -278,6 +278,12 @@ void BaseTabStrip::ShowContextMenuForTab(BaseTab* tab, const gfx::Point& p) {
controller_->ShowContextMenuForTab(tab, p);
}
+bool BaseTabStrip::IsActiveTab(const BaseTab* tab) const {
+ int model_index = GetModelIndexOfBaseTab(tab);
+ return IsValidModelIndex(model_index) &&
+ controller_->IsActiveTab(model_index);
+}
+
bool BaseTabStrip::IsTabSelected(const BaseTab* tab) const {
int model_index = GetModelIndexOfBaseTab(tab);
return IsValidModelIndex(model_index) &&
diff --git a/chrome/browser/ui/views/tabs/base_tab_strip.h b/chrome/browser/ui/views/tabs/base_tab_strip.h
index 58fabd5..958b538 100644
--- a/chrome/browser/ui/views/tabs/base_tab_strip.h
+++ b/chrome/browser/ui/views/tabs/base_tab_strip.h
@@ -126,6 +126,7 @@ class BaseTabStrip : public AbstractTabStripView,
virtual void CloseTab(BaseTab* tab) OVERRIDE;
virtual void ShowContextMenuForTab(BaseTab* tab,
const gfx::Point& p) OVERRIDE;
+ virtual bool IsActiveTab(const BaseTab* tab) const OVERRIDE;
virtual bool IsTabSelected(const BaseTab* tab) const OVERRIDE;
virtual bool IsTabPinned(const BaseTab* tab) const OVERRIDE;
virtual bool IsTabCloseable(const BaseTab* tab) const OVERRIDE;
diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
index a662e63..56bcfa6 100644
--- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
+++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc
@@ -192,6 +192,10 @@ bool BrowserTabStripController::IsValidIndex(int index) const {
return model_->ContainsIndex(index);
}
+bool BrowserTabStripController::IsActiveTab(int model_index) const {
+ return model_->selected_index() == model_index;
+}
+
bool BrowserTabStripController::IsTabSelected(int model_index) const {
return model_->IsTabSelected(model_index);
}
diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h
index 4006c11..dbb929d 100644
--- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h
+++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.h
@@ -42,6 +42,7 @@ class BrowserTabStripController : public TabStripController,
// TabStripController implementation:
virtual int GetCount() const OVERRIDE;
virtual bool IsValidIndex(int model_index) const OVERRIDE;
+ virtual bool IsActiveTab(int model_index) const;
virtual bool IsTabSelected(int model_index) const OVERRIDE;
virtual bool IsTabPinned(int model_index) const OVERRIDE;
virtual bool IsTabCloseable(int model_index) const OVERRIDE;
diff --git a/chrome/browser/ui/views/tabs/side_tab.cc b/chrome/browser/ui/views/tabs/side_tab.cc
index 3046747..0a63faf 100644
--- a/chrome/browser/ui/views/tabs/side_tab.cc
+++ b/chrome/browser/ui/views/tabs/side_tab.cc
@@ -76,6 +76,7 @@ void SideTab::Layout() {
}
void SideTab::OnPaint(gfx::Canvas* canvas) {
+ // TODO: should render the active tab differently.
if (ShouldPaintHighlight()) {
SkPaint paint;
paint.setColor(kTabBackgroundColor);
diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc
index 104171d..8f51117 100644
--- a/chrome/browser/ui/views/tabs/tab.cc
+++ b/chrome/browser/ui/views/tabs/tab.cc
@@ -54,6 +54,12 @@ static const int kMiniTabRendererAsNormalTabWidth =
static const double kHoverOpacity = 0.33;
static const double kHoverSlideOpacity = 0.5;
+// Opacity for the non-active selected tab.
+static const double kSelectedTabOpacity = .4;
+
+// Selected (but not active) tabs have their throb value scaled down by this.
+static const double kSelectedTabThrobScale = .5;
+
Tab::TabImage Tab::tab_alpha_ = {0};
Tab::TabImage Tab::tab_active_ = {0};
Tab::TabImage Tab::tab_inactive_ = {0};
@@ -361,7 +367,7 @@ void Tab::OnMouseMoved(const views::MouseEvent& event) {
// Tab, private
void Tab::PaintTabBackground(gfx::Canvas* canvas) {
- if (IsSelected()) {
+ if (IsActive()) {
PaintActiveTabBackground(canvas);
} else {
if (mini_title_animation_.get() && mini_title_animation_->is_animating())
@@ -615,8 +621,8 @@ bool Tab::ShouldShowIcon() const {
return true;
if (!data().show_icon) {
return false;
- } else if (IsSelected()) {
- // The selected tab clips favicon before close button.
+ } else if (IsActive()) {
+ // The active tab clips favicon before close button.
return IconCapacity() >= 2;
}
// Non-selected tabs clip close button before favicon.
@@ -624,17 +630,23 @@ bool Tab::ShouldShowIcon() const {
}
bool Tab::ShouldShowCloseBox() const {
- // The selected tab never clips close button.
+ // The active tab never clips close button.
return !data().mini && IsCloseable() &&
- (IsSelected() || IconCapacity() >= 3);
+ (IsActive() || IconCapacity() >= 3);
}
double Tab::GetThrobValue() {
+ bool is_selected = IsSelected();
+ double min = is_selected ? kSelectedTabOpacity : 0;
+ double scale = is_selected ? kSelectedTabThrobScale : 1;
+
if (pulse_animation() && pulse_animation()->is_animating())
- return pulse_animation()->GetCurrentValue() * kHoverOpacity;
+ return pulse_animation()->GetCurrentValue() * kHoverOpacity * scale + min;
+
+ if (hover_animation())
+ return kHoverOpacity * hover_animation()->GetCurrentValue() * scale + min;
- return hover_animation() ?
- kHoverOpacity * hover_animation()->GetCurrentValue() : 0;
+ return is_selected ? kSelectedTabOpacity : 0;
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/ui/views/tabs/tab_controller.h b/chrome/browser/ui/views/tabs/tab_controller.h
index e2082ff..82db124 100644
--- a/chrome/browser/ui/views/tabs/tab_controller.h
+++ b/chrome/browser/ui/views/tabs/tab_controller.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -33,6 +33,10 @@ class TabController {
// Shows a context menu for the tab at the specified point in screen coords.
virtual void ShowContextMenuForTab(BaseTab* tab, const gfx::Point& p) = 0;
+ // Returns true if |tab| is the active tab. The active tab is the one whose
+ // content is shown in the browser.
+ virtual bool IsActiveTab(const BaseTab* tab) const = 0;
+
// Returns true if the specified Tab is selected.
virtual bool IsTabSelected(const BaseTab* tab) const = 0;
diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc
index 8adc2fe..d08f811 100644
--- a/chrome/browser/ui/views/tabs/tab_strip.cc
+++ b/chrome/browser/ui/views/tabs/tab_strip.cc
@@ -243,7 +243,7 @@ void TabStrip::SelectTabAt(int old_model_index, int new_model_index) {
void TabStrip::TabTitleChangedNotLoading(int model_index) {
Tab* tab = GetTabAtModelIndex(model_index);
- if (tab->data().mini && !tab->IsSelected())
+ if (tab->data().mini && !tab->IsActive())
tab->StartMiniTabTitleAnimation();
}
@@ -269,25 +269,34 @@ BaseTab* TabStrip::CreateTabForDragging() {
void TabStrip::PaintChildren(gfx::Canvas* canvas) {
// Tabs are painted in reverse order, so they stack to the left.
- std::vector<Tab*> selected_tabs;
+ Tab* active_tab = NULL;
std::vector<Tab*> tabs_dragging;
+ std::vector<Tab*> selected_tabs;
+ bool is_dragging = false;
for (int i = tab_count() - 1; i >= 0; --i) {
- Tab* tab = GetTabAtTabDataIndex(i);
// We must ask the _Tab's_ model, not ourselves, because in some situations
// the model will be different to this object, e.g. when a Tab is being
// removed after its TabContents has been destroyed.
+ Tab* tab = GetTabAtTabDataIndex(i);
if (tab->dragging()) {
- tabs_dragging.push_back(tab);
- } else if (!tab->IsSelected()) {
- tab->Paint(canvas);
+ is_dragging = true;
+ if (tab->IsActive())
+ active_tab = tab;
+ else
+ tabs_dragging.push_back(tab);
+ } else if (!tab->IsActive()) {
+ if (!tab->IsSelected())
+ tab->Paint(canvas);
+ else
+ selected_tabs.push_back(tab);
} else {
- selected_tabs.push_back(tab);
+ active_tab = tab;
}
}
if (GetWindow()->non_client_view()->UseNativeFrame()) {
- // Make sure unselected tabs are somewhat transparent.
+ // Make sure non-active tabs are somewhat transparent.
SkPaint paint;
paint.setColor(SkColorSetARGB(200, 255, 255, 255));
paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
@@ -297,20 +306,25 @@ void TabStrip::PaintChildren(gfx::Canvas* canvas) {
paint);
}
- // Next comes selected tabs.
- for (std::vector<Tab*>::reverse_iterator i = selected_tabs.rbegin();
- i != selected_tabs.rend(); ++i) {
- (*i)->Paint(canvas);
- }
+ // Now selected but not active. We don't want these dimmed if using native
+ // frame, so they're painted after initial pass.
+ for (size_t i = 0; i < selected_tabs.size(); ++i)
+ selected_tabs[i]->Paint(canvas);
+
+ // Next comes the active tab.
+ if (active_tab && !is_dragging)
+ active_tab->Paint(canvas);
// Paint the New Tab button.
newtab_button_->Paint(canvas);
// And the dragged tabs.
- for (std::vector<Tab*>::reverse_iterator i = tabs_dragging.rbegin();
- i != tabs_dragging.rend(); ++i) {
- (*i)->Paint(canvas);
- }
+ for (size_t i = 0; i < tabs_dragging.size(); ++i)
+ tabs_dragging[i]->Paint(canvas);
+
+ // If the active tab is being dragged, it goes last.
+ if (active_tab && is_dragging)
+ active_tab->Paint(canvas);
}
// Overridden to support automation. See automation_proxy_uitest.cc.
@@ -383,12 +397,12 @@ views::View* TabStrip::GetEventHandlerForPoint(const gfx::Point& point) {
return v;
// The display order doesn't necessarily match the child list order, so we
- // walk the display list hit-testing Tabs. Since the selected tab always
+ // walk the display list hit-testing Tabs. Since the active tab always
// renders on top of adjacent tabs, it needs to be hit-tested before any
// left-adjacent Tab, so we look ahead for it as we walk.
for (int i = 0; i < tab_count(); ++i) {
Tab* next_tab = i < (tab_count() - 1) ? GetTabAtTabDataIndex(i + 1) : NULL;
- if (next_tab && next_tab->IsSelected() && IsPointInTab(next_tab, point))
+ if (next_tab && next_tab->IsActive() && IsPointInTab(next_tab, point))
return next_tab;
Tab* tab = GetTabAtTabDataIndex(i);
if (IsPointInTab(tab, point))
@@ -659,7 +673,8 @@ void TabStrip::ResizeLayoutTabs() {
Tab* first_tab = GetTabAtTabDataIndex(mini_tab_count);
double unselected, selected;
GetDesiredTabWidths(tab_count(), mini_tab_count, &unselected, &selected);
- int w = Round(first_tab->IsSelected() ? selected : selected);
+ // TODO: this is always selected, should it be 'selected : unselected'?
+ int w = Round(first_tab->IsActive() ? selected : selected);
// We only want to run the animation if we're not already at the desired
// size.
@@ -872,7 +887,7 @@ void TabStrip::GenerateIdealBounds() {
// Give a bigger gap between mini and non-mini tabs.
tab_x += mini_to_non_mini_gap_;
}
- if (tab->IsSelected())
+ if (tab->IsActive())
tab_width = selected;
}
double end_of_tab = tab_x + tab_width;
diff --git a/chrome/browser/ui/views/tabs/tab_strip_controller.h b/chrome/browser/ui/views/tabs/tab_strip_controller.h
index d4773cf..5ed1e7b 100644
--- a/chrome/browser/ui/views/tabs/tab_strip_controller.h
+++ b/chrome/browser/ui/views/tabs/tab_strip_controller.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -26,6 +26,10 @@ class TabStripController {
// Returns true if |index| is a valid model index.
virtual bool IsValidIndex(int index) const = 0;
+ // Returns true if the tab at |index| is the active tab. The active tab is the
+ // one whose content is shown.
+ virtual bool IsActiveTab(int index) const = 0;
+
// Returns true if the selected index is selected.
virtual bool IsTabSelected(int index) const = 0;