Commit 665e5d4e authored by Peter Kasting's avatar Peter Kasting Committed by Chromium LUCI CQ

Recolor the default tab favicon based on minimum contrast.

The existing code bases the decision on whether the toolbar button
icons have a custom color, which causes accessibility problems.

Bug: 1153079
Change-Id: I0f9996891a7327ffed3d45b77944fa33481b8b0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2587578
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarCharlene Yan <cyan@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836793}
parent ce65216d
...@@ -22,7 +22,9 @@ ...@@ -22,7 +22,9 @@
#include "ui/gfx/animation/linear_animation.h" #include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/animation/tween.h" #include "ui/gfx/animation/tween.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_analysis.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/favicon_size.h" #include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/scoped_canvas.h" #include "ui/gfx/scoped_canvas.h"
...@@ -432,11 +434,32 @@ void TabIcon::RefreshLayer() { ...@@ -432,11 +434,32 @@ void TabIcon::RefreshLayer() {
} }
gfx::ImageSkia TabIcon::ThemeImage(const gfx::ImageSkia& source) { gfx::ImageSkia TabIcon::ThemeImage(const gfx::ImageSkia& source) {
if (!GetThemeProvider()->HasCustomColor( // Choose between leaving the image as-is or changing to the toolbar button
ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON)) // icon color.
return source; const SkColor original_color =
color_utils::CalculateKMeanColorOfBitmap(*source.bitmap());
return gfx::ImageSkiaOperations::CreateColorMask( const ui::ThemeProvider* tp = GetThemeProvider();
source, const SkColor alternate_color =
GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON)); tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
// Compute the minimum contrast of each color against foreground and
// background tabs (for active windows).
const SkColor active_tab_background =
tp->GetColor(ThemeProperties::COLOR_TAB_BACKGROUND_ACTIVE_FRAME_ACTIVE);
const SkColor inactive_tab_background =
tp->GetColor(ThemeProperties::COLOR_TAB_BACKGROUND_INACTIVE_FRAME_ACTIVE);
const float original_contrast = std::min(
color_utils::GetContrastRatio(original_color, active_tab_background),
color_utils::GetContrastRatio(original_color, inactive_tab_background));
const float alternate_contrast = std::min(
color_utils::GetContrastRatio(alternate_color, active_tab_background),
color_utils::GetContrastRatio(alternate_color, inactive_tab_background));
// Recolor the image if the original has low minimum contrast and recoloring
// will improve it.
return ((original_contrast < color_utils::kMinimumReadableContrastRatio) &&
(alternate_contrast > original_contrast))
? gfx::ImageSkiaOperations::CreateColorMask(source,
alternate_color)
: source;
} }
...@@ -111,8 +111,6 @@ class TabIcon : public views::View, public views::AnimationDelegateViews { ...@@ -111,8 +111,6 @@ class TabIcon : public views::View, public views::AnimationDelegateViews {
// whether a layer can be used. // whether a layer can be used.
void RefreshLayer(); void RefreshLayer();
void UpdateThemedFavicon();
gfx::ImageSkia ThemeImage(const gfx::ImageSkia& source); gfx::ImageSkia ThemeImage(const gfx::ImageSkia& source);
const base::TickClock* clock_; const base::TickClock* clock_;
......
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