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

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

Issue 2319313003: views: refactor away PlatformStyle::BackgroundColorForMdButton (Closed)
Patch Set: nits and rename Created 4 years, 3 months 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/native_theme/common_theme.cc » ('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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 SkColorGetG(background) * b_weight) / 255.0; 277 SkColorGetG(background) * b_weight) / 255.0;
278 double b = (SkColorGetB(foreground) * f_weight + 278 double b = (SkColorGetB(foreground) * f_weight +
279 SkColorGetB(background) * b_weight) / 255.0; 279 SkColorGetB(background) * b_weight) / 255.0;
280 280
281 return SkColorSetARGB(static_cast<int>(std::round(normalizer)), 281 return SkColorSetARGB(static_cast<int>(std::round(normalizer)),
282 static_cast<int>(std::round(r)), 282 static_cast<int>(std::round(r)),
283 static_cast<int>(std::round(g)), 283 static_cast<int>(std::round(g)),
284 static_cast<int>(std::round(b))); 284 static_cast<int>(std::round(b)));
285 } 285 }
286 286
287 SkColor GetResultingPaintColor(SkColor foreground, SkColor background) {
288 return AlphaBlend(SkColorSetA(foreground, SK_AlphaOPAQUE), background,
289 SkColorGetA(foreground));
290 }
291
287 bool IsDark(SkColor color) { 292 bool IsDark(SkColor color) {
288 return GetLuma(color) < 128; 293 return GetLuma(color) < 128;
289 } 294 }
290 295
291 SkColor BlendTowardOppositeLuma(SkColor color, SkAlpha alpha) { 296 SkColor BlendTowardOppositeLuma(SkColor color, SkAlpha alpha) {
292 return AlphaBlend(IsDark(color) ? SK_ColorWHITE : SK_ColorBLACK, color, 297 return AlphaBlend(IsDark(color) ? SK_ColorWHITE : SK_ColorBLACK, color,
293 alpha); 298 alpha);
294 } 299 }
295 300
296 SkColor GetReadableColor(SkColor foreground, SkColor background) { 301 SkColor GetReadableColor(SkColor foreground, SkColor background) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // For black text, this comes out to kChromeIconGrey. 341 // For black text, this comes out to kChromeIconGrey.
337 return color_utils::AlphaBlend(SK_ColorWHITE, text_color, 342 return color_utils::AlphaBlend(SK_ColorWHITE, text_color,
338 SkColorGetR(gfx::kChromeIconGrey)); 343 SkColorGetR(gfx::kChromeIconGrey));
339 } 344 }
340 // For a light color, just reduce opacity. 345 // For a light color, just reduce opacity.
341 return SkColorSetA(text_color, 346 return SkColorSetA(text_color,
342 static_cast<int>(0.8f * SkColorGetA(text_color))); 347 static_cast<int>(0.8f * SkColorGetA(text_color)));
343 } 348 }
344 349
345 } // namespace color_utils 350 } // namespace color_utils
OLDNEW
« no previous file with comments | « ui/gfx/color_utils.h ('k') | ui/native_theme/common_theme.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698