diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-03 15:50:07 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-03 15:50:07 +0000 |
commit | 66171abedad9f817901db48328fdc417ecf56c7a (patch) | |
tree | 59ebd2a67731072f9326f08fa3fcce32cc1c5866 /chrome | |
parent | 7aebaf878d8ec781f8fcc5f2932d67a9f6afb966 (diff) | |
download | chromium_src-66171abedad9f817901db48328fdc417ecf56c7a.zip chromium_src-66171abedad9f817901db48328fdc417ecf56c7a.tar.gz chromium_src-66171abedad9f817901db48328fdc417ecf56c7a.tar.bz2 |
Convert IconLoader and IconManager to deal with gfx::Image rather than SkBitmap.
This allows loading of icons in the platform format, avoiding unnecessary
conversions if the image is going to be used with the platform toolkit. In other
cases, this just pushes image conversion to the callsite rather than the actual
image load.
BUG=19685
TEST=unit_tests and visual inspection of icons in the download shelf
Review URL: http://codereview.chromium.org/6597043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
21 files changed, 133 insertions, 129 deletions
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index b8bcd12..180c768 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -53,6 +53,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas_skia.h" +#include "ui/gfx/image.h" #include "ui/gfx/rect.h" #if defined(TOOLKIT_VIEWS) @@ -504,7 +505,7 @@ int GetBigProgressIconOffset() { #if defined(TOOLKIT_VIEWS) // Download dragging void DragDownload(const DownloadItem* download, - SkBitmap* icon, + gfx::Image* icon, gfx::NativeView view) { DCHECK(download); @@ -513,7 +514,7 @@ void DragDownload(const DownloadItem* download, if (icon) { drag_utils::CreateDragImageForFile( - download->GetFileNameToReportUser(), icon, &data); + download->GetFileNameToReportUser(), *icon, &data); } const FilePath full_path = download->full_path(); @@ -552,7 +553,7 @@ void DragDownload(const DownloadItem* download, } #elif defined(USE_X11) void DragDownload(const DownloadItem* download, - SkBitmap* icon, + gfx::Image* icon, gfx::NativeView view) { DownloadItemDrag::BeginDrag(download, icon); } diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h index 89ab17e..dce55b7 100644 --- a/chrome/browser/download/download_util.h +++ b/chrome/browser/download/download_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -21,6 +21,7 @@ namespace gfx { class Canvas; +class Image; } class BaseDownloadItemModel; @@ -148,7 +149,7 @@ void PaintDownloadComplete(gfx::Canvas* canvas, // DownloadItem. If |icon| is NULL, no image will be accompany the drag. |view| // is only required for Mac OS X, elsewhere it can be NULL. void DragDownload(const DownloadItem* download, - SkBitmap* icon, + gfx::Image* icon, gfx::NativeView view); // Helpers --------------------------------------------------------------------- diff --git a/chrome/browser/icon_loader.cc b/chrome/browser/icon_loader.cc index 0c30301..c1d8e8f 100644 --- a/chrome/browser/icon_loader.cc +++ b/chrome/browser/icon_loader.cc @@ -1,9 +1,10 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/icon_loader.h" +#include "base/basictypes.h" #include "content/browser/browser_thread.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -16,7 +17,7 @@ IconLoader::IconLoader(const IconGroupID& group, IconSize size, : target_message_loop_(NULL), group_(group), icon_size_(size), - bitmap_(NULL), + image_(NULL), delegate_(delegate) { } @@ -36,6 +37,8 @@ void IconLoader::Start() { } void IconLoader::NotifyDelegate() { - if (delegate_->OnBitmapLoaded(this, bitmap_.Get())) - bitmap_.Release(); + // If the delegate takes ownership of the Image, release it from the scoped + // pointer. + if (delegate_->OnImageLoaded(this, image_.get())) + ignore_result(image_.release()); // Can't ignore return value. } diff --git a/chrome/browser/icon_loader.h b/chrome/browser/icon_loader.h index bfd078d..8a15ca0 100644 --- a/chrome/browser/icon_loader.h +++ b/chrome/browser/icon_loader.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,7 +13,8 @@ #include "base/basictypes.h" #include "base/message_loop_proxy.h" #include "base/ref_counted.h" -#include "ui/gfx/scoped_image.h" +#include "base/scoped_ptr.h" +#include "ui/gfx/image.h" #if defined(TOOLKIT_USES_GTK) #include "base/file_path.h" @@ -28,9 +29,6 @@ typedef std::wstring IconGroupID; typedef std::string IconGroupID; #endif -class MessageLoop; -class SkBitmap; - //////////////////////////////////////////////////////////////////////////////// // // A facility to read a file containing an icon asynchronously in the IO @@ -50,7 +48,7 @@ class IconLoader : public base::RefCountedThreadSafe<IconLoader> { // Invoked when an icon has been read. |source| is the IconLoader. If the // icon has been successfully loaded, result is non-null. This method must // return true if it is taking ownership of the returned bitmap. - virtual bool OnBitmapLoaded(IconLoader* source, SkBitmap* result) = 0; + virtual bool OnImageLoaded(IconLoader* source, gfx::Image* result) = 0; protected: virtual ~Delegate() {} @@ -77,7 +75,7 @@ class IconLoader : public base::RefCountedThreadSafe<IconLoader> { IconSize icon_size_; - gfx::ScopedImage<SkBitmap> bitmap_; + scoped_ptr<gfx::Image> image_; Delegate* delegate_; diff --git a/chrome/browser/icon_loader_linux.cc b/chrome/browser/icon_loader_linux.cc index 29d7f7f1..ce8eade 100644 --- a/chrome/browser/icon_loader_linux.cc +++ b/chrome/browser/icon_loader_linux.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,9 +14,6 @@ #include "base/mime_util.h" #include "base/threading/thread.h" #include "base/string_util.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/gfx/codec/png_codec.h" -#include "ui/gfx/gtk_util.h" static int SizeToInt(IconLoader::IconSize size) { int pixels = 48; @@ -46,30 +43,15 @@ void IconLoader::ParseIcon() { reinterpret_cast<const guchar*>(icon_data_.data()), icon_data_.length(), NULL); gdk_pixbuf_loader_close(loader, NULL); - // We don't own a reference, we rely on the loader's ref. + // At this point, the pixbuf is owned by the loader. GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); if (pixbuf) { - guchar* pixels = gdk_pixbuf_get_pixels(pixbuf); - int width = gdk_pixbuf_get_width(pixbuf); - int height = gdk_pixbuf_get_height(pixbuf); - DCHECK_EQ(width, size); - DCHECK_EQ(height, size); - int stride = gdk_pixbuf_get_rowstride(pixbuf); - - if (!gdk_pixbuf_get_has_alpha(pixbuf)) { - LOG(WARNING) << "Got an image with no alpha channel, aborting load."; - } else { - uint8_t* BGRA_pixels = - gfx::BGRAToRGBA(pixels, width, height, stride); - std::vector<unsigned char> pixel_vector; - pixel_vector.resize(height * stride); - memcpy(const_cast<unsigned char*>(pixel_vector.data()), BGRA_pixels, - height * stride); - bitmap_.Set(gfx::PNGCodec::CreateSkBitmapFromBGRAFormat(pixel_vector, - width, height)); - free(BGRA_pixels); - } + DCHECK_EQ(size, gdk_pixbuf_get_width(pixbuf)); + DCHECK_EQ(size, gdk_pixbuf_get_height(pixbuf)); + // Takes ownership of |pixbuf|. + g_object_ref(pixbuf); + image_.reset(new gfx::Image(pixbuf)); } else { LOG(WARNING) << "Unsupported file type or load error: " << filename_.value(); diff --git a/chrome/browser/icon_loader_mac.mm b/chrome/browser/icon_loader_mac.mm index e14bde7..9b26ff3 100644 --- a/chrome/browser/icon_loader_mac.mm +++ b/chrome/browser/icon_loader_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -17,15 +17,9 @@ void IconLoader::ReadIcon() { NSWorkspace* workspace = [NSWorkspace sharedWorkspace]; NSImage* icon = [workspace iconForFileType:group]; - NSSize size; - if (icon_size_ == NORMAL) - size = NSMakeSize(32, 32); - else if (icon_size_ == SMALL) - size = NSMakeSize(16, 16); - else - return; - - bitmap_.Set(new SkBitmap(gfx::NSImageToSkBitmap(icon, size, false))); + // Mac will ignore the size because icons have multiple size representations + // and NSImage choses the best at draw-time. + image_.reset(new gfx::Image([icon retain])); target_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, &IconLoader::NotifyDelegate)); diff --git a/chrome/browser/icon_loader_win.cc b/chrome/browser/icon_loader_win.cc index 717c15b..eeeedb0 100644 --- a/chrome/browser/icon_loader_win.cc +++ b/chrome/browser/icon_loader_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -42,7 +42,8 @@ void IconLoader::ReadIcon() { DCHECK(r); gfx::Size icon_size(bitmap_info.bmWidth, bitmap_info.bmHeight); - bitmap_.Set(IconUtil::CreateSkBitmapFromHICON(file_info.hIcon, icon_size)); + image_.reset(new gfx::Image( + IconUtil::CreateSkBitmapFromHICON(file_info.hIcon, icon_size))); target_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, &IconLoader::NotifyDelegate)); diff --git a/chrome/browser/icon_manager.cc b/chrome/browser/icon_manager.cc index 8f74ce4..b2fd95b 100644 --- a/chrome/browser/icon_manager.cc +++ b/chrome/browser/icon_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -23,8 +23,8 @@ IconManager::~IconManager() { STLDeleteValues(&icon_cache_); } -SkBitmap* IconManager::LookupIcon(const FilePath& file_name, - IconLoader::IconSize size) { +gfx::Image* IconManager::LookupIcon(const FilePath& file_name, + IconLoader::IconSize size) { IconGroupID group = GetGroupIDFromFilepath(file_name); IconMap::iterator it = icon_cache_.find(CacheKey(group, size)); if (it != icon_cache_.end()) @@ -52,7 +52,7 @@ IconManager::Handle IconManager::LoadIcon( // IconLoader::Delegate implementation ----------------------------------------- -bool IconManager::OnBitmapLoaded(IconLoader* source, SkBitmap* result) { +bool IconManager::OnImageLoaded(IconLoader* source, gfx::Image* result) { ClientRequests::iterator rit = requests_.find(source); // Balances the AddRef() in LoadIcon(). source->Release(); @@ -74,7 +74,7 @@ bool IconManager::OnBitmapLoaded(IconLoader* source, SkBitmap* result) { CacheKey key(client_request.group, client_request.size); IconMap::iterator it = icon_cache_.find(key); if (it != icon_cache_.end() && result && it->second) { - it->second->swap(*result); + it->second->SwapRepresentations(result); delete result; result = it->second; } else { diff --git a/chrome/browser/icon_manager.h b/chrome/browser/icon_manager.h index a7a2441..81ecb9f 100644 --- a/chrome/browser/icon_manager.h +++ b/chrome/browser/icon_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -52,9 +52,9 @@ #include "base/hash_tables.h" #include "chrome/browser/icon_loader.h" #include "content/browser/cancelable_request.h" +#include "ui/gfx/image.h" class FilePath; -class SkBitmap; class IconManager : public IconLoader::Delegate, public CancelableRequestProvider { @@ -67,11 +67,11 @@ class IconManager : public IconLoader::Delegate, // it via 'LoadIcon'. The returned bitmap is owned by the IconManager and must // not be free'd by the caller. If the caller needs to modify the icon, it // must make a copy and modify the copy. - SkBitmap* LookupIcon(const FilePath& file_name, - IconLoader::IconSize size); + gfx::Image* LookupIcon(const FilePath& file_name, + IconLoader::IconSize size); typedef CancelableRequestProvider::Handle Handle; - typedef Callback2<Handle, SkBitmap*>::Type IconRequestCallback; + typedef Callback2<Handle, gfx::Image*>::Type IconRequestCallback; // Asynchronous call to lookup and return the icon associated with file. The // work is done on the file thread, with the callbacks running on the UI @@ -85,7 +85,7 @@ class IconManager : public IconLoader::Delegate, IconRequestCallback* callback); // IconLoader::Delegate interface. - virtual bool OnBitmapLoaded(IconLoader* source, SkBitmap* result); + virtual bool OnImageLoaded(IconLoader* source, gfx::Image* result); // Get the identifying string for the given file. The implementation // is in icon_manager_[platform].cc. @@ -102,7 +102,7 @@ class IconManager : public IconLoader::Delegate, IconLoader::IconSize size; }; - typedef std::map<CacheKey, SkBitmap*> IconMap; + typedef std::map<CacheKey, gfx::Image*> IconMap; IconMap icon_cache_; typedef CancelableRequest<IconRequestCallback> IconRequest; diff --git a/chrome/browser/ui/cocoa/download/download_item_mac.h b/chrome/browser/ui/cocoa/download/download_item_mac.h index 159e470..8eafb17 100644 --- a/chrome/browser/ui/cocoa/download/download_item_mac.h +++ b/chrome/browser/ui/cocoa/download/download_item_mac.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -18,6 +18,10 @@ class BaseDownloadItemModel; @class DownloadItemController; +namespace gfx{ +class Image; +} + // A class that bridges the visible mac download items to chromium's download // model. The owning object (DownloadItemController) must explicitly call // |LoadIcon| if it wants to display the icon associated with this download. @@ -43,7 +47,8 @@ class DownloadItemMac : DownloadItem::Observer { private: // Callback for asynchronous icon loading. - void OnExtractIconComplete(IconManager::Handle handle, SkBitmap* icon_bitmap); + void OnExtractIconComplete(IconManager::Handle handle, + gfx::Image* icon_bitmap); // The download item model we represent. scoped_ptr<BaseDownloadItemModel> download_model_; diff --git a/chrome/browser/ui/cocoa/download/download_item_mac.mm b/chrome/browser/ui/cocoa/download/download_item_mac.mm index ab756ce..7c02af2 100644 --- a/chrome/browser/ui/cocoa/download/download_item_mac.mm +++ b/chrome/browser/ui/cocoa/download/download_item_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,7 +10,7 @@ #include "chrome/browser/download/download_item_model.h" #import "chrome/browser/ui/cocoa/download/download_item_controller.h" #include "chrome/browser/ui/cocoa/download/download_util_mac.h" -#include "skia/ext/skia_utils_mac.h" +#include "ui/gfx/image.h" // DownloadItemMac ------------------------------------------------------------- @@ -78,10 +78,9 @@ void DownloadItemMac::LoadIcon() { // We may already have this particular image cached. FilePath file = download_model_->download()->GetUserVerifiedFilePath(); - SkBitmap* icon_bitmap = icon_manager->LookupIcon(file, IconLoader::SMALL); - if (icon_bitmap) { - NSImage* icon = gfx::SkBitmapToNSImage(*icon_bitmap); - [item_controller_ setIcon:icon]; + gfx::Image* icon = icon_manager->LookupIcon(file, IconLoader::SMALL); + if (icon) { + [item_controller_ setIcon:*icon]; return; } @@ -92,10 +91,8 @@ void DownloadItemMac::LoadIcon() { } void DownloadItemMac::OnExtractIconComplete(IconManager::Handle handle, - SkBitmap* icon_bitmap) { - if (!icon_bitmap) + gfx::Image* icon) { + if (!icon) return; - - NSImage* icon = gfx::SkBitmapToNSImage(*icon_bitmap); - [item_controller_ setIcon:icon]; + [item_controller_ setIcon:*icon]; } diff --git a/chrome/browser/ui/cocoa/download/download_util_mac.mm b/chrome/browser/ui/cocoa/download/download_util_mac.mm index 1c6808f..f3bd357 100644 --- a/chrome/browser/ui/cocoa/download/download_util_mac.mm +++ b/chrome/browser/ui/cocoa/download/download_util_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -10,7 +10,7 @@ #include "chrome/browser/download/download_item.h" #include "chrome/browser/download/download_manager.h" #import "chrome/browser/ui/cocoa/dock_icon.h" -#include "skia/ext/skia_utils_mac.h" +#include "ui/gfx/image.h" #include "ui/gfx/native_widget_types.h" namespace download_util { @@ -38,14 +38,11 @@ void NotifySystemOfDownloadComplete(const FilePath& path) { } void DragDownload(const DownloadItem* download, - SkBitmap* icon, + gfx::Image* icon, gfx::NativeView view) { NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard]; AddFileToPasteboard(pasteboard, download->full_path()); - // Convert to an NSImage. - NSImage* dragImage = gfx::SkBitmapToNSImage(*icon); - // Synthesize a drag event, since we don't have access to the actual event // that initiated a drag (possibly consumed by the Web UI, for example). NSPoint position = [[view window] mouseLocationOutsideOfEventStream]; @@ -61,7 +58,7 @@ void DragDownload(const DownloadItem* download, pressure:1.0]; // Run the drag operation. - [[view window] dragImage:dragImage + [[view window] dragImage:*icon at:position offset:NSZeroSize event:dragEvent diff --git a/chrome/browser/ui/gtk/custom_drag.cc b/chrome/browser/ui/gtk/custom_drag.cc index 23fa7ca..18ee606 100644 --- a/chrome/browser/ui/gtk/custom_drag.cc +++ b/chrome/browser/ui/gtk/custom_drag.cc @@ -12,6 +12,7 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/dragdrop/gtk_dnd_util.h" #include "ui/gfx/gtk_util.h" +#include "ui/gfx/image.h" namespace { @@ -40,9 +41,9 @@ void OnDragDataGetStandalone(GtkWidget* widget, GdkDragContext* context, // CustomDrag ------------------------------------------------------------------ -CustomDrag::CustomDrag(SkBitmap* icon, int code_mask, GdkDragAction action) +CustomDrag::CustomDrag(gfx::Image* icon, int code_mask, GdkDragAction action) : drag_widget_(gtk_invisible_new()), - pixbuf_(icon ? gfx::GdkPixbufFromSkBitmap(icon) : NULL) { + image_(icon) { g_signal_connect(drag_widget_, "drag-data-get", G_CALLBACK(OnDragDataGetThunk), this); g_signal_connect(drag_widget_, "drag-begin", @@ -59,14 +60,12 @@ CustomDrag::CustomDrag(SkBitmap* icon, int code_mask, GdkDragAction action) } CustomDrag::~CustomDrag() { - if (pixbuf_) - g_object_unref(pixbuf_); gtk_widget_destroy(drag_widget_); } void CustomDrag::OnDragBegin(GtkWidget* widget, GdkDragContext* drag_context) { - if (pixbuf_) - gtk_drag_set_icon_pixbuf(drag_context, pixbuf_, 0, 0); + if (image_) + gtk_drag_set_icon_pixbuf(drag_context, *image_, 0, 0); } void CustomDrag::OnDragEnd(GtkWidget* widget, GdkDragContext* drag_context) { @@ -76,7 +75,7 @@ void CustomDrag::OnDragEnd(GtkWidget* widget, GdkDragContext* drag_context) { // DownloadItemDrag ------------------------------------------------------------ DownloadItemDrag::DownloadItemDrag(const DownloadItem* item, - SkBitmap* icon) + gfx::Image* icon) : CustomDrag(icon, kDownloadItemCodeMask, kDownloadItemDragAction), download_item_(item) { } @@ -94,7 +93,7 @@ void DownloadItemDrag::OnDragDataGet( // static void DownloadItemDrag::SetSource(GtkWidget* widget, DownloadItem* item, - SkBitmap* icon) { + gfx::Image* icon) { gtk_drag_source_set(widget, GDK_BUTTON1_MASK, NULL, 0, kDownloadItemDragAction); ui::SetSourceTargetListFromCodeMask(widget, kDownloadItemCodeMask); @@ -108,15 +107,12 @@ void DownloadItemDrag::SetSource(GtkWidget* widget, g_signal_connect(widget, "drag-data-get", G_CALLBACK(OnDragDataGetStandalone), item); - GdkPixbuf* pixbuf = icon ? gfx::GdkPixbufFromSkBitmap(icon) : NULL; - if (pixbuf) { - gtk_drag_source_set_icon_pixbuf(widget, pixbuf); - g_object_unref(pixbuf); - } + if (icon) + gtk_drag_source_set_icon_pixbuf(widget, *icon); } // static -void DownloadItemDrag::BeginDrag(const DownloadItem* item, SkBitmap* icon) { +void DownloadItemDrag::BeginDrag(const DownloadItem* item, gfx::Image* icon) { new DownloadItemDrag(item, icon); } diff --git a/chrome/browser/ui/gtk/custom_drag.h b/chrome/browser/ui/gtk/custom_drag.h index d3f893b..8ec9936 100644 --- a/chrome/browser/ui/gtk/custom_drag.h +++ b/chrome/browser/ui/gtk/custom_drag.h @@ -15,12 +15,15 @@ class BookmarkNode; class DownloadItem; class Profile; -class SkBitmap; + +namespace gfx { +class Image; +} // Base class for programatically generated drags. class CustomDrag { protected: - explicit CustomDrag(SkBitmap* icon, int code_mask, GdkDragAction action); + explicit CustomDrag(gfx::Image* icon, int code_mask, GdkDragAction action); virtual ~CustomDrag(); virtual void OnDragDataGet(GtkWidget* widget, GdkDragContext* context, @@ -44,7 +47,9 @@ class CustomDrag { // sinks the reference. GtkWidget* drag_widget_; - GdkPixbuf* pixbuf_; + // The image for the drag. The lifetime of the image should be managed outside + // this object. Most icons are owned by the IconManager. + gfx::Image* image_; DISALLOW_COPY_AND_ASSIGN(CustomDrag); }; @@ -55,14 +60,16 @@ class DownloadItemDrag : public CustomDrag { // Sets |widget| as a source for drags pertaining to |item|. No // DownloadItemDrag object is created. // It is safe to call this multiple times with different values of |icon|. - static void SetSource(GtkWidget* widget, DownloadItem* item, SkBitmap* icon); + static void SetSource(GtkWidget* widget, + DownloadItem* item, + gfx::Image* icon); // Creates a new DownloadItemDrag, the lifetime of which is tied to the // system drag. - static void BeginDrag(const DownloadItem* item, SkBitmap* icon); + static void BeginDrag(const DownloadItem* item, gfx::Image* icon); private: - DownloadItemDrag(const DownloadItem* item, SkBitmap* icon); + DownloadItemDrag(const DownloadItem* item, gfx::Image* icon); virtual ~DownloadItemDrag(); virtual void OnDragDataGet(GtkWidget* widget, GdkDragContext* context, diff --git a/chrome/browser/ui/gtk/download_item_gtk.cc b/chrome/browser/ui/gtk/download_item_gtk.cc index a1d56f4..15f15fd 100644 --- a/chrome/browser/ui/gtk/download_item_gtk.cc +++ b/chrome/browser/ui/gtk/download_item_gtk.cc @@ -34,6 +34,7 @@ #include "ui/gfx/canvas_skia_paint.h" #include "ui/gfx/color_utils.h" #include "ui/gfx/font.h" +#include "ui/gfx/image.h" #include "ui/gfx/skia_utils_gtk.h" namespace { @@ -495,14 +496,14 @@ void DownloadItemGtk::StopDownloadProgress() { // Icon loading functions. void DownloadItemGtk::OnLoadSmallIconComplete(IconManager::Handle handle, - SkBitmap* icon_bitmap) { - icon_small_ = icon_bitmap; + gfx::Image* image) { + icon_small_ = image; gtk_widget_queue_draw(progress_area_.get()); } void DownloadItemGtk::OnLoadLargeIconComplete(IconManager::Handle handle, - SkBitmap* icon_bitmap) { - icon_large_ = icon_bitmap; + gfx::Image* image) { + icon_large_ = image; DownloadItemDrag::SetSource(body_.get(), get_download(), icon_large_); } diff --git a/chrome/browser/ui/gtk/download_item_gtk.h b/chrome/browser/ui/gtk/download_item_gtk.h index 68d605c..e2f2583 100644 --- a/chrome/browser/ui/gtk/download_item_gtk.h +++ b/chrome/browser/ui/gtk/download_item_gtk.h @@ -27,6 +27,10 @@ class GtkThemeProvider; class NineBox; class SkBitmap; +namespace gfx { +class Image; +} + namespace ui { class SlideAnimation; } @@ -58,9 +62,9 @@ class DownloadItemGtk : public DownloadItem::Observer, // Called when the icon manager has finished loading the icon. We take // ownership of |icon_bitmap|. void OnLoadSmallIconComplete(IconManager::Handle handle, - SkBitmap* icon_bitmap); + gfx::Image* image); void OnLoadLargeIconComplete(IconManager::Handle handle, - SkBitmap* icon_bitmap); + gfx::Image* image); // Returns the DownloadItem model object belonging to this item. DownloadItem* get_download(); @@ -205,8 +209,9 @@ class DownloadItemGtk : public DownloadItem::Observer, // The file icon for the download. May be null. The small version is used // for display in the shelf; the large version is for use as a drag icon. - SkBitmap* icon_small_; - SkBitmap* icon_large_; + // These icons are owned by the IconManager (owned by the BrowserProcess). + gfx::Image* icon_small_; + gfx::Image* icon_large_; // The last download file path for which we requested an icon. FilePath icon_filepath_; diff --git a/chrome/browser/ui/views/download_item_view.cc b/chrome/browser/ui/views/download_item_view.cc index b6098de..1783b16 100644 --- a/chrome/browser/ui/views/download_item_view.cc +++ b/chrome/browser/ui/views/download_item_view.cc @@ -26,6 +26,7 @@ #include "ui/base/text/text_elider.h" #include "ui/gfx/canvas_skia.h" #include "ui/gfx/color_utils.h" +#include "ui/gfx/image.h" #include "views/controls/button/native_button.h" #include "views/controls/menu/menu_2.h" #include "views/widget/root_view.h" @@ -652,10 +653,15 @@ void DownloadItemView::OnPaint(gfx::Canvas* canvas) { mirrored_x, y, kTextWidth, font_.GetHeight()); } - // Paint the icon. + // Load the icon. IconManager* im = g_browser_process->icon_manager(); - SkBitmap* icon = IsDangerousMode() ? warning_icon_ : - im->LookupIcon(download_->GetUserVerifiedFilePath(), IconLoader::SMALL); + gfx::Image* image = im->LookupIcon(download_->GetUserVerifiedFilePath(), + IconLoader::SMALL); + const SkBitmap* icon = NULL; + if (IsDangerousMode()) + icon = warning_icon_; + else if (image) + icon = *image; // We count on the fact that the icon manager will cache the icons and if one // is available, it will be cached here. We *don't* want to request the icon @@ -868,8 +874,8 @@ bool DownloadItemView::OnMouseDragged(const views::MouseEvent& event) { if (dragging_) { if (download_->state() == DownloadItem::COMPLETE) { IconManager* im = g_browser_process->icon_manager(); - SkBitmap* icon = im->LookupIcon(download_->GetUserVerifiedFilePath(), - IconLoader::SMALL); + gfx::Image* icon = im->LookupIcon(download_->GetUserVerifiedFilePath(), + IconLoader::SMALL); if (icon) { views::Widget* widget = GetWidget(); download_util::DragDownload(download_, icon, @@ -971,7 +977,7 @@ void DownloadItemView::OpenDownload() { } void DownloadItemView::OnExtractIconComplete(IconManager::Handle handle, - SkBitmap* icon_bitmap) { + gfx::Image* icon_bitmap) { if (icon_bitmap) parent()->SchedulePaint(); } diff --git a/chrome/browser/ui/views/download_item_view.h b/chrome/browser/ui/views/download_item_view.h index a2357c9..e8f427a 100644 --- a/chrome/browser/ui/views/download_item_view.h +++ b/chrome/browser/ui/views/download_item_view.h @@ -38,6 +38,10 @@ class DownloadShelfView; class SkBitmap; class DownloadShelfContextMenuWin; +namespace gfx { +class Image; +} + namespace ui { class SlideAnimation; } @@ -88,7 +92,7 @@ class DownloadItemView : public views::ButtonListener, void StopDownloadProgress(); // IconManager::Client interface. - void OnExtractIconComplete(IconManager::Handle handle, SkBitmap* icon_bitmap); + void OnExtractIconComplete(IconManager::Handle handle, gfx::Image* icon); // Returns the DownloadItem model object belonging to this item. DownloadItem* download() const { return download_; } @@ -179,7 +183,7 @@ class DownloadItemView : public views::ButtonListener, DropDownImageSet pushed_drop_down_image_set_; // The warning icon showns for dangerous downloads. - SkBitmap* warning_icon_; + const SkBitmap* warning_icon_; // The model we query for display information DownloadItem* download_; diff --git a/chrome/browser/ui/webui/downloads_dom_handler.cc b/chrome/browser/ui/webui/downloads_dom_handler.cc index 32e03af..272227f 100644 --- a/chrome/browser/ui/webui/downloads_dom_handler.cc +++ b/chrome/browser/ui/webui/downloads_dom_handler.cc @@ -27,6 +27,7 @@ #include "content/browser/browser_thread.h" #include "content/browser/tab_contents/tab_contents.h" #include "grit/generated_resources.h" +#include "ui/gfx/image.h" namespace { @@ -157,8 +158,8 @@ void DownloadsDOMHandler::HandleDrag(const ListValue* args) { DownloadItem* file = GetDownloadByValue(args); if (file) { IconManager* im = g_browser_process->icon_manager(); - SkBitmap* icon = im->LookupIcon(file->GetUserVerifiedFilePath(), - IconLoader::NORMAL); + gfx::Image* icon = im->LookupIcon(file->GetUserVerifiedFilePath(), + IconLoader::NORMAL); gfx::NativeView view = web_ui_->tab_contents()->GetNativeView(); download_util::DragDownload(file, icon, view); } diff --git a/chrome/browser/ui/webui/fileicon_source.cc b/chrome/browser/ui/webui/fileicon_source.cc index fe08a65..a1d97aa 100644 --- a/chrome/browser/ui/webui/fileicon_source.cc +++ b/chrome/browser/ui/webui/fileicon_source.cc @@ -12,7 +12,9 @@ #include "chrome/common/time_format.h" #include "grit/generated_resources.h" #include "net/base/escape.h" +#include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/codec/png_codec.h" +#include "ui/gfx/image.h" // The path used in internal URLs to file icon data. static const char kFileIconPath[] = "fileicon"; @@ -27,10 +29,7 @@ FileIconSource::~FileIconSource() { void FileIconSource::StartDataRequest(const std::string& path, bool is_off_the_record, int request_id) { - IconManager* im = g_browser_process->icon_manager(); - std::string escaped_path = UnescapeURLComponent(path, UnescapeRule::SPACES); - #if defined(OS_WIN) // The path we receive has the wrong slashes and escaping for what we need; // this only appears to matter for getting icons from .exe files. @@ -40,7 +39,9 @@ void FileIconSource::StartDataRequest(const std::string& path, // The correct encoding on Linux may not actually be UTF8. FilePath escaped_filepath(escaped_path); #endif - SkBitmap* icon = im->LookupIcon(escaped_filepath, IconLoader::NORMAL); + + IconManager* im = g_browser_process->icon_manager(); + gfx::Image* icon = im->LookupIcon(escaped_filepath, IconLoader::NORMAL); if (icon) { scoped_refptr<RefCountedBytes> icon_data(new RefCountedBytes); @@ -65,7 +66,7 @@ std::string FileIconSource::GetMimeType(const std::string&) const { } void FileIconSource::OnFileIconDataAvailable(IconManager::Handle handle, - SkBitmap* icon) { + gfx::Image* icon) { IconManager* im = g_browser_process->icon_manager(); int request_id = cancelable_consumer_.GetClientData(im, handle); diff --git a/chrome/browser/ui/webui/fileicon_source.h b/chrome/browser/ui/webui/fileicon_source.h index d160cb6..81dae47 100644 --- a/chrome/browser/ui/webui/fileicon_source.h +++ b/chrome/browser/ui/webui/fileicon_source.h @@ -14,6 +14,10 @@ class GURL; class RefCountedBytes; +namespace gfx { +class Image; +} + // FileIconSource is the gateway between network-level chrome: // requests for favicons and the history backend that serves these. class FileIconSource : public ChromeURLDataManager::DataSource { @@ -31,7 +35,7 @@ class FileIconSource : public ChromeURLDataManager::DataSource { // Called when favicon data is available from the history backend. void OnFileIconDataAvailable( IconManager::Handle request_handle, - SkBitmap* icon); + gfx::Image* icon); private: virtual ~FileIconSource(); |