Commit 52defab7 authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] Use profile colors in profile menu and interception bubble

Screenshot:
https://screenshot.googleplex.com/UaY0XVo8r6B.png
With dark background:
https://screenshot.googleplex.com/zkCm5YkgnpS.png

Bug: 1076880, 1099286
Change-Id: I5255ce9f25d88c19b7d24cb684f574cc544cb63f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2328854Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarAlex Ilin <alexilin@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Auto-Submit: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794539}
parent f95893f1
...@@ -1153,6 +1153,8 @@ static_library("ui") { ...@@ -1153,6 +1153,8 @@ static_library("ui") {
"serial/serial_chooser.h", "serial/serial_chooser.h",
"serial/serial_chooser_controller.cc", "serial/serial_chooser_controller.cc",
"serial/serial_chooser_controller.h", "serial/serial_chooser_controller.h",
"signin/profile_colors_util.cc",
"signin/profile_colors_util.h",
"singleton_tabs.cc", "singleton_tabs.cc",
"singleton_tabs.h", "singleton_tabs.h",
"startup/automation_infobar_delegate.cc", "startup/automation_infobar_delegate.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/signin/profile_colors_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "ui/gfx/color_utils.h"
ProfileThemeColors GetThemeColorsForProfile(Profile* profile) {
DCHECK(profile->IsRegularProfile());
ProfileAttributesEntry* entry = nullptr;
g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile->GetPath(), &entry);
DCHECK(entry);
return entry->GetProfileThemeColors();
}
SkColor GetProfileForegroundTextColor(SkColor profile_highlight_color) {
return color_utils::GetColorWithMaxContrast(profile_highlight_color);
}
SkColor GetProfileForegroundIconColor(SkColor profile_highlight_color) {
SkColor text_color = GetProfileForegroundTextColor(profile_highlight_color);
SkColor icon_color = color_utils::DeriveDefaultIconColor(text_color);
return color_utils::BlendForMinContrast(icon_color, profile_highlight_color,
text_color)
.color;
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_SIGNIN_PROFILE_COLORS_UTIL_H_
#define CHROME_BROWSER_UI_SIGNIN_PROFILE_COLORS_UTIL_H_
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "third_party/skia/include/core/SkColor.h"
class Profile;
// Gets the profile theme colors associated with a profile. Does not support
// incognito or guest profiles.
ProfileThemeColors GetThemeColorsForProfile(Profile* profile);
// Returns the color that should be used to display text over the profile
// highlight color.
SkColor GetProfileForegroundTextColor(SkColor profile_highlight_color);
// Returns the color that should be used to display icons over the profile
// highlight color.
SkColor GetProfileForegroundIconColor(SkColor profile_highlight_color);
#endif // CHROME_BROWSER_UI_SIGNIN_PROFILE_COLORS_UTIL_H_
...@@ -46,7 +46,9 @@ void IncognitoMenuView::BuildMenu() { ...@@ -46,7 +46,9 @@ void IncognitoMenuView::BuildMenu() {
browser()->profile()); browser()->profile());
SetProfileIdentityInfo( SetProfileIdentityInfo(
/*profile_name=*/base::string16(), /*edit_button=*/base::nullopt, /*profile_name=*/base::string16(),
/*background_color=*/SK_ColorTRANSPARENT,
/*edit_button=*/base::nullopt,
ui::ImageModel::FromVectorIcon( ui::ImageModel::FromVectorIcon(
kIncognitoProfileIcon, ui::NativeTheme::kColorId_BubbleForeground), kIncognitoProfileIcon, ui::NativeTheme::kColorId_BubbleForeground),
l10n_util::GetStringUTF16(IDS_INCOGNITO_PROFILE_MENU_TITLE), l10n_util::GetStringUTF16(IDS_INCOGNITO_PROFILE_MENU_TITLE),
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator_params.h" #include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
#include "chrome/browser/ui/signin/profile_colors_util.h"
#include "chrome/browser/ui/sync/sync_promo_ui.h" #include "chrome/browser/ui/sync/sync_promo_ui.h"
#include "chrome/browser/ui/ui_features.h" #include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/accessibility/non_accessible_image_view.h" #include "chrome/browser/ui/views/accessibility/non_accessible_image_view.h"
...@@ -456,9 +457,11 @@ void ProfileMenuView::BuildIdentity() { ...@@ -456,9 +457,11 @@ void ProfileMenuView::BuildIdentity() {
} }
#endif #endif
SkColor background_color =
GetThemeColorsForProfile(profile).profile_highlight_color;
if (account_info.has_value()) { if (account_info.has_value()) {
SetProfileIdentityInfo( SetProfileIdentityInfo(
profile_name, edit_button_params, profile_name, background_color, edit_button_params,
ui::ImageModel::FromImage(account_info.value().account_image), ui::ImageModel::FromImage(account_info.value().account_image),
base::UTF8ToUTF16(account_info.value().full_name), base::UTF8ToUTF16(account_info.value().full_name),
IsSyncPaused(profile) IsSyncPaused(profile)
...@@ -466,7 +469,7 @@ void ProfileMenuView::BuildIdentity() { ...@@ -466,7 +469,7 @@ void ProfileMenuView::BuildIdentity() {
: base::UTF8ToUTF16(account_info.value().email)); : base::UTF8ToUTF16(account_info.value().email));
} else { } else {
SetProfileIdentityInfo( SetProfileIdentityInfo(
profile_name, edit_button_params, profile_name, background_color, edit_button_params,
ui::ImageModel::FromImage(profile_attributes->GetAvatarIcon()), ui::ImageModel::FromImage(profile_attributes->GetAvatarIcon()),
/*title=*/base::string16(), /*title=*/base::string16(),
l10n_util::GetStringUTF16(IDS_PROFILES_LOCAL_PROFILE_STATE)); l10n_util::GetStringUTF16(IDS_PROFILES_LOCAL_PROFILE_STATE));
...@@ -475,6 +478,7 @@ void ProfileMenuView::BuildIdentity() { ...@@ -475,6 +478,7 @@ void ProfileMenuView::BuildIdentity() {
void ProfileMenuView::BuildGuestIdentity() { void ProfileMenuView::BuildGuestIdentity() {
SetProfileIdentityInfo(/*profile_name=*/base::string16(), SetProfileIdentityInfo(/*profile_name=*/base::string16(),
/*background_color=*/SK_ColorTRANSPARENT,
/*edit_button=*/base::nullopt, /*edit_button=*/base::nullopt,
profiles::GetGuestAvatar(), profiles::GetGuestAvatar(),
l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME)); l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME));
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chrome/browser/signin/signin_ui_util.h" #include "chrome/browser/signin/signin_ui_util.h"
#include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/signin/profile_colors_util.h"
#include "chrome/browser/ui/ui_features.h" #include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h" #include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h" #include "chrome/browser/ui/views/chrome_typography.h"
...@@ -155,15 +156,14 @@ gfx::ImageSkia SizeImageModel(const ui::ImageModel& image_model, ...@@ -155,15 +156,14 @@ gfx::ImageSkia SizeImageModel(const ui::ImageModel& image_model,
class CircularImageButton : public views::ImageButton { class CircularImageButton : public views::ImageButton {
public: public:
CircularImageButton( CircularImageButton(views::ButtonListener* listener,
views::ButtonListener* listener,
const gfx::VectorIcon& icon, const gfx::VectorIcon& icon,
const base::string16& text, const base::string16& text,
SkColor background_color_for_contrast = SK_ColorTRANSPARENT, SkColor background_profile_color = SK_ColorTRANSPARENT,
bool show_border = false) bool show_border = false)
: ImageButton(listener), : ImageButton(listener),
icon_(icon), icon_(icon),
background_color_for_contrast_(background_color_for_contrast), background_profile_color_(background_profile_color),
show_border_(show_border) { show_border_(show_border) {
SetTooltipText(text); SetTooltipText(text);
SetInkDropMode(views::Button::InkDropMode::ON); SetInkDropMode(views::Button::InkDropMode::ON);
...@@ -182,13 +182,8 @@ class CircularImageButton : public views::ImageButton { ...@@ -182,13 +182,8 @@ class CircularImageButton : public views::ImageButton {
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) { if (background_profile_color_ != SK_ColorTRANSPARENT)
// Adjust |icon_color| to assure high enough contrast with the bg. icon_color = GetProfileForegroundIconColor(background_profile_color_);
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);
SetImage(views::Button::STATE_NORMAL, SetImage(views::Button::STATE_NORMAL,
...@@ -205,7 +200,7 @@ class CircularImageButton : public views::ImageButton { ...@@ -205,7 +200,7 @@ class CircularImageButton : public views::ImageButton {
private: private:
const gfx::VectorIcon& icon_; const gfx::VectorIcon& icon_;
const SkColor background_color_for_contrast_; const SkColor background_profile_color_;
bool show_border_; bool show_border_;
}; };
...@@ -506,6 +501,7 @@ gfx::ImageSkia ProfileMenuViewBase::GetSyncIcon() const { ...@@ -506,6 +501,7 @@ gfx::ImageSkia ProfileMenuViewBase::GetSyncIcon() const {
void ProfileMenuViewBase::SetProfileIdentityInfo( void ProfileMenuViewBase::SetProfileIdentityInfo(
const base::string16& profile_name, const base::string16& profile_name,
SkColor profile_background_color,
base::Optional<EditButtonParams> edit_button_params, base::Optional<EditButtonParams> edit_button_params,
const ui::ImageModel& image_model, const ui::ImageModel& image_model,
const base::string16& title, const base::string16& title,
...@@ -560,13 +556,7 @@ void ProfileMenuViewBase::SetProfileIdentityInfo( ...@@ -560,13 +556,7 @@ void ProfileMenuViewBase::SetProfileIdentityInfo(
// Only show a colored background when there is an edit button (this // Only show a colored background when there is an edit button (this
// coincides with the profile being a real profile that can be edited). // coincides with the profile being a real profile that can be edited).
if (edit_button_params.has_value()) { if (edit_button_params.has_value()) {
// We get the theme provider from the anchor view since our widget hasn't background_color = profile_background_color;
// been created yet.
const ui::ThemeProvider* theme_provider =
anchor_button_->GetThemeProvider();
DCHECK(theme_provider);
background_color =
theme_provider->GetColor(ThemeProperties::COLOR_FRAME_ACTIVE);
} }
std::unique_ptr<views::Label> heading_label; std::unique_ptr<views::Label> heading_label;
...@@ -579,9 +569,9 @@ void ProfileMenuViewBase::SetProfileIdentityInfo( ...@@ -579,9 +569,9 @@ void ProfileMenuViewBase::SetProfileIdentityInfo(
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) { if (background_color) {
// This only informs the label about the color it is put on so that it can heading_label->SetAutoColorReadabilityEnabled(false);
// assure minimum contrast automatically. heading_label->SetEnabledColor(
heading_label->SetBackgroundColor(*background_color); GetProfileForegroundTextColor(*background_color));
} }
} }
......
...@@ -120,6 +120,7 @@ class ProfileMenuViewBase : public content::WebContentsDelegate, ...@@ -120,6 +120,7 @@ class ProfileMenuViewBase : public content::WebContentsDelegate,
// If |profile_name| is empty, no heading will be displayed. // If |profile_name| is empty, no heading will be displayed.
void SetProfileIdentityInfo( void SetProfileIdentityInfo(
const base::string16& profile_name, const base::string16& profile_name,
SkColor profile_background_color,
base::Optional<EditButtonParams> edit_button_params, base::Optional<EditButtonParams> edit_button_params,
const ui::ImageModel& image_model, const ui::ImageModel& image_model,
const base::string16& title, const base::string16& title,
......
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#include "chrome/browser/ui/webui/signin/dice_web_signin_intercept_ui.h" #include "chrome/browser/ui/webui/signin/dice_web_signin_intercept_ui.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h" #include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/ui/signin/profile_colors_util.h"
#include "chrome/browser/ui/webui/signin/dice_web_signin_intercept_handler.h" #include "chrome/browser/ui/webui/signin/dice_web_signin_intercept_handler.h"
#include "chrome/browser/ui/webui/webui_util.h" #include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
...@@ -33,14 +35,14 @@ DiceWebSigninInterceptUI::DiceWebSigninInterceptUI(content::WebUI* web_ui) ...@@ -33,14 +35,14 @@ DiceWebSigninInterceptUI::DiceWebSigninInterceptUI(content::WebUI* web_ui)
source->AddResourcePath("signin_shared_css.js", IDR_SIGNIN_SHARED_CSS_JS); source->AddResourcePath("signin_shared_css.js", IDR_SIGNIN_SHARED_CSS_JS);
source->AddResourcePath("signin_vars_css.js", IDR_SIGNIN_VARS_CSS_JS); source->AddResourcePath("signin_vars_css.js", IDR_SIGNIN_VARS_CSS_JS);
// TODO(droger): Use the color from the profile. Profile* profile = Profile::FromWebUI(web_ui);
SkColor header_background_color = SkColorSetRGB(206, 234, 214); SkColor background_color =
SkColor header_text_color = GetThemeColorsForProfile(profile).profile_highlight_color;
color_utils::GetColorWithMaxContrast(header_background_color);
source->AddString("headerBackgroundColor", source->AddString("headerBackgroundColor",
color_utils::SkColorToRgbaString(header_background_color)); color_utils::SkColorToRgbaString(background_color));
source->AddString("headerTextColor", source->AddString("headerTextColor",
color_utils::SkColorToRgbaString(header_text_color)); color_utils::SkColorToRgbaString(
GetProfileForegroundTextColor(background_color)));
// Localized strings. // Localized strings.
source->UseStringsJs(); source->UseStringsJs();
...@@ -64,7 +66,7 @@ DiceWebSigninInterceptUI::DiceWebSigninInterceptUI(content::WebUI* web_ui) ...@@ -64,7 +66,7 @@ DiceWebSigninInterceptUI::DiceWebSigninInterceptUI(content::WebUI* web_ui)
source->AddResourcePath("test_loader.js", IDR_WEBUI_JS_TEST_LOADER); source->AddResourcePath("test_loader.js", IDR_WEBUI_JS_TEST_LOADER);
source->AddResourcePath("test_loader.html", IDR_WEBUI_HTML_TEST_LOADER); source->AddResourcePath("test_loader.html", IDR_WEBUI_HTML_TEST_LOADER);
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source); content::WebUIDataSource::Add(profile, source);
} }
DiceWebSigninInterceptUI::~DiceWebSigninInterceptUI() = default; DiceWebSigninInterceptUI::~DiceWebSigninInterceptUI() = default;
......
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