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

Side by Side Diff: chrome/browser/extensions/extension_uninstall_dialog.cc

Issue 10915251: Fix for pixelated icons in extension install ui on 2x scale. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: default icons fix Created 8 years, 3 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 | Annotate | Revision Log
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 #include "chrome/browser/extensions/extension_uninstall_dialog.h" 5 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/common/chrome_notification_types.h" 9 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/common/extensions/extension.h" 10 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_constants.h" 11 #include "chrome/common/extensions/extension_constants.h"
12 #include "chrome/common/extensions/extension_icon_set.h" 12 #include "chrome/common/extensions/extension_icon_set.h"
13 #include "chrome/common/extensions/extension_resource.h" 13 #include "chrome/common/extensions/extension_resource.h"
14 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
16 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
17 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
18 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
20 20
21 namespace {
22
23 // Returns pixel size under maximal scale factor for the icon whose device
24 // independent size is |size_in_dip|
25 int GetSizeForMaxScaleFactor(int size_in_dip) {
26 std::vector<ui::ScaleFactor> supported_scale_factors =
27 ui::GetSupportedScaleFactors();
28 // Scale factors are in ascending order, so the last one is the one we need.
29 ui::ScaleFactor max_scale_factor =
30 supported_scale_factors[supported_scale_factors.size() - 1];
31 float max_scale_factor_scale = ui::GetScaleFactorScale(max_scale_factor);
32
33 return static_cast<int>(size_in_dip * max_scale_factor_scale);
34 }
35
36 // Returns bitmap for the default icon with size equal to the default icon's
37 // pixel size under maximal supported scale factor.
38 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
39 std::vector<ui::ScaleFactor> supported_scale_factors =
40 ui::GetSupportedScaleFactors();
41 // Scale factors are in ascending order, so the last one is the one we need.
42 ui::ScaleFactor max_scale_factor =
43 supported_scale_factors[supported_scale_factors.size() - 1];
Jeffrey Yasskin 2012/09/14 19:34:01 This should be written as supported_scale_factors.
tbarzic 2012/09/14 22:34:31 Done.
44
45 return extensions::Extension::GetDefaultIcon(is_app).
46 GetRepresentation(max_scale_factor).sk_bitmap();
47 }
48
49 } // namespace
50
21 // Size of extension icon in top left of dialog. 51 // Size of extension icon in top left of dialog.
22 static const int kIconSize = 69; 52 static const int kIconSize = 69;
23 53
24 ExtensionUninstallDialog::ExtensionUninstallDialog( 54 ExtensionUninstallDialog::ExtensionUninstallDialog(
25 Browser* browser, 55 Browser* browser,
26 ExtensionUninstallDialog::Delegate* delegate) 56 ExtensionUninstallDialog::Delegate* delegate)
27 : browser_(browser), 57 : browser_(browser),
28 delegate_(delegate), 58 delegate_(delegate),
29 extension_(NULL), 59 extension_(NULL),
30 ui_loop_(MessageLoop::current()) { 60 ui_loop_(MessageLoop::current()) {
(...skipping 10 matching lines...) Expand all
41 void ExtensionUninstallDialog::ConfirmUninstall( 71 void ExtensionUninstallDialog::ConfirmUninstall(
42 const extensions::Extension* extension) { 72 const extensions::Extension* extension) {
43 DCHECK(ui_loop_ == MessageLoop::current()); 73 DCHECK(ui_loop_ == MessageLoop::current());
44 extension_ = extension; 74 extension_ = extension;
45 75
46 ExtensionResource image = 76 ExtensionResource image =
47 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, 77 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE,
48 ExtensionIconSet::MATCH_BIGGER); 78 ExtensionIconSet::MATCH_BIGGER);
49 // Load the image asynchronously. The response will be sent to OnImageLoaded. 79 // Load the image asynchronously. The response will be sent to OnImageLoaded.
50 tracker_.reset(new ImageLoadingTracker(this)); 80 tracker_.reset(new ImageLoadingTracker(this));
81 // Load the icon whose pixel size is large enough to be displayed under
82 // maximal supported scale factor. UI code will scale the icon down if needed.
83 int pixel_size = GetSizeForMaxScaleFactor(kIconSize);
51 tracker_->LoadImage(extension_, image, 84 tracker_->LoadImage(extension_, image,
52 gfx::Size(kIconSize, kIconSize), 85 gfx::Size(pixel_size, pixel_size),
53 ImageLoadingTracker::DONT_CACHE); 86 ImageLoadingTracker::DONT_CACHE);
54 } 87 }
55 88
56 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { 89 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) {
57 if (image.IsEmpty()) { 90 if (image.IsEmpty()) {
58 if (extension_->is_app()) { 91 // Let's set default icon bitmap whose size is equal to the default icon's
59 icon_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 92 // pixel size under maximal supported scale factor. If the bitmap is larger
60 IDR_APP_DEFAULT_ICON); 93 // than the one we need, it will be scaled down by the ui code.
61 } else { 94 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app());
62 icon_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
63 IDR_EXTENSION_DEFAULT_ICON);
64 }
65 } else { 95 } else {
66 icon_ = *image.ToImageSkia(); 96 icon_ = *image.ToImageSkia();
67 } 97 }
68 } 98 }
69 99
70 void ExtensionUninstallDialog::OnImageLoaded(const gfx::Image& image, 100 void ExtensionUninstallDialog::OnImageLoaded(const gfx::Image& image,
71 const std::string& extension_id, 101 const std::string& extension_id,
72 int index) { 102 int index) {
73 SetIcon(image); 103 SetIcon(image);
74 104
(...skipping 11 matching lines...) Expand all
86 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSING); 116 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSING);
87 117
88 browser_ = NULL; 118 browser_ = NULL;
89 if (tracker_.get()) { 119 if (tracker_.get()) {
90 // If we're waiting for the icon, stop doing so because we're not going to 120 // If we're waiting for the icon, stop doing so because we're not going to
91 // show the dialog. 121 // show the dialog.
92 tracker_.reset(); 122 tracker_.reset();
93 delegate_->ExtensionUninstallCanceled(); 123 delegate_->ExtensionUninstallCanceled();
94 } 124 }
95 } 125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698