Commit da458835 authored by Monica Basta's avatar Monica Basta Committed by Commit Bot

[ProfilePicker]: Show generic colored avatar for the local profile creation.

Screenshot:
https://drive.google.com/file/d/1hJB_rmXQ13zfwdMI-we-LoVPlOy9Fspt/view?usp=sharing

Bug: 1115056
Change-Id: I324dfca8105e439aeb1d29c2a7a6130b9cf5af1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362753
Commit-Queue: Monica Basta <msalama@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarAlex Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799871}
parent f4e154cc
......@@ -96,28 +96,6 @@ int GetLowEntropyHashValue(const std::string& value) {
return base::PersistentHash(value) % kNumberOfLowEntropyHashValues;
}
class ImageWithBackgroundSource : public gfx::CanvasImageSource {
public:
ImageWithBackgroundSource(const gfx::ImageSkia& image, SkColor background)
: gfx::CanvasImageSource(image.size()),
image_(image),
background_(background) {}
~ImageWithBackgroundSource() override = default;
// gfx::CanvasImageSource override.
void Draw(gfx::Canvas* canvas) override {
canvas->DrawColor(background_);
canvas->DrawImageInt(image_, 0, 0);
}
private:
const gfx::ImageSkia image_;
const SkColor background_;
DISALLOW_COPY_AND_ASSIGN(ImageWithBackgroundSource);
};
} // namespace
bool ProfileThemeColors::operator==(const ProfileThemeColors& other) const {
......@@ -748,14 +726,9 @@ const gfx::Image* ProfileAttributesEntry::GetHighResAvatar() const {
gfx::Image ProfileAttributesEntry::GetPlaceholderAvatarIcon(int size) const {
ProfileThemeColors colors = GetProfileThemeColors();
gfx::ImageSkia icon_without_background =
gfx::CreateVectorIcon(gfx::IconDescription(
kPersonOutlinePaddedIcon, size, colors.default_avatar_stroke_color));
gfx::ImageSkia icon_with_background(
std::make_unique<ImageWithBackgroundSource>(
icon_without_background, colors.default_avatar_fill_color),
return profiles::GetPlaceholderAvatarIconWithColors(
colors.default_avatar_fill_color, colors.default_avatar_stroke_color,
size);
return gfx::Image(icon_with_background);
}
bool ProfileAttributesEntry::HasMultipleAccountNames() const {
......
......@@ -285,6 +285,28 @@ void AvatarImageSource::Draw(gfx::Canvas* canvas) {
}
}
class ImageWithBackgroundSource : public gfx::CanvasImageSource {
public:
ImageWithBackgroundSource(const gfx::ImageSkia& image, SkColor background)
: gfx::CanvasImageSource(image.size()),
image_(image),
background_(background) {}
~ImageWithBackgroundSource() override = default;
// gfx::CanvasImageSource override.
void Draw(gfx::Canvas* canvas) override {
canvas->DrawColor(background_);
canvas->DrawImageInt(image_, 0, 0);
}
private:
const gfx::ImageSkia image_;
const SkColor background_;
DISALLOW_COPY_AND_ASSIGN(ImageWithBackgroundSource);
};
} // namespace
namespace profiles {
......@@ -591,6 +613,18 @@ const IconResourceInfo* GetDefaultAvatarIconResourceInfo(size_t index) {
return &resource_info[index];
}
gfx::Image GetPlaceholderAvatarIconWithColors(SkColor fill_color,
SkColor stroke_color,
int size) {
gfx::ImageSkia icon_without_background = gfx::CreateVectorIcon(
gfx::IconDescription(kPersonOutlinePaddedIcon, size, stroke_color));
gfx::ImageSkia icon_with_background(
std::make_unique<ImageWithBackgroundSource>(icon_without_background,
fill_color),
size);
return gfx::Image(icon_with_background);
}
int GetDefaultAvatarIconResourceIDAtIndex(size_t index) {
return GetDefaultAvatarIconResourceInfo(index)->resource_id;
}
......
......@@ -118,6 +118,11 @@ int GetPlaceholderAvatarIconResourceID();
// Returns a URL for the placeholder avatar icon.
std::string GetPlaceholderAvatarIconUrl();
// Returns colored generic avatar.
gfx::Image GetPlaceholderAvatarIconWithColors(SkColor fill_color,
SkColor stroke_color,
int size);
// Gets the resource ID of the default avatar icon at |index|.
int GetDefaultAvatarIconResourceIDAtIndex(size_t index);
......
......@@ -24,6 +24,7 @@ export let ProfileState;
* themeFrameColor: string,
* themeShapeColor: string,
* themeFrameTextColor: string,
* themeGenericAvatar: string,
* }}
*/
export let AutogeneratedThemeColorInfo;
......
......@@ -16,5 +16,5 @@
on-click="onClickBack_" aria-label="$i18n{backButtonLabel}">
</cr-icon-button>
<h2 id="title">$i18n{localProfileCreationTitle}<h2>
<img class="avatar" src="chrome://theme/IDR_PROFILE_AVATAR_PLACEHOLDER_LARGE">
<img class="avatar" src$="[[profileThemeInfo.themeGenericAvatar]]">
</div>
......@@ -54,7 +54,7 @@
on-click="onClickBack_" aria-label="$i18n{backButtonLabel}">
</cr-icon-button>
<div id="signinPromoBanner" class="banner"></div>
<img class="avatar" src="chrome://theme/IDR_PROFILE_AVATAR_PLACEHOLDER_LARGE">
<img class="avatar" src="[[profileThemeInfo.themeGenericAvatar]]">
</div>
<div class="title-container">
<h2>$i18n{profileTypeChoiceTitle}</h2>
......
......@@ -164,6 +164,12 @@ void ProfilePickerHandler::HandleGetNewProfileSuggestedThemeInfo(
theme_colors.active_tab_color));
dict.SetStringKey("themeFrameTextColor", color_utils::SkColorToRgbaString(
theme_colors.frame_text_color));
gfx::Image icon = profiles::GetPlaceholderAvatarIconWithColors(
/*fill_color=*/theme_colors.frame_color,
/*stroke_color=*/GetAvatarStrokeColor(theme_colors.frame_color),
kAvatarIconSize);
dict.SetStringKey("themeGenericAvatar",
webui::GetBitmapDataUrl(icon.AsBitmap()));
ResolveJavascriptCallback(callback_id, std::move(dict));
}
......
......@@ -54,7 +54,8 @@ export class TestManageProfilesBrowserProxy extends TestBrowserProxy {
colorId: 0,
themeFrameColor: '',
themeShapeColor: '',
themeFrameTextColor: ''
themeFrameTextColor: '',
themeGenericAvatar: ''
});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment