| 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/gfx/png_decoder.h" | 8 #include "base/gfx/png_decoder.h" |
| 9 #include "base/gfx/png_encoder.h" | 9 #include "base/gfx/png_encoder.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 SaveImageData(extension->GetThemeImages()); | 489 SaveImageData(extension->GetThemeImages()); |
| 490 SaveColorData(); | 490 SaveColorData(); |
| 491 SaveTintData(); | 491 SaveTintData(); |
| 492 SaveDisplayPropertyData(); | 492 SaveDisplayPropertyData(); |
| 493 SaveThemeID(extension->id()); | 493 SaveThemeID(extension->id()); |
| 494 | 494 |
| 495 // Process all images when we first set theme. | 495 // Process all images when we first set theme. |
| 496 process_images_ = true; | 496 process_images_ = true; |
| 497 | 497 |
| 498 GenerateFrameColors(); | 498 GenerateFrameColors(); |
| 499 GenerateFrameImages(); | 499 if (ShouldTintFrames()) { |
| 500 GenerateTabImages(); | 500 GenerateFrameImages(); |
| 501 WriteImagesToDisk(); | 501 GenerateTabImages(); |
| 502 WriteImagesToDisk(); |
| 503 } |
| 502 | 504 |
| 503 NotifyThemeChanged(); | 505 NotifyThemeChanged(); |
| 504 UserMetrics::RecordAction(L"Themes_Installed", profile_); | 506 UserMetrics::RecordAction(L"Themes_Installed", profile_); |
| 505 } | 507 } |
| 506 | 508 |
| 507 void BrowserThemeProvider::UseDefaultTheme() { | 509 void BrowserThemeProvider::UseDefaultTheme() { |
| 508 ClearAllThemeData(); | 510 ClearAllThemeData(); |
| 509 NotifyThemeChanged(); | 511 NotifyThemeChanged(); |
| 510 UserMetrics::RecordAction(L"Themes_Reset", profile_); | 512 UserMetrics::RecordAction(L"Themes_Reset", profile_); |
| 511 } | 513 } |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 } else if (base_id != id && HasCustomImage(base_id)) { | 919 } else if (base_id != id && HasCustomImage(base_id)) { |
| 918 frame.reset(LoadThemeBitmap(base_id)); | 920 frame.reset(LoadThemeBitmap(base_id)); |
| 919 } else if (base_id == IDR_THEME_FRAME_OVERLAY && | 921 } else if (base_id == IDR_THEME_FRAME_OVERLAY && |
| 920 HasCustomImage(IDR_THEME_FRAME)) { | 922 HasCustomImage(IDR_THEME_FRAME)) { |
| 921 // If there is no theme overlay, don't tint the default frame, | 923 // If there is no theme overlay, don't tint the default frame, |
| 922 // because it will overwrite the custom frame image when we cache and | 924 // because it will overwrite the custom frame image when we cache and |
| 923 // reload from disk. | 925 // reload from disk. |
| 924 frame.reset(NULL); | 926 frame.reset(NULL); |
| 925 } else { | 927 } else { |
| 926 // If the theme doesn't specify an image, then apply the tint to | 928 // If the theme doesn't specify an image, then apply the tint to |
| 927 // the default frame. Note that the default theme provides default | 929 // the default frame. |
| 928 // bitmaps for all frame types, so this isn't strictly necessary | |
| 929 // in the case where no tint is provided either. | |
| 930 frame.reset(new SkBitmap(*rb_.GetBitmapNamed(IDR_THEME_FRAME))); | 930 frame.reset(new SkBitmap(*rb_.GetBitmapNamed(IDR_THEME_FRAME))); |
| 931 } | 931 } |
| 932 | 932 |
| 933 if (frame.get()) { | 933 if (frame.get()) { |
| 934 SkBitmap* tinted = new SkBitmap(TintBitmap(*frame, iter->second)); | 934 SkBitmap* tinted = new SkBitmap(TintBitmap(*frame, iter->second)); |
| 935 image_cache_[id] = tinted; | 935 image_cache_[id] = tinted; |
| 936 SaveThemeBitmap(resource_name, id); | 936 SaveThemeBitmap(resource_name, id); |
| 937 } | 937 } |
| 938 } | 938 } |
| 939 ++iter; | 939 ++iter; |
| 940 } | 940 } |
| 941 } | 941 } |
| 942 | 942 |
| 943 bool BrowserThemeProvider::ShouldTintFrames() { |
| 944 return (HasCustomImage(IDR_THEME_FRAME) || |
| 945 tints_.find(GetTintKey(TINT_BACKGROUND_TAB)) != tints_.end() || |
| 946 tints_.find(GetTintKey(TINT_FRAME)) != tints_.end() || |
| 947 tints_.find(GetTintKey(TINT_FRAME_INACTIVE)) != tints_.end() || |
| 948 tints_.find(GetTintKey(TINT_FRAME_INCOGNITO)) != tints_.end() || |
| 949 tints_.find(GetTintKey(TINT_FRAME_INCOGNITO_INACTIVE)) != tints_.end()); |
| 950 } |
| 951 |
| 943 void BrowserThemeProvider::GenerateTabImages() { | 952 void BrowserThemeProvider::GenerateTabImages() { |
| 944 GenerateBitmap(IDR_THEME_TAB_BACKGROUND); | 953 GenerateBitmap(IDR_THEME_TAB_BACKGROUND); |
| 945 GenerateBitmap(IDR_THEME_TAB_BACKGROUND_INCOGNITO); | 954 GenerateBitmap(IDR_THEME_TAB_BACKGROUND_INCOGNITO); |
| 946 } | 955 } |
| 947 | 956 |
| 948 void BrowserThemeProvider::ClearAllThemeData() { | 957 void BrowserThemeProvider::ClearAllThemeData() { |
| 949 // Clear our image cache. | 958 // Clear our image cache. |
| 950 ClearCaches(); | 959 ClearCaches(); |
| 951 | 960 |
| 952 images_.clear(); | 961 images_.clear(); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 // the image_cache_, and have therefore all been deleted in the lines above. | 1162 // the image_cache_, and have therefore all been deleted in the lines above. |
| 1154 // TODO(mirandac): make memory management clearer here. | 1163 // TODO(mirandac): make memory management clearer here. |
| 1155 image_save_cache_.clear(); | 1164 image_save_cache_.clear(); |
| 1156 } | 1165 } |
| 1157 | 1166 |
| 1158 #if defined(TOOLKIT_VIEWS) | 1167 #if defined(TOOLKIT_VIEWS) |
| 1159 void BrowserThemeProvider::FreePlatformCaches() { | 1168 void BrowserThemeProvider::FreePlatformCaches() { |
| 1160 // Views (Skia) has no platform image cache to clear. | 1169 // Views (Skia) has no platform image cache to clear. |
| 1161 } | 1170 } |
| 1162 #endif | 1171 #endif |
| OLD | NEW |