diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-20 21:09:00 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-20 21:09:00 +0000 |
commit | 3e45ba94d8be022dd139b60772fe5025cfe542cf (patch) | |
tree | c017d907ed512731711653bccb3ed685b2ee6f05 /chrome/browser/gtk | |
parent | d7943126bb5f9ef65b6270e52420a6f1859cf7d9 (diff) | |
download | chromium_src-3e45ba94d8be022dd139b60772fe5025cfe542cf.zip chromium_src-3e45ba94d8be022dd139b60772fe5025cfe542cf.tar.gz chromium_src-3e45ba94d8be022dd139b60772fe5025cfe542cf.tar.bz2 |
Show page icons on back/forward menu lists on linux.
Also fix some gtk memory warnings and enable some code for favicon fetching.
Review URL: http://codereview.chromium.org/21532
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10126 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/chrome/browser/gtk/menu_gtk.cc b/chrome/browser/gtk/menu_gtk.cc index 4efe09e..af6c4e9 100644 --- a/chrome/browser/gtk/menu_gtk.cc +++ b/chrome/browser/gtk/menu_gtk.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "base/string_util.h" #include "chrome/common/l10n_util.h" +#include "skia/include/SkBitmap.h" namespace { @@ -30,18 +31,59 @@ std::wstring ConvertAcceleratorsFromWindowsStyle(const std::wstring& label) { return ret; } +void FreePixels(guchar* pixels, gpointer data) { + free(data); } +// We have to copy the pixels and reverse their order manually. +GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap) { + bitmap->lockPixels(); + int width = bitmap->width(); + int height = bitmap->height(); + int stride = bitmap->rowBytes(); + const guchar* orig_data = static_cast<guchar*>(bitmap->getPixels()); + guchar* data = static_cast<guchar*>(malloc(height * stride)); + + // Swap from BGRA to RGBA. + for (int i = 0; i < height; ++i) { + for (int j = 0; j < width; ++j) { + int idx = i * stride + j * 4; + data[idx] = orig_data[idx + 2]; + data[idx + 1] = orig_data[idx + 1]; + data[idx + 2] = orig_data[idx]; + data[idx + 3] = orig_data[idx + 3]; + } + } + + // This pixbuf takes ownership of our malloc()ed data and will + // free it for us when it is destroyed. + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data( + data, + GDK_COLORSPACE_RGB, // the only colorspace gtk supports + true, // there is an alpha channel + 8, + width, height, stride, &FreePixels, data); + + // Assume ownership of pixbuf. + g_object_ref_sink(pixbuf); + bitmap->unlockPixels(); + return pixbuf; +} + +} // namespace + MenuGtk::MenuGtk(MenuGtk::Delegate* delegate, const MenuCreateMaterial* menu_data) : delegate_(delegate), menu_(gtk_menu_new()) { + g_object_ref_sink(menu_); BuildMenuIn(menu_, menu_data); } MenuGtk::MenuGtk(MenuGtk::Delegate* delegate) : delegate_(delegate), menu_(gtk_menu_new()) { + g_object_ref_sink(menu_); BuildMenuFromDelegate(); } @@ -125,7 +167,11 @@ void MenuGtk::BuildMenuFromDelegate() { } else if (delegate_->HasIcon(i)) { menu_item = gtk_image_menu_item_new_with_label( delegate_->GetLabel(i).c_str()); - // TODO(port): set the image with delegate->GetIcon() + const SkBitmap* icon = delegate_->GetIcon(i); + GdkPixbuf* pixbuf = GdkPixbufFromSkBitmap(icon); + GtkWidget* widget = gtk_image_new_from_pixbuf(pixbuf); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), widget); + g_object_unref(pixbuf); } else { menu_item = gtk_menu_item_new_with_label(delegate_->GetLabel(i).c_str()); } |