Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/browser_theme_provider.cc

Issue 258020: GTK: Refactor some things so GTK doesn't touch the on disk image cache. (Closed)
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/browser_theme_provider.h ('k') | chrome/browser/gtk/gtk_theme_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "app/gfx/skbitmap_operations.h" 7 #include "app/gfx/skbitmap_operations.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/gfx/png_decoder.h" 9 #include "base/gfx/png_decoder.h"
10 #include "base/gfx/png_encoder.h" 10 #include "base/gfx/png_encoder.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // generate and store. 325 // generate and store.
326 ImageCache::const_iterator found = image_cache_.find(id); 326 ImageCache::const_iterator found = image_cache_.find(id);
327 if (found != image_cache_.end()) 327 if (found != image_cache_.end())
328 return found->second; 328 return found->second;
329 329
330 scoped_ptr<SkBitmap> result; 330 scoped_ptr<SkBitmap> result;
331 331
332 // Try to load the image from the extension. 332 // Try to load the image from the extension.
333 result.reset(LoadThemeBitmap(id)); 333 result.reset(LoadThemeBitmap(id));
334 334
335 // If the extension doesn't provide the requested image, but has provided
336 // a custom frame, then we may be able to generate the image required.
337 if (!result.get())
338 result.reset(GenerateTabBackgroundBitmap(id));
339
340 // If we still don't have an image, load it from resourcebundle. 335 // If we still don't have an image, load it from resourcebundle.
341 if (!result.get()) 336 if (!result.get())
342 result.reset(new SkBitmap(*rb_.GetBitmapNamed(id))); 337 result.reset(new SkBitmap(*rb_.GetBitmapNamed(id)));
343 338
344 if (result.get()) { 339 if (result.get()) {
345 // If the requested image is part of the toolbar button set, and we have 340 // If the requested image is part of the toolbar button set, and we have
346 // a provided tint for that set, tint it appropriately. 341 // a provided tint for that set, tint it appropriately.
347 if (button_images_.count(id) && tints_.count(kTintButtons)) { 342 if (button_images_.count(id) && tints_.count(kTintButtons)) {
348 SkBitmap* tinted = 343 SkBitmap* tinted =
349 new SkBitmap(TintBitmap(*result.release(), TINT_BUTTONS)); 344 new SkBitmap(TintBitmap(*result.release(), TINT_BUTTONS));
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 // The requested image is a background tab. Get a frame to create the 1060 // The requested image is a background tab. Get a frame to create the
1066 // tab against. As themes don't use the glass frame, we don't have to 1061 // tab against. As themes don't use the glass frame, we don't have to
1067 // worry about compositing them together, as our default theme provides 1062 // worry about compositing them together, as our default theme provides
1068 // the necessary bitmaps. 1063 // the necessary bitmaps.
1069 if (!process_images_) { 1064 if (!process_images_) {
1070 scoped_ptr<SkBitmap> frame; 1065 scoped_ptr<SkBitmap> frame;
1071 frame.reset(LoadThemeBitmap(id)); 1066 frame.reset(LoadThemeBitmap(id));
1072 if (frame.get()) 1067 if (frame.get())
1073 themed_image_cache_[id] = new SkBitmap(*frame.get()); 1068 themed_image_cache_[id] = new SkBitmap(*frame.get());
1074 } else { 1069 } else {
1075 int base_id; 1070 SkBitmap* bg_tab = GenerateTabBackgroundBitmapImpl(id);
1076 std::string resource_name;
1077 if (id == IDR_THEME_TAB_BACKGROUND) {
1078 base_id = IDR_THEME_FRAME;
1079 resource_name = "theme_tab_background";
1080 } else {
1081 base_id = IDR_THEME_FRAME_INCOGNITO;
1082 resource_name = "theme_tab_background_incognito";
1083 }
1084 std::map<int, SkBitmap*>::iterator it = themed_image_cache_.find(base_id);
1085 if (it != themed_image_cache_.end()) {
1086 SkBitmap bg_tint = TintBitmap(*(it->second), TINT_BACKGROUND_TAB);
1087 int vertical_offset = HasCustomImage(id) ?
1088 kRestoredTabVerticalOffset : 0;
1089 SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap(
1090 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height()));
1091 1071
1092 // If they've provided a custom image, overlay it. 1072 if (bg_tab) {
1093 if (HasCustomImage(id)) { 1073 std::string resource_name;
1094 SkBitmap* overlay = LoadThemeBitmap(id); 1074 if (id == IDR_THEME_TAB_BACKGROUND) {
1095 if (overlay) { 1075 resource_name = "theme_tab_background";
1096 SkCanvas canvas(*bg_tab); 1076 } else {
1097 for (int x = 0; x < bg_tab->width(); x += overlay->width()) 1077 resource_name = "theme_tab_background_incognito";
1098 canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL);
1099 }
1100 } 1078 }
1101 1079
1102 themed_image_cache_[id] = bg_tab; 1080 themed_image_cache_[id] = bg_tab;
1103 SaveThemeBitmap(resource_name, id); 1081 SaveThemeBitmap(resource_name, id);
1104 return bg_tab; 1082 return bg_tab;
1105 } 1083 }
1106 } 1084 }
1107 } 1085 }
1108 return NULL; 1086 return NULL;
1109 } 1087 }
1110 1088
1089 SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmapImpl(int id) {
1090 int base_id;
1091 if (id == IDR_THEME_TAB_BACKGROUND) {
1092 base_id = IDR_THEME_FRAME;
1093 } else {
1094 base_id = IDR_THEME_FRAME_INCOGNITO;
1095 }
1096 std::map<int, SkBitmap*>::iterator it = themed_image_cache_.find(base_id);
1097 if (it != themed_image_cache_.end()) {
1098 SkBitmap bg_tint = TintBitmap(*(it->second), TINT_BACKGROUND_TAB);
1099 int vertical_offset = HasCustomImage(id) ?
1100 kRestoredTabVerticalOffset : 0;
1101 SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap(
1102 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height()));
1103
1104 // If they've provided a custom image, overlay it.
1105 if (HasCustomImage(id)) {
1106 SkBitmap* overlay = LoadThemeBitmap(id);
1107 if (overlay) {
1108 SkCanvas canvas(*bg_tab);
1109 for (int x = 0; x < bg_tab->width(); x += overlay->width())
1110 canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL);
1111 }
1112 }
1113
1114 return bg_tab;
1115 }
1116
1117 return NULL;
1118 }
1119
1111 void BrowserThemeProvider::SaveCachedImageData() { 1120 void BrowserThemeProvider::SaveCachedImageData() {
1112 DictionaryValue* pref_images = 1121 DictionaryValue* pref_images =
1113 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); 1122 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages);
1114 1123
1115 for (ImagesDiskCache::iterator it = images_disk_cache_.begin(); 1124 for (ImagesDiskCache::iterator it = images_disk_cache_.begin();
1116 it != images_disk_cache_.end(); it++) { 1125 it != images_disk_cache_.end(); it++) {
1117 std::wstring disk_path = it->first.ToWStringHack(); 1126 std::wstring disk_path = it->first.ToWStringHack();
1118 std::string pref_name = resource_names_[it->second]; 1127 std::string pref_name = resource_names_[it->second];
1119 pref_images->SetString(UTF8ToWide(pref_name), 1128 pref_images->SetString(UTF8ToWide(pref_name),
1120 WideToUTF8(disk_path)); 1129 WideToUTF8(disk_path));
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 } 1299 }
1291 image_cache_.clear(); 1300 image_cache_.clear();
1292 images_disk_cache_.clear(); 1301 images_disk_cache_.clear();
1293 } 1302 }
1294 1303
1295 #if defined(OS_WIN) 1304 #if defined(OS_WIN)
1296 void BrowserThemeProvider::FreePlatformCaches() { 1305 void BrowserThemeProvider::FreePlatformCaches() {
1297 // Views (Skia) has no platform image cache to clear. 1306 // Views (Skia) has no platform image cache to clear.
1298 } 1307 }
1299 #endif 1308 #endif
OLDNEW
« no previous file with comments | « chrome/browser/browser_theme_provider.h ('k') | chrome/browser/gtk/gtk_theme_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698