Changeset 28809 in webkit
- Timestamp:
- Dec 17, 2007 8:18:44 AM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r28798 r28809 1 2007-12-17 Christian Dywan <christian@twotoasts.de> 2 3 Reviewed by Alp Toker. 4 5 http://bugs.webkit.org/show_bug.cgi?id=16378 6 Implement Icon for Gtk 7 8 Icon provides a GdkPixbuf containing a themed icon. 9 The icon theme is probed for an icon name according to the 10 Icon Naming Specification or conventional Gnome icon names respectively. 11 12 See http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html 13 14 * platform/graphics/Icon.h: 15 * platform/graphics/gtk/IconGtk.cpp: 16 (WebCore::Icon::~Icon): 17 (WebCore::lookupIconName): 18 (WebCore::Icon::newIconForFile): 19 (WebCore::Icon::paint): 20 1 21 2007-12-16 Sam Weinig <sam@webkit.org> 2 22 -
trunk/WebCore/platform/graphics/Icon.h
r27776 r28809 36 36 #elif PLATFORM(QT) 37 37 #include <QIcon> 38 #elif PLATFORM(GTK) 39 #include <gdk/gdk.h> 38 40 #endif 39 41 … … 67 69 #elif PLATFORM(QT) 68 70 QIcon m_icon; 71 #elif PLATFORM(GTK) 72 GdkPixbuf* m_icon; 69 73 #endif 70 74 }; -
trunk/WebCore/platform/graphics/gtk/IconGtk.cpp
r25703 r28809 31 31 #include "Icon.h" 32 32 33 #include "CString.h" 34 #include "GraphicsContext.h" 35 #include "MIMETypeRegistry.h" 33 36 #include "NotImplemented.h" 34 37 #include "PassRefPtr.h" 38 39 #include <gtk/gtk.h> 35 40 36 41 namespace WebCore { 37 42 38 43 Icon::Icon() 44 : m_icon(0) 39 45 { 40 46 notImplemented(); … … 43 49 Icon::~Icon() 44 50 { 45 notImplemented(); 51 if(m_icon) 52 g_object_unref(m_icon); 46 53 } 47 54 48 PassRefPtr<Icon> Icon::newIconForFile(const String&)55 static String lookupIconName(String MIMEType) 49 56 { 50 notImplemented(); 51 return PassRefPtr<Icon>(new Icon()); 57 /* 58 Lookup an appropriate icon according to either the Icon Naming Spec 59 or conventional Gnome icon names respectively. 60 61 See http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html 62 63 The icon theme is probed for the following names: 64 1. media-subtype 65 2. gnome-mime-media-subtype 66 3. media-x-generic 67 4. gnome-mime-media 68 69 In the worst case it falls back to the stock file icon. 70 */ 71 int pos = MIMEType.find('/'); 72 if(pos >= 0) { 73 String media = MIMEType.substring(0, pos); 74 String subtype = MIMEType.substring(pos + 1); 75 GtkIconTheme* iconTheme = gtk_icon_theme_get_default(); 76 String iconName = media + "-" + subtype; 77 if(gtk_icon_theme_has_icon(iconTheme, iconName.utf8().data())) 78 return iconName; 79 iconName = "gnome-mime-" + media + "-" + subtype; 80 if(gtk_icon_theme_has_icon(iconTheme, iconName.utf8().data())) 81 return iconName; 82 iconName = media + "-x-generic"; 83 if(gtk_icon_theme_has_icon(iconTheme, iconName.utf8().data())) 84 return iconName; 85 iconName = media + "gnome-mime-" + media; 86 if(gtk_icon_theme_has_icon(iconTheme, iconName.utf8().data())) 87 return iconName; 88 } 89 return GTK_STOCK_FILE; 52 90 } 53 91 54 void Icon::paint(GraphicsContext*, const IntRect&)92 PassRefPtr<Icon> Icon::newIconForFile(const String& filename) 55 93 { 56 notImplemented(); 94 if (!g_path_skip_root(filename.utf8().data())) 95 return 0; 96 97 String MIMEType = MIMETypeRegistry::getMIMETypeForPath(filename); 98 String iconName = lookupIconName(MIMEType); 99 100 Icon* icon = new Icon; 101 icon->m_icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), iconName.utf8().data(), 16, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); 102 return icon->m_icon ? icon : 0; 103 } 104 105 void Icon::paint(GraphicsContext* context, const IntRect& rect) 106 { 107 // TODO: Scale/clip the image if necessary. 108 cairo_t* cr = context->platformContext(); 109 cairo_save(cr); 110 gdk_cairo_set_source_pixbuf(cr, m_icon, rect.x(), rect.y()); 111 cairo_paint(cr); 112 cairo_restore(cr); 57 113 } 58 114
Note: See TracChangeset
for help on using the changeset viewer.