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

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: better fix for app/popup browser crash 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 "grit/generated_resources.h"
8 #include "grit/theme_resources.h"
9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/color_utils.h"
13 #include "ui/views/border.h"
14 #include "ui/views/painter.h"
15
16 namespace {
17
18 // Text padding within the button border.
19 const int kInset = 10;
20
21 views::TextButtonDefaultBorder* CreateBorder(const int normal_image_set[],
22 const int hot_image_set[],
23 const int pushed_image_set[]) {
24 views::TextButtonDefaultBorder* border = new views::TextButtonDefaultBorder();
25
26 border->SetInsets(gfx::Insets(kInset, kInset, kInset, kInset));
27 border->set_normal_painter(
28 views::Painter::CreateImageGridPainter(normal_image_set));
29 border->set_hot_painter(
30 views::Painter::CreateImageGridPainter(hot_image_set));
31 border->set_pushed_painter(
32 views::Painter::CreateImageGridPainter(pushed_image_set));
33
34 return border;
35 }
36
37 } // namespace
38
39 NewAvatarButton::NewAvatarButton(
40 views::ButtonListener* listener,
41 const string16& profile_name,
42 AvatarButtonStyle button_style)
43 : MenuButton(listener, profile_name, NULL, true) {
44 set_animate_on_state_change(false);
45
46 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
47 SetFont(rb->GetFont(ui::ResourceBundle::BaseFont));
48
49 if (button_style == GLASS_BUTTON) {
50 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
51 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
52 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
53
54 set_border(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
55 set_menu_marker(
56 rb->GetImageNamed(IDR_AVATAR_GLASS_BUTTON_DROPARROW).ToImageSkia());
57 } else {
58 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
59 const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER);
60 const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED);
61
62 set_border(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
63 set_menu_marker(
64 rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia());
65 }
66 SchedulePaint();
67 }
68
69 NewAvatarButton::~NewAvatarButton() {
70 }
71
72 void NewAvatarButton::OnPaint(gfx::Canvas* canvas) {
73 // From TextButton::PaintButton, draw everything but the text.
74 OnPaintBackground(canvas);
75 OnPaintBorder(canvas);
76 OnPaintFocusBorder(canvas);
77
78 gfx::Rect rect;
79 // In RTL languages the marker gets drawn leftmost, so account for its offset.
80 if (base::i18n::IsRTL())
81 rect = gfx::Rect(-kInset, 0, size().width(), size().height());
82 else
83 rect = gfx::Rect(kInset, 0, size().width(), size().height());
84 // TODO(noms): This should be DrawStringRectWithHalo but that function
85 // has a bug at the moment and incorrectly draws the background.
86 canvas->DrawStringRectWithFlags(
87 text(),
88 gfx::FontList(ui::ResourceBundle::GetSharedInstance().GetFont(
89 ui::ResourceBundle::BaseFont)),
90 SK_ColorBLACK,
91 rect,
92 gfx::Canvas::NO_SUBPIXEL_RENDERING);
93
94 // From MenuButton::PaintButton, paint the marker
95 PaintMenuMarker(canvas);
96 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/new_avatar_button.h ('k') | chrome/browser/ui/views/new_avatar_menu_button_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698