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) { ...@@ -51,49 +51,65 @@ void CustomImageView::OnPaint(gfx::Canvas* canvas) {
ImageView::OnPaint(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) { // views::View
ui::NativeTheme* native_theme = ui::NativeTheme::GetInstanceForNativeUi(); void OnThemeChanged() override {
switch (badge_type) { switch (badge_type_) {
case BadgedProfilePhoto::BADGE_TYPE_SUPERVISOR: case BadgedProfilePhoto::BADGE_TYPE_SUPERVISOR:
return gfx::CreateVectorIcon( SetImage(gfx::CreateVectorIcon(
kSupervisorAccountCircleIcon, kBadgeIconSize, kSupervisorAccountCircleIcon, kBadgeIconSize,
native_theme->GetSystemColor( GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor)); ui::NativeTheme::kColorId_DefaultIconColor)));
break;
case BadgedProfilePhoto::BADGE_TYPE_CHILD: case BadgedProfilePhoto::BADGE_TYPE_CHILD:
return gfx::CreateVectorIcon( SetImage(gfx::CreateVectorIcon(
kAccountChildCircleIcon, kBadgeIconSize, kAccountChildCircleIcon, kBadgeIconSize,
native_theme->GetSystemColor( GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor)); ui::NativeTheme::kColorId_DefaultIconColor)));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_COMPLETE: case BadgedProfilePhoto::BADGE_TYPE_SYNC_COMPLETE:
return gfx::CreateVectorIcon( SetImage(gfx::CreateVectorIcon(
kSyncCircleIcon, kBadgeIconSize, kSyncCircleIcon, kBadgeIconSize,
native_theme->GetSystemColor( GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_AlertSeverityLow)); ui::NativeTheme::kColorId_AlertSeverityLow)));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_ERROR: case BadgedProfilePhoto::BADGE_TYPE_SYNC_ERROR:
return gfx::CreateVectorIcon( SetImage(gfx::CreateVectorIcon(
kSyncErrorCircleIcon, kBadgeIconSize, kSyncErrorCircleIcon, kBadgeIconSize,
native_theme->GetSystemColor( GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_AlertSeverityHigh)); ui::NativeTheme::kColorId_AlertSeverityHigh)));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_PAUSED: case BadgedProfilePhoto::BADGE_TYPE_SYNC_PAUSED:
return gfx::CreateVectorIcon( SetImage(gfx::CreateVectorIcon(
kSyncPausedCircleIcon, kBadgeIconSize, kSyncPausedCircleIcon, kBadgeIconSize,
native_theme->GetSystemColor( GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_ProminentButtonColor)); ui::NativeTheme::kColorId_ProminentButtonColor)));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_DISABLED: case BadgedProfilePhoto::BADGE_TYPE_SYNC_DISABLED:
return gfx::CreateVectorIcon(kSyncCircleIcon, kBadgeIconSize, SetImage(gfx::CreateVectorIcon(kSyncCircleIcon, kBadgeIconSize,
gfx::kGoogleGrey400); gfx::kGoogleGrey400));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_OFF: case BadgedProfilePhoto::BADGE_TYPE_SYNC_OFF:
return gfx::CreateVectorIcon(kSyncPausedCircleIcon, kBadgeIconSize, SetImage(gfx::CreateVectorIcon(kSyncPausedCircleIcon, kBadgeIconSize,
gfx::kGoogleGrey600); gfx::kGoogleGrey600));
break;
case BadgedProfilePhoto::BADGE_TYPE_NONE: case BadgedProfilePhoto::BADGE_TYPE_NONE:
NOTREACHED(); NOTREACHED();
return gfx::ImageSkia(); break;
}
} }
NOTREACHED();
return gfx::ImageSkia(); private:
} const BadgedProfilePhoto::BadgeType badge_type_;
};
} // namespace } // namespace
...@@ -116,16 +132,8 @@ BadgedProfilePhoto::BadgedProfilePhoto(BadgeType badge_type, ...@@ -116,16 +132,8 @@ BadgedProfilePhoto::BadgedProfilePhoto(BadgeType badge_type,
profile_photo_view->SizeToPreferredSize(); profile_photo_view->SizeToPreferredSize();
AddChildView(profile_photo_view); AddChildView(profile_photo_view);
if (badge_type != BADGE_TYPE_NONE) { if (badge_type != BADGE_TYPE_NONE)
// Create and add image view for badge icon. AddChildView(std::make_unique<BadgeView>(badge_type));
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));
}
SetPreferredSize( SetPreferredSize(
gfx::Size(kBadgedProfilePhotoWidth, kBadgedProfilePhotoHeight)); 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