summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_uninstall_dialog.cc
diff options
context:
space:
mode:
authortbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-15 10:50:50 +0000
committertbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-15 10:50:50 +0000
commitdd46a4ce7cf1de1f0eff98165c81c218503d1d12 (patch)
tree810aaff15a9bc0b2cd73ee9221ef69cb29ed7392 /chrome/browser/extensions/extension_uninstall_dialog.cc
parent932a94767b5b067f2e6845a5f56642e502a2c4ff (diff)
downloadchromium_src-dd46a4ce7cf1de1f0eff98165c81c218503d1d12.zip
chromium_src-dd46a4ce7cf1de1f0eff98165c81c218503d1d12.tar.gz
chromium_src-dd46a4ce7cf1de1f0eff98165c81c218503d1d12.tar.bz2
Fix for pixelated icons in extension install ui on 2x scale.
We should probably do something like https://chromiumcodereview.appspot.com/10917146/ (and add lazy representation loading for views), but for M23 timeframe this will also do. BUG=135268 TEST=manual TBR=aa@chromium.org Review URL: https://chromiumcodereview.appspot.com/10915251 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157000 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_uninstall_dialog.cc')
-rw-r--r--chrome/browser/extensions/extension_uninstall_dialog.cc47
1 files changed, 39 insertions, 8 deletions
diff --git a/chrome/browser/extensions/extension_uninstall_dialog.cc b/chrome/browser/extensions/extension_uninstall_dialog.cc
index 694d5d8..d46e002 100644
--- a/chrome/browser/extensions/extension_uninstall_dialog.cc
+++ b/chrome/browser/extensions/extension_uninstall_dialog.cc
@@ -18,6 +18,35 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
+namespace {
+
+// Returns pixel size under maximal scale factor for the icon whose device
+// independent size is |size_in_dip|
+int GetSizeForMaxScaleFactor(int size_in_dip) {
+ std::vector<ui::ScaleFactor> supported_scale_factors =
+ ui::GetSupportedScaleFactors();
+ // Scale factors are in ascending order, so the last one is the one we need.
+ ui::ScaleFactor max_scale_factor = supported_scale_factors.back();
+ float max_scale_factor_scale = ui::GetScaleFactorScale(max_scale_factor);
+
+ return static_cast<int>(size_in_dip * max_scale_factor_scale);
+}
+
+// Returns bitmap for the default icon with size equal to the default icon's
+// pixel size under maximal supported scale factor.
+SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
+ std::vector<ui::ScaleFactor> supported_scale_factors =
+ ui::GetSupportedScaleFactors();
+ // Scale factors are in ascending order, so the last one is the one we need.
+ ui::ScaleFactor max_scale_factor =
+ supported_scale_factors[supported_scale_factors.size() - 1];
+
+ return extensions::Extension::GetDefaultIcon(is_app).
+ GetRepresentation(max_scale_factor).sk_bitmap();
+}
+
+} // namespace
+
// Size of extension icon in top left of dialog.
static const int kIconSize = 69;
@@ -48,20 +77,22 @@ void ExtensionUninstallDialog::ConfirmUninstall(
ExtensionIconSet::MATCH_BIGGER);
// Load the image asynchronously. The response will be sent to OnImageLoaded.
tracker_.reset(new ImageLoadingTracker(this));
+ // Load the icon whose pixel size is large enough to be displayed under
+ // maximal supported scale factor. UI code will scale the icon down if needed.
+ int pixel_size = GetSizeForMaxScaleFactor(kIconSize);
tracker_->LoadImage(extension_, image,
- gfx::Size(kIconSize, kIconSize),
+ gfx::Size(pixel_size, pixel_size),
ImageLoadingTracker::DONT_CACHE);
}
void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) {
if (image.IsEmpty()) {
- if (extension_->is_app()) {
- icon_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IDR_APP_DEFAULT_ICON);
- } else {
- icon_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
- IDR_EXTENSION_DEFAULT_ICON);
- }
+ // Let's set default icon bitmap whose size is equal to the default icon's
+ // pixel size under maximal supported scale factor. If the bitmap is larger
+ // than the one we need, it will be scaled down by the ui code.
+ // TODO(tbarzic): We should use IconImage here and load the required bitmap
+ // lazily.
+ icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app());
} else {
icon_ = *image.ToImageSkia();
}