| Index: chrome/browser/views/tabs/base_tab.cc
|
| diff --git a/chrome/browser/views/tabs/base_tab.cc b/chrome/browser/views/tabs/base_tab.cc
|
| index f128abc231f8867b1370a4ce7259acfad28dc174..04124ed9d615e75704919183406303443749e522 100644
|
| --- a/chrome/browser/views/tabs/base_tab.cc
|
| +++ b/chrome/browser/views/tabs/base_tab.cc
|
| @@ -20,6 +20,7 @@
|
| #include "gfx/canvas.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"
|
| @@ -48,20 +49,36 @@ 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 TabCloseButton : public views::ImageButton {
|
| +class BaseTab::TabCloseButton : public views::ImageButton {
|
| public:
|
| - explicit TabCloseButton(views::ButtonListener* listener)
|
| - : views::ImageButton(listener) {
|
| + TabCloseButton(BaseTab* tab, bool show_mini_dot)
|
| + : views::ImageButton(tab),
|
| + tab_(tab),
|
| + is_mouse_near_(!show_mini_dot),
|
| + color_(0) {
|
| }
|
| 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
|
| @@ -82,12 +99,63 @@ class 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
|
| @@ -139,7 +207,7 @@ class BaseTab::FavIconCrashAnimation : public LinearAnimation,
|
| DISALLOW_COPY_AND_ASSIGN(FavIconCrashAnimation);
|
| };
|
|
|
| -BaseTab::BaseTab(TabController* controller)
|
| +BaseTab::BaseTab(TabController* controller, bool show_mini_dot)
|
| : controller_(controller),
|
| closing_(false),
|
| dragging_(false),
|
| @@ -151,7 +219,7 @@ BaseTab::BaseTab(TabController* controller)
|
| BaseTab::InitResources();
|
|
|
| // Add the Close Button.
|
| - TabCloseButton* close_button = new TabCloseButton(this);
|
| + TabCloseButton* close_button = new TabCloseButton(this, show_mini_dot);
|
| close_button_ = close_button;
|
| close_button->SetImage(views::CustomButton::BS_NORMAL, close_button_n);
|
| close_button->SetImage(views::CustomButton::BS_HOT, close_button_h);
|
| @@ -228,6 +296,10 @@ void BaseTab::StopPulse() {
|
| pulse_animation_.reset(NULL);
|
| }
|
|
|
| +void BaseTab::SelectedChanged() {
|
| + close_button_->SelectedStateChanged();
|
| +}
|
| +
|
| bool BaseTab::IsSelected() const {
|
| return controller() ? controller()->IsTabSelected(this) : true;
|
| }
|
| @@ -334,6 +406,14 @@ 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())
|
|
|