Commit 809e7a79 authored by alp@webkit.org's avatar alp@webkit.org

2007-12-17 Christian Dywan <christian@twotoasts.de>

        Reviewed by Alp Toker.

        http://bugs.webkit.org/show_bug.cgi?id=16378
        Implement Icon for Gtk

        Icon provides a GdkPixbuf containing a themed icon.
        The icon theme is probed for an icon name according to the
        Icon Naming Specification or conventional Gnome icon names respectively.

        See http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html

        * platform/graphics/Icon.h:
        * platform/graphics/gtk/IconGtk.cpp:
        (WebCore::Icon::~Icon):
        (WebCore::lookupIconName):
        (WebCore::Icon::newIconForFile):
        (WebCore::Icon::paint):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@28809 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 896e750c
2007-12-17 Christian Dywan <christian@twotoasts.de>
Reviewed by Alp Toker.
http://bugs.webkit.org/show_bug.cgi?id=16378
Implement Icon for Gtk
Icon provides a GdkPixbuf containing a themed icon.
The icon theme is probed for an icon name according to the
Icon Naming Specification or conventional Gnome icon names respectively.
See http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
* platform/graphics/Icon.h:
* platform/graphics/gtk/IconGtk.cpp:
(WebCore::Icon::~Icon):
(WebCore::lookupIconName):
(WebCore::Icon::newIconForFile):
(WebCore::Icon::paint):
2007-12-16 Sam Weinig <sam@webkit.org>
Reviewed by Mitz.
......
......@@ -35,6 +35,8 @@ class NSImage;
typedef struct HICON__* HICON;
#elif PLATFORM(QT)
#include <QIcon>
#elif PLATFORM(GTK)
#include <gdk/gdk.h>
#endif
namespace WebCore {
......@@ -66,6 +68,8 @@ private:
HICON m_hIcon;
#elif PLATFORM(QT)
QIcon m_icon;
#elif PLATFORM(GTK)
GdkPixbuf* m_icon;
#endif
};
......
......@@ -30,30 +30,86 @@
#include "config.h"
#include "Icon.h"
#include "CString.h"
#include "GraphicsContext.h"
#include "MIMETypeRegistry.h"
#include "NotImplemented.h"
#include "PassRefPtr.h"
#include <gtk/gtk.h>
namespace WebCore {
Icon::Icon()
: m_icon(0)
{
notImplemented();
}
Icon::~Icon()
{
notImplemented();
if(m_icon)
g_object_unref(m_icon);
}
PassRefPtr<Icon> Icon::newIconForFile(const String&)
static String lookupIconName(String MIMEType)
{
notImplemented();
return PassRefPtr<Icon>(new Icon());
/*
Lookup an appropriate icon according to either the Icon Naming Spec
or conventional Gnome icon names respectively.
See http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
The icon theme is probed for the following names:
1. media-subtype
2. gnome-mime-media-subtype
3. media-x-generic
4. gnome-mime-media
In the worst case it falls back to the stock file icon.
*/
int pos = MIMEType.find('/');
if(pos >= 0) {
String media = MIMEType.substring(0, pos);
String subtype = MIMEType.substring(pos + 1);
GtkIconTheme* iconTheme = gtk_icon_theme_get_default();
String iconName = media + "-" + subtype;
if(gtk_icon_theme_has_icon(iconTheme, iconName.utf8().data()))
return iconName;
iconName = "gnome-mime-" + media + "-" + subtype;
if(gtk_icon_theme_has_icon(iconTheme, iconName.utf8().data()))
return iconName;
iconName = media + "-x-generic";
if(gtk_icon_theme_has_icon(iconTheme, iconName.utf8().data()))
return iconName;
iconName = media + "gnome-mime-" + media;
if(gtk_icon_theme_has_icon(iconTheme, iconName.utf8().data()))
return iconName;
}
return GTK_STOCK_FILE;
}
void Icon::paint(GraphicsContext*, const IntRect&)
PassRefPtr<Icon> Icon::newIconForFile(const String& filename)
{
notImplemented();
if (!g_path_skip_root(filename.utf8().data()))
return 0;
String MIMEType = MIMETypeRegistry::getMIMETypeForPath(filename);
String iconName = lookupIconName(MIMEType);
Icon* icon = new Icon;
icon->m_icon = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), iconName.utf8().data(), 16, GTK_ICON_LOOKUP_USE_BUILTIN, NULL);
return icon->m_icon ? icon : 0;
}
void Icon::paint(GraphicsContext* context, const IntRect& rect)
{
// TODO: Scale/clip the image if necessary.
cairo_t* cr = context->platformContext();
cairo_save(cr);
gdk_cairo_set_source_pixbuf(cr, m_icon, rect.x(), rect.y());
cairo_paint(cr);
cairo_restore(cr);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment