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 "base/memory/scoped_ptr.h" |
7 #include "chrome/browser/themes/theme_properties.h" | 8 #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" | 9 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
10 #include "chrome/browser/ui/views/frame/browser_view.h" | 10 #include "chrome/browser/ui/views/frame/browser_view.h" |
11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
12 #include "ui/base/events/event.h" | 12 #include "ui/base/events/event.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/base/theme_provider.h" | 15 #include "ui/base/theme_provider.h" |
16 #include "ui/gfx/point.h" | 16 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/color_utils.h" |
| 18 #include "ui/views/painter.h" |
| 19 |
| 20 namespace { |
| 21 |
| 22 // A special text button border for the managed user avatar label. |
| 23 class AvatarLabelBorder: public views::TextButtonBorder { |
| 24 public: |
| 25 explicit AvatarLabelBorder(ui::ThemeProvider* theme_provider); |
| 26 |
| 27 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; |
| 28 |
| 29 private: |
| 30 scoped_ptr<views::Painter> hot_painter_; |
| 31 scoped_ptr<views::Painter> painter_; |
| 32 |
| 33 DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder); |
| 34 }; |
| 35 |
| 36 AvatarLabelBorder::AvatarLabelBorder(ui::ThemeProvider* theme_provider) { |
| 37 const int kHorizontalInset = 10; |
| 38 const int kVerticalInset = 2; |
| 39 SetInsets(gfx::Insets( |
| 40 kVerticalInset, kHorizontalInset, kVerticalInset, kHorizontalInset)); |
| 41 SkColor color = theme_provider->GetColor( |
| 42 ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND); |
| 43 SkColor color2 = color_utils::BlendTowardOppositeLuminance(color, 0x20); |
| 44 painter_.reset(views::Painter::CreateVerticalGradient(color, color2)); |
| 45 hot_painter_.reset(views::Painter::CreateVerticalGradient(color2, color)); |
| 46 } |
| 47 |
| 48 void AvatarLabelBorder::Paint(const views::View& view, gfx::Canvas* canvas) { |
| 49 const views::TextButton* button = |
| 50 static_cast<const views::TextButton*>(&view); |
| 51 if (button->state() == views::TextButton::STATE_HOVERED || |
| 52 button->state() == views::TextButton::STATE_PRESSED) |
| 53 hot_painter_->Paint(canvas, view.size()); |
| 54 else |
| 55 painter_->Paint(canvas, view.size()); |
| 56 } |
| 57 |
| 58 } // namespace |
18 | 59 |
19 AvatarLabel::AvatarLabel(BrowserView* browser_view, | 60 AvatarLabel::AvatarLabel(BrowserView* browser_view, |
20 ui::ThemeProvider* theme_provider) | 61 ui::ThemeProvider* theme_provider) |
21 : TextButton(NULL, | 62 : TextButton(NULL, |
22 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)), | 63 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)), |
23 browser_view_(browser_view), | 64 browser_view_(browser_view), |
24 theme_provider_(theme_provider) { | 65 theme_provider_(theme_provider) { |
25 SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | 66 SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( |
26 ui::ResourceBundle::SmallFont)); | 67 ui::ResourceBundle::SmallFont)); |
27 ClearMaxTextSize(); | 68 ClearMaxTextSize(); |
28 views::TextButtonNativeThemeBorder* border = | 69 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(); | 70 UpdateLabelStyle(); |
36 } | 71 } |
37 | 72 |
38 AvatarLabel::~AvatarLabel() {} | 73 AvatarLabel::~AvatarLabel() {} |
39 | 74 |
40 bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) { | 75 bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) { |
41 if (!TextButton::OnMousePressed(event)) | 76 if (!TextButton::OnMousePressed(event)) |
42 return false; | 77 return false; |
43 | 78 |
44 browser_view_->ShowAvatarBubbleFromAvatarButton(); | 79 browser_view_->ShowAvatarBubbleFromAvatarButton(); |
45 return true; | 80 return true; |
46 } | 81 } |
47 | 82 |
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() { | 83 void AvatarLabel::UpdateLabelStyle() { |
55 SkColor color_label = | 84 SkColor color_label = |
56 theme_provider_->GetColor(ThemeProperties::COLOR_MANAGED_USER_LABEL); | 85 theme_provider_->GetColor(ThemeProperties::COLOR_MANAGED_USER_LABEL); |
57 SetEnabledColor(color_label); | 86 SetEnabledColor(color_label); |
| 87 SetHighlightColor(color_label); |
| 88 SetHoverColor(color_label); |
| 89 SetDisabledColor(color_label); |
58 SchedulePaint(); | 90 SchedulePaint(); |
59 } | 91 } |
OLD | NEW |