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 de923dbe6968b8193fdc5e936ae9d0bab7c4c913..c5a65ae8de991b69b09e1e95e031a2890f54daab 100644 |
| --- a/chrome/browser/ui/views/avatar_label.cc |
| +++ b/chrome/browser/ui/views/avatar_label.cc |
| @@ -23,7 +23,7 @@ namespace { |
| // A special text button border for the managed user avatar label. |
| class AvatarLabelBorder: public views::TextButtonBorder { |
| public: |
| - explicit AvatarLabelBorder(); |
| + explicit AvatarLabelBorder(bool label_on_right); |
| // views::TextButtonBorder: |
| virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; |
| @@ -35,9 +35,9 @@ class AvatarLabelBorder: public views::TextButtonBorder { |
| DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder); |
| }; |
| -AvatarLabelBorder::AvatarLabelBorder() { |
| - const int kHorizontalInsetRight = 10; |
| - const int kHorizontalInsetLeft = 43; |
| +AvatarLabelBorder::AvatarLabelBorder(bool label_on_right) { |
| + const int kHorizontalInsetRight = label_on_right ? 43 : 10; |
| + const int kHorizontalInsetLeft = label_on_right ? 10 : 43; |
| const int kVerticalInsetTop = 2; |
| const int kVerticalInsetBottom = 3; |
| // We want to align with the top of the tab. This works if the default font |
| @@ -91,17 +91,24 @@ gfx::Size AvatarLabelBorder::GetMinimumSize() const { |
| } // namespace |
| +// static |
| +const char AvatarLabel::kViewClassName[] = "AvatarLabel"; |
| + |
| AvatarLabel::AvatarLabel(BrowserView* browser_view) |
| : TextButton(NULL, |
| l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)), |
| - browser_view_(browser_view) { |
| + browser_view_(browser_view), label_on_right_(false) { |
|
Peter Kasting
2014/01/15 02:06:26
Nit: One member per line
Adrian Kuegel
2014/01/15 16:24:51
Done.
|
| ClearMaxTextSize(); |
| - set_border(new AvatarLabelBorder); |
| + set_border(new AvatarLabelBorder(label_on_right_)); |
| UpdateLabelStyle(); |
| } |
| AvatarLabel::~AvatarLabel() {} |
| +const char* AvatarLabel::GetClassName() const { |
| + return kViewClassName; |
| +} |
| + |
| bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) { |
| if (!TextButton::OnMousePressed(event)) |
| return false; |
| @@ -111,6 +118,10 @@ bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) { |
| } |
| void AvatarLabel::UpdateLabelStyle() { |
| + // |browser_view_| can be NULL in unit tests. |
| + if (!browser_view_) |
| + return; |
| + |
| SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor( |
| ThemeProperties::COLOR_MANAGED_USER_LABEL); |
| SetEnabledColor(color_label); |
| @@ -119,3 +130,10 @@ void AvatarLabel::UpdateLabelStyle() { |
| SetDisabledColor(color_label); |
| SchedulePaint(); |
| } |
| + |
| +void AvatarLabel::SetLabelOnRight(bool label_on_right) { |
| + if (label_on_right_ != label_on_right) { |
|
Peter Kasting
2014/01/15 02:06:26
Nit: Do we actually need this conditional? If we
Adrian Kuegel
2014/01/15 16:24:51
I checked it now, and it looks it is called only o
|
| + label_on_right_ = label_on_right; |
| + set_border(new AvatarLabelBorder(label_on_right_)); |
| + } |
| +} |