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

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: Address nits. 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return size; 89 return size;
90 } 90 }
91 91
92 } // namespace 92 } // namespace
93 93
94 AvatarLabel::AvatarLabel(BrowserView* browser_view) 94 AvatarLabel::AvatarLabel(BrowserView* browser_view)
95 : TextButton(NULL, 95 : TextButton(NULL,
96 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)), 96 l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)),
97 browser_view_(browser_view) { 97 browser_view_(browser_view) {
98 ClearMaxTextSize(); 98 ClearMaxTextSize();
99 set_border(new AvatarLabelBorder); 99 SetLabelOnRight(false);
100 UpdateLabelStyle(); 100 UpdateLabelStyle();
101 } 101 }
102 102
103 AvatarLabel::~AvatarLabel() {} 103 AvatarLabel::~AvatarLabel() {}
104 104
105 bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) { 105 bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) {
106 if (!TextButton::OnMousePressed(event)) 106 if (!TextButton::OnMousePressed(event))
107 return false; 107 return false;
108 108
109 browser_view_->ShowAvatarBubbleFromAvatarButton(); 109 browser_view_->ShowAvatarBubbleFromAvatarButton();
110 return true; 110 return true;
111 } 111 }
112 112
113 void AvatarLabel::UpdateLabelStyle() { 113 void AvatarLabel::UpdateLabelStyle() {
114 // |browser_view_| can be NULL in unit tests.
115 if (!browser_view_)
116 return;
117
114 SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor( 118 SkColor color_label = browser_view_->frame()->GetThemeProvider()->GetColor(
115 ThemeProperties::COLOR_MANAGED_USER_LABEL); 119 ThemeProperties::COLOR_MANAGED_USER_LABEL);
116 SetEnabledColor(color_label); 120 SetEnabledColor(color_label);
117 SetHighlightColor(color_label); 121 SetHighlightColor(color_label);
118 SetHoverColor(color_label); 122 SetHoverColor(color_label);
119 SetDisabledColor(color_label); 123 SetDisabledColor(color_label);
120 SchedulePaint(); 124 SchedulePaint();
121 } 125 }
126
127 void AvatarLabel::SetLabelOnRight(bool label_on_right) {
128 set_border(new AvatarLabelBorder(label_on_right));
129 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/avatar_label.h ('k') | chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698