Chromium Code Reviews| Index: chrome/browser/ui/views/tabs/tab.cc |
| diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc |
| index 6c179d1075d2fa4fea81fe6c460a589563fb1456..749a708b5f127b13f760328b828387d73cc14243 100644 |
| --- a/chrome/browser/ui/views/tabs/tab.cc |
| +++ b/chrome/browser/ui/views/tabs/tab.cc |
| @@ -37,8 +37,12 @@ |
| #include "ui/gfx/favicon_size.h" |
| #include "ui/gfx/geometry/rect_conversions.h" |
| #include "ui/gfx/image/image_skia_operations.h" |
| +#include "ui/gfx/paint_vector_icon.h" |
| #include "ui/gfx/path.h" |
| #include "ui/gfx/skia_util.h" |
| +#include "ui/gfx/vector_icons_public.h" |
| +#include "ui/native_theme/common_theme.h" |
| +#include "ui/native_theme/native_theme.h" |
| #include "ui/resources/grit/ui_resources.h" |
| #include "ui/views/border.h" |
| #include "ui/views/controls/button/image_button.h" |
| @@ -75,8 +79,8 @@ const int kTouchWidth = 120; |
| const int kToolbarOverlap = 1; |
| const int kExtraLeftPaddingToBalanceCloseButtonPadding = 2; |
| const int kFaviconTitleSpacing = 4; |
| -const int kAfterTitleSpacing = 3; |
| -const int kCloseButtonRightPaddingOverlap = 3; |
| +const int kAfterTitleSpacing = 4; |
| +const int kCloseButtonRightPaddingOverlap = 2; |
| const int kStandardTitleWidth = 175; |
| // Width of the content inside a pinned tab. |
| @@ -144,6 +148,7 @@ const double kImmersiveTabMinThrobOpacity = 0.66; |
| const int kImmersiveLoadingStepCount = 32; |
| const char kTabCloseButtonName[] = "TabCloseButton"; |
| +const int kTabCloseButtonSize = 16; |
| void DrawIconAtLocation(gfx::Canvas* canvas, |
| const gfx::ImageSkia& image, |
| @@ -428,7 +433,7 @@ Tab::Tab(TabController* controller) |
| showing_icon_(false), |
| showing_media_indicator_(false), |
| showing_close_button_(false), |
| - close_button_color_(0) { |
| + close_button_color_(SK_ColorTRANSPARENT) { |
| DCHECK(controller); |
| InitTabResources(); |
| @@ -448,20 +453,25 @@ Tab::Tab(TabController* controller) |
| SetEventTargeter( |
| scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| - // Add the Close Button. |
| close_button_ = new TabCloseButton(this); |
| - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| - close_button_->SetImage(views::CustomButton::STATE_NORMAL, |
| - rb.GetImageSkiaNamed(IDR_CLOSE_1)); |
| - close_button_->SetImage(views::CustomButton::STATE_HOVERED, |
| - rb.GetImageSkiaNamed(IDR_CLOSE_1_H)); |
| - close_button_->SetImage(views::CustomButton::STATE_PRESSED, |
| - rb.GetImageSkiaNamed(IDR_CLOSE_1_P)); |
| close_button_->SetAccessibleName( |
| l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| + // The normal image is set in various other places because it depends on the |
| + // current theme and active state. The hovered and pressed images don't |
| + // depend on the these, so we can set them here. |
| + const gfx::ImageSkia& hovered = gfx::CreateVectorIcon( |
| + gfx::VectorIconId::TAB_CLOSE_HOVERED_PRESSED, kTabCloseButtonSize, |
| + SkColorSetARGB(0xFF, 0xDB, 0x44, 0x37)); |
| + const gfx::ImageSkia& pressed = gfx::CreateVectorIcon( |
| + gfx::VectorIconId::TAB_CLOSE_HOVERED_PRESSED, kTabCloseButtonSize, |
| + SkColorSetARGB(0xFF, 0xA8, 0x35, 0x2A)); |
| + close_button_->SetImage(views::CustomButton::STATE_HOVERED, &hovered); |
| + close_button_->SetImage(views::CustomButton::STATE_PRESSED, &pressed); |
| + |
| // Disable animation so that the red danger sign shows up immediately |
| // to help avoid mis-clicks. |
| close_button_->SetAnimationDuration(0); |
| + |
| AddChildView(close_button_); |
| set_context_menu_controller(this); |
| @@ -481,6 +491,7 @@ bool Tab::IsActive() const { |
| void Tab::ActiveStateChanged() { |
| GetMediaIndicatorButton()->UpdateEnabledForMuteToggle(); |
| + SetCloseButtonNormalStateImage(); |
| } |
| bool Tab::IsSelected() const { |
| @@ -735,6 +746,10 @@ bool Tab::GetHitTestMask(gfx::Path* mask) const { |
| //////////////////////////////////////////////////////////////////////////////// |
| // Tab, views::View overrides: |
| +void Tab::ViewHierarchyChanged(const ViewHierarchyChangedDetails& details) { |
| + SetCloseButtonNormalStateImage(); |
|
Evan Stade
2015/09/18 21:51:18
maybe guard with:
if (details.is_add && details.c
Peter Kasting
2015/09/19 01:20:56
I intentionally didn't do that. Let's say a paren
Evan Stade
2015/09/21 18:49:10
OK, although it seems like if this is a problem it
Peter Kasting
2015/09/23 00:12:34
Most places we guard with this we're not so much w
|
| +} |
| + |
| void Tab::OnPaint(gfx::Canvas* canvas) { |
| // Don't paint if we're narrower than we can render correctly. (This should |
| // only happen during animations). |
| @@ -744,6 +759,11 @@ void Tab::OnPaint(gfx::Canvas* canvas) { |
| gfx::Rect clip; |
| if (!controller_->ShouldPaintTab(this, &clip)) |
| return; |
| + |
| + // If we haven't set the correct close button normal image, we can do so now. |
| + if (close_button_color_ == SK_ColorTRANSPARENT) |
| + OnThemeChanged(); |
| + |
| if (!clip.IsEmpty()) { |
| canvas->Save(); |
| canvas->ClipRect(clip); |
| @@ -847,6 +867,7 @@ void Tab::Layout() { |
| void Tab::OnThemeChanged() { |
| LoadTabImages(); |
| + SetCloseButtonNormalStateImage(); |
| } |
| const char* Tab::GetClassName() const { |
| @@ -1048,29 +1069,18 @@ void Tab::PaintTab(gfx::Canvas* canvas) { |
| const bool show_close_button = ShouldShowCloseBox(); |
| if (show_icon != showing_icon_ || |
| show_media_indicator != showing_media_indicator_ || |
| - show_close_button != showing_close_button_) { |
| + show_close_button != showing_close_button_) |
| Layout(); |
| - } |
| PaintTabBackground(canvas); |
| const SkColor title_color = GetThemeProvider()->GetColor(IsSelected() ? |
| ThemeProperties::COLOR_TAB_TEXT : |
| ThemeProperties::COLOR_BACKGROUND_TAB_TEXT); |
| - title_->SetVisible(ShouldRenderAsNormalTab()); |
| title_->SetEnabledColor(title_color); |
| if (show_icon) |
| PaintIcon(canvas); |
| - |
| - // If the close button color has changed, generate a new one. |
| - if (!close_button_color_ || title_color != close_button_color_) { |
| - close_button_color_ = title_color; |
| - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| - close_button_->SetBackground(close_button_color_, |
| - rb.GetImageSkiaNamed(IDR_CLOSE_1), |
| - rb.GetImageSkiaNamed(IDR_CLOSE_1_MASK)); |
| - } |
| } |
| void Tab::PaintImmersiveTab(gfx::Canvas* canvas) { |
| @@ -1513,6 +1523,25 @@ bool Tab::IsPerformingCrashAnimation() const { |
| return crash_icon_animation_.get() && data_.IsCrashed(); |
| } |
| +void Tab::SetCloseButtonNormalStateImage() { |
| + // The theme provider may be null if we're not currently in a widget |
| + // hierarchy. |
| + ui::ThemeProvider* theme_provider = GetThemeProvider(); |
| + if (!theme_provider) |
| + return; |
| + |
| + const SkColor new_close_button_color = SkColorSetA(theme_provider->GetColor( |
|
Evan Stade
2015/09/18 21:51:18
why not use COLOR_TAB_ICON?
Peter Kasting
2015/09/19 01:20:56
Thanks for pointing me at that. Looks like only t
Evan Stade
2015/09/21 18:49:10
sure.
Peter Kasting
2015/09/23 00:12:33
I was worrying about cases like we had in the omni
Evan Stade
2015/09/23 18:16:35
fair enough
|
| + IsActive() ? ThemeProperties::COLOR_TAB_TEXT |
| + : ThemeProperties::COLOR_BACKGROUND_TAB_TEXT), 0x70); |
| + if (close_button_color_ != new_close_button_color) { |
| + close_button_color_ = new_close_button_color; |
| + const gfx::ImageSkia& normal = gfx::CreateVectorIcon( |
| + gfx::VectorIconId::TAB_CLOSE_NORMAL, kTabCloseButtonSize, |
| + close_button_color_); |
| + close_button_->SetImage(views::CustomButton::STATE_NORMAL, &normal); |
| + } |
| +} |
| + |
| void Tab::ScheduleIconPaint() { |
| gfx::Rect bounds = favicon_bounds_; |
| if (bounds.IsEmpty()) |