Changeset 74997 in webkit
- Timestamp:
- Jan 4, 2011 1:09:23 PM (13 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r74995 r74997 1 2011-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 1 28 2010-12-31 Antti Koivisto <antti@apple.com> 2 29 -
trunk/WebCore/platform/gtk/RenderThemeGtk.cpp
r74945 r74997 45 45 using namespace HTMLNames; 46 46 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 60 47 #if ENABLE(VIDEO) 61 48 static HTMLMediaElement* getMediaElementFromRenderObject(RenderObject* o) … … 294 281 } 295 282 283 static 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 296 292 void RenderThemeGtk::adjustSearchFieldResultsButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const 297 293 { … … 331 327 bool RenderThemeGtk::paintSearchFieldResultsDecoration(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 332 328 { 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)); 338 333 return false; 339 334 } … … 352 347 bool RenderThemeGtk::paintSearchFieldCancelButton(RenderObject* renderObject, const PaintInfo& paintInfo, const IntRect& rect) 353 348 { 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)); 359 353 return false; 360 354 } … … 454 448 bool RenderThemeGtk::paintMediaButton(RenderObject* renderObject, GraphicsContext* context, const IntRect& rect, const char* iconName) 455 449 { 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)); 457 454 IntPoint iconPoint(rect.x() + (rect.width() - m_mediaIconSize) / 2, 458 455 rect.y() + (rect.height() - m_mediaIconSize) / 2); 459 456 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); 463 458 return false; 464 459 } -
trunk/WebCore/platform/gtk/RenderThemeGtk.h
r74817 r74997 175 175 GtkStateType gtkIconState(RenderObject*); 176 176 static void setTextInputBorders(RenderStyle*); 177 PlatformRefPtr<GdkPixbuf> getStockIcon(GType, const char* iconName, gint direction, gint state, gint iconSize); 177 178 178 179 mutable GtkWidget* m_gtkWindow; -
trunk/WebCore/platform/gtk/RenderThemeGtk2.cpp
r74945 r74997 376 376 #endif 377 377 378 PlatformRefPtr<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 378 391 Color RenderThemeGtk::platformActiveSelectionBackgroundColor() const 379 392 { -
trunk/WebCore/platform/gtk/RenderThemeGtk3.cpp
r74945 r74997 33 33 #include "HTMLNames.h" 34 34 #include "MediaControlElements.h" 35 #include "Page.h" 35 36 #include "RenderObject.h" 36 37 #include "TextDirection.h" … … 46 47 47 48 namespace WebCore { 49 50 typedef HashMap<GType, PlatformRefPtr<GtkStyleContext> > StyleContextMap; 51 static StyleContextMap& styleContextMap(); 52 53 static 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 62 static 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 76 static 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 } 48 92 49 93 // This is not a static method, because we want to avoid having GTK+ headers in RenderThemeGtk.h. … … 367 411 #endif 368 412 413 PlatformRefPtr<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 369 435 Color RenderThemeGtk::platformActiveSelectionBackgroundColor() const 370 436 {
Note: See TracChangeset
for help on using the changeset viewer.