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

Unified Diff: ash/system/user/rounded_image_view.cc

Issue 210903003: Implemented system tray UI for new account management. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge conflicts resolved. Created 6 years, 8 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 | « ash/system/user/rounded_image_view.h ('k') | ash/system/user/tray_user.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/user/rounded_image_view.cc
diff --git a/ash/system/user/rounded_image_view.cc b/ash/system/user/rounded_image_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b5a38bd560ebf0cc7647128dde0b89b92598c1c4
--- /dev/null
+++ b/ash/system/user/rounded_image_view.cc
@@ -0,0 +1,79 @@
+// Copyright 2014 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 "ash/system/user/rounded_image_view.h"
+#include "skia/ext/image_operations.h"
+#include "third_party/skia/include/core/SkPaint.h"
+#include "third_party/skia/include/core/SkPath.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/image/image_skia_operations.h"
+#include "ui/gfx/skia_util.h"
+
+namespace ash {
+namespace tray {
+
+RoundedImageView::RoundedImageView(int corner_radius, bool active_user)
+ : active_user_(active_user) {
+ for (int i = 0; i < 4; ++i)
+ corner_radius_[i] = corner_radius;
+}
+
+RoundedImageView::~RoundedImageView() {}
+
+void RoundedImageView::SetImage(const gfx::ImageSkia& img,
+ const gfx::Size& size) {
+ image_ = img;
+ image_size_ = size;
+
+ // Try to get the best image quality for the avatar.
+ resized_ = gfx::ImageSkiaOperations::CreateResizedImage(
+ image_, skia::ImageOperations::RESIZE_BEST, size);
+ if (GetWidget() && visible()) {
+ PreferredSizeChanged();
+ SchedulePaint();
+ }
+}
+
+void RoundedImageView::SetCornerRadii(int top_left,
+ int top_right,
+ int bottom_right,
+ int bottom_left) {
+ corner_radius_[0] = top_left;
+ corner_radius_[1] = top_right;
+ corner_radius_[2] = bottom_right;
+ corner_radius_[3] = bottom_left;
+}
+
+gfx::Size RoundedImageView::GetPreferredSize() {
+ return gfx::Size(image_size_.width() + GetInsets().width(),
+ image_size_.height() + GetInsets().height());
+}
+
+void RoundedImageView::OnPaint(gfx::Canvas* canvas) {
+ View::OnPaint(canvas);
+ gfx::Rect image_bounds(size());
+ image_bounds.ClampToCenteredSize(GetPreferredSize());
+ image_bounds.Inset(GetInsets());
+ const SkScalar kRadius[8] = {
+ SkIntToScalar(corner_radius_[0]),
+ SkIntToScalar(corner_radius_[0]),
+ SkIntToScalar(corner_radius_[1]),
+ SkIntToScalar(corner_radius_[1]),
+ SkIntToScalar(corner_radius_[2]),
+ SkIntToScalar(corner_radius_[2]),
+ SkIntToScalar(corner_radius_[3]),
+ SkIntToScalar(corner_radius_[3])
+ };
+ SkPath path;
+ path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius);
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setXfermodeMode(active_user_ ? SkXfermode::kSrcOver_Mode
+ : SkXfermode::kLuminosity_Mode);
+ canvas->DrawImageInPath(
+ resized_, image_bounds.x(), image_bounds.y(), path, paint);
+}
+
+} // namespace tray
+} // namespace ash
« no previous file with comments | « ash/system/user/rounded_image_view.h ('k') | ash/system/user/tray_user.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698