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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@74997 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1230fa59
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):
2010-12-31 Antti Koivisto <antti@apple.com>
Reviewed by Dave Hyatt.
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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();
......
......@@ -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();
......
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