Changeset 74997 in webkit


Ignore:
Timestamp:
Jan 4, 2011 1:09:23 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-01-04 Carlos Garcia Campos <cgarcia@igalia.com> and Martin Robinson <mrobinson@igalia.com>

Reviewed by Xan Lopez.

[GTK] Port stock icon painting to GtkStyleContext
https://bugs.webkit.org/show_bug.cgi?id=51764

Port stock icon painting for media and search input elements to
GtkStyleContext. Also create the initial machinery for accessing
style contexts for all GTK+ 3.x based widgets.

No new tests. This should not change functionality.

  • platform/gtk/RenderThemeGtk.cpp: (WebCore::paintGdkPixbuf): (WebCore::RenderThemeGtk::paintSearchFieldResultsDecoration): (WebCore::RenderThemeGtk::paintSearchFieldCancelButton): (WebCore::RenderThemeGtk::paintMediaButton):
  • platform/gtk/RenderThemeGtk.h:
  • platform/gtk/RenderThemeGtk2.cpp: (WebCore::RenderThemeGtk::getStockIcon):
  • platform/gtk/RenderThemeGtk3.cpp: (WebCore::gtkStyleChangedCallback): (WebCore::styleContextMap): (WebCore::getStyleContext): (WebCore::RenderThemeGtk::paintMenuList):
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r74995 r74997  
     12011-01-04  Carlos Garcia Campos  <cgarcia@igalia.com> and Martin Robinson  <mrobinson@igalia.com>
     2
     3        Reviewed by Xan Lopez.
     4
     5        [GTK] Port stock icon painting to GtkStyleContext
     6        https://bugs.webkit.org/show_bug.cgi?id=51764
     7
     8        Port stock icon painting for media and search input elements to
     9        GtkStyleContext. Also create the initial machinery for accessing
     10        style contexts for all GTK+ 3.x based widgets.
     11
     12        No new tests. This should not change functionality.
     13
     14        * platform/gtk/RenderThemeGtk.cpp:
     15        (WebCore::paintGdkPixbuf):
     16        (WebCore::RenderThemeGtk::paintSearchFieldResultsDecoration):
     17        (WebCore::RenderThemeGtk::paintSearchFieldCancelButton):
     18        (WebCore::RenderThemeGtk::paintMediaButton):
     19        * platform/gtk/RenderThemeGtk.h:
     20        * platform/gtk/RenderThemeGtk2.cpp:
     21        (WebCore::RenderThemeGtk::getStockIcon):
     22        * platform/gtk/RenderThemeGtk3.cpp:
     23        (WebCore::gtkStyleChangedCallback):
     24        (WebCore::styleContextMap):
     25        (WebCore::getStyleContext):
     26        (WebCore::RenderThemeGtk::paintMenuList):
     27
    1282010-12-31  Antti Koivisto  <antti@apple.com>
    229
  • trunk/WebCore/platform/gtk/RenderThemeGtk.cpp

    r74945 r74997  
    4545using namespace HTMLNames;
    4646
    47 static void paintStockIcon(GraphicsContext* context, const IntPoint& iconPoint, GtkStyle* style, const char* iconName,
    48                            GtkTextDirection direction, GtkStateType state, GtkIconSize iconSize)
    49 {
    50     GtkIconSet* iconSet = gtk_style_lookup_icon_set(style, iconName);
    51     PlatformRefPtr<GdkPixbuf> icon = adoptPlatformRef(gtk_icon_set_render_icon(iconSet, style, direction, state, iconSize, 0, 0));
    52 
    53     cairo_t* cr = context->platformContext();
    54     cairo_save(cr);
    55     gdk_cairo_set_source_pixbuf(cr, icon.get(), iconPoint.x(), iconPoint.y());
    56     cairo_paint(cr);
    57     cairo_restore(cr);
    58 }
    59 
    6047#if ENABLE(VIDEO)
    6148static HTMLMediaElement* getMediaElementFromRenderObject(RenderObject* o)
     
    294281}
    295282
     283static void paintGdkPixbuf(GraphicsContext* context, const GdkPixbuf* icon, const IntPoint& iconPoint)
     284{
     285    cairo_t* cr = context->platformContext();
     286    cairo_save(cr);
     287    gdk_cairo_set_source_pixbuf(cr, icon, iconPoint.x(), iconPoint.y());
     288    cairo_paint(cr);
     289    cairo_restore(cr);
     290}
     291
    296292void RenderThemeGtk::adjustSearchFieldResultsButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
    297293{
     
    331327bool RenderThemeGtk::paintSearchFieldResultsDecoration(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
    332328{
    333     GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(gtkEntry()));
    334     IntPoint iconPoint(centerRectVerticallyInParentInputElement(renderObject, rect));
    335     paintStockIcon(paintInfo.context, iconPoint, style, GTK_STOCK_FIND,
    336                    gtkTextDirection(renderObject->style()->direction()),
    337                    gtkIconState(renderObject), GTK_ICON_SIZE_MENU);
     329    PlatformRefPtr<GdkPixbuf> icon = getStockIcon(GTK_TYPE_ENTRY, GTK_STOCK_FIND,
     330                                                  gtkTextDirection(renderObject->style()->direction()),
     331                                                  gtkIconState(renderObject), GTK_ICON_SIZE_MENU);
     332    paintGdkPixbuf(paintInfo.context, icon.get(), centerRectVerticallyInParentInputElement(renderObject, rect));
    338333    return false;
    339334}
     
    352347bool RenderThemeGtk::paintSearchFieldCancelButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
    353348{
    354     GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(gtkEntry()));
    355     IntPoint iconPoint(centerRectVerticallyInParentInputElement(renderObject, rect));
    356     paintStockIcon(paintInfo.context, iconPoint, style, GTK_STOCK_CLEAR,
    357                    gtkTextDirection(renderObject->style()->direction()),
    358                    gtkIconState(renderObject), GTK_ICON_SIZE_MENU);
     349    PlatformRefPtr<GdkPixbuf> icon = getStockIcon(GTK_TYPE_ENTRY, GTK_STOCK_CLEAR,
     350                                                  gtkTextDirection(renderObject->style()->direction()),
     351                                                  gtkIconState(renderObject), GTK_ICON_SIZE_MENU);
     352    paintGdkPixbuf(paintInfo.context, icon.get(), centerRectVerticallyInParentInputElement(renderObject, rect));
    359353    return false;
    360354}
     
    454448bool RenderThemeGtk::paintMediaButton(RenderObject* renderObject, GraphicsContext* context, const IntRect& rect, const char* iconName)
    455449{
    456     GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(gtkContainer()));
     450    PlatformRefPtr<GdkPixbuf> icon = getStockIcon(GTK_TYPE_CONTAINER, iconName,
     451                                                  gtkTextDirection(renderObject->style()->direction()),
     452                                                  gtkIconState(renderObject),
     453                                                  getMediaButtonIconSize(m_mediaIconSize));
    457454    IntPoint iconPoint(rect.x() + (rect.width() - m_mediaIconSize) / 2,
    458455                       rect.y() + (rect.height() - m_mediaIconSize) / 2);
    459456    context->fillRect(FloatRect(rect), m_panelColor, ColorSpaceDeviceRGB);
    460     paintStockIcon(context, iconPoint, style, iconName,
    461                    gtkTextDirection(renderObject->style()->direction()), gtkIconState(renderObject), getMediaButtonIconSize(m_mediaIconSize));
    462 
     457    paintGdkPixbuf(context, icon.get(), iconPoint);
    463458    return false;
    464459}
  • trunk/WebCore/platform/gtk/RenderThemeGtk.h

    r74817 r74997  
    175175    GtkStateType gtkIconState(RenderObject*);
    176176    static void setTextInputBorders(RenderStyle*);
     177    PlatformRefPtr<GdkPixbuf> getStockIcon(GType, const char* iconName, gint direction, gint state, gint iconSize);
    177178
    178179    mutable GtkWidget* m_gtkWindow;
  • trunk/WebCore/platform/gtk/RenderThemeGtk2.cpp

    r74945 r74997  
    376376#endif
    377377
     378PlatformRefPtr<GdkPixbuf> RenderThemeGtk::getStockIcon(GType widgetType, const char* iconName, gint direction, gint state, gint iconSize)
     379{
     380    ASSERT(widgetType == GTK_TYPE_CONTAINER || widgetType == GTK_TYPE_ENTRY);
     381    GtkWidget* widget = widgetType == GTK_TYPE_CONTAINER ? GTK_WIDGET(gtkContainer()) : gtkEntry();
     382    GtkStyle* style = gtk_widget_get_style(widget);
     383    GtkIconSet* iconSet = gtk_style_lookup_icon_set(style, iconName);
     384    return adoptPlatformRef(gtk_icon_set_render_icon(iconSet, style,
     385                                                     static_cast<GtkTextDirection>(direction),
     386                                                     static_cast<GtkStateType>(state),
     387                                                     static_cast<GtkIconSize>(iconSize), 0, 0));
     388}
     389
     390
    378391Color RenderThemeGtk::platformActiveSelectionBackgroundColor() const
    379392{
  • trunk/WebCore/platform/gtk/RenderThemeGtk3.cpp

    r74945 r74997  
    3333#include "HTMLNames.h"
    3434#include "MediaControlElements.h"
     35#include "Page.h"
    3536#include "RenderObject.h"
    3637#include "TextDirection.h"
     
    4647
    4748namespace WebCore {
     49
     50typedef HashMap<GType, PlatformRefPtr<GtkStyleContext> > StyleContextMap;
     51static StyleContextMap& styleContextMap();
     52
     53static void gtkStyleChangedCallback(GObject*, GParamSpec*)
     54{
     55    StyleContextMap::const_iterator end = styleContextMap().end();
     56    for (StyleContextMap::const_iterator iter = styleContextMap().begin(); iter != end; ++iter)
     57        gtk_style_context_invalidate(iter->second.get());
     58
     59    Page::scheduleForcedStyleRecalcForAllPages();
     60}
     61
     62static StyleContextMap& styleContextMap()
     63{
     64    DEFINE_STATIC_LOCAL(StyleContextMap, map, ());
     65
     66    static bool initialized = false;
     67    if (!initialized) {
     68        GtkSettings* settings = gtk_settings_get_default();
     69        g_signal_connect(settings, "notify::gtk-theme-name", G_CALLBACK(gtkStyleChangedCallback), 0);
     70        g_signal_connect(settings, "notify::gtk-color-scheme", G_CALLBACK(gtkStyleChangedCallback), 0);
     71        initialized = true;
     72    }
     73    return map;
     74}
     75
     76static GtkStyleContext* getStyleContext(GType widgetType)
     77{
     78    std::pair<StyleContextMap::iterator, bool> result = styleContextMap().add(widgetType, 0);
     79    if (!result.second)
     80        return result.first->second.get();
     81
     82    GtkWidgetPath* path = gtk_widget_path_new();
     83    gtk_widget_path_append_type(path, widgetType);
     84
     85    PlatformRefPtr<GtkStyleContext> context = adoptPlatformRef(gtk_style_context_new());
     86    gtk_style_context_set_path(context.get(), path);
     87    gtk_widget_path_free(path);
     88
     89    result.first->second = context;
     90    return context.get();
     91}
    4892
    4993// This is not a static method, because we want to avoid having GTK+ headers in RenderThemeGtk.h.
     
    367411#endif
    368412
     413PlatformRefPtr<GdkPixbuf> RenderThemeGtk::getStockIcon(GType widgetType, const char* iconName, gint direction, gint state, gint iconSize)
     414{
     415    GtkStyleContext* context = getStyleContext(widgetType);
     416    GtkIconSet* iconSet = gtk_style_context_lookup_icon_set(context, iconName);
     417
     418    gtk_style_context_save(context);
     419
     420    guint flags = 0;
     421    if (state == GTK_STATE_PRELIGHT)
     422        flags |= GTK_STATE_FLAG_PRELIGHT;
     423    else if (state == GTK_STATE_INSENSITIVE)
     424        flags |= GTK_STATE_FLAG_INSENSITIVE;
     425
     426    gtk_style_context_set_state(context, static_cast<GtkStateFlags>(flags));
     427    gtk_style_context_set_direction(context, static_cast<GtkTextDirection>(direction));
     428    GdkPixbuf* icon = gtk_icon_set_render_icon_pixbuf(iconSet, context, static_cast<GtkIconSize>(iconSize));
     429
     430    gtk_style_context_restore(context);
     431
     432    return adoptPlatformRef(icon);
     433}
     434
    369435Color RenderThemeGtk::platformActiveSelectionBackgroundColor() const
    370436{
Note: See TracChangeset for help on using the changeset viewer.