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

Side by Side Diff: chrome/browser/ui/views/avatar_label.cc

Issue 18083014: Create new look of the avatar label. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix font size issue and some more positioning. Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/memory/scoped_ptr.h"
8 #include "chrome/browser/themes/theme_properties.h" 8 #include "chrome/browser/themes/theme_properties.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 "grit/theme_resources.h"
12 #include "ui/base/events/event.h" 13 #include "ui/base/events/event.h"
13 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/base/theme_provider.h" 16 #include "ui/base/theme_provider.h"
16 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/color_utils.h" 18 #include "ui/gfx/color_utils.h"
18 #include "ui/views/painter.h" 19 #include "ui/views/painter.h"
19 20
20 namespace { 21 namespace {
21 22
22 // A special text button border for the managed user avatar label. 23 // A special text button border for the managed user avatar label.
23 class AvatarLabelBorder: public views::TextButtonBorder { 24 class AvatarLabelBorder: public views::TextButtonBorder {
24 public: 25 public:
25 explicit AvatarLabelBorder(ui::ThemeProvider* theme_provider); 26 explicit AvatarLabelBorder(ui::ThemeProvider* theme_provider);
26 27
27 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; 28 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE;
28 29
29 private: 30 private:
30 scoped_ptr<views::Painter> hot_painter_;
31 scoped_ptr<views::Painter> painter_; 31 scoped_ptr<views::Painter> painter_;
32 32
33 DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder); 33 DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder);
34 }; 34 };
35 35
36 AvatarLabelBorder::AvatarLabelBorder(ui::ThemeProvider* theme_provider) { 36 AvatarLabelBorder::AvatarLabelBorder(ui::ThemeProvider* theme_provider) {
37 const int kHorizontalInset = 10; 37 const int kHorizontalInsetRight = 10;
38 const int kVerticalInset = 2; 38 const int kHorizontalInsetLeft = 43;
39 SetInsets(gfx::Insets( 39 const int kVerticalInsetTop = 2;
40 kVerticalInset, kHorizontalInset, kVerticalInset, kHorizontalInset)); 40 const int kVerticalInsetBottom = 3;
41 SkColor color = theme_provider->GetColor( 41 SetInsets(gfx::Insets(kVerticalInsetTop,
42 ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND); 42 kHorizontalInsetLeft,
43 SkColor color2 = color_utils::BlendTowardOppositeLuminance(color, 0x20); 43 kVerticalInsetBottom,
44 painter_.reset(views::Painter::CreateVerticalGradient(color, color2)); 44 kHorizontalInsetRight));
45 hot_painter_.reset(views::Painter::CreateVerticalGradient(color2, color)); 45 const int kImages[] = IMAGE_GRID(IDR_MANAGED_USER_LABEL);
46 painter_.reset(views::Painter::CreateImageGridPainter(kImages));
46 } 47 }
47 48
48 void AvatarLabelBorder::Paint(const views::View& view, gfx::Canvas* canvas) { 49 void AvatarLabelBorder::Paint(const views::View& view, gfx::Canvas* canvas) {
49 const views::TextButton* button = 50 painter_->Paint(canvas, view.size());
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 } 51 }
57 52
58 } // namespace 53 } // namespace
59 54
60 AvatarLabel::AvatarLabel(BrowserView* browser_view, 55 AvatarLabel::AvatarLabel(BrowserView* browser_view,
61 ui::ThemeProvider* theme_provider) 56 ui::ThemeProvider* theme_provider)
62 : TextButton(NULL, 57 : TextButton(NULL,
63 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)), 58 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)),
64 browser_view_(browser_view), 59 browser_view_(browser_view),
65 theme_provider_(theme_provider) { 60 theme_provider_(theme_provider) {
66 SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( 61 gfx::Font font = ui::ResourceBundle::GetSharedInstance().GetFont(
67 ui::ResourceBundle::SmallFont)); 62 ui::ResourceBundle::BaseFont);
63 // We need to make sure the font size is 13, otherwise the top of the label
64 // will not align with the top of the tab.
65 if (font.GetFontSize() != 13)
sky 2013/07/03 23:17:31 Can't you instead align to the top so you don't ha
Adrian Kuegel 2013/07/05 14:22:23 In our specification we have two requirements: the
66 font = font.DeriveFont(13 - font.GetFontSize());
67 SetFont(font);
68 ClearMaxTextSize(); 68 ClearMaxTextSize();
69 set_border(new AvatarLabelBorder(theme_provider)); 69 set_border(new AvatarLabelBorder(theme_provider));
70 UpdateLabelStyle(); 70 UpdateLabelStyle();
71 } 71 }
72 72
73 AvatarLabel::~AvatarLabel() {} 73 AvatarLabel::~AvatarLabel() {}
74 74
75 bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) { 75 bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) {
76 if (!TextButton::OnMousePressed(event)) 76 if (!TextButton::OnMousePressed(event))
77 return false; 77 return false;
78 78
79 browser_view_->ShowAvatarBubbleFromAvatarButton(); 79 browser_view_->ShowAvatarBubbleFromAvatarButton();
80 return true; 80 return true;
81 } 81 }
82 82
83 void AvatarLabel::UpdateLabelStyle() { 83 void AvatarLabel::UpdateLabelStyle() {
84 SkColor color_label = 84 SkColor color_label =
85 theme_provider_->GetColor(ThemeProperties::COLOR_MANAGED_USER_LABEL); 85 theme_provider_->GetColor(ThemeProperties::COLOR_MANAGED_USER_LABEL);
86 SetEnabledColor(color_label); 86 SetEnabledColor(color_label);
87 SetHighlightColor(color_label); 87 SetHighlightColor(color_label);
88 SetHoverColor(color_label); 88 SetHoverColor(color_label);
89 SetDisabledColor(color_label); 89 SetDisabledColor(color_label);
90 SchedulePaint(); 90 SchedulePaint();
91 } 91 }
OLDNEW
« no previous file with comments | « chrome/app/theme/theme_resources.grd ('k') | chrome/browser/ui/views/frame/browser_non_client_frame_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698