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:
gfx::ImageSkia ImageForBadgeType(BadgedProfilePhoto::BadgeType badge_type) { explicit BadgeView(BadgedProfilePhoto::BadgeType badge_type)
ui::NativeTheme* native_theme = ui::NativeTheme::GetInstanceForNativeUi(); : badge_type_(badge_type) {
switch (badge_type) { SizeToPreferredSize();
case BadgedProfilePhoto::BADGE_TYPE_SUPERVISOR: SetPosition(gfx::Point(kBadgedProfilePhotoWidth - kBadgeIconSize,
return gfx::CreateVectorIcon( kBadgedProfilePhotoHeight - kBadgeIconSize));
kSupervisorAccountCircleIcon, kBadgeIconSize, }
native_theme->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor)); // views::View
case BadgedProfilePhoto::BADGE_TYPE_CHILD: void OnThemeChanged() override {
return gfx::CreateVectorIcon( switch (badge_type_) {
kAccountChildCircleIcon, kBadgeIconSize, case BadgedProfilePhoto::BADGE_TYPE_SUPERVISOR:
native_theme->GetSystemColor( SetImage(gfx::CreateVectorIcon(
ui::NativeTheme::kColorId_DefaultIconColor)); kSupervisorAccountCircleIcon, kBadgeIconSize,
case BadgedProfilePhoto::BADGE_TYPE_SYNC_COMPLETE: GetNativeTheme()->GetSystemColor(
return gfx::CreateVectorIcon( ui::NativeTheme::kColorId_DefaultIconColor)));
kSyncCircleIcon, kBadgeIconSize, break;
native_theme->GetSystemColor( case BadgedProfilePhoto::BADGE_TYPE_CHILD:
ui::NativeTheme::kColorId_AlertSeverityLow)); SetImage(gfx::CreateVectorIcon(
case BadgedProfilePhoto::BADGE_TYPE_SYNC_ERROR: kAccountChildCircleIcon, kBadgeIconSize,
return gfx::CreateVectorIcon( GetNativeTheme()->GetSystemColor(
kSyncErrorCircleIcon, kBadgeIconSize, ui::NativeTheme::kColorId_DefaultIconColor)));
native_theme->GetSystemColor( break;
ui::NativeTheme::kColorId_AlertSeverityHigh)); case BadgedProfilePhoto::BADGE_TYPE_SYNC_COMPLETE:
case BadgedProfilePhoto::BADGE_TYPE_SYNC_PAUSED: SetImage(gfx::CreateVectorIcon(
return gfx::CreateVectorIcon( kSyncCircleIcon, kBadgeIconSize,
kSyncPausedCircleIcon, kBadgeIconSize, GetNativeTheme()->GetSystemColor(
native_theme->GetSystemColor( ui::NativeTheme::kColorId_AlertSeverityLow)));
ui::NativeTheme::kColorId_ProminentButtonColor)); break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_DISABLED: case BadgedProfilePhoto::BADGE_TYPE_SYNC_ERROR:
return gfx::CreateVectorIcon(kSyncCircleIcon, kBadgeIconSize, SetImage(gfx::CreateVectorIcon(
gfx::kGoogleGrey400); kSyncErrorCircleIcon, kBadgeIconSize,
case BadgedProfilePhoto::BADGE_TYPE_SYNC_OFF: GetNativeTheme()->GetSystemColor(
return gfx::CreateVectorIcon(kSyncPausedCircleIcon, kBadgeIconSize, ui::NativeTheme::kColorId_AlertSeverityHigh)));
gfx::kGoogleGrey600); break;
case BadgedProfilePhoto::BADGE_TYPE_NONE: case BadgedProfilePhoto::BADGE_TYPE_SYNC_PAUSED:
NOTREACHED(); SetImage(gfx::CreateVectorIcon(
return gfx::ImageSkia(); kSyncPausedCircleIcon, kBadgeIconSize,
GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_ProminentButtonColor)));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_DISABLED:
SetImage(gfx::CreateVectorIcon(kSyncCircleIcon, kBadgeIconSize,
gfx::kGoogleGrey400));
break;
case BadgedProfilePhoto::BADGE_TYPE_SYNC_OFF:
SetImage(gfx::CreateVectorIcon(kSyncPausedCircleIcon, kBadgeIconSize,
gfx::kGoogleGrey600));
break;
case BadgedProfilePhoto::BADGE_TYPE_NONE:
NOTREACHED();
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