Commit e5a9ddce authored by msw@chromium.org's avatar msw@chromium.org

Convert AvatarLabel from TextButton to LabelButton.

TextButton will be deprecated soon; use LabelButton.
Use views::Border as the AvatarLabelBorder base class.
Other minor cleanup.

BUG=155363
TEST=No regressions of this Windows/CrOS/LinuxAura supervised user UI.
R=sky@chromium.org

Review URL: https://codereview.chromium.org/163953006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251241 0039d316-1c4b-4281-b951-d872f2087c98
parent 9d9e0225
...@@ -6,31 +6,30 @@ ...@@ -6,31 +6,30 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "grit/theme_resources.h" #include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/theme_provider.h" #include "ui/base/theme_provider.h"
#include "ui/events/event.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/gfx/font_list.h"
#include "ui/views/painter.h" #include "ui/views/painter.h"
namespace { namespace {
// A special text button border for the managed user avatar label. // A custom border for the managed user avatar label.
class AvatarLabelBorder: public views::TextButtonBorder { class AvatarLabelBorder : public views::Border {
public: public:
explicit AvatarLabelBorder(bool label_on_right); explicit AvatarLabelBorder(bool label_on_right);
// views::TextButtonBorder: // views::Border:
virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE;
virtual gfx::Insets GetInsets() const OVERRIDE;
virtual gfx::Size GetMinimumSize() const OVERRIDE; virtual gfx::Size GetMinimumSize() const OVERRIDE;
private: private:
scoped_ptr<views::Painter> painter_; scoped_ptr<views::Painter> painter_;
gfx::Insets insets_;
DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder); DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder);
}; };
...@@ -42,15 +41,13 @@ AvatarLabelBorder::AvatarLabelBorder(bool label_on_right) { ...@@ -42,15 +41,13 @@ AvatarLabelBorder::AvatarLabelBorder(bool label_on_right) {
const int kVerticalInsetBottom = 3; const int kVerticalInsetBottom = 3;
// We want to align with the top of the tab. This works if the default font // We want to align with the top of the tab. This works if the default font
// size is 13. If it is smaller, we need to increase the TopInset accordingly. // size is 13. If it is smaller, we need to increase the TopInset accordingly.
const gfx::FontList font_list; const int difference = std::max<int>(0, 13 - gfx::FontList().GetFontSize());
int difference = const int addToTop = difference / 2;
(font_list.GetFontSize() < 13) ? 13 - font_list.GetFontSize() : 0; const int addToBottom = difference - addToTop;
int addToTop = difference / 2; insets_ = gfx::Insets(kVerticalInsetTop + addToTop,
int addToBottom = difference - addToTop;
SetInsets(gfx::Insets(kVerticalInsetTop + addToTop,
kHorizontalInsetLeft, kHorizontalInsetLeft,
kVerticalInsetBottom + addToBottom, kVerticalInsetBottom + addToBottom,
kHorizontalInsetRight)); kHorizontalInsetRight);
const int kImages[] = IMAGE_GRID(IDR_MANAGED_USER_LABEL); const int kImages[] = IMAGE_GRID(IDR_MANAGED_USER_LABEL);
painter_.reset(views::Painter::CreateImageGridPainter(kImages)); painter_.reset(views::Painter::CreateImageGridPainter(kImages));
} }
...@@ -60,7 +57,7 @@ void AvatarLabelBorder::Paint(const views::View& view, gfx::Canvas* canvas) { ...@@ -60,7 +57,7 @@ void AvatarLabelBorder::Paint(const views::View& view, gfx::Canvas* canvas) {
// includes a border with almost transparent white color. // includes a border with almost transparent white color.
painter_->Paint(canvas, view.size()); painter_->Paint(canvas, view.size());
// Now repaint the inner part of the background in order to be able to change // Repaint the inner part of the background in order to be able to change
// the colors according to the currently installed theme. // the colors according to the currently installed theme.
gfx::Rect rect(1, 1, view.size().width() - 2, view.size().height() - 2); gfx::Rect rect(1, 1, view.size().width() - 2, view.size().height() - 2);
SkPaint paint; SkPaint paint;
...@@ -69,20 +66,22 @@ void AvatarLabelBorder::Paint(const views::View& view, gfx::Canvas* canvas) { ...@@ -69,20 +66,22 @@ void AvatarLabelBorder::Paint(const views::View& view, gfx::Canvas* canvas) {
ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND); ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND);
paint.setStyle(SkPaint::kFill_Style); paint.setStyle(SkPaint::kFill_Style);
// For the inner border, use a color which is slightly darker than the // Paint the inner border with a color slightly darker than the background.
// background color.
SkAlpha kAlphaForBlending = 230; SkAlpha kAlphaForBlending = 230;
paint.setColor(color_utils::AlphaBlend( paint.setColor(color_utils::AlphaBlend(
background_color, SK_ColorBLACK, kAlphaForBlending)); background_color, SK_ColorBLACK, kAlphaForBlending));
canvas->DrawRoundRect(rect, kRadius, paint); canvas->DrawRoundRect(rect, kRadius, paint);
// Now paint the inner background using the color provided by the // Paint the inner background using the color provided by the ThemeProvider.
// ThemeProvider.
paint.setColor(background_color); paint.setColor(background_color);
rect = gfx::Rect(2, 2, view.size().width() - 4, view.size().height() - 4); rect = gfx::Rect(2, 2, view.size().width() - 4, view.size().height() - 4);
canvas->DrawRoundRect(rect, kRadius, paint); canvas->DrawRoundRect(rect, kRadius, paint);
} }
gfx::Insets AvatarLabelBorder::GetInsets() const {
return insets_;
}
gfx::Size AvatarLabelBorder::GetMinimumSize() const { gfx::Size AvatarLabelBorder::GetMinimumSize() const {
gfx::Size size(4, 4); gfx::Size size(4, 4);
size.SetToMax(painter_->GetMinimumSize()); size.SetToMax(painter_->GetMinimumSize());
...@@ -92,10 +91,9 @@ gfx::Size AvatarLabelBorder::GetMinimumSize() const { ...@@ -92,10 +91,9 @@ gfx::Size AvatarLabelBorder::GetMinimumSize() const {
} // namespace } // namespace
AvatarLabel::AvatarLabel(BrowserView* browser_view) AvatarLabel::AvatarLabel(BrowserView* browser_view)
: TextButton(NULL, : LabelButton(NULL,
l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)), l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)),
browser_view_(browser_view) { browser_view_(browser_view) {
ClearMaxTextSize();
SetLabelOnRight(false); SetLabelOnRight(false);
UpdateLabelStyle(); UpdateLabelStyle();
} }
...@@ -103,7 +101,7 @@ AvatarLabel::AvatarLabel(BrowserView* browser_view) ...@@ -103,7 +101,7 @@ AvatarLabel::AvatarLabel(BrowserView* browser_view)
AvatarLabel::~AvatarLabel() {} AvatarLabel::~AvatarLabel() {}
bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) { bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) {
if (!TextButton::OnMousePressed(event)) if (!LabelButton::OnMousePressed(event))
return false; return false;
browser_view_->ShowAvatarBubbleFromAvatarButton(); browser_view_->ShowAvatarBubbleFromAvatarButton();
...@@ -117,10 +115,8 @@ void AvatarLabel::UpdateLabelStyle() { ...@@ -117,10 +115,8 @@ void AvatarLabel::UpdateLabelStyle() {
SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor( SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor(
ThemeProperties::COLOR_MANAGED_USER_LABEL); ThemeProperties::COLOR_MANAGED_USER_LABEL);
SetEnabledColor(color_label); for (size_t state = 0; state < STATE_COUNT; ++state)
SetHighlightColor(color_label); SetTextColor(static_cast<ButtonState>(state), color_label);
SetHoverColor(color_label);
SetDisabledColor(color_label);
SchedulePaint(); SchedulePaint();
} }
......
...@@ -6,25 +6,20 @@ ...@@ -6,25 +6,20 @@
#define CHROME_BROWSER_UI_VIEWS_AVATAR_LABEL_H_ #define CHROME_BROWSER_UI_VIEWS_AVATAR_LABEL_H_
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "ui/views/controls/button/text_button.h" #include "ui/views/controls/button/label_button.h"
class BrowserView; class BrowserView;
namespace ui {
class MouseEvent;
class ThemeProvider;
}
// AvatarLabel // AvatarLabel
// //
// A label used to display a string indicating that the current profile belongs // A label used to display a string indicating that the current profile belongs
// to a managed user. // to a managed user.
class AvatarLabel : public views::TextButton { class AvatarLabel : public views::LabelButton {
public: public:
explicit AvatarLabel(BrowserView* browser_view); explicit AvatarLabel(BrowserView* browser_view);
virtual ~AvatarLabel(); virtual ~AvatarLabel();
// views::TextButton: // views::LabelButton:
virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
// Update the style of the label according to the provided theme. // Update the style of the label according to the provided theme.
......
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