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

Side by Side Diff: chrome/browser/ui/views/profiles/themed_avatar_button.cc

Issue 2851543002: Update avatar button to MD (part 1) (Closed)
Patch Set: More review changes Created 3 years, 7 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 2017 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/profiles/themed_avatar_button.h"
6
7 #include "chrome/grit/theme_resources.h"
8 #include "ui/base/resource/resource_bundle.h"
9 #include "ui/views/controls/button/label_button_border.h"
10
11 #if defined(OS_WIN)
12 #include "base/win/windows_version.h"
13 #endif
14
15 const int kButtonHeight = 20;
16
17 ThemedAvatarButton::ThemedAvatarButton(views::MenuButtonListener* listener,
18 AvatarButtonStyle button_style,
19 Profile* profile)
20 : AvatarButton(listener, profile) {
21 if (button_style == AvatarButtonStyle::THEMED) {
22 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
23 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER);
24 const int kPressedImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_PRESSED);
25 SetButtonAvatar(IDR_AVATAR_THEMED_BUTTON_AVATAR);
26 SetBorder(CreateBorder(kNormalImageSet, kHoverImageSet, kPressedImageSet));
27 #if defined(OS_WIN)
28 } else if (base::win::GetVersion() < base::win::VERSION_WIN8) {
29 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
30 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
31 const int kPressedImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_PRESSED);
32 SetButtonAvatar(IDR_AVATAR_GLASS_BUTTON_AVATAR);
33 SetBorder(CreateBorder(kNormalImageSet, kHoverImageSet, kPressedImageSet));
34 #endif
35 } else {
36 const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL);
37 const int kHoverImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER);
38 const int kPressedImageSet[] = IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED);
39 SetButtonAvatar(IDR_AVATAR_NATIVE_BUTTON_AVATAR);
40 SetBorder(CreateBorder(kNormalImageSet, kHoverImageSet, kPressedImageSet));
41 }
42
43 Update();
44 SchedulePaint();
45 }
46
47 ThemedAvatarButton::~ThemedAvatarButton() {}
48
49 gfx::Size ThemedAvatarButton::GetPreferredSize() const {
50 gfx::Size size = views::MenuButton::GetPreferredSize();
51 size.set_height(kButtonHeight);
52 return size;
53 }
54
55 std::unique_ptr<views::Border> ThemedAvatarButton::CreateBorder(
Evan Stade 2017/05/02 15:49:20 can this go back to being a file-local static?
emx 2017/05/03 17:10:59 Done.
56 const int normal_image_set[],
57 const int hot_image_set[],
58 const int pushed_image_set[]) const {
59 std::unique_ptr<views::LabelButtonAssetBorder> border(
60 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON));
61
62 border->SetPainter(false, views::Button::STATE_NORMAL,
63 views::Painter::CreateImageGridPainter(normal_image_set));
64 border->SetPainter(false, views::Button::STATE_HOVERED,
65 views::Painter::CreateImageGridPainter(hot_image_set));
66 border->SetPainter(false, views::Button::STATE_PRESSED,
67 views::Painter::CreateImageGridPainter(pushed_image_set));
68
69 const int kLeftRightInset = 8;
70 const int kTopInset = 2;
71 const int kBottomInset = 4;
72 border->set_insets(
73 gfx::Insets(kTopInset, kLeftRightInset, kBottomInset, kLeftRightInset));
74
75 return std::move(border);
76 }
77
78 void ThemedAvatarButton::SetButtonAvatar(int avatar_idr) {
79 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
80 set_generic_avatar(*rb->GetImageNamed(avatar_idr).ToImageSkia());
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698