OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/themes/browser_theme_pack.h" | 5 #include "chrome/browser/themes/browser_theme_pack.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 { 39, IDR_MENU_DROPARROW, NULL }, | 156 { 39, IDR_MENU_DROPARROW, NULL }, |
157 { 40, IDR_THROBBER, NULL }, | 157 { 40, IDR_THROBBER, NULL }, |
158 { 41, IDR_THROBBER_WAITING, NULL }, | 158 { 41, IDR_THROBBER_WAITING, NULL }, |
159 { 42, IDR_THROBBER_LIGHT, NULL }, | 159 { 42, IDR_THROBBER_LIGHT, NULL }, |
160 { 43, IDR_TOOLBAR_BEZEL_HOVER, NULL }, | 160 { 43, IDR_TOOLBAR_BEZEL_HOVER, NULL }, |
161 { 44, IDR_TOOLBAR_BEZEL_PRESSED, NULL }, | 161 { 44, IDR_TOOLBAR_BEZEL_PRESSED, NULL }, |
162 { 45, IDR_TOOLS_BAR, NULL }, | 162 { 45, IDR_TOOLS_BAR, NULL }, |
163 }; | 163 }; |
164 const size_t kPersistingImagesLength = arraysize(kPersistingImages); | 164 const size_t kPersistingImagesLength = arraysize(kPersistingImages); |
165 | 165 |
166 #if defined(OS_WIN) && defined(USE_AURA) | 166 #if defined(OS_WIN) |
167 // Persistent theme ids for Windows AURA. | 167 // Persistent theme ids for Windows. |
168 const int PRS_THEME_FRAME_WIN = 100; | 168 const int PRS_THEME_FRAME_WIN = 100; |
169 const int PRS_THEME_FRAME_INACTIVE_WIN = 101; | 169 const int PRS_THEME_FRAME_INACTIVE_WIN = 101; |
170 const int PRS_THEME_FRAME_INCOGNITO_WIN = 102; | 170 const int PRS_THEME_FRAME_INCOGNITO_WIN = 102; |
171 const int PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN = 103; | 171 const int PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN = 103; |
172 const int PRS_THEME_TOOLBAR_WIN = 104; | 172 const int PRS_THEME_TOOLBAR_WIN = 104; |
173 const int PRS_THEME_TAB_BACKGROUND_WIN = 105; | 173 const int PRS_THEME_TAB_BACKGROUND_WIN = 105; |
174 const int PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN = 106; | 174 const int PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN = 106; |
175 | 175 |
176 // Persistent theme to resource id mapping for Windows AURA. | 176 // Persistent theme to resource id mapping for Windows AURA. |
177 PersistingImagesTable kPersistingImagesWinDesktopAura[] = { | 177 PersistingImagesTable kPersistingImagesWinDesktopAura[] = { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 215 } |
216 | 216 |
217 int GetPersistentIDByIDR(int idr) { | 217 int GetPersistentIDByIDR(int idr) { |
218 static std::map<int,int>* lookup_table = new std::map<int,int>(); | 218 static std::map<int,int>* lookup_table = new std::map<int,int>(); |
219 if (lookup_table->empty()) { | 219 if (lookup_table->empty()) { |
220 for (size_t i = 0; i < kPersistingImagesLength; ++i) { | 220 for (size_t i = 0; i < kPersistingImagesLength; ++i) { |
221 int idr = kPersistingImages[i].idr_id; | 221 int idr = kPersistingImages[i].idr_id; |
222 int prs_id = kPersistingImages[i].persistent_id; | 222 int prs_id = kPersistingImages[i].persistent_id; |
223 (*lookup_table)[idr] = prs_id; | 223 (*lookup_table)[idr] = prs_id; |
224 } | 224 } |
225 #if defined(OS_WIN) && defined(USE_AURA) | 225 #if defined(OS_WIN) |
226 for (size_t i = 0; i < kPersistingImagesWinDesktopAuraLength; ++i) { | 226 for (size_t i = 0; i < kPersistingImagesWinDesktopAuraLength; ++i) { |
227 int idr = kPersistingImagesWinDesktopAura[i].idr_id; | 227 int idr = kPersistingImagesWinDesktopAura[i].idr_id; |
228 int prs_id = kPersistingImagesWinDesktopAura[i].persistent_id; | 228 int prs_id = kPersistingImagesWinDesktopAura[i].persistent_id; |
229 (*lookup_table)[idr] = prs_id; | 229 (*lookup_table)[idr] = prs_id; |
230 } | 230 } |
231 #endif | 231 #endif |
232 } | 232 } |
233 std::map<int,int>::iterator it = lookup_table->find(idr); | 233 std::map<int,int>::iterator it = lookup_table->find(idr); |
234 return (it == lookup_table->end()) ? -1 : it->second; | 234 return (it == lookup_table->end()) ? -1 : it->second; |
235 } | 235 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // tint ID that should maybe be applied to it. | 335 // tint ID that should maybe be applied to it. |
336 IntToIntTable kFrameTintMap[] = { | 336 IntToIntTable kFrameTintMap[] = { |
337 { PRS_THEME_FRAME, ThemeProperties::TINT_FRAME }, | 337 { PRS_THEME_FRAME, ThemeProperties::TINT_FRAME }, |
338 { PRS_THEME_FRAME_INACTIVE, ThemeProperties::TINT_FRAME_INACTIVE }, | 338 { PRS_THEME_FRAME_INACTIVE, ThemeProperties::TINT_FRAME_INACTIVE }, |
339 { PRS_THEME_FRAME_OVERLAY, ThemeProperties::TINT_FRAME }, | 339 { PRS_THEME_FRAME_OVERLAY, ThemeProperties::TINT_FRAME }, |
340 { PRS_THEME_FRAME_OVERLAY_INACTIVE, | 340 { PRS_THEME_FRAME_OVERLAY_INACTIVE, |
341 ThemeProperties::TINT_FRAME_INACTIVE }, | 341 ThemeProperties::TINT_FRAME_INACTIVE }, |
342 { PRS_THEME_FRAME_INCOGNITO, ThemeProperties::TINT_FRAME_INCOGNITO }, | 342 { PRS_THEME_FRAME_INCOGNITO, ThemeProperties::TINT_FRAME_INCOGNITO }, |
343 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, | 343 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, |
344 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, | 344 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, |
345 #if defined(OS_WIN) && defined(USE_AURA) | 345 #if defined(OS_WIN) |
346 { PRS_THEME_FRAME_WIN, ThemeProperties::TINT_FRAME }, | 346 { PRS_THEME_FRAME_WIN, ThemeProperties::TINT_FRAME }, |
347 { PRS_THEME_FRAME_INACTIVE_WIN, ThemeProperties::TINT_FRAME_INACTIVE }, | 347 { PRS_THEME_FRAME_INACTIVE_WIN, ThemeProperties::TINT_FRAME_INACTIVE }, |
348 { PRS_THEME_FRAME_INCOGNITO_WIN, ThemeProperties::TINT_FRAME_INCOGNITO }, | 348 { PRS_THEME_FRAME_INCOGNITO_WIN, ThemeProperties::TINT_FRAME_INCOGNITO }, |
349 { PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN, | 349 { PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN, |
350 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, | 350 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, |
351 #endif | 351 #endif |
352 }; | 352 }; |
353 | 353 |
354 // Mapping used in GenerateTabBackgroundImages() to associate what frame image | 354 // Mapping used in GenerateTabBackgroundImages() to associate what frame image |
355 // goes with which tab background. | 355 // goes with which tab background. |
356 IntToIntTable kTabBackgroundMap[] = { | 356 IntToIntTable kTabBackgroundMap[] = { |
357 { PRS_THEME_TAB_BACKGROUND, PRS_THEME_FRAME }, | 357 { PRS_THEME_TAB_BACKGROUND, PRS_THEME_FRAME }, |
358 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO }, | 358 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO }, |
359 #if defined(OS_WIN) && defined(USE_AURA) | 359 #if defined(OS_WIN) |
360 { PRS_THEME_TAB_BACKGROUND_WIN, PRS_THEME_FRAME_WIN }, | 360 { PRS_THEME_TAB_BACKGROUND_WIN, PRS_THEME_FRAME_WIN }, |
361 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN, PRS_THEME_FRAME_INCOGNITO_WIN }, | 361 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN, PRS_THEME_FRAME_INCOGNITO_WIN }, |
362 #endif | 362 #endif |
363 }; | 363 }; |
364 | 364 |
365 struct CropEntry { | 365 struct CropEntry { |
366 int prs_id; | 366 int prs_id; |
367 | 367 |
368 // The maximum useful height of the image at |prs_id|. | 368 // The maximum useful height of the image at |prs_id|. |
369 int max_height; | 369 int max_height; |
(...skipping 13 matching lines...) Expand all Loading... |
383 struct CropEntry kImagesToCrop[] = { | 383 struct CropEntry kImagesToCrop[] = { |
384 { PRS_THEME_FRAME, 120, true }, | 384 { PRS_THEME_FRAME, 120, true }, |
385 { PRS_THEME_FRAME_INACTIVE, 120, true }, | 385 { PRS_THEME_FRAME_INACTIVE, 120, true }, |
386 { PRS_THEME_FRAME_INCOGNITO, 120, true }, | 386 { PRS_THEME_FRAME_INCOGNITO, 120, true }, |
387 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, 120, true }, | 387 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, 120, true }, |
388 { PRS_THEME_FRAME_OVERLAY, 120, true }, | 388 { PRS_THEME_FRAME_OVERLAY, 120, true }, |
389 { PRS_THEME_FRAME_OVERLAY_INACTIVE, 120, true }, | 389 { PRS_THEME_FRAME_OVERLAY_INACTIVE, 120, true }, |
390 { PRS_THEME_TOOLBAR, 200, false }, | 390 { PRS_THEME_TOOLBAR, 200, false }, |
391 { PRS_THEME_BUTTON_BACKGROUND, 60, false }, | 391 { PRS_THEME_BUTTON_BACKGROUND, 60, false }, |
392 { PRS_THEME_WINDOW_CONTROL_BACKGROUND, 50, false }, | 392 { PRS_THEME_WINDOW_CONTROL_BACKGROUND, 50, false }, |
393 #if defined(OS_WIN) && defined(USE_AURA) | 393 #if defined(OS_WIN) |
394 { PRS_THEME_TOOLBAR_WIN, 200, false } | 394 { PRS_THEME_TOOLBAR_WIN, 200, false } |
395 #endif | 395 #endif |
396 }; | 396 }; |
397 | 397 |
398 | 398 |
399 // A list of images that don't need tinting or any other modification and can | 399 // A list of images that don't need tinting or any other modification and can |
400 // be byte-copied directly into the finished DataPack. This should contain the | 400 // be byte-copied directly into the finished DataPack. This should contain the |
401 // persistent IDs for all themeable image IDs that aren't in kFrameTintMap, | 401 // persistent IDs for all themeable image IDs that aren't in kFrameTintMap, |
402 // kTabBackgroundMap or kImagesToCrop. | 402 // kTabBackgroundMap or kImagesToCrop. |
403 const int kPreloadIDs[] = { | 403 const int kPreloadIDs[] = { |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 | 763 |
764 // static | 764 // static |
765 void BrowserThemePack::GetThemeableImageIDRs(std::set<int>* result) { | 765 void BrowserThemePack::GetThemeableImageIDRs(std::set<int>* result) { |
766 if (!result) | 766 if (!result) |
767 return; | 767 return; |
768 | 768 |
769 result->clear(); | 769 result->clear(); |
770 for (size_t i = 0; i < kPersistingImagesLength; ++i) | 770 for (size_t i = 0; i < kPersistingImagesLength; ++i) |
771 result->insert(kPersistingImages[i].idr_id); | 771 result->insert(kPersistingImages[i].idr_id); |
772 | 772 |
773 #if defined(OS_WIN) && defined(USE_AURA) | 773 #if defined(OS_WIN) |
774 for (size_t i = 0; i < kPersistingImagesWinDesktopAuraLength; ++i) | 774 for (size_t i = 0; i < kPersistingImagesWinDesktopAuraLength; ++i) |
775 result->insert(kPersistingImagesWinDesktopAura[i].idr_id); | 775 result->insert(kPersistingImagesWinDesktopAura[i].idr_id); |
776 #endif | 776 #endif |
777 } | 777 } |
778 | 778 |
779 bool BrowserThemePack::WriteToDisk(const base::FilePath& path) const { | 779 bool BrowserThemePack::WriteToDisk(const base::FilePath& path) const { |
780 // Add resources for each of the property arrays. | 780 // Add resources for each of the property arrays. |
781 RawDataForWriting resources; | 781 RawDataForWriting resources; |
782 resources[kHeaderID] = base::StringPiece( | 782 resources[kHeaderID] = base::StringPiece( |
783 reinterpret_cast<const char*>(header_), sizeof(BrowserThemePackHeader)); | 783 reinterpret_cast<const char*>(header_), sizeof(BrowserThemePackHeader)); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 } | 1204 } |
1205 } | 1205 } |
1206 | 1206 |
1207 void BrowserThemePack::AddFileAtScaleToMap(const std::string& image_name, | 1207 void BrowserThemePack::AddFileAtScaleToMap(const std::string& image_name, |
1208 ui::ScaleFactor scale_factor, | 1208 ui::ScaleFactor scale_factor, |
1209 const base::FilePath& image_path, | 1209 const base::FilePath& image_path, |
1210 FilePathMap* file_paths) const { | 1210 FilePathMap* file_paths) const { |
1211 int id = GetPersistentIDByName(image_name); | 1211 int id = GetPersistentIDByName(image_name); |
1212 if (id != -1) | 1212 if (id != -1) |
1213 (*file_paths)[id][scale_factor] = image_path; | 1213 (*file_paths)[id][scale_factor] = image_path; |
1214 #if defined(OS_WIN) && defined(USE_AURA) | 1214 #if defined(OS_WIN) |
1215 id = GetPersistentIDByNameHelper(image_name, | 1215 id = GetPersistentIDByNameHelper(image_name, |
1216 kPersistingImagesWinDesktopAura, | 1216 kPersistingImagesWinDesktopAura, |
1217 kPersistingImagesWinDesktopAuraLength); | 1217 kPersistingImagesWinDesktopAuraLength); |
1218 if (id != -1) | 1218 if (id != -1) |
1219 (*file_paths)[id][scale_factor] = image_path; | 1219 (*file_paths)[id][scale_factor] = image_path; |
1220 #endif | 1220 #endif |
1221 } | 1221 } |
1222 | 1222 |
1223 void BrowserThemePack::BuildSourceImagesArray(const FilePathMap& file_paths) { | 1223 void BrowserThemePack::BuildSourceImagesArray(const FilePathMap& file_paths) { |
1224 std::vector<int> ids; | 1224 std::vector<int> ids; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 ImageCache temp_output; | 1332 ImageCache temp_output; |
1333 | 1333 |
1334 for (size_t i = 0; i < arraysize(kFrameTintMap); ++i) { | 1334 for (size_t i = 0; i < arraysize(kFrameTintMap); ++i) { |
1335 int prs_id = kFrameTintMap[i].key; | 1335 int prs_id = kFrameTintMap[i].key; |
1336 gfx::Image frame; | 1336 gfx::Image frame; |
1337 // If there's no frame image provided for the specified id, then load | 1337 // If there's no frame image provided for the specified id, then load |
1338 // the default provided frame. If that's not provided, skip this whole | 1338 // the default provided frame. If that's not provided, skip this whole |
1339 // thing and just use the default images. | 1339 // thing and just use the default images. |
1340 int prs_base_id = 0; | 1340 int prs_base_id = 0; |
1341 | 1341 |
1342 #if defined(OS_WIN) && defined(USE_AURA) | 1342 #if defined(OS_WIN) |
1343 if (prs_id == PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN) { | 1343 if (prs_id == PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN) { |
1344 prs_base_id = images->count(PRS_THEME_FRAME_INCOGNITO_WIN) ? | 1344 prs_base_id = images->count(PRS_THEME_FRAME_INCOGNITO_WIN) ? |
1345 PRS_THEME_FRAME_INCOGNITO_WIN : PRS_THEME_FRAME_WIN; | 1345 PRS_THEME_FRAME_INCOGNITO_WIN : PRS_THEME_FRAME_WIN; |
1346 } else if (prs_id == PRS_THEME_FRAME_INACTIVE_WIN) { | 1346 } else if (prs_id == PRS_THEME_FRAME_INACTIVE_WIN) { |
1347 prs_base_id = PRS_THEME_FRAME_WIN; | 1347 prs_base_id = PRS_THEME_FRAME_WIN; |
1348 } else if (prs_id == PRS_THEME_FRAME_INCOGNITO_WIN && | 1348 } else if (prs_id == PRS_THEME_FRAME_INCOGNITO_WIN && |
1349 !images->count(PRS_THEME_FRAME_INCOGNITO_WIN)) { | 1349 !images->count(PRS_THEME_FRAME_INCOGNITO_WIN)) { |
1350 prs_base_id = PRS_THEME_FRAME_WIN; | 1350 prs_base_id = PRS_THEME_FRAME_WIN; |
1351 } | 1351 } |
1352 #endif | 1352 #endif |
(...skipping 10 matching lines...) Expand all Loading... |
1363 prs_base_id = PRS_THEME_FRAME; | 1363 prs_base_id = PRS_THEME_FRAME; |
1364 } else { | 1364 } else { |
1365 prs_base_id = prs_id; | 1365 prs_base_id = prs_id; |
1366 } | 1366 } |
1367 } | 1367 } |
1368 if (images->count(prs_id)) { | 1368 if (images->count(prs_id)) { |
1369 frame = (*images)[prs_id]; | 1369 frame = (*images)[prs_id]; |
1370 } else if (prs_base_id != prs_id && images->count(prs_base_id)) { | 1370 } else if (prs_base_id != prs_id && images->count(prs_base_id)) { |
1371 frame = (*images)[prs_base_id]; | 1371 frame = (*images)[prs_base_id]; |
1372 } else if (prs_base_id == PRS_THEME_FRAME_OVERLAY) { | 1372 } else if (prs_base_id == PRS_THEME_FRAME_OVERLAY) { |
1373 #if defined(OS_WIN) && defined(USE_AURA) | 1373 #if defined(OS_WIN) |
1374 if (images->count(PRS_THEME_FRAME_WIN)) { | 1374 if (images->count(PRS_THEME_FRAME_WIN)) { |
1375 #else | 1375 #else |
1376 if (images->count(PRS_THEME_FRAME)) { | 1376 if (images->count(PRS_THEME_FRAME)) { |
1377 #endif | 1377 #endif |
1378 // If there is no theme overlay, don't tint the default frame, | 1378 // If there is no theme overlay, don't tint the default frame, |
1379 // because it will overwrite the custom frame image when we cache and | 1379 // because it will overwrite the custom frame image when we cache and |
1380 // reload from disk. | 1380 // reload from disk. |
1381 frame = gfx::Image(); | 1381 frame = gfx::Image(); |
1382 } | 1382 } |
1383 } else { | 1383 } else { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1607 false, | 1607 false, |
1608 &bitmap_data)) { | 1608 &bitmap_data)) { |
1609 NOTREACHED() << "Unable to encode theme image for prs_id=" | 1609 NOTREACHED() << "Unable to encode theme image for prs_id=" |
1610 << prs_id << " for scale_factor=" << scale_factors_[i]; | 1610 << prs_id << " for scale_factor=" << scale_factors_[i]; |
1611 break; | 1611 break; |
1612 } | 1612 } |
1613 image_memory_[scaled_raw_id] = | 1613 image_memory_[scaled_raw_id] = |
1614 base::RefCountedBytes::TakeVector(&bitmap_data); | 1614 base::RefCountedBytes::TakeVector(&bitmap_data); |
1615 } | 1615 } |
1616 } | 1616 } |
OLD | NEW |