From def8d424ee935324641788246795db6b5765387e Mon Sep 17 00:00:00 2001 From: "mmoss@chromium.org" Date: Fri, 20 Feb 2009 08:06:04 +0000 Subject: Make BrowserWindowGtk work with resource bundle theme images. This is a quick fix to allow chrome to run from outside the build tree (so I can make a demo package). More extensive reworking is underway separately by evanm. Review URL: http://codereview.chromium.org/20530 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10083 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/gtk/browser_window_gtk.cc | 53 ++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 86bbfa4..06ad7af 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -15,16 +15,37 @@ #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" #include "chrome/browser/tab_contents/web_contents.h" +#include "chrome/common/resource_bundle.h" +#include "grit/theme_resources.h" + namespace { -static GdkPixbuf* LoadThemeImage(const std::string& filename) { - FilePath path; - bool ok = PathService::Get(base::DIR_SOURCE_ROOT, &path); - DCHECK(ok); - path = path.Append("chrome/app/theme").Append(filename); - // We intentionally ignore errors here, as some buttons don't have images - // for all states. This will all be removed once ResourceBundle works. - return gdk_pixbuf_new_from_file(path.value().c_str(), NULL); +static GdkPixbuf* LoadThemeImage(int resource_id) { + // TODO(mmoss) refactor -- stolen from custom_button.cc + if (0 == resource_id) + return NULL; + + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + std::vector data; + rb.LoadImageResourceBytes(resource_id, &data); + + GdkPixbufLoader* loader = gdk_pixbuf_loader_new(); + bool ok = gdk_pixbuf_loader_write(loader, static_cast(data.data()), + data.size(), NULL); + DCHECK(ok) << "failed to write " << resource_id; + // Calling gdk_pixbuf_loader_close forces the data to be parsed by the + // loader. We must do this before calling gdk_pixbuf_loader_get_pixbuf. + ok = gdk_pixbuf_loader_close(loader, NULL); + DCHECK(ok) << "close failed " << resource_id; + GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); + DCHECK(pixbuf) << "failed to load " << resource_id << " " << data.size(); + + // The pixbuf is owned by the loader, so add a ref so when we delete the + // loader, the pixbuf still exists. + g_object_ref(pixbuf); + g_object_unref(loader); + + return pixbuf; } gboolean MainWindowDestroyed(GtkWindow* window, BrowserWindowGtk* browser_win) { @@ -120,15 +141,15 @@ void BrowserWindowGtk::Init() { bounds_ = GetInitialWindowBounds(window_); GdkPixbuf* images[9] = { - LoadThemeImage("content_top_left_corner.png"), - LoadThemeImage("content_top_center.png"), - LoadThemeImage("content_top_right_corner.png"), - LoadThemeImage("content_left_side.png"), + LoadThemeImage(IDR_CONTENT_TOP_LEFT_CORNER), + LoadThemeImage(IDR_CONTENT_TOP_CENTER), + LoadThemeImage(IDR_CONTENT_TOP_RIGHT_CORNER), + LoadThemeImage(IDR_CONTENT_LEFT_SIDE), NULL, - LoadThemeImage("content_right_side.png"), - LoadThemeImage("content_bottom_left_corner.png"), - LoadThemeImage("content_bottom_center.png"), - LoadThemeImage("content_bottom_right_corner.png") + LoadThemeImage(IDR_CONTENT_RIGHT_SIDE), + LoadThemeImage(IDR_CONTENT_BOTTOM_LEFT_CORNER), + LoadThemeImage(IDR_CONTENT_BOTTOM_CENTER), + LoadThemeImage(IDR_CONTENT_BOTTOM_RIGHT_CORNER) }; content_area_ninebox_.reset(new NineBox(images)); -- cgit v1.1