diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 00:24:39 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 00:24:39 +0000 |
commit | dcefa305312e7045cce1ec6bc746a4ba26dec871 (patch) | |
tree | 7fbea6592ac6d4c59cc456227a3d5195818a7679 | |
parent | cf2a4e4fe2c337c2c4bf4f14443fc2cbb3f6e2d9 (diff) | |
download | chromium_src-dcefa305312e7045cce1ec6bc746a4ba26dec871.zip chromium_src-dcefa305312e7045cce1ec6bc746a4ba26dec871.tar.gz chromium_src-dcefa305312e7045cce1ec6bc746a4ba26dec871.tar.bz2 |
Linux download shelf icons first cut.
Nor do we have support for alternate file formats; nor do we have a default icon.
BUG=http://crbug.com/8631
Review URL: http://codereview.chromium.org/113571
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16444 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/mime_util.h | 2 | ||||
-rw-r--r-- | base/mime_util_linux.cc | 17 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 2 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_dom_handler.cc | 12 | ||||
-rw-r--r-- | chrome/browser/dom_ui/downloads_ui.cc | 8 | ||||
-rw-r--r-- | chrome/browser/dom_ui/fileicon_source.h | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/download_item_gtk.cc | 29 | ||||
-rw-r--r-- | chrome/browser/gtk/download_item_gtk.h | 15 | ||||
-rw-r--r-- | chrome/browser/icon_loader_linux.cc | 29 | ||||
-rw-r--r-- | chrome/browser/icon_manager_linux.cc | 5 | ||||
-rw-r--r-- | chrome/chrome.gyp | 1 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.h | 20 | ||||
-rw-r--r-- | net/base/platform_mime_util_linux.cc | 4 |
13 files changed, 104 insertions, 46 deletions
diff --git a/base/mime_util.h b/base/mime_util.h index 850613b..47c5975 100644 --- a/base/mime_util.h +++ b/base/mime_util.h @@ -15,7 +15,7 @@ namespace mime_util { // have to exist. Please note because it doesn't touch the disk, this does not // work for directories. // If the mime type is unknown, this will return application/octet-stream. -std::string GetFileMimeType(const std::string& file_path); +std::string GetFileMimeType(const FilePath& filepath); // Gets the file name for an icon given the mime type and icon pixel size. // Where an icon is a square image of |size| x |size|. diff --git a/base/mime_util_linux.cc b/base/mime_util_linux.cc index 36d9029..15abd5c 100644 --- a/base/mime_util_linux.cc +++ b/base/mime_util_linux.cc @@ -21,6 +21,9 @@ namespace { +// Toggles whether we can handle SVG icons. See http://crbug.com/12272 +const bool kEnableSVG = false; + class IconTheme; class MimeUtilConstants { @@ -435,7 +438,7 @@ void EnsureUpdated() { constants->icon_dirs = new std::map<FilePath, int>; constants->icon_themes = new std::map<std::string, IconTheme*>; constants->icon_formats = new std::vector<std::string>; - EnableSvgIcon(true); + EnableSvgIcon(kEnableSVG); InitIconDir(); constants->last_check_time = now; } else { @@ -467,6 +470,9 @@ FilePath LookupFallbackIcon(const std::string& icon_name) { void InitDefaultThemes() { IconTheme** default_themes = Singleton<MimeUtilConstants>::get()->default_themes; + for (size_t i = 0; i < MimeUtilConstants::kDefaultThemeNum; ++i) + default_themes[i] = NULL; + // TODO(thestig): There is no standard way to know about the current icon // theme. So just make a guess. We may be able to do this better. If so, // upstream fix to Google Gadgets for Linux. @@ -500,11 +506,12 @@ FilePath LookupIconInDefaultTheme(const std::string& icon_name, int size) { EnsureUpdated(); MimeUtilConstants* constants = Singleton<MimeUtilConstants>::get(); std::map<std::string, IconTheme*>* icon_themes = constants->icon_themes; - if (icon_themes->size() == 0) InitDefaultThemes(); + if (icon_themes->size() == 0) + InitDefaultThemes(); FilePath icon_path; IconTheme** default_themes = constants->default_themes; - for (size_t i = 0; i < constants->kDefaultThemeNum; i++) { + for (size_t i = 0; i < MimeUtilConstants::kDefaultThemeNum; i++) { if (default_themes[i]) { icon_path = default_themes[i]->GetIconPath(icon_name, size, true); if (!icon_path.empty()) @@ -526,8 +533,8 @@ MimeUtilConstants::~MimeUtilConstants() { namespace mime_util { -std::string GetFileMimeType(const std::string& file_path) { - return xdg_mime_get_mime_type_from_file_name(file_path.c_str()); +std::string GetFileMimeType(const FilePath& filepath) { + return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); } FilePath GetMimeIcon(const std::string& mime_type, size_t size) { diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 759934b..18e3a83 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -17,6 +17,7 @@ #include "chrome/browser/download/download_file.h" #include "chrome/browser/download/save_file_manager.h" #include "chrome/browser/google_url_tracker.h" +#include "chrome/browser/icon_manager.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/net/dns_global.h" #include "chrome/browser/net/sdch_dictionary_fetcher.h" @@ -33,7 +34,6 @@ #if defined(OS_WIN) #include "chrome/browser/automation/automation_provider_list.h" -#include "chrome/browser/icon_manager.h" #include "chrome/browser/printing/print_job_manager.h" #include "views/focus/view_storage.h" #include "views/widget/accelerator_handler.h" diff --git a/chrome/browser/dom_ui/downloads_dom_handler.cc b/chrome/browser/dom_ui/downloads_dom_handler.cc index ea56c07..f38a664 100644 --- a/chrome/browser/dom_ui/downloads_dom_handler.cc +++ b/chrome/browser/dom_ui/downloads_dom_handler.cc @@ -5,6 +5,7 @@ #include "chrome/browser/dom_ui/downloads_dom_handler.h" #include "app/l10n_util.h" +#include "base/basictypes.h" #include "base/gfx/png_encoder.h" #include "base/string_piece.h" #include "base/thread.h" @@ -12,10 +13,6 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" #include "chrome/browser/dom_ui/fileicon_source.h" -#if defined(OS_WIN) -// TODO(port): re-enable when download_util is ported -#include "chrome/browser/download/download_util.h" -#endif #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/profile.h" #include "chrome/common/jstemplate_builder.h" @@ -24,6 +21,13 @@ #include "grit/browser_resources.h" #include "grit/generated_resources.h" +#if defined(OS_WIN) +// TODO(port): re-enable when download_util is ported +#include "chrome/browser/download/download_util.h" +#else +#include "chrome/common/temp_scaffolding_stubs.h" +#endif + namespace { // Maximum number of downloads to show. TODO(glen): Remove this and instead diff --git a/chrome/browser/dom_ui/downloads_ui.cc b/chrome/browser/dom_ui/downloads_ui.cc index 76eb9074..9039200 100644 --- a/chrome/browser/dom_ui/downloads_ui.cc +++ b/chrome/browser/dom_ui/downloads_ui.cc @@ -19,6 +19,14 @@ #include "grit/browser_resources.h" #include "grit/generated_resources.h" +#if defined(OS_WIN) +// TODO(port): re-enable when download_util is ported +#include "chrome/browser/download/download_util.h" +#else +#include "chrome/common/temp_scaffolding_stubs.h" +#endif + + namespace { /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/dom_ui/fileicon_source.h b/chrome/browser/dom_ui/fileicon_source.h index 423efcb..0f2924d 100644 --- a/chrome/browser/dom_ui/fileicon_source.h +++ b/chrome/browser/dom_ui/fileicon_source.h @@ -7,13 +7,7 @@ #include "app/resource_bundle.h" #include "chrome/browser/dom_ui/chrome_url_data_manager.h" - -#if defined(OS_WIN) #include "chrome/browser/icon_manager.h" -#else -// TODO(port): Remove when IconManager has been ported. -#include "chrome/common/temp_scaffolding_stubs.h" -#endif class GURL; diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc index 02f2f3f..80996f3 100644 --- a/chrome/browser/gtk/download_item_gtk.cc +++ b/chrome/browser/gtk/download_item_gtk.cc @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/string_util.h" #include "base/time.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/download/download_item_model.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_shelf.h" @@ -21,6 +22,7 @@ #include "chrome/common/gtk_util.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" +#include "third_party/skia/include/core/SkBitmap.h" namespace { @@ -148,8 +150,10 @@ DownloadItemGtk::DownloadItemGtk(DownloadShelfGtk* parent_shelf, : parent_shelf_(parent_shelf), progress_angle_(download_util::kStartAngleDegrees), download_model_(download_model), - bounding_widget_(parent_shelf->GetRightBoundingWidget()) { + bounding_widget_(parent_shelf->GetRightBoundingWidget()), + icon_(NULL) { InitNineBoxes(); + LoadIcon(); body_ = gtk_button_new(); gtk_widget_set_app_paintable(body_, TRUE); @@ -326,6 +330,21 @@ void DownloadItemGtk::StopDownloadProgress() { progress_timer_.Stop(); } +// Icon loading functions. + +void DownloadItemGtk::OnLoadIconComplete(IconManager::Handle handle, + SkBitmap* icon_bitmap) { + icon_ = icon_bitmap; + gtk_widget_queue_draw(progress_area_); +} + +void DownloadItemGtk::LoadIcon() { + IconManager* im = g_browser_process->icon_manager(); + im->LoadIcon(download_model_->download()->full_path(), + IconLoader::SMALL, &icon_consumer_, + NewCallback(this, &DownloadItemGtk::OnLoadIconComplete)); +} + // static void DownloadItemGtk::InitNineBoxes() { if (body_nine_box_normal_) @@ -422,7 +441,13 @@ gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, download_util::SMALL); } - // TODO(estade): paint download icon. + // TODO(estade): draw a default icon if |icon_| is null. + if (download_item->icon_) { + canvas.DrawBitmapInt(*download_item->icon_, + widget->allocation.x + download_util::kSmallProgressIconOffset, + widget->allocation.y + download_util::kSmallProgressIconOffset); + } + return TRUE; } diff --git a/chrome/browser/gtk/download_item_gtk.h b/chrome/browser/gtk/download_item_gtk.h index 00f1795..fd21680 100644 --- a/chrome/browser/gtk/download_item_gtk.h +++ b/chrome/browser/gtk/download_item_gtk.h @@ -10,11 +10,13 @@ #include "app/animation.h" #include "base/scoped_ptr.h" #include "chrome/browser/download/download_manager.h" +#include "chrome/browser/icon_manager.h" class BaseDownloadItemModel; class DownloadShelfContextMenuGtk; class DownloadShelfGtk; class NineBox; +class SkBitmap; class SlideAnimation; class DownloadItemGtk : public DownloadItem::Observer, @@ -35,6 +37,10 @@ class DownloadItemGtk : public DownloadItem::Observer, // AnimationDelegate implementation. virtual void AnimationProgressed(const Animation* animation); + // Called when the icon manager has finished loading the icon. We take + // ownership of |icon_bitmap|. + void OnLoadIconComplete(IconManager::Handle handle, SkBitmap* icon_bitmap); + private: // Functions for controlling the progress animation. // Repaint the download progress. @@ -46,6 +52,9 @@ class DownloadItemGtk : public DownloadItem::Observer, // Stops the repeating timer. void StopDownloadProgress(); + // Ask the icon manager to asynchronously start loading the icon for the file. + void LoadIcon(); + static void InitNineBoxes(); // Used for the download item's body and menu button. @@ -124,6 +133,12 @@ class DownloadItemGtk : public DownloadItem::Observer, // Animation for download complete. scoped_ptr<SlideAnimation> complete_animation_; + + // The file icon for the download. May be null. + SkBitmap* icon_; + + // For canceling an in progress icon request. + CancelableRequestConsumerT<int, 0> icon_consumer_; }; #endif // CHROME_BROWSER_GTK_DOWNLOAD_ITEM_GTK_H_ diff --git a/chrome/browser/icon_loader_linux.cc b/chrome/browser/icon_loader_linux.cc index 83a8305..26788d8 100644 --- a/chrome/browser/icon_loader_linux.cc +++ b/chrome/browser/icon_loader_linux.cc @@ -4,11 +4,38 @@ #include "chrome/browser/icon_loader.h" +#include "base/file_util.h" +#include "base/gfx/png_decoder.h" +#include "base/logging.h" #include "base/message_loop.h" +#include "base/mime_util.h" #include "base/thread.h" +#include "base/string_util.h" +#include "third_party/skia/include/core/SkBitmap.h" void IconLoader::ReadIcon() { - NOTIMPLEMENTED(); + size_t size = 48; + if (icon_size_ == NORMAL) + size = 32; + else if (icon_size_ == SMALL) + size = 16; + + FilePath filename = mime_util::GetMimeIcon(group_, size); + if (LowerCaseEqualsASCII(mime_util::GetFileMimeType(filename), "image/png")) { + std::string file_contents; + file_util::ReadFileToString(filename, &file_contents); + + std::vector<unsigned char> pixels; + int width, height; + if (PNGDecoder::Decode( + reinterpret_cast<const unsigned char*>(file_contents.c_str()), + file_contents.length(), PNGDecoder::FORMAT_BGRA, + &pixels, &width, &height)) { + bitmap_ = PNGDecoder::CreateSkBitmapFromBGRAFormat(pixels, width, height); + } + } else { + // TODO(estade): support other file types. + } target_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, &IconLoader::NotifyDelegate)); diff --git a/chrome/browser/icon_manager_linux.cc b/chrome/browser/icon_manager_linux.cc index 3e5d8be..c653d2f 100644 --- a/chrome/browser/icon_manager_linux.cc +++ b/chrome/browser/icon_manager_linux.cc @@ -4,9 +4,8 @@ #include "chrome/browser/icon_manager.h" -#include "base/file_path.h" +#include "base/mime_util.h" IconGroupID IconManager::GetGroupIDFromFilepath(const FilePath& filepath) { - NOTIMPLEMENTED(); - return std::string(); + return mime_util::GetFileMimeType(filepath); } diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 6644c45..7741491 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1529,7 +1529,6 @@ 'browser/bookmarks/bookmark_context_menu.cc', 'browser/bookmarks/bookmark_drop_info.cc', 'browser/debugger/debugger_shell_stubs.cc', - 'browser/icon_manager.cc', ], 'sources': [ # Build the necessary GTM sources diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h index ac62d3c1..7fad342 100644 --- a/chrome/common/temp_scaffolding_stubs.h +++ b/chrome/common/temp_scaffolding_stubs.h @@ -323,26 +323,6 @@ namespace download_util { void DragDownload(const DownloadItem* download, SkBitmap* icon); } // namespace download_util -class IconLoader { - public: - enum IconSize { - SMALL = 0, // 16x16 - NORMAL, // 32x32 - LARGE - }; -}; - -class IconManager : public CancelableRequestProvider { - public: - typedef CancelableRequestProvider::Handle Handle; - typedef Callback2<Handle, SkBitmap*>::Type IconRequestCallback; - SkBitmap* LookupIcon(const FilePath&, IconLoader::IconSize) - { NOTIMPLEMENTED(); return NULL; } - Handle LoadIcon(const FilePath&, IconLoader::IconSize, - CancelableRequestConsumerBase*, IconRequestCallback*) - { NOTIMPLEMENTED(); return NULL; } -}; - class DebuggerWindow : public base::RefCountedThreadSafe<DebuggerWindow> { public: }; diff --git a/net/base/platform_mime_util_linux.cc b/net/base/platform_mime_util_linux.cc index 105048d..7debe35 100644 --- a/net/base/platform_mime_util_linux.cc +++ b/net/base/platform_mime_util_linux.cc @@ -18,12 +18,12 @@ bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( if (ext == "pl") return false; - FilePath::StringType dummy_path = "foo." + ext; + FilePath dummy_path("foo." + ext); std::string out = mime_util::GetFileMimeType(dummy_path); // GetFileMimeType likes to return application/octet-stream // for everything it doesn't know - ignore that. - if (out == "application/octet-stream" || !out.length()) + if (out == "application/octet-stream" || out.empty()) return false; // GetFileMimeType returns image/x-ico because that's what's in the XDG |