OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser_theme_provider.h" | 5 #include "chrome/browser/browser_theme_provider.h" |
6 | 6 |
7 #include "base/gfx/png_decoder.h" | 7 #include "base/gfx/png_decoder.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
11 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
12 #include "chrome/browser/metrics/user_metrics.h" | 12 #include "chrome/browser/metrics/user_metrics.h" |
13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
14 #include "chrome/browser/theme_resources_util.h" | 14 #include "chrome/browser/theme_resources_util.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
17 #include "chrome/common/notification_type.h" | 17 #include "chrome/common/notification_type.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "chrome/common/pref_service.h" | 19 #include "chrome/common/pref_service.h" |
20 #include "grit/app_resources.h" | 20 #include "grit/app_resources.h" |
21 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
22 #include "net/base/file_stream.h" | 22 #include "net/base/file_stream.h" |
23 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
24 #include "skia/ext/image_operations.h" | 24 #include "skia/ext/image_operations.h" |
25 #include "skia/ext/skia_utils.h" | 25 #include "skia/ext/skia_utils.h" |
26 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
| 27 #include "third_party/skia/include/core/SkCanvas.h" |
27 | 28 |
28 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
29 #include "app/win_util.h" | 30 #include "app/win_util.h" |
30 #endif | 31 #endif |
31 | 32 |
32 // Strings used by themes to identify colors for different parts of our UI. | 33 // Strings used by themes to identify colors for different parts of our UI. |
33 const char* BrowserThemeProvider::kColorFrame = "frame"; | 34 const char* BrowserThemeProvider::kColorFrame = "frame"; |
34 const char* BrowserThemeProvider::kColorFrameInactive = "frame_inactive"; | 35 const char* BrowserThemeProvider::kColorFrameInactive = "frame_inactive"; |
35 const char* BrowserThemeProvider::kColorFrameIncognito = "frame_incognito"; | 36 const char* BrowserThemeProvider::kColorFrameIncognito = "frame_incognito"; |
36 const char* BrowserThemeProvider::kColorFrameIncognitoInactive = | 37 const char* BrowserThemeProvider::kColorFrameIncognitoInactive = |
(...skipping 22 matching lines...) Expand all Loading... |
59 const char* BrowserThemeProvider::kTintFrameIncognito = "frame_incognito"; | 60 const char* BrowserThemeProvider::kTintFrameIncognito = "frame_incognito"; |
60 const char* BrowserThemeProvider::kTintFrameIncognitoInactive = | 61 const char* BrowserThemeProvider::kTintFrameIncognitoInactive = |
61 "frame_incognito_inactive"; | 62 "frame_incognito_inactive"; |
62 const char* BrowserThemeProvider::kTintBackgroundTab = "background_tab"; | 63 const char* BrowserThemeProvider::kTintBackgroundTab = "background_tab"; |
63 | 64 |
64 // Strings used by themes to identify miscellaneous numerical properties. | 65 // Strings used by themes to identify miscellaneous numerical properties. |
65 const char* BrowserThemeProvider::kDisplayPropertyNTPAlignment = | 66 const char* BrowserThemeProvider::kDisplayPropertyNTPAlignment = |
66 "ntp_background_alignment"; | 67 "ntp_background_alignment"; |
67 const char* BrowserThemeProvider::kDisplayPropertyNTPTiling = | 68 const char* BrowserThemeProvider::kDisplayPropertyNTPTiling = |
68 "ntp_background_repeat"; | 69 "ntp_background_repeat"; |
| 70 const char* BrowserThemeProvider::kDisplayPropertyNTPInverseLogo = |
| 71 "ntp_logo_alternate"; |
69 | 72 |
70 // Strings used in alignment properties. | 73 // Strings used in alignment properties. |
71 const char* BrowserThemeProvider::kAlignmentTop = "top"; | 74 const char* BrowserThemeProvider::kAlignmentTop = "top"; |
72 const char* BrowserThemeProvider::kAlignmentBottom = "bottom"; | 75 const char* BrowserThemeProvider::kAlignmentBottom = "bottom"; |
73 const char* BrowserThemeProvider::kAlignmentLeft = "left"; | 76 const char* BrowserThemeProvider::kAlignmentLeft = "left"; |
74 const char* BrowserThemeProvider::kAlignmentRight = "right"; | 77 const char* BrowserThemeProvider::kAlignmentRight = "right"; |
75 | 78 |
76 // Strings used in background tiling repetition properties. | 79 // Strings used in background tiling repetition properties. |
77 const char* BrowserThemeProvider::kTilingNoRepeat = "no-repeat"; | 80 const char* BrowserThemeProvider::kTilingNoRepeat = "no-repeat"; |
78 const char* BrowserThemeProvider::kTilingRepeatX = "repeat-x"; | 81 const char* BrowserThemeProvider::kTilingRepeatX = "repeat-x"; |
79 const char* BrowserThemeProvider::kTilingRepeatY = "repeat-y"; | 82 const char* BrowserThemeProvider::kTilingRepeatY = "repeat-y"; |
80 const char* BrowserThemeProvider::kTilingRepeat = "repeat"; | 83 const char* BrowserThemeProvider::kTilingRepeat = "repeat"; |
81 | 84 |
82 // Default colors. | 85 // Default colors. |
83 const SkColor BrowserThemeProvider::kDefaultColorFrame = | 86 const SkColor BrowserThemeProvider::kDefaultColorFrame = |
84 SkColorSetRGB(77, 139, 217); | 87 SkColorSetRGB(77, 139, 217); |
85 const SkColor BrowserThemeProvider::kDefaultColorFrameInactive = | 88 const SkColor BrowserThemeProvider::kDefaultColorFrameInactive = |
86 SkColorSetRGB(152, 188, 233); | 89 SkColorSetRGB(152, 188, 233); |
87 const SkColor BrowserThemeProvider::kDefaultColorFrameIncognito = | 90 const SkColor BrowserThemeProvider::kDefaultColorFrameIncognito = |
88 SkColorSetRGB(83, 106, 139); | 91 SkColorSetRGB(83, 106, 139); |
89 const SkColor BrowserThemeProvider::kDefaultColorFrameIncognitoInactive = | 92 const SkColor BrowserThemeProvider::kDefaultColorFrameIncognitoInactive = |
90 SkColorSetRGB(126, 139, 156); | 93 SkColorSetRGB(126, 139, 156); |
91 const SkColor BrowserThemeProvider::kDefaultColorToolbar = | 94 const SkColor BrowserThemeProvider::kDefaultColorToolbar = |
92 SkColorSetRGB(210, 225, 246); | 95 SkColorSetRGB(210, 225, 246); |
93 const SkColor BrowserThemeProvider::kDefaultColorTabText = | 96 const SkColor BrowserThemeProvider::kDefaultColorTabText = |
94 SkColorSetRGB(0, 0, 0); | 97 SkColorSetRGB(0, 0, 0); |
95 const SkColor BrowserThemeProvider::kDefaultColorBackgroundTabText = | 98 const SkColor BrowserThemeProvider::kDefaultColorBackgroundTabText = |
96 SkColorSetRGB(64, 64, 64); | 99 SkColorSetRGB(64, 64, 64); |
97 const SkColor BrowserThemeProvider::kDefaultColorBookmarkText = | 100 const SkColor BrowserThemeProvider::kDefaultColorBookmarkText = |
98 SkColorSetRGB(64, 64, 64); | 101 SkColorSetRGB(18, 50, 114); |
99 const SkColor BrowserThemeProvider::kDefaultColorNTPBackground = | 102 const SkColor BrowserThemeProvider::kDefaultColorNTPBackground = |
100 SkColorSetRGB(255, 255, 255); | 103 SkColorSetRGB(255, 255, 255); |
101 const SkColor BrowserThemeProvider::kDefaultColorNTPText = | 104 const SkColor BrowserThemeProvider::kDefaultColorNTPText = |
102 SkColorSetRGB(0, 0, 0); | 105 SkColorSetRGB(0, 0, 0); |
103 const SkColor BrowserThemeProvider::kDefaultColorNTPLink = | 106 const SkColor BrowserThemeProvider::kDefaultColorNTPLink = |
104 SkColorSetRGB(0, 0, 204); | 107 SkColorSetRGB(0, 0, 0); |
105 const SkColor BrowserThemeProvider::kDefaultColorNTPSection = | 108 const SkColor BrowserThemeProvider::kDefaultColorNTPSection = |
106 SkColorSetRGB(225, 236, 254); | 109 SkColorSetRGB(75, 140, 220); |
107 const SkColor BrowserThemeProvider::kDefaultColorNTPSectionText = | 110 const SkColor BrowserThemeProvider::kDefaultColorNTPSectionText = |
108 SkColorSetRGB(0, 0, 0); | 111 SkColorSetRGB(255, 255, 255); |
109 const SkColor BrowserThemeProvider::kDefaultColorNTPSectionLink = | 112 const SkColor BrowserThemeProvider::kDefaultColorNTPSectionLink = |
110 SkColorSetRGB(0, 0, 204); | 113 SkColorSetRGB(127, 148, 173); |
111 const SkColor BrowserThemeProvider::kDefaultColorControlBackground = NULL; | 114 const SkColor BrowserThemeProvider::kDefaultColorControlBackground = NULL; |
112 const SkColor BrowserThemeProvider::kDefaultColorButtonBackground = NULL; | 115 const SkColor BrowserThemeProvider::kDefaultColorButtonBackground = NULL; |
113 | 116 |
114 // Default tints. | 117 // Default tints. |
115 const skia::HSL BrowserThemeProvider::kDefaultTintButtons = { -1, -1, -1 }; | 118 const skia::HSL BrowserThemeProvider::kDefaultTintButtons = { -1, -1, -1 }; |
116 const skia::HSL BrowserThemeProvider::kDefaultTintFrame = { -1, -1, -1 }; | 119 const skia::HSL BrowserThemeProvider::kDefaultTintFrame = { -1, -1, -1 }; |
117 const skia::HSL BrowserThemeProvider::kDefaultTintFrameInactive = | 120 const skia::HSL BrowserThemeProvider::kDefaultTintFrameInactive = |
118 { -1, -1, 0.75f }; | 121 { -1, -1, 0.75f }; |
119 const skia::HSL BrowserThemeProvider::kDefaultTintFrameIncognito = | 122 const skia::HSL BrowserThemeProvider::kDefaultTintFrameIncognito = |
120 { -1, 0.2f, 0.35f }; | 123 { -1, 0.2f, 0.35f }; |
121 const skia::HSL BrowserThemeProvider::kDefaultTintFrameIncognitoInactive = | 124 const skia::HSL BrowserThemeProvider::kDefaultTintFrameIncognitoInactive = |
122 { -1, 0.3f, 0.6f }; | 125 { -1, 0.3f, 0.6f }; |
123 const skia::HSL BrowserThemeProvider::kDefaultTintBackgroundTab = | 126 const skia::HSL BrowserThemeProvider::kDefaultTintBackgroundTab = |
124 { -1, 0.5, 0.75 }; | 127 { -1, 0.5, 0.75 }; |
125 | 128 |
126 // Default display properties. | 129 // Default display properties. |
127 static const int kDefaultDisplayPropertyNTPAlignment = | 130 static const int kDefaultDisplayPropertyNTPAlignment = |
128 BrowserThemeProvider::ALIGN_BOTTOM; | 131 BrowserThemeProvider::ALIGN_BOTTOM; |
129 static const int kDefaultDisplayPropertyNTPTiling = | 132 static const int kDefaultDisplayPropertyNTPTiling = |
130 BrowserThemeProvider::NO_REPEAT; | 133 BrowserThemeProvider::NO_REPEAT; |
| 134 static const int kDefaultDisplayPropertyNTPInverseLogo = 0; |
131 | 135 |
132 // The image resources that will be tinted by the 'button' tint value. | 136 // The image resources that will be tinted by the 'button' tint value. |
133 static const int kToolbarButtonIDs[] = { | 137 static const int kToolbarButtonIDs[] = { |
134 IDR_BACK, IDR_BACK_D, IDR_BACK_H, IDR_BACK_P, | 138 IDR_BACK, IDR_BACK_D, IDR_BACK_H, IDR_BACK_P, |
135 IDR_FORWARD, IDR_FORWARD_D, IDR_FORWARD_H, IDR_FORWARD_P, | 139 IDR_FORWARD, IDR_FORWARD_D, IDR_FORWARD_H, IDR_FORWARD_P, |
136 IDR_RELOAD, IDR_RELOAD_H, IDR_RELOAD_P, | 140 IDR_RELOAD, IDR_RELOAD_H, IDR_RELOAD_P, |
137 IDR_HOME, IDR_HOME_H, IDR_HOME_P, | 141 IDR_HOME, IDR_HOME_H, IDR_HOME_P, |
138 IDR_STAR, IDR_STAR_NOBORDER, IDR_STAR_D, IDR_STAR_H, IDR_STAR_P, | 142 IDR_STAR, IDR_STAR_NOBORDER, IDR_STAR_D, IDR_STAR_H, IDR_STAR_P, |
139 IDR_STARRED, IDR_STARRED_NOBORDER, IDR_STARRED_H, IDR_STARRED_P, | 143 IDR_STARRED, IDR_STARRED_NOBORDER, IDR_STARRED_H, IDR_STARRED_P, |
140 IDR_GO, IDR_GO_H, IDR_GO_P, | 144 IDR_GO, IDR_GO_H, IDR_GO_P, |
141 IDR_STOP, IDR_STOP_H, IDR_STOP_P, | 145 IDR_STOP, IDR_STOP_H, IDR_STOP_P, |
142 IDR_MENU_PAGE, IDR_MENU_PAGE_RTL, | 146 IDR_MENU_PAGE, IDR_MENU_PAGE_RTL, |
143 IDR_MENU_CHROME, IDR_MENU_CHROME_RTL, | 147 IDR_MENU_CHROME, IDR_MENU_CHROME_RTL, |
144 IDR_MENU_DROPARROW, | 148 IDR_MENU_DROPARROW, |
145 IDR_THROBBER, IDR_THROBBER_WAITING, IDR_THROBBER_LIGHT | 149 IDR_THROBBER, IDR_THROBBER_WAITING, IDR_THROBBER_LIGHT, |
| 150 IDR_LOCATIONBG |
146 }; | 151 }; |
147 | 152 |
148 // A map for kToolbarButtonIDs. | 153 // A map for kToolbarButtonIDs. |
149 static std::map<const int, bool> button_images_; | 154 static std::map<const int, bool> button_images_; |
150 | 155 |
| 156 // The image resources we will allow people to theme. |
| 157 static const int kThemeableImages[] = { |
| 158 IDR_THEME_FRAME, |
| 159 IDR_THEME_FRAME_INACTIVE, |
| 160 IDR_THEME_FRAME_INCOGNITO, |
| 161 IDR_THEME_FRAME_INCOGNITO_INACTIVE, |
| 162 IDR_THEME_TOOLBAR, |
| 163 IDR_THEME_TAB_BACKGROUND, |
| 164 IDR_THEME_TAB_BACKGROUND_INCOGNITO, |
| 165 IDR_THEME_TAB_BACKGROUND_V, |
| 166 IDR_THEME_NTP_BACKGROUND, |
| 167 IDR_THEME_FRAME_OVERLAY, |
| 168 IDR_THEME_FRAME_OVERLAY_INACTIVE, |
| 169 IDR_THEME_BUTTON_BACKGROUND, |
| 170 IDR_THEME_NTP_ATTRIBUTION, |
| 171 IDR_THEME_WINDOW_CONTROL_BACKGROUND |
| 172 }; |
| 173 |
| 174 // A map for kThemeableImages. |
| 175 static std::map<const int, bool> themeable_images_; |
| 176 |
151 // A map of frame image IDs to the tints for those ids. | 177 // A map of frame image IDs to the tints for those ids. |
152 static std::map<const int, int> frame_tints_; | 178 static std::map<const int, int> frame_tints_; |
153 | 179 |
154 BrowserThemeProvider::BrowserThemeProvider() | 180 BrowserThemeProvider::BrowserThemeProvider() |
155 : rb_(ResourceBundle::GetSharedInstance()) { | 181 : rb_(ResourceBundle::GetSharedInstance()) { |
156 static bool initialized = false; | 182 static bool initialized = false; |
157 if (!initialized) { | 183 if (!initialized) { |
158 for (size_t i = 0; i < arraysize(kToolbarButtonIDs); ++i) { | 184 for (size_t i = 0; i < arraysize(kToolbarButtonIDs); ++i) { |
159 button_images_[kToolbarButtonIDs[i]] = true; | 185 button_images_[kToolbarButtonIDs[i]] = true; |
160 } | 186 } |
| 187 for (size_t i = 0; i < arraysize(kThemeableImages); ++i) { |
| 188 themeable_images_[kThemeableImages[i]] = true; |
| 189 } |
161 frame_tints_[IDR_THEME_FRAME] = TINT_FRAME; | 190 frame_tints_[IDR_THEME_FRAME] = TINT_FRAME; |
162 frame_tints_[IDR_THEME_FRAME_INACTIVE] = TINT_FRAME_INACTIVE; | 191 frame_tints_[IDR_THEME_FRAME_INACTIVE] = TINT_FRAME_INACTIVE; |
| 192 frame_tints_[IDR_THEME_FRAME_OVERLAY] = TINT_FRAME; |
| 193 frame_tints_[IDR_THEME_FRAME_OVERLAY_INACTIVE] = TINT_FRAME_INACTIVE; |
163 frame_tints_[IDR_THEME_FRAME_INCOGNITO] = TINT_FRAME_INCOGNITO; | 194 frame_tints_[IDR_THEME_FRAME_INCOGNITO] = TINT_FRAME_INCOGNITO; |
164 frame_tints_[IDR_THEME_FRAME_INCOGNITO_INACTIVE] = | 195 frame_tints_[IDR_THEME_FRAME_INCOGNITO_INACTIVE] = |
165 TINT_FRAME_INCOGNITO_INACTIVE; | 196 TINT_FRAME_INCOGNITO_INACTIVE; |
166 } | 197 } |
167 } | 198 } |
168 | 199 |
169 BrowserThemeProvider::~BrowserThemeProvider() { | 200 BrowserThemeProvider::~BrowserThemeProvider() { |
170 ClearCaches(); | 201 ClearCaches(); |
171 } | 202 } |
172 | 203 |
173 void BrowserThemeProvider::Init(Profile* profile) { | 204 void BrowserThemeProvider::Init(Profile* profile) { |
174 DCHECK(CalledOnValidThread()); | 205 DCHECK(CalledOnValidThread()); |
175 profile_ = profile; | 206 profile_ = profile; |
176 LoadThemePrefs(); | 207 LoadThemePrefs(); |
177 } | 208 } |
178 | 209 |
179 SkBitmap* BrowserThemeProvider::GetBitmapNamed(int id) { | 210 SkBitmap* BrowserThemeProvider::GetBitmapNamed(int id) { |
180 DCHECK(CalledOnValidThread()); | 211 DCHECK(CalledOnValidThread()); |
181 | 212 |
| 213 // Check to see whether we should substitute some images. |
| 214 int ntp_alternate; |
| 215 GetDisplayProperty(NTP_LOGO_ALTERNATE, &ntp_alternate); |
| 216 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) |
| 217 id = IDR_PRODUCT_LOGO_WHITE; |
| 218 |
182 // Check to see if we already have the Skia image in the cache. | 219 // Check to see if we already have the Skia image in the cache. |
183 ImageCache::const_iterator found = image_cache_.find(id); | 220 ImageCache::const_iterator found = image_cache_.find(id); |
184 if (found != image_cache_.end()) | 221 if (found != image_cache_.end()) |
185 return found->second; | 222 return found->second; |
186 | 223 |
187 scoped_ptr<SkBitmap> result; | 224 scoped_ptr<SkBitmap> result; |
188 | 225 |
189 // Try to load the image from the extension. | 226 // Try to load the image from the extension. |
190 result.reset(LoadThemeBitmap(id)); | 227 result.reset(LoadThemeBitmap(id)); |
191 | 228 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } | 312 } |
276 return true; | 313 return true; |
277 case NTP_BACKGROUND_TILING: | 314 case NTP_BACKGROUND_TILING: |
278 if (display_properties_.find(kDisplayPropertyNTPTiling) != | 315 if (display_properties_.find(kDisplayPropertyNTPTiling) != |
279 display_properties_.end()) { | 316 display_properties_.end()) { |
280 *result = display_properties_[kDisplayPropertyNTPTiling]; | 317 *result = display_properties_[kDisplayPropertyNTPTiling]; |
281 } else { | 318 } else { |
282 *result = kDefaultDisplayPropertyNTPTiling; | 319 *result = kDefaultDisplayPropertyNTPTiling; |
283 } | 320 } |
284 return true; | 321 return true; |
| 322 case NTP_LOGO_ALTERNATE: |
| 323 if (display_properties_.find(kDisplayPropertyNTPInverseLogo) != |
| 324 display_properties_.end()) { |
| 325 *result = display_properties_[kDisplayPropertyNTPInverseLogo]; |
| 326 } else { |
| 327 *result = kDefaultDisplayPropertyNTPInverseLogo; |
| 328 } |
| 329 return true; |
285 default: | 330 default: |
286 NOTREACHED() << "Unknown property requested"; | 331 NOTREACHED() << "Unknown property requested"; |
287 } | 332 } |
288 return false; | 333 return false; |
289 } | 334 } |
290 | 335 |
291 bool BrowserThemeProvider::ShouldUseNativeFrame() { | 336 bool BrowserThemeProvider::ShouldUseNativeFrame() { |
292 if (images_.find(IDR_THEME_FRAME) != images_.end()) | 337 if (HasCustomImage(IDR_THEME_FRAME)) |
293 return false; | 338 return false; |
294 #if defined(OS_WIN) | 339 #if defined(OS_WIN) |
295 return win_util::ShouldUseVistaFrame(); | 340 return win_util::ShouldUseVistaFrame(); |
296 #else | 341 #else |
297 return false; | 342 return false; |
298 #endif | 343 #endif |
299 } | 344 } |
300 | 345 |
301 bool BrowserThemeProvider::HasCustomImage(int id) { | 346 bool BrowserThemeProvider::HasCustomImage(int id) { |
| 347 if (!themeable_images_[id]) |
| 348 return false; |
| 349 |
302 return (images_.find(id) != images_.end()); | 350 return (images_.find(id) != images_.end()); |
303 } | 351 } |
304 | 352 |
305 void BrowserThemeProvider::SetTheme(Extension* extension) { | 353 void BrowserThemeProvider::SetTheme(Extension* extension) { |
306 // Clear our image cache. | 354 // Clear our image cache. |
307 ClearCaches(); | 355 ClearCaches(); |
308 | 356 |
309 DCHECK(extension); | 357 DCHECK(extension); |
310 DCHECK(extension->IsTheme()); | 358 DCHECK(extension->IsTheme()); |
311 SetImageData(extension->GetThemeImages(), | 359 SetImageData(extension->GetThemeImages(), |
312 extension->path()); | 360 extension->path()); |
313 SetColorData(extension->GetThemeColors()); | 361 SetColorData(extension->GetThemeColors()); |
314 SetTintData(extension->GetThemeTints()); | 362 SetTintData(extension->GetThemeTints()); |
315 SetDisplayPropertyData(extension->GetThemeDisplayProperties()); | 363 SetDisplayPropertyData(extension->GetThemeDisplayProperties()); |
316 GenerateFrameColors(); | 364 GenerateFrameColors(); |
317 GenerateFrameImages(); | 365 GenerateFrameImages(); |
| 366 GenerateTabImages(); |
318 | 367 |
319 SaveImageData(extension->GetThemeImages()); | 368 SaveImageData(extension->GetThemeImages()); |
320 SaveColorData(); | 369 SaveColorData(); |
321 SaveTintData(); | 370 SaveTintData(); |
322 SaveDisplayPropertyData(); | 371 SaveDisplayPropertyData(); |
323 | 372 |
324 NotifyThemeChanged(); | 373 NotifyThemeChanged(); |
325 UserMetrics::RecordAction(L"Themes_Installed", profile_); | 374 UserMetrics::RecordAction(L"Themes_Installed", profile_); |
326 } | 375 } |
327 | 376 |
(...skipping 27 matching lines...) Expand all Loading... |
355 } | 404 } |
356 } | 405 } |
357 } | 406 } |
358 } | 407 } |
359 | 408 |
360 return false; | 409 return false; |
361 } | 410 } |
362 | 411 |
363 SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { | 412 SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { |
364 DCHECK(CalledOnValidThread()); | 413 DCHECK(CalledOnValidThread()); |
| 414 |
| 415 if (!themeable_images_[id]) |
| 416 return NULL; |
| 417 |
365 // Attempt to find the image in our theme bundle. | 418 // Attempt to find the image in our theme bundle. |
366 std::vector<unsigned char> raw_data, png_data; | 419 std::vector<unsigned char> raw_data, png_data; |
367 if (ReadThemeFileData(id, &raw_data)) { | 420 if (ReadThemeFileData(id, &raw_data)) { |
368 // Decode the PNG. | 421 // Decode the PNG. |
369 int image_width = 0; | 422 int image_width = 0; |
370 int image_height = 0; | 423 int image_height = 0; |
371 | 424 |
372 if (!PNGDecoder::Decode(&raw_data.front(), raw_data.size(), | 425 if (!PNGDecoder::Decode(&raw_data.front(), raw_data.size(), |
373 PNGDecoder::FORMAT_BGRA, &png_data, | 426 PNGDecoder::FORMAT_BGRA, &png_data, |
374 &image_width, &image_height)) { | 427 &image_width, &image_height)) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 if (display_properties_value->GetString(*iter, &val)) | 585 if (display_properties_value->GetString(*iter, &val)) |
533 display_properties_[kDisplayPropertyNTPAlignment] = | 586 display_properties_[kDisplayPropertyNTPAlignment] = |
534 StringToAlignment(val); | 587 StringToAlignment(val); |
535 } else if (base::strcasecmp(WideToUTF8(*iter).c_str(), | 588 } else if (base::strcasecmp(WideToUTF8(*iter).c_str(), |
536 kDisplayPropertyNTPTiling) == 0) { | 589 kDisplayPropertyNTPTiling) == 0) { |
537 std::string val; | 590 std::string val; |
538 if (display_properties_value->GetString(*iter, &val)) | 591 if (display_properties_value->GetString(*iter, &val)) |
539 display_properties_[kDisplayPropertyNTPTiling] = | 592 display_properties_[kDisplayPropertyNTPTiling] = |
540 StringToTiling(val); | 593 StringToTiling(val); |
541 } | 594 } |
| 595 if (base::strcasecmp(WideToUTF8(*iter).c_str(), |
| 596 kDisplayPropertyNTPInverseLogo) == 0) { |
| 597 std::string val; |
| 598 if (display_properties_value->GetString(*iter, &val)) |
| 599 display_properties_[kDisplayPropertyNTPInverseLogo] = StringToInt(val); |
| 600 } |
542 ++iter; | 601 ++iter; |
543 } | 602 } |
544 } | 603 } |
545 | 604 |
546 // static | 605 // static |
547 int BrowserThemeProvider::StringToAlignment(const std::string& alignment) { | 606 int BrowserThemeProvider::StringToAlignment(const std::string& alignment) { |
548 std::vector<std::wstring> split; | 607 std::vector<std::wstring> split; |
549 SplitStringAlongWhitespace(UTF8ToWide(alignment), &split); | 608 SplitStringAlongWhitespace(UTF8ToWide(alignment), &split); |
550 | 609 |
551 std::vector<std::wstring>::iterator alignments = split.begin(); | 610 std::vector<std::wstring>::iterator alignments = split.begin(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 } | 707 } |
649 | 708 |
650 void BrowserThemeProvider::GenerateFrameImages() { | 709 void BrowserThemeProvider::GenerateFrameImages() { |
651 std::map<const int, int>::iterator iter = frame_tints_.begin(); | 710 std::map<const int, int>::iterator iter = frame_tints_.begin(); |
652 while (iter != frame_tints_.end()) { | 711 while (iter != frame_tints_.end()) { |
653 int id = iter->first; | 712 int id = iter->first; |
654 scoped_ptr<SkBitmap> frame; | 713 scoped_ptr<SkBitmap> frame; |
655 // If there's no frame image provided for the specified id, then load | 714 // If there's no frame image provided for the specified id, then load |
656 // the default provided frame. If that's not provided, skip this whole | 715 // the default provided frame. If that's not provided, skip this whole |
657 // thing and just use the default images. | 716 // thing and just use the default images. |
658 int base_id = (id == IDR_THEME_FRAME_INCOGNITO || | 717 int base_id; |
659 id == IDR_THEME_FRAME_INCOGNITO_INACTIVE) ? | 718 if (id == IDR_THEME_FRAME_INCOGNITO_INACTIVE) |
660 IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME; | 719 base_id = (HasCustomImage(IDR_THEME_FRAME_INCOGNITO)) ? |
| 720 IDR_THEME_FRAME_INCOGNITO : |
| 721 IDR_THEME_FRAME; |
| 722 else if (id == IDR_THEME_FRAME_OVERLAY_INACTIVE) |
| 723 base_id = IDR_THEME_FRAME_OVERLAY; |
| 724 else if (id == IDR_THEME_FRAME_INACTIVE) |
| 725 base_id = IDR_THEME_FRAME; |
| 726 else if (id == IDR_THEME_FRAME_INCOGNITO && |
| 727 !HasCustomImage(IDR_THEME_FRAME_INCOGNITO)) |
| 728 base_id = IDR_THEME_FRAME; |
| 729 else |
| 730 base_id = id; |
661 | 731 |
662 if (images_.find(id) != images_.end()) { | 732 if (HasCustomImage(id)) { |
663 frame.reset(LoadThemeBitmap(id)); | 733 frame.reset(LoadThemeBitmap(id)); |
664 } else if (base_id != id && images_.find(base_id) != images_.end()) { | 734 } else if (base_id != id && HasCustomImage(base_id)) { |
665 frame.reset(LoadThemeBitmap(base_id)); | 735 frame.reset(LoadThemeBitmap(base_id)); |
666 } else { | 736 } else { |
667 // If the theme doesn't specify an image, then apply the tint to | 737 // If the theme doesn't specify an image, then apply the tint to |
668 // the default frame. Note that the default theme provides default | 738 // the default frame. Note that the default theme provides default |
669 // bitmaps for all frame types, so this isn't strictly necessary | 739 // bitmaps for all frame types, so this isn't strictly necessary |
670 // in the case where no tint is provided either. | 740 // in the case where no tint is provided either. |
671 frame.reset(new SkBitmap(*rb_.GetBitmapNamed(IDR_THEME_FRAME))); | 741 frame.reset(new SkBitmap(*rb_.GetBitmapNamed(IDR_THEME_FRAME))); |
672 } | 742 } |
673 | 743 |
674 if (frame.get()) { | 744 if (frame.get()) { |
675 SkBitmap* tinted = new SkBitmap(TintBitmap(*frame, iter->second)); | 745 SkBitmap* tinted = new SkBitmap(TintBitmap(*frame, iter->second)); |
676 image_cache_[id] = tinted; | 746 image_cache_[id] = tinted; |
677 } | 747 } |
678 ++iter; | 748 ++iter; |
679 } | 749 } |
680 } | 750 } |
681 | 751 |
| 752 void BrowserThemeProvider::GenerateTabImages() { |
| 753 GenerateBitmap(IDR_THEME_TAB_BACKGROUND); |
| 754 GenerateBitmap(IDR_THEME_TAB_BACKGROUND_INCOGNITO); |
| 755 } |
| 756 |
682 void BrowserThemeProvider::ClearAllThemeData() { | 757 void BrowserThemeProvider::ClearAllThemeData() { |
683 // Clear our image cache. | 758 // Clear our image cache. |
684 ClearCaches(); | 759 ClearCaches(); |
685 | 760 |
686 images_.clear(); | 761 images_.clear(); |
687 colors_.clear(); | 762 colors_.clear(); |
688 tints_.clear(); | 763 tints_.clear(); |
689 display_properties_.clear(); | 764 display_properties_.clear(); |
690 | 765 |
691 SaveImageData(NULL); | 766 SaveImageData(NULL); |
692 SaveColorData(); | 767 SaveColorData(); |
693 SaveTintData(); | 768 SaveTintData(); |
694 SaveDisplayPropertyData(); | 769 SaveDisplayPropertyData(); |
695 } | 770 } |
696 | 771 |
697 SkBitmap* BrowserThemeProvider::GenerateBitmap(int id) { | 772 SkBitmap* BrowserThemeProvider::GenerateBitmap(int id) { |
698 if (id == IDR_THEME_TAB_BACKGROUND || | 773 if (id == IDR_THEME_TAB_BACKGROUND || |
699 id == IDR_THEME_TAB_BACKGROUND_INCOGNITO) { | 774 id == IDR_THEME_TAB_BACKGROUND_INCOGNITO) { |
700 // The requested image is a background tab. Get a frame to create the | 775 // The requested image is a background tab. Get a frame to create the |
701 // tab against. As themes don't use the glass frame, we don't have to | 776 // tab against. As themes don't use the glass frame, we don't have to |
702 // worry about compositing them together, as our default theme provides | 777 // worry about compositing them together, as our default theme provides |
703 // the necessary bitmaps. | 778 // the necessary bitmaps. |
704 int base_id = (id == IDR_THEME_TAB_BACKGROUND) ? | 779 int base_id = (id == IDR_THEME_TAB_BACKGROUND) ? |
705 IDR_THEME_FRAME : IDR_THEME_FRAME_INCOGNITO; | 780 IDR_THEME_FRAME : IDR_THEME_FRAME_INCOGNITO; |
706 | 781 |
707 std::map<int, SkBitmap*>::iterator it = image_cache_.find(base_id); | 782 std::map<int, SkBitmap*>::iterator it = image_cache_.find(base_id); |
708 if (it != image_cache_.end()) { | 783 if (it != image_cache_.end()) { |
709 SkBitmap* frame = it->second; | 784 SkBitmap* frame = it->second; |
| 785 int blur_amount = (HasCustomImage(id)) ? 1 : 5; |
710 SkBitmap blurred = | 786 SkBitmap blurred = |
711 skia::ImageOperations::CreateBlurredBitmap(*frame, 5); | 787 skia::ImageOperations::CreateBlurredBitmap(*frame, blur_amount); |
712 SkBitmap* bg_tab = | 788 SkBitmap* bg_tab = |
713 new SkBitmap(TintBitmap(blurred, TINT_BACKGROUND_TAB)); | 789 new SkBitmap(TintBitmap(blurred, TINT_BACKGROUND_TAB)); |
| 790 |
| 791 // If they've provided a custom image, overlay it. |
| 792 if (HasCustomImage(id)) { |
| 793 SkBitmap* overlay = LoadThemeBitmap(id); |
| 794 SkCanvas canvas(*bg_tab); |
| 795 for (int x = 0; x < bg_tab->width(); x += overlay->width()) |
| 796 canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL); |
| 797 } |
| 798 |
| 799 image_cache_[id] = bg_tab; |
714 return bg_tab; | 800 return bg_tab; |
715 } | 801 } |
716 } | 802 } |
717 | 803 |
718 return NULL; | 804 return NULL; |
719 } | 805 } |
720 | 806 |
721 void BrowserThemeProvider::SaveImageData(DictionaryValue* images_value) { | 807 void BrowserThemeProvider::SaveImageData(DictionaryValue* images_value) { |
722 // Save our images data. | 808 // Save our images data. |
723 DictionaryValue* pref_images = | 809 DictionaryValue* pref_images = |
(...skipping 21 matching lines...) Expand all Loading... |
745 pref_colors->Clear(); | 831 pref_colors->Clear(); |
746 if (colors_.size()) { | 832 if (colors_.size()) { |
747 ColorMap::iterator iter = colors_.begin(); | 833 ColorMap::iterator iter = colors_.begin(); |
748 while (iter != colors_.end()) { | 834 while (iter != colors_.end()) { |
749 SkColor rgba = (*iter).second; | 835 SkColor rgba = (*iter).second; |
750 ListValue* rgb_list = new ListValue(); | 836 ListValue* rgb_list = new ListValue(); |
751 rgb_list->Set(0, Value::CreateIntegerValue(SkColorGetR(rgba))); | 837 rgb_list->Set(0, Value::CreateIntegerValue(SkColorGetR(rgba))); |
752 rgb_list->Set(1, Value::CreateIntegerValue(SkColorGetG(rgba))); | 838 rgb_list->Set(1, Value::CreateIntegerValue(SkColorGetG(rgba))); |
753 rgb_list->Set(2, Value::CreateIntegerValue(SkColorGetB(rgba))); | 839 rgb_list->Set(2, Value::CreateIntegerValue(SkColorGetB(rgba))); |
754 if (SkColorGetA(rgba) != 255) | 840 if (SkColorGetA(rgba) != 255) |
755 rgb_list->Set(3, Value::CreateRealValue(SkColorGetA(rgba))); | 841 rgb_list->Set(3, Value::CreateRealValue(SkColorGetA(rgba) / 255.0)); |
756 pref_colors->Set(UTF8ToWide((*iter).first), rgb_list); | 842 pref_colors->Set(UTF8ToWide((*iter).first), rgb_list); |
757 ++iter; | 843 ++iter; |
758 } | 844 } |
759 } | 845 } |
760 } | 846 } |
761 | 847 |
762 void BrowserThemeProvider::SaveTintData() { | 848 void BrowserThemeProvider::SaveTintData() { |
763 // Save our tint data. | 849 // Save our tint data. |
764 DictionaryValue* pref_tints = | 850 DictionaryValue* pref_tints = |
765 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeTints); | 851 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeTints); |
(...skipping 26 matching lines...) Expand all Loading... |
792 kDisplayPropertyNTPAlignment) == 0) { | 878 kDisplayPropertyNTPAlignment) == 0) { |
793 pref_display_properties-> | 879 pref_display_properties-> |
794 SetString(UTF8ToWide((*iter).first), AlignmentToString( | 880 SetString(UTF8ToWide((*iter).first), AlignmentToString( |
795 (*iter).second)); | 881 (*iter).second)); |
796 } else if (base::strcasecmp((*iter).first.c_str(), | 882 } else if (base::strcasecmp((*iter).first.c_str(), |
797 kDisplayPropertyNTPTiling) == 0) { | 883 kDisplayPropertyNTPTiling) == 0) { |
798 pref_display_properties-> | 884 pref_display_properties-> |
799 SetString(UTF8ToWide((*iter).first), TilingToString( | 885 SetString(UTF8ToWide((*iter).first), TilingToString( |
800 (*iter).second)); | 886 (*iter).second)); |
801 } | 887 } |
| 888 if (base::strcasecmp((*iter).first.c_str(), |
| 889 kDisplayPropertyNTPInverseLogo) == 0) { |
| 890 pref_display_properties-> |
| 891 SetInteger(UTF8ToWide((*iter).first), (*iter).second); |
| 892 } |
802 ++iter; | 893 ++iter; |
803 } | 894 } |
804 } | 895 } |
805 } | 896 } |
806 | 897 |
807 void BrowserThemeProvider::NotifyThemeChanged() { | 898 void BrowserThemeProvider::NotifyThemeChanged() { |
808 // Redraw! | 899 // Redraw! |
809 NotificationService* service = NotificationService::current(); | 900 NotificationService* service = NotificationService::current(); |
810 service->Notify(NotificationType::BROWSER_THEME_CHANGED, | 901 service->Notify(NotificationType::BROWSER_THEME_CHANGED, |
811 Source<BrowserThemeProvider>(this), | 902 Source<BrowserThemeProvider>(this), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 delete i->second; | 937 delete i->second; |
847 } | 938 } |
848 image_cache_.clear(); | 939 image_cache_.clear(); |
849 } | 940 } |
850 | 941 |
851 #if defined(TOOLKIT_VIEWS) | 942 #if defined(TOOLKIT_VIEWS) |
852 void BrowserThemeProvider::FreePlatformCaches() { | 943 void BrowserThemeProvider::FreePlatformCaches() { |
853 // Views (Skia) has no platform image cache to clear. | 944 // Views (Skia) has no platform image cache to clear. |
854 } | 945 } |
855 #endif | 946 #endif |
OLD | NEW |