Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: ui/gfx/color_utils.cc

Issue 1448433004: [MD] update EV bubble icon and location bar https icons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build.gn Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/color_utils.h ('k') | ui/gfx/vector_icons/location_bar_https_invalid_invert.icon » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/color_utils.h" 5 #include "ui/gfx/color_utils.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include <windows.h> 9 #include <windows.h>
10 #endif 10 #endif
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 SkColorGetG(background) * b_weight) / 255.0; 284 SkColorGetG(background) * b_weight) / 255.0;
285 double b = (SkColorGetB(foreground) * f_weight + 285 double b = (SkColorGetB(foreground) * f_weight +
286 SkColorGetB(background) * b_weight) / 255.0; 286 SkColorGetB(background) * b_weight) / 255.0;
287 287
288 return SkColorSetARGB(static_cast<int>(normalizer), 288 return SkColorSetARGB(static_cast<int>(normalizer),
289 static_cast<int>(r), 289 static_cast<int>(r),
290 static_cast<int>(g), 290 static_cast<int>(g),
291 static_cast<int>(b)); 291 static_cast<int>(b));
292 } 292 }
293 293
294 bool IsDark(SkColor color) {
295 return GetLuminanceForColor(color) < 128;
296 }
297
294 SkColor BlendTowardOppositeLuminance(SkColor color, SkAlpha alpha) { 298 SkColor BlendTowardOppositeLuminance(SkColor color, SkAlpha alpha) {
295 unsigned char background_luminance = 299 return AlphaBlend(IsDark(color) ? SK_ColorWHITE : SK_ColorBLACK, color,
296 color_utils::GetLuminanceForColor(color); 300 alpha);
297 const SkColor blend_color =
298 (background_luminance < 128) ? SK_ColorWHITE : SK_ColorBLACK;
299 return color_utils::AlphaBlend(blend_color, color, alpha);
300 } 301 }
301 302
302 SkColor GetReadableColor(SkColor foreground, SkColor background) { 303 SkColor GetReadableColor(SkColor foreground, SkColor background) {
303 const SkColor foreground2 = LumaInvertColor(foreground); 304 const SkColor foreground2 = LumaInvertColor(foreground);
304 const double background_luminance = RelativeLuminance(background); 305 const double background_luminance = RelativeLuminance(background);
305 return (ContrastRatio(RelativeLuminance(foreground), background_luminance) >= 306 return (ContrastRatio(RelativeLuminance(foreground), background_luminance) >=
306 ContrastRatio(RelativeLuminance(foreground2), background_luminance)) ? 307 ContrastRatio(RelativeLuminance(foreground2), background_luminance)) ?
307 foreground : foreground2; 308 foreground : foreground2;
308 } 309 }
309 310
(...skipping 17 matching lines...) Expand all
327 // OS_WIN implementation lives in sys_color_change_listener.cc 328 // OS_WIN implementation lives in sys_color_change_listener.cc
328 #if !defined(OS_WIN) 329 #if !defined(OS_WIN)
329 bool IsInvertedColorScheme() { 330 bool IsInvertedColorScheme() {
330 return false; 331 return false;
331 } 332 }
332 #endif // !defined(OS_WIN) 333 #endif // !defined(OS_WIN)
333 334
334 SkColor DeriveDefaultIconColor(SkColor text_color) { 335 SkColor DeriveDefaultIconColor(SkColor text_color) {
335 // This function works similarly to BlendTowardOppositeLuminance, but uses a 336 // This function works similarly to BlendTowardOppositeLuminance, but uses a
336 // different blend value for lightening and darkening. 337 // different blend value for lightening and darkening.
337 unsigned char luminance = color_utils::GetLuminanceForColor(text_color); 338 if (IsDark(text_color)) {
338 if (luminance < 128) {
339 // For black text, this comes out to kChromeIconGrey. 339 // For black text, this comes out to kChromeIconGrey.
340 return color_utils::AlphaBlend(SK_ColorWHITE, text_color, 340 return color_utils::AlphaBlend(SK_ColorWHITE, text_color,
341 SkColorGetR(gfx::kChromeIconGrey)); 341 SkColorGetR(gfx::kChromeIconGrey));
342 } 342 }
343 // The dimming is less dramatic when darkening a light color. 343 // The dimming is less dramatic when darkening a light color.
344 return color_utils::AlphaBlend(SK_ColorBLACK, text_color, 0x33); 344 return color_utils::AlphaBlend(SK_ColorBLACK, text_color, 0x33);
345 } 345 }
346 346
347 } // namespace color_utils 347 } // namespace color_utils
OLDNEW
« no previous file with comments | « ui/gfx/color_utils.h ('k') | ui/gfx/vector_icons/location_bar_https_invalid_invert.icon » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698