Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Side by Side Diff: ui/base/resource/resource_bundle.h

Issue 1689623004: Start removing enum ui::ResourceBundle::FontStyle, fix MacViews font sizes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix transcription error Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/default_style.h ('k') | ui/base/resource/resource_bundle.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 25 matching lines...) Expand all
36 36
37 namespace ui { 37 namespace ui {
38 38
39 class DataPack; 39 class DataPack;
40 class ResourceHandle; 40 class ResourceHandle;
41 41
42 // ResourceBundle is a central facility to load images and other resources, 42 // ResourceBundle is a central facility to load images and other resources,
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 // An enumeration of the various font styles used throughout Chrome. 46 // Legacy font size deltas. Consider these to be magic numbers. New code
47 // The following holds true for the font sizes: 47 // should declare their own size delta constant using an identifier that
48 // Small <= SmallBold <= Base <= Bold <= Medium <= MediumBold <= Large. 48 // imparts some semantic meaning.
49 static const int kSmallFontDelta = -1;
50 static const int kMediumFontDelta = 3;
51 static const int kLargeFontDelta = 8;
52
53 // 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.
49 enum FontStyle { 55 enum FontStyle {
50 // NOTE: depending upon the locale, using one of the *BoldFont below
51 // may *not* actually result in a bold font.
52 SmallFont, 56 SmallFont,
53 SmallBoldFont, 57 SmallBoldFont,
54 BaseFont, 58 BaseFont,
55 BoldFont, 59 BoldFont,
56 MediumFont, 60 MediumFont,
57 MediumBoldFont, 61 MediumBoldFont,
58 LargeFont, 62 LargeFont,
59 LargeBoldFont, 63 LargeBoldFont,
60 }; 64 };
61 65
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // nearest the scale factor |scale_factor|. 235 // nearest the scale factor |scale_factor|.
232 // Use ResourceHandle::SCALE_FACTOR_NONE for scale independent image resources 236 // Use ResourceHandle::SCALE_FACTOR_NONE for scale independent image resources
233 // (such as wallpaper). 237 // (such as wallpaper).
234 base::StringPiece GetRawDataResourceForScale(int resource_id, 238 base::StringPiece GetRawDataResourceForScale(int resource_id,
235 ScaleFactor scale_factor) const; 239 ScaleFactor scale_factor) const;
236 240
237 // Get a localized string given a message id. Returns an empty 241 // Get a localized string given a message id. Returns an empty
238 // string if the message_id is not found. 242 // string if the message_id is not found.
239 base::string16 GetLocalizedString(int message_id); 243 base::string16 GetLocalizedString(int message_id);
240 244
241 // Returns the font list for the specified style. 245 // 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.
247 const gfx::FontList& GetFontListWithDelta(
248 int size_delta,
249 gfx::Font::FontStyle style = gfx::Font::NORMAL);
250
251 // Returns the primary font from the FontList given by GetFontListWithDelta().
252 const gfx::Font& GetFontWithDelta(
253 int size_delta,
254 gfx::Font::FontStyle style = gfx::Font::NORMAL);
255
256 // Deprecated. Returns fonts using hard-coded size deltas implied by |style|.
242 const gfx::FontList& GetFontList(FontStyle style); 257 const gfx::FontList& GetFontList(FontStyle style);
243
244 // Returns the font for the specified style.
245 const gfx::Font& GetFont(FontStyle style); 258 const gfx::Font& GetFont(FontStyle style);
246 259
247 // Resets and reloads the cached fonts. This is useful when the fonts of the 260 // Resets and reloads the cached fonts. This is useful when the fonts of the
248 // system have changed, for example, when the locale has changed. 261 // system have changed, for example, when the locale has changed.
249 void ReloadFonts(); 262 void ReloadFonts();
250 263
251 // Overrides the path to the pak file from which the locale resources will be 264 // Overrides the path to the pak file from which the locale resources will be
252 // loaded. Pass an empty path to undo. 265 // loaded. Pass an empty path to undo.
253 void OverrideLocalePakForTest(const base::FilePath& pak_path); 266 void OverrideLocalePakForTest(const base::FilePath& pak_path);
254 267
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 void LoadTestResources(const base::FilePath& path, 347 void LoadTestResources(const base::FilePath& path,
335 const base::FilePath& locale_path); 348 const base::FilePath& locale_path);
336 349
337 // Unload the locale specific strings and prepares to load new ones. See 350 // Unload the locale specific strings and prepares to load new ones. See
338 // comments for ReloadLocaleResources(). 351 // comments for ReloadLocaleResources().
339 void UnloadLocaleResources(); 352 void UnloadLocaleResources();
340 353
341 // Initializes the font description of default gfx::FontList. 354 // Initializes the font description of default gfx::FontList.
342 void InitDefaultFontList(); 355 void InitDefaultFontList();
343 356
344 // Initializes all the gfx::FontList members if they haven't yet been
345 // initialized.
346 void LoadFontsIfNecessary();
347
348 // Fills the |bitmap| given the data file to look in and the |resource_id|. 357 // Fills the |bitmap| given the data file to look in and the |resource_id|.
349 // Returns false if the resource does not exist. 358 // Returns false if the resource does not exist.
350 // 359 //
351 // If the call succeeds, |fell_back_to_1x| indicates whether Chrome's custom 360 // If the call succeeds, |fell_back_to_1x| indicates whether Chrome's custom
352 // csCl PNG chunk is present (added by GRIT if it falls back to a 100% image). 361 // csCl PNG chunk is present (added by GRIT if it falls back to a 100% image).
353 bool LoadBitmap(const ResourceHandle& data_handle, 362 bool LoadBitmap(const ResourceHandle& data_handle,
354 int resource_id, 363 int resource_id,
355 SkBitmap* bitmap, 364 SkBitmap* bitmap,
356 bool* fell_back_to_1x) const; 365 bool* fell_back_to_1x) const;
357 366
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // The maximum scale factor currently loaded. 413 // The maximum scale factor currently loaded.
405 ScaleFactor max_scale_factor_; 414 ScaleFactor max_scale_factor_;
406 415
407 // Cached images. The ResourceBundle caches all retrieved images and keeps 416 // Cached images. The ResourceBundle caches all retrieved images and keeps
408 // ownership of the pointers. 417 // ownership of the pointers.
409 typedef std::map<int, gfx::Image> ImageMap; 418 typedef std::map<int, gfx::Image> ImageMap;
410 ImageMap images_; 419 ImageMap images_;
411 420
412 gfx::Image empty_image_; 421 gfx::Image empty_image_;
413 422
414 // The various font lists used. Cached to avoid repeated GDI 423 // The various font lists used, as a map from a signed size delta from the
415 // creation/destruction. 424 // platform base font size, plus style, to the FontList. Cached to avoid
416 scoped_ptr<gfx::FontList> base_font_list_; 425 // repeated GDI creation/destruction and font derivation.
417 scoped_ptr<gfx::FontList> bold_font_list_; 426 // Must be accessed only while holding |images_and_fonts_lock_|.
418 scoped_ptr<gfx::FontList> small_font_list_; 427 std::map<std::pair<int, gfx::Font::FontStyle>, gfx::FontList> font_cache_;
419 scoped_ptr<gfx::FontList> small_bold_font_list_;
420 scoped_ptr<gfx::FontList> medium_font_list_;
421 scoped_ptr<gfx::FontList> medium_bold_font_list_;
422 scoped_ptr<gfx::FontList> large_font_list_;
423 scoped_ptr<gfx::FontList> large_bold_font_list_;
424 scoped_ptr<gfx::FontList> web_font_list_;
425 428
426 base::FilePath overridden_pak_path_; 429 base::FilePath overridden_pak_path_;
427 430
428 IdToStringMap overridden_locale_strings_; 431 IdToStringMap overridden_locale_strings_;
429 432
430 DISALLOW_COPY_AND_ASSIGN(ResourceBundle); 433 DISALLOW_COPY_AND_ASSIGN(ResourceBundle);
431 }; 434 };
432 435
433 } // namespace ui 436 } // namespace ui
434 437
435 // TODO(beng): Someday, maybe, get rid of this. 438 // TODO(beng): Someday, maybe, get rid of this.
436 using ui::ResourceBundle; 439 using ui::ResourceBundle;
437 440
438 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_ 441 #endif // UI_BASE_RESOURCE_RESOURCE_BUNDLE_H_
OLDNEW
« no previous file with comments | « ui/base/default_style.h ('k') | ui/base/resource/resource_bundle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698