Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 return color_utils::HSLToSkColor(result, SkColorGetA(color)); | 71 return color_utils::HSLToSkColor(result, SkColorGetA(color)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Writes the theme pack to disk on a separate thread. | 74 // Writes the theme pack to disk on a separate thread. |
| 75 void WritePackToDiskCallback(BrowserThemePack* pack, | 75 void WritePackToDiskCallback(BrowserThemePack* pack, |
| 76 const base::FilePath& path) { | 76 const base::FilePath& path) { |
| 77 if (!pack->WriteToDisk(path)) | 77 if (!pack->WriteToDisk(path)) |
| 78 NOTREACHED() << "Could not write theme pack to disk"; | 78 NOTREACHED() << "Could not write theme pack to disk"; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Heuristic to determine if color is grayscale. This is used to decide whether | |
| 82 // to use the colorful or white logo, if a theme fails to specify which. | |
| 83 bool IsColorGrayscale(SkColor color) { | |
| 84 const int kChannelTolerance = 9; | |
| 85 int r = SkColorGetR(color); | |
| 86 int g = SkColorGetG(color); | |
| 87 int b = SkColorGetB(color); | |
| 88 // range = max(r, g, b) - min(r, g, b). | |
|
pkotwicz
2014/09/16 03:57:18
Nit: Use std::max() and std::min(). It makes the c
huangs
2014/09/16 15:38:54
Done.
| |
| 89 int range = (r > g) ? (r > b ? r : b) - (g < b ? g : b) : | |
| 90 (g > b ? g : b) - (r < b ? r : b); | |
| 91 return range < kChannelTolerance; | |
| 92 } | |
| 93 | |
| 81 } // namespace | 94 } // namespace |
| 82 | 95 |
| 83 ThemeService::ThemeService() | 96 ThemeService::ThemeService() |
| 84 : ready_(false), | 97 : ready_(false), |
| 85 rb_(ResourceBundle::GetSharedInstance()), | 98 rb_(ResourceBundle::GetSharedInstance()), |
| 86 profile_(NULL), | 99 profile_(NULL), |
| 87 installed_pending_load_id_(kDefaultThemeID), | 100 installed_pending_load_id_(kDefaultThemeID), |
| 88 number_of_infobars_(0), | 101 number_of_infobars_(0), |
| 89 weak_ptr_factory_(this) { | 102 weak_ptr_factory_(this) { |
| 90 } | 103 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 return Properties::GetDefaultColor(id); | 199 return Properties::GetDefaultColor(id); |
| 187 } | 200 } |
| 188 | 201 |
| 189 int ThemeService::GetDisplayProperty(int id) const { | 202 int ThemeService::GetDisplayProperty(int id) const { |
| 190 int result = 0; | 203 int result = 0; |
| 191 if (theme_supplier_.get() && | 204 if (theme_supplier_.get() && |
| 192 theme_supplier_->GetDisplayProperty(id, &result)) { | 205 theme_supplier_->GetDisplayProperty(id, &result)) { |
| 193 return result; | 206 return result; |
| 194 } | 207 } |
| 195 | 208 |
| 196 if (id == Properties::NTP_LOGO_ALTERNATE && | 209 if (id == Properties::NTP_LOGO_ALTERNATE) { |
| 197 !UsingDefaultTheme() && | 210 // Use colorful logo for |kDefaultThemeGalleryID| themes. |
|
pkotwicz
2014/09/16 03:57:18
Remove the comment. It no longer makes sense.
huangs
2014/09/16 15:38:54
Done; made the comments more succinct.
| |
| 198 !UsingSystemTheme()) { | 211 if (UsingDefaultTheme() || UsingSystemTheme()) |
| 199 // Use the alternate logo for themes from the web store except for | 212 return 0; |
| 200 // |kDefaultThemeGalleryID|. | 213 |
| 201 return 1; | 214 // Use white logo if background image is used. |
| 215 if (HasCustomImage(IDR_THEME_NTP_BACKGROUND)) | |
| 216 return 1; | |
| 217 | |
| 218 SkColor background_color = GetColor(Properties::COLOR_NTP_BACKGROUND); | |
| 219 return IsColorGrayscale(background_color) ? 0 : 1; | |
| 202 } | 220 } |
| 203 | 221 |
| 204 return Properties::GetDefaultDisplayProperty(id); | 222 return Properties::GetDefaultDisplayProperty(id); |
| 205 } | 223 } |
| 206 | 224 |
| 207 bool ThemeService::ShouldUseNativeFrame() const { | 225 bool ThemeService::ShouldUseNativeFrame() const { |
| 208 if (HasCustomImage(IDR_THEME_FRAME)) | 226 if (HasCustomImage(IDR_THEME_FRAME)) |
| 209 return false; | 227 return false; |
| 210 #if defined(OS_WIN) | 228 #if defined(OS_WIN) |
| 211 return ui::win::IsAeroGlassEnabled(); | 229 return ui::win::IsAeroGlassEnabled(); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 void ThemeService::OnInfobarDestroyed() { | 621 void ThemeService::OnInfobarDestroyed() { |
| 604 number_of_infobars_--; | 622 number_of_infobars_--; |
| 605 | 623 |
| 606 if (number_of_infobars_ == 0) | 624 if (number_of_infobars_ == 0) |
| 607 RemoveUnusedThemes(false); | 625 RemoveUnusedThemes(false); |
| 608 } | 626 } |
| 609 | 627 |
| 610 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { | 628 ThemeSyncableService* ThemeService::GetThemeSyncableService() const { |
| 611 return theme_syncable_service_.get(); | 629 return theme_syncable_service_.get(); |
| 612 } | 630 } |
| OLD | NEW |