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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 const char* BrowserThemeProvider::kTintFrame = "frame"; | 57 const char* BrowserThemeProvider::kTintFrame = "frame"; |
58 const char* BrowserThemeProvider::kTintFrameInactive = "frame_inactive"; | 58 const char* BrowserThemeProvider::kTintFrameInactive = "frame_inactive"; |
59 const char* BrowserThemeProvider::kTintFrameIncognito = "frame_incognito"; | 59 const char* BrowserThemeProvider::kTintFrameIncognito = "frame_incognito"; |
60 const char* BrowserThemeProvider::kTintFrameIncognitoInactive = | 60 const char* BrowserThemeProvider::kTintFrameIncognitoInactive = |
61 "frame_incognito_inactive"; | 61 "frame_incognito_inactive"; |
62 const char* BrowserThemeProvider::kTintBackgroundTab = "background_tab"; | 62 const char* BrowserThemeProvider::kTintBackgroundTab = "background_tab"; |
63 | 63 |
64 // Strings used by themes to identify miscellaneous numerical properties. | 64 // Strings used by themes to identify miscellaneous numerical properties. |
65 const char* BrowserThemeProvider::kDisplayPropertyNTPAlignment = | 65 const char* BrowserThemeProvider::kDisplayPropertyNTPAlignment = |
66 "ntp_background_alignment"; | 66 "ntp_background_alignment"; |
| 67 const char* BrowserThemeProvider::kDisplayPropertyNTPTiling = |
| 68 "ntp_background_repeat"; |
67 | 69 |
68 // Strings used in alignment properties. | 70 // Strings used in alignment properties. |
69 const char* BrowserThemeProvider::kAlignmentTop = "top"; | 71 const char* BrowserThemeProvider::kAlignmentTop = "top"; |
70 const char* BrowserThemeProvider::kAlignmentBottom = "bottom"; | 72 const char* BrowserThemeProvider::kAlignmentBottom = "bottom"; |
71 const char* BrowserThemeProvider::kAlignmentLeft = "left"; | 73 const char* BrowserThemeProvider::kAlignmentLeft = "left"; |
72 const char* BrowserThemeProvider::kAlignmentRight = "right"; | 74 const char* BrowserThemeProvider::kAlignmentRight = "right"; |
73 | 75 |
| 76 // Strings used in background tiling repetition properties. |
| 77 const char* BrowserThemeProvider::kTilingNoRepeat = "no-repeat"; |
| 78 const char* BrowserThemeProvider::kTilingRepeatX = "repeat-x"; |
| 79 const char* BrowserThemeProvider::kTilingRepeatY = "repeat-y"; |
| 80 const char* BrowserThemeProvider::kTilingRepeat = "repeat"; |
| 81 |
74 // Default colors. | 82 // Default colors. |
75 const SkColor BrowserThemeProvider::kDefaultColorFrame = | 83 const SkColor BrowserThemeProvider::kDefaultColorFrame = |
76 SkColorSetRGB(77, 139, 217); | 84 SkColorSetRGB(77, 139, 217); |
77 const SkColor BrowserThemeProvider::kDefaultColorFrameInactive = | 85 const SkColor BrowserThemeProvider::kDefaultColorFrameInactive = |
78 SkColorSetRGB(152, 188, 233); | 86 SkColorSetRGB(152, 188, 233); |
79 const SkColor BrowserThemeProvider::kDefaultColorFrameIncognito = | 87 const SkColor BrowserThemeProvider::kDefaultColorFrameIncognito = |
80 SkColorSetRGB(83, 106, 139); | 88 SkColorSetRGB(83, 106, 139); |
81 const SkColor BrowserThemeProvider::kDefaultColorFrameIncognitoInactive = | 89 const SkColor BrowserThemeProvider::kDefaultColorFrameIncognitoInactive = |
82 SkColorSetRGB(126, 139, 156); | 90 SkColorSetRGB(126, 139, 156); |
83 const SkColor BrowserThemeProvider::kDefaultColorToolbar = | 91 const SkColor BrowserThemeProvider::kDefaultColorToolbar = |
(...skipping 27 matching lines...) Expand all Loading... |
111 const skia::HSL BrowserThemeProvider::kDefaultTintFrameIncognito = | 119 const skia::HSL BrowserThemeProvider::kDefaultTintFrameIncognito = |
112 { -1, 0.2f, 0.35f }; | 120 { -1, 0.2f, 0.35f }; |
113 const skia::HSL BrowserThemeProvider::kDefaultTintFrameIncognitoInactive = | 121 const skia::HSL BrowserThemeProvider::kDefaultTintFrameIncognitoInactive = |
114 { -1, 0.3f, 0.6f }; | 122 { -1, 0.3f, 0.6f }; |
115 const skia::HSL BrowserThemeProvider::kDefaultTintBackgroundTab = | 123 const skia::HSL BrowserThemeProvider::kDefaultTintBackgroundTab = |
116 { -1, 0.5, 0.75 }; | 124 { -1, 0.5, 0.75 }; |
117 | 125 |
118 // Default display properties. | 126 // Default display properties. |
119 static const int kDefaultDisplayPropertyNTPAlignment = | 127 static const int kDefaultDisplayPropertyNTPAlignment = |
120 BrowserThemeProvider::ALIGN_BOTTOM; | 128 BrowserThemeProvider::ALIGN_BOTTOM; |
| 129 static const int kDefaultDisplayPropertyNTPTiling = |
| 130 BrowserThemeProvider::NO_REPEAT; |
121 | 131 |
122 // The image resources that will be tinted by the 'button' tint value. | 132 // The image resources that will be tinted by the 'button' tint value. |
123 static const int kToolbarButtonIDs[] = { | 133 static const int kToolbarButtonIDs[] = { |
124 IDR_BACK, IDR_BACK_D, IDR_BACK_H, IDR_BACK_P, | 134 IDR_BACK, IDR_BACK_D, IDR_BACK_H, IDR_BACK_P, |
125 IDR_FORWARD, IDR_FORWARD_D, IDR_FORWARD_H, IDR_FORWARD_P, | 135 IDR_FORWARD, IDR_FORWARD_D, IDR_FORWARD_H, IDR_FORWARD_P, |
126 IDR_RELOAD, IDR_RELOAD_H, IDR_RELOAD_P, | 136 IDR_RELOAD, IDR_RELOAD_H, IDR_RELOAD_P, |
127 IDR_HOME, IDR_HOME_H, IDR_HOME_P, | 137 IDR_HOME, IDR_HOME_H, IDR_HOME_P, |
128 IDR_STAR, IDR_STAR_NOBORDER, IDR_STAR_D, IDR_STAR_H, IDR_STAR_P, | 138 IDR_STAR, IDR_STAR_NOBORDER, IDR_STAR_D, IDR_STAR_H, IDR_STAR_P, |
129 IDR_STARRED, IDR_STARRED_NOBORDER, IDR_STARRED_H, IDR_STARRED_P, | 139 IDR_STARRED, IDR_STARRED_NOBORDER, IDR_STARRED_H, IDR_STARRED_P, |
130 IDR_GO, IDR_GO_H, IDR_GO_P, | 140 IDR_GO, IDR_GO_H, IDR_GO_P, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) { | 267 bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) { |
258 switch (id) { | 268 switch (id) { |
259 case NTP_BACKGROUND_ALIGNMENT: | 269 case NTP_BACKGROUND_ALIGNMENT: |
260 if (display_properties_.find(kDisplayPropertyNTPAlignment) != | 270 if (display_properties_.find(kDisplayPropertyNTPAlignment) != |
261 display_properties_.end()) { | 271 display_properties_.end()) { |
262 *result = display_properties_[kDisplayPropertyNTPAlignment]; | 272 *result = display_properties_[kDisplayPropertyNTPAlignment]; |
263 } else { | 273 } else { |
264 *result = kDefaultDisplayPropertyNTPAlignment; | 274 *result = kDefaultDisplayPropertyNTPAlignment; |
265 } | 275 } |
266 return true; | 276 return true; |
| 277 case NTP_BACKGROUND_TILING: |
| 278 if (display_properties_.find(kDisplayPropertyNTPTiling) != |
| 279 display_properties_.end()) { |
| 280 *result = display_properties_[kDisplayPropertyNTPTiling]; |
| 281 } else { |
| 282 *result = kDefaultDisplayPropertyNTPTiling; |
| 283 } |
| 284 return true; |
267 default: | 285 default: |
268 NOTREACHED() << "Unknown property requested"; | 286 NOTREACHED() << "Unknown property requested"; |
269 } | 287 } |
270 return false; | 288 return false; |
271 } | 289 } |
272 | 290 |
273 bool BrowserThemeProvider::ShouldUseNativeFrame() { | 291 bool BrowserThemeProvider::ShouldUseNativeFrame() { |
274 if (images_.find(IDR_THEME_FRAME) != images_.end()) | 292 if (images_.find(IDR_THEME_FRAME) != images_.end()) |
275 return false; | 293 return false; |
276 #if defined(OS_WIN) | 294 #if defined(OS_WIN) |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 518 |
501 void BrowserThemeProvider::SetDisplayPropertyData( | 519 void BrowserThemeProvider::SetDisplayPropertyData( |
502 DictionaryValue* display_properties_value) { | 520 DictionaryValue* display_properties_value) { |
503 display_properties_.clear(); | 521 display_properties_.clear(); |
504 | 522 |
505 if (!display_properties_value) | 523 if (!display_properties_value) |
506 return; | 524 return; |
507 | 525 |
508 DictionaryValue::key_iterator iter = display_properties_value->begin_keys(); | 526 DictionaryValue::key_iterator iter = display_properties_value->begin_keys(); |
509 while (iter != display_properties_value->end_keys()) { | 527 while (iter != display_properties_value->end_keys()) { |
510 // New tab page alignment. | 528 // New tab page alignment and background tiling. |
511 if (base::strcasecmp(WideToUTF8(*iter).c_str(), | 529 if (base::strcasecmp(WideToUTF8(*iter).c_str(), |
512 kDisplayPropertyNTPAlignment) == 0) { | 530 kDisplayPropertyNTPAlignment) == 0) { |
513 std::string val; | 531 std::string val; |
514 if (display_properties_value->GetString(*iter, &val)) | 532 if (display_properties_value->GetString(*iter, &val)) |
515 display_properties_[kDisplayPropertyNTPAlignment] = | 533 display_properties_[kDisplayPropertyNTPAlignment] = |
516 StringToAlignment(val); | 534 StringToAlignment(val); |
| 535 } else if (base::strcasecmp(WideToUTF8(*iter).c_str(), |
| 536 kDisplayPropertyNTPTiling) == 0) { |
| 537 std::string val; |
| 538 if (display_properties_value->GetString(*iter, &val)) |
| 539 display_properties_[kDisplayPropertyNTPTiling] = |
| 540 StringToTiling(val); |
517 } | 541 } |
518 ++iter; | 542 ++iter; |
519 } | 543 } |
520 } | 544 } |
521 | 545 |
522 // static | 546 // static |
523 int BrowserThemeProvider::StringToAlignment(const std::string& alignment) { | 547 int BrowserThemeProvider::StringToAlignment(const std::string& alignment) { |
524 std::vector<std::wstring> split; | 548 std::vector<std::wstring> split; |
525 SplitStringAlongWhitespace(UTF8ToWide(alignment), &split); | 549 SplitStringAlongWhitespace(UTF8ToWide(alignment), &split); |
526 | 550 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 horizontal_string = kAlignmentRight; | 585 horizontal_string = kAlignmentRight; |
562 | 586 |
563 if (!vertical_string.empty() && !horizontal_string.empty()) | 587 if (!vertical_string.empty() && !horizontal_string.empty()) |
564 return vertical_string + " " + horizontal_string; | 588 return vertical_string + " " + horizontal_string; |
565 else if (vertical_string.empty()) | 589 else if (vertical_string.empty()) |
566 return horizontal_string; | 590 return horizontal_string; |
567 else | 591 else |
568 return vertical_string; | 592 return vertical_string; |
569 } | 593 } |
570 | 594 |
| 595 // static |
| 596 int BrowserThemeProvider::StringToTiling(const std::string &tiling) { |
| 597 const char* component = tiling.c_str(); |
| 598 |
| 599 if (base::strcasecmp(component, kTilingRepeatX) == 0) |
| 600 return BrowserThemeProvider::REPEAT_X; |
| 601 else if (base::strcasecmp(component, kTilingRepeatY) == 0) |
| 602 return BrowserThemeProvider::REPEAT_Y; |
| 603 else if (base::strcasecmp(component, kTilingRepeat) == 0) |
| 604 return BrowserThemeProvider::REPEAT; |
| 605 // NO_REPEAT is the default choice. |
| 606 return BrowserThemeProvider::NO_REPEAT; |
| 607 } |
| 608 |
| 609 // static |
| 610 std::string BrowserThemeProvider::TilingToString(int tiling) { |
| 611 // Convert from a TilingProperty back into a string. |
| 612 if (tiling == BrowserThemeProvider::REPEAT_X) |
| 613 return kTilingRepeatX; |
| 614 else if (tiling == BrowserThemeProvider::REPEAT_Y) |
| 615 return kTilingRepeatY; |
| 616 else if (tiling == BrowserThemeProvider::REPEAT) |
| 617 return kTilingRepeat; |
| 618 else |
| 619 return kTilingNoRepeat; |
| 620 } |
| 621 |
571 void BrowserThemeProvider::SetColor(const char* key, const SkColor& color) { | 622 void BrowserThemeProvider::SetColor(const char* key, const SkColor& color) { |
572 colors_[key] = color; | 623 colors_[key] = color; |
573 } | 624 } |
574 | 625 |
575 void BrowserThemeProvider::SetTint(const char* key, const skia::HSL& tint) { | 626 void BrowserThemeProvider::SetTint(const char* key, const skia::HSL& tint) { |
576 tints_[key] = tint; | 627 tints_[key] = tint; |
577 } | 628 } |
578 | 629 |
579 void BrowserThemeProvider::GenerateFrameColors() { | 630 void BrowserThemeProvider::GenerateFrameColors() { |
580 // Generate any secondary frame colors that weren't provided. | 631 // Generate any secondary frame colors that weren't provided. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 pref_display_properties->Clear(); | 786 pref_display_properties->Clear(); |
736 | 787 |
737 if (display_properties_.size()) { | 788 if (display_properties_.size()) { |
738 DisplayPropertyMap::iterator iter = display_properties_.begin(); | 789 DisplayPropertyMap::iterator iter = display_properties_.begin(); |
739 while (iter != display_properties_.end()) { | 790 while (iter != display_properties_.end()) { |
740 if (base::strcasecmp((*iter).first.c_str(), | 791 if (base::strcasecmp((*iter).first.c_str(), |
741 kDisplayPropertyNTPAlignment) == 0) { | 792 kDisplayPropertyNTPAlignment) == 0) { |
742 pref_display_properties-> | 793 pref_display_properties-> |
743 SetString(UTF8ToWide((*iter).first), AlignmentToString( | 794 SetString(UTF8ToWide((*iter).first), AlignmentToString( |
744 (*iter).second)); | 795 (*iter).second)); |
| 796 } else if (base::strcasecmp((*iter).first.c_str(), |
| 797 kDisplayPropertyNTPTiling) == 0) { |
| 798 pref_display_properties-> |
| 799 SetString(UTF8ToWide((*iter).first), TilingToString( |
| 800 (*iter).second)); |
745 } | 801 } |
746 ++iter; | 802 ++iter; |
747 } | 803 } |
748 } | 804 } |
749 } | 805 } |
750 | 806 |
751 void BrowserThemeProvider::NotifyThemeChanged() { | 807 void BrowserThemeProvider::NotifyThemeChanged() { |
752 // Redraw! | 808 // Redraw! |
753 NotificationService* service = NotificationService::current(); | 809 NotificationService* service = NotificationService::current(); |
754 service->Notify(NotificationType::BROWSER_THEME_CHANGED, | 810 service->Notify(NotificationType::BROWSER_THEME_CHANGED, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 delete i->second; | 846 delete i->second; |
791 } | 847 } |
792 image_cache_.clear(); | 848 image_cache_.clear(); |
793 } | 849 } |
794 | 850 |
795 #if defined(TOOLKIT_VIEWS) | 851 #if defined(TOOLKIT_VIEWS) |
796 void BrowserThemeProvider::FreePlatformCaches() { | 852 void BrowserThemeProvider::FreePlatformCaches() { |
797 // Views (Skia) has no platform image cache to clear. | 853 // Views (Skia) has no platform image cache to clear. |
798 } | 854 } |
799 #endif | 855 #endif |
OLD | NEW |