OLD | NEW |
---|---|
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 "chrome/browser/themes/theme_service.h" | 5 #include "chrome/browser/themes/theme_service.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 // realize we've installed the default theme, we already have an extension | 70 // realize we've installed the default theme, we already have an extension |
71 // unpacked on the filesystem.) | 71 // unpacked on the filesystem.) |
72 const char kDefaultThemeGalleryID[] = "hkacjpbfdknhflllbcmjibkdeoafencn"; | 72 const char kDefaultThemeGalleryID[] = "hkacjpbfdknhflllbcmjibkdeoafencn"; |
73 | 73 |
74 // Wait this many seconds after startup to garbage collect unused themes. | 74 // Wait this many seconds after startup to garbage collect unused themes. |
75 // Removing unused themes is done after a delay because there is no | 75 // Removing unused themes is done after a delay because there is no |
76 // reason to do it at startup. | 76 // reason to do it at startup. |
77 // ExtensionService::GarbageCollectExtensions() does something similar. | 77 // ExtensionService::GarbageCollectExtensions() does something similar. |
78 const int kRemoveUnusedThemesStartupDelay = 30; | 78 const int kRemoveUnusedThemesStartupDelay = 30; |
79 | 79 |
80 // Computes the "toolbar top separator" color. This color is drawn atop the | |
81 // frame to separate it from tabs, the toolbar, and the new tab button, as well | |
82 // as atop background tabs to separate them from other tabs or the toolbar. We | |
83 // use semitransparent black or white so as to darken or lighten the frame, with | |
84 // the goal of contrasting with both the frame color and the active tab (i.e. | |
85 // toolbar) color. (It's too difficult to try to find colors that will contrast | |
86 // with both of these as well as the background tab color, and contrasting with | |
87 // the foreground tab is the most important). | |
88 SkColor GetSeparatorColor(SkColor tab_color, SkColor frame_color) { | |
89 // We use this alpha value for the separator if possible. | |
90 const SkAlpha kAlpha = 0x40; | |
91 | |
92 // In most cases, if the tab is lighter than the frame, we darken the | |
93 // frame; if the tab is darker than the frame, we lighten the frame. | |
94 // However, if the frame is already very dark or very light, respectively, | |
95 // this won't contrast sufficiently with the frame color, so we'll need to | |
96 // reverse when we're lightening and darkening. | |
97 const double tab_luminance = color_utils::GetRelativeLuminance(tab_color); | |
98 const double frame_luminance = color_utils::GetRelativeLuminance(frame_color); | |
99 const bool lighten = tab_luminance < frame_luminance; | |
100 SkColor separator_color = lighten ? SK_ColorWHITE : SK_ColorBLACK; | |
101 double separator_luminance = color_utils::GetRelativeLuminance( | |
102 color_utils::AlphaBlend(separator_color, frame_color, kAlpha)); | |
103 const double kMinContrastRatio = 1.146484375; | |
Evan Stade
2016/03/14 20:30:05
this value seems very specific... where did it com
Peter Kasting
2016/03/15 01:30:51
I was looking for a value that was as close as pos
Evan Stade
2016/03/15 02:06:42
Can you put a comment to that effect? "This is 0x*
Peter Kasting
2016/03/15 11:49:03
Good idea. Done.
| |
104 if (color_utils::GetContrastRatio(separator_luminance, frame_luminance) >= | |
105 kMinContrastRatio) | |
106 return SkColorSetA(separator_color, kAlpha); | |
107 | |
108 // We need to reverse whether we're darkening or lightening. We know the new | |
109 // separator color will contrast with the frame; check whether it also | |
110 // contrasts at least as well with the tab. | |
111 separator_color = color_utils::InvertColor(separator_color); | |
112 separator_luminance = color_utils::GetRelativeLuminance( | |
113 color_utils::AlphaBlend(separator_color, frame_color, kAlpha)); | |
114 if (color_utils::GetContrastRatio(separator_luminance, tab_luminance) >= | |
115 color_utils::GetContrastRatio(separator_luminance, frame_luminance)) | |
116 return SkColorSetA(separator_color, kAlpha); | |
117 | |
118 // The reversed separator doesn't contrast enough with the tab. Compute the | |
119 // resulting luminance from adjusting the tab color, instead of the frame | |
120 // color, by the separator color. | |
121 const double target_luminance = color_utils::GetRelativeLuminance( | |
122 color_utils::AlphaBlend(separator_color, tab_color, kAlpha)); | |
123 | |
124 // Now try to compute an alpha for the separator such that, when blended with | |
125 // the frame, it results in the above luminance. | |
126 SkAlpha alpha = 128; | |
127 for (int delta = lighten ? 64 : -64; delta != 0; delta /= 2) { | |
Evan Stade
2016/03/14 20:30:05
reusing lighten here seems a little misleading ---
Peter Kasting
2016/03/15 01:30:51
Yes. I waffled on this. I eventually decided tha
Evan Stade
2016/03/15 02:06:42
Yea, I squinted at it for a while but couldn't com
Peter Kasting
2016/03/15 11:49:03
Yeah, it doesn't seem much better to me. I added
| |
128 const double luminance = color_utils::GetRelativeLuminance( | |
129 color_utils::AlphaBlend(separator_color, frame_color, alpha)); | |
130 if (luminance == target_luminance) | |
131 break; | |
132 alpha += (luminance < target_luminance) ? -delta : delta; | |
133 } | |
134 return SkColorSetA(separator_color, alpha); | |
135 } | |
136 | |
80 SkColor IncreaseLightness(SkColor color, double percent) { | 137 SkColor IncreaseLightness(SkColor color, double percent) { |
81 color_utils::HSL result; | 138 color_utils::HSL result; |
82 color_utils::SkColorToHSL(color, &result); | 139 color_utils::SkColorToHSL(color, &result); |
83 result.l += (1 - result.l) * percent; | 140 result.l += (1 - result.l) * percent; |
84 return color_utils::HSLToSkColor(result, SkColorGetA(color)); | 141 return color_utils::HSLToSkColor(result, SkColorGetA(color)); |
85 } | 142 } |
86 | 143 |
87 // Writes the theme pack to disk on a separate thread. | 144 // Writes the theme pack to disk on a separate thread. |
88 void WritePackToDiskCallback(BrowserThemePack* pack, | 145 void WritePackToDiskCallback(BrowserThemePack* pack, |
89 const base::FilePath& path) { | 146 const base::FilePath& path) { |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 switch (id) { | 475 switch (id) { |
419 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON: | 476 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON: |
420 return color_utils::HSLShift( | 477 return color_utils::HSLShift( |
421 gfx::kChromeIconGrey, | 478 gfx::kChromeIconGrey, |
422 GetTint(ThemeProperties::TINT_BUTTONS, incognito)); | 479 GetTint(ThemeProperties::TINT_BUTTONS, incognito)); |
423 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE: | 480 case ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON_INACTIVE: |
424 // The active color is overridden in Gtk2UI. | 481 // The active color is overridden in Gtk2UI. |
425 return SkColorSetA( | 482 return SkColorSetA( |
426 GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON, incognito), | 483 GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON, incognito), |
427 0x33); | 484 0x33); |
485 case ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR: { | |
486 const SkColor tab_color = | |
487 GetColor(ThemeProperties::COLOR_TOOLBAR, incognito); | |
488 const SkColor frame_color = | |
489 GetColor(ThemeProperties::COLOR_FRAME, incognito); | |
490 const SeparatorColorKey key(tab_color, frame_color); | |
491 auto i = separator_color_cache_.find(key); | |
492 if (i != separator_color_cache_.end()) | |
493 return i->second; | |
494 const SkColor separator_color = GetSeparatorColor(tab_color, frame_color); | |
495 separator_color_cache_.insert(std::make_pair(key, separator_color)); | |
Evan Stade
2016/03/14 20:30:05
nit: separator_color_cache_[key] = separator_color
Peter Kasting
2016/03/15 01:30:51
That would work. This way is more efficient since
Evan Stade
2016/03/15 02:06:42
isn't there a lookup phase either way?
Peter Kasting
2016/03/15 11:49:03
You're right. Because I'm not providing a hint, t
| |
496 return separator_color; | |
497 } | |
428 case ThemeProperties::COLOR_BACKGROUND_TAB: { | 498 case ThemeProperties::COLOR_BACKGROUND_TAB: { |
429 // The tints here serve a different purpose than TINT_BACKGROUND_TAB. | 499 // The tints here serve a different purpose than TINT_BACKGROUND_TAB. |
430 // That tint is used to create background tab images for custom themes by | 500 // That tint is used to create background tab images for custom themes by |
431 // lightening the frame images. The tints here create solid colors for | 501 // lightening the frame images. The tints here create solid colors for |
432 // background tabs by darkening the foreground tab (toolbar) color. | 502 // background tabs by darkening the foreground tab (toolbar) color. |
433 const color_utils::HSL kTint = {-1, -1, 0.4296875}; | 503 const color_utils::HSL kTint = {-1, -1, 0.4296875}; |
434 const color_utils::HSL kTintIncognito = {-1, -1, 0.34375}; | 504 const color_utils::HSL kTintIncognito = {-1, -1, 0.34375}; |
435 return color_utils::HSLShift( | 505 return color_utils::HSLShift( |
436 GetColor(ThemeProperties::COLOR_TOOLBAR, incognito), | 506 GetColor(ThemeProperties::COLOR_TOOLBAR, incognito), |
437 incognito ? kTintIncognito : kTint); | 507 incognito ? kTintIncognito : kTint); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 | 849 |
780 #if defined(ENABLE_SUPERVISED_USERS) | 850 #if defined(ENABLE_SUPERVISED_USERS) |
781 bool ThemeService::IsSupervisedUser() const { | 851 bool ThemeService::IsSupervisedUser() const { |
782 return profile_->IsSupervised(); | 852 return profile_->IsSupervised(); |
783 } | 853 } |
784 | 854 |
785 void ThemeService::SetSupervisedUserTheme() { | 855 void ThemeService::SetSupervisedUserTheme() { |
786 SetCustomDefaultTheme(new SupervisedUserTheme); | 856 SetCustomDefaultTheme(new SupervisedUserTheme); |
787 } | 857 } |
788 #endif | 858 #endif |
OLD | NEW |