Skip to content

Commit

Permalink
Systematize omnibox and custom tab bar colors.
Browse files Browse the repository at this point in the history
This makes tiny changes in light mode.  In dark mode, it results in
using a medium grey instead of light grey for e.g. HTTP "not secure"
mode, and red instead of light grey for e.g. HTTPS "bad cert" mode.
Both these parallel how we use colors in light mode and have been
signed off by sereeena@.

Bug: 1061127
Change-Id: I1b822ec27a7fadcfb39b663e404943aaa879c5db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2728515
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#859146}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Mar 2, 2021
1 parent 3d884a4 commit ded9aea
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 104 deletions.
30 changes: 7 additions & 23 deletions chrome/browser/themes/theme_helper.cc
Expand Up @@ -77,23 +77,6 @@ const std::array<SkColor, 2> GetTabGroupColors(int color_id) {
}
}

// Translate the relevant ThemeProperty color ids to SecurityChipColorIds so
// that the security chip color implementation can be shared between NativeTheme
// and ThemeProvider.
ui::NativeTheme::SecurityChipColorId GetSecurityChipColorId(int color_id) {
static const base::NoDestructor<
base::flat_map<int, ui::NativeTheme::SecurityChipColorId>>
color_id_map({
{TP::COLOR_OMNIBOX_SECURITY_CHIP_DEFAULT,
ui::NativeTheme::SecurityChipColorId::DEFAULT},
{TP::COLOR_OMNIBOX_SECURITY_CHIP_SECURE,
ui::NativeTheme::SecurityChipColorId::SECURE},
{TP::COLOR_OMNIBOX_SECURITY_CHIP_DANGEROUS,
ui::NativeTheme::SecurityChipColorId::DANGEROUS},
});
return color_id_map->at(color_id);
}

SkColor IncreaseLightness(SkColor color, double percent) {
color_utils::HSL result;
color_utils::SkColorToHSL(color, &result);
Expand Down Expand Up @@ -684,12 +667,13 @@ base::Optional<ThemeHelper::OmniboxColor> ThemeHelper::GetOmniboxColorImpl(
return blend_toward_max_contrast(bg, gfx::kGoogleGreyAlpha400);
case TP::COLOR_OMNIBOX_SECURITY_CHIP_DEFAULT:
case TP::COLOR_OMNIBOX_SECURITY_CHIP_SECURE:
case TP::COLOR_OMNIBOX_SECURITY_CHIP_DANGEROUS: {
return {
{ui::GetSecurityChipColor(GetSecurityChipColorId(id), fg.value,
bg_hovered_color().value, high_contrast),
fg.custom || (!dark && bg.custom)}};
}
return blend_for_min_contrast(
{dark ? gfx::kGoogleGrey500 : gfx::kGoogleGrey700, false},
bg_hovered_color());
case TP::COLOR_OMNIBOX_SECURITY_CHIP_DANGEROUS:
return blend_for_min_contrast(
{dark ? gfx::kGoogleRed300 : gfx::kGoogleRed600, false},
bg_hovered_color());
default:
return base::nullopt;
}
Expand Down
79 changes: 14 additions & 65 deletions ui/native_theme/common_theme.cc
Expand Up @@ -28,23 +28,6 @@ namespace ui {

namespace {

NativeTheme::SecurityChipColorId GetSecurityChipColorId(
NativeTheme::ColorId color_id) {
static constexpr const auto color_id_map =
base::MakeFixedFlatMap<NativeTheme::ColorId,
NativeTheme::SecurityChipColorId>({
{NativeTheme::kColorId_CustomTabBarSecurityChipDefaultColor,
NativeTheme::SecurityChipColorId::DEFAULT},
{NativeTheme::kColorId_CustomTabBarSecurityChipSecureColor,
NativeTheme::SecurityChipColorId::SECURE},
{NativeTheme::kColorId_CustomTabBarSecurityChipWithCertColor,
NativeTheme::SecurityChipColorId::SECURE_WITH_CERT},
{NativeTheme::kColorId_CustomTabBarSecurityChipDangerousColor,
NativeTheme::SecurityChipColorId::DANGEROUS},
});
return color_id_map.at(color_id);
}

base::Optional<SkColor> GetHighContrastColor(
NativeTheme::ColorId color_id,
NativeTheme::ColorScheme color_scheme) {
Expand Down Expand Up @@ -85,10 +68,6 @@ base::Optional<SkColor> GetDarkSchemeColor(NativeTheme::ColorId color_id) {
case NativeTheme::kColorId_ProminentButtonColor:
return gfx::kGoogleBlue300;

// Custom tab bar
case NativeTheme::kColorId_CustomTabBarBackgroundColor:
return gfx::kGoogleGrey900;

// Frame
case NativeTheme::kColorId_CustomFrameActiveColor:
return gfx::kGoogleGrey900;
Expand Down Expand Up @@ -217,21 +196,24 @@ SkColor GetDefaultColor(NativeTheme::ColorId color_id,
return gfx::kGoogleBlue600;

// Custom tab bar
case NativeTheme::kColorId_CustomTabBarBackgroundColor:
return SK_ColorWHITE;
case NativeTheme::kColorId_CustomTabBarBackgroundColor: {
const SkColor fg = base_theme->GetSystemColor(
NativeTheme::kColorId_CustomTabBarForegroundColor, color_scheme);
return color_utils::GetColorWithMaxContrast(fg);
}
case NativeTheme::kColorId_CustomTabBarForegroundColor:
return color_utils::GetColorWithMaxContrast(base_theme->GetSystemColor(
NativeTheme::kColorId_CustomTabBarBackgroundColor, color_scheme));
return base_theme->GetSystemColor(
NativeTheme::kColorId_LabelTextSelectionColor, color_scheme);
case NativeTheme::kColorId_CustomTabBarSecurityChipWithCertColor:
return base_theme->GetSystemColor(
NativeTheme::kColorId_LabelDisabledColor, color_scheme);
case NativeTheme::kColorId_CustomTabBarSecurityChipSecureColor:
case NativeTheme::kColorId_CustomTabBarSecurityChipDefaultColor:
case NativeTheme::kColorId_CustomTabBarSecurityChipDangerousColor: {
const SkColor fg = base_theme->GetSystemColor(
NativeTheme::kColorId_CustomTabBarForegroundColor, color_scheme);
const SkColor bg = base_theme->GetSystemColor(
NativeTheme::kColorId_CustomTabBarBackgroundColor, color_scheme);
return GetSecurityChipColor(GetSecurityChipColorId(color_id), fg, bg);
}
return base_theme->GetSystemColor(
NativeTheme::kColorId_LabelSecondaryColor, color_scheme);
case NativeTheme::kColorId_CustomTabBarSecurityChipDangerousColor:
return base_theme->GetSystemColor(NativeTheme::kColorId_AlertSeverityHigh,
color_scheme);

// Dialog
case NativeTheme::kColorId_DialogBackground:
Expand Down Expand Up @@ -540,39 +522,6 @@ SkColor GetDefaultColor(NativeTheme::ColorId color_id,

} // namespace

SkColor GetSecurityChipColor(NativeTheme::SecurityChipColorId chip_color_id,
SkColor fg,
SkColor bg,
bool high_contrast) {
const bool dark = color_utils::IsDark(bg);
const auto blend_for_min_contrast = [&](SkColor fg, SkColor bg,
base::Optional<SkColor> hc_fg =
base::nullopt) {
const float ratio =
high_contrast ? 6.0f : color_utils::kMinimumReadableContrastRatio;
return color_utils::BlendForMinContrast(fg, bg, hc_fg, ratio).color;
};
const auto security_chip_color = [&](SkColor color) {
return blend_for_min_contrast(color, bg);
};

switch (chip_color_id) {
case NativeTheme::SecurityChipColorId::DEFAULT:
case NativeTheme::SecurityChipColorId::SECURE:
return dark
? color_utils::BlendTowardMaxContrast(fg, 0x18)
: security_chip_color(color_utils::DeriveDefaultIconColor(fg));
case NativeTheme::SecurityChipColorId::DANGEROUS:
return dark ? color_utils::BlendTowardMaxContrast(fg, 0x18)
: security_chip_color(gfx::kGoogleRed600);
case NativeTheme::SecurityChipColorId::SECURE_WITH_CERT:
return blend_for_min_contrast(fg, fg, blend_for_min_contrast(bg, bg));
default:
NOTREACHED();
return gfx::kPlaceholderColor;
}
}

SkColor GetAlertSeverityColor(NativeTheme::ColorId color_id, bool dark) {
constexpr auto kColorIdMap =
base::MakeFixedFlatMap<NativeTheme::ColorId, std::array<SkColor, 2>>({
Expand Down
8 changes: 0 additions & 8 deletions ui/native_theme/common_theme.h
Expand Up @@ -14,14 +14,6 @@ namespace ui {

// Drawing code that is common for all platforms.

// Takes a SecurityChipColorId and |fg| and |bg| colors so that the security
// chip color implementation can be shared outside of NativeTheme.
SkColor NATIVE_THEME_EXPORT
GetSecurityChipColor(NativeTheme::SecurityChipColorId chip_color_id,
SkColor fg,
SkColor bg,
bool high_contrast = false);

// Gets the appropriate alert severity color for light / dark mode.
// TODO(tluk): Create unique color ids for each use of the alert severity colors
// and update this function to take the background color over which the alert
Expand Down
8 changes: 0 additions & 8 deletions ui/native_theme/native_theme.h
Expand Up @@ -147,14 +147,6 @@ class NATIVE_THEME_EXPORT NativeTheme {
// Win)
};

// This enum represents the available unique security chip color states.
enum class SecurityChipColorId {
DEFAULT,
SECURE,
SECURE_WITH_CERT,
DANGEROUS,
};

// Each structure below holds extra information needed when painting a given
// part.

Expand Down

0 comments on commit ded9aea

Please sign in to comment.