[SCM] WebKit Debian packaging branch, debian/experimental, updated. debian/1.3.8-1-1049-g2e11a8e

commit-queue at webkit.org commit-queue at webkit.org
Fri Jan 21 14:55:17 UTC 2011


The following commit has been merged in the debian/experimental branch:
commit 04095dde0e03182dcd585e8c47d647a929249d1f
Author: commit-queue at webkit.org <commit-queue at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Jan 4 21:09:23 2011 +0000

    2011-01-04  Carlos Garcia Campos  <cgarcia at igalia.com> and Martin Robinson  <mrobinson at 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):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@74997 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 5bd7435..9f8d972 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,30 @@
+2011-01-04  Carlos Garcia Campos  <cgarcia at igalia.com> and Martin Robinson  <mrobinson at 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):
+
 2010-12-31  Antti Koivisto  <antti at apple.com>
 
         Reviewed by Dave Hyatt.
diff --git a/WebCore/platform/gtk/RenderThemeGtk.cpp b/WebCore/platform/gtk/RenderThemeGtk.cpp
index 3f7d752..8fca711 100644
--- a/WebCore/platform/gtk/RenderThemeGtk.cpp
+++ b/WebCore/platform/gtk/RenderThemeGtk.cpp
@@ -44,19 +44,6 @@ namespace WebCore {
 
 using namespace HTMLNames;
 
-static void paintStockIcon(GraphicsContext* context, const IntPoint& iconPoint, GtkStyle* style, const char* iconName,
-                           GtkTextDirection direction, GtkStateType state, GtkIconSize iconSize)
-{
-    GtkIconSet* iconSet = gtk_style_lookup_icon_set(style, iconName);
-    PlatformRefPtr<GdkPixbuf> icon = adoptPlatformRef(gtk_icon_set_render_icon(iconSet, style, direction, state, iconSize, 0, 0));
-
-    cairo_t* cr = context->platformContext();
-    cairo_save(cr);
-    gdk_cairo_set_source_pixbuf(cr, icon.get(), iconPoint.x(), iconPoint.y());
-    cairo_paint(cr);
-    cairo_restore(cr);
-}
-
 #if ENABLE(VIDEO)
 static HTMLMediaElement* getMediaElementFromRenderObject(RenderObject* o)
 {
@@ -293,6 +280,15 @@ bool RenderThemeGtk::paintTextArea(RenderObject* o, const PaintInfo& i, const In
     return paintTextField(o, i, r);
 }
 
+static void paintGdkPixbuf(GraphicsContext* context, const GdkPixbuf* icon, const IntPoint& iconPoint)
+{
+    cairo_t* cr = context->platformContext();
+    cairo_save(cr);
+    gdk_cairo_set_source_pixbuf(cr, icon, iconPoint.x(), iconPoint.y());
+    cairo_paint(cr);
+    cairo_restore(cr);
+}
+
 void RenderThemeGtk::adjustSearchFieldResultsButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
 {
     adjustSearchFieldCancelButtonStyle(selector, style, e);
@@ -330,11 +326,10 @@ static IntPoint centerRectVerticallyInParentInputElement(RenderObject* object, c
 
 bool RenderThemeGtk::paintSearchFieldResultsDecoration(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
 {
-    GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(gtkEntry()));
-    IntPoint iconPoint(centerRectVerticallyInParentInputElement(renderObject, rect));
-    paintStockIcon(paintInfo.context, iconPoint, style, GTK_STOCK_FIND,
-                   gtkTextDirection(renderObject->style()->direction()),
-                   gtkIconState(renderObject), GTK_ICON_SIZE_MENU);
+    PlatformRefPtr<GdkPixbuf> icon = getStockIcon(GTK_TYPE_ENTRY, GTK_STOCK_FIND,
+                                                  gtkTextDirection(renderObject->style()->direction()),
+                                                  gtkIconState(renderObject), GTK_ICON_SIZE_MENU);
+    paintGdkPixbuf(paintInfo.context, icon.get(), centerRectVerticallyInParentInputElement(renderObject, rect));
     return false;
 }
 
@@ -351,11 +346,10 @@ void RenderThemeGtk::adjustSearchFieldCancelButtonStyle(CSSStyleSelector* select
 
 bool RenderThemeGtk::paintSearchFieldCancelButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect)
 {
-    GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(gtkEntry()));
-    IntPoint iconPoint(centerRectVerticallyInParentInputElement(renderObject, rect));
-    paintStockIcon(paintInfo.context, iconPoint, style, GTK_STOCK_CLEAR,
-                   gtkTextDirection(renderObject->style()->direction()),
-                   gtkIconState(renderObject), GTK_ICON_SIZE_MENU);
+    PlatformRefPtr<GdkPixbuf> icon = getStockIcon(GTK_TYPE_ENTRY, GTK_STOCK_CLEAR,
+                                                  gtkTextDirection(renderObject->style()->direction()),
+                                                  gtkIconState(renderObject), GTK_ICON_SIZE_MENU);
+    paintGdkPixbuf(paintInfo.context, icon.get(), centerRectVerticallyInParentInputElement(renderObject, rect));
     return false;
 }
 
@@ -453,13 +447,14 @@ String RenderThemeGtk::extraMediaControlsStyleSheet()
 
 bool RenderThemeGtk::paintMediaButton(RenderObject* renderObject, GraphicsContext* context, const IntRect& rect, const char* iconName)
 {
-    GtkStyle* style = gtk_widget_get_style(GTK_WIDGET(gtkContainer()));
+    PlatformRefPtr<GdkPixbuf> icon = getStockIcon(GTK_TYPE_CONTAINER, iconName,
+                                                  gtkTextDirection(renderObject->style()->direction()),
+                                                  gtkIconState(renderObject),
+                                                  getMediaButtonIconSize(m_mediaIconSize));
     IntPoint iconPoint(rect.x() + (rect.width() - m_mediaIconSize) / 2,
                        rect.y() + (rect.height() - m_mediaIconSize) / 2);
     context->fillRect(FloatRect(rect), m_panelColor, ColorSpaceDeviceRGB);
-    paintStockIcon(context, iconPoint, style, iconName, 
-                   gtkTextDirection(renderObject->style()->direction()), gtkIconState(renderObject), getMediaButtonIconSize(m_mediaIconSize));
-
+    paintGdkPixbuf(context, icon.get(), iconPoint);
     return false;
 }
 
diff --git a/WebCore/platform/gtk/RenderThemeGtk.h b/WebCore/platform/gtk/RenderThemeGtk.h
index 67a9d30..29bf66a 100644
--- a/WebCore/platform/gtk/RenderThemeGtk.h
+++ b/WebCore/platform/gtk/RenderThemeGtk.h
@@ -174,6 +174,7 @@ private:
 #endif
     GtkStateType gtkIconState(RenderObject*);
     static void setTextInputBorders(RenderStyle*);
+    PlatformRefPtr<GdkPixbuf> getStockIcon(GType, const char* iconName, gint direction, gint state, gint iconSize);
 
     mutable GtkWidget* m_gtkWindow;
     mutable GtkWidget* m_gtkContainer;
diff --git a/WebCore/platform/gtk/RenderThemeGtk2.cpp b/WebCore/platform/gtk/RenderThemeGtk2.cpp
index 572cc25..e37f924 100644
--- a/WebCore/platform/gtk/RenderThemeGtk2.cpp
+++ b/WebCore/platform/gtk/RenderThemeGtk2.cpp
@@ -375,6 +375,19 @@ bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInf
 }
 #endif
 
+PlatformRefPtr<GdkPixbuf> RenderThemeGtk::getStockIcon(GType widgetType, const char* iconName, gint direction, gint state, gint iconSize)
+{
+    ASSERT(widgetType == GTK_TYPE_CONTAINER || widgetType == GTK_TYPE_ENTRY);
+    GtkWidget* widget = widgetType == GTK_TYPE_CONTAINER ? GTK_WIDGET(gtkContainer()) : gtkEntry();
+    GtkStyle* style = gtk_widget_get_style(widget);
+    GtkIconSet* iconSet = gtk_style_lookup_icon_set(style, iconName);
+    return adoptPlatformRef(gtk_icon_set_render_icon(iconSet, style,
+                                                     static_cast<GtkTextDirection>(direction),
+                                                     static_cast<GtkStateType>(state),
+                                                     static_cast<GtkIconSize>(iconSize), 0, 0));
+}
+
+
 Color RenderThemeGtk::platformActiveSelectionBackgroundColor() const
 {
     GtkWidget* widget = gtkEntry();
diff --git a/WebCore/platform/gtk/RenderThemeGtk3.cpp b/WebCore/platform/gtk/RenderThemeGtk3.cpp
index eae94ce..ee33c3b 100644
--- a/WebCore/platform/gtk/RenderThemeGtk3.cpp
+++ b/WebCore/platform/gtk/RenderThemeGtk3.cpp
@@ -32,6 +32,7 @@
 #include "GtkVersioning.h"
 #include "HTMLNames.h"
 #include "MediaControlElements.h"
+#include "Page.h"
 #include "RenderObject.h"
 #include "TextDirection.h"
 #include "UserAgentStyleSheets.h"
@@ -46,6 +47,49 @@
 
 namespace WebCore {
 
+typedef HashMap<GType, PlatformRefPtr<GtkStyleContext> > StyleContextMap;
+static StyleContextMap& styleContextMap();
+
+static void gtkStyleChangedCallback(GObject*, GParamSpec*)
+{
+    StyleContextMap::const_iterator end = styleContextMap().end();
+    for (StyleContextMap::const_iterator iter = styleContextMap().begin(); iter != end; ++iter)
+        gtk_style_context_invalidate(iter->second.get());
+
+    Page::scheduleForcedStyleRecalcForAllPages();
+}
+
+static StyleContextMap& styleContextMap()
+{
+    DEFINE_STATIC_LOCAL(StyleContextMap, map, ());
+
+    static bool initialized = false;
+    if (!initialized) {
+        GtkSettings* settings = gtk_settings_get_default();
+        g_signal_connect(settings, "notify::gtk-theme-name", G_CALLBACK(gtkStyleChangedCallback), 0);
+        g_signal_connect(settings, "notify::gtk-color-scheme", G_CALLBACK(gtkStyleChangedCallback), 0);
+        initialized = true;
+    }
+    return map;
+}
+
+static GtkStyleContext* getStyleContext(GType widgetType)
+{
+    std::pair<StyleContextMap::iterator, bool> result = styleContextMap().add(widgetType, 0);
+    if (!result.second)
+        return result.first->second.get();
+
+    GtkWidgetPath* path = gtk_widget_path_new();
+    gtk_widget_path_append_type(path, widgetType);
+
+    PlatformRefPtr<GtkStyleContext> context = adoptPlatformRef(gtk_style_context_new());
+    gtk_style_context_set_path(context.get(), path);
+    gtk_widget_path_free(path);
+
+    result.first->second = context;
+    return context.get();
+}
+
 // This is not a static method, because we want to avoid having GTK+ headers in RenderThemeGtk.h.
 extern GtkTextDirection gtkTextDirection(TextDirection);
 
@@ -366,6 +410,28 @@ bool RenderThemeGtk::paintProgressBar(RenderObject* renderObject, const PaintInf
 }
 #endif
 
+PlatformRefPtr<GdkPixbuf> RenderThemeGtk::getStockIcon(GType widgetType, const char* iconName, gint direction, gint state, gint iconSize)
+{
+    GtkStyleContext* context = getStyleContext(widgetType);
+    GtkIconSet* iconSet = gtk_style_context_lookup_icon_set(context, iconName);
+
+    gtk_style_context_save(context);
+
+    guint flags = 0;
+    if (state == GTK_STATE_PRELIGHT)
+        flags |= GTK_STATE_FLAG_PRELIGHT;
+    else if (state == GTK_STATE_INSENSITIVE)
+        flags |= GTK_STATE_FLAG_INSENSITIVE;
+
+    gtk_style_context_set_state(context, static_cast<GtkStateFlags>(flags));
+    gtk_style_context_set_direction(context, static_cast<GtkTextDirection>(direction));
+    GdkPixbuf* icon = gtk_icon_set_render_icon_pixbuf(iconSet, context, static_cast<GtkIconSize>(iconSize));
+
+    gtk_style_context_restore(context);
+
+    return adoptPlatformRef(icon);
+}
+
 Color RenderThemeGtk::platformActiveSelectionBackgroundColor() const
 {
     GtkWidget* widget = gtkEntry();

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list