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

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

Issue 127253004: Support displaying the avatar label on the right side. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test. Created 6 years, 11 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 "grit/theme_resources.h"
13 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/theme_provider.h" 14 #include "ui/base/theme_provider.h"
15 #include "ui/events/event.h" 15 #include "ui/events/event.h"
16 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/color_utils.h" 17 #include "ui/gfx/color_utils.h"
18 #include "ui/gfx/font_list.h" 18 #include "ui/gfx/font_list.h"
19 #include "ui/views/painter.h" 19 #include "ui/views/painter.h"
20 20
21 namespace { 21 namespace {
22 22
23 // A special text button border for the managed user avatar label. 23 // A special text button border for the managed user avatar label.
24 class AvatarLabelBorder: public views::TextButtonBorder { 24 class AvatarLabelBorder: public views::TextButtonBorder {
25 public: 25 public:
26 explicit AvatarLabelBorder(); 26 explicit AvatarLabelBorder(bool label_on_right);
27 27
28 // views::TextButtonBorder: 28 // views::TextButtonBorder:
29 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE; 29 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE;
30 virtual gfx::Size GetMinimumSize() const OVERRIDE; 30 virtual gfx::Size GetMinimumSize() const OVERRIDE;
31 31
32 private: 32 private:
33 scoped_ptr<views::Painter> painter_; 33 scoped_ptr<views::Painter> painter_;
34 34
35 DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder); 35 DISALLOW_COPY_AND_ASSIGN(AvatarLabelBorder);
36 }; 36 };
37 37
38 AvatarLabelBorder::AvatarLabelBorder() { 38 AvatarLabelBorder::AvatarLabelBorder(bool label_on_right) {
39 const int kHorizontalInsetRight = 10; 39 const int kHorizontalInsetRight = label_on_right ? 43 : 10;
40 const int kHorizontalInsetLeft = 43; 40 const int kHorizontalInsetLeft = label_on_right ? 10 : 43;
41 const int kVerticalInsetTop = 2; 41 const int kVerticalInsetTop = 2;
42 const int kVerticalInsetBottom = 3; 42 const int kVerticalInsetBottom = 3;
43 // We want to align with the top of the tab. This works if the default font 43 // We want to align with the top of the tab. This works if the default font
44 // size is 13. If it is smaller, we need to increase the TopInset accordingly. 44 // size is 13. If it is smaller, we need to increase the TopInset accordingly.
45 const gfx::FontList font_list; 45 const gfx::FontList font_list;
46 int difference = 46 int difference =
47 (font_list.GetFontSize() < 13) ? 13 - font_list.GetFontSize() : 0; 47 (font_list.GetFontSize() < 13) ? 13 - font_list.GetFontSize() : 0;
48 int addToTop = difference / 2; 48 int addToTop = difference / 2;
49 int addToBottom = difference - addToTop; 49 int addToBottom = difference - addToTop;
50 SetInsets(gfx::Insets(kVerticalInsetTop + addToTop, 50 SetInsets(gfx::Insets(kVerticalInsetTop + addToTop,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 84 }
85 85
86 gfx::Size AvatarLabelBorder::GetMinimumSize() const { 86 gfx::Size AvatarLabelBorder::GetMinimumSize() const {
87 gfx::Size size(4, 4); 87 gfx::Size size(4, 4);
88 size.SetToMax(painter_->GetMinimumSize()); 88 size.SetToMax(painter_->GetMinimumSize());
89 return size; 89 return size;
90 } 90 }
91 91
92 } // namespace 92 } // namespace
93 93
94 // static
95 const char AvatarLabel::kViewClassName[] = "AvatarLabel";
96
94 AvatarLabel::AvatarLabel(BrowserView* browser_view) 97 AvatarLabel::AvatarLabel(BrowserView* browser_view)
95 : TextButton(NULL, 98 : TextButton(NULL,
96 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)), 99 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)),
97 browser_view_(browser_view) { 100 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.
98 ClearMaxTextSize(); 101 ClearMaxTextSize();
99 set_border(new AvatarLabelBorder); 102 set_border(new AvatarLabelBorder(label_on_right_));
100 UpdateLabelStyle(); 103 UpdateLabelStyle();
101 } 104 }
102 105
103 AvatarLabel::~AvatarLabel() {} 106 AvatarLabel::~AvatarLabel() {}
104 107
108 const char* AvatarLabel::GetClassName() const {
109 return kViewClassName;
110 }
111
105 bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) { 112 bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) {
106 if (!TextButton::OnMousePressed(event)) 113 if (!TextButton::OnMousePressed(event))
107 return false; 114 return false;
108 115
109 browser_view_->ShowAvatarBubbleFromAvatarButton(); 116 browser_view_->ShowAvatarBubbleFromAvatarButton();
110 return true; 117 return true;
111 } 118 }
112 119
113 void AvatarLabel::UpdateLabelStyle() { 120 void AvatarLabel::UpdateLabelStyle() {
121 // |browser_view_| can be NULL in unit tests.
122 if (!browser_view_)
123 return;
124
114 SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor( 125 SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor(
115 ThemeProperties::COLOR_MANAGED_USER_LABEL); 126 ThemeProperties::COLOR_MANAGED_USER_LABEL);
116 SetEnabledColor(color_label); 127 SetEnabledColor(color_label);
117 SetHighlightColor(color_label); 128 SetHighlightColor(color_label);
118 SetHoverColor(color_label); 129 SetHoverColor(color_label);
119 SetDisabledColor(color_label); 130 SetDisabledColor(color_label);
120 SchedulePaint(); 131 SchedulePaint();
121 } 132 }
133
134 void AvatarLabel::SetLabelOnRight(bool label_on_right) {
135 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
136 label_on_right_ = label_on_right;
137 set_border(new AvatarLabelBorder(label_on_right_));
138 }
139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698