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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 // Strings used by themes to identify colors for different parts of our UI. | 29 // Strings used by themes to identify colors for different parts of our UI. |
30 static const char* kColorFrame = "frame"; | 30 static const char* kColorFrame = "frame"; |
31 static const char* kColorFrameInactive = "frame_inactive"; | 31 static const char* kColorFrameInactive = "frame_inactive"; |
32 static const char* kColorFrameIncognito = "frame_incognito"; | 32 static const char* kColorFrameIncognito = "frame_incognito"; |
33 static const char* kColorFrameIncognitoInactive = | 33 static const char* kColorFrameIncognitoInactive = |
34 "frame_incognito_inactive"; | 34 "frame_incognito_inactive"; |
35 static const char* kColorToolbar = "toolbar"; | 35 static const char* kColorToolbar = "toolbar"; |
36 static const char* kColorTabText = "tab_text"; | 36 static const char* kColorTabText = "tab_text"; |
37 static const char* kColorBackgroundTabText = "background_tab_text"; | 37 static const char* kColorBackgroundTabText = "background_tab_text"; |
38 static const char* kColorBookmarkText = "bookmark_text"; | 38 static const char* kColorBookmarkText = "bookmark_text"; |
| 39 static const char* kColorNTPBackground = "ntp_background"; |
39 static const char* kColorNTPText = "ntp_text"; | 40 static const char* kColorNTPText = "ntp_text"; |
40 static const char* kColorNTPLink = "ntp_link"; | 41 static const char* kColorNTPLink = "ntp_link"; |
41 static const char* kColorNTPSection = "ntp_section"; | 42 static const char* kColorNTPSection = "ntp_section"; |
42 | 43 |
43 // Strings used by themes to identify tints to apply to different parts of | 44 // Strings used by themes to identify tints to apply to different parts of |
44 // our UI. The frame tints apply to the frame color and produce the | 45 // our UI. The frame tints apply to the frame color and produce the |
45 // COLOR_FRAME* colors. | 46 // COLOR_FRAME* colors. |
46 static const char* kTintButtons = "buttons"; | 47 static const char* kTintButtons = "buttons"; |
47 static const char* kTintFrame = "frame"; | 48 static const char* kTintFrame = "frame"; |
48 static const char* kTintFrameInactive = "frame_inactive"; | 49 static const char* kTintFrameInactive = "frame_inactive"; |
49 static const char* kTintFrameIncognito = "frame_incognito"; | 50 static const char* kTintFrameIncognito = "frame_incognito"; |
50 static const char* kTintFrameIncognitoInactive = | 51 static const char* kTintFrameIncognitoInactive = |
51 "frame_incognito_inactive"; | 52 "frame_incognito_inactive"; |
52 static const char* kTintBackgroundTab = "background_tab"; | 53 static const char* kTintBackgroundTab = "background_tab"; |
53 | 54 |
| 55 // Strings used by themes to identify miscellaneous numerical properties. |
| 56 static const char* kDisplayPropertyNTPAlignment = "ntp_background_alignment"; |
| 57 |
| 58 // Strings used in alignment properties. |
| 59 static const char* kAlignmentTop = "top"; |
| 60 static const char* kAlignmentBottom = "bottom"; |
| 61 static const char* kAlignmentLeft = "left"; |
| 62 static const char* kAlignmentRight = "right"; |
| 63 |
54 // Default colors. | 64 // Default colors. |
55 static const SkColor kDefaultColorFrame = SkColorSetRGB(77, 139, 217); | 65 static const SkColor kDefaultColorFrame = SkColorSetRGB(77, 139, 217); |
56 static const SkColor kDefaultColorFrameInactive = SkColorSetRGB(152, 188, 233); | 66 static const SkColor kDefaultColorFrameInactive = SkColorSetRGB(152, 188, 233); |
57 static const SkColor kDefaultColorFrameIncognito = SkColorSetRGB(83, 106, 139); | 67 static const SkColor kDefaultColorFrameIncognito = SkColorSetRGB(83, 106, 139); |
58 static const SkColor kDefaultColorFrameIncognitoInactive = | 68 static const SkColor kDefaultColorFrameIncognitoInactive = |
59 SkColorSetRGB(126, 139, 156); | 69 SkColorSetRGB(126, 139, 156); |
60 static const SkColor kDefaultColorToolbar = SkColorSetRGB(210, 225, 246); | 70 static const SkColor kDefaultColorToolbar = SkColorSetRGB(210, 225, 246); |
61 static const SkColor kDefaultColorTabText = SkColorSetRGB(0, 0, 0); | 71 static const SkColor kDefaultColorTabText = SkColorSetRGB(0, 0, 0); |
62 static const SkColor kDefaultColorBackgroundTabText = SkColorSetRGB(64, 64, 64); | 72 static const SkColor kDefaultColorBackgroundTabText = SkColorSetRGB(64, 64, 64); |
63 static const SkColor kDefaultColorBookmarkText = SkColorSetRGB(64, 64, 64); | 73 static const SkColor kDefaultColorBookmarkText = SkColorSetRGB(64, 64, 64); |
| 74 static const SkColor kDefaultColorNTPBackground = SkColorSetRGB(255, 255, 255); |
64 static const SkColor kDefaultColorNTPText = SkColorSetRGB(0, 0, 0); | 75 static const SkColor kDefaultColorNTPText = SkColorSetRGB(0, 0, 0); |
65 static const SkColor kDefaultColorNTPLink = SkColorSetRGB(0, 0, 204); | 76 static const SkColor kDefaultColorNTPLink = SkColorSetRGB(0, 0, 204); |
66 static const SkColor kDefaultColorNTPSection = SkColorSetRGB(225, 236, 254); | 77 static const SkColor kDefaultColorNTPSection = SkColorSetRGB(225, 236, 254); |
67 | 78 |
68 // Default tints. | 79 // Default tints. |
69 static const skia::HSL kDefaultTintButtons = { -1, -1, -1 }; | 80 static const skia::HSL kDefaultTintButtons = { -1, -1, -1 }; |
70 static const skia::HSL kDefaultTintFrame = { -1, -1, -1 }; | 81 static const skia::HSL kDefaultTintFrame = { -1, -1, -1 }; |
71 static const skia::HSL kDefaultTintFrameInactive = { -1, 0.5f, 0.72f }; | 82 static const skia::HSL kDefaultTintFrameInactive = { -1, 0.5f, 0.72f }; |
72 static const skia::HSL kDefaultTintFrameIncognito = { -1, 0.2f, 0.35f }; | 83 static const skia::HSL kDefaultTintFrameIncognito = { -1, 0.2f, 0.35f }; |
73 static const skia::HSL kDefaultTintFrameIncognitoInactive = { -1, 0.3f, 0.6f }; | 84 static const skia::HSL kDefaultTintFrameIncognitoInactive = { -1, 0.3f, 0.6f }; |
74 static const skia::HSL kDefaultTintBackgroundTab = { -1, 0.5, 0.75 }; | 85 static const skia::HSL kDefaultTintBackgroundTab = { -1, 0.5, 0.75 }; |
75 | 86 |
| 87 // Default display properties. |
| 88 static const int kDefaultDisplayPropertyNTPAlignment = |
| 89 BrowserThemeProvider::ALIGN_BOTTOM; |
| 90 |
76 // The image resources that will be tinted by the 'button' tint value. | 91 // The image resources that will be tinted by the 'button' tint value. |
77 static const int kToolbarButtonIDs[] = { | 92 static const int kToolbarButtonIDs[] = { |
78 IDR_BACK, IDR_BACK_D, IDR_BACK_H, IDR_BACK_P, | 93 IDR_BACK, IDR_BACK_D, IDR_BACK_H, IDR_BACK_P, |
79 IDR_FORWARD, IDR_FORWARD_D, IDR_FORWARD_H, IDR_FORWARD_P, | 94 IDR_FORWARD, IDR_FORWARD_D, IDR_FORWARD_H, IDR_FORWARD_P, |
80 IDR_RELOAD, IDR_RELOAD_H, IDR_RELOAD_P, | 95 IDR_RELOAD, IDR_RELOAD_H, IDR_RELOAD_P, |
81 IDR_HOME, IDR_HOME_H, IDR_HOME_P, | 96 IDR_HOME, IDR_HOME_H, IDR_HOME_P, |
82 IDR_STAR, IDR_STAR_D, IDR_STAR_H, IDR_STAR_P, | 97 IDR_STAR, IDR_STAR_D, IDR_STAR_H, IDR_STAR_P, |
83 IDR_STARRED, IDR_STARRED_H, IDR_STARRED_P, | 98 IDR_STARRED, IDR_STARRED_H, IDR_STARRED_P, |
84 IDR_GO, IDR_GO_H, IDR_GO_P, | 99 IDR_GO, IDR_GO_H, IDR_GO_P, |
85 IDR_STOP, IDR_STOP_H, IDR_STOP_P, | 100 IDR_STOP, IDR_STOP_H, IDR_STOP_P, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 return (colors_.find(kColorTabText) != colors_.end()) ? | 208 return (colors_.find(kColorTabText) != colors_.end()) ? |
194 colors_[kColorTabText] : kDefaultColorTabText; | 209 colors_[kColorTabText] : kDefaultColorTabText; |
195 case COLOR_BACKGROUND_TAB_TEXT: | 210 case COLOR_BACKGROUND_TAB_TEXT: |
196 return (colors_.find(kColorBackgroundTabText) != colors_.end()) ? | 211 return (colors_.find(kColorBackgroundTabText) != colors_.end()) ? |
197 colors_[kColorBackgroundTabText] : | 212 colors_[kColorBackgroundTabText] : |
198 kDefaultColorBackgroundTabText; | 213 kDefaultColorBackgroundTabText; |
199 case COLOR_BOOKMARK_TEXT: | 214 case COLOR_BOOKMARK_TEXT: |
200 return (colors_.find(kColorBookmarkText) != colors_.end()) ? | 215 return (colors_.find(kColorBookmarkText) != colors_.end()) ? |
201 colors_[kColorBookmarkText] : | 216 colors_[kColorBookmarkText] : |
202 kDefaultColorBookmarkText; | 217 kDefaultColorBookmarkText; |
| 218 case COLOR_NTP_BACKGROUND: |
| 219 return (colors_.find(kColorNTPBackground) != colors_.end()) ? |
| 220 colors_[kColorNTPBackground] : |
| 221 kDefaultColorNTPBackground; |
203 case COLOR_NTP_TEXT: | 222 case COLOR_NTP_TEXT: |
204 return (colors_.find(kColorNTPText) != colors_.end()) ? | 223 return (colors_.find(kColorNTPText) != colors_.end()) ? |
205 colors_[kColorNTPText] : | 224 colors_[kColorNTPText] : |
206 kDefaultColorNTPText; | 225 kDefaultColorNTPText; |
207 case COLOR_NTP_LINK: | 226 case COLOR_NTP_LINK: |
208 return (colors_.find(kColorNTPLink) != colors_.end()) ? | 227 return (colors_.find(kColorNTPLink) != colors_.end()) ? |
209 colors_[kColorNTPLink] : | 228 colors_[kColorNTPLink] : |
210 kDefaultColorNTPLink; | 229 kDefaultColorNTPLink; |
211 case COLOR_NTP_SECTION: | 230 case COLOR_NTP_SECTION: |
212 return (colors_.find(kColorNTPSection) != colors_.end()) ? | 231 return (colors_.find(kColorNTPSection) != colors_.end()) ? |
213 colors_[kColorNTPSection] : | 232 colors_[kColorNTPSection] : |
214 kDefaultColorNTPSection; | 233 kDefaultColorNTPSection; |
215 default: | 234 default: |
216 NOTREACHED() << "Unknown color requested"; | 235 NOTREACHED() << "Unknown color requested"; |
217 } | 236 } |
218 | 237 |
219 // Return a debugging red color. | 238 // Return a debugging red color. |
220 return 0xffff0000; | 239 return 0xffff0000; |
221 } | 240 } |
222 | 241 |
| 242 bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) { |
| 243 switch (id) { |
| 244 case NTP_BACKGROUND_ALIGNMENT: |
| 245 if (display_properties_.find(kDisplayPropertyNTPAlignment) != |
| 246 display_properties_.end()) { |
| 247 *result = display_properties_[kDisplayPropertyNTPAlignment]; |
| 248 } else { |
| 249 *result = kDefaultDisplayPropertyNTPAlignment; |
| 250 } |
| 251 return true; |
| 252 default: |
| 253 NOTREACHED() << "Unknown property requested"; |
| 254 } |
| 255 return false; |
| 256 } |
| 257 |
223 bool BrowserThemeProvider::ShouldUseNativeFrame() { | 258 bool BrowserThemeProvider::ShouldUseNativeFrame() { |
224 if (images_.find(IDR_THEME_FRAME) != images_.end()) | 259 if (images_.find(IDR_THEME_FRAME) != images_.end()) |
225 return false; | 260 return false; |
226 #if defined(OS_WIN) | 261 #if defined(OS_WIN) |
227 return win_util::ShouldUseVistaFrame(); | 262 return win_util::ShouldUseVistaFrame(); |
228 #else | 263 #else |
229 return false; | 264 return false; |
230 #endif | 265 #endif |
231 } | 266 } |
232 | 267 |
233 void BrowserThemeProvider::SetTheme(Extension* extension) { | 268 void BrowserThemeProvider::SetTheme(Extension* extension) { |
234 // Clear our image cache. | 269 // Clear our image cache. |
235 FreeImages(); | 270 FreeImages(); |
236 | 271 |
237 DCHECK(extension); | 272 DCHECK(extension); |
238 DCHECK(extension->IsTheme()); | 273 DCHECK(extension->IsTheme()); |
239 SetImageData(extension->GetThemeImages(), | 274 SetImageData(extension->GetThemeImages(), |
240 extension->path()); | 275 extension->path()); |
241 SetColorData(extension->GetThemeColors()); | 276 SetColorData(extension->GetThemeColors()); |
242 SetTintData(extension->GetThemeTints()); | 277 SetTintData(extension->GetThemeTints()); |
| 278 SetDisplayPropertyData(extension->GetThemeDisplayProperties()); |
243 GenerateFrameColors(); | 279 GenerateFrameColors(); |
244 GenerateFrameImages(); | 280 GenerateFrameImages(); |
245 | 281 |
246 SaveImageData(extension->GetThemeImages()); | 282 SaveImageData(extension->GetThemeImages()); |
247 SaveColorData(); | 283 SaveColorData(); |
248 SaveTintData(); | 284 SaveTintData(); |
| 285 SaveDisplayPropertyData(); |
249 | 286 |
250 NotifyThemeChanged(); | 287 NotifyThemeChanged(); |
251 UserMetrics::RecordAction(L"Themes_Installed", profile_); | 288 UserMetrics::RecordAction(L"Themes_Installed", profile_); |
252 } | 289 } |
253 | 290 |
254 void BrowserThemeProvider::UseDefaultTheme() { | 291 void BrowserThemeProvider::UseDefaultTheme() { |
255 // Clear our image cache. | 292 // Clear our image cache. |
256 FreeImages(); | 293 FreeImages(); |
257 | 294 |
258 images_.clear(); | 295 images_.clear(); |
259 colors_.clear(); | 296 colors_.clear(); |
260 tints_.clear(); | 297 tints_.clear(); |
| 298 display_properties_.clear(); |
261 | 299 |
262 SaveImageData(NULL); | 300 SaveImageData(NULL); |
263 SaveColorData(); | 301 SaveColorData(); |
264 SaveTintData(); | 302 SaveTintData(); |
| 303 SaveDisplayPropertyData(); |
265 | 304 |
266 NotifyThemeChanged(); | 305 NotifyThemeChanged(); |
| 306 UserMetrics::RecordAction(L"Themes_Reset", profile_); |
267 } | 307 } |
268 | 308 |
269 SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { | 309 SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { |
270 DCHECK(CalledOnValidThread()); | 310 DCHECK(CalledOnValidThread()); |
271 // Attempt to find the image in our theme bundle. | 311 // Attempt to find the image in our theme bundle. |
272 std::vector<unsigned char> raw_data, png_data; | 312 std::vector<unsigned char> raw_data, png_data; |
273 if (images_.count(id)) { | 313 if (images_.count(id)) { |
274 // First check to see if we have a registered theme extension and whether | 314 // First check to see if we have a registered theme extension and whether |
275 // it can handle this resource. | 315 // it can handle this resource. |
276 #if defined(OS_WIN) | 316 #if defined(OS_WIN) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 388 } |
349 | 389 |
350 SkBitmap BrowserThemeProvider::TintBitmap(const SkBitmap& bitmap, int hsl_id) { | 390 SkBitmap BrowserThemeProvider::TintBitmap(const SkBitmap& bitmap, int hsl_id) { |
351 return skia::ImageOperations::CreateHSLShiftedBitmap(bitmap, GetTint(hsl_id)); | 391 return skia::ImageOperations::CreateHSLShiftedBitmap(bitmap, GetTint(hsl_id)); |
352 } | 392 } |
353 | 393 |
354 void BrowserThemeProvider::SetImageData(DictionaryValue* images_value, | 394 void BrowserThemeProvider::SetImageData(DictionaryValue* images_value, |
355 FilePath images_path) { | 395 FilePath images_path) { |
356 images_.clear(); | 396 images_.clear(); |
357 | 397 |
358 if (images_value) { | 398 if (!images_value) |
359 DictionaryValue::key_iterator iter = images_value->begin_keys(); | 399 return; |
360 while (iter != images_value->end_keys()) { | 400 |
361 std::string val; | 401 DictionaryValue::key_iterator iter = images_value->begin_keys(); |
362 if (images_value->GetString(*iter, &val)) { | 402 while (iter != images_value->end_keys()) { |
363 int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); | 403 std::string val; |
364 if (id != -1) { | 404 if (images_value->GetString(*iter, &val)) { |
365 if (!images_path.empty()) { | 405 int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); |
366 images_[id] = WideToUTF8(images_path.AppendASCII(val) | 406 if (id != -1) { |
367 .ToWStringHack()); | 407 if (!images_path.empty()) { |
368 } else { | 408 images_[id] = WideToUTF8(images_path.AppendASCII(val) |
369 images_[id] = val; | 409 .ToWStringHack()); |
370 } | 410 } else { |
| 411 images_[id] = val; |
371 } | 412 } |
372 } | 413 } |
373 ++iter; | |
374 } | 414 } |
| 415 ++iter; |
375 } | 416 } |
376 } | 417 } |
377 | 418 |
378 void BrowserThemeProvider::SetColorData(DictionaryValue* colors_value) { | 419 void BrowserThemeProvider::SetColorData(DictionaryValue* colors_value) { |
379 colors_.clear(); | 420 colors_.clear(); |
380 | 421 |
381 if (colors_value) { | 422 if (!colors_value) |
382 DictionaryValue::key_iterator iter = colors_value->begin_keys(); | 423 return; |
383 while (iter != colors_value->end_keys()) { | 424 |
384 ListValue* color_list; | 425 DictionaryValue::key_iterator iter = colors_value->begin_keys(); |
385 if (colors_value->GetList(*iter, &color_list) && | 426 while (iter != colors_value->end_keys()) { |
386 color_list->GetSize() == 3) { | 427 ListValue* color_list; |
387 int r, g, b; | 428 if (colors_value->GetList(*iter, &color_list) && |
388 color_list->GetInteger(0, &r); | 429 color_list->GetSize() == 3) { |
389 color_list->GetInteger(1, &g); | 430 int r, g, b; |
390 color_list->GetInteger(2, &b); | 431 color_list->GetInteger(0, &r); |
391 colors_[WideToUTF8(*iter)] = SkColorSetRGB(r, g, b); | 432 color_list->GetInteger(1, &g); |
392 } | 433 color_list->GetInteger(2, &b); |
393 ++iter; | 434 colors_[WideToUTF8(*iter)] = SkColorSetRGB(r, g, b); |
394 } | 435 } |
| 436 ++iter; |
395 } | 437 } |
396 } | 438 } |
397 | 439 |
398 void BrowserThemeProvider::SetTintData(DictionaryValue* tints_value) { | 440 void BrowserThemeProvider::SetTintData(DictionaryValue* tints_value) { |
399 tints_.clear(); | 441 tints_.clear(); |
400 | 442 |
401 if (tints_value) { | 443 if (!tints_value) |
402 DictionaryValue::key_iterator iter = tints_value->begin_keys(); | 444 return; |
403 while (iter != tints_value->end_keys()) { | 445 |
404 ListValue* tint_list; | 446 DictionaryValue::key_iterator iter = tints_value->begin_keys(); |
405 if (tints_value->GetList(*iter, &tint_list) && | 447 while (iter != tints_value->end_keys()) { |
406 tint_list->GetSize() == 3) { | 448 ListValue* tint_list; |
407 skia::HSL hsl = { -1, -1, -1 }; | 449 if (tints_value->GetList(*iter, &tint_list) && |
408 // TODO(glen): Make this work with integer values. | 450 tint_list->GetSize() == 3) { |
409 tint_list->GetReal(0, &hsl.h); | 451 skia::HSL hsl = { -1, -1, -1 }; |
410 tint_list->GetReal(1, &hsl.s); | 452 // TODO(glen): Make this work with integer values. |
411 tint_list->GetReal(2, &hsl.l); | 453 tint_list->GetReal(0, &hsl.h); |
412 tints_[WideToUTF8(*iter)] = hsl; | 454 tint_list->GetReal(1, &hsl.s); |
413 } | 455 tint_list->GetReal(2, &hsl.l); |
414 ++iter; | 456 tints_[WideToUTF8(*iter)] = hsl; |
415 } | 457 } |
| 458 ++iter; |
416 } | 459 } |
417 } | 460 } |
418 | 461 |
| 462 void BrowserThemeProvider::SetDisplayPropertyData( |
| 463 DictionaryValue* display_properties_value) { |
| 464 display_properties_.clear(); |
| 465 |
| 466 if (!display_properties_value) |
| 467 return; |
| 468 |
| 469 DictionaryValue::key_iterator iter = display_properties_value->begin_keys(); |
| 470 while (iter != display_properties_value->end_keys()) { |
| 471 // New tab page alignment. |
| 472 if (base::strcasecmp(WideToUTF8(*iter).c_str(), |
| 473 kDisplayPropertyNTPAlignment) == 0) { |
| 474 std::string val; |
| 475 if (display_properties_value->GetString(*iter, &val)) |
| 476 display_properties_[kDisplayPropertyNTPAlignment] = |
| 477 StringToAlignment(val); |
| 478 } |
| 479 ++iter; |
| 480 } |
| 481 } |
| 482 |
| 483 // static |
| 484 int BrowserThemeProvider::StringToAlignment(const std::string& alignment) { |
| 485 std::vector<std::wstring> split; |
| 486 SplitStringAlongWhitespace(UTF8ToWide(alignment), &split); |
| 487 |
| 488 std::vector<std::wstring>::iterator alignments = split.begin(); |
| 489 int alignment_mask = 0; |
| 490 while (alignments != split.end()) { |
| 491 std::string comp = WideToUTF8(*alignments); |
| 492 const char* component = comp.c_str(); |
| 493 |
| 494 if (base::strcasecmp(component, kAlignmentTop) == 0) |
| 495 alignment_mask |= BrowserThemeProvider::ALIGN_TOP; |
| 496 else if (base::strcasecmp(component, kAlignmentBottom) == 0) |
| 497 alignment_mask |= BrowserThemeProvider::ALIGN_BOTTOM; |
| 498 |
| 499 if (base::strcasecmp(component, kAlignmentLeft) == 0) |
| 500 alignment_mask |= BrowserThemeProvider::ALIGN_LEFT; |
| 501 else if (base::strcasecmp(component, kAlignmentRight) == 0) |
| 502 alignment_mask |= BrowserThemeProvider::ALIGN_RIGHT; |
| 503 alignments++; |
| 504 } |
| 505 return alignment_mask; |
| 506 } |
| 507 |
| 508 // static |
| 509 std::string BrowserThemeProvider::AlignmentToString(int alignment) { |
| 510 // Convert from an AlignmentProperty back into a string. |
| 511 std::string vertical_string; |
| 512 std::string horizontal_string; |
| 513 |
| 514 if (alignment & BrowserThemeProvider::ALIGN_TOP) |
| 515 vertical_string = kAlignmentTop; |
| 516 else if (alignment & BrowserThemeProvider::ALIGN_BOTTOM) |
| 517 vertical_string = kAlignmentBottom; |
| 518 |
| 519 if (alignment & BrowserThemeProvider::ALIGN_LEFT) |
| 520 horizontal_string = kAlignmentLeft; |
| 521 else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) |
| 522 horizontal_string = kAlignmentRight; |
| 523 |
| 524 if (!vertical_string.empty() && !horizontal_string.empty()) |
| 525 return vertical_string + " " + horizontal_string; |
| 526 else if (vertical_string.empty()) |
| 527 return horizontal_string; |
| 528 else |
| 529 return vertical_string; |
| 530 } |
| 531 |
419 void BrowserThemeProvider::GenerateFrameColors() { | 532 void BrowserThemeProvider::GenerateFrameColors() { |
420 // Generate any secondary frame colors that weren't provided. | 533 // Generate any secondary frame colors that weren't provided. |
421 skia::HSL frame_hsl = { 0, 0, 0 }; | 534 skia::HSL frame_hsl = { 0, 0, 0 }; |
422 skia::SkColorToHSL(GetColor(COLOR_FRAME), frame_hsl); | 535 skia::SkColorToHSL(GetColor(COLOR_FRAME), frame_hsl); |
423 | 536 |
424 if (colors_.find(kColorFrame) == colors_.end()) | 537 if (colors_.find(kColorFrame) == colors_.end()) |
425 colors_[kColorFrame] = HSLShift(frame_hsl, GetTint(TINT_FRAME)); | 538 colors_[kColorFrame] = HSLShift(frame_hsl, GetTint(TINT_FRAME)); |
426 if (colors_.find(kColorFrameInactive) == colors_.end()) { | 539 if (colors_.find(kColorFrameInactive) == colors_.end()) { |
427 colors_[kColorFrameInactive] = | 540 colors_[kColorFrameInactive] = |
428 HSLShift(frame_hsl, GetTint(TINT_FRAME_INACTIVE)); | 541 HSLShift(frame_hsl, GetTint(TINT_FRAME_INACTIVE)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 new SkBitmap(TintBitmap(blurred, TINT_BACKGROUND_TAB)); | 601 new SkBitmap(TintBitmap(blurred, TINT_BACKGROUND_TAB)); |
489 generated_images_.push_back(bg_tab); | 602 generated_images_.push_back(bg_tab); |
490 return bg_tab; | 603 return bg_tab; |
491 } | 604 } |
492 } | 605 } |
493 | 606 |
494 return NULL; | 607 return NULL; |
495 } | 608 } |
496 | 609 |
497 void BrowserThemeProvider::NotifyThemeChanged() { | 610 void BrowserThemeProvider::NotifyThemeChanged() { |
498 // TODO(glen): If we're in glass and IDR_THEME_FRAME has been provided, | |
499 // swap us back to opaque frame. | |
500 | |
501 // Redraw! | 611 // Redraw! |
502 for (BrowserList::const_iterator browser = BrowserList::begin(); | 612 for (BrowserList::const_iterator browser = BrowserList::begin(); |
503 browser != BrowserList::end(); ++browser) { | 613 browser != BrowserList::end(); ++browser) { |
504 (*browser)->window()->UserChangedTheme(); | 614 (*browser)->window()->UserChangedTheme(); |
505 } | 615 } |
506 } | 616 } |
507 | 617 |
508 void BrowserThemeProvider::LoadThemePrefs() { | 618 void BrowserThemeProvider::LoadThemePrefs() { |
509 PrefService* prefs = profile_->GetPrefs(); | 619 PrefService* prefs = profile_->GetPrefs(); |
510 | 620 |
511 // TODO(glen): Figure out if any custom prefs were loaded, and if so | 621 // TODO(glen): Figure out if any custom prefs were loaded, and if so |
512 // UMA-log the fact that a theme was loaded. | 622 // UMA-log the fact that a theme was loaded. |
513 if (prefs->HasPrefPath(prefs::kCurrentThemeImages) || | 623 if (prefs->HasPrefPath(prefs::kCurrentThemeImages) || |
514 prefs->HasPrefPath(prefs::kCurrentThemeColors) || | 624 prefs->HasPrefPath(prefs::kCurrentThemeColors) || |
515 prefs->HasPrefPath(prefs::kCurrentThemeTints)) { | 625 prefs->HasPrefPath(prefs::kCurrentThemeTints)) { |
516 // Our prefs already have the extension path baked in, so we don't need | 626 // Our prefs already have the extension path baked in, so we don't need |
517 // to provide it. | 627 // to provide it. |
518 SetImageData(prefs->GetMutableDictionary(prefs::kCurrentThemeImages), | 628 SetImageData(prefs->GetMutableDictionary(prefs::kCurrentThemeImages), |
519 FilePath()); | 629 FilePath()); |
520 SetColorData(prefs->GetMutableDictionary(prefs::kCurrentThemeColors)); | 630 SetColorData(prefs->GetMutableDictionary(prefs::kCurrentThemeColors)); |
521 SetTintData(prefs->GetMutableDictionary(prefs::kCurrentThemeTints)); | 631 SetTintData(prefs->GetMutableDictionary(prefs::kCurrentThemeTints)); |
| 632 SetDisplayPropertyData(prefs->GetMutableDictionary( |
| 633 prefs::kCurrentThemeDisplayProperties)); |
522 GenerateFrameColors(); | 634 GenerateFrameColors(); |
523 GenerateFrameImages(); | 635 GenerateFrameImages(); |
524 UserMetrics::RecordAction(L"Themes_loaded", profile_); | 636 UserMetrics::RecordAction(L"Themes_loaded", profile_); |
525 } | 637 } |
526 } | 638 } |
527 | 639 |
528 void BrowserThemeProvider::SaveImageData(DictionaryValue* images_value) { | 640 void BrowserThemeProvider::SaveImageData(DictionaryValue* images_value) { |
529 // Save our images data. | 641 // Save our images data. |
530 DictionaryValue* pref_images = | 642 DictionaryValue* pref_images = |
531 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); | 643 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 ListValue* hsl_list = new ListValue(); | 688 ListValue* hsl_list = new ListValue(); |
577 hsl_list->Set(0, Value::CreateRealValue(hsl.h)); | 689 hsl_list->Set(0, Value::CreateRealValue(hsl.h)); |
578 hsl_list->Set(1, Value::CreateRealValue(hsl.s)); | 690 hsl_list->Set(1, Value::CreateRealValue(hsl.s)); |
579 hsl_list->Set(2, Value::CreateRealValue(hsl.l)); | 691 hsl_list->Set(2, Value::CreateRealValue(hsl.l)); |
580 pref_tints->Set(UTF8ToWide((*iter).first), hsl_list); | 692 pref_tints->Set(UTF8ToWide((*iter).first), hsl_list); |
581 ++iter; | 693 ++iter; |
582 } | 694 } |
583 } | 695 } |
584 } | 696 } |
585 | 697 |
| 698 void BrowserThemeProvider::SaveDisplayPropertyData() { |
| 699 // Save our display property data. |
| 700 DictionaryValue* pref_display_properties = |
| 701 profile_->GetPrefs()-> |
| 702 GetMutableDictionary(prefs::kCurrentThemeDisplayProperties); |
| 703 pref_display_properties->Clear(); |
| 704 |
| 705 if (display_properties_.size()) { |
| 706 DisplayPropertyMap::iterator iter = display_properties_.begin(); |
| 707 while (iter != display_properties_.end()) { |
| 708 if (base::strcasecmp((*iter).first.c_str(), |
| 709 kDisplayPropertyNTPAlignment) == 0) { |
| 710 pref_display_properties-> |
| 711 SetString(UTF8ToWide((*iter).first), AlignmentToString( |
| 712 (*iter).second)); |
| 713 } |
| 714 ++iter; |
| 715 } |
| 716 } |
| 717 } |
| 718 |
586 void BrowserThemeProvider::FreeImages() { | 719 void BrowserThemeProvider::FreeImages() { |
587 for (std::vector<SkBitmap*>::iterator i = generated_images_.begin(); | 720 for (std::vector<SkBitmap*>::iterator i = generated_images_.begin(); |
588 i != generated_images_.end(); i++) { | 721 i != generated_images_.end(); i++) { |
589 delete *i; | 722 delete *i; |
590 } | 723 } |
591 generated_images_.clear(); | 724 generated_images_.clear(); |
592 image_cache_.clear(); | 725 image_cache_.clear(); |
593 } | 726 } |
OLD | NEW |