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 | |
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
-rw-r--r-- | chrome/browser/browser.scons | 1 | ||||
-rw-r--r-- | chrome/browser/gtk/menu_gtk.cc | 48 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 21 | ||||
-rw-r--r-- | chrome/chrome.xcodeproj/project.pbxproj | 2 | ||||
-rw-r--r-- | chrome/common/temp_scaffolding_stubs.h | 5 | ||||
-rw-r--r-- | webkit/glue/image_decoder.cc | 2 |
6 files changed, 68 insertions, 11 deletions
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons index 1d2d6df..09a977b 100644 --- a/chrome/browser/browser.scons +++ b/chrome/browser/browser.scons @@ -731,7 +731,6 @@ if not env.Bit('windows'): 'shell_integration.cc', 'tab_contents/native_ui_contents.cc', 'tab_contents/render_view_context_menu.cc', - 'tab_contents/tab_contents.cc', 'tab_contents/view_source_contents.cc', 'tab_contents/web_drag_source.cc', 'tab_contents/web_drop_target.cc', 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()); } diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index c928031..087198a 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -2,13 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#if defined(OS_WIN) #include "chrome/browser/tab_contents/tab_contents.h" +#elif defined(OS_POSIX) +#include "chrome/common/temp_scaffolding_stubs.h" +#endif #include "chrome/browser/cert_store.h" -#include "chrome/browser/views/download_shelf_view.h" -#include "chrome/browser/views/download_started_animation.h" -#include "chrome/browser/views/blocked_popup_container.h" -#include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/tab_contents/web_contents.h" @@ -16,14 +16,24 @@ #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" + +#if defined(OS_WIN) +// TODO(port): some of these headers should be ported. +#include "chrome/browser/tab_contents/infobar_delegate.h" +#include "chrome/browser/views/download_shelf_view.h" +#include "chrome/browser/views/download_started_animation.h" +#include "chrome/browser/views/blocked_popup_container.h" #include "chrome/views/native_scroll_bar.h" #include "chrome/views/root_view.h" #include "chrome/views/view.h" #include "chrome/views/view_storage.h" #include "chrome/views/widget.h" +#endif #include "generated_resources.h" +// TODO(port): port the rest of this file. +#if defined(OS_WIN) namespace { BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { @@ -181,6 +191,7 @@ void TabContents::UpdateMaxPageID(int32 page_id) { const std::wstring TabContents::GetDefaultTitle() const { return l10n_util::GetString(IDS_DEFAULT_TAB_TITLE); } +#endif // defined(OS_WIN) SkBitmap TabContents::GetFavIcon() const { // Like GetTitle(), we also want to use the favicon for the last committed @@ -197,6 +208,7 @@ SkBitmap TabContents::GetFavIcon() const { return SkBitmap(); } +#if defined(OS_WIN) SecurityStyle TabContents::GetSecurityStyle() const { // We may not have a navigation entry yet. NavigationEntry* entry = controller_->GetActiveEntry(); @@ -623,3 +635,4 @@ void TabContents::ExpireInfoBars( RemoveInfoBar(delegate); } } +#endif // defined(OS_WIN) diff --git a/chrome/chrome.xcodeproj/project.pbxproj b/chrome/chrome.xcodeproj/project.pbxproj index 5f58e72..cc7b7ca 100644 --- a/chrome/chrome.xcodeproj/project.pbxproj +++ b/chrome/chrome.xcodeproj/project.pbxproj @@ -598,6 +598,7 @@ E765478D55A73228BAD044E3 /* cert_store.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF8570E9D4839009A6919 /* cert_store.cc */; }; E9104FE91402AE1783A22D93 /* alternate_nav_url_fetcher.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BF8240E9D4839009A6919 /* alternate_nav_url_fetcher.cc */; }; EA8058FD371756B46906B157 /* password_manager.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5D16EB40F21445600861FAC /* password_manager.cc */; }; + EEA5B4CB2EB282403BDE41D7 /* tab_contents.cc in Sources */ = {isa = PBXBuildFile; fileRef = B6CCB9E40F1EC32700106F0D /* tab_contents.cc */; }; F081CEE97F8C75FEAF3D0FD2 /* jstemplate_builder.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4D7BFBC70E9D4C9F009A6919 /* jstemplate_builder.cc */; }; F4143C8C0F4B1D43008C8F73 /* renderer.sb in Resources */ = {isa = PBXBuildFile; fileRef = F4143C8B0F4B1D07008C8F73 /* renderer.sb */; }; F47CA1280F44AE0E00FFFAFB /* libnet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D7B004E0E9D5464009A6919 /* libnet.a */; }; @@ -5539,6 +5540,7 @@ E4F3245D0EE5CFDF002533CE /* starred_url_database.cc in Sources */, E45075EE0F150ABA003BE099 /* sync_resource_handler.cc in Sources */, E455DDBA0F3227A600DD4383 /* tab_cell.mm in Sources */, + EEA5B4CB2EB282403BDE41D7 /* tab_contents.cc in Sources */, E455DCF10F320CFE00DD4383 /* tab_contents_controller.mm in Sources */, B57F3A38042C46748C19E75B /* tab_contents_factory.cc in Sources */, 1C284EB767D0E3D302AC675C /* tab_restore_service.cc in Sources */, diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h index 8f2adb8..5d36a24 100644 --- a/chrome/common/temp_scaffolding_stubs.h +++ b/chrome/common/temp_scaffolding_stubs.h @@ -382,10 +382,7 @@ class TabContents : public PageNavigator, public NotificationObserver { WebContents* AsWebContents() const { return const_cast<TabContents*>(this)->AsWebContents(); } - virtual SkBitmap GetFavIcon() const { - NOTIMPLEMENTED(); - return SkBitmap(); - } + virtual SkBitmap GetFavIcon() const; const GURL& GetURL() const; virtual const std::wstring& GetTitle() const; TabContentsType type() const { return type_; } diff --git a/webkit/glue/image_decoder.cc b/webkit/glue/image_decoder.cc index 946f4b3..e7abc58 100644 --- a/webkit/glue/image_decoder.cc +++ b/webkit/glue/image_decoder.cc @@ -49,7 +49,7 @@ SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) const { #endif WTF::RefPtr<WebCore::SharedBuffer> buffer(WebCore::SharedBuffer::create( data, static_cast<int>(size))); -#if defined(OS_WIN) +#if defined(OS_WIN) || defined(OS_LINUX) source.setData(buffer.get(), true, WebCore::IntSize(desired_icon_size_.width(), desired_icon_size_.height())); |