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

Unified 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: reinstate ash browser test fix 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/profiles/profile_indicator_icon.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/profiles/profile_indicator_icon.cc
diff --git a/chrome/browser/ui/views/profiles/profile_indicator_icon.cc b/chrome/browser/ui/views/profiles/profile_indicator_icon.cc
new file mode 100644
index 0000000000000000000000000000000000000000..70c9b1d8a67a1452ead0e02f58a3e957c51f9289
--- /dev/null
+++ b/chrome/browser/ui/views/profiles/profile_indicator_icon.cc
@@ -0,0 +1,54 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/profiles/profile_indicator_icon.h"
+
+#include "chrome/browser/profiles/profile_avatar_icon_util.h"
+#include "ui/gfx/canvas.h"
+
+ProfileIndicatorIcon::ProfileIndicatorIcon() : old_height_(0) {
+ // In RTL mode, the incognito icon should be looking the opposite direction.
+ EnableCanvasFlippingForRTLUI(true);
+}
+
+ProfileIndicatorIcon::~ProfileIndicatorIcon() {}
+
+void ProfileIndicatorIcon::OnPaint(gfx::Canvas* canvas) {
+ if (base_icon_.IsEmpty())
+ return;
+
+ if (old_height_ != height() || modified_icon_.isNull()) {
+ old_height_ = height();
+ modified_icon_ = *profiles::GetAvatarIconForTitleBar(base_icon_, false,
+ width(), height())
+ .ToImageSkia();
+ }
+
+ // Scale the image to fit the width of the button.
+ int dst_width = std::min(modified_icon_.width(), width());
+ // Truncate rather than rounding, so that for odd widths we put the extra
+ // pixel on the left.
+ int dst_x = (width() - dst_width) / 2;
+
+ // Scale the height and maintain aspect ratio. This means that the
+ // icon may not fit in the view. That's ok, we just vertically center it.
+ float scale = static_cast<float>(dst_width) /
+ static_cast<float>(modified_icon_.width());
+ // Round here so that we minimize the aspect ratio drift.
+ int dst_height = std::round(modified_icon_.height() * scale);
+ // Round rather than truncating, so that for odd heights we select an extra
+ // pixel below the image center rather than above. This is because the
+ // incognito image has shadows at the top that make the apparent center below
+ // the real center.
+ int dst_y = std::round((height() - dst_height) / 2.0f);
+ canvas->DrawImageInt(modified_icon_, 0, 0, modified_icon_.width(),
+ modified_icon_.height(), dst_x, dst_y, dst_width,
+ dst_height, false);
+}
+
+void ProfileIndicatorIcon::SetIcon(const gfx::Image& icon) {
+ base_icon_ = icon;
+ modified_icon_ = gfx::ImageSkia();
+ SchedulePaint();
+}
« no previous file with comments | « chrome/browser/ui/views/profiles/profile_indicator_icon.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698