diff options
| author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-08 21:10:31 +0000 |
|---|---|---|
| committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-08 21:10:31 +0000 |
| commit | 29d0d4ac924f7fb211baf2aadbf3248bf7fef78e (patch) | |
| tree | fb8bd762c19248d14e22ec07a39545422f4cfc73 | |
| parent | f0cd4461c006a2f6c10291b72368d1c8ac560dd7 (diff) | |
| download | chromium_src-29d0d4ac924f7fb211baf2aadbf3248bf7fef78e.zip chromium_src-29d0d4ac924f7fb211baf2aadbf3248bf7fef78e.tar.gz chromium_src-29d0d4ac924f7fb211baf2aadbf3248bf7fef78e.tar.bz2 | |
Fix spacing for extension omnibox keyword icons.
BUG=51981
TEST=no
Review URL: http://codereview.chromium.org/3266015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58872 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 62 insertions, 4 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc index b2b2dd3..74cbb1f 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_model.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc @@ -298,6 +298,6 @@ const SkBitmap* AutocompletePopupModel::GetSpecialIconForMatch( if (!match.template_url || !match.template_url->IsExtensionKeyword()) return NULL; - return &profile_->GetExtensionsService()->GetOmniboxIcon( + return &profile_->GetExtensionsService()->GetOmniboxPopupIcon( match.template_url->GetExtensionId()); } diff --git a/chrome/browser/extensions/extension_icon_manager.cc b/chrome/browser/extensions/extension_icon_manager.cc index ecdca47..69d4952 100644 --- a/chrome/browser/extensions/extension_icon_manager.cc +++ b/chrome/browser/extensions/extension_icon_manager.cc @@ -9,6 +9,7 @@ #include "base/stl_util-inl.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_resource.h" +#include "gfx/canvas_skia.h" #include "gfx/color_utils.h" #include "gfx/favicon_size.h" #include "gfx/skbitmap_operations.h" @@ -16,11 +17,33 @@ #include "grit/theme_resources.h" #include "skia/ext/image_operations.h" +namespace { + +// Helper function to create a new bitmap with |padding| amount of empty space +// around the original bitmap. +static SkBitmap ApplyPadding(const SkBitmap& source, + const gfx::Insets& padding) { + scoped_ptr<gfx::CanvasSkia> result( + new gfx::CanvasSkia(source.width() + padding.width(), + source.height() + padding.height(), false)); + result->DrawBitmapInt( + source, + 0, 0, source.width(), source.height(), + padding.left(), padding.top(), source.width(), source.height(), + false); + return result->ExtractBitmap(); +} + +} // namespace + ExtensionIconManager::ExtensionIconManager() : ALLOW_THIS_IN_INITIALIZER_LIST(image_tracker_(this)), monochrome_(false) { } +ExtensionIconManager::~ExtensionIconManager() { +} + void ExtensionIconManager::LoadIcon(Extension* extension) { ExtensionResource icon_resource; extension->GetIconResourceAllowLargerSize(&icon_resource, @@ -43,8 +66,8 @@ const SkBitmap& ExtensionIconManager::GetIcon(const std::string& extension_id) { result = &default_icon_; } DCHECK(result); - DCHECK(result->width() == kFavIconSize); - DCHECK(result->height() == kFavIconSize); + DCHECK_EQ(kFavIconSize + padding_.width(), result->width()); + DCHECK_EQ(kFavIconSize + padding_.height(), result->height()); return *result; } @@ -92,5 +115,8 @@ SkBitmap ExtensionIconManager::ApplyTransforms(const SkBitmap& source) { result = SkBitmapOperations::CreateHSLShiftedBitmap(result, shift); } + if (!padding_.empty()) + result = ApplyPadding(result, padding_); + return result; } diff --git a/chrome/browser/extensions/extension_icon_manager.h b/chrome/browser/extensions/extension_icon_manager.h index c39421c..876f5e0 100644 --- a/chrome/browser/extensions/extension_icon_manager.h +++ b/chrome/browser/extensions/extension_icon_manager.h @@ -12,6 +12,7 @@ #include "base/basictypes.h" #include "chrome/browser/extensions/image_loading_tracker.h" +#include "gfx/insets.h" #include "third_party/skia/include/core/SkBitmap.h" class Extension; @@ -19,6 +20,7 @@ class Extension; class ExtensionIconManager : public ImageLoadingTracker::Observer { public: ExtensionIconManager(); + virtual ~ExtensionIconManager(); // Start loading the icon for the given extension. void LoadIcon(Extension* extension); @@ -36,6 +38,7 @@ class ExtensionIconManager : public ImageLoadingTracker::Observer { int index); void set_monochrome(bool value) { monochrome_ = value; } + void set_padding(const gfx::Insets& value) { padding_ = value; } private: // Makes sure we've done one-time initialization of the default extension icon @@ -61,6 +64,9 @@ class ExtensionIconManager : public ImageLoadingTracker::Observer { // If true, we will desaturate the icons to make them monochromatic. bool monochrome_; + // Specifies the amount of empty padding to place around the icon. + gfx::Insets padding_; + DISALLOW_COPY_AND_ASSIGN(ExtensionIconManager); }; diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 06198387..e876e9f 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -68,6 +68,17 @@ namespace errors = extension_manifest_errors; namespace { +#if defined(OS_LINUX) +static const int kOmniboxIconPaddingLeft = 2; +static const int kOmniboxIconPaddingRight = 2; +#elif defined(OS_MACOSX) +static const int kOmniboxIconPaddingLeft = 0; +static const int kOmniboxIconPaddingRight = 2; +#else +static const int kOmniboxIconPaddingLeft = 0; +static const int kOmniboxIconPaddingRight = 0; +#endif + bool ShouldReloadExtensionManifest(const ExtensionInfo& info) { // Always reload LOAD extension manifests, because they can change on disk // independent of the manifest in our prefs. @@ -233,7 +244,10 @@ ExtensionsService::ExtensionsService(Profile* profile, backend_ = new ExtensionsServiceBackend(install_directory_); // Use monochrome icons for Omnibox icons. + omnibox_popup_icon_manager_.set_monochrome(true); omnibox_icon_manager_.set_monochrome(true); + omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, + 0, kOmniboxIconPaddingRight)); } ExtensionsService::~ExtensionsService() { @@ -1118,8 +1132,10 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension, // Load the icon for omnibox-enabled extensions so it will be ready to display // in the URL bar. - if (!extension->omnibox_keyword().empty()) + if (!extension->omnibox_keyword().empty()) { + omnibox_popup_icon_manager_.LoadIcon(extension); omnibox_icon_manager_.LoadIcon(extension); + } } void ExtensionsService::UpdateActiveExtensionsInCrashReporter() { @@ -1323,6 +1339,11 @@ const SkBitmap& ExtensionsService::GetOmniboxIcon( return omnibox_icon_manager_.GetIcon(extension_id); } +const SkBitmap& ExtensionsService::GetOmniboxPopupIcon( + const std::string& extension_id) { + return omnibox_popup_icon_manager_.GetIcon(extension_id); +} + void ExtensionsService::ClearProvidersForTesting() { ChromeThread::PostTask( ChromeThread::FILE, FROM_HERE, diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index f158303..f966ad7 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -296,6 +296,10 @@ class ExtensionsService // Returns the icon to display in the omnibox for the given extension. const SkBitmap& GetOmniboxIcon(const std::string& extension_id); + // Returns the icon to display in the omnibox popup window for the given + // extension. + const SkBitmap& GetOmniboxPopupIcon(const std::string& extension_id); + // Clear all ExternalExtensionProviders. void ClearProvidersForTesting(); @@ -484,6 +488,7 @@ class ExtensionsService // Keeps track of favicon-sized omnibox icons for extensions. ExtensionIconManager omnibox_icon_manager_; + ExtensionIconManager omnibox_popup_icon_manager_; // List of registered component extensions (see Extension::Location). typedef std::vector<ComponentExtensionInfo> RegisteredComponentExtensions; |
