Commit f531fef0 authored by Jan Krcal's avatar Jan Krcal Committed by Commit Bot

[User menu] Make the profile title and edit button white on dark bg

This CL flips UI elements on top of dark colored background in the user
menu to white color so that these elements are readable.

Bug: 1099286
Change-Id: I481c96b6cf566a31d418d24a13a5985fc95e5fb3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2289974
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#787525}
parent 61212de9
...@@ -144,11 +144,16 @@ const gfx::ImageSkia ImageForMenu(const gfx::VectorIcon& icon, ...@@ -144,11 +144,16 @@ const gfx::ImageSkia ImageForMenu(const gfx::VectorIcon& icon,
class CircularImageButton : public views::ImageButton { class CircularImageButton : public views::ImageButton {
public: public:
CircularImageButton(views::ButtonListener* listener, CircularImageButton(
const gfx::VectorIcon& icon, views::ButtonListener* listener,
const base::string16& text, const gfx::VectorIcon& icon,
bool show_border = false) const base::string16& text,
: ImageButton(listener), icon_(icon), show_border_(show_border) { SkColor background_color_for_contrast = SK_ColorTRANSPARENT,
bool show_border = false)
: ImageButton(listener),
icon_(icon),
background_color_for_contrast_(background_color_for_contrast),
show_border_(show_border) {
SetTooltipText(text); SetTooltipText(text);
SetInkDropMode(views::Button::InkDropMode::ON); SetInkDropMode(views::Button::InkDropMode::ON);
SetFocusForPlatform(); SetFocusForPlatform();
...@@ -163,8 +168,15 @@ class CircularImageButton : public views::ImageButton { ...@@ -163,8 +168,15 @@ class CircularImageButton : public views::ImageButton {
const int kBorderThickness = show_border_ ? 1 : 0; const int kBorderThickness = show_border_ ? 1 : 0;
const SkScalar kButtonRadius = const SkScalar kButtonRadius =
(kCircularImageButtonSize + 2 * kBorderThickness) / 2.0f; (kCircularImageButtonSize + 2 * kBorderThickness) / 2.0f;
const SkColor icon_color = GetNativeTheme()->GetSystemColor(
SkColor icon_color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DefaultIconColor); ui::NativeTheme::kColorId_DefaultIconColor);
if (background_color_for_contrast_ != SK_ColorTRANSPARENT) {
// Adjust |icon_color| to assure high enough contrast with the bg.
icon_color = color_utils::BlendForMinContrast(
icon_color, background_color_for_contrast_)
.color;
}
gfx::ImageSkia image = gfx::ImageSkia image =
ImageForMenu(icon_, kShortcutIconToImageRatio, icon_color); ImageForMenu(icon_, kShortcutIconToImageRatio, icon_color);
...@@ -182,6 +194,7 @@ class CircularImageButton : public views::ImageButton { ...@@ -182,6 +194,7 @@ class CircularImageButton : public views::ImageButton {
private: private:
const gfx::VectorIcon& icon_; const gfx::VectorIcon& icon_;
const SkColor background_color_for_contrast_;
bool show_border_; bool show_border_;
}; };
...@@ -549,8 +562,6 @@ void ProfileMenuViewBase::SetProfileIdentityInfo( ...@@ -549,8 +562,6 @@ void ProfileMenuViewBase::SetProfileIdentityInfo(
const ui::ThemeProvider* theme_provider = const ui::ThemeProvider* theme_provider =
anchor_button_->GetThemeProvider(); anchor_button_->GetThemeProvider();
DCHECK(theme_provider); DCHECK(theme_provider);
// TODO(crbug.com/1099286): Make the |heading_label| and |edit_button| have
// good contrast against |background_color|.
background_color = background_color =
theme_provider->GetColor(ThemeProperties::COLOR_FRAME_ACTIVE); theme_provider->GetColor(ThemeProperties::COLOR_FRAME_ACTIVE);
} }
...@@ -564,13 +575,19 @@ void ProfileMenuViewBase::SetProfileIdentityInfo( ...@@ -564,13 +575,19 @@ void ProfileMenuViewBase::SetProfileIdentityInfo(
heading_label = std::make_unique<views::Label>(profile_name, font); heading_label = std::make_unique<views::Label>(profile_name, font);
heading_label->SetElideBehavior(gfx::ELIDE_TAIL); heading_label->SetElideBehavior(gfx::ELIDE_TAIL);
heading_label->SetHorizontalAlignment(gfx::ALIGN_CENTER); heading_label->SetHorizontalAlignment(gfx::ALIGN_CENTER);
if (background_color) {
// This only informs the label about the color it is put on so that it can
// assure minimum contrast automatically.
heading_label->SetBackgroundColor(*background_color);
}
} }
std::unique_ptr<views::View> edit_button; std::unique_ptr<views::View> edit_button;
if (edit_button_params.has_value()) { if (edit_button_params.has_value()) {
edit_button = std::make_unique<CircularImageButton>( edit_button = std::make_unique<CircularImageButton>(
this, *edit_button_params->edit_icon, this, *edit_button_params->edit_icon,
edit_button_params->edit_tooltip_text); edit_button_params->edit_tooltip_text,
background_color.value_or(SK_ColorTRANSPARENT));
RegisterClickAction(edit_button.get(), edit_button_params->edit_action); RegisterClickAction(edit_button.get(), edit_button_params->edit_action);
} }
...@@ -669,6 +686,7 @@ void ProfileMenuViewBase::AddShortcutFeatureButton( ...@@ -669,6 +686,7 @@ void ProfileMenuViewBase::AddShortcutFeatureButton(
views::Button* button = shortcut_features_container_->AddChildView( views::Button* button = shortcut_features_container_->AddChildView(
std::make_unique<CircularImageButton>(this, icon, text, std::make_unique<CircularImageButton>(this, icon, text,
SK_ColorTRANSPARENT,
/*show_border=*/true)); /*show_border=*/true));
button->EnableCanvasFlippingForRTLUI(false); button->EnableCanvasFlippingForRTLUI(false);
......
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