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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 } | 322 } |
323 | 323 |
324 return -1; | 324 return -1; |
325 } | 325 } |
326 | 326 |
327 struct IntToIntTable { | 327 struct IntToIntTable { |
328 int key; | 328 int key; |
329 int value; | 329 int value; |
330 }; | 330 }; |
331 | 331 |
332 // Mapping used in GenerateFrameImages() to associate frame images with the | 332 // Mapping used in CreateFrameImages() to associate frame images with the |
333 // tint ID that should maybe be applied to it. | 333 // tint ID that should maybe be applied to it. |
334 IntToIntTable kFrameTintMap[] = { | 334 IntToIntTable kFrameTintMap[] = { |
335 { PRS_THEME_FRAME, ThemeProperties::TINT_FRAME }, | 335 { PRS_THEME_FRAME, ThemeProperties::TINT_FRAME }, |
336 { PRS_THEME_FRAME_INACTIVE, ThemeProperties::TINT_FRAME_INACTIVE }, | 336 { PRS_THEME_FRAME_INACTIVE, ThemeProperties::TINT_FRAME_INACTIVE }, |
337 { PRS_THEME_FRAME_OVERLAY, ThemeProperties::TINT_FRAME }, | 337 { PRS_THEME_FRAME_OVERLAY, ThemeProperties::TINT_FRAME }, |
338 { PRS_THEME_FRAME_OVERLAY_INACTIVE, | 338 { PRS_THEME_FRAME_OVERLAY_INACTIVE, |
339 ThemeProperties::TINT_FRAME_INACTIVE }, | 339 ThemeProperties::TINT_FRAME_INACTIVE }, |
340 { PRS_THEME_FRAME_INCOGNITO, ThemeProperties::TINT_FRAME_INCOGNITO }, | 340 { PRS_THEME_FRAME_INCOGNITO, ThemeProperties::TINT_FRAME_INCOGNITO }, |
341 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, | 341 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, |
342 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, | 342 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, |
(...skipping 10 matching lines...) Expand all Loading... | |
353 // goes with which tab background. | 353 // goes with which tab background. |
354 IntToIntTable kTabBackgroundMap[] = { | 354 IntToIntTable kTabBackgroundMap[] = { |
355 { PRS_THEME_TAB_BACKGROUND, PRS_THEME_FRAME }, | 355 { PRS_THEME_TAB_BACKGROUND, PRS_THEME_FRAME }, |
356 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO }, | 356 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO }, |
357 #if defined(OS_WIN) && defined(USE_AURA) | 357 #if defined(OS_WIN) && defined(USE_AURA) |
358 { PRS_THEME_TAB_BACKGROUND_WIN, PRS_THEME_FRAME_WIN }, | 358 { PRS_THEME_TAB_BACKGROUND_WIN, PRS_THEME_FRAME_WIN }, |
359 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN, PRS_THEME_FRAME_INCOGNITO_WIN }, | 359 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN, PRS_THEME_FRAME_INCOGNITO_WIN }, |
360 #endif | 360 #endif |
361 }; | 361 }; |
362 | 362 |
363 struct CropEntry { | |
364 int prs_id; | |
365 | |
366 // The maximum useful height of the image at |prs_id|. | |
367 int max_height; | |
368 | |
369 // Whether cropping the image at |prs_id| should be skipped on OSes which | |
370 // have a frame border to the left and right of the web contents. | |
371 // This should be true for images which can be used to decorate the border to | |
372 // the left and the right of the web contents. | |
373 bool skip_if_frame_border; | |
374 }; | |
375 | |
376 // The images which should be cropped before being saved to the data pack. The | |
377 // maximum heights are meant to be conservative as to give room for the UI to | |
378 // change without the maximum heights having to be modified. | |
379 // |kThemePackVersion| must be incremented if any of the maximum heights below | |
380 // are modified. | |
381 struct CropEntry kImagesToCrop[] = { | |
382 { PRS_THEME_FRAME, 120, true }, | |
383 { PRS_THEME_FRAME_INACTIVE, 120, true }, | |
384 { PRS_THEME_FRAME_INCOGNITO, 120, true }, | |
385 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, 120, true }, | |
386 { PRS_THEME_FRAME_OVERLAY, 120, true }, | |
387 { PRS_THEME_FRAME_OVERLAY_INACTIVE, 120, true }, | |
388 { PRS_THEME_TOOLBAR, 200, false }, | |
389 { PRS_THEME_BUTTON_BACKGROUND, 60, false }, | |
390 { PRS_THEME_WINDOW_CONTROL_BACKGROUND, 50, false } | |
391 #if defined(OS_WIN) && defined(USE_AURA) | |
392 { PRS_THEME_TOOLBAR_WIN, 200, false } | |
393 #endif | |
394 }; | |
395 | |
363 | 396 |
364 // A list of images that don't need tinting or any other modification and can | 397 // A list of images that don't need tinting or any other modification and can |
365 // be byte-copied directly into the finished DataPack. This should contain the | 398 // be byte-copied directly into the finished DataPack. This should contain the |
366 // persistent IDs for all themeable image IDs that aren't in kFrameTintMap or | 399 // persistent IDs for all themeable image IDs that aren't in kFrameTintMap, |
367 // kTabBackgroundMap. | 400 // kTabBackgroundMap or kImagesToCrop. |
368 const int kPreloadIDs[] = { | 401 const int kPreloadIDs[] = { |
369 PRS_THEME_TOOLBAR, | |
370 PRS_THEME_NTP_BACKGROUND, | 402 PRS_THEME_NTP_BACKGROUND, |
371 PRS_THEME_BUTTON_BACKGROUND, | |
372 PRS_THEME_NTP_ATTRIBUTION, | 403 PRS_THEME_NTP_ATTRIBUTION, |
373 PRS_THEME_WINDOW_CONTROL_BACKGROUND, | 404 }; |
374 #if defined(OS_WIN) && defined(USE_AURA) | 405 |
375 PRS_THEME_TOOLBAR_WIN, | 406 // Returns true if this OS uses a browser frame which has a non zero width to |
407 // the left and the right of the web contents. | |
408 bool HasFrameBorder() { | |
409 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) | |
410 return false; | |
411 #else | |
412 return true; | |
376 #endif | 413 #endif |
377 }; | 414 } |
378 | 415 |
379 // Returns a piece of memory with the contents of the file |path|. | 416 // Returns a piece of memory with the contents of the file |path|. |
380 base::RefCountedMemory* ReadFileData(const base::FilePath& path) { | 417 base::RefCountedMemory* ReadFileData(const base::FilePath& path) { |
381 if (!path.empty()) { | 418 if (!path.empty()) { |
382 net::FileStream file(NULL); | 419 net::FileStream file(NULL); |
383 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; | 420 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; |
384 if (file.OpenSync(path, flags) == net::OK) { | 421 if (file.OpenSync(path, flags) == net::OK) { |
385 int64 avail = file.Available(); | 422 int64 avail = file.Available(); |
386 if (avail > 0 && avail < INT_MAX) { | 423 if (avail > 0 && avail < INT_MAX) { |
387 size_t size = static_cast<size_t>(avail); | 424 size_t size = static_cast<size_t>(avail); |
388 std::vector<unsigned char> raw_data; | 425 std::vector<unsigned char> raw_data; |
389 raw_data.resize(size); | 426 raw_data.resize(size); |
390 char* data = reinterpret_cast<char*>(&(raw_data.front())); | 427 char* data = reinterpret_cast<char*>(&(raw_data.front())); |
391 if (file.ReadUntilComplete(data, size) == avail) | 428 if (file.ReadUntilComplete(data, size) == avail) |
392 return base::RefCountedBytes::TakeVector(&raw_data); | 429 return base::RefCountedBytes::TakeVector(&raw_data); |
393 } | 430 } |
394 } | 431 } |
395 } | 432 } |
396 | 433 |
397 return NULL; | 434 return NULL; |
398 } | 435 } |
399 | 436 |
400 // Shifts an image's HSL values. The caller is responsible for deleting | 437 // Shifts an image's HSL values. The caller is responsible for deleting |
401 // the returned image. | 438 // the returned image. |
402 gfx::Image* CreateHSLShiftedImage(const gfx::Image& image, | 439 gfx::Image CreateHSLShiftedImage(const gfx::Image& image, |
403 const color_utils::HSL& hsl_shift) { | 440 const color_utils::HSL& hsl_shift) { |
404 const gfx::ImageSkia* src_image = image.ToImageSkia(); | 441 const gfx::ImageSkia* src_image = image.ToImageSkia(); |
405 return new gfx::Image(gfx::ImageSkiaOperations::CreateHSLShiftedImage( | 442 return gfx::Image(gfx::ImageSkiaOperations::CreateHSLShiftedImage( |
406 *src_image, hsl_shift)); | 443 *src_image, hsl_shift)); |
407 } | 444 } |
408 | 445 |
409 // A ImageSkiaSource that scales 100P image to the target scale factor | 446 // A ImageSkiaSource that scales 100P image to the target scale factor |
410 // if the ImageSkiaRep for the target scale factor isn't available. | 447 // if the ImageSkiaRep for the target scale factor isn't available. |
411 class ThemeImageSource: public gfx::ImageSkiaSource { | 448 class ThemeImageSource: public gfx::ImageSkiaSource { |
412 public: | 449 public: |
413 explicit ThemeImageSource(const gfx::ImageSkia& source) : source_(source) { | 450 explicit ThemeImageSource(const gfx::ImageSkia& source) : source_(source) { |
414 } | 451 } |
415 virtual ~ThemeImageSource() {} | 452 virtual ~ThemeImageSource() {} |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 } // namespace | 522 } // namespace |
486 | 523 |
487 BrowserThemePack::~BrowserThemePack() { | 524 BrowserThemePack::~BrowserThemePack() { |
488 if (!data_pack_.get()) { | 525 if (!data_pack_.get()) { |
489 delete header_; | 526 delete header_; |
490 delete [] tints_; | 527 delete [] tints_; |
491 delete [] colors_; | 528 delete [] colors_; |
492 delete [] display_properties_; | 529 delete [] display_properties_; |
493 delete [] source_images_; | 530 delete [] source_images_; |
494 } | 531 } |
495 | |
496 STLDeleteValues(&images_on_ui_thread_); | |
497 STLDeleteValues(&images_on_file_thread_); | |
498 } | 532 } |
499 | 533 |
500 // static | 534 // static |
501 scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromExtension( | 535 scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromExtension( |
502 const Extension* extension) { | 536 const Extension* extension) { |
503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
504 DCHECK(extension); | 538 DCHECK(extension); |
505 DCHECK(extension->is_theme()); | 539 DCHECK(extension->is_theme()); |
506 | 540 |
507 scoped_refptr<BrowserThemePack> pack(new BrowserThemePack); | 541 scoped_refptr<BrowserThemePack> pack(new BrowserThemePack); |
508 pack->BuildHeader(extension); | 542 pack->BuildHeader(extension); |
509 pack->BuildTintsFromJSON(extensions::ThemeInfo::GetThemeTints(extension)); | 543 pack->BuildTintsFromJSON(extensions::ThemeInfo::GetThemeTints(extension)); |
510 pack->BuildColorsFromJSON(extensions::ThemeInfo::GetThemeColors(extension)); | 544 pack->BuildColorsFromJSON(extensions::ThemeInfo::GetThemeColors(extension)); |
511 pack->BuildDisplayPropertiesFromJSON( | 545 pack->BuildDisplayPropertiesFromJSON( |
512 extensions::ThemeInfo::GetThemeDisplayProperties(extension)); | 546 extensions::ThemeInfo::GetThemeDisplayProperties(extension)); |
513 | 547 |
514 // Builds the images. (Image building is dependent on tints). | 548 // Builds the images. (Image building is dependent on tints). |
515 FilePathMap file_paths; | 549 FilePathMap file_paths; |
516 pack->ParseImageNamesFromJSON( | 550 pack->ParseImageNamesFromJSON( |
517 extensions::ThemeInfo::GetThemeImages(extension), | 551 extensions::ThemeInfo::GetThemeImages(extension), |
518 extension->path(), | 552 extension->path(), |
519 &file_paths); | 553 &file_paths); |
520 pack->BuildSourceImagesArray(file_paths); | 554 pack->BuildSourceImagesArray(file_paths); |
521 | 555 |
522 if (!pack->LoadRawBitmapsTo(file_paths, &pack->images_on_ui_thread_)) | 556 if (!pack->LoadRawBitmapsTo(file_paths, &pack->images_on_ui_thread_)) |
523 return NULL; | 557 return NULL; |
524 | 558 |
525 pack->CopyImagesTo(pack->images_on_ui_thread_, &pack->images_on_file_thread_); | 559 pack->images_on_file_thread_ = pack->images_on_ui_thread_; |
526 | 560 |
527 pack->CreateImages(&pack->images_on_ui_thread_); | 561 pack->CreateImages(&pack->images_on_ui_thread_); |
528 pack->CreateImages(&pack->images_on_file_thread_); | 562 pack->CreateImages(&pack->images_on_file_thread_); |
Elliot Glaysher
2013/04/03 17:23:35
I think that somethings gone a little screwy here.
pkotwicz
2013/04/03 20:27:22
You are right that this is suboptimal. I will take
| |
529 | 563 |
530 // Make sure the |images_on_file_thread_| has bitmaps for supported | 564 // Make sure the |images_on_file_thread_| has bitmaps for supported |
531 // scale factors before passing to FILE thread. | 565 // scale factors before passing to FILE thread. |
532 for (ImageCache::iterator it = pack->images_on_file_thread_.begin(); | 566 for (ImageCache::iterator it = pack->images_on_file_thread_.begin(); |
533 it != pack->images_on_file_thread_.end(); ++it) { | 567 it != pack->images_on_file_thread_.end(); ++it) { |
534 gfx::ImageSkia* image_skia = | 568 gfx::ImageSkia* image_skia = |
535 const_cast<gfx::ImageSkia*>(it->second->ToImageSkia()); | 569 const_cast<gfx::ImageSkia*>(it->second.ToImageSkia()); |
536 image_skia->MakeThreadSafe(); | 570 image_skia->MakeThreadSafe(); |
537 } | 571 } |
538 | 572 |
539 // The BrowserThemePack is now in a consistent state. | 573 // The BrowserThemePack is now in a consistent state. |
540 return pack; | 574 return pack; |
541 } | 575 } |
542 | 576 |
543 // static | 577 // static |
544 scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromDataPack( | 578 scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromDataPack( |
545 const base::FilePath& path, const std::string& expected_id) { | 579 const base::FilePath& path, const std::string& expected_id) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 if (display_properties_[i].id == id) { | 713 if (display_properties_[i].id == id) { |
680 *result = display_properties_[i].property; | 714 *result = display_properties_[i].property; |
681 return true; | 715 return true; |
682 } | 716 } |
683 } | 717 } |
684 } | 718 } |
685 | 719 |
686 return false; | 720 return false; |
687 } | 721 } |
688 | 722 |
689 const gfx::Image* BrowserThemePack::GetImageNamed(int idr_id) const { | 723 gfx::Image BrowserThemePack::GetImageNamed(int idr_id) { |
690 int prs_id = GetPersistentIDByIDR(idr_id); | 724 int prs_id = GetPersistentIDByIDR(idr_id); |
691 if (prs_id == -1) | 725 if (prs_id == -1) |
692 return NULL; | 726 return gfx::Image(); |
693 | 727 |
694 // Check if the image is cached. | 728 // Check if the image is cached. |
695 ImageCache::const_iterator image_iter = images_on_ui_thread_.find(prs_id); | 729 ImageCache::const_iterator image_iter = images_on_ui_thread_.find(prs_id); |
696 if (image_iter != images_on_ui_thread_.end()) | 730 if (image_iter != images_on_ui_thread_.end()) |
697 return image_iter->second; | 731 return image_iter->second; |
698 | 732 |
699 // TODO(pkotwicz): Do something better than loading the bitmaps | 733 // TODO(pkotwicz): Do something better than loading the bitmaps |
700 // for all the scale factors associated with |idr_id|. | 734 // for all the scale factors associated with |idr_id|. |
701 gfx::ImageSkia source_image_skia; | 735 gfx::ImageSkia source_image_skia; |
702 for (size_t i = 0; i < scale_factors_.size(); ++i) { | 736 for (size_t i = 0; i < scale_factors_.size(); ++i) { |
703 scoped_refptr<base::RefCountedMemory> memory = | 737 scoped_refptr<base::RefCountedMemory> memory = |
704 GetRawData(idr_id, scale_factors_[i]); | 738 GetRawData(idr_id, scale_factors_[i]); |
705 if (memory.get()) { | 739 if (memory.get()) { |
706 // Decode the PNG. | 740 // Decode the PNG. |
707 SkBitmap bitmap; | 741 SkBitmap bitmap; |
708 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), | 742 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), |
709 &bitmap)) { | 743 &bitmap)) { |
710 NOTREACHED() << "Unable to decode theme image resource " << idr_id | 744 NOTREACHED() << "Unable to decode theme image resource " << idr_id |
711 << " from saved DataPack."; | 745 << " from saved DataPack."; |
712 continue; | 746 continue; |
713 } | 747 } |
714 source_image_skia.AddRepresentation( | 748 source_image_skia.AddRepresentation( |
715 gfx::ImageSkiaRep(bitmap, scale_factors_[i])); | 749 gfx::ImageSkiaRep(bitmap, scale_factors_[i])); |
716 } | 750 } |
717 } | 751 } |
718 | 752 |
719 if (!source_image_skia.isNull()) { | 753 if (!source_image_skia.isNull()) { |
720 ThemeImageSource* source = new ThemeImageSource(source_image_skia); | 754 ThemeImageSource* source = new ThemeImageSource(source_image_skia); |
721 gfx::ImageSkia image_skia(source, source_image_skia.size()); | 755 gfx::ImageSkia image_skia(source, source_image_skia.size()); |
722 gfx::Image* ret = new gfx::Image(image_skia); | 756 gfx::Image ret = gfx::Image(image_skia); |
723 images_on_ui_thread_[prs_id] = ret; | 757 images_on_ui_thread_[prs_id] = ret; |
724 return ret; | 758 return ret; |
725 } | 759 } |
726 return NULL; | 760 return gfx::Image(); |
727 } | 761 } |
728 | 762 |
729 base::RefCountedMemory* BrowserThemePack::GetRawData( | 763 base::RefCountedMemory* BrowserThemePack::GetRawData( |
730 int idr_id, | 764 int idr_id, |
731 ui::ScaleFactor scale_factor) const { | 765 ui::ScaleFactor scale_factor) const { |
732 base::RefCountedMemory* memory = NULL; | 766 base::RefCountedMemory* memory = NULL; |
733 int prs_id = GetPersistentIDByIDR(idr_id); | 767 int prs_id = GetPersistentIDByIDR(idr_id); |
734 int raw_id = GetRawIDByPersistentID(prs_id, scale_factor); | 768 int raw_id = GetRawIDByPersistentID(prs_id, scale_factor); |
735 | 769 |
736 if (raw_id != -1) { | 770 if (raw_id != -1) { |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 | 1120 |
1087 if (is_copyable) { | 1121 if (is_copyable) { |
1088 int raw_id = GetRawIDByPersistentID(prs_id, ui::SCALE_FACTOR_100P); | 1122 int raw_id = GetRawIDByPersistentID(prs_id, ui::SCALE_FACTOR_100P); |
1089 image_memory_[raw_id] = raw_data; | 1123 image_memory_[raw_id] = raw_data; |
1090 } else if (raw_data.get() && raw_data->size()) { | 1124 } else if (raw_data.get() && raw_data->size()) { |
1091 // Decode the PNG. | 1125 // Decode the PNG. |
1092 SkBitmap bitmap; | 1126 SkBitmap bitmap; |
1093 if (gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(), | 1127 if (gfx::PNGCodec::Decode(raw_data->front(), raw_data->size(), |
1094 &bitmap)) { | 1128 &bitmap)) { |
1095 (*image_cache)[prs_id] = | 1129 (*image_cache)[prs_id] = |
1096 new gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(bitmap)); | 1130 gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(bitmap)); |
1097 } else { | 1131 } else { |
1098 NOTREACHED() << "Unable to decode theme image resource " << it->first; | 1132 NOTREACHED() << "Unable to decode theme image resource " << it->first; |
1099 } | 1133 } |
1100 } | 1134 } |
1101 } | 1135 } |
1102 | 1136 |
1103 return true; | 1137 return true; |
1104 } | 1138 } |
1105 | 1139 |
1106 void BrowserThemePack::CreateImages(ImageCache* images) const { | 1140 void BrowserThemePack::CreateImages(ImageCache* images) const { |
1141 CropImages(images); | |
1107 CreateFrameImages(images); | 1142 CreateFrameImages(images); |
1108 CreateTintedButtons(GetTintInternal(ThemeProperties::TINT_BUTTONS), images); | 1143 CreateTintedButtons(GetTintInternal(ThemeProperties::TINT_BUTTONS), images); |
1109 CreateTabBackgroundImages(images); | 1144 CreateTabBackgroundImages(images); |
1110 } | 1145 } |
1111 | 1146 |
1147 void BrowserThemePack::CropImages(ImageCache* images) const { | |
1148 bool has_frame_border = HasFrameBorder(); | |
1149 for (size_t i = 0; i < arraysize(kImagesToCrop); ++i) { | |
1150 if (has_frame_border && kImagesToCrop[i].skip_if_frame_border) | |
1151 continue; | |
1152 | |
1153 int prs_id = kImagesToCrop[i].prs_id; | |
1154 ImageCache::iterator it = images->find(prs_id); | |
1155 if (it == images->end()) | |
1156 continue; | |
1157 | |
1158 int crop_height = kImagesToCrop[i].max_height; | |
1159 gfx::ImageSkia image_skia = it->second.AsImageSkia(); | |
1160 (*images)[prs_id] = gfx::Image(gfx::ImageSkiaOperations::ExtractSubset( | |
1161 image_skia, gfx::Rect(0, 0, image_skia.width(), crop_height))); | |
1162 } | |
1163 } | |
1164 | |
1112 void BrowserThemePack::CreateFrameImages(ImageCache* images) const { | 1165 void BrowserThemePack::CreateFrameImages(ImageCache* images) const { |
1113 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1166 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1114 | 1167 |
1115 // Create all the output images in a separate cache and move them back into | 1168 // Create all the output images in a separate cache and move them back into |
1116 // the input images because there can be name collisions. | 1169 // the input images because there can be name collisions. |
1117 ImageCache temp_output; | 1170 ImageCache temp_output; |
1118 | 1171 |
1119 for (size_t i = 0; i < arraysize(kFrameTintMap); ++i) { | 1172 for (size_t i = 0; i < arraysize(kFrameTintMap); ++i) { |
1120 int prs_id = kFrameTintMap[i].key; | 1173 int prs_id = kFrameTintMap[i].key; |
1121 const gfx::Image* frame = NULL; | 1174 gfx::Image frame; |
1122 // If there's no frame image provided for the specified id, then load | 1175 // If there's no frame image provided for the specified id, then load |
1123 // the default provided frame. If that's not provided, skip this whole | 1176 // the default provided frame. If that's not provided, skip this whole |
1124 // thing and just use the default images. | 1177 // thing and just use the default images. |
1125 int prs_base_id = 0; | 1178 int prs_base_id = 0; |
1126 | 1179 |
1127 #if defined(OS_WIN) && defined(USE_AURA) | 1180 #if defined(OS_WIN) && defined(USE_AURA) |
1128 if (prs_id == PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN) { | 1181 if (prs_id == PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN) { |
1129 prs_base_id = images->count(PRS_THEME_FRAME_INCOGNITO_WIN) ? | 1182 prs_base_id = images->count(PRS_THEME_FRAME_INCOGNITO_WIN) ? |
1130 PRS_THEME_FRAME_INCOGNITO_WIN : PRS_THEME_FRAME_WIN; | 1183 PRS_THEME_FRAME_INCOGNITO_WIN : PRS_THEME_FRAME_WIN; |
1131 } else if (prs_id == PRS_THEME_FRAME_INACTIVE_WIN) { | 1184 } else if (prs_id == PRS_THEME_FRAME_INACTIVE_WIN) { |
(...skipping 24 matching lines...) Expand all Loading... | |
1156 frame = (*images)[prs_base_id]; | 1209 frame = (*images)[prs_base_id]; |
1157 } else if (prs_base_id == PRS_THEME_FRAME_OVERLAY) { | 1210 } else if (prs_base_id == PRS_THEME_FRAME_OVERLAY) { |
1158 #if defined(OS_WIN) && defined(USE_AURA) | 1211 #if defined(OS_WIN) && defined(USE_AURA) |
1159 if (images->count(PRS_THEME_FRAME_WIN)) { | 1212 if (images->count(PRS_THEME_FRAME_WIN)) { |
1160 #else | 1213 #else |
1161 if (images->count(PRS_THEME_FRAME)) { | 1214 if (images->count(PRS_THEME_FRAME)) { |
1162 #endif | 1215 #endif |
1163 // If there is no theme overlay, don't tint the default frame, | 1216 // If there is no theme overlay, don't tint the default frame, |
1164 // because it will overwrite the custom frame image when we cache and | 1217 // because it will overwrite the custom frame image when we cache and |
1165 // reload from disk. | 1218 // reload from disk. |
1166 frame = NULL; | 1219 frame = gfx::Image(); |
1167 } | 1220 } |
1168 } else { | 1221 } else { |
1169 // If the theme doesn't specify an image, then apply the tint to | 1222 // If the theme doesn't specify an image, then apply the tint to |
1170 // the default frame. | 1223 // the default frame. |
1171 frame = &rb.GetImageNamed(IDR_THEME_FRAME); | 1224 frame = rb.GetImageNamed(IDR_THEME_FRAME); |
1172 #if defined(OS_WIN) && defined(USE_AURA) | 1225 #if defined(OS_WIN) && defined(USE_AURA) |
1173 if (prs_id >= PRS_THEME_FRAME_WIN && | 1226 if (prs_id >= PRS_THEME_FRAME_WIN && |
1174 prs_id <= PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN) { | 1227 prs_id <= PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN) { |
1175 frame = &rb.GetImageNamed(IDR_THEME_FRAME_WIN); | 1228 frame = rb.GetImageNamed(IDR_THEME_FRAME_WIN); |
1176 } | 1229 } |
1177 #endif | 1230 #endif |
1178 } | 1231 } |
1179 if (frame) { | 1232 if (!frame.IsEmpty()) { |
1180 temp_output[prs_id] = CreateHSLShiftedImage( | 1233 temp_output[prs_id] = CreateHSLShiftedImage( |
1181 *frame, GetTintInternal(kFrameTintMap[i].value)); | 1234 frame, GetTintInternal(kFrameTintMap[i].value)); |
1182 } | 1235 } |
1183 } | 1236 } |
1184 MergeImageCaches(temp_output, images); | 1237 MergeImageCaches(temp_output, images); |
1185 } | 1238 } |
1186 | 1239 |
1187 void BrowserThemePack::CreateTintedButtons( | 1240 void BrowserThemePack::CreateTintedButtons( |
1188 const color_utils::HSL& button_tint, | 1241 const color_utils::HSL& button_tint, |
1189 ImageCache* processed_images) const { | 1242 ImageCache* processed_images) const { |
1190 if (button_tint.h != -1 || button_tint.s != -1 || button_tint.l != -1) { | 1243 if (button_tint.h != -1 || button_tint.s != -1 || button_tint.l != -1) { |
1191 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1244 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
(...skipping 17 matching lines...) Expand all Loading... | |
1209 void BrowserThemePack::CreateTabBackgroundImages(ImageCache* images) const { | 1262 void BrowserThemePack::CreateTabBackgroundImages(ImageCache* images) const { |
1210 ImageCache temp_output; | 1263 ImageCache temp_output; |
1211 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) { | 1264 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) { |
1212 int prs_id = kTabBackgroundMap[i].key; | 1265 int prs_id = kTabBackgroundMap[i].key; |
1213 int prs_base_id = kTabBackgroundMap[i].value; | 1266 int prs_base_id = kTabBackgroundMap[i].value; |
1214 | 1267 |
1215 // We only need to generate the background tab images if we were provided | 1268 // We only need to generate the background tab images if we were provided |
1216 // with a PRS_THEME_FRAME. | 1269 // with a PRS_THEME_FRAME. |
1217 ImageCache::const_iterator it = images->find(prs_base_id); | 1270 ImageCache::const_iterator it = images->find(prs_base_id); |
1218 if (it != images->end()) { | 1271 if (it != images->end()) { |
1219 const gfx::ImageSkia* image_to_tint = (it->second)->ToImageSkia(); | 1272 gfx::ImageSkia image_to_tint = (it->second).AsImageSkia(); |
1220 color_utils::HSL hsl_shift = GetTintInternal( | 1273 color_utils::HSL hsl_shift = GetTintInternal( |
1221 ThemeProperties::TINT_BACKGROUND_TAB); | 1274 ThemeProperties::TINT_BACKGROUND_TAB); |
1222 int vertical_offset = images->count(prs_id) | 1275 int vertical_offset = images->count(prs_id) |
1223 ? kRestoredTabVerticalOffset : 0; | 1276 ? kRestoredTabVerticalOffset : 0; |
1224 | 1277 |
1225 gfx::ImageSkia overlay; | 1278 gfx::ImageSkia overlay; |
1226 ImageCache::const_iterator overlay_it = images->find(prs_id); | 1279 ImageCache::const_iterator overlay_it = images->find(prs_id); |
1227 if (overlay_it != images->end()) | 1280 if (overlay_it != images->end()) |
1228 overlay = *overlay_it->second->ToImageSkia(); | 1281 overlay = overlay_it->second.AsImageSkia(); |
1229 | 1282 |
1230 gfx::ImageSkiaSource* source = new TabBackgroundImageSource( | 1283 gfx::ImageSkiaSource* source = new TabBackgroundImageSource( |
1231 *image_to_tint, overlay, hsl_shift, vertical_offset); | 1284 image_to_tint, overlay, hsl_shift, vertical_offset); |
1232 // ImageSkia takes ownership of |source|. | 1285 // ImageSkia takes ownership of |source|. |
1233 temp_output[prs_id] = new gfx::Image(gfx::ImageSkia(source, | 1286 temp_output[prs_id] = gfx::Image(gfx::ImageSkia(source, |
1234 image_to_tint->size())); | 1287 image_to_tint.size())); |
1235 } | 1288 } |
1236 } | 1289 } |
1237 MergeImageCaches(temp_output, images); | 1290 MergeImageCaches(temp_output, images); |
1238 } | 1291 } |
1239 | 1292 |
1240 void BrowserThemePack::RepackImages(const ImageCache& images, | 1293 void BrowserThemePack::RepackImages(const ImageCache& images, |
1241 RawImages* reencoded_images) const { | 1294 RawImages* reencoded_images) const { |
1242 typedef std::vector<ui::ScaleFactor> ScaleFactors; | 1295 typedef std::vector<ui::ScaleFactor> ScaleFactors; |
1243 for (ImageCache::const_iterator it = images.begin(); | 1296 for (ImageCache::const_iterator it = images.begin(); |
1244 it != images.end(); ++it) { | 1297 it != images.end(); ++it) { |
1245 gfx::ImageSkia image_skia = *it->second->ToImageSkia(); | 1298 gfx::ImageSkia image_skia = *it->second.ToImageSkia(); |
1246 | 1299 |
1247 typedef std::vector<gfx::ImageSkiaRep> ImageSkiaReps; | 1300 typedef std::vector<gfx::ImageSkiaRep> ImageSkiaReps; |
1248 ImageSkiaReps image_reps = image_skia.image_reps(); | 1301 ImageSkiaReps image_reps = image_skia.image_reps(); |
1249 if (image_reps.empty()) { | 1302 if (image_reps.empty()) { |
1250 NOTREACHED() << "No image reps for resource " << it->first << "."; | 1303 NOTREACHED() << "No image reps for resource " << it->first << "."; |
1251 } | 1304 } |
1252 for (ImageSkiaReps::iterator rep_it = image_reps.begin(); | 1305 for (ImageSkiaReps::iterator rep_it = image_reps.begin(); |
1253 rep_it != image_reps.end(); ++rep_it) { | 1306 rep_it != image_reps.end(); ++rep_it) { |
1254 std::vector<unsigned char> bitmap_data; | 1307 std::vector<unsigned char> bitmap_data; |
1255 if (!gfx::PNGCodec::EncodeBGRASkBitmap(rep_it->sk_bitmap(), false, | 1308 if (!gfx::PNGCodec::EncodeBGRASkBitmap(rep_it->sk_bitmap(), false, |
1256 &bitmap_data)) { | 1309 &bitmap_data)) { |
1257 NOTREACHED() << "Image file for resource " << it->first | 1310 NOTREACHED() << "Image file for resource " << it->first |
1258 << " could not be encoded."; | 1311 << " could not be encoded."; |
1259 } | 1312 } |
1260 int raw_id = GetRawIDByPersistentID(it->first, rep_it->scale_factor()); | 1313 int raw_id = GetRawIDByPersistentID(it->first, rep_it->scale_factor()); |
1261 (*reencoded_images)[raw_id] = | 1314 (*reencoded_images)[raw_id] = |
1262 base::RefCountedBytes::TakeVector(&bitmap_data); | 1315 base::RefCountedBytes::TakeVector(&bitmap_data); |
1263 } | 1316 } |
1264 } | 1317 } |
1265 } | 1318 } |
1266 | 1319 |
1267 void BrowserThemePack::MergeImageCaches( | 1320 void BrowserThemePack::MergeImageCaches( |
1268 const ImageCache& source, ImageCache* destination) const { | 1321 const ImageCache& source, ImageCache* destination) const { |
1269 for (ImageCache::const_iterator it = source.begin(); it != source.end(); | 1322 for (ImageCache::const_iterator it = source.begin(); it != source.end(); |
1270 ++it) { | 1323 ++it) { |
1271 ImageCache::const_iterator image_it = destination->find(it->first); | |
1272 if (image_it != destination->end()) | |
1273 delete image_it->second; | |
1274 | |
1275 (*destination)[it->first] = it->second; | 1324 (*destination)[it->first] = it->second; |
1276 } | 1325 } |
1277 } | 1326 } |
1278 | 1327 |
1279 void BrowserThemePack::CopyImagesTo(const ImageCache& source, | |
1280 ImageCache* destination) const { | |
1281 for (ImageCache::const_iterator it = source.begin(); it != source.end(); | |
1282 ++it) { | |
1283 (*destination)[it->first] = new gfx::Image(*it->second); | |
1284 } | |
1285 } | |
1286 | |
1287 void BrowserThemePack::AddRawImagesTo(const RawImages& images, | 1328 void BrowserThemePack::AddRawImagesTo(const RawImages& images, |
1288 RawDataForWriting* out) const { | 1329 RawDataForWriting* out) const { |
1289 for (RawImages::const_iterator it = images.begin(); it != images.end(); | 1330 for (RawImages::const_iterator it = images.begin(); it != images.end(); |
1290 ++it) { | 1331 ++it) { |
1291 (*out)[it->first] = base::StringPiece( | 1332 (*out)[it->first] = base::StringPiece( |
1292 reinterpret_cast<const char*>(it->second->front()), it->second->size()); | 1333 reinterpret_cast<const char*>(it->second->front()), it->second->size()); |
1293 } | 1334 } |
1294 } | 1335 } |
1295 | 1336 |
1296 color_utils::HSL BrowserThemePack::GetTintInternal(int id) const { | 1337 color_utils::HSL BrowserThemePack::GetTintInternal(int id) const { |
(...skipping 17 matching lines...) Expand all Loading... | |
1314 ui::ScaleFactor scale_factor) const { | 1355 ui::ScaleFactor scale_factor) const { |
1315 if (prs_id < 0) | 1356 if (prs_id < 0) |
1316 return -1; | 1357 return -1; |
1317 | 1358 |
1318 for (size_t i = 0; i < scale_factors_.size(); ++i) { | 1359 for (size_t i = 0; i < scale_factors_.size(); ++i) { |
1319 if (scale_factors_[i] == scale_factor) | 1360 if (scale_factors_[i] == scale_factor) |
1320 return static_cast<int>(kPersistingImagesLength * i) + prs_id; | 1361 return static_cast<int>(kPersistingImagesLength * i) + prs_id; |
1321 } | 1362 } |
1322 return -1; | 1363 return -1; |
1323 } | 1364 } |
OLD | NEW |