Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Unified Diff: chrome/browser/ui/views/avatar_label.cc

Issue 163953006: Convert AvatarLabel from TextButton to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Convert AvatarLabel from TextButton to LabelButton. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/avatar_label.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9bdb576a2efc2021bca859a9c6bebafc0e0ed779..65ae8fc9ceaddfa0cb1ac28a33bcd4f64fb64092 100644
--- a/chrome/browser/ui/views/avatar_label.cc
+++ b/chrome/browser/ui/views/avatar_label.cc
@@ -6,31 +6,30 @@
#include "base/memory/scoped_ptr.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 "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/theme_provider.h"
-#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
-#include "ui/gfx/font_list.h"
#include "ui/views/painter.h"
namespace {
-// A special text button border for the managed user avatar label.
-class AvatarLabelBorder: public views::TextButtonBorder {
+// A custom border for the managed user avatar label.
+class AvatarLabelBorder : public views::Border {
public:
explicit AvatarLabelBorder(bool label_on_right);
- // views::TextButtonBorder:
+ // views::Border:
virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE;
+ virtual gfx::Insets GetInsets() const OVERRIDE;
virtual gfx::Size GetMinimumSize() const OVERRIDE;
private:
scoped_ptr<views::Painter> painter_;
+ gfx::Insets insets_;
DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder);
};
@@ -42,15 +41,13 @@ AvatarLabelBorder::AvatarLabelBorder(bool label_on_right) {
const int kVerticalInsetBottom = 3;
// 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.
- const gfx::FontList font_list;
- int difference =
- (font_list.GetFontSize() < 13) ? 13 - font_list.GetFontSize() : 0;
- int addToTop = difference / 2;
- int addToBottom = difference - addToTop;
- SetInsets(gfx::Insets(kVerticalInsetTop + addToTop,
+ const int difference = std::max<int>(0, 13 - gfx::FontList().GetFontSize());
+ const int addToTop = difference / 2;
+ const int addToBottom = difference - addToTop;
+ insets_ = gfx::Insets(kVerticalInsetTop + addToTop,
kHorizontalInsetLeft,
kVerticalInsetBottom + addToBottom,
- kHorizontalInsetRight));
+ kHorizontalInsetRight);
const int kImages[] = IMAGE_GRID(IDR_MANAGED_USER_LABEL);
painter_.reset(views::Painter::CreateImageGridPainter(kImages));
}
@@ -60,7 +57,7 @@ void AvatarLabelBorder::Paint(const views::View& view, gfx::Canvas* canvas) {
// includes a border with almost transparent white color.
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.
gfx::Rect rect(1, 1, view.size().width() - 2, view.size().height() - 2);
SkPaint paint;
@@ -69,20 +66,22 @@ void AvatarLabelBorder::Paint(const views::View& view, gfx::Canvas* canvas) {
ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND);
paint.setStyle(SkPaint::kFill_Style);
- // For the inner border, use a color which is slightly darker than the
- // background color.
+ // Paint the inner border with a color slightly darker than the background.
SkAlpha kAlphaForBlending = 230;
paint.setColor(color_utils::AlphaBlend(
background_color, SK_ColorBLACK, kAlphaForBlending));
canvas->DrawRoundRect(rect, kRadius, paint);
- // Now paint the inner background using the color provided by the
- // ThemeProvider.
+ // Paint the inner background using the color provided by the ThemeProvider.
paint.setColor(background_color);
rect = gfx::Rect(2, 2, view.size().width() - 4, view.size().height() - 4);
canvas->DrawRoundRect(rect, kRadius, paint);
}
+gfx::Insets AvatarLabelBorder::GetInsets() const {
+ return insets_;
+}
+
gfx::Size AvatarLabelBorder::GetMinimumSize() const {
gfx::Size size(4, 4);
size.SetToMax(painter_->GetMinimumSize());
@@ -92,10 +91,9 @@ gfx::Size AvatarLabelBorder::GetMinimumSize() const {
} // namespace
AvatarLabel::AvatarLabel(BrowserView* browser_view)
- : TextButton(NULL,
- l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)),
+ : LabelButton(NULL,
+ l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)),
browser_view_(browser_view) {
- ClearMaxTextSize();
SetLabelOnRight(false);
UpdateLabelStyle();
}
@@ -103,7 +101,7 @@ AvatarLabel::AvatarLabel(BrowserView* browser_view)
AvatarLabel::~AvatarLabel() {}
bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) {
- if (!TextButton::OnMousePressed(event))
+ if (!LabelButton::OnMousePressed(event))
return false;
browser_view_->ShowAvatarBubbleFromAvatarButton();
@@ -117,10 +115,8 @@ void AvatarLabel::UpdateLabelStyle() {
SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor(
ThemeProperties::COLOR_MANAGED_USER_LABEL);
- SetEnabledColor(color_label);
- SetHighlightColor(color_label);
- SetHoverColor(color_label);
- SetDisabledColor(color_label);
+ for (size_t state = 0; state < STATE_COUNT; ++state)
+ SetTextColor(static_cast<ButtonState>(state), color_label);
SchedulePaint();
}
« no previous file with comments | « chrome/browser/ui/views/avatar_label.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698