Index: chrome/browser/profiles/profile_avatar_icon_util.cc |
diff --git a/chrome/browser/profiles/profile_avatar_icon_util.cc b/chrome/browser/profiles/profile_avatar_icon_util.cc |
index 2d82b35a684ce27f9220bf0795ba8455ffd41856..48177923c1b4005d6ec3b552c27006289eb3dcc6 100644 |
--- a/chrome/browser/profiles/profile_avatar_icon_util.cc |
+++ b/chrome/browser/profiles/profile_avatar_icon_util.cc |
@@ -29,6 +29,7 @@ |
#include "ui/gfx/image/canvas_image_source.h" |
#include "ui/gfx/image/image.h" |
#include "ui/gfx/image/image_skia_operations.h" |
+#include "ui/gfx/path.h" |
#include "ui/gfx/skia_util.h" |
#include "url/gurl.h" |
#include "url/url_canon.h" |
@@ -72,7 +73,8 @@ class AvatarImageSource : public gfx::CanvasImageSource { |
const gfx::Size& canvas_size, |
int width, |
AvatarPosition position, |
- AvatarBorder border); |
+ AvatarBorder border, |
+ bool is_circular = false); |
Roger Tawa OOO till Jul 10th
2016/06/13 15:20:44
No spaces around = for default args.
Jane
2016/06/13 17:53:42
Done.
|
~AvatarImageSource() override; |
// CanvasImageSource override: |
@@ -85,6 +87,7 @@ class AvatarImageSource : public gfx::CanvasImageSource { |
const int height_; |
const AvatarPosition position_; |
const AvatarBorder border_; |
+ bool is_circular_; |
DISALLOW_COPY_AND_ASSIGN(AvatarImageSource); |
}; |
@@ -93,13 +96,15 @@ AvatarImageSource::AvatarImageSource(gfx::ImageSkia avatar, |
const gfx::Size& canvas_size, |
int width, |
AvatarPosition position, |
- AvatarBorder border) |
+ AvatarBorder border, |
+ bool is_circular) |
: gfx::CanvasImageSource(canvas_size, false), |
canvas_size_(canvas_size), |
width_(width), |
height_(GetScaledAvatarHeightForWidth(width, avatar)), |
position_(position), |
- border_(border) { |
+ border_(border), |
+ is_circular_(is_circular) { |
avatar_ = gfx::ImageSkiaOperations::CreateResizedImage( |
avatar, skia::ImageOperations::RESIZE_BEST, |
gfx::Size(width_, height_)); |
@@ -109,11 +114,25 @@ AvatarImageSource::~AvatarImageSource() { |
} |
void AvatarImageSource::Draw(gfx::Canvas* canvas) { |
+ if (is_circular_) { |
+ // Calculate the circular mask that will be used to display the avatar |
+ // image. |
+ gfx::Path circular_mask; |
Jane
2016/06/10 17:28:55
Question: Why am I getting "error: undefined refer
Roger Tawa OOO till Jul 10th
2016/06/13 15:20:44
Sorry, not sure. Try asking Justin (junov@)
Jane
2016/06/14 03:02:48
Added #ifdef and the Android unit tests passed! PT
|
+ circular_mask.addCircle(SkIntToScalar(canvas_size_.width() / 2), |
+ SkIntToScalar(canvas_size_.height() / 2), |
+ SkIntToScalar(canvas_size_.width() / 2)); |
+ canvas->ClipPath(circular_mask, true); |
+ } |
+ |
// Center the avatar horizontally. |
int x = (canvas_size_.width() - width_) / 2; |
int y; |
- if (position_ == POSITION_CENTER) { |
+ if (is_circular_) { |
+ // Draw the avatar on the bottom center of the canvas; overrides the |
+ // position specification. |
+ y = canvas_size_.height() - height_; |
+ } else if (position_ == POSITION_CENTER) { |
// Draw the avatar centered on the canvas. |
y = (canvas_size_.height() - height_) / 2; |
} else { |
@@ -226,7 +245,8 @@ const size_t kPlaceholderAvatarIndex = 26; |
gfx::Image GetSizedAvatarIcon(const gfx::Image& image, |
bool is_rectangle, |
- int width, int height) { |
+ int width, int height, |
+ bool is_circular) { |
if (!is_rectangle && image.Height() <= height) |
return image; |
@@ -235,7 +255,8 @@ gfx::Image GetSizedAvatarIcon(const gfx::Image& image, |
// Source for a centered, sized icon. GAIA images get a border. |
std::unique_ptr<gfx::ImageSkiaSource> source(new AvatarImageSource( |
*image.ToImageSkia(), size, std::min(width, height), |
- AvatarImageSource::POSITION_CENTER, AvatarImageSource::BORDER_NONE)); |
+ AvatarImageSource::POSITION_CENTER, AvatarImageSource::BORDER_NONE, |
+ is_circular)); |
return gfx::Image(gfx::ImageSkia(source.release(), size)); |
} |