Changeset 194362 in webkit


Ignore:
Timestamp:
Dec 22, 2015 6:22:03 AM (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

    r194326 r194362  
     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-20  Jeremy Zerfas  <WebKit@JeremyZerfas.com>
    245
  • trunk/Source/WebCore/platform/gtk/GRefPtrGtk.cpp

    r147499 r194362  
    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

    r185502 r194362  
    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

    r192723 r194362  
    164164
    165165#ifndef GTK_API_VERSION_2
     166
     167#if !GTK_CHECK_VERSION(3, 19, 2)
     168// Currently we use a static GtkStyleContext for GTK+ < 3.19, and a bunch of unique
     169// GtkStyleContexts for GTK+ >= 3.19. This is crazy and definitely should not be necessary, but I
     170// couldn't find any other way to not break one version or the other. Ideally one of the two
     171// people on the planet who really understand GTK+ styles would fix this.
    166172class ScrollbarStyleContext {
    167173    WTF_MAKE_NONCOPYABLE(ScrollbarStyleContext); WTF_MAKE_FAST_ALLOCATED;
     
    192198    return styleContext.get().context();
    193199}
     200#endif
    194201
    195202ScrollbarThemeGtk::ScrollbarThemeGtk()
     
    200207void ScrollbarThemeGtk::themeChanged()
    201208{
     209#if !GTK_CHECK_VERSION(3, 19, 2)
    202210    gtk_style_context_invalidate(gtkScrollbarStyleContext());
     211#endif
    203212    updateThemeProperties();
    204213}
     
    206215void ScrollbarThemeGtk::updateThemeProperties()
    207216{
     217#if GTK_CHECK_VERSION(3, 19, 2)
     218    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
     219    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     220
     221    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     222    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
     223
     224    gtk_style_context_set_path(styleContext.get(), path.get());
     225#else
     226    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
     227#endif
     228
    208229    gtk_style_context_get_style(
    209         gtkScrollbarStyleContext(),
     230        styleContext.get(),
    210231        "min-slider-length", &m_minThumbLength,
    211232        "slider-width", &m_thumbFatness,
     
    273294}
    274295
     296
     297static const char* orientationStyleClass(ScrollbarOrientation orientation)
     298{
     299    return orientation == VerticalScrollbar ? "vertical" : "horizontal";
     300}
     301
     302#if !GTK_CHECK_VERSION(3, 19, 2)
    275303static void applyScrollbarStyleContextClasses(GtkStyleContext* context, ScrollbarOrientation orientation)
    276304{
    277305    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 }
     306    gtk_style_context_add_class(context, orientationStyleClass(orientation));
     307}
     308#endif
    280309
    281310static void adjustRectAccordingToMargin(GtkStyleContext* context, GtkStateFlags state, IntRect& rect)
     
    297326        fullScrollbarRect = IntRect(scrollbar.x(), scrollbar.y(), scrollbar.width(), scrollbar.height());
    298327
    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);
     328#if GTK_CHECK_VERSION(3, 19, 2)
     329    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
     330    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     331
     332    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     333    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
     334    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
     335
     336    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     337    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     338
     339    gtk_style_context_set_path(styleContext.get(), path.get());
     340#else
     341    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
     342    gtk_style_context_save(styleContext.get());
     343
     344    applyScrollbarStyleContextClasses(styleContext.get(), scrollbar.orientation());
     345    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_TROUGH);
     346#endif
     347
     348    adjustRectAccordingToMargin(styleContext.get(), static_cast<GtkStateFlags>(0), fullScrollbarRect);
     349    gtk_render_background(styleContext.get(), context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
     350    gtk_render_frame(styleContext.get(), context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
     351
     352#if !GTK_CHECK_VERSION(3, 19, 2)
     353    gtk_style_context_restore(styleContext.get());
     354#endif
    310355}
    311356
    312357void ScrollbarThemeGtk::paintScrollbarBackground(GraphicsContext& context, Scrollbar& scrollbar)
    313358{
    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);
     359#if GTK_CHECK_VERSION(3, 19, 2)
     360    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
     361    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     362
     363    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     364    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
     365    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
     366
     367    gtk_style_context_set_path(styleContext.get(), path.get());
     368#else
     369    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
     370    gtk_style_context_save(styleContext.get());
     371
     372    applyScrollbarStyleContextClasses(styleContext.get(), scrollbar.orientation());
     373    gtk_style_context_add_class(styleContext.get(), "scrolled-window");
     374#endif
     375
     376    gtk_render_frame(styleContext.get(), context.platformContext()->cr(), scrollbar.x(), scrollbar.y(), scrollbar.width(), scrollbar.height());
     377
     378#if !GTK_CHECK_VERSION(3, 19, 2)
     379    gtk_style_context_restore(styleContext.get());
     380#endif
    322381}
    323382
    324383void ScrollbarThemeGtk::paintThumb(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& rect)
    325384{
    326     GtkStyleContext* styleContext = gtkScrollbarStyleContext();
    327     gtk_style_context_save(styleContext);
     385#if GTK_CHECK_VERSION(3, 19, 2)
     386    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
     387    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     388
     389    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     390    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
     391    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
     392
     393    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     394    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     395
     396    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     397    gtk_widget_path_iter_set_object_name(path.get(), 2, "slider");
     398
     399    gtk_style_context_set_path(styleContext.get(), path.get());
     400#else
     401    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
     402    gtk_style_context_save(styleContext.get());
     403#endif
    328404
    329405    ScrollbarOrientation orientation = scrollbar.orientation();
    330     applyScrollbarStyleContextClasses(styleContext, orientation);
    331     gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_SLIDER);
     406#if !GTK_CHECK_VERSION(3, 19, 2)
     407    applyScrollbarStyleContextClasses(styleContext.get(), orientation);
     408    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_SLIDER);
     409#endif
    332410
    333411    guint flags = 0;
     
    336414    if (scrollbar.hoveredPart() == ThumbPart)
    337415        flags |= GTK_STATE_FLAG_PRELIGHT;
    338     gtk_style_context_set_state(styleContext, static_cast<GtkStateFlags>(flags));
     416    gtk_style_context_set_state(styleContext.get(), static_cast<GtkStateFlags>(flags));
    339417
    340418    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(),
     419    adjustRectAccordingToMargin(styleContext.get(), static_cast<GtkStateFlags>(flags), thumbRect);
     420    gtk_render_slider(styleContext.get(), context.platformContext()->cr(), thumbRect.x(), thumbRect.y(), thumbRect.width(), thumbRect.height(),
    343421        orientation == VerticalScrollbar ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
    344422
    345     gtk_style_context_restore(styleContext);
     423#if !GTK_CHECK_VERSION(3, 19, 2)
     424    gtk_style_context_restore(styleContext.get());
     425#endif
    346426}
    347427
    348428void ScrollbarThemeGtk::paintButton(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& rect, ScrollbarPart part)
    349429{
    350     GtkStyleContext* styleContext = gtkScrollbarStyleContext();
    351     gtk_style_context_save(styleContext);
     430#if GTK_CHECK_VERSION(3, 19, 2)
     431    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
     432    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     433
     434    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     435    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
     436    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
     437
     438    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
     439    gtk_widget_path_iter_set_object_name(path.get(), 1, "button");
     440
     441    gtk_style_context_set_path(styleContext.get(), path.get());
     442#else
     443    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
     444    gtk_style_context_save(styleContext.get());
     445#endif
    352446
    353447    ScrollbarOrientation orientation = scrollbar.orientation();
    354     applyScrollbarStyleContextClasses(styleContext, orientation);
     448#if !GTK_CHECK_VERSION(3, 19, 2)
     449    applyScrollbarStyleContextClasses(styleContext.get(), orientation);
     450#endif
    355451
    356452    guint flags = 0;
     
    365461    } else
    366462        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());
     463    gtk_style_context_set_state(styleContext.get(), static_cast<GtkStateFlags>(flags));
     464
     465#if !GTK_CHECK_VERSION(3, 19, 2)
     466    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_BUTTON);
     467#endif
     468
     469    gtk_render_background(styleContext.get(), context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
     470    gtk_render_frame(styleContext.get(), context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
    372471
    373472    gfloat arrowScaling;
    374     gtk_style_context_get_style(styleContext, "arrow-scaling", &arrowScaling, nullptr);
     473    gtk_style_context_get_style(styleContext.get(), "arrow-scaling", &arrowScaling, nullptr);
    375474
    376475    double arrowSize = std::min(rect.width(), rect.height()) * arrowScaling;
     
    381480    if (flags & GTK_STATE_FLAG_ACTIVE) {
    382481        gint arrowDisplacementX, arrowDisplacementY;
    383         gtk_style_context_get_style(styleContext, "arrow-displacement-x", &arrowDisplacementX, "arrow-displacement-y", &arrowDisplacementY, nullptr);
     482        gtk_style_context_get_style(styleContext.get(), "arrow-displacement-x", &arrowDisplacementX, "arrow-displacement-y", &arrowDisplacementY, nullptr);
    384483        arrowPoint.move(arrowDisplacementX, arrowDisplacementY);
    385484    }
     
    391490        angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI / 2 : 3 * (G_PI / 2);
    392491
    393     gtk_render_arrow(styleContext, context.platformContext()->cr(), angle, arrowPoint.x(), arrowPoint.y(), arrowSize);
    394 
    395     gtk_style_context_restore(styleContext);
     492    gtk_render_arrow(styleContext.get(), context.platformContext()->cr(), angle, arrowPoint.x(), arrowPoint.y(), arrowSize);
     493
     494#if !GTK_CHECK_VERSION(3, 19, 2)
     495    gtk_style_context_restore(styleContext.get());
     496#endif
    396497}
    397498
  • trunk/Source/WebCore/rendering/RenderThemeGtk.cpp

    r193896 r194362  
    153153    }
    154154
    155     GtkWidgetPath* path = gtk_widget_path_new();
    156     gtk_widget_path_append_type(path, widgetType);
    157 
     155    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     156    gtk_widget_path_append_type(path.get(), widgetType);
     157
     158#if GTK_CHECK_VERSION(3, 19, 2)
     159    // Pick a good default object path for the style context based on the widget type. This will
     160    // usually need to be overridden manually, but it doesn't hurt to have a good default.
    158161    if (widgetType == GTK_TYPE_ENTRY)
    159         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_ENTRY);
     162        gtk_widget_path_iter_set_object_name(path.get(), 0, "entry");
    160163    else if (widgetType == GTK_TYPE_ARROW)
    161         gtk_widget_path_iter_add_class(path, 0, "arrow");
     164        gtk_widget_path_iter_set_object_name(path.get(), 0, "button"); // Note: not a typo.
    162165    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");
     166        gtk_widget_path_iter_set_object_name(path.get(), 0, "button");
     167        gtk_widget_path_iter_add_class(path.get(), 0, "text-button");
    165168    } else if (widgetType == GTK_TYPE_SCALE)
    166         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SCALE);
     169        gtk_widget_path_iter_set_object_name(path.get(), 0, "scale");
    167170    else if (widgetType == GTK_TYPE_SEPARATOR)
    168         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SEPARATOR);
     171        gtk_widget_path_iter_set_object_name(path.get(), 0, "separator");
    169172    else if (widgetType == GTK_TYPE_PROGRESS_BAR)
    170         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_PROGRESSBAR);
     173        gtk_widget_path_iter_set_object_name(path.get(), 0, "progressbar");
    171174    else if (widgetType == GTK_TYPE_SPIN_BUTTON)
    172         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SPINBUTTON);
     175        gtk_widget_path_iter_set_object_name(path.get(), 0, "spinbutton");
     176    else if (widgetType == GTK_TYPE_TREE_VIEW) {
     177        gtk_widget_path_iter_set_object_name(path.get(), 0, "treeview");
     178        gtk_widget_path_iter_add_class(path.get(), 0, "view");
     179    } else if (widgetType == GTK_TYPE_CHECK_BUTTON)
     180        gtk_widget_path_iter_set_object_name(path.get(), 0, "checkbutton");
     181    else if (widgetType == GTK_TYPE_RADIO_BUTTON)
     182        gtk_widget_path_iter_set_object_name(path.get(), 0, "radiobutton");
     183    else if (widgetType == GTK_TYPE_COMBO_BOX)
     184        gtk_widget_path_iter_set_object_name(path.get(), 0, "combobox");
     185#else
     186    if (widgetType == GTK_TYPE_ENTRY)
     187        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_ENTRY);
     188    else if (widgetType == GTK_TYPE_ARROW)
     189        gtk_widget_path_iter_add_class(path.get(), 0, "arrow");
     190    else if (widgetType == GTK_TYPE_BUTTON) {
     191        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_BUTTON);
     192        gtk_widget_path_iter_add_class(path.get(), 0, "text-button");
     193    } else if (widgetType == GTK_TYPE_SCALE)
     194        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_SCALE);
     195    else if (widgetType == GTK_TYPE_SEPARATOR)
     196        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_SEPARATOR);
     197    else if (widgetType == GTK_TYPE_PROGRESS_BAR)
     198        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_PROGRESSBAR);
     199    else if (widgetType == GTK_TYPE_SPIN_BUTTON)
     200        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_SPINBUTTON);
    173201    else if (widgetType == GTK_TYPE_TREE_VIEW)
    174         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_VIEW);
     202        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_VIEW);
    175203    else if (widgetType == GTK_TYPE_CHECK_BUTTON)
    176         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_CHECK);
     204        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_CHECK);
    177205    else if (widgetType == GTK_TYPE_RADIO_BUTTON)
    178         gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_RADIO);
     206        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_RADIO);
     207#endif
    179208
    180209    GRefPtr<GtkStyleContext> context = adoptGRef(gtk_style_context_new());
    181     gtk_style_context_set_path(context.get(), path);
    182     gtk_widget_path_free(path);
     210    gtk_style_context_set_path(context.get(), path.get());
    183211
    184212    return context;
     
    453481        return;
    454482
    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.
     483    // Other ports hard-code this to 13. GTK+ users tend to demand the native look.
    458484    gint indicatorSize;
    459485    gtk_style_context_get_style(context.get(), "indicator-size", &indicatorSize, nullptr);
     
    469495{
    470496    GRefPtr<GtkStyleContext> context = createStyleContext(widgetType);
     497#if GTK_CHECK_VERSION(3, 19, 2)
     498    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     499
     500    if (widgetType == GTK_TYPE_CHECK_BUTTON) {
     501        if (theme->isChecked(renderObject) || theme->isIndeterminate(renderObject)) {
     502            gtk_widget_path_append_type(path.get(), GTK_TYPE_CHECK_BUTTON);
     503            gtk_widget_path_iter_set_object_name(path.get(), 0, "checkbutton");
     504        } else {
     505            gtk_widget_path_append_type(path.get(), GTK_TYPE_CHECK_BUTTON);
     506            gtk_widget_path_iter_set_object_name(path.get(), 0, "button");
     507            gtk_widget_path_iter_add_class(path.get(), 0, "check");
     508        }
     509
     510        gtk_widget_path_append_type(path.get(), GTK_TYPE_CHECK_BUTTON);
     511        gtk_widget_path_iter_set_object_name(path.get(), 1, "check");
     512    } else if (widgetType == GTK_TYPE_RADIO_BUTTON) {
     513        if (theme->isChecked(renderObject) || theme->isIndeterminate(renderObject)) {
     514            gtk_widget_path_append_type(path.get(), GTK_TYPE_RADIO_BUTTON);
     515            gtk_widget_path_iter_set_object_name(path.get(), 0, "radiobutton");
     516        } else {
     517            gtk_widget_path_append_type(path.get(), GTK_TYPE_RADIO_BUTTON);
     518            gtk_widget_path_iter_set_object_name(path.get(), 0, "button");
     519            gtk_widget_path_iter_add_class(path.get(), 0, "radio");
     520        }
     521
     522        gtk_widget_path_append_type(path.get(), GTK_TYPE_RADIO_BUTTON);
     523        gtk_widget_path_iter_set_object_name(path.get(), 1, "radio");
     524    }
     525
     526    gtk_style_context_set_path(context.get(), path.get());
     527#endif
    471528
    472529    // Some themes do not render large toggle buttons properly, so we simply
     
    488545
    489546    gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(renderObject.style().direction())));
     547
     548#if GTK_CHECK_VERSION(3, 19, 2)
     549    gtk_style_context_add_class(context.get(), "toggle");
     550#else
    490551    gtk_style_context_add_class(context.get(), widgetType == GTK_TYPE_CHECK_BUTTON ? GTK_STYLE_CLASS_CHECK : GTK_STYLE_CLASS_RADIO);
     552#endif
    491553
    492554    guint flags = 0;
     
    615677
    616678    gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(renderObject.style().direction())));
     679#if !GTK_CHECK_VERSION(3, 19, 2)
    617680    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_BUTTON);
     681#endif
    618682
    619683    renderButton(this, context.get(), renderObject, paintInfo, rect);
     
    644708
    645709    GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_COMBO_BOX);
    646 
     710#if GTK_CHECK_VERSION(3, 19, 2)
     711    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     712
     713    gtk_widget_path_append_type(path.get(), GTK_TYPE_COMBO_BOX);
     714    gtk_widget_path_iter_set_object_name(path.get(), 0, "combobox");
     715
     716    gtk_widget_path_append_type(path.get(), GTK_TYPE_COMBO_BOX);
     717    gtk_widget_path_iter_set_object_name(path.get(), 1, "button");
     718    gtk_widget_path_iter_add_class(path.get(), 1, "combo");
     719
     720    gtk_style_context_set_path(context.get(), path.get());
     721#else
    647722    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_BUTTON);
     723#endif
    648724    gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(style.direction())));
    649725
     
    660736    GtkTextDirection direction = static_cast<GtkTextDirection>(gtkTextDirection(style.direction()));
    661737    gtk_style_context_set_direction(context.get(), direction);
     738#if !GTK_CHECK_VERSION(3, 19, 2)
    662739    gtk_style_context_add_class(context.get(), "separator");
     740#endif
    663741
    664742    gboolean wideSeparators;
     
    722800    GRefPtr<GtkStyleContext> buttonStyleContext = createStyleContext(GTK_TYPE_BUTTON);
    723801    gtk_style_context_set_direction(buttonStyleContext.get(), direction);
     802#if !GTK_CHECK_VERSION(3, 19, 2)
    724803    gtk_style_context_add_class(buttonStyleContext.get(), GTK_STYLE_CLASS_BUTTON);
     804#endif
    725805    renderButton(this, buttonStyleContext.get(), renderObject, paintInfo, rect);
    726806
     
    759839
    760840    gtk_style_context_set_direction(arrowStyleContext.get(), direction);
     841#if !GTK_CHECK_VERSION(3, 19, 2)
    761842    gtk_style_context_add_class(arrowStyleContext.get(), "arrow");
    762843    gtk_style_context_add_class(arrowStyleContext.get(), GTK_STYLE_CLASS_BUTTON);
     844#endif
    763845
    764846    gfloat arrowScaling;
     
    780862    // Paint the separator if needed.
    781863    GRefPtr<GtkStyleContext> separatorStyleContext = createStyleContext(GTK_TYPE_COMBO_BOX);
     864#if GTK_CHECK_VERSION(3, 19, 2)
     865    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     866
     867    gtk_widget_path_append_type(path.get(), GTK_TYPE_SEPARATOR);
     868    gtk_widget_path_iter_set_object_name(path.get(), 0, "separator");
     869
     870    gtk_style_context_set_path(separatorStyleContext.get(), path.get());
     871#else
     872    gtk_style_context_add_class(separatorStyleContext.get(), "separator");
     873#endif
    782874
    783875    gtk_style_context_set_direction(separatorStyleContext.get(), direction);
    784     gtk_style_context_add_class(separatorStyleContext.get(), "separator");
    785876
    786877    gboolean wideSeparators;
     
    832923
    833924    gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(renderObject.style().direction())));
     925#if !GTK_CHECK_VERSION(3, 19, 2)
    834926    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_ENTRY);
     927#endif
    835928
    836929    guint flags = 0;
     
    10421135static void applySliderStyleContextClasses(GtkStyleContext* context, ControlPart part)
    10431136{
     1137#if !GTK_CHECK_VERSION(3, 19, 2)
    10441138    gtk_style_context_add_class(context, GTK_STYLE_CLASS_SCALE);
     1139#endif
    10451140    if (part == SliderHorizontalPart || part == SliderThumbHorizontalPart)
    10461141        gtk_style_context_add_class(context, GTK_STYLE_CLASS_HORIZONTAL);
     
    10551150
    10561151    GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_SCALE);
     1152#if GTK_CHECK_VERSION(3, 19, 2)
     1153    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     1154
     1155    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
     1156    gtk_widget_path_iter_set_object_name(path.get(), 0, "scale");
     1157
     1158    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
     1159    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     1160
     1161    gtk_style_context_set_path(context.get(), path.get());
     1162#endif
    10571163
    10581164    gtk_style_context_set_direction(context.get(), gtkTextDirection(renderObject.style().direction()));
    10591165    applySliderStyleContextClasses(context.get(), part);
     1166#if !GTK_CHECK_VERSION(3, 19, 2)
    10601167    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_TROUGH);
     1168#endif
    10611169
    10621170    if (!isEnabled(renderObject))
     
    10831191
    10841192    GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_SCALE);
     1193#if GTK_CHECK_VERSION(3, 19, 2)
     1194    // FIXME: The entire slider is too wide, stretching the thumb into an oval rather than a circle.
     1195    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     1196
     1197    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
     1198    gtk_widget_path_iter_set_object_name(path.get(), 0, "scale");
     1199
     1200    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
     1201    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     1202
     1203    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
     1204    gtk_widget_path_iter_set_object_name(path.get(), 2, "slider");
     1205
     1206    gtk_style_context_set_path(context.get(), path.get());
     1207#endif
    10851208
    10861209    gtk_style_context_set_direction(context.get(), gtkTextDirection(renderObject.style().direction()));
    10871210    applySliderStyleContextClasses(context.get(), part);
    1088     gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_SLIDER);
    10891211
    10901212    guint flags = 0;
     
    11281250
    11291251    GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_PROGRESS_BAR);
     1252#if GTK_CHECK_VERSION(3, 19, 2)
     1253    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     1254
     1255    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
     1256    gtk_widget_path_iter_set_object_name(path.get(), 0, "progressbar");
     1257
     1258    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
     1259    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     1260
     1261    gtk_style_context_set_path(context.get(), path.get());
     1262#else
    11301263    gtk_style_context_save(context.get());
    1131 
    11321264    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_TROUGH);
     1265#endif
    11331266
    11341267    gtk_render_background(context.get(), paintInfo.context().platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
    11351268    gtk_render_frame(context.get(), paintInfo.context().platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
    11361269
     1270#if GTK_CHECK_VERSION(3, 19, 2)
     1271    path = adoptGRef(gtk_widget_path_new());
     1272
     1273    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
     1274    gtk_widget_path_iter_set_object_name(path.get(), 0, "progressbar");
     1275
     1276    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
     1277    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
     1278
     1279    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
     1280    gtk_widget_path_iter_set_object_name(path.get(), 2, "progress");
     1281
     1282    gtk_style_context_set_path(context.get(), path.get());
     1283#else
    11371284    gtk_style_context_restore(context.get());
    1138 
    11391285    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_PROGRESSBAR);
     1286#endif
     1287
    11401288    gtk_style_context_set_state(context.get(), static_cast<GtkStateFlags>(0));
    11411289
     
    11891337
    11901338    gtk_style_context_save(context);
     1339
     1340#if GTK_CHECK_VERSION(3, 19, 2)
     1341    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     1342
     1343    gtk_widget_path_append_type(path.get(), GTK_TYPE_SPIN_BUTTON);
     1344    gtk_widget_path_iter_set_object_name(path.get(), 0, "spinbutton");
     1345
     1346    gtk_widget_path_append_type(path.get(), GTK_TYPE_SPIN_BUTTON);
     1347    gtk_widget_path_iter_set_object_name(path.get(), 1, "button");
     1348    gtk_widget_path_iter_add_class(path.get(), 1, arrowType == GTK_ARROW_UP ? "up" : "down");
     1349
     1350    gtk_style_context_set_path(context, path.get());
     1351#else
    11911352    gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON);
     1353#endif
    11921354
    11931355    GtkTextDirection direction = gtk_style_context_get_direction(context);
     
    12901452static Color styleColor(GType widgetType, GtkStateFlags state, StyleColorType colorType)
    12911453{
    1292 
    12931454    GRefPtr<GtkStyleContext> context = createStyleContext(widgetType);
    1294     // Recent GTK+ versions (> 3.14) require to explicitly set the state before getting the color.
     1455#if GTK_CHECK_VERSION(3, 19, 2)
     1456    if (widgetType == GTK_TYPE_ENTRY) {
     1457        GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     1458
     1459        gtk_widget_path_append_type(path.get(), GTK_TYPE_ENTRY);
     1460        gtk_widget_path_iter_set_object_name(path.get(), 0, "entry");
     1461
     1462        gtk_widget_path_append_type(path.get(), GTK_TYPE_ENTRY);
     1463        gtk_widget_path_iter_set_object_name(path.get(), 1, "selection");
     1464
     1465        gtk_style_context_set_path(context.get(), path.get());
     1466    }
     1467#endif
     1468
    12951469    gtk_style_context_set_state(context.get(), state);
    12961470
    12971471    GdkRGBA gdkRGBAColor;
    12981472    if (colorType == StyleColorBackground)
    1299         gtk_style_context_get_background_color(context.get(), gtk_style_context_get_state(context.get()), &gdkRGBAColor);
     1473        gtk_style_context_get_background_color(context.get(), state, &gdkRGBAColor);
    13001474    else
    1301         gtk_style_context_get_color(context.get(), gtk_style_context_get_state(context.get()), &gdkRGBAColor);
     1475        gtk_style_context_get_color(context.get(), state, &gdkRGBAColor);
    13021476    return gdkRGBAColor;
    13031477}
Note: See TracChangeset for help on using the changeset viewer.