Changeset 194377 in webkit


Ignore:
Timestamp:
Dec 22, 2015 3:15:25 PM (8 years ago)
Author:
Michael Catanzaro
Message:

[GTK] Everything broken in GTK+ 3.19
https://bugs.webkit.org/show_bug.cgi?id=150550

Reviewed by Carlos Garcia Campos.

Port RenderThemeGtk and ScrollbarThemeGtk to use CSS nodes. This makes it possible to render
stuff with modern GTK+.

No new tests. We already have tons of tests for this functionality, but we're running them
with GTK+ 3.16, so they cannot have detected this breakage. These fixes require unreleased
GTK+, and GTK+ rendering is currently in a state of flux; once things settle down, we can
consider upgrading the GTK+ used for our layout tests.

  • platform/gtk/GRefPtrGtk.cpp:

(WTF::refGPtr):
(WTF::derefGPtr):

  • platform/gtk/GRefPtrGtk.h:
  • platform/gtk/ScrollbarThemeGtk.cpp:

(WebCore::ScrollbarThemeGtk::themeChanged):
(WebCore::ScrollbarThemeGtk::updateThemeProperties):
(WebCore::orientationStyleClass):
(WebCore::applyScrollbarStyleContextClasses):
(WebCore::ScrollbarThemeGtk::paintTrackBackground):
(WebCore::ScrollbarThemeGtk::paintScrollbarBackground):
(WebCore::ScrollbarThemeGtk::paintThumb):
(WebCore::ScrollbarThemeGtk::paintButton):

  • rendering/RenderThemeGtk.cpp:

(WebCore::createStyleContext):
(WebCore::setToggleSize):
(WebCore::paintToggle):
(WebCore::RenderThemeGtk::paintButton):
(WebCore::getComboBoxMetrics):
(WebCore::RenderThemeGtk::paintMenuList):
(WebCore::RenderThemeGtk::paintTextField):
(WebCore::applySliderStyleContextClasses):
(WebCore::RenderThemeGtk::paintSliderTrack):
(WebCore::RenderThemeGtk::paintSliderThumb):
(WebCore::RenderThemeGtk::paintProgressBar):
(WebCore::paintSpinArrowButton):
(WebCore::styleColor):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r194371 r194377  
     12015-12-22  Michael Catanzaro  <mcatanzaro@igalia.com>
     2
     3        [GTK] Everything broken in GTK+ 3.19
     4        https://bugs.webkit.org/show_bug.cgi?id=150550
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Port RenderThemeGtk and ScrollbarThemeGtk to use CSS nodes. This makes it possible to render
     9        stuff with modern GTK+.
     10
     11        No new tests. We already have tons of tests for this functionality, but we're running them
     12        with GTK+ 3.16, so they cannot have detected this breakage. These fixes require unreleased
     13        GTK+, and GTK+ rendering is currently in a state of flux; once things settle down, we can
     14        consider upgrading the GTK+ used for our layout tests.
     15
     16        * platform/gtk/GRefPtrGtk.cpp:
     17        (WTF::refGPtr):
     18        (WTF::derefGPtr):
     19        * platform/gtk/GRefPtrGtk.h:
     20        * platform/gtk/ScrollbarThemeGtk.cpp:
     21        (WebCore::ScrollbarThemeGtk::themeChanged):
     22        (WebCore::ScrollbarThemeGtk::updateThemeProperties):
     23        (WebCore::orientationStyleClass):
     24        (WebCore::applyScrollbarStyleContextClasses):
     25        (WebCore::ScrollbarThemeGtk::paintTrackBackground):
     26        (WebCore::ScrollbarThemeGtk::paintScrollbarBackground):
     27        (WebCore::ScrollbarThemeGtk::paintThumb):
     28        (WebCore::ScrollbarThemeGtk::paintButton):
     29        * rendering/RenderThemeGtk.cpp:
     30        (WebCore::createStyleContext):
     31        (WebCore::setToggleSize):
     32        (WebCore::paintToggle):
     33        (WebCore::RenderThemeGtk::paintButton):
     34        (WebCore::getComboBoxMetrics):
     35        (WebCore::RenderThemeGtk::paintMenuList):
     36        (WebCore::RenderThemeGtk::paintTextField):
     37        (WebCore::applySliderStyleContextClasses):
     38        (WebCore::RenderThemeGtk::paintSliderTrack):
     39        (WebCore::RenderThemeGtk::paintSliderThumb):
     40        (WebCore::RenderThemeGtk::paintProgressBar):
     41        (WebCore::paintSpinArrowButton):
     42        (WebCore::styleColor):
     43
    1442015-12-22  Eric Carlson  <eric.carlson@apple.com>
    245
  • trunk/Source/WebCore/platform/gtk/GRefPtrGtk.cpp

    r194370 r194377  
    7373        gdk_cursor_unref(ptr);
    7474}
     75
     76#else
     77
     78template <> GtkWidgetPath* refGPtr(GtkWidgetPath* ptr)
     79{
     80    if (ptr)
     81        gtk_widget_path_ref(ptr);
     82    return ptr;
     83}
     84
     85template <> void derefGPtr(GtkWidgetPath* ptr)
     86{
     87    if (ptr)
     88        gtk_widget_path_unref(ptr);
     89}
     90
    7591#endif
    7692
  • trunk/Source/WebCore/platform/gtk/GRefPtrGtk.h

    r194370 r194377  
    2424#include <wtf/glib/GRefPtr.h>
    2525
     26typedef struct _GtkWidgetPath GtkWidgetPath;
    2627typedef struct _SecretValue SecretValue;
    2728
     
    3940template <> GdkCursor* refGPtr(GdkCursor* ptr);
    4041template <> void derefGPtr(GdkCursor* ptr);
     42#else
     43template <> GtkWidgetPath* refGPtr(GtkWidgetPath* ptr);
     44template <> void derefGPtr(GtkWidgetPath* ptr);
    4145#endif
    4246
  • trunk/Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp

    r194370 r194377  
    2727#include "ScrollbarThemeGtk.h"
    2828
     29#include "GRefPtrGtk.h"
    2930#include "PlatformContextCairo.h"
    3031#include "PlatformMouseEvent.h"
     
    164165
    165166#ifndef GTK_API_VERSION_2
     167
     168#if !GTK_CHECK_VERSION(3, 19, 2)
     169// Currently we use a static GtkStyleContext for GTK+ < 3.19, and a bunch of unique
     170// GtkStyleContexts for GTK+ >= 3.19. This is crazy and definitely should not be necessary, but I
     171// couldn't find any other way to not break one version or the other. Ideally one of the two
     172// people on the planet who really understand GTK+ styles would fix this.
    166173class ScrollbarStyleContext {
    167174    WTF_MAKE_NONCOPYABLE(ScrollbarStyleContext); WTF_MAKE_FAST_ALLOCATED;
     
    192199    return styleContext.get().context();
    193200}
     201#endif
    194202
    195203ScrollbarThemeGtk::ScrollbarThemeGtk()
     
    200208void ScrollbarThemeGtk::themeChanged()
    201209{
     210#if !GTK_CHECK_VERSION(3, 19, 2)
    202211    gtk_style_context_invalidate(gtkScrollbarStyleContext());
     212#endif
    203213    updateThemeProperties();
    204214}
     
    206216void ScrollbarThemeGtk::updateThemeProperties()
    207217{
     218#if GTK_CHECK_VERSION(3, 19, 2)
     219    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
     220    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     221
     222    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     223    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
     224
     225    gtk_style_context_set_path(styleContext.get(), path.get());
     226#else
     227    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
     228#endif
     229
    208230    gtk_style_context_get_style(
    209         gtkScrollbarStyleContext(),
     231        styleContext.get(),
    210232        "min-slider-length", &m_minThumbLength,
    211233        "slider-width", &m_thumbFatness,
     
    273295}
    274296
     297
     298static const char* orientationStyleClass(ScrollbarOrientation orientation)
     299{
     300    return orientation == VerticalScrollbar ? "vertical" : "horizontal";
     301}
     302
     303#if !GTK_CHECK_VERSION(3, 19, 2)
    275304static void applyScrollbarStyleContextClasses(GtkStyleContext* context, ScrollbarOrientation orientation)
    276305{
    277306    gtk_style_context_add_class(context, GTK_STYLE_CLASS_SCROLLBAR);
    278     gtk_style_context_add_class(context, orientation == VerticalScrollbar ?  GTK_STYLE_CLASS_VERTICAL : GTK_STYLE_CLASS_HORIZONTAL);
    279 }
     307    gtk_style_context_add_class(context, orientationStyleClass(orientation));
     308}
     309#endif
    280310
    281311static void adjustRectAccordingToMargin(GtkStyleContext* context, GtkStateFlags state, IntRect& rect)
     
    297327        fullScrollbarRect = IntRect(scrollbar.x(), scrollbar.y(), scrollbar.width(), scrollbar.height());
    298328
    299     GtkStyleContext* styleContext = gtkScrollbarStyleContext();
    300     gtk_style_context_save(styleContext);
    301 
    302     applyScrollbarStyleContextClasses(styleContext, scrollbar.orientation());
    303     gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_TROUGH);
    304 
    305     adjustRectAccordingToMargin(styleContext, static_cast<GtkStateFlags>(0), fullScrollbarRect);
    306     gtk_render_background(styleContext, context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
    307     gtk_render_frame(styleContext, context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
    308 
    309     gtk_style_context_restore(styleContext);
     329#if GTK_CHECK_VERSION(3, 19, 2)
     330    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
     331    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     332
     333    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     334    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
     335    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
     336
     337    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     338    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     339
     340    gtk_style_context_set_path(styleContext.get(), path.get());
     341#else
     342    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
     343    gtk_style_context_save(styleContext.get());
     344
     345    applyScrollbarStyleContextClasses(styleContext.get(), scrollbar.orientation());
     346    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_TROUGH);
     347#endif
     348
     349    adjustRectAccordingToMargin(styleContext.get(), static_cast<GtkStateFlags>(0), fullScrollbarRect);
     350    gtk_render_background(styleContext.get(), context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
     351    gtk_render_frame(styleContext.get(), context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
     352
     353#if !GTK_CHECK_VERSION(3, 19, 2)
     354    gtk_style_context_restore(styleContext.get());
     355#endif
    310356}
    311357
    312358void ScrollbarThemeGtk::paintScrollbarBackground(GraphicsContext& context, Scrollbar& scrollbar)
    313359{
    314     GtkStyleContext* styleContext = gtkScrollbarStyleContext();
    315     gtk_style_context_save(styleContext);
    316 
    317     applyScrollbarStyleContextClasses(styleContext, scrollbar.orientation());
    318     gtk_style_context_add_class(styleContext, "scrolled-window");
    319     gtk_render_frame(styleContext, context.platformContext()->cr(), scrollbar.x(), scrollbar.y(), scrollbar.width(), scrollbar.height());
    320 
    321     gtk_style_context_restore(styleContext);
     360#if GTK_CHECK_VERSION(3, 19, 2)
     361    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
     362    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     363
     364    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     365    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
     366    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
     367
     368    gtk_style_context_set_path(styleContext.get(), path.get());
     369#else
     370    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
     371    gtk_style_context_save(styleContext.get());
     372
     373    applyScrollbarStyleContextClasses(styleContext.get(), scrollbar.orientation());
     374    gtk_style_context_add_class(styleContext.get(), "scrolled-window");
     375#endif
     376
     377    gtk_render_frame(styleContext.get(), context.platformContext()->cr(), scrollbar.x(), scrollbar.y(), scrollbar.width(), scrollbar.height());
     378
     379#if !GTK_CHECK_VERSION(3, 19, 2)
     380    gtk_style_context_restore(styleContext.get());
     381#endif
    322382}
    323383
    324384void ScrollbarThemeGtk::paintThumb(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& rect)
    325385{
    326     GtkStyleContext* styleContext = gtkScrollbarStyleContext();
    327     gtk_style_context_save(styleContext);
     386#if GTK_CHECK_VERSION(3, 19, 2)
     387    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
     388    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     389
     390    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     391    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
     392    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
     393
     394    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     395    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     396
     397    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     398    gtk_widget_path_iter_set_object_name(path.get(), 2, "slider");
     399
     400    gtk_style_context_set_path(styleContext.get(), path.get());
     401#else
     402    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
     403    gtk_style_context_save(styleContext.get());
     404#endif
    328405
    329406    ScrollbarOrientation orientation = scrollbar.orientation();
    330     applyScrollbarStyleContextClasses(styleContext, orientation);
    331     gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_SLIDER);
     407#if !GTK_CHECK_VERSION(3, 19, 2)
     408    applyScrollbarStyleContextClasses(styleContext.get(), orientation);
     409    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_SLIDER);
     410#endif
    332411
    333412    guint flags = 0;
     
    336415    if (scrollbar.hoveredPart() == ThumbPart)
    337416        flags |= GTK_STATE_FLAG_PRELIGHT;
    338     gtk_style_context_set_state(styleContext, static_cast<GtkStateFlags>(flags));
     417    gtk_style_context_set_state(styleContext.get(), static_cast<GtkStateFlags>(flags));
    339418
    340419    IntRect thumbRect(rect);
    341     adjustRectAccordingToMargin(styleContext, static_cast<GtkStateFlags>(flags), thumbRect);
    342     gtk_render_slider(styleContext, context.platformContext()->cr(), thumbRect.x(), thumbRect.y(), thumbRect.width(), thumbRect.height(),
     420    adjustRectAccordingToMargin(styleContext.get(), static_cast<GtkStateFlags>(flags), thumbRect);
     421    gtk_render_slider(styleContext.get(), context.platformContext()->cr(), thumbRect.x(), thumbRect.y(), thumbRect.width(), thumbRect.height(),
    343422        orientation == VerticalScrollbar ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
    344423
    345     gtk_style_context_restore(styleContext);
     424#if !GTK_CHECK_VERSION(3, 19, 2)
     425    gtk_style_context_restore(styleContext.get());
     426#endif
    346427}
    347428
    348429void ScrollbarThemeGtk::paintButton(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& rect, ScrollbarPart part)
    349430{
    350     GtkStyleContext* styleContext = gtkScrollbarStyleContext();
    351     gtk_style_context_save(styleContext);
     431#if GTK_CHECK_VERSION(3, 19, 2)
     432    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
     433    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     434
     435    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     436    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
     437    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
     438
     439    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     440    gtk_widget_path_iter_set_object_name(path.get(), 1, "button");
     441
     442    gtk_style_context_set_path(styleContext.get(), path.get());
     443#else
     444    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
     445    gtk_style_context_save(styleContext.get());
     446#endif
    352447
    353448    ScrollbarOrientation orientation = scrollbar.orientation();
    354     applyScrollbarStyleContextClasses(styleContext, orientation);
     449#if !GTK_CHECK_VERSION(3, 19, 2)
     450    applyScrollbarStyleContextClasses(styleContext.get(), orientation);
     451#endif
    355452
    356453    guint flags = 0;
     
    365462    } else
    366463        flags |= GTK_STATE_FLAG_INSENSITIVE;
    367     gtk_style_context_set_state(styleContext, static_cast<GtkStateFlags>(flags));
    368 
    369     gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_BUTTON);
    370     gtk_render_background(styleContext, context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
    371     gtk_render_frame(styleContext, context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
     464    gtk_style_context_set_state(styleContext.get(), static_cast<GtkStateFlags>(flags));
     465
     466#if !GTK_CHECK_VERSION(3, 19, 2)
     467    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_BUTTON);
     468#endif
     469
     470    gtk_render_background(styleContext.get(), context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
     471    gtk_render_frame(styleContext.get(), context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
    372472
    373473    gfloat arrowScaling;
    374     gtk_style_context_get_style(styleContext, "arrow-scaling", &arrowScaling, nullptr);
     474    gtk_style_context_get_style(styleContext.get(), "arrow-scaling", &arrowScaling, nullptr);
    375475
    376476    double arrowSize = std::min(rect.width(), rect.height()) * arrowScaling;
     
    381481    if (flags & GTK_STATE_FLAG_ACTIVE) {
    382482        gint arrowDisplacementX, arrowDisplacementY;
    383         gtk_style_context_get_style(styleContext, "arrow-displacement-x", &arrowDisplacementX, "arrow-displacement-y", &arrowDisplacementY, nullptr);
     483        gtk_style_context_get_style(styleContext.get(), "arrow-displacement-x", &arrowDisplacementX, "arrow-displacement-y", &arrowDisplacementY, nullptr);
    384484        arrowPoint.move(arrowDisplacementX, arrowDisplacementY);
    385485    }
     
    391491        angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI / 2 : 3 * (G_PI / 2);
    392492
    393     gtk_render_arrow(styleContext, context.platformContext()->cr(), angle, arrowPoint.x(), arrowPoint.y(), arrowSize);
    394 
    395     gtk_style_context_restore(styleContext);
     493    gtk_render_arrow(styleContext.get(), context.platformContext()->cr(), angle, arrowPoint.x(), arrowPoint.y(), arrowSize);
     494
     495#if !GTK_CHECK_VERSION(3, 19, 2)
     496    gtk_style_context_restore(styleContext.get());
     497#endif
    396498}
    397499
  • trunk/Source/WebCore/rendering/RenderThemeGtk.cpp

    r194370 r194377  
    3131#include "FileSystem.h"
    3232#include "FontDescription.h"
     33#include "GRefPtrGtk.h"
    3334#include "GUniquePtrGtk.h"
    3435#include "Gradient.h"
     
    153154    }
    154155
    155     GtkWidgetPath* path = gtk_widget_path_new();
    156     gtk_widget_path_append_type(path, widgetType);
    157 
     156    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     157    gtk_widget_path_append_type(path.get(), widgetType);
     158
     159#if GTK_CHECK_VERSION(3, 19, 2)
     160    // Pick a good default object path for the style context based on the widget type. This will
     161    // usually need to be overridden manually, but it doesn't hurt to have a good default.
    158162    if (widgetType == GTK_TYPE_ENTRY)
    159         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_ENTRY);
     163        gtk_widget_path_iter_set_object_name(path.get(), 0, "entry");
    160164    else if (widgetType == GTK_TYPE_ARROW)
    161         gtk_widget_path_iter_add_class(path, 0, "arrow");
     165        gtk_widget_path_iter_set_object_name(path.get(), 0, "button"); // Note: not a typo.
    162166    else if (widgetType == GTK_TYPE_BUTTON) {
    163         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_BUTTON);
    164         gtk_widget_path_iter_add_class(path, 0, "text-button");
     167        gtk_widget_path_iter_set_object_name(path.get(), 0, "button");
     168        gtk_widget_path_iter_add_class(path.get(), 0, "text-button");
    165169    } else if (widgetType == GTK_TYPE_SCALE)
    166         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SCALE);
     170        gtk_widget_path_iter_set_object_name(path.get(), 0, "scale");
    167171    else if (widgetType == GTK_TYPE_SEPARATOR)
    168         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SEPARATOR);
     172        gtk_widget_path_iter_set_object_name(path.get(), 0, "separator");
    169173    else if (widgetType == GTK_TYPE_PROGRESS_BAR)
    170         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_PROGRESSBAR);
     174        gtk_widget_path_iter_set_object_name(path.get(), 0, "progressbar");
    171175    else if (widgetType == GTK_TYPE_SPIN_BUTTON)
    172         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SPINBUTTON);
     176        gtk_widget_path_iter_set_object_name(path.get(), 0, "spinbutton");
     177    else if (widgetType == GTK_TYPE_TREE_VIEW) {
     178        gtk_widget_path_iter_set_object_name(path.get(), 0, "treeview");
     179        gtk_widget_path_iter_add_class(path.get(), 0, "view");
     180    } else if (widgetType == GTK_TYPE_CHECK_BUTTON)
     181        gtk_widget_path_iter_set_object_name(path.get(), 0, "checkbutton");
     182    else if (widgetType == GTK_TYPE_RADIO_BUTTON)
     183        gtk_widget_path_iter_set_object_name(path.get(), 0, "radiobutton");
     184    else if (widgetType == GTK_TYPE_COMBO_BOX)
     185        gtk_widget_path_iter_set_object_name(path.get(), 0, "combobox");
     186#else
     187    if (widgetType == GTK_TYPE_ENTRY)
     188        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_ENTRY);
     189    else if (widgetType == GTK_TYPE_ARROW)
     190        gtk_widget_path_iter_add_class(path.get(), 0, "arrow");
     191    else if (widgetType == GTK_TYPE_BUTTON) {
     192        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_BUTTON);
     193        gtk_widget_path_iter_add_class(path.get(), 0, "text-button");
     194    } else if (widgetType == GTK_TYPE_SCALE)
     195        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_SCALE);
     196    else if (widgetType == GTK_TYPE_SEPARATOR)
     197        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_SEPARATOR);
     198    else if (widgetType == GTK_TYPE_PROGRESS_BAR)
     199        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_PROGRESSBAR);
     200    else if (widgetType == GTK_TYPE_SPIN_BUTTON)
     201        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_SPINBUTTON);
    173202    else if (widgetType == GTK_TYPE_TREE_VIEW)
    174         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_VIEW);
     203        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_VIEW);
    175204    else if (widgetType == GTK_TYPE_CHECK_BUTTON)
    176         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_CHECK);
     205        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_CHECK);
    177206    else if (widgetType == GTK_TYPE_RADIO_BUTTON)
    178         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_RADIO);
     207        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_RADIO);
     208#endif
    179209
    180210    GRefPtr<GtkStyleContext> context = adoptGRef(gtk_style_context_new());
    181     gtk_style_context_set_path(context.get(), path);
    182     gtk_widget_path_free(path);
     211    gtk_style_context_set_path(context.get(), path.get());
    183212
    184213    return context;
     
    453482        return;
    454483
    455     // Other ports hard-code this to 13 which is also the default value defined by GTK+.
    456     // GTK+ users tend to demand the native look.
    457     // It could be made a configuration option values other than 13 actually break site compatibility.
     484    // Other ports hard-code this to 13. GTK+ users tend to demand the native look.
    458485    gint indicatorSize;
    459486    gtk_style_context_get_style(context.get(), "indicator-size", &indicatorSize, nullptr);
     
    469496{
    470497    GRefPtr<GtkStyleContext> context = createStyleContext(widgetType);
     498#if GTK_CHECK_VERSION(3, 19, 2)
     499    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     500
     501    if (widgetType == GTK_TYPE_CHECK_BUTTON) {
     502        if (theme->isChecked(renderObject) || theme->isIndeterminate(renderObject)) {
     503            gtk_widget_path_append_type(path.get(), GTK_TYPE_CHECK_BUTTON);
     504            gtk_widget_path_iter_set_object_name(path.get(), 0, "checkbutton");
     505        } else {
     506            gtk_widget_path_append_type(path.get(), GTK_TYPE_CHECK_BUTTON);
     507            gtk_widget_path_iter_set_object_name(path.get(), 0, "button");
     508            gtk_widget_path_iter_add_class(path.get(), 0, "check");
     509        }
     510
     511        gtk_widget_path_append_type(path.get(), GTK_TYPE_CHECK_BUTTON);
     512        gtk_widget_path_iter_set_object_name(path.get(), 1, "check");
     513    } else if (widgetType == GTK_TYPE_RADIO_BUTTON) {
     514        if (theme->isChecked(renderObject) || theme->isIndeterminate(renderObject)) {
     515            gtk_widget_path_append_type(path.get(), GTK_TYPE_RADIO_BUTTON);
     516            gtk_widget_path_iter_set_object_name(path.get(), 0, "radiobutton");
     517        } else {
     518            gtk_widget_path_append_type(path.get(), GTK_TYPE_RADIO_BUTTON);
     519            gtk_widget_path_iter_set_object_name(path.get(), 0, "button");
     520            gtk_widget_path_iter_add_class(path.get(), 0, "radio");
     521        }
     522
     523        gtk_widget_path_append_type(path.get(), GTK_TYPE_RADIO_BUTTON);
     524        gtk_widget_path_iter_set_object_name(path.get(), 1, "radio");
     525    }
     526
     527    gtk_style_context_set_path(context.get(), path.get());
     528#endif
    471529
    472530    // Some themes do not render large toggle buttons properly, so we simply
     
    488546
    489547    gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(renderObject.style().direction())));
     548
     549#if GTK_CHECK_VERSION(3, 19, 2)
     550    gtk_style_context_add_class(context.get(), "toggle");
     551#else
    490552    gtk_style_context_add_class(context.get(), widgetType == GTK_TYPE_CHECK_BUTTON ? GTK_STYLE_CLASS_CHECK : GTK_STYLE_CLASS_RADIO);
     553#endif
    491554
    492555    guint flags = 0;
     
    615678
    616679    gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(renderObject.style().direction())));
     680#if !GTK_CHECK_VERSION(3, 19, 2)
    617681    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_BUTTON);
     682#endif
    618683
    619684    renderButton(this, context.get(), renderObject, paintInfo, rect);
     
    644709
    645710    GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_COMBO_BOX);
    646 
     711#if GTK_CHECK_VERSION(3, 19, 2)
     712    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     713
     714    gtk_widget_path_append_type(path.get(), GTK_TYPE_COMBO_BOX);
     715    gtk_widget_path_iter_set_object_name(path.get(), 0, "combobox");
     716
     717    gtk_widget_path_append_type(path.get(), GTK_TYPE_COMBO_BOX);
     718    gtk_widget_path_iter_set_object_name(path.get(), 1, "button");
     719    gtk_widget_path_iter_add_class(path.get(), 1, "combo");
     720
     721    gtk_style_context_set_path(context.get(), path.get());
     722#else
    647723    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_BUTTON);
     724#endif
    648725    gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(style.direction())));
    649726
     
    660737    GtkTextDirection direction = static_cast<GtkTextDirection>(gtkTextDirection(style.direction()));
    661738    gtk_style_context_set_direction(context.get(), direction);
     739#if !GTK_CHECK_VERSION(3, 19, 2)
    662740    gtk_style_context_add_class(context.get(), "separator");
     741#endif
    663742
    664743    gboolean wideSeparators;
     
    722801    GRefPtr<GtkStyleContext> buttonStyleContext = createStyleContext(GTK_TYPE_BUTTON);
    723802    gtk_style_context_set_direction(buttonStyleContext.get(), direction);
     803#if !GTK_CHECK_VERSION(3, 19, 2)
    724804    gtk_style_context_add_class(buttonStyleContext.get(), GTK_STYLE_CLASS_BUTTON);
     805#endif
    725806    renderButton(this, buttonStyleContext.get(), renderObject, paintInfo, rect);
    726807
     
    759840
    760841    gtk_style_context_set_direction(arrowStyleContext.get(), direction);
     842#if !GTK_CHECK_VERSION(3, 19, 2)
    761843    gtk_style_context_add_class(arrowStyleContext.get(), "arrow");
    762844    gtk_style_context_add_class(arrowStyleContext.get(), GTK_STYLE_CLASS_BUTTON);
     845#endif
    763846
    764847    gfloat arrowScaling;
     
    780863    // Paint the separator if needed.
    781864    GRefPtr<GtkStyleContext> separatorStyleContext = createStyleContext(GTK_TYPE_COMBO_BOX);
     865#if GTK_CHECK_VERSION(3, 19, 2)
     866    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     867
     868    gtk_widget_path_append_type(path.get(), GTK_TYPE_SEPARATOR);
     869    gtk_widget_path_iter_set_object_name(path.get(), 0, "separator");
     870
     871    gtk_style_context_set_path(separatorStyleContext.get(), path.get());
     872#else
     873    gtk_style_context_add_class(separatorStyleContext.get(), "separator");
     874#endif
    782875
    783876    gtk_style_context_set_direction(separatorStyleContext.get(), direction);
    784     gtk_style_context_add_class(separatorStyleContext.get(), "separator");
    785877
    786878    gboolean wideSeparators;
     
    832924
    833925    gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(renderObject.style().direction())));
     926#if !GTK_CHECK_VERSION(3, 19, 2)
    834927    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_ENTRY);
     928#endif
    835929
    836930    guint flags = 0;
     
    10421136static void applySliderStyleContextClasses(GtkStyleContext* context, ControlPart part)
    10431137{
     1138#if !GTK_CHECK_VERSION(3, 19, 2)
    10441139    gtk_style_context_add_class(context, GTK_STYLE_CLASS_SCALE);
     1140#endif
    10451141    if (part == SliderHorizontalPart || part == SliderThumbHorizontalPart)
    10461142        gtk_style_context_add_class(context, GTK_STYLE_CLASS_HORIZONTAL);
     
    10551151
    10561152    GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_SCALE);
     1153#if GTK_CHECK_VERSION(3, 19, 2)
     1154    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     1155
     1156    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
     1157    gtk_widget_path_iter_set_object_name(path.get(), 0, "scale");
     1158
     1159    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
     1160    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     1161
     1162    gtk_style_context_set_path(context.get(), path.get());
     1163#endif
    10571164
    10581165    gtk_style_context_set_direction(context.get(), gtkTextDirection(renderObject.style().direction()));
    10591166    applySliderStyleContextClasses(context.get(), part);
     1167#if !GTK_CHECK_VERSION(3, 19, 2)
    10601168    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_TROUGH);
     1169#endif
    10611170
    10621171    if (!isEnabled(renderObject))
     
    10831192
    10841193    GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_SCALE);
     1194#if GTK_CHECK_VERSION(3, 19, 2)
     1195    // FIXME: The entire slider is too wide, stretching the thumb into an oval rather than a circle.
     1196    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     1197
     1198    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
     1199    gtk_widget_path_iter_set_object_name(path.get(), 0, "scale");
     1200
     1201    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
     1202    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     1203
     1204    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
     1205    gtk_widget_path_iter_set_object_name(path.get(), 2, "slider");
     1206
     1207    gtk_style_context_set_path(context.get(), path.get());
     1208#endif
    10851209
    10861210    gtk_style_context_set_direction(context.get(), gtkTextDirection(renderObject.style().direction()));
    10871211    applySliderStyleContextClasses(context.get(), part);
    1088     gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_SLIDER);
    10891212
    10901213    guint flags = 0;
     
    11281251
    11291252    GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_PROGRESS_BAR);
     1253#if GTK_CHECK_VERSION(3, 19, 2)
     1254    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     1255
     1256    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
     1257    gtk_widget_path_iter_set_object_name(path.get(), 0, "progressbar");
     1258
     1259    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
     1260    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     1261
     1262    gtk_style_context_set_path(context.get(), path.get());
     1263#else
    11301264    gtk_style_context_save(context.get());
    1131 
    11321265    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_TROUGH);
     1266#endif
    11331267
    11341268    gtk_render_background(context.get(), paintInfo.context().platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
    11351269    gtk_render_frame(context.get(), paintInfo.context().platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
    11361270
     1271#if GTK_CHECK_VERSION(3, 19, 2)
     1272    path = adoptGRef(gtk_widget_path_new());
     1273
     1274    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
     1275    gtk_widget_path_iter_set_object_name(path.get(), 0, "progressbar");
     1276
     1277    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
     1278    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     1279
     1280    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
     1281    gtk_widget_path_iter_set_object_name(path.get(), 2, "progress");
     1282
     1283    gtk_style_context_set_path(context.get(), path.get());
     1284#else
    11371285    gtk_style_context_restore(context.get());
    1138 
    11391286    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_PROGRESSBAR);
     1287#endif
     1288
    11401289    gtk_style_context_set_state(context.get(), static_cast<GtkStateFlags>(0));
    11411290
     
    11891338
    11901339    gtk_style_context_save(context);
     1340
     1341#if GTK_CHECK_VERSION(3, 19, 2)
     1342    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     1343
     1344    gtk_widget_path_append_type(path.get(), GTK_TYPE_SPIN_BUTTON);
     1345    gtk_widget_path_iter_set_object_name(path.get(), 0, "spinbutton");
     1346
     1347    gtk_widget_path_append_type(path.get(), GTK_TYPE_SPIN_BUTTON);
     1348    gtk_widget_path_iter_set_object_name(path.get(), 1, "button");
     1349    gtk_widget_path_iter_add_class(path.get(), 1, arrowType == GTK_ARROW_UP ? "up" : "down");
     1350
     1351    gtk_style_context_set_path(context, path.get());
     1352#else
    11911353    gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON);
     1354#endif
    11921355
    11931356    GtkTextDirection direction = gtk_style_context_get_direction(context);
     
    12901453static Color styleColor(GType widgetType, GtkStateFlags state, StyleColorType colorType)
    12911454{
    1292 
    12931455    GRefPtr<GtkStyleContext> context = createStyleContext(widgetType);
    1294     // Recent GTK+ versions (> 3.14) require to explicitly set the state before getting the color.
     1456#if GTK_CHECK_VERSION(3, 19, 2)
     1457    if (widgetType == GTK_TYPE_ENTRY) {
     1458        GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     1459
     1460        gtk_widget_path_append_type(path.get(), GTK_TYPE_ENTRY);
     1461        gtk_widget_path_iter_set_object_name(path.get(), 0, "entry");
     1462
     1463        gtk_widget_path_append_type(path.get(), GTK_TYPE_ENTRY);
     1464        gtk_widget_path_iter_set_object_name(path.get(), 1, "selection");
     1465
     1466        gtk_style_context_set_path(context.get(), path.get());
     1467    }
     1468#endif
     1469
    12951470    gtk_style_context_set_state(context.get(), state);
    12961471
    12971472    GdkRGBA gdkRGBAColor;
    12981473    if (colorType == StyleColorBackground)
    1299         gtk_style_context_get_background_color(context.get(), gtk_style_context_get_state(context.get()), &gdkRGBAColor);
     1474        gtk_style_context_get_background_color(context.get(), state, &gdkRGBAColor);
    13001475    else
    1301         gtk_style_context_get_color(context.get(), gtk_style_context_get_state(context.get()), &gdkRGBAColor);
     1476        gtk_style_context_get_color(context.get(), state, &gdkRGBAColor);
    13021477    return gdkRGBAColor;
    13031478}
Note: See TracChangeset for help on using the changeset viewer.