Commit c87ae2fa authored by akuegel@chromium.org's avatar akuegel@chromium.org

Improve the look of the avatar label button (views).

BUG=241387

Review URL: https://chromiumcodereview.appspot.com/17176015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208038 0039d316-1c4b-4281-b951-d872f2087c98
parent a58eae87
......@@ -4,8 +4,8 @@
#include "chrome/browser/ui/views/avatar_label.h"
#include "base/memory/scoped_ptr.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 +13,49 @@
#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) OVERRIDE;
private:
scoped_ptr<views::Painter> hot_painter_;
scoped_ptr<views::Painter> painter_;
DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder);
};
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_.reset(views::Painter::CreateVerticalGradient(color, color2));
hot_painter_.reset(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 +66,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 +80,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();
}
......@@ -13,7 +13,6 @@ class BrowserView;
namespace ui {
class MouseEvent;
class ThemeProvider;
class NativeTheme;
}
// AvatarLabel
......@@ -27,8 +26,6 @@ class AvatarLabel : public views::TextButton {
// views::TextButton:
virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
virtual void GetExtraParams(
ui::NativeTheme::ExtraParams* params) const OVERRIDE;
// Update the style of the label according to the provided theme.
void UpdateLabelStyle();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment