summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-07 15:38:19 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-07 15:38:19 +0000
commit9fc4f203c93d906a5b94a0e48556ee52515185f0 (patch)
treebd16f20b4442184b98ccf9db656491940b64cbcd /chrome/browser/views
parent2f4294538dea93c4b48b20b9b564d09bb7591301 (diff)
downloadchromium_src-9fc4f203c93d906a5b94a0e48556ee52515185f0.zip
chromium_src-9fc4f203c93d906a5b94a0e48556ee52515185f0.tar.gz
chromium_src-9fc4f203c93d906a5b94a0e48556ee52515185f0.tar.bz2
Bye bye tab close dot, we hardly knew you.
BUG=none TEST=none Review URL: http://codereview.chromium.org/2813045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51718 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/tabs/base_tab.cc98
-rw-r--r--chrome/browser/views/tabs/base_tab.h14
-rw-r--r--chrome/browser/views/tabs/side_tab.cc8
-rw-r--r--chrome/browser/views/tabs/tab.cc26
-rw-r--r--chrome/browser/views/tabs/tab_strip.cc9
-rw-r--r--chrome/browser/views/tabs/tab_strip_interactive_uitest.cc59
6 files changed, 28 insertions, 186 deletions
diff --git a/chrome/browser/views/tabs/base_tab.cc b/chrome/browser/views/tabs/base_tab.cc
index 9583233..5441379 100644
--- a/chrome/browser/views/tabs/base_tab.cc
+++ b/chrome/browser/views/tabs/base_tab.cc
@@ -20,7 +20,6 @@
#include "gfx/canvas_skia.h"
#include "gfx/favicon_size.h"
#include "gfx/font.h"
-#include "gfx/skbitmap_operations.h"
#include "grit/app_resources.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -49,36 +48,20 @@ static SkBitmap* close_button_p = NULL;
static SkBitmap* crashed_fav_icon = NULL;
+namespace {
+
////////////////////////////////////////////////////////////////////////////////
// TabCloseButton
//
// This is a Button subclass that causes middle clicks to be forwarded to the
// parent View by explicitly not handling them in OnMousePressed.
-class BaseTab::TabCloseButton : public views::ImageButton {
+class TabCloseButton : public views::ImageButton {
public:
- TabCloseButton(BaseTab* tab, bool show_mini_dot)
- : views::ImageButton(tab),
- tab_(tab),
- is_mouse_near_(!show_mini_dot),
- color_(0) {
+ explicit TabCloseButton(views::ButtonListener* listener)
+ : views::ImageButton(listener) {
}
virtual ~TabCloseButton() {}
- // Sets the color used to derive the background color.
- void SetColor(SkColor color) {
- if (color_ == color)
- return;
-
- color_ = color;
- // This is invoked from Paint, so we don't need to schedule a paint.
- UpdateBackgroundImage(false);
- }
-
- // Invoked when the selected state changes.
- void SelectedStateChanged() {
- UpdateBackgroundImage(true);
- }
-
virtual bool OnMousePressed(const views::MouseEvent& event) {
bool handled = ImageButton::OnMousePressed(event);
// Explicitly mark midle-mouse clicks as non-handled to ensure the tab
@@ -99,63 +82,12 @@ class BaseTab::TabCloseButton : public views::ImageButton {
GetParent()->OnMouseExited(event);
}
- virtual void OnMouseNear(const views::MouseEvent& event) {
- is_mouse_near_ = true;
- UpdateBackgroundImage(true);
- }
-
- virtual void OnMouseExitedNear(const views::MouseEvent& event) {
- is_mouse_near_ = false;
- UpdateBackgroundImage(true);
- }
-
private:
- // Returns the image to use for the background.
- static const SkBitmap& GetBackgroundImage(SkColor color, bool is_mouse_near) {
- // All tabs share the same color, so we cache the bitmaps.
- static SkColor cached_color = 0;
- static SkBitmap* near_image = NULL;
- static SkBitmap* far_image = NULL;
- if (!near_image || cached_color != color) {
- cached_color = color;
- if (!near_image) {
- near_image = new SkBitmap();
- far_image = new SkBitmap();
- }
- ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- *near_image = SkBitmapOperations::CreateButtonBackground(
- color,
- *rb.GetBitmapNamed(IDR_TAB_CLOSE),
- *rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK));
- *far_image = SkBitmapOperations::CreateButtonBackground(
- color,
- *rb.GetBitmapNamed(IDR_TAB_CLOSE),
- *rb.GetBitmapNamed(IDR_TAB_CLOSE_DOT_MASK));
- }
- return is_mouse_near ? *near_image : *far_image;
- }
-
- // Should we use the near image?
- bool use_near_image() const { return is_mouse_near_ || tab_->IsSelected(); }
-
- // Resets the background image.
- void UpdateBackgroundImage(bool paint) {
- set_background_image(GetBackgroundImage(color_, use_near_image()));
- if (paint)
- SchedulePaint();
- }
-
- BaseTab* tab_;
-
- // Is the mouse near the close button?
- bool is_mouse_near_;
-
- // Color used to derive the background image from.
- SkColor color_;
-
DISALLOW_COPY_AND_ASSIGN(TabCloseButton);
};
+} // namespace
+
// static
int BaseTab::close_button_width_ = 0;
// static
@@ -207,7 +139,7 @@ class BaseTab::FavIconCrashAnimation : public LinearAnimation,
DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation);
};
-BaseTab::BaseTab(TabController* controller, bool show_mini_dot)
+BaseTab::BaseTab(TabController* controller)
: controller_(controller),
closing_(false),
dragging_(false),
@@ -219,7 +151,7 @@ BaseTab::BaseTab(TabController* controller, bool show_mini_dot)
BaseTab::InitResources();
// Add the Close Button.
- TabCloseButton* close_button = new TabCloseButton(this, show_mini_dot);
+ TabCloseButton* close_button = new TabCloseButton(this);
close_button_ = close_button;
close_button->SetImage(views::CustomButton::BS_NORMAL, close_button_n);
close_button->SetImage(views::CustomButton::BS_HOT, close_button_h);
@@ -296,10 +228,6 @@ void BaseTab::StopPulse() {
pulse_animation_.reset(NULL);
}
-void BaseTab::SelectedChanged() {
- close_button_->SelectedStateChanged();
-}
-
bool BaseTab::IsSelected() const {
return controller() ? controller()->IsTabSelected(this) : true;
}
@@ -406,14 +334,6 @@ void BaseTab::AdvanceLoadingAnimation(TabRendererData::NetworkState old_state,
SchedulePaint();
}
-views::ImageButton* BaseTab::close_button() const {
- return close_button_;
-}
-
-void BaseTab::SetCloseButtonColor(SkColor color) {
- close_button_->SetColor(color);
-}
-
void BaseTab::PaintIcon(gfx::Canvas* canvas, int x, int y) {
if (base::i18n::IsRTL()) {
if (!data().favicon.isNull())
diff --git a/chrome/browser/views/tabs/base_tab.h b/chrome/browser/views/tabs/base_tab.h
index c0c9bde..e2ac34a 100644
--- a/chrome/browser/views/tabs/base_tab.h
+++ b/chrome/browser/views/tabs/base_tab.h
@@ -32,7 +32,7 @@ class BaseTab : public AnimationDelegate,
public views::ContextMenuController,
public views::View {
public:
- BaseTab(TabController* controller, bool show_mini_dot);
+ explicit BaseTab(TabController* controller);
~BaseTab();
// Sets the data this tabs displays. Invokes DataChanged for subclasses to
@@ -71,10 +71,6 @@ class BaseTab : public AnimationDelegate,
theme_provider_ = provider;
}
- // Invoked when the selected state changes. Resets the image of the close
- // button.
- void SelectedChanged();
-
// Returns true if the tab is selected.
virtual bool IsSelected() const;
@@ -108,10 +104,7 @@ class BaseTab : public AnimationDelegate,
return hover_animation_.get();
}
- views::ImageButton* close_button() const;
-
- // Sets the color used to derive the close button images.
- void SetCloseButtonColor(SkColor color);
+ views::ImageButton* close_button() const { return close_button_; }
// Paints the icon at the specified x-coordinate.
void PaintIcon(gfx::Canvas* canvas, int x, int y);
@@ -150,7 +143,6 @@ class BaseTab : public AnimationDelegate,
private:
// The animation object used to swap the favicon with the sad tab icon.
class FavIconCrashAnimation;
- class TabCloseButton;
// Set the temporary offset for the favicon. This is used during the crash
// animation.
@@ -194,7 +186,7 @@ class BaseTab : public AnimationDelegate,
scoped_refptr<AnimationContainer> animation_container_;
- TabCloseButton* close_button_;
+ views::ImageButton* close_button_;
// The current index of the loading animation.
int loading_animation_frame_;
diff --git a/chrome/browser/views/tabs/side_tab.cc b/chrome/browser/views/tabs/side_tab.cc
index 0169772..f57a32b 100644
--- a/chrome/browser/views/tabs/side_tab.cc
+++ b/chrome/browser/views/tabs/side_tab.cc
@@ -13,6 +13,7 @@
#include "gfx/path.h"
#include "gfx/skia_util.h"
#include "grit/app_resources.h"
+#include "grit/theme_resources.h"
#include "views/controls/button/image_button.h"
namespace {
@@ -37,8 +38,11 @@ const int kPhantomTabIconAlpha = 100;
// SideTab, public:
SideTab::SideTab(TabController* controller)
- : BaseTab(controller, false) {
- SetCloseButtonColor(kTextColor);
+ : BaseTab(controller) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ close_button()->SetBackground(kTextColor,
+ rb.GetBitmapNamed(IDR_TAB_CLOSE),
+ rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK));
}
SideTab::~SideTab() {
diff --git a/chrome/browser/views/tabs/tab.cc b/chrome/browser/views/tabs/tab.cc
index 22e424a..8b981e6 100644
--- a/chrome/browser/views/tabs/tab.cc
+++ b/chrome/browser/views/tabs/tab.cc
@@ -23,7 +23,6 @@
#include "grit/theme_resources.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "views/controls/button/image_button.h"
-#include "views/widget/root_view.h"
#include "views/widget/tooltip_manager.h"
#include "views/widget/widget.h"
#include "views/window/non_client_view.h"
@@ -102,7 +101,7 @@ const char Tab::kViewClassName[] = "browser/tabs/Tab";
// Tab, public:
Tab::Tab(TabController* controller)
- : BaseTab(controller, true),
+ : BaseTab(controller),
showing_icon_(false),
showing_close_button_(false),
close_button_color_(NULL) {
@@ -213,7 +212,13 @@ void Tab::Paint(gfx::Canvas* canvas) {
PaintIcon(canvas);
// If the close button color has changed, generate a new one.
- SetCloseButtonColor(title_color);
+ if (!close_button_color_ || title_color != close_button_color_) {
+ close_button_color_ = title_color;
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ close_button()->SetBackground(close_button_color_,
+ rb.GetBitmapNamed(IDR_TAB_CLOSE),
+ rb.GetBitmapNamed(IDR_TAB_CLOSE_MASK));
+ }
}
void Tab::Layout() {
@@ -261,7 +266,6 @@ void Tab::Layout() {
// Size the Close button.
showing_close_button_ = ShouldShowCloseBox();
- gfx::Insets near_insets;
if (showing_close_button_) {
int close_button_top =
kTopPadding + kCloseButtonVertFuzz +
@@ -271,24 +275,10 @@ void Tab::Layout() {
close_button_top, close_button_width(),
close_button_height());
close_button()->SetVisible(true);
- int avail_width = width() - close_button()->bounds().right();
- if (avail_width > 0) {
- View* root = GetRootView();
- if (root) { // Root is NULL when dragging.
- // Enable mouse near events for the region from the top of the browser
- // to the bottom of the tab.
- gfx::Point loc;
- ConvertPointToView(close_button(), GetRootView(), &loc);
- near_insets.Set(loc.y(), close_button()->x(),
- height() - close_button()->bounds().bottom(),
- avail_width);
- }
- }
} else {
close_button()->SetBounds(0, 0, 0, 0);
close_button()->SetVisible(false);
}
- close_button()->RegisterForMouseNearEvents(near_insets);
int title_left = favicon_bounds_.right() + kFavIconTitleSpacing;
int title_top = kTopPadding + (content_height - font_height()) / 2;
diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc
index 3054e0a..03cc42f 100644
--- a/chrome/browser/views/tabs/tab_strip.cc
+++ b/chrome/browser/views/tabs/tab_strip.cc
@@ -248,13 +248,8 @@ void TabStrip::SelectTabAt(int old_model_index, int new_model_index) {
}
if (old_model_index >= 0) {
- Tab* tab = GetTabAtTabDataIndex(ModelIndexToTabIndex(old_model_index));
- tab->StopMiniTabTitleAnimation();
- tab->SelectedChanged();
- }
- if (new_model_index >= 0) {
- GetTabAtTabDataIndex(
- ModelIndexToTabIndex(new_model_index))->SelectedChanged();
+ GetTabAtTabDataIndex(ModelIndexToTabIndex(old_model_index))->
+ StopMiniTabTitleAnimation();
}
}
diff --git a/chrome/browser/views/tabs/tab_strip_interactive_uitest.cc b/chrome/browser/views/tabs/tab_strip_interactive_uitest.cc
deleted file mode 100644
index b6a5d4a..0000000
--- a/chrome/browser/views/tabs/tab_strip_interactive_uitest.cc
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2010 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.
-
-#include "base/message_loop.h"
-#include "chrome/browser/automation/ui_controls.h"
-#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_window.h"
-#include "chrome/browser/view_ids.h"
-#include "chrome/browser/views/tabs/base_tab.h"
-#include "chrome/browser/views/tabs/tab_strip.h"
-#include "chrome/common/url_constants.h"
-#include "chrome/test/in_process_browser_test.h"
-#include "chrome/test/ui_test_utils.h"
-#include "views/widget/root_view.h"
-#include "views/widget/widget.h"
-
-typedef InProcessBrowserTest TabStripTest;
-
-// Creates a tab, middle clicks to close the first, then clicks back on the
-// first. This test exercises a crasher in the mouse near code path.
-IN_PROC_BROWSER_TEST_F(TabStripTest, Close) {
- int initial_tab_count = browser()->tab_count();
-
- browser()->AddTabWithURL(
- GURL(chrome::kAboutBlankURL), GURL(), PageTransition::TYPED, -1,
- TabStripModel::ADD_SELECTED, NULL, std::string());
- views::RootView* root =
- views::Widget::FindRootView(browser()->window()->GetNativeHandle());
- ASSERT_TRUE(root);
- TabStrip* tab_strip =
- static_cast<TabStrip*>(root->GetViewByID(VIEW_ID_TAB_STRIP));
- ASSERT_TRUE(tab_strip);
-
- // Force a layout to ensure no animations are active.
- tab_strip->Layout();
-
- // Close the first tab by way of am middle click.
- BaseTab* tab1 = tab_strip->base_tab_at_tab_index(1);
- ui_controls::MoveMouseToCenterAndPress(
- tab1, ui_controls::MIDDLE, ui_controls::DOWN | ui_controls::UP,
- new MessageLoop::QuitTask());
-
- // Force a layout to ensure no animations are active.
- ui_test_utils::RunMessageLoop();
-
- EXPECT_EQ(initial_tab_count, browser()->tab_count());
-
- // Force a layout to ensure no animations are active.
- tab_strip->Layout();
-
- // Click on the first tab.
- BaseTab* tab0 = tab_strip->base_tab_at_tab_index(0);
- ui_controls::MoveMouseToCenterAndPress(
- tab0, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
- new MessageLoop::QuitTask());
-
- ui_test_utils::RunMessageLoop();
-}