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

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: .. 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 = supported_scale_factors.back();
30 float max_scale_factor_scale = ui::GetScaleFactorScale(max_scale_factor);
31
32 return static_cast<int>(size_in_dip * max_scale_factor_scale);
33 }
34
35 // Returns bitmap for the default icon with size equal to the default icon's
36 // pixel size under maximal supported scale factor.
37 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
38 std::vector<ui::ScaleFactor> supported_scale_factors =
39 ui::GetSupportedScaleFactors();
40 // Scale factors are in ascending order, so the last one is the one we need.
41 ui::ScaleFactor max_scale_factor =
42 supported_scale_factors[supported_scale_factors.size() - 1];
43
44 return extensions::Extension::GetDefaultIcon(is_app).
45 GetRepresentation(max_scale_factor).sk_bitmap();
46 }
47
48 } // namespace
49
21 // Size of extension icon in top left of dialog. 50 // Size of extension icon in top left of dialog.
22 static const int kIconSize = 69; 51 static const int kIconSize = 69;
23 52
24 ExtensionUninstallDialog::ExtensionUninstallDialog( 53 ExtensionUninstallDialog::ExtensionUninstallDialog(
25 Browser* browser, 54 Browser* browser,
26 ExtensionUninstallDialog::Delegate* delegate) 55 ExtensionUninstallDialog::Delegate* delegate)
27 : browser_(browser), 56 : browser_(browser),
28 delegate_(delegate), 57 delegate_(delegate),
29 extension_(NULL), 58 extension_(NULL),
30 ui_loop_(MessageLoop::current()) { 59 ui_loop_(MessageLoop::current()) {
(...skipping 10 matching lines...) Expand all
41 void ExtensionUninstallDialog::ConfirmUninstall( 70 void ExtensionUninstallDialog::ConfirmUninstall(
42 const extensions::Extension* extension) { 71 const extensions::Extension* extension) {
43 DCHECK(ui_loop_ == MessageLoop::current()); 72 DCHECK(ui_loop_ == MessageLoop::current());
44 extension_ = extension; 73 extension_ = extension;
45 74
46 ExtensionResource image = 75 ExtensionResource image =
47 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, 76 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE,
48 ExtensionIconSet::MATCH_BIGGER); 77 ExtensionIconSet::MATCH_BIGGER);
49 // Load the image asynchronously. The response will be sent to OnImageLoaded. 78 // Load the image asynchronously. The response will be sent to OnImageLoaded.
50 tracker_.reset(new ImageLoadingTracker(this)); 79 tracker_.reset(new ImageLoadingTracker(this));
80 // Load the icon whose pixel size is large enough to be displayed under
81 // maximal supported scale factor. UI code will scale the icon down if needed.
82 int pixel_size = GetSizeForMaxScaleFactor(kIconSize);
51 tracker_->LoadImage(extension_, image, 83 tracker_->LoadImage(extension_, image,
52 gfx::Size(kIconSize, kIconSize), 84 gfx::Size(pixel_size, pixel_size),
53 ImageLoadingTracker::DONT_CACHE); 85 ImageLoadingTracker::DONT_CACHE);
54 } 86 }
55 87
56 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { 88 void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) {
57 if (image.IsEmpty()) { 89 if (image.IsEmpty()) {
58 if (extension_->is_app()) { 90 // Let's set default icon bitmap whose size is equal to the default icon's
59 icon_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 91 // pixel size under maximal supported scale factor. If the bitmap is larger
60 IDR_APP_DEFAULT_ICON); 92 // than the one we need, it will be scaled down by the ui code.
61 } else { 93 // TODO(tbarzic): We should use IconImage here and load the required bitmap
62 icon_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 94 // lazily.
63 IDR_EXTENSION_DEFAULT_ICON); 95 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app());
64 }
65 } else { 96 } else {
66 icon_ = *image.ToImageSkia(); 97 icon_ = *image.ToImageSkia();
67 } 98 }
68 } 99 }
69 100
70 void ExtensionUninstallDialog::OnImageLoaded(const gfx::Image& image, 101 void ExtensionUninstallDialog::OnImageLoaded(const gfx::Image& image,
71 const std::string& extension_id, 102 const std::string& extension_id,
72 int index) { 103 int index) {
73 SetIcon(image); 104 SetIcon(image);
74 105
(...skipping 11 matching lines...) Expand all
86 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSING); 117 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSING);
87 118
88 browser_ = NULL; 119 browser_ = NULL;
89 if (tracker_.get()) { 120 if (tracker_.get()) {
90 // If we're waiting for the icon, stop doing so because we're not going to 121 // If we're waiting for the icon, stop doing so because we're not going to
91 // show the dialog. 122 // show the dialog.
92 tracker_.reset(); 123 tracker_.reset();
93 delegate_->ExtensionUninstallCanceled(); 124 delegate_->ExtensionUninstallCanceled();
94 } 125 }
95 } 126 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_install_prompt.cc ('k') | chrome/common/extensions/extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698