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

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

Issue 1972033002: Simplify some old avatar menu button code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 4 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 2014 The Chromium Authors. All rights reserved.
Peter Kasting 2016/05/17 03:51:43 Nit: 2016
Evan Stade 2016/05/17 18:13:09 this is just a trimmed down version of avatar_menu
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/profile_indicator_icon.h"
6
7 #include <stddef.h>
8
9 #include "base/command_line.h"
10 #include "build/build_config.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/profiles/avatar_menu.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_attributes_entry.h"
16 #include "chrome/browser/profiles/profile_attributes_storage.h"
17 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
18 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/profiles/profile_metrics.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/browser/ui/views/frame/browser_view.h"
23 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
24 #include "components/prefs/pref_service.h"
25 #include "components/signin/core/common/profile_management_switches.h"
26 #include "content/public/browser/notification_service.h"
27 #include "grit/theme_resources.h"
28 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/gfx/canvas.h"
30 #include "ui/views/view_targeter.h"
31 #include "ui/views/widget/widget.h"
Peter Kasting 2016/05/17 03:51:43 Surely we don't need all these #includes?
Evan Stade 2016/05/17 18:13:09 Done.
32
33 static inline int Round(double x) {
Peter Kasting 2016/05/17 03:51:43 Use std::round() instead.
Evan Stade 2016/05/17 18:13:09 Done.
34 return static_cast<int>(x + 0.5);
35 }
36
37 ProfileIndicatorIcon::ProfileIndicatorIcon(BrowserView* browser_view)
38 : browser_view_(browser_view), old_height_(0) {
39 // In RTL mode, the avatar icon should be looking the opposite direction.
Peter Kasting 2016/05/17 03:51:43 Nit: avatar -> profile (or nothing)
Evan Stade 2016/05/17 18:13:09 removed --- I don't think we want this anywhere ex
40 EnableCanvasFlippingForRTLUI(true);
41 }
42
43 ProfileIndicatorIcon::~ProfileIndicatorIcon() {}
44
45 void ProfileIndicatorIcon::OnPaint(gfx::Canvas* canvas) {
46 if (base_icon_.IsEmpty())
47 return;
48
49 if (old_height_ != height() || modified_icon_.isNull()) {
50 old_height_ = height();
51 modified_icon_ = *profiles::GetAvatarIconForTitleBar(base_icon_, false,
52 width(), height())
53 .ToImageSkia();
54 }
55
56 // Scale the image to fit the width of the button.
57 int dst_width = std::min(modified_icon_.width(), width());
58 // Truncate rather than rounding, so that for odd widths we put the extra
59 // pixel on the left.
60 int dst_x = (width() - dst_width) / 2;
61
62 // Scale the height and maintain aspect ratio. This means that the
63 // icon may not fit in the view. That's ok, we just vertically center it.
64 float scale = static_cast<float>(dst_width) /
65 static_cast<float>(modified_icon_.width());
66 // Round here so that we minimize the aspect ratio drift.
67 int dst_height = Round(modified_icon_.height() * scale);
68 // Round rather than truncating, so that for odd heights we select an extra
69 // pixel below the image center rather than above. This is because the
70 // incognito image has shadows at the top that make the apparent center below
71 // the real center.
72 int dst_y = Round((height() - dst_height) / 2.0);
Peter Kasting 2016/05/17 03:51:43 Nit: 2.0f?
Evan Stade 2016/05/17 18:13:09 Done.
73 canvas->DrawImageInt(modified_icon_, 0, 0, modified_icon_.width(),
74 modified_icon_.height(), dst_x, dst_y, dst_width,
75 dst_height, false);
76 }
77
78 void ProfileIndicatorIcon::SetIcon(const gfx::Image& icon) {
79 base_icon_ = icon;
80 modified_icon_ = gfx::ImageSkia();
81 SchedulePaint();
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698