diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 00:45:11 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-09 00:45:11 +0000 |
commit | 62e238b018f733fda3bd978fd0241d6a1ca23688 (patch) | |
tree | b79bfac04817b057cea17c973e2e948d7f519e9e /chrome | |
parent | 46bb0159f2cd001b3add3c6be4fdeda1dbc898cc (diff) | |
download | chromium_src-62e238b018f733fda3bd978fd0241d6a1ca23688.zip chromium_src-62e238b018f733fda3bd978fd0241d6a1ca23688.tar.gz chromium_src-62e238b018f733fda3bd978fd0241d6a1ca23688.tar.bz2 |
Make the max size for ImageTrackingLoader configurable. This makes it so that icons larger than 16px can be used in browser actions.
This is not that useful until we fix the inset issue in the browser action buttons though, so I will not be checking it in.
Review URL: http://codereview.chromium.org/271029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28489 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/extensions/image_loading_tracker.cc | 40 | ||||
-rw-r--r-- | chrome/browser/extensions/image_loading_tracker.h | 4 | ||||
-rw-r--r-- | chrome/browser/views/browser_actions_container.cc | 6 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 6 |
4 files changed, 40 insertions, 16 deletions
diff --git a/chrome/browser/extensions/image_loading_tracker.cc b/chrome/browser/extensions/image_loading_tracker.cc index e141391..211a07b4 100644 --- a/chrome/browser/extensions/image_loading_tracker.cc +++ b/chrome/browser/extensions/image_loading_tracker.cc @@ -29,13 +29,19 @@ class ImageLoadingTracker::LoadImageTask : public Task { // we use to communicate back to the entity that wants the image after we // decode it. |path| is the path to load the image from. |index| is an // identifier for the image that we pass back to the caller. + // |max_size| is the maximum size for the loaded image. If the image is + // larger, it will be resized to fit. It is optional. LoadImageTask(ImageLoadingTracker* tracker, const ExtensionResource& resource, - size_t index) + size_t index, + gfx::Size* max_size) : callback_loop_(MessageLoop::current()), tracker_(tracker), resource_(resource), - index_(index) {} + index_(index){ + if (max_size) + max_size_.reset(new gfx::Size(*max_size)); + } void ReportBack(SkBitmap* image) { DCHECK(image); @@ -65,15 +71,18 @@ class ImageLoadingTracker::LoadImageTask : public Task { return; // Unable to decode. } - if (decoded->width() != kFavIconSize || decoded->height() != kFavIconSize) { - // The bitmap is not the correct size, re-sample. - int new_width = decoded->width(); - int new_height = decoded->height(); - // Calculate what dimensions to use within the constraints (16x16 max). - calc_favicon_target_size(&new_width, &new_height); - *decoded = skia::ImageOperations::Resize( - *decoded, skia::ImageOperations::RESIZE_LANCZOS3, - new_width, new_height); + if (max_size_.get()) { + if (decoded->width() > max_size_->width() || + decoded->height() > max_size_->height()) { + // The bitmap is not the correct size, re-sample. + int new_width = decoded->width(); + int new_height = decoded->height(); + // Calculate what dimensions to use within the constraints (16x16 max). + calc_favicon_target_size(&new_width, &new_height); + *decoded = skia::ImageOperations::Resize( + *decoded, skia::ImageOperations::RESIZE_LANCZOS3, + new_width, new_height); + } } ReportBack(decoded.release()); @@ -91,15 +100,20 @@ class ImageLoadingTracker::LoadImageTask : public Task { // The index of the icon being loaded. size_t index_; + + // The max size for the image. If the image is larger than this, it will be + // scaled down. + scoped_ptr<gfx::Size> max_size_; }; //////////////////////////////////////////////////////////////////////////////// // ImageLoadingTracker -void ImageLoadingTracker::PostLoadImageTask(const ExtensionResource& resource) { +void ImageLoadingTracker::PostLoadImageTask(const ExtensionResource& resource, + gfx::Size* max_size) { MessageLoop* file_loop = g_browser_process->file_thread()->message_loop(); file_loop->PostTask(FROM_HERE, new LoadImageTask(this, resource, - posted_count_++)); + posted_count_++, max_size)); } void ImageLoadingTracker::OnImageLoaded(SkBitmap* image, size_t index) { diff --git a/chrome/browser/extensions/image_loading_tracker.h b/chrome/browser/extensions/image_loading_tracker.h index 9732a00..732e0e2 100644 --- a/chrome/browser/extensions/image_loading_tracker.h +++ b/chrome/browser/extensions/image_loading_tracker.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ #define CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ +#include "base/gfx/size.h" #include "base/ref_counted.h" class ExtensionResource; @@ -45,7 +46,8 @@ class ImageLoadingTracker // Specify image resource to load. This method must be called a number of // times equal to the |image_count| arugment to the constructor. Calling it // any more or less than that is an error. - void PostLoadImageTask(const ExtensionResource& resource); + void PostLoadImageTask(const ExtensionResource& resource, + gfx::Size* max_size); private: class LoadImageTask; diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index 4a246f2..8d5d20a 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -35,6 +35,9 @@ static const int kHorizontalPadding = 4; // can draw the badge outside the visual bounds of the contianer. static const int kControlVertOffset = 6; +// The maximum dimension of the browser action icons. +static const int kMaxIconSize = 16; + //////////////////////////////////////////////////////////////////////////////// // BrowserActionButton @@ -127,9 +130,10 @@ BrowserActionButton::BrowserActionButton( const std::vector<std::string>& icon_paths = browser_action->icon_paths(); browser_action_icons_.resize(icon_paths.size()); tracker_ = new ImageLoadingTracker(this, icon_paths.size()); + gfx::Size max_size(kMaxIconSize, kMaxIconSize); for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); iter != icon_paths.end(); ++iter) { - tracker_->PostLoadImageTask(extension->GetResource(*iter)); + tracker_->PostLoadImageTask(extension->GetResource(*iter), &max_size); } registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index b7a97a7..31494ba 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -59,6 +59,9 @@ static const int kEntryPadding = 3; // Padding between the entry and the leading/trailing views. static const int kInnerPadding = 3; +// Maximum size of the page action icons. +static const int kMaxPageActionIconSize = 16; + static const SkBitmap* kBackground = NULL; static const SkBitmap* kPopupBackground = NULL; @@ -1202,9 +1205,10 @@ LocationBarView::PageActionImageView::PageActionImageView( const std::vector<std::string>& icon_paths = page_action->icon_paths(); page_action_icons_.resize(icon_paths.size()); tracker_ = new ImageLoadingTracker(this, icon_paths.size()); + gfx::Size max_size(kMaxPageActionIconSize, kMaxPageActionIconSize); for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); iter != icon_paths.end(); ++iter) { - tracker_->PostLoadImageTask(extension->GetResource(*iter)); + tracker_->PostLoadImageTask(extension->GetResource(*iter), &max_size); } } |