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

Side by Side Diff: extensions/browser/extension_icon_placeholder.cc

Issue 2447553003: More pre-MD odds and ends. (Closed)
Patch Set: fix typo Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "extensions/browser/extension_icon_placeholder.h" 5 #include "extensions/browser/extension_icon_placeholder.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "extensions/grit/extensions_browser_resources.h" 9 #include "extensions/grit/extensions_browser_resources.h"
10 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/codec/png_codec.h" 12 #include "ui/gfx/codec/png_codec.h"
13 #include "ui/gfx/geometry/rect.h" 13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/size.h" 14 #include "ui/gfx/geometry/size.h"
15 #include "ui/gfx/image/canvas_image_source.h" 15 #include "ui/gfx/image/canvas_image_source.h"
16 #include "ui/gfx/image/image_skia.h" 16 #include "ui/gfx/image/image_skia.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 namespace { 20 namespace {
21 21
22 // Returns the FontStyle to use for the given icon |size|. 22 // Returns the FontStyle to use for the given icon |size|.
23 ui::ResourceBundle::FontStyle GetFontStyleForIconSize( 23 ui::ResourceBundle::FontStyle GetFontStyleForIconSize(
24 extension_misc::ExtensionIcons size) { 24 extension_misc::ExtensionIcons size) {
25 switch (size) { 25 switch (size) {
26 case extension_misc::EXTENSION_ICON_INVALID: 26 case extension_misc::EXTENSION_ICON_INVALID:
27 case extension_misc::EXTENSION_ICON_BITTY: 27 case extension_misc::EXTENSION_ICON_BITTY:
28 return ui::ResourceBundle::SmallFont; 28 return ui::ResourceBundle::SmallFont;
29 case extension_misc::EXTENSION_ICON_ACTION:
30 case extension_misc::EXTENSION_ICON_SMALLISH: 29 case extension_misc::EXTENSION_ICON_SMALLISH:
31 case extension_misc::EXTENSION_ICON_SMALL: 30 case extension_misc::EXTENSION_ICON_SMALL:
32 return ui::ResourceBundle::MediumFont; 31 return ui::ResourceBundle::MediumFont;
33 case extension_misc::EXTENSION_ICON_MEDIUM: 32 case extension_misc::EXTENSION_ICON_MEDIUM:
34 case extension_misc::EXTENSION_ICON_LARGE: 33 case extension_misc::EXTENSION_ICON_LARGE:
35 case extension_misc::EXTENSION_ICON_EXTRA_LARGE: 34 case extension_misc::EXTENSION_ICON_EXTRA_LARGE:
36 case extension_misc::EXTENSION_ICON_GIGANTOR: 35 case extension_misc::EXTENSION_ICON_GIGANTOR:
37 return ui::ResourceBundle::LargeFont; 36 return ui::ResourceBundle::LargeFont;
38 } 37 }
39 NOTREACHED(); 38 NOTREACHED();
40 return ui::ResourceBundle::MediumFont; 39 return ui::ResourceBundle::MediumFont;
41 } 40 }
42 41
43 // Returns the background image to use for the given icon |size|. 42 // Returns the background image to use for the given icon |size|.
44 gfx::Image GetBackgroundImageForIconSize(extension_misc::ExtensionIcons size) { 43 gfx::Image GetBackgroundImageForIconSize(extension_misc::ExtensionIcons size) {
45 int resource_id = 0; 44 int resource_id = 0;
46 // Right now, we have resources for a 19x19 (action) and a 48x48 (extensions 45 // Right now, we have resources for a 19x19 (action) and a 48x48 (extensions
47 // page icon). The implementation of the placeholder scales these correctly, 46 // page icon). The implementation of the placeholder scales these correctly,
48 // so it's not a big deal to use these for other sizes, but if it's something 47 // so it's not a big deal to use these for other sizes, but if it's something
49 // that will be done frequently, we should probably make a devoted asset for 48 // that will be done frequently, we should probably make a devoted asset for
50 // that size. 49 // that size.
51 switch (size) { 50 switch (size) {
52 case extension_misc::EXTENSION_ICON_INVALID: 51 case extension_misc::EXTENSION_ICON_INVALID:
53 case extension_misc::EXTENSION_ICON_BITTY: 52 case extension_misc::EXTENSION_ICON_BITTY:
54 case extension_misc::EXTENSION_ICON_ACTION:
55 case extension_misc::EXTENSION_ICON_SMALLISH: 53 case extension_misc::EXTENSION_ICON_SMALLISH:
56 case extension_misc::EXTENSION_ICON_SMALL: 54 case extension_misc::EXTENSION_ICON_SMALL:
57 resource_id = IDR_EXTENSION_ACTION_PLAIN_BACKGROUND; 55 resource_id = IDR_EXTENSION_ACTION_PLAIN_BACKGROUND;
58 break; 56 break;
59 case extension_misc::EXTENSION_ICON_MEDIUM: 57 case extension_misc::EXTENSION_ICON_MEDIUM:
60 case extension_misc::EXTENSION_ICON_LARGE: 58 case extension_misc::EXTENSION_ICON_LARGE:
61 case extension_misc::EXTENSION_ICON_EXTRA_LARGE: 59 case extension_misc::EXTENSION_ICON_EXTRA_LARGE:
62 case extension_misc::EXTENSION_ICON_GIGANTOR: 60 case extension_misc::EXTENSION_ICON_GIGANTOR:
63 resource_id = IDR_EXTENSION_ICON_PLAIN_BACKGROUND; 61 resource_id = IDR_EXTENSION_ICON_PLAIN_BACKGROUND;
64 break; 62 break;
(...skipping 29 matching lines...) Expand all
94 0, 0, size().width(), size().height(), true); 92 0, 0, size().width(), size().height(), true);
95 gfx::Rect bounds(size().width(), size().height()); 93 gfx::Rect bounds(size().width(), size().height());
96 // Draw the letter on top. 94 // Draw the letter on top.
97 canvas->DrawStringRectWithFlags( 95 canvas->DrawStringRectWithFlags(
98 letter_, ui::ResourceBundle::GetSharedInstance().GetFontList( 96 letter_, ui::ResourceBundle::GetSharedInstance().GetFontList(
99 GetFontStyleForIconSize(icon_size_)), 97 GetFontStyleForIconSize(icon_size_)),
100 SK_ColorWHITE, bounds, gfx::Canvas::TEXT_ALIGN_CENTER); 98 SK_ColorWHITE, bounds, gfx::Canvas::TEXT_ALIGN_CENTER);
101 } 99 }
102 100
103 } // namespace extensions 101 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/extension_action/page_action_manifest_unittest.cc ('k') | extensions/common/constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698