Commit 3833be6d authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Fixed color access in BadgedProfilePhoto

Removed use of the global GetInstanceForNativeUI() from
BadgedProfilePhoto. Created a wrapper class to encapsulate the badge
ImageView that keeps the badge icon color in sync with the current
theme colors.

Bug: 1056916
Change-Id: I99a71d9912f16d8102a3a244a6db974ec46c371c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090309Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747501}
parent 9d0df34a
......@@ -51,49 +51,65 @@ void CustomImageView::OnPaint(gfx::Canvas* canvas) {
ImageView::OnPaint(canvas);
}
// Helpers --------------------------------------------------------------------
class BadgeView : public ::views::ImageView {
public:
explicit BadgeView(BadgedProfilePhoto::BadgeType badge_type)
: badge_type_(badge_type) {
SizeToPreferredSize();
SetPosition(gfx::Point(kBadgedProfilePhotoWidth - kBadgeIconSize,
kBadgedProfilePhotoHeight - kBadgeIconSize));
}
gfx::ImageSkia ImageForBadgeType(BadgedProfilePhoto::BadgeType badge_type) {
ui::NativeTheme* native_theme = ui::NativeTheme::GetInstanceForNativeUi();
switch (badge_type) {
// views::View
void OnThemeChanged() override {
switch (badge_type_) {
case BadgedProfilePhoto::BADGE_TYPE_SUPERVISOR:
return gfx::CreateVectorIcon(
SetImage(gfx::CreateVectorIcon(
kSupervisorAccountCircleIcon, kBadgeIconSize,
native_theme->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor));
GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor)));
break;
case BadgedProfilePhoto::BADGE_TYPE_CHILD:
return gfx::CreateVectorIcon(
SetImage(gfx::CreateVectorIcon(
kAccountChildCircleIcon, kBadgeIconSize,
native_theme->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor));
GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor)));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_COMPLETE:
return gfx::CreateVectorIcon(
SetImage(gfx::CreateVectorIcon(
kSyncCircleIcon, kBadgeIconSize,
native_theme->GetSystemColor(
ui::NativeTheme::kColorId_AlertSeverityLow));
GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_AlertSeverityLow)));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_ERROR:
return gfx::CreateVectorIcon(
SetImage(gfx::CreateVectorIcon(
kSyncErrorCircleIcon, kBadgeIconSize,
native_theme->GetSystemColor(
ui::NativeTheme::kColorId_AlertSeverityHigh));
GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_AlertSeverityHigh)));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_PAUSED:
return gfx::CreateVectorIcon(
SetImage(gfx::CreateVectorIcon(
kSyncPausedCircleIcon, kBadgeIconSize,
native_theme->GetSystemColor(
ui::NativeTheme::kColorId_ProminentButtonColor));
GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_ProminentButtonColor)));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_DISABLED:
return gfx::CreateVectorIcon(kSyncCircleIcon, kBadgeIconSize,
gfx::kGoogleGrey400);
SetImage(gfx::CreateVectorIcon(kSyncCircleIcon, kBadgeIconSize,
gfx::kGoogleGrey400));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_OFF:
return gfx::CreateVectorIcon(kSyncPausedCircleIcon, kBadgeIconSize,
gfx::kGoogleGrey600);
SetImage(gfx::CreateVectorIcon(kSyncPausedCircleIcon, kBadgeIconSize,
gfx::kGoogleGrey600));
break;
case BadgedProfilePhoto::BADGE_TYPE_NONE:
NOTREACHED();
return gfx::ImageSkia();
break;
}
}
NOTREACHED();
return gfx::ImageSkia();
}
private:
const BadgedProfilePhoto::BadgeType badge_type_;
};
} // namespace
......@@ -116,16 +132,8 @@ BadgedProfilePhoto::BadgedProfilePhoto(BadgeType badge_type,
profile_photo_view->SizeToPreferredSize();
AddChildView(profile_photo_view);
if (badge_type != BADGE_TYPE_NONE) {
// Create and add image view for badge icon.
views::ImageView* badge_view = new views::ImageView();
badge_view->SetImage(ImageForBadgeType(badge_type));
badge_view->SizeToPreferredSize();
AddChildView(badge_view);
badge_view->SetPosition(
gfx::Point(kBadgedProfilePhotoWidth - kBadgeIconSize,
kBadgedProfilePhotoHeight - kBadgeIconSize));
}
if (badge_type != BADGE_TYPE_NONE)
AddChildView(std::make_unique<BadgeView>(badge_type));
SetPreferredSize(
gfx::Size(kBadgedProfilePhotoWidth, kBadgedProfilePhotoHeight));
......
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