Changeset 28809 in webkit


Ignore:
Timestamp:
Dec 17, 2007 8:18:44 AM (16 years ago)
Author:
alp@webkit.org
Message:

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):
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r28798 r28809  
     12007-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
    1212007-12-16  Sam Weinig  <sam@webkit.org>
    222
  • trunk/WebCore/platform/graphics/Icon.h

    r27776 r28809  
    3636#elif PLATFORM(QT)
    3737#include <QIcon>
     38#elif PLATFORM(GTK)
     39#include <gdk/gdk.h>
    3840#endif
    3941
     
    6769#elif PLATFORM(QT)
    6870    QIcon m_icon;
     71#elif PLATFORM(GTK)
     72    GdkPixbuf* m_icon;
    6973#endif
    7074};
  • trunk/WebCore/platform/graphics/gtk/IconGtk.cpp

    r25703 r28809  
    3131#include "Icon.h"
    3232
     33#include "CString.h"
     34#include "GraphicsContext.h"
     35#include "MIMETypeRegistry.h"
    3336#include "NotImplemented.h"
    3437#include "PassRefPtr.h"
     38
     39#include <gtk/gtk.h>
    3540
    3641namespace WebCore {
    3742
    3843Icon::Icon()
     44    : m_icon(0)
    3945{
    4046    notImplemented();
     
    4349Icon::~Icon()
    4450{
    45     notImplemented();
     51    if(m_icon)
     52        g_object_unref(m_icon);
    4653}
    4754
    48 PassRefPtr<Icon> Icon::newIconForFile(const String&)
     55static String lookupIconName(String MIMEType)
    4956{
    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;
    5290}
    5391
    54 void Icon::paint(GraphicsContext*, const IntRect&)
     92PassRefPtr<Icon> Icon::newIconForFile(const String& filename)
    5593{
    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
     105void 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);
    57113}
    58114
Note: See TracChangeset for help on using the changeset viewer.