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

Unified Diff: chrome/browser/extensions/extension_install_prompt.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: .. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_uninstall_dialog.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_install_prompt.cc
diff --git a/chrome/browser/extensions/extension_install_prompt.cc b/chrome/browser/extensions/extension_install_prompt.cc
index 2e5c3241f1cd0eb8afe4f64f1712755a9b68081a..2113b174e8bc2b98e19a8e778bfe4adee3d5044c 100644
--- a/chrome/browser/extensions/extension_install_prompt.cc
+++ b/chrome/browser/extensions/extension_install_prompt.cc
@@ -95,6 +95,31 @@ namespace {
// Size of extension icon in top left of dialog.
const int kIconSize = 69;
+// 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 Extension::GetDefaultIcon(is_app).
+ GetRepresentation(max_scale_factor).sk_bitmap();
+}
+
} // namespace
ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type)
@@ -416,8 +441,12 @@ void ExtensionInstallPrompt::SetIcon(const SkBitmap* image) {
icon_ = *image;
else
icon_ = SkBitmap();
- if (icon_.empty())
- icon_ = Extension::GetDefaultIcon(extension_->is_app());
+ if (icon_.empty()) {
+ // 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.
+ icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app());
+ }
}
void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image,
@@ -438,8 +467,13 @@ void ExtensionInstallPrompt::LoadImageIfNeeded() {
ExtensionResource image =
extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE,
ExtensionIconSet::MATCH_BIGGER);
+ // 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.
+ // TODO(tbarzic): We should use IconImage here and load the required bitmap
+ // lazily.
+ int pixel_size = GetSizeForMaxScaleFactor(kIconSize);
tracker_.LoadImage(extension_, image,
- gfx::Size(kIconSize, kIconSize),
+ gfx::Size(pixel_size, pixel_size),
ImageLoadingTracker::DONT_CACHE);
}
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_uninstall_dialog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698