OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/avatar_label.h" | 5 #include "chrome/browser/ui/views/avatar_label.h" |
6 | 6 |
7 #include "chrome/browser/themes/theme_properties.h" | 7 #include "chrome/browser/themes/theme_properties.h" |
8 #include "chrome/browser/ui/browser.h" | |
9 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" | 8 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
10 #include "chrome/browser/ui/views/frame/browser_view.h" | 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
11 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
12 #include "ui/base/events/event.h" | 11 #include "ui/base/events/event.h" |
13 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/base/theme_provider.h" | 14 #include "ui/base/theme_provider.h" |
16 #include "ui/gfx/point.h" | 15 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/color_utils.h" |
17 #include "ui/views/painter.h" | |
18 | |
19 namespace { | |
20 | |
21 // A special text button border for the managed user avatar label. | |
22 class AvatarLabelBorder: public views::TextButtonBorder { | |
23 public: | |
24 explicit AvatarLabelBorder(ui::ThemeProvider* theme_provider); | |
25 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.
| |
26 private: | |
sky
2013/06/21 16:28:26
nit: newline between 25/26 and DISALLOW_...
Adrian Kuegel
2013/06/21 21:19:32
Done.
| |
27 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.
| |
28 views::Painter* painter_; | |
29 }; | |
30 | |
31 AvatarLabelBorder::AvatarLabelBorder(ui::ThemeProvider* theme_provider) { | |
32 const int kHorizontalInset = 10; | |
33 const int kVerticalInset = 2; | |
34 SetInsets(gfx::Insets( | |
35 kVerticalInset, kHorizontalInset, kVerticalInset, kHorizontalInset)); | |
36 SkColor color = theme_provider->GetColor( | |
37 ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND); | |
38 SkColor color2 = color_utils::BlendTowardOppositeLuminance(color, 0x20); | |
39 painter_ = views::Painter::CreateVerticalGradient(color, color2); | |
40 hot_painter_ = views::Painter::CreateVerticalGradient(color2, color); | |
41 } | |
42 | |
43 void AvatarLabelBorder::Paint(const views::View& view, gfx::Canvas* canvas) { | |
44 const views::TextButton* button = | |
45 static_cast<const views::TextButton*>(&view); | |
46 if (button->state() == views::TextButton::STATE_HOVERED || | |
47 button->state() == views::TextButton::STATE_PRESSED) | |
48 hot_painter_->Paint(canvas, view.size()); | |
49 else | |
50 painter_->Paint(canvas, view.size()); | |
51 } | |
52 | |
53 } // namespace | |
18 | 54 |
19 AvatarLabel::AvatarLabel(BrowserView* browser_view, | 55 AvatarLabel::AvatarLabel(BrowserView* browser_view, |
20 ui::ThemeProvider* theme_provider) | 56 ui::ThemeProvider* theme_provider) |
21 : TextButton(NULL, | 57 : TextButton(NULL, |
22 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)), | 58 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)), |
23 browser_view_(browser_view), | 59 browser_view_(browser_view), |
24 theme_provider_(theme_provider) { | 60 theme_provider_(theme_provider) { |
25 SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | 61 SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( |
26 ui::ResourceBundle::SmallFont)); | 62 ui::ResourceBundle::SmallFont)); |
27 ClearMaxTextSize(); | 63 ClearMaxTextSize(); |
28 views::TextButtonNativeThemeBorder* border = | 64 set_border(new AvatarLabelBorder(theme_provider)); |
29 new views::TextButtonNativeThemeBorder(this); | |
30 const int kHorizontalInset = 10; | |
31 const int kVerticalInset = 2; | |
32 border->SetInsets(gfx::Insets( | |
33 kVerticalInset, kHorizontalInset, kVerticalInset, kHorizontalInset)); | |
34 set_border(border); | |
35 UpdateLabelStyle(); | 65 UpdateLabelStyle(); |
36 } | 66 } |
37 | 67 |
38 AvatarLabel::~AvatarLabel() {} | 68 AvatarLabel::~AvatarLabel() {} |
39 | 69 |
40 bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) { | 70 bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) { |
41 if (!TextButton::OnMousePressed(event)) | 71 if (!TextButton::OnMousePressed(event)) |
42 return false; | 72 return false; |
43 | 73 |
44 browser_view_->ShowAvatarBubbleFromAvatarButton(); | 74 browser_view_->ShowAvatarBubbleFromAvatarButton(); |
45 return true; | 75 return true; |
46 } | 76 } |
47 | 77 |
48 void AvatarLabel::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { | |
49 TextButton::GetExtraParams(params); | |
50 params->button.background_color = theme_provider_->GetColor( | |
51 ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND); | |
52 } | |
53 | |
54 void AvatarLabel::UpdateLabelStyle() { | 78 void AvatarLabel::UpdateLabelStyle() { |
55 SkColor color_label = | 79 SkColor color_label = |
56 theme_provider_->GetColor(ThemeProperties::COLOR_MANAGED_USER_LABEL); | 80 theme_provider_->GetColor(ThemeProperties::COLOR_MANAGED_USER_LABEL); |
57 SetEnabledColor(color_label); | 81 SetEnabledColor(color_label); |
82 SetHighlightColor(color_label); | |
83 SetHoverColor(color_label); | |
84 SetDisabledColor(color_label); | |
58 SchedulePaint(); | 85 SchedulePaint(); |
59 } | 86 } |
OLD | NEW |