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/string_util.h" |
8 #include "base/gfx/png_decoder.h" | 9 #include "base/gfx/png_decoder.h" |
9 #include "base/gfx/png_encoder.h" | 10 #include "base/gfx/png_encoder.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/browser_list.h" | 13 #include "chrome/browser/browser_list.h" |
13 #include "chrome/browser/browser_window.h" | 14 #include "chrome/browser/browser_window.h" |
14 #include "chrome/browser/metrics/user_metrics.h" | 15 #include "chrome/browser/metrics/user_metrics.h" |
15 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
16 #include "chrome/browser/theme_resources_util.h" | 17 #include "chrome/browser/theme_resources_util.h" |
17 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // Saved default values. | 139 // Saved default values. |
139 const char* BrowserThemeProvider::kDefaultThemeID = ""; | 140 const char* BrowserThemeProvider::kDefaultThemeID = ""; |
140 | 141 |
141 // Default display properties. | 142 // Default display properties. |
142 static const int kDefaultDisplayPropertyNTPAlignment = | 143 static const int kDefaultDisplayPropertyNTPAlignment = |
143 BrowserThemeProvider::ALIGN_BOTTOM; | 144 BrowserThemeProvider::ALIGN_BOTTOM; |
144 static const int kDefaultDisplayPropertyNTPTiling = | 145 static const int kDefaultDisplayPropertyNTPTiling = |
145 BrowserThemeProvider::NO_REPEAT; | 146 BrowserThemeProvider::NO_REPEAT; |
146 static const int kDefaultDisplayPropertyNTPInverseLogo = 0; | 147 static const int kDefaultDisplayPropertyNTPInverseLogo = 0; |
147 | 148 |
| 149 // The sum of kFrameBorderThickness and kNonClientRestoredExtraThickness from |
| 150 // OpaqueBrowserFrameView. |
| 151 static const int kRestoredTabVerticalOffset = 15; |
| 152 |
148 // The image resources that will be tinted by the 'button' tint value. | 153 // The image resources that will be tinted by the 'button' tint value. |
149 static const int kToolbarButtonIDs[] = { | 154 static const int kToolbarButtonIDs[] = { |
150 IDR_BACK, IDR_BACK_D, IDR_BACK_H, IDR_BACK_P, | 155 IDR_BACK, IDR_BACK_D, IDR_BACK_H, IDR_BACK_P, |
151 IDR_FORWARD, IDR_FORWARD_D, IDR_FORWARD_H, IDR_FORWARD_P, | 156 IDR_FORWARD, IDR_FORWARD_D, IDR_FORWARD_H, IDR_FORWARD_P, |
152 IDR_RELOAD, IDR_RELOAD_H, IDR_RELOAD_P, | 157 IDR_RELOAD, IDR_RELOAD_H, IDR_RELOAD_P, |
153 IDR_HOME, IDR_HOME_H, IDR_HOME_P, | 158 IDR_HOME, IDR_HOME_H, IDR_HOME_P, |
154 IDR_STAR, IDR_STAR_NOBORDER, IDR_STAR_NOBORDER_CENTER, IDR_STAR_D, IDR_STAR_H, | 159 IDR_STAR, IDR_STAR_NOBORDER, IDR_STAR_NOBORDER_CENTER, IDR_STAR_D, IDR_STAR_H, |
155 IDR_STAR_P, | 160 IDR_STAR_P, |
156 IDR_STARRED, IDR_STARRED_NOBORDER, IDR_STARRED_NOBORDER_CENTER, IDR_STARRED_H, | 161 IDR_STARRED, IDR_STARRED_NOBORDER, IDR_STARRED_NOBORDER_CENTER, IDR_STARRED_H, |
157 IDR_STARRED_P, | 162 IDR_STARRED_P, |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 return win_util::ShouldUseVistaFrame(); | 479 return win_util::ShouldUseVistaFrame(); |
475 #else | 480 #else |
476 return false; | 481 return false; |
477 #endif | 482 #endif |
478 } | 483 } |
479 | 484 |
480 bool BrowserThemeProvider::HasCustomImage(int id) { | 485 bool BrowserThemeProvider::HasCustomImage(int id) { |
481 if (!themeable_images_[id]) | 486 if (!themeable_images_[id]) |
482 return false; | 487 return false; |
483 | 488 |
484 return (images_.find(id) != images_.end()); | 489 // A custom image = base name is NOT equal to resource name. See note in |
| 490 // SaveThemeBitmap describing the process by which an original image is |
| 491 // tagged. |
| 492 if (images_.find(id) != images_.end() && |
| 493 resource_names_.find(id) != resource_names_.end()) |
| 494 return !EndsWith(UTF8ToWide(images_[id]), |
| 495 UTF8ToWide(resource_names_[id]), false); |
| 496 else |
| 497 return false; |
485 } | 498 } |
486 | 499 |
487 bool BrowserThemeProvider::GetRawData(int id, | 500 bool BrowserThemeProvider::GetRawData(int id, |
488 std::vector<unsigned char>* raw_data) { | 501 std::vector<unsigned char>* raw_data) { |
489 // Check to see whether we should substitute some images. | 502 // Check to see whether we should substitute some images. |
490 int ntp_alternate; | 503 int ntp_alternate; |
491 GetDisplayProperty(NTP_LOGO_ALTERNATE, &ntp_alternate); | 504 GetDisplayProperty(NTP_LOGO_ALTERNATE, &ntp_alternate); |
492 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) | 505 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) |
493 id = IDR_PRODUCT_LOGO_WHITE; | 506 id = IDR_PRODUCT_LOGO_WHITE; |
494 | 507 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 image_height); | 618 image_height); |
606 } else { | 619 } else { |
607 // TODO(glen): File no-longer exists, we're out of date. We should | 620 // TODO(glen): File no-longer exists, we're out of date. We should |
608 // clear the theme (or maybe just the pref that points to this | 621 // clear the theme (or maybe just the pref that points to this |
609 // image). | 622 // image). |
610 return NULL; | 623 return NULL; |
611 } | 624 } |
612 } | 625 } |
613 | 626 |
614 void BrowserThemeProvider::SaveThemeBitmap( | 627 void BrowserThemeProvider::SaveThemeBitmap( |
615 const std::string resource_name, int id) { | 628 std::string resource_name, int id) { |
616 DCHECK(CalledOnValidThread()); | 629 DCHECK(CalledOnValidThread()); |
617 if (!image_cache_[id]) { | 630 if (!image_cache_[id]) { |
618 NOTREACHED(); | 631 NOTREACHED(); |
619 return; | 632 return; |
620 } | 633 } |
621 | 634 |
| 635 // The images_ directory, at this point, contains only the custom images |
| 636 // provided by the extension. We tag these images "_original" in the prefs |
| 637 // file so we can distinguish them from images which have been generated and |
| 638 // saved to disk by the theme caching process (WriteImagesToDisk). This way, |
| 639 // when we call HasCustomImage, we can check for the "_original" tag to see |
| 640 // whether an image was originally provided by the extension, or saved |
| 641 // in the caching process. |
| 642 if (images_.find(id) != images_.end()) |
| 643 resource_name.append("_original"); |
| 644 |
622 #if defined(OS_WIN) | 645 #if defined(OS_WIN) |
623 FilePath image_path = image_dir_.Append(FilePath(UTF8ToWide(resource_name))); | 646 FilePath image_path = image_dir_.Append(UTF8ToWide(resource_name)); |
624 #elif defined(OS_POSIX) | 647 #elif defined(OS_POSIX) |
625 FilePath image_path = image_dir_.Append(FilePath(resource_name)); | 648 FilePath image_path = image_dir_.Append(resource_name); |
626 #endif | 649 #endif |
627 | 650 |
628 images_disk_cache_[image_path] = id; | 651 images_disk_cache_[image_path] = id; |
629 } | 652 } |
630 | 653 |
631 | 654 |
632 | 655 |
633 const std::string BrowserThemeProvider::GetTintKey(int id) { | 656 const std::string BrowserThemeProvider::GetTintKey(int id) { |
634 switch (id) { | 657 switch (id) { |
635 case TINT_FRAME: | 658 case TINT_FRAME: |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 std::string resource_name; | 1040 std::string resource_name; |
1018 if (id == IDR_THEME_TAB_BACKGROUND) { | 1041 if (id == IDR_THEME_TAB_BACKGROUND) { |
1019 base_id = IDR_THEME_FRAME; | 1042 base_id = IDR_THEME_FRAME; |
1020 resource_name = "theme_tab_background"; | 1043 resource_name = "theme_tab_background"; |
1021 } else { | 1044 } else { |
1022 base_id = IDR_THEME_FRAME_INCOGNITO; | 1045 base_id = IDR_THEME_FRAME_INCOGNITO; |
1023 resource_name = "theme_tab_background_incognito"; | 1046 resource_name = "theme_tab_background_incognito"; |
1024 } | 1047 } |
1025 std::map<int, SkBitmap*>::iterator it = image_cache_.find(base_id); | 1048 std::map<int, SkBitmap*>::iterator it = image_cache_.find(base_id); |
1026 if (it != image_cache_.end()) { | 1049 if (it != image_cache_.end()) { |
1027 SkBitmap* bg_tab = new SkBitmap(TintBitmap(*(it->second), | 1050 SkBitmap bg_tint = TintBitmap(*(it->second), TINT_BACKGROUND_TAB); |
1028 TINT_BACKGROUND_TAB)); | 1051 int vertical_offset = HasCustomImage(id) ? |
| 1052 kRestoredTabVerticalOffset : 0; |
| 1053 SkBitmap* bg_tab = new SkBitmap( |
| 1054 skia::ImageOperations::CreateTiledBitmap(bg_tint, 0, |
| 1055 vertical_offset, bg_tint.width(), bg_tint.height())); |
1029 | 1056 |
1030 // If they've provided a custom image, overlay it. | 1057 // If they've provided a custom image, overlay it. |
1031 if (HasCustomImage(id)) { | 1058 if (HasCustomImage(id)) { |
1032 SkBitmap* overlay = LoadThemeBitmap(id); | 1059 SkBitmap* overlay = LoadThemeBitmap(id); |
1033 if (overlay) { | 1060 if (overlay) { |
1034 SkCanvas canvas(*bg_tab); | 1061 SkCanvas canvas(*bg_tab); |
1035 for (int x = 0; x < bg_tab->width(); x += overlay->width()) | 1062 for (int x = 0; x < bg_tab->width(); x += overlay->width()) |
1036 canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL); | 1063 canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL); |
1037 } | 1064 } |
1038 } | 1065 } |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 } | 1239 } |
1213 image_cache_.clear(); | 1240 image_cache_.clear(); |
1214 images_disk_cache_.clear(); | 1241 images_disk_cache_.clear(); |
1215 } | 1242 } |
1216 | 1243 |
1217 #if defined(TOOLKIT_VIEWS) | 1244 #if defined(TOOLKIT_VIEWS) |
1218 void BrowserThemeProvider::FreePlatformCaches() { | 1245 void BrowserThemeProvider::FreePlatformCaches() { |
1219 // Views (Skia) has no platform image cache to clear. | 1246 // Views (Skia) has no platform image cache to clear. |
1220 } | 1247 } |
1221 #endif | 1248 #endif |
OLD | NEW |