Chromium Code Reviews| Index: chrome/browser/ui/views/avatar_label.cc |
| diff --git a/chrome/browser/ui/views/avatar_label.cc b/chrome/browser/ui/views/avatar_label.cc |
| index 8a6465dbed8ca2fd98fdf1ce4cd7fe12117e7082..6a5d1cae083376ab3a84d47536a0ed497034ffce 100644 |
| --- a/chrome/browser/ui/views/avatar_label.cc |
| +++ b/chrome/browser/ui/views/avatar_label.cc |
| @@ -5,7 +5,6 @@ |
| #include "chrome/browser/ui/views/avatar_label.h" |
| #include "chrome/browser/themes/theme_properties.h" |
| -#include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
| #include "chrome/browser/ui/views/frame/browser_view.h" |
| #include "grit/generated_resources.h" |
| @@ -13,8 +12,45 @@ |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/base/theme_provider.h" |
| -#include "ui/gfx/point.h" |
| -#include "ui/gfx/rect.h" |
| +#include "ui/gfx/canvas.h" |
| +#include "ui/gfx/color_utils.h" |
| +#include "ui/views/painter.h" |
| + |
| +namespace { |
| + |
| +// A special text button border for the managed user avatar label. |
| +class AvatarLabelBorder: public views::TextButtonBorder { |
| + public: |
| + explicit AvatarLabelBorder(ui::ThemeProvider* theme_provider); |
| + virtual void Paint(const views::View& view, gfx::Canvas* canvas); |
|
sky
2013/06/21 16:28:26
OVERRIDE
Adrian Kuegel
2013/06/21 21:19:32
Done.
|
| + private: |
|
sky
2013/06/21 16:28:26
nit: newline between 25/26 and DISALLOW_...
Adrian Kuegel
2013/06/21 21:19:32
Done.
|
| + views::Painter* hot_painter_; |
|
sky
2013/06/21 16:28:26
Document ownership, in fact I'm pretty sure these
Adrian Kuegel
2013/06/21 21:19:32
Yes, sorry, forgot to use scoped_ptr here.
|
| + views::Painter* painter_; |
| +}; |
| + |
| +AvatarLabelBorder::AvatarLabelBorder(ui::ThemeProvider* theme_provider) { |
| + const int kHorizontalInset = 10; |
| + const int kVerticalInset = 2; |
| + SetInsets(gfx::Insets( |
| + kVerticalInset, kHorizontalInset, kVerticalInset, kHorizontalInset)); |
| + SkColor color = theme_provider->GetColor( |
| + ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND); |
| + SkColor color2 = color_utils::BlendTowardOppositeLuminance(color, 0x20); |
| + painter_ = views::Painter::CreateVerticalGradient(color, color2); |
| + hot_painter_ = views::Painter::CreateVerticalGradient(color2, color); |
| +} |
| + |
| +void AvatarLabelBorder::Paint(const views::View& view, gfx::Canvas* canvas) { |
| + const views::TextButton* button = |
| + static_cast<const views::TextButton*>(&view); |
| + if (button->state() == views::TextButton::STATE_HOVERED || |
| + button->state() == views::TextButton::STATE_PRESSED) |
| + hot_painter_->Paint(canvas, view.size()); |
| + else |
| + painter_->Paint(canvas, view.size()); |
| +} |
| + |
| +} // namespace |
| AvatarLabel::AvatarLabel(BrowserView* browser_view, |
| ui::ThemeProvider* theme_provider) |
| @@ -25,13 +61,7 @@ AvatarLabel::AvatarLabel(BrowserView* browser_view, |
| SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( |
| ui::ResourceBundle::SmallFont)); |
| ClearMaxTextSize(); |
| - views::TextButtonNativeThemeBorder* border = |
| - new views::TextButtonNativeThemeBorder(this); |
| - const int kHorizontalInset = 10; |
| - const int kVerticalInset = 2; |
| - border->SetInsets(gfx::Insets( |
| - kVerticalInset, kHorizontalInset, kVerticalInset, kHorizontalInset)); |
| - set_border(border); |
| + set_border(new AvatarLabelBorder(theme_provider)); |
| UpdateLabelStyle(); |
| } |
| @@ -45,15 +75,12 @@ bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) { |
| return true; |
| } |
| -void AvatarLabel::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { |
| - TextButton::GetExtraParams(params); |
| - params->button.background_color = theme_provider_->GetColor( |
| - ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND); |
| -} |
| - |
| void AvatarLabel::UpdateLabelStyle() { |
| SkColor color_label = |
| theme_provider_->GetColor(ThemeProperties::COLOR_MANAGED_USER_LABEL); |
| SetEnabledColor(color_label); |
| + SetHighlightColor(color_label); |
| + SetHoverColor(color_label); |
| + SetDisabledColor(color_label); |
| SchedulePaint(); |
| } |