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

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

Issue 24647003: Redesign of the avatar menu button. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix RTL button Created 7 years, 2 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/new_avatar_button.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/profiles/profile_metrics.h"
sky 2013/09/26 20:21:39 I think this code would be cleaner if you keep the
9 #include "chrome/browser/themes/theme_properties.h"
10 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
11 #include "chrome/browser/ui/views/frame/browser_view.h"
12 #include "chrome/browser/ui/views/profile_chooser_view.h"
13 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/base/theme_provider.h"
18 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/color_utils.h"
20 #include "ui/views/border.h"
21 #include "ui/views/painter.h"
22
23 namespace {
24
25 const int kInset = 10;
26
27
28 // AvatarGlassButtonBorder ----------------------------------------------------
29 class AvatarGlassButtonBorder : public views::TextButtonDefaultBorder {
30 public:
31 AvatarGlassButtonBorder() {
32 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
33 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
34 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
35
36 SetInsets(gfx::Insets(kInset, kInset, kInset, kInset));
37 set_normal_painter(views::Painter::CreateImageGridPainter(kNormalImageSet));
38 set_hot_painter(views::Painter::CreateImageGridPainter(kHotImageSet));
39 set_pushed_painter(views::Painter::CreateImageGridPainter(kPushedImageSet));
40 };
41
42 private:
43 virtual ~AvatarGlassButtonBorder() {
44 };
45
46 DISALLOW_COPY_AND_ASSIGN(AvatarGlassButtonBorder);
47 };
48
49
50 // AvatarThemedButtonBorder ---------------------------------------------------
51
52 class AvatarThemedButtonBorder : public views::TextButtonDefaultBorder {
53 public:
54 AvatarThemedButtonBorder() {
55 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
56 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER);
57 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED);
58
59 SetInsets(gfx::Insets(kInset, kInset, kInset, kInset));
60 set_normal_painter(views::Painter::CreateImageGridPainter(kNormalImageSet));
61 set_hot_painter(views::Painter::CreateImageGridPainter(kHotImageSet));
62 set_pushed_painter(views::Painter::CreateImageGridPainter(kPushedImageSet));
63 };
64
65 private:
66 virtual ~AvatarThemedButtonBorder() {
67 };
68
69 DISALLOW_COPY_AND_ASSIGN(AvatarThemedButtonBorder);
70 };
71
72 } // namespace
73
74
75 // NewAvatarButton ------------------------------------------------------------
76 NewAvatarButton::NewAvatarButton(
77 BrowserView* browser_view,
78 const string16& profile_name)
79 : MenuButton(NULL, string16(), NULL, true),
80 browser_view_(browser_view) {
81
sky 2013/09/26 20:21:39 nit: remove newline.
noms (inactive) 2013/10/01 17:42:21 Done.
82 SetText(profile_name);
83 set_animate_on_state_change(false);
84
85 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
86 SetFont(rb->GetFont(ui::ResourceBundle::BaseFont));
87
88 if (browser_view->frame()->ShouldUseNativeFrame()) {
89 set_border(new AvatarGlassButtonBorder);
90 set_menu_marker(
91 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia());
92 } else {
93 set_border(new AvatarThemedButtonBorder);
94 set_menu_marker(
95 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia());
96 }
97 SchedulePaint();
98 }
99
100 NewAvatarButton::~NewAvatarButton() {
101 }
102
103 void NewAvatarButton::OnPaint(gfx::Canvas* canvas) {
104 // From TextButton::PaintButton, draw everything but the text.
105 OnPaintBackground(canvas);
106 OnPaintBorder(canvas);
107 OnPaintFocusBorder(canvas);
108
109 gfx::Rect rect;
110 // In RTL languages the marker gets drawn leftmost, so account for its offset.
111 if (base::i18n::IsRTL())
112 rect = gfx::Rect(-kInset, 0, size().width(), size().height());
113 else
114 rect = gfx::Rect(kInset, 0, size().width(), size().height());
115 // TODO(noms): This should be DrawStringRectWithHalo but that function
116 // has a bug at the moment and incorrectly draws the background.
117 canvas->DrawStringRectWithFlags(
118 text(),
119 gfx::FontList(ui::ResourceBundle::GetSharedInstance().GetFont(
120 ui::ResourceBundle::BaseFont)),
121 SK_ColorBLACK,
122 rect,
123 gfx::Canvas::NO_SUBPIXEL_RENDERING);
124
125 // From MenuButton::PaintButton, paint the marker
126 PaintMenuMarker(canvas);
127 }
128
129 bool NewAvatarButton::OnMousePressed(const ui::MouseEvent& event) {
130 if (!TextButton::OnMousePressed(event))
131 return false;
132 ShowAvatarBubble();
133 return true;
134 }
135
136 void NewAvatarButton::ShowAvatarBubble() {
137 gfx::Point origin;
138 views::View::ConvertPointToScreen(this, &origin);
139 gfx::Rect bounds(origin, size());
140
141 ProfileChooserView::ShowBubble(
142 this, views::BubbleBorder::TOP_LEFT,
143 views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, bounds,
144 browser_view_->browser());
145
146 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE);
147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698