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 11 matching lines...) Expand all Loading... |
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 | 27 |
28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
29 #include "app/win_util.h" | 29 #include "app/win_util.h" |
30 #endif | 30 #endif |
31 | 31 |
| 32 |
| 33 namespace themes { |
| 34 |
32 // Strings used by themes to identify colors for different parts of our UI. | 35 // Strings used by themes to identify colors for different parts of our UI. |
33 static const char* kColorFrame = "frame"; | 36 const char* kColorFrame = "frame"; |
34 static const char* kColorFrameInactive = "frame_inactive"; | 37 const char* kColorFrameInactive = "frame_inactive"; |
35 static const char* kColorFrameIncognito = "frame_incognito"; | 38 const char* kColorFrameIncognito = "frame_incognito"; |
36 static const char* kColorFrameIncognitoInactive = | 39 const char* kColorFrameIncognitoInactive = "frame_incognito_inactive"; |
37 "frame_incognito_inactive"; | 40 const char* kColorToolbar = "toolbar"; |
38 static const char* kColorToolbar = "toolbar"; | 41 const char* kColorTabText = "tab_text"; |
39 static const char* kColorTabText = "tab_text"; | 42 const char* kColorBackgroundTabText = "background_tab_text"; |
40 static const char* kColorBackgroundTabText = "background_tab_text"; | 43 const char* kColorBookmarkText = "bookmark_text"; |
41 static const char* kColorBookmarkText = "bookmark_text"; | 44 const char* kColorNTPBackground = "ntp_background"; |
42 static const char* kColorNTPBackground = "ntp_background"; | 45 const char* kColorNTPText = "ntp_text"; |
43 static const char* kColorNTPText = "ntp_text"; | 46 const char* kColorNTPLink = "ntp_link"; |
44 static const char* kColorNTPLink = "ntp_link"; | 47 const char* kColorNTPSection = "ntp_section"; |
45 static const char* kColorNTPSection = "ntp_section"; | 48 const char* kColorNTPSectionText = "ntp_section_text"; |
46 static const char* kColorNTPSectionText = "ntp_section_text"; | 49 const char* kColorNTPSectionLink = "ntp_section_link"; |
47 static const char* kColorNTPSectionLink = "ntp_section_link"; | 50 const char* kColorControlBackground = "control_background"; |
48 static const char* kColorControlBackground = "control_background"; | 51 const char* kColorButtonBackground = "button_background"; |
49 static const char* kColorButtonBackground = "button_background"; | |
50 | 52 |
51 // Strings used by themes to identify tints to apply to different parts of | 53 // Strings used by themes to identify tints to apply to different parts of |
52 // our UI. The frame tints apply to the frame color and produce the | 54 // our UI. The frame tints apply to the frame color and produce the |
53 // COLOR_FRAME* colors. | 55 // COLOR_FRAME* colors. |
54 static const char* kTintButtons = "buttons"; | 56 const char* kTintButtons = "buttons"; |
55 static const char* kTintFrame = "frame"; | 57 const char* kTintFrame = "frame"; |
56 static const char* kTintFrameInactive = "frame_inactive"; | 58 const char* kTintFrameInactive = "frame_inactive"; |
57 static const char* kTintFrameIncognito = "frame_incognito"; | 59 const char* kTintFrameIncognito = "frame_incognito"; |
58 static const char* kTintFrameIncognitoInactive = | 60 const char* kTintFrameIncognitoInactive = "frame_incognito_inactive"; |
59 "frame_incognito_inactive"; | 61 const char* kTintBackgroundTab = "background_tab"; |
60 static const char* kTintBackgroundTab = "background_tab"; | |
61 | 62 |
62 // Strings used by themes to identify miscellaneous numerical properties. | 63 // Strings used by themes to identify miscellaneous numerical properties. |
63 static const char* kDisplayPropertyNTPAlignment = "ntp_background_alignment"; | 64 const char* kDisplayPropertyNTPAlignment = "ntp_background_alignment"; |
64 | 65 |
65 // Strings used in alignment properties. | 66 // Strings used in alignment properties. |
66 static const char* kAlignmentTop = "top"; | 67 const char* kAlignmentTop = "top"; |
67 static const char* kAlignmentBottom = "bottom"; | 68 const char* kAlignmentBottom = "bottom"; |
68 static const char* kAlignmentLeft = "left"; | 69 const char* kAlignmentLeft = "left"; |
69 static const char* kAlignmentRight = "right"; | 70 const char* kAlignmentRight = "right"; |
70 | 71 |
71 // Default colors. | 72 // Default colors. |
72 static const SkColor kDefaultColorFrame = SkColorSetRGB(77, 139, 217); | 73 const SkColor kDefaultColorFrame = SkColorSetRGB(77, 139, 217); |
73 static const SkColor kDefaultColorFrameInactive = SkColorSetRGB(152, 188, 233); | 74 const SkColor kDefaultColorFrameInactive = SkColorSetRGB(152, 188, 233); |
74 static const SkColor kDefaultColorFrameIncognito = SkColorSetRGB(83, 106, 139); | 75 const SkColor kDefaultColorFrameIncognito = SkColorSetRGB(83, 106, 139); |
75 static const SkColor kDefaultColorFrameIncognitoInactive = | 76 const SkColor kDefaultColorFrameIncognitoInactive = |
76 SkColorSetRGB(126, 139, 156); | 77 SkColorSetRGB(126, 139, 156); |
77 static const SkColor kDefaultColorToolbar = SkColorSetRGB(210, 225, 246); | 78 const SkColor kDefaultColorToolbar = SkColorSetRGB(210, 225, 246); |
78 static const SkColor kDefaultColorTabText = SkColorSetRGB(0, 0, 0); | 79 const SkColor kDefaultColorTabText = SkColorSetRGB(0, 0, 0); |
79 static const SkColor kDefaultColorBackgroundTabText = SkColorSetRGB(64, 64, 64); | 80 const SkColor kDefaultColorBackgroundTabText = SkColorSetRGB(64, 64, 64); |
80 static const SkColor kDefaultColorBookmarkText = SkColorSetRGB(64, 64, 64); | 81 const SkColor kDefaultColorBookmarkText = SkColorSetRGB(64, 64, 64); |
81 static const SkColor kDefaultColorNTPBackground = SkColorSetRGB(255, 255, 255); | 82 const SkColor kDefaultColorNTPBackground = SkColorSetRGB(255, 255, 255); |
82 static const SkColor kDefaultColorNTPText = SkColorSetRGB(0, 0, 0); | 83 const SkColor kDefaultColorNTPText = SkColorSetRGB(0, 0, 0); |
83 static const SkColor kDefaultColorNTPLink = SkColorSetRGB(0, 0, 204); | 84 const SkColor kDefaultColorNTPLink = SkColorSetRGB(0, 0, 204); |
84 static const SkColor kDefaultColorNTPSection = SkColorSetRGB(225, 236, 254); | 85 const SkColor kDefaultColorNTPSection = SkColorSetRGB(225, 236, 254); |
85 static const SkColor kDefaultColorNTPSectionText = SkColorSetRGB(0, 0, 0); | 86 const SkColor kDefaultColorNTPSectionText = SkColorSetRGB(0, 0, 0); |
86 static const SkColor kDefaultColorNTPSectionLink = SkColorSetRGB(0, 0, 204); | 87 const SkColor kDefaultColorNTPSectionLink = SkColorSetRGB(0, 0, 204); |
87 static const SkColor kDefaultColorControlBackground = NULL; | 88 const SkColor kDefaultColorControlBackground = NULL; |
88 static const SkColor kDefaultColorButtonBackground = NULL; | 89 const SkColor kDefaultColorButtonBackground = NULL; |
89 | 90 |
90 // Default tints. | 91 // Default tints. |
91 static const skia::HSL kDefaultTintButtons = { -1, -1, -1 }; | 92 const skia::HSL kDefaultTintButtons = { -1, -1, -1 }; |
92 static const skia::HSL kDefaultTintFrame = { -1, -1, -1 }; | 93 const skia::HSL kDefaultTintFrame = { -1, -1, -1 }; |
93 static const skia::HSL kDefaultTintFrameInactive = { -1, 0.5f, 0.72f }; | 94 const skia::HSL kDefaultTintFrameInactive = { -1, 0.5f, 0.72f }; |
94 static const skia::HSL kDefaultTintFrameIncognito = { -1, 0.2f, 0.35f }; | 95 const skia::HSL kDefaultTintFrameIncognito = { -1, 0.2f, 0.35f }; |
95 static const skia::HSL kDefaultTintFrameIncognitoInactive = { -1, 0.3f, 0.6f }; | 96 const skia::HSL kDefaultTintFrameIncognitoInactive = { -1, 0.3f, 0.6f }; |
96 static const skia::HSL kDefaultTintBackgroundTab = { -1, 0.5, 0.75 }; | 97 const skia::HSL kDefaultTintBackgroundTab = { -1, 0.5, 0.75 }; |
| 98 } // namespace themes |
| 99 |
| 100 // We really want every member of the previous namespace to be exposed |
| 101 // here. The alternative is to list every member of namespace themes in a using |
| 102 // directive. |
| 103 using namespace themes; |
97 | 104 |
98 // Default display properties. | 105 // Default display properties. |
99 static const int kDefaultDisplayPropertyNTPAlignment = | 106 static const int kDefaultDisplayPropertyNTPAlignment = |
100 BrowserThemeProvider::ALIGN_BOTTOM; | 107 BrowserThemeProvider::ALIGN_BOTTOM; |
101 | 108 |
102 // The image resources that will be tinted by the 'button' tint value. | 109 // The image resources that will be tinted by the 'button' tint value. |
103 static const int kToolbarButtonIDs[] = { | 110 static const int kToolbarButtonIDs[] = { |
104 IDR_BACK, IDR_BACK_D, IDR_BACK_H, IDR_BACK_P, | 111 IDR_BACK, IDR_BACK_D, IDR_BACK_H, IDR_BACK_P, |
105 IDR_FORWARD, IDR_FORWARD_D, IDR_FORWARD_H, IDR_FORWARD_P, | 112 IDR_FORWARD, IDR_FORWARD_D, IDR_FORWARD_H, IDR_FORWARD_P, |
106 IDR_RELOAD, IDR_RELOAD_H, IDR_RELOAD_P, | 113 IDR_RELOAD, IDR_RELOAD_H, IDR_RELOAD_P, |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 SaveImageData(extension->GetThemeImages()); | 288 SaveImageData(extension->GetThemeImages()); |
282 SaveColorData(); | 289 SaveColorData(); |
283 SaveTintData(); | 290 SaveTintData(); |
284 SaveDisplayPropertyData(); | 291 SaveDisplayPropertyData(); |
285 | 292 |
286 NotifyThemeChanged(); | 293 NotifyThemeChanged(); |
287 UserMetrics::RecordAction(L"Themes_Installed", profile_); | 294 UserMetrics::RecordAction(L"Themes_Installed", profile_); |
288 } | 295 } |
289 | 296 |
290 void BrowserThemeProvider::UseDefaultTheme() { | 297 void BrowserThemeProvider::UseDefaultTheme() { |
291 // Clear our image cache. | 298 ClearAllThemeData(); |
292 ClearCaches(); | |
293 | |
294 images_.clear(); | |
295 colors_.clear(); | |
296 tints_.clear(); | |
297 display_properties_.clear(); | |
298 | |
299 SaveImageData(NULL); | |
300 SaveColorData(); | |
301 SaveTintData(); | |
302 SaveDisplayPropertyData(); | |
303 | |
304 NotifyThemeChanged(); | 299 NotifyThemeChanged(); |
305 UserMetrics::RecordAction(L"Themes_Reset", profile_); | 300 UserMetrics::RecordAction(L"Themes_Reset", profile_); |
306 } | 301 } |
307 | 302 |
308 bool BrowserThemeProvider::ReadThemeFileData( | 303 bool BrowserThemeProvider::ReadThemeFileData( |
309 int id, std::vector<unsigned char>* raw_data) { | 304 int id, std::vector<unsigned char>* raw_data) { |
310 if (images_.count(id)) { | 305 if (images_.count(id)) { |
311 // First check to see if we have a registered theme extension and whether | 306 // First check to see if we have a registered theme extension and whether |
312 // it can handle this resource. | 307 // it can handle this resource. |
313 #if defined(OS_WIN) | 308 #if defined(OS_WIN) |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 horizontal_string = kAlignmentRight; | 548 horizontal_string = kAlignmentRight; |
554 | 549 |
555 if (!vertical_string.empty() && !horizontal_string.empty()) | 550 if (!vertical_string.empty() && !horizontal_string.empty()) |
556 return vertical_string + " " + horizontal_string; | 551 return vertical_string + " " + horizontal_string; |
557 else if (vertical_string.empty()) | 552 else if (vertical_string.empty()) |
558 return horizontal_string; | 553 return horizontal_string; |
559 else | 554 else |
560 return vertical_string; | 555 return vertical_string; |
561 } | 556 } |
562 | 557 |
| 558 void BrowserThemeProvider::SetColor(const char* key, const SkColor& color) { |
| 559 colors_[kColorFrame] = color; |
| 560 } |
| 561 |
| 562 void BrowserThemeProvider::SetTint(const char* key, const skia::HSL& tint) { |
| 563 tints_[key] = tint; |
| 564 } |
| 565 |
563 void BrowserThemeProvider::GenerateFrameColors() { | 566 void BrowserThemeProvider::GenerateFrameColors() { |
564 // Generate any secondary frame colors that weren't provided. | 567 // Generate any secondary frame colors that weren't provided. |
565 skia::HSL frame_hsl = { 0, 0, 0 }; | 568 skia::HSL frame_hsl = { 0, 0, 0 }; |
566 skia::SkColorToHSL(GetColor(COLOR_FRAME), frame_hsl); | 569 skia::SkColorToHSL(GetColor(COLOR_FRAME), frame_hsl); |
567 | 570 |
568 if (colors_.find(kColorFrame) == colors_.end()) | 571 if (colors_.find(kColorFrame) == colors_.end()) |
569 colors_[kColorFrame] = HSLShift(frame_hsl, GetTint(TINT_FRAME)); | 572 colors_[kColorFrame] = HSLShift(frame_hsl, GetTint(TINT_FRAME)); |
570 if (colors_.find(kColorFrameInactive) == colors_.end()) { | 573 if (colors_.find(kColorFrameInactive) == colors_.end()) { |
571 colors_[kColorFrameInactive] = | 574 colors_[kColorFrameInactive] = |
572 HSLShift(frame_hsl, GetTint(TINT_FRAME_INACTIVE)); | 575 HSLShift(frame_hsl, GetTint(TINT_FRAME_INACTIVE)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 } | 609 } |
607 | 610 |
608 if (frame.get()) { | 611 if (frame.get()) { |
609 SkBitmap* tinted = new SkBitmap(TintBitmap(*frame, iter->second)); | 612 SkBitmap* tinted = new SkBitmap(TintBitmap(*frame, iter->second)); |
610 image_cache_[id] = tinted; | 613 image_cache_[id] = tinted; |
611 } | 614 } |
612 ++iter; | 615 ++iter; |
613 } | 616 } |
614 } | 617 } |
615 | 618 |
| 619 void BrowserThemeProvider::ClearAllThemeData() { |
| 620 // Clear our image cache. |
| 621 ClearCaches(); |
| 622 |
| 623 images_.clear(); |
| 624 colors_.clear(); |
| 625 tints_.clear(); |
| 626 display_properties_.clear(); |
| 627 |
| 628 SaveImageData(NULL); |
| 629 SaveColorData(); |
| 630 SaveTintData(); |
| 631 SaveDisplayPropertyData(); |
| 632 } |
| 633 |
616 SkBitmap* BrowserThemeProvider::GenerateBitmap(int id) { | 634 SkBitmap* BrowserThemeProvider::GenerateBitmap(int id) { |
617 if (id == IDR_THEME_TAB_BACKGROUND || | 635 if (id == IDR_THEME_TAB_BACKGROUND || |
618 id == IDR_THEME_TAB_BACKGROUND_INCOGNITO) { | 636 id == IDR_THEME_TAB_BACKGROUND_INCOGNITO) { |
619 // The requested image is a background tab. Get a frame to create the | 637 // The requested image is a background tab. Get a frame to create the |
620 // tab against. As themes don't use the glass frame, we don't have to | 638 // tab against. As themes don't use the glass frame, we don't have to |
621 // worry about compositing them together, as our default theme provides | 639 // worry about compositing them together, as our default theme provides |
622 // the necessary bitmaps. | 640 // the necessary bitmaps. |
623 int base_id = (id == IDR_THEME_TAB_BACKGROUND) ? | 641 int base_id = (id == IDR_THEME_TAB_BACKGROUND) ? |
624 IDR_THEME_FRAME : IDR_THEME_FRAME_INCOGNITO; | 642 IDR_THEME_FRAME : IDR_THEME_FRAME_INCOGNITO; |
625 | 643 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 delete i->second; | 774 delete i->second; |
757 } | 775 } |
758 image_cache_.clear(); | 776 image_cache_.clear(); |
759 } | 777 } |
760 | 778 |
761 #if defined(OS_WIN) | 779 #if defined(OS_WIN) |
762 void BrowserThemeProvider::FreePlatformCaches() { | 780 void BrowserThemeProvider::FreePlatformCaches() { |
763 // Windows has no platform image cache to clear. | 781 // Windows has no platform image cache to clear. |
764 } | 782 } |
765 #endif | 783 #endif |
OLD | NEW |