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 UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ | 5 #ifndef UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ |
6 #define UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ | 6 #define UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // such as theme graphics. Every resource is loaded only once. | 43 // such as theme graphics. Every resource is loaded only once. |
44 class UI_BASE_EXPORT ResourceBundle { | 44 class UI_BASE_EXPORT ResourceBundle { |
45 public: | 45 public: |
46 // Legacy font size deltas. Consider these to be magic numbers. New code | 46 // Legacy font size deltas. Consider these to be magic numbers. New code |
47 // should declare their own size delta constant using an identifier that | 47 // should declare their own size delta constant using an identifier that |
48 // imparts some semantic meaning. | 48 // imparts some semantic meaning. |
49 static const int kSmallFontDelta = -1; | 49 static const int kSmallFontDelta = -1; |
50 static const int kMediumFontDelta = 3; | 50 static const int kMediumFontDelta = 3; |
51 static const int kLargeFontDelta = 8; | 51 static const int kLargeFontDelta = 8; |
52 | 52 |
| 53 static constexpr const char* CUSTOM_GZIP_HEADER = "\xff\x1f\x8b"; |
| 54 |
53 // Legacy font style mappings. TODO(tapted): Phase these out in favour of | 55 // Legacy font style mappings. TODO(tapted): Phase these out in favour of |
54 // client code providing their own constant with the desired font size delta. | 56 // client code providing their own constant with the desired font size delta. |
55 enum FontStyle { | 57 enum FontStyle { |
56 SmallFont, | 58 SmallFont, |
57 SmallBoldFont, | 59 SmallBoldFont, |
58 BaseFont, | 60 BaseFont, |
59 BoldFont, | 61 BoldFont, |
60 MediumFont, | 62 MediumFont, |
61 MediumBoldFont, | 63 MediumBoldFont, |
62 LargeFont, | 64 LargeFont, |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // Similar to GetImageNamed, but rather than loading the image in Skia format, | 211 // Similar to GetImageNamed, but rather than loading the image in Skia format, |
210 // it will load in the native platform type. This can avoid conversion from | 212 // it will load in the native platform type. This can avoid conversion from |
211 // one image type to another. ResourceBundle owns the result. | 213 // one image type to another. ResourceBundle owns the result. |
212 // | 214 // |
213 // Note that if the same resource has already been loaded in GetImageNamed(), | 215 // Note that if the same resource has already been loaded in GetImageNamed(), |
214 // gfx::Image will perform a conversion, rather than using the native image | 216 // gfx::Image will perform a conversion, rather than using the native image |
215 // loading code of ResourceBundle. | 217 // loading code of ResourceBundle. |
216 gfx::Image& GetNativeImageNamed(int resource_id); | 218 gfx::Image& GetNativeImageNamed(int resource_id); |
217 | 219 |
218 // Loads the raw bytes of a scale independent data resource. | 220 // Loads the raw bytes of a scale independent data resource. |
| 221 // Will perform gzip decompression on any resource which has |
| 222 // ResourceBundle::CUSTOM_GZIP_HEADER as its first 3 bytes. |
| 223 // To compress a resource, add 'compress="gzip"' to that resource's .grd file. |
219 base::RefCountedMemory* LoadDataResourceBytes(int resource_id) const; | 224 base::RefCountedMemory* LoadDataResourceBytes(int resource_id) const; |
220 | 225 |
221 // Loads the raw bytes of a data resource nearest the scale factor | 226 // Loads the raw bytes of a data resource nearest the scale factor |
222 // |scale_factor| into |bytes|, without doing any processing or | 227 // |scale_factor| into |bytes|, without doing any processing or |
223 // interpretation of the resource. Use ResourceHandle::SCALE_FACTOR_NONE | 228 // interpretation of the resource. Use ResourceHandle::SCALE_FACTOR_NONE |
224 // for scale independent image resources (such as wallpaper). | 229 // for scale independent image resources (such as wallpaper). |
| 230 // Will perform gzip decompression on any resource which has |
| 231 // ResourceBundle::CUSTOM_GZIP_HEADER as its first 3 bytes. |
| 232 // To compress a resource, add 'compress="gzip"' to that resource's .grd file. |
225 // Returns NULL if we fail to read the resource. | 233 // Returns NULL if we fail to read the resource. |
226 base::RefCountedMemory* LoadDataResourceBytesForScale( | 234 base::RefCountedMemory* LoadDataResourceBytesForScale( |
227 int resource_id, | 235 int resource_id, |
228 ScaleFactor scale_factor) const; | 236 ScaleFactor scale_factor) const; |
229 | 237 |
230 // Return the contents of a scale independent resource in a | 238 // Return the contents of a scale independent resource in a |
231 // StringPiece given the resource id | 239 // StringPiece given the resource id. |
| 240 // NOTE: CHECKs to ensure this is not called on a resource which has |
| 241 // ResourceBundle::CUSTOM_GZIP_HEADER as its first 3 bytes. |
232 base::StringPiece GetRawDataResource(int resource_id) const; | 242 base::StringPiece GetRawDataResource(int resource_id) const; |
233 | 243 |
234 // Return the contents of a resource in a StringPiece given the resource id | 244 // Return the contents of a resource in a StringPiece given the resource id |
235 // nearest the scale factor |scale_factor|. | 245 // nearest the scale factor |scale_factor|. |
236 // Use ResourceHandle::SCALE_FACTOR_NONE for scale independent image resources | 246 // Use ResourceHandle::SCALE_FACTOR_NONE for scale independent image resources |
237 // (such as wallpaper). | 247 // (such as wallpaper). |
| 248 // NOTE: CHECKs to ensure this is not called on a resource which has |
| 249 // ResourceBundle::CUSTOM_GZIP_HEADER as its first 3 bytes. |
238 base::StringPiece GetRawDataResourceForScale(int resource_id, | 250 base::StringPiece GetRawDataResourceForScale(int resource_id, |
239 ScaleFactor scale_factor) const; | 251 ScaleFactor scale_factor) const; |
240 | 252 |
241 // Get a localized string given a message id. Returns an empty | 253 // Get a localized string given a message id. Returns an empty |
242 // string if the message_id is not found. | 254 // string if the message_id is not found. |
243 base::string16 GetLocalizedString(int message_id); | 255 base::string16 GetLocalizedString(int message_id); |
244 | 256 |
245 // Returns a font list derived from the platform-specific "Base" font list. | 257 // Returns a font list derived from the platform-specific "Base" font list. |
246 // The result is always cached and exists for the lifetime of the process. | 258 // The result is always cached and exists for the lifetime of the process. |
247 const gfx::FontList& GetFontListWithDelta( | 259 const gfx::FontList& GetFontListWithDelta( |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 387 |
376 // Fills the |bitmap| given the |resource_id| and |scale_factor|. | 388 // Fills the |bitmap| given the |resource_id| and |scale_factor|. |
377 // Returns false if the resource does not exist. This may fall back to | 389 // Returns false if the resource does not exist. This may fall back to |
378 // the data pack with SCALE_FACTOR_NONE, and when this happens, | 390 // the data pack with SCALE_FACTOR_NONE, and when this happens, |
379 // |scale_factor| will be set to SCALE_FACTOR_100P. | 391 // |scale_factor| will be set to SCALE_FACTOR_100P. |
380 bool LoadBitmap(int resource_id, | 392 bool LoadBitmap(int resource_id, |
381 ScaleFactor* scale_factor, | 393 ScaleFactor* scale_factor, |
382 SkBitmap* bitmap, | 394 SkBitmap* bitmap, |
383 bool* fell_back_to_1x) const; | 395 bool* fell_back_to_1x) const; |
384 | 396 |
| 397 // Loads the raw bytes of a data resource nearest the scale factor |
| 398 // |scale_factor| into |bytes|, without doing any processing or |
| 399 // interpretation of the resource. Use ResourceHandle::SCALE_FACTOR_NONE |
| 400 // for scale independent image resources (such as wallpaper). |
| 401 // Returns NULL if we fail to read the resource. |
| 402 base::StringPiece DoGetRawDataResourceForScale( |
| 403 int resource_id, |
| 404 ScaleFactor scale_factor) const; |
| 405 |
385 // Returns true if missing scaled resources should be visually indicated when | 406 // Returns true if missing scaled resources should be visually indicated when |
386 // drawing the fallback (e.g., by tinting the image). | 407 // drawing the fallback (e.g., by tinting the image). |
387 static bool ShouldHighlightMissingScaledResources(); | 408 static bool ShouldHighlightMissingScaledResources(); |
388 | 409 |
389 // Returns true if the data in |buf| is a PNG that has the special marker | 410 // Returns true if the data in |buf| is a PNG that has the special marker |
390 // added by GRIT that indicates that the image is actually 1x data. | 411 // added by GRIT that indicates that the image is actually 1x data. |
391 static bool PNGContainsFallbackMarker(const unsigned char* buf, size_t size); | 412 static bool PNGContainsFallbackMarker(const unsigned char* buf, size_t size); |
392 | 413 |
393 // A wrapper for PNGCodec::Decode that returns information about custom | 414 // A wrapper for PNGCodec::Decode that returns information about custom |
394 // chunks. For security reasons we can't alter PNGCodec to return this | 415 // chunks. For security reasons we can't alter PNGCodec to return this |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 464 |
444 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); | 465 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); |
445 }; | 466 }; |
446 | 467 |
447 } // namespace ui | 468 } // namespace ui |
448 | 469 |
449 // TODO(beng): Someday, maybe, get rid of this. | 470 // TODO(beng): Someday, maybe, get rid of this. |
450 using ui::ResourceBundle; | 471 using ui::ResourceBundle; |
451 | 472 |
452 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ | 473 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ |
OLD | NEW |