| 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 #ifndef CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ | 5 #ifndef CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ |
| 6 #define CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ | 6 #define CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 bool WriteToDisk(const base::FilePath& path) const; | 77 bool WriteToDisk(const base::FilePath& path) const; |
| 78 | 78 |
| 79 // If this theme specifies data for the corresponding |id|, return true and | 79 // If this theme specifies data for the corresponding |id|, return true and |
| 80 // write the corresponding value to the output parameter. These functions | 80 // write the corresponding value to the output parameter. These functions |
| 81 // don't return the default data. These methods should only be called from | 81 // don't return the default data. These methods should only be called from |
| 82 // the UI thread. (But this isn't enforced because of unit tests). | 82 // the UI thread. (But this isn't enforced because of unit tests). |
| 83 bool GetTint(int id, color_utils::HSL* hsl) const; | 83 bool GetTint(int id, color_utils::HSL* hsl) const; |
| 84 bool GetColor(int id, SkColor* color) const; | 84 bool GetColor(int id, SkColor* color) const; |
| 85 bool GetDisplayProperty(int id, int* result) const; | 85 bool GetDisplayProperty(int id, int* result) const; |
| 86 | 86 |
| 87 // Returns an image if we have a custom image for |id|, otherwise NULL. | 87 // Returns the theme pack image for |id|. Returns an empty image if an image |
| 88 const gfx::Image* GetImageNamed(int id) const; | 88 // is not found. |
| 89 gfx::Image GetImageNamed(int id); |
| 89 | 90 |
| 90 // Returns the raw PNG encoded data for IDR_THEME_NTP_*. This method is only | 91 // Returns the raw PNG encoded data for IDR_THEME_NTP_*. This method is only |
| 91 // supposed to work for the NTP attribution and background resources. | 92 // supposed to work for the NTP attribution and background resources. |
| 92 base::RefCountedMemory* GetRawData(int id, | 93 base::RefCountedMemory* GetRawData(int id, |
| 93 ui::ScaleFactor scale_factor) const; | 94 ui::ScaleFactor scale_factor) const; |
| 94 | 95 |
| 95 // Returns the set of image idrs which can be overwritten by a user provided | 96 // Returns the set of image idrs which can be overwritten by a user provided |
| 96 // theme. | 97 // theme. |
| 97 static void GetThemeableImageIDRs(std::set<int>* result); | 98 static void GetThemeableImageIDRs(std::set<int>* result); |
| 98 | 99 |
| 99 // Whether this theme provides an image for |id|. | 100 // Whether this theme provides an image for |id|. |
| 100 bool HasCustomImage(int id) const; | 101 bool HasCustomImage(int id) const; |
| 101 | 102 |
| 102 private: | 103 private: |
| 103 friend struct content::BrowserThread::DeleteOnThread< | 104 friend struct content::BrowserThread::DeleteOnThread< |
| 104 content::BrowserThread::FILE>; | 105 content::BrowserThread::FILE>; |
| 105 friend class base::DeleteHelper<BrowserThemePack>; | 106 friend class base::DeleteHelper<BrowserThemePack>; |
| 106 friend class BrowserThemePackTest; | 107 friend class BrowserThemePackTest; |
| 107 | 108 |
| 108 // Cached images. We cache all retrieved and generated images and keep | 109 // Cached images. |
| 109 // track of the pointers. We own these and will delete them when we're done | 110 typedef std::map<int, gfx::Image> ImageCache; |
| 110 // using them. | |
| 111 typedef std::map<int, const gfx::Image*> ImageCache; | |
| 112 | 111 |
| 113 // The raw PNG memory associated with a certain id. | 112 // The raw PNG memory associated with a certain id. |
| 114 typedef std::map<int, scoped_refptr<base::RefCountedMemory> > RawImages; | 113 typedef std::map<int, scoped_refptr<base::RefCountedMemory> > RawImages; |
| 115 | 114 |
| 116 // The type passed to ui::DataPack::WritePack. | 115 // The type passed to ui::DataPack::WritePack. |
| 117 typedef std::map<uint16, base::StringPiece> RawDataForWriting; | 116 typedef std::map<uint16, base::StringPiece> RawDataForWriting; |
| 118 | 117 |
| 119 // An association between an id and the base::FilePath that has the image data
. | 118 // An association between an id and the base::FilePath that has the image data
. |
| 120 typedef std::map<int, base::FilePath> FilePathMap; | 119 typedef std::map<int, base::FilePath> FilePathMap; |
| 121 | 120 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // Loads the unmodified images packed in the extension to SkBitmaps. Returns | 153 // Loads the unmodified images packed in the extension to SkBitmaps. Returns |
| 155 // true if all images loaded. | 154 // true if all images loaded. |
| 156 bool LoadRawBitmapsTo(const FilePathMap& file_paths, | 155 bool LoadRawBitmapsTo(const FilePathMap& file_paths, |
| 157 ImageCache* image_cache); | 156 ImageCache* image_cache); |
| 158 | 157 |
| 159 // Populate |images| cache with empty gfx::Images. Image reps are lazily | 158 // Populate |images| cache with empty gfx::Images. Image reps are lazily |
| 160 // generated when an image rep is requested via ImageSkia::GetRepresentation. | 159 // generated when an image rep is requested via ImageSkia::GetRepresentation. |
| 161 // Source and destination is |images|. | 160 // Source and destination is |images|. |
| 162 void CreateImages(ImageCache* images) const; | 161 void CreateImages(ImageCache* images) const; |
| 163 | 162 |
| 163 // Crops images down to a size such that most of the cropped image will be |
| 164 // displayed in the UI. Cropping is useful because images from custom themes |
| 165 // can be of any size. Source and destination is |images|. |
| 166 void CropImages(ImageCache* images) const; |
| 167 |
| 164 // Creates tinted and composited frame images. Source and destination is | 168 // Creates tinted and composited frame images. Source and destination is |
| 165 // |images|. | 169 // |images|. |
| 166 void CreateFrameImages(ImageCache* images) const; | 170 void CreateFrameImages(ImageCache* images) const; |
| 167 | 171 |
| 168 // Creates button images tinted with |button_tint| and places them in | 172 // Creates button images tinted with |button_tint| and places them in |
| 169 // processed_images. | 173 // processed_images. |
| 170 void CreateTintedButtons(const color_utils::HSL& button_tint, | 174 void CreateTintedButtons(const color_utils::HSL& button_tint, |
| 171 ImageCache* processed_images) const; | 175 ImageCache* processed_images) const; |
| 172 | 176 |
| 173 // Creates the semi-transparent tab background images, putting the results | 177 // Creates the semi-transparent tab background images, putting the results |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 253 |
| 250 // References to raw PNG data. This map isn't touched when |data_pack_| is | 254 // References to raw PNG data. This map isn't touched when |data_pack_| is |
| 251 // non-NULL; |image_memory_| is only filled during BuildFromExtension(). Any | 255 // non-NULL; |image_memory_| is only filled during BuildFromExtension(). Any |
| 252 // image data that needs to be written to the DataPack during WriteToDisk() | 256 // image data that needs to be written to the DataPack during WriteToDisk() |
| 253 // needs to be in |image_memory_|. | 257 // needs to be in |image_memory_|. |
| 254 RawImages image_memory_; | 258 RawImages image_memory_; |
| 255 | 259 |
| 256 // Loaded images. These are loaded from |image_memory_|, from |data_pack_|, | 260 // Loaded images. These are loaded from |image_memory_|, from |data_pack_|, |
| 257 // and by BuildFromExtension(). These images should only be accessed on the UI | 261 // and by BuildFromExtension(). These images should only be accessed on the UI |
| 258 // thread. | 262 // thread. |
| 259 mutable ImageCache images_on_ui_thread_; | 263 ImageCache images_on_ui_thread_; |
| 260 | 264 |
| 261 // Cache of images created in BuildFromExtension(). Once the theme pack is | 265 // Cache of images created in BuildFromExtension(). Once the theme pack is |
| 262 // created, this cache should only be accessed on the file thread. There | 266 // created, this cache should only be accessed on the file thread. There |
| 263 // should be no IDs in |image_memory_| that are in |images_on_file_thread_| | 267 // should be no IDs in |image_memory_| that are in |images_on_file_thread_| |
| 264 // or vice versa. | 268 // or vice versa. |
| 265 ImageCache images_on_file_thread_; | 269 ImageCache images_on_file_thread_; |
| 266 | 270 |
| 267 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack); | 271 DISALLOW_COPY_AND_ASSIGN(BrowserThemePack); |
| 268 }; | 272 }; |
| 269 | 273 |
| 270 #endif // CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ | 274 #endif // CHROME_BROWSER_THEMES_BROWSER_THEME_PACK_H_ |
| OLD | NEW |