Skip to content

Commit

Permalink
Remove the majority of uses of GetLuma().
Browse files Browse the repository at this point in the history
Typically this is to determine a contrasting color or to distinguish light/dark.
There are better fucntions for these purposes.

Bug: 659451
Change-Id: Iad770610ef6b93c75c880badcc2ac9784c74ac12
Reviewed-on: https://chromium-review.googlesource.com/c/1401428
Reviewed-by: Ben Wells <benwells@chromium.org>
Reviewed-by: Michael Wasserman <msw@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#621161}
  • Loading branch information
pkasting authored and Commit Bot committed Jan 9, 2019
1 parent 63b7be7 commit b029e67
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
9 changes: 3 additions & 6 deletions apps/ui/views/app_window_frame_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,10 @@ SkColor AppWindowFrameView::CurrentFrameColor() {
void AppWindowFrameView::SetButtonImagesForFrame() {
DCHECK(draw_frame_);

// If the frame is dark, we should use the light images so they have
// some contrast.
const uint8_t kLumaThreshold = 100;
bool use_light = color_utils::GetLuma(CurrentFrameColor()) < kLumaThreshold;

// If the frame is dark, we should use the light images so they have some
// contrast.
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
if (use_light) {
if (color_utils::IsDark(CurrentFrameColor())) {
maximize_button_->SetImage(
views::Button::STATE_NORMAL,
rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_L).ToImageSkia());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class GeneratedIconImageSource : public gfx::CanvasImageSource {
private:
// gfx::CanvasImageSource overrides:
void Draw(gfx::Canvas* canvas) override {
const uint8_t kLumaThreshold = 190;
const int icon_size = output_size_ * 3 / 4;
const int icon_inset = output_size_ / 8;
const size_t border_radius = output_size_ / 16;
Expand All @@ -64,13 +63,10 @@ class GeneratedIconImageSource : public gfx::CanvasImageSource {

// The text rect's size needs to be odd to center the text correctly.
gfx::Rect text_rect(icon_inset, icon_inset, icon_size + 1, icon_size + 1);
// Draw the letter onto the rounded rect. The letter's color depends on the
// luma of |color|.
const uint8_t luma = color_utils::GetLuma(color_);
canvas->DrawStringRectWithFlags(
base::string16(1, std::toupper(letter_)),
gfx::FontList(gfx::Font(font_name, font_size)),
(luma > kLumaThreshold) ? SK_ColorBLACK : SK_ColorWHITE, text_rect,
color_utils::GetColorWithMaxContrast(color_), text_rect,
gfx::Canvas::TEXT_ALIGN_CENTER);
}

Expand Down
14 changes: 7 additions & 7 deletions ui/gfx/sys_color_change_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ bool g_is_inverted_color_scheme = false;
bool g_is_inverted_color_scheme_initialized = false;

void UpdateInvertedColorScheme() {
const uint8_t foreground_luma =
color_utils::GetLuma(color_utils::GetSysSkColor(COLOR_WINDOWTEXT));
const uint8_t background_luma =
color_utils::GetLuma(color_utils::GetSysSkColor(COLOR_WINDOW));
HIGHCONTRAST high_contrast = {0};
high_contrast.cbSize = sizeof(HIGHCONTRAST);
g_is_inverted_color_scheme =
const bool is_high_contrast =
SystemParametersInfo(SPI_GETHIGHCONTRAST, 0, &high_contrast, 0) &&
((high_contrast.dwFlags & HCF_HIGHCONTRASTON) != 0) &&
foreground_luma > background_luma;
((high_contrast.dwFlags & HCF_HIGHCONTRASTON) != 0);
g_is_inverted_color_scheme =
is_high_contrast && (color_utils::GetRelativeLuminance(
color_utils::GetSysSkColor(COLOR_WINDOWTEXT)) >
color_utils::GetRelativeLuminance(
color_utils::GetSysSkColor(COLOR_WINDOW)));
g_is_inverted_color_scheme_initialized = true;
}

Expand Down

0 comments on commit b029e67

Please sign in to comment.