Title: [194362] trunk/Source/WebCore
Revision
194362
Author
[email protected]
Date
2015-12-22 06:22:03 -0800 (Tue, 22 Dec 2015)

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (194361 => 194362)


--- trunk/Source/WebCore/ChangeLog	2015-12-22 09:16:24 UTC (rev 194361)
+++ trunk/Source/WebCore/ChangeLog	2015-12-22 14:22:03 UTC (rev 194362)
@@ -1,3 +1,46 @@
+2015-12-22  Michael Catanzaro  <[email protected]>
+
+        [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):
+
 2015-12-20  Jeremy Zerfas  <[email protected]>
 
         Don't allocate a NSImage and skip unneeded call to TIFFRepresentation when copying image to clipboard.

Modified: trunk/Source/WebCore/platform/gtk/GRefPtrGtk.cpp (194361 => 194362)


--- trunk/Source/WebCore/platform/gtk/GRefPtrGtk.cpp	2015-12-22 09:16:24 UTC (rev 194361)
+++ trunk/Source/WebCore/platform/gtk/GRefPtrGtk.cpp	2015-12-22 14:22:03 UTC (rev 194362)
@@ -72,6 +72,22 @@
     if (ptr)
         gdk_cursor_unref(ptr);
 }
+
+#else
+
+template <> GtkWidgetPath* refGPtr(GtkWidgetPath* ptr)
+{
+    if (ptr)
+        gtk_widget_path_ref(ptr);
+    return ptr;
+}
+
+template <> void derefGPtr(GtkWidgetPath* ptr)
+{
+    if (ptr)
+        gtk_widget_path_unref(ptr);
+}
+
 #endif
 
 }

Modified: trunk/Source/WebCore/platform/gtk/GRefPtrGtk.h (194361 => 194362)


--- trunk/Source/WebCore/platform/gtk/GRefPtrGtk.h	2015-12-22 09:16:24 UTC (rev 194361)
+++ trunk/Source/WebCore/platform/gtk/GRefPtrGtk.h	2015-12-22 14:22:03 UTC (rev 194362)
@@ -23,6 +23,7 @@
 
 #include <wtf/glib/GRefPtr.h>
 
+typedef struct _GtkWidgetPath GtkWidgetPath;
 typedef struct _SecretValue SecretValue;
 
 namespace WTF {
@@ -38,6 +39,9 @@
 #ifdef GTK_API_VERSION_2
 template <> GdkCursor* refGPtr(GdkCursor* ptr);
 template <> void derefGPtr(GdkCursor* ptr);
+#else
+template <> GtkWidgetPath* refGPtr(GtkWidgetPath* ptr);
+template <> void derefGPtr(GtkWidgetPath* ptr);
 #endif
 
 }

Modified: trunk/Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp (194361 => 194362)


--- trunk/Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp	2015-12-22 09:16:24 UTC (rev 194361)
+++ trunk/Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp	2015-12-22 14:22:03 UTC (rev 194362)
@@ -163,6 +163,12 @@
 }
 
 #ifndef GTK_API_VERSION_2
+
+#if !GTK_CHECK_VERSION(3, 19, 2)
+// Currently we use a static GtkStyleContext for GTK+ < 3.19, and a bunch of unique
+// GtkStyleContexts for GTK+ >= 3.19. This is crazy and definitely should not be necessary, but I
+// couldn't find any other way to not break one version or the other. Ideally one of the two
+// people on the planet who really understand GTK+ styles would fix this.
 class ScrollbarStyleContext {
     WTF_MAKE_NONCOPYABLE(ScrollbarStyleContext); WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -191,6 +197,7 @@
     static NeverDestroyed<ScrollbarStyleContext> styleContext;
     return styleContext.get().context();
 }
+#endif
 
 ScrollbarThemeGtk::ScrollbarThemeGtk()
 {
@@ -199,14 +206,28 @@
 
 void ScrollbarThemeGtk::themeChanged()
 {
+#if !GTK_CHECK_VERSION(3, 19, 2)
     gtk_style_context_invalidate(gtkScrollbarStyleContext());
+#endif
     updateThemeProperties();
 }
 
 void ScrollbarThemeGtk::updateThemeProperties()
 {
+#if GTK_CHECK_VERSION(3, 19, 2)
+    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
+
+    gtk_style_context_set_path(styleContext.get(), path.get());
+#else
+    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
+#endif
+
     gtk_style_context_get_style(
-        gtkScrollbarStyleContext(),
+        styleContext.get(),
         "min-slider-length", &m_minThumbLength,
         "slider-width", &m_thumbFatness,
         "trough-border", &m_troughBorderWidth,
@@ -272,11 +293,19 @@
     return IntRect(trackRect.x() + (trackRect.width() - m_thumbFatness) / 2, trackRect.y() + thumbPos, m_thumbFatness, thumbLength(scrollbar));
 }
 
+
+static const char* orientationStyleClass(ScrollbarOrientation orientation)
+{
+    return orientation == VerticalScrollbar ? "vertical" : "horizontal";
+}
+
+#if !GTK_CHECK_VERSION(3, 19, 2)
 static void applyScrollbarStyleContextClasses(GtkStyleContext* context, ScrollbarOrientation orientation)
 {
     gtk_style_context_add_class(context, GTK_STYLE_CLASS_SCROLLBAR);
-    gtk_style_context_add_class(context, orientation == VerticalScrollbar ?  GTK_STYLE_CLASS_VERTICAL : GTK_STYLE_CLASS_HORIZONTAL);
+    gtk_style_context_add_class(context, orientationStyleClass(orientation));
 }
+#endif
 
 static void adjustRectAccordingToMargin(GtkStyleContext* context, GtkStateFlags state, IntRect& rect)
 {
@@ -296,62 +325,129 @@
     if (m_troughUnderSteppers)
         fullScrollbarRect = IntRect(scrollbar.x(), scrollbar.y(), scrollbar.width(), scrollbar.height());
 
-    GtkStyleContext* styleContext = gtkScrollbarStyleContext();
-    gtk_style_context_save(styleContext);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
 
-    applyScrollbarStyleContextClasses(styleContext, scrollbar.orientation());
-    gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_TROUGH);
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
+    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
 
-    adjustRectAccordingToMargin(styleContext, static_cast<GtkStateFlags>(0), fullScrollbarRect);
-    gtk_render_background(styleContext, context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
-    gtk_render_frame(styleContext, context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
 
-    gtk_style_context_restore(styleContext);
+    gtk_style_context_set_path(styleContext.get(), path.get());
+#else
+    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
+    gtk_style_context_save(styleContext.get());
+
+    applyScrollbarStyleContextClasses(styleContext.get(), scrollbar.orientation());
+    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_TROUGH);
+#endif
+
+    adjustRectAccordingToMargin(styleContext.get(), static_cast<GtkStateFlags>(0), fullScrollbarRect);
+    gtk_render_background(styleContext.get(), context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
+    gtk_render_frame(styleContext.get(), context.platformContext()->cr(), fullScrollbarRect.x(), fullScrollbarRect.y(), fullScrollbarRect.width(), fullScrollbarRect.height());
+
+#if !GTK_CHECK_VERSION(3, 19, 2)
+    gtk_style_context_restore(styleContext.get());
+#endif
 }
 
 void ScrollbarThemeGtk::paintScrollbarBackground(GraphicsContext& context, Scrollbar& scrollbar)
 {
-    GtkStyleContext* styleContext = gtkScrollbarStyleContext();
-    gtk_style_context_save(styleContext);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
 
-    applyScrollbarStyleContextClasses(styleContext, scrollbar.orientation());
-    gtk_style_context_add_class(styleContext, "scrolled-window");
-    gtk_render_frame(styleContext, context.platformContext()->cr(), scrollbar.x(), scrollbar.y(), scrollbar.width(), scrollbar.height());
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
+    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
 
-    gtk_style_context_restore(styleContext);
+    gtk_style_context_set_path(styleContext.get(), path.get());
+#else
+    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
+    gtk_style_context_save(styleContext.get());
+
+    applyScrollbarStyleContextClasses(styleContext.get(), scrollbar.orientation());
+    gtk_style_context_add_class(styleContext.get(), "scrolled-window");
+#endif
+
+    gtk_render_frame(styleContext.get(), context.platformContext()->cr(), scrollbar.x(), scrollbar.y(), scrollbar.width(), scrollbar.height());
+
+#if !GTK_CHECK_VERSION(3, 19, 2)
+    gtk_style_context_restore(styleContext.get());
+#endif
 }
 
 void ScrollbarThemeGtk::paintThumb(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& rect)
 {
-    GtkStyleContext* styleContext = gtkScrollbarStyleContext();
-    gtk_style_context_save(styleContext);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
 
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
+    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 2, "slider");
+
+    gtk_style_context_set_path(styleContext.get(), path.get());
+#else
+    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
+    gtk_style_context_save(styleContext.get());
+#endif
+
     ScrollbarOrientation orientation = scrollbar.orientation();
-    applyScrollbarStyleContextClasses(styleContext, orientation);
-    gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_SLIDER);
+#if !GTK_CHECK_VERSION(3, 19, 2)
+    applyScrollbarStyleContextClasses(styleContext.get(), orientation);
+    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_SLIDER);
+#endif
 
     guint flags = 0;
     if (scrollbar.pressedPart() == ThumbPart)
         flags |= GTK_STATE_FLAG_ACTIVE;
     if (scrollbar.hoveredPart() == ThumbPart)
         flags |= GTK_STATE_FLAG_PRELIGHT;
-    gtk_style_context_set_state(styleContext, static_cast<GtkStateFlags>(flags));
+    gtk_style_context_set_state(styleContext.get(), static_cast<GtkStateFlags>(flags));
 
     IntRect thumbRect(rect);
-    adjustRectAccordingToMargin(styleContext, static_cast<GtkStateFlags>(flags), thumbRect);
-    gtk_render_slider(styleContext, context.platformContext()->cr(), thumbRect.x(), thumbRect.y(), thumbRect.width(), thumbRect.height(),
+    adjustRectAccordingToMargin(styleContext.get(), static_cast<GtkStateFlags>(flags), thumbRect);
+    gtk_render_slider(styleContext.get(), context.platformContext()->cr(), thumbRect.x(), thumbRect.y(), thumbRect.width(), thumbRect.height(),
         orientation == VerticalScrollbar ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
 
-    gtk_style_context_restore(styleContext);
+#if !GTK_CHECK_VERSION(3, 19, 2)
+    gtk_style_context_restore(styleContext.get());
+#endif
 }
 
 void ScrollbarThemeGtk::paintButton(GraphicsContext& context, Scrollbar& scrollbar, const IntRect& rect, ScrollbarPart part)
 {
-    GtkStyleContext* styleContext = gtkScrollbarStyleContext();
-    gtk_style_context_save(styleContext);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    GRefPtr<GtkStyleContext> styleContext = adoptGRef(gtk_style_context_new());
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
 
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "scrollbar");
+    gtk_widget_path_iter_add_class(path.get(), 0, orientationStyleClass(scrollbar.orientation()));
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCROLLBAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 1, "button");
+
+    gtk_style_context_set_path(styleContext.get(), path.get());
+#else
+    GRefPtr<GtkStyleContext> styleContext = gtkScrollbarStyleContext();
+    gtk_style_context_save(styleContext.get());
+#endif
+
     ScrollbarOrientation orientation = scrollbar.orientation();
-    applyScrollbarStyleContextClasses(styleContext, orientation);
+#if !GTK_CHECK_VERSION(3, 19, 2)
+    applyScrollbarStyleContextClasses(styleContext.get(), orientation);
+#endif
 
     guint flags = 0;
     if ((BackButtonStartPart == part && scrollbar.currentPos())
@@ -364,14 +460,17 @@
             flags |= GTK_STATE_FLAG_PRELIGHT;
     } else
         flags |= GTK_STATE_FLAG_INSENSITIVE;
-    gtk_style_context_set_state(styleContext, static_cast<GtkStateFlags>(flags));
+    gtk_style_context_set_state(styleContext.get(), static_cast<GtkStateFlags>(flags));
 
-    gtk_style_context_add_class(styleContext, GTK_STYLE_CLASS_BUTTON);
-    gtk_render_background(styleContext, context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
-    gtk_render_frame(styleContext, context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
+#if !GTK_CHECK_VERSION(3, 19, 2)
+    gtk_style_context_add_class(styleContext.get(), GTK_STYLE_CLASS_BUTTON);
+#endif
 
+    gtk_render_background(styleContext.get(), context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
+    gtk_render_frame(styleContext.get(), context.platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
+
     gfloat arrowScaling;
-    gtk_style_context_get_style(styleContext, "arrow-scaling", &arrowScaling, nullptr);
+    gtk_style_context_get_style(styleContext.get(), "arrow-scaling", &arrowScaling, nullptr);
 
     double arrowSize = std::min(rect.width(), rect.height()) * arrowScaling;
     FloatPoint arrowPoint(
@@ -380,7 +479,7 @@
 
     if (flags & GTK_STATE_FLAG_ACTIVE) {
         gint arrowDisplacementX, arrowDisplacementY;
-        gtk_style_context_get_style(styleContext, "arrow-displacement-x", &arrowDisplacementX, "arrow-displacement-y", &arrowDisplacementY, nullptr);
+        gtk_style_context_get_style(styleContext.get(), "arrow-displacement-x", &arrowDisplacementX, "arrow-displacement-y", &arrowDisplacementY, nullptr);
         arrowPoint.move(arrowDisplacementX, arrowDisplacementY);
     }
 
@@ -390,9 +489,11 @@
     else
         angle = (part == ForwardButtonEndPart || part == ForwardButtonStartPart) ? G_PI / 2 : 3 * (G_PI / 2);
 
-    gtk_render_arrow(styleContext, context.platformContext()->cr(), angle, arrowPoint.x(), arrowPoint.y(), arrowSize);
+    gtk_render_arrow(styleContext.get(), context.platformContext()->cr(), angle, arrowPoint.x(), arrowPoint.y(), arrowSize);
 
-    gtk_style_context_restore(styleContext);
+#if !GTK_CHECK_VERSION(3, 19, 2)
+    gtk_style_context_restore(styleContext.get());
+#endif
 }
 
 bool ScrollbarThemeGtk::paint(Scrollbar& scrollbar, GraphicsContext& graphicsContext, const IntRect& damageRect)

Modified: trunk/Source/WebCore/rendering/RenderThemeGtk.cpp (194361 => 194362)


--- trunk/Source/WebCore/rendering/RenderThemeGtk.cpp	2015-12-22 09:16:24 UTC (rev 194361)
+++ trunk/Source/WebCore/rendering/RenderThemeGtk.cpp	2015-12-22 14:22:03 UTC (rev 194362)
@@ -152,34 +152,62 @@
         initialized = true;
     }
 
-    GtkWidgetPath* path = gtk_widget_path_new();
-    gtk_widget_path_append_type(path, widgetType);
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
+    gtk_widget_path_append_type(path.get(), widgetType);
 
+#if GTK_CHECK_VERSION(3, 19, 2)
+    // Pick a good default object path for the style context based on the widget type. This will
+    // usually need to be overridden manually, but it doesn't hurt to have a good default.
     if (widgetType == GTK_TYPE_ENTRY)
-        gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_ENTRY);
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "entry");
     else if (widgetType == GTK_TYPE_ARROW)
-        gtk_widget_path_iter_add_class(path, 0, "arrow");
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "button"); // Note: not a typo.
     else if (widgetType == GTK_TYPE_BUTTON) {
-        gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_BUTTON);
-        gtk_widget_path_iter_add_class(path, 0, "text-button");
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "button");
+        gtk_widget_path_iter_add_class(path.get(), 0, "text-button");
     } else if (widgetType == GTK_TYPE_SCALE)
-        gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SCALE);
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "scale");
     else if (widgetType == GTK_TYPE_SEPARATOR)
-        gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SEPARATOR);
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "separator");
     else if (widgetType == GTK_TYPE_PROGRESS_BAR)
-        gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_PROGRESSBAR);
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "progressbar");
     else if (widgetType == GTK_TYPE_SPIN_BUTTON)
-        gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_SPINBUTTON);
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "spinbutton");
+    else if (widgetType == GTK_TYPE_TREE_VIEW) {
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "treeview");
+        gtk_widget_path_iter_add_class(path.get(), 0, "view");
+    } else if (widgetType == GTK_TYPE_CHECK_BUTTON)
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "checkbutton");
+    else if (widgetType == GTK_TYPE_RADIO_BUTTON)
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "radiobutton");
+    else if (widgetType == GTK_TYPE_COMBO_BOX)
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "combobox");
+#else
+    if (widgetType == GTK_TYPE_ENTRY)
+        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_ENTRY);
+    else if (widgetType == GTK_TYPE_ARROW)
+        gtk_widget_path_iter_add_class(path.get(), 0, "arrow");
+    else if (widgetType == GTK_TYPE_BUTTON) {
+        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_BUTTON);
+        gtk_widget_path_iter_add_class(path.get(), 0, "text-button");
+    } else if (widgetType == GTK_TYPE_SCALE)
+        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_SCALE);
+    else if (widgetType == GTK_TYPE_SEPARATOR)
+        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_SEPARATOR);
+    else if (widgetType == GTK_TYPE_PROGRESS_BAR)
+        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_PROGRESSBAR);
+    else if (widgetType == GTK_TYPE_SPIN_BUTTON)
+        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_SPINBUTTON);
     else if (widgetType == GTK_TYPE_TREE_VIEW)
-        gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_VIEW);
+        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_VIEW);
     else if (widgetType == GTK_TYPE_CHECK_BUTTON)
-        gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_CHECK);
+        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_CHECK);
     else if (widgetType == GTK_TYPE_RADIO_BUTTON)
-        gtk_widget_path_iter_add_class(path, 0, GTK_STYLE_CLASS_RADIO);
+        gtk_widget_path_iter_add_class(path.get(), 0, GTK_STYLE_CLASS_RADIO);
+#endif
 
     GRefPtr<GtkStyleContext> context = adoptGRef(gtk_style_context_new());
-    gtk_style_context_set_path(context.get(), path);
-    gtk_widget_path_free(path);
+    gtk_style_context_set_path(context.get(), path.get());
 
     return context;
 }
@@ -452,9 +480,7 @@
     if (!style.width().isIntrinsicOrAuto() && !style.height().isAuto())
         return;
 
-    // Other ports hard-code this to 13 which is also the default value defined by GTK+.
-    // GTK+ users tend to demand the native look.
-    // It could be made a configuration option values other than 13 actually break site compatibility.
+    // Other ports hard-code this to 13. GTK+ users tend to demand the native look.
     gint indicatorSize;
     gtk_style_context_get_style(context.get(), "indicator-size", &indicatorSize, nullptr);
 
@@ -468,7 +494,38 @@
 static void paintToggle(const RenderThemeGtk* theme, GType widgetType, const RenderObject& renderObject, const PaintInfo& paintInfo, const IntRect& fullRect)
 {
     GRefPtr<GtkStyleContext> context = createStyleContext(widgetType);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
 
+    if (widgetType == GTK_TYPE_CHECK_BUTTON) {
+        if (theme->isChecked(renderObject) || theme->isIndeterminate(renderObject)) {
+            gtk_widget_path_append_type(path.get(), GTK_TYPE_CHECK_BUTTON);
+            gtk_widget_path_iter_set_object_name(path.get(), 0, "checkbutton");
+        } else {
+            gtk_widget_path_append_type(path.get(), GTK_TYPE_CHECK_BUTTON);
+            gtk_widget_path_iter_set_object_name(path.get(), 0, "button");
+            gtk_widget_path_iter_add_class(path.get(), 0, "check");
+        }
+
+        gtk_widget_path_append_type(path.get(), GTK_TYPE_CHECK_BUTTON);
+        gtk_widget_path_iter_set_object_name(path.get(), 1, "check");
+    } else if (widgetType == GTK_TYPE_RADIO_BUTTON) {
+        if (theme->isChecked(renderObject) || theme->isIndeterminate(renderObject)) {
+            gtk_widget_path_append_type(path.get(), GTK_TYPE_RADIO_BUTTON);
+            gtk_widget_path_iter_set_object_name(path.get(), 0, "radiobutton");
+        } else {
+            gtk_widget_path_append_type(path.get(), GTK_TYPE_RADIO_BUTTON);
+            gtk_widget_path_iter_set_object_name(path.get(), 0, "button");
+            gtk_widget_path_iter_add_class(path.get(), 0, "radio");
+        }
+
+        gtk_widget_path_append_type(path.get(), GTK_TYPE_RADIO_BUTTON);
+        gtk_widget_path_iter_set_object_name(path.get(), 1, "radio");
+    }
+
+    gtk_style_context_set_path(context.get(), path.get());
+#endif
+
     // Some themes do not render large toggle buttons properly, so we simply
     // shrink the rectangle back down to the default size and then center it
     // in the full toggle button region. The reason for not simply forcing toggle
@@ -487,7 +544,12 @@
     }
 
     gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(renderObject.style().direction())));
+
+#if GTK_CHECK_VERSION(3, 19, 2)
+    gtk_style_context_add_class(context.get(), "toggle");
+#else
     gtk_style_context_add_class(context.get(), widgetType == GTK_TYPE_CHECK_BUTTON ? GTK_STYLE_CLASS_CHECK : GTK_STYLE_CLASS_RADIO);
+#endif
 
     guint flags = 0;
     if (!theme->isEnabled(renderObject))
@@ -614,7 +676,9 @@
     GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_BUTTON);
 
     gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(renderObject.style().direction())));
+#if !GTK_CHECK_VERSION(3, 19, 2)
     gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_BUTTON);
+#endif
 
     renderButton(this, context.get(), renderObject, paintInfo, rect);
 
@@ -643,8 +707,20 @@
         return;
 
     GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_COMBO_BOX);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
 
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_COMBO_BOX);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "combobox");
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_COMBO_BOX);
+    gtk_widget_path_iter_set_object_name(path.get(), 1, "button");
+    gtk_widget_path_iter_add_class(path.get(), 1, "combo");
+
+    gtk_style_context_set_path(context.get(), path.get());
+#else
     gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_BUTTON);
+#endif
     gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(style.direction())));
 
     gtk_style_context_set_state(context.get(), static_cast<GtkStateFlags>(0));
@@ -659,7 +735,9 @@
 
     GtkTextDirection direction = static_cast<GtkTextDirection>(gtkTextDirection(style.direction()));
     gtk_style_context_set_direction(context.get(), direction);
+#if !GTK_CHECK_VERSION(3, 19, 2)
     gtk_style_context_add_class(context.get(), "separator");
+#endif
 
     gboolean wideSeparators;
     gint separatorWidth;
@@ -721,7 +799,9 @@
     // Paint the button.
     GRefPtr<GtkStyleContext> buttonStyleContext = createStyleContext(GTK_TYPE_BUTTON);
     gtk_style_context_set_direction(buttonStyleContext.get(), direction);
+#if !GTK_CHECK_VERSION(3, 19, 2)
     gtk_style_context_add_class(buttonStyleContext.get(), GTK_STYLE_CLASS_BUTTON);
+#endif
     renderButton(this, buttonStyleContext.get(), renderObject, paintInfo, rect);
 
     // Get the inner rectangle.
@@ -758,8 +838,10 @@
     GRefPtr<GtkStyleContext> arrowStyleContext = createStyleContext(GTK_TYPE_ARROW);
 
     gtk_style_context_set_direction(arrowStyleContext.get(), direction);
+#if !GTK_CHECK_VERSION(3, 19, 2)
     gtk_style_context_add_class(arrowStyleContext.get(), "arrow");
     gtk_style_context_add_class(arrowStyleContext.get(), GTK_STYLE_CLASS_BUTTON);
+#endif
 
     gfloat arrowScaling;
     gtk_style_context_get_style(arrowStyleContext.get(), "arrow-scaling", &arrowScaling, nullptr);
@@ -779,10 +861,19 @@
 
     // Paint the separator if needed.
     GRefPtr<GtkStyleContext> separatorStyleContext = createStyleContext(GTK_TYPE_COMBO_BOX);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
 
-    gtk_style_context_set_direction(separatorStyleContext.get(), direction);
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SEPARATOR);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "separator");
+
+    gtk_style_context_set_path(separatorStyleContext.get(), path.get());
+#else
     gtk_style_context_add_class(separatorStyleContext.get(), "separator");
+#endif
 
+    gtk_style_context_set_direction(separatorStyleContext.get(), direction);
+
     gboolean wideSeparators;
     gint separatorWidth;
     gtk_style_context_get_style(separatorStyleContext.get(), "wide-separators", &wideSeparators, "separator-width", &separatorWidth, nullptr);
@@ -831,7 +922,9 @@
     GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_ENTRY);
 
     gtk_style_context_set_direction(context.get(), static_cast<GtkTextDirection>(gtkTextDirection(renderObject.style().direction())));
+#if !GTK_CHECK_VERSION(3, 19, 2)
     gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_ENTRY);
+#endif
 
     guint flags = 0;
     if (!isEnabled(renderObject) || isReadOnlyControl(renderObject))
@@ -1041,7 +1134,9 @@
 
 static void applySliderStyleContextClasses(GtkStyleContext* context, ControlPart part)
 {
+#if !GTK_CHECK_VERSION(3, 19, 2)
     gtk_style_context_add_class(context, GTK_STYLE_CLASS_SCALE);
+#endif
     if (part == SliderHorizontalPart || part == SliderThumbHorizontalPart)
         gtk_style_context_add_class(context, GTK_STYLE_CLASS_HORIZONTAL);
     else if (part == SliderVerticalPart || part == SliderThumbVerticalPart)
@@ -1054,10 +1149,23 @@
     ASSERT_UNUSED(part, part == SliderHorizontalPart || part == SliderVerticalPart || part == MediaVolumeSliderPart);
 
     GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_SCALE);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
 
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "scale");
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
+    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
+
+    gtk_style_context_set_path(context.get(), path.get());
+#endif
+
     gtk_style_context_set_direction(context.get(), gtkTextDirection(renderObject.style().direction()));
     applySliderStyleContextClasses(context.get(), part);
+#if !GTK_CHECK_VERSION(3, 19, 2)
     gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_TROUGH);
+#endif
 
     if (!isEnabled(renderObject))
         gtk_style_context_set_state(context.get(), GTK_STATE_FLAG_INSENSITIVE);
@@ -1082,10 +1190,24 @@
     ASSERT(part == SliderThumbHorizontalPart || part == SliderThumbVerticalPart || part == MediaVolumeSliderThumbPart);
 
     GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_SCALE);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    // FIXME: The entire slider is too wide, stretching the thumb into an oval rather than a circle.
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
 
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "scale");
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
+    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SCALE);
+    gtk_widget_path_iter_set_object_name(path.get(), 2, "slider");
+
+    gtk_style_context_set_path(context.get(), path.get());
+#endif
+
     gtk_style_context_set_direction(context.get(), gtkTextDirection(renderObject.style().direction()));
     applySliderStyleContextClasses(context.get(), part);
-    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_SLIDER);
 
     guint flags = 0;
     if (!isEnabled(renderObject))
@@ -1127,16 +1249,42 @@
         return true;
 
     GRefPtr<GtkStyleContext> context = createStyleContext(GTK_TYPE_PROGRESS_BAR);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "progressbar");
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
+
+    gtk_style_context_set_path(context.get(), path.get());
+#else
     gtk_style_context_save(context.get());
-
     gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_TROUGH);
+#endif
 
     gtk_render_background(context.get(), paintInfo.context().platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
     gtk_render_frame(context.get(), paintInfo.context().platformContext()->cr(), rect.x(), rect.y(), rect.width(), rect.height());
 
+#if GTK_CHECK_VERSION(3, 19, 2)
+    path = adoptGRef(gtk_widget_path_new());
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "progressbar");
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 1, "trough");
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_PROGRESS_BAR);
+    gtk_widget_path_iter_set_object_name(path.get(), 2, "progress");
+
+    gtk_style_context_set_path(context.get(), path.get());
+#else
     gtk_style_context_restore(context.get());
+    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_PROGRESSBAR);
+#endif
 
-    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_PROGRESSBAR);
     gtk_style_context_set_state(context.get(), static_cast<GtkStateFlags>(0));
 
     GtkBorder padding;
@@ -1188,7 +1336,21 @@
     ASSERT(arrowType == GTK_ARROW_UP || arrowType == GTK_ARROW_DOWN);
 
     gtk_style_context_save(context);
+
+#if GTK_CHECK_VERSION(3, 19, 2)
+    GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SPIN_BUTTON);
+    gtk_widget_path_iter_set_object_name(path.get(), 0, "spinbutton");
+
+    gtk_widget_path_append_type(path.get(), GTK_TYPE_SPIN_BUTTON);
+    gtk_widget_path_iter_set_object_name(path.get(), 1, "button");
+    gtk_widget_path_iter_add_class(path.get(), 1, arrowType == GTK_ARROW_UP ? "up" : "down");
+
+    gtk_style_context_set_path(context, path.get());
+#else
     gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON);
+#endif
 
     GtkTextDirection direction = gtk_style_context_get_direction(context);
     guint state = static_cast<guint>(gtk_style_context_get_state(context));
@@ -1289,16 +1451,28 @@
 
 static Color styleColor(GType widgetType, GtkStateFlags state, StyleColorType colorType)
 {
+    GRefPtr<GtkStyleContext> context = createStyleContext(widgetType);
+#if GTK_CHECK_VERSION(3, 19, 2)
+    if (widgetType == GTK_TYPE_ENTRY) {
+        GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
 
-    GRefPtr<GtkStyleContext> context = createStyleContext(widgetType);
-    // Recent GTK+ versions (> 3.14) require to explicitly set the state before getting the color.
+        gtk_widget_path_append_type(path.get(), GTK_TYPE_ENTRY);
+        gtk_widget_path_iter_set_object_name(path.get(), 0, "entry");
+
+        gtk_widget_path_append_type(path.get(), GTK_TYPE_ENTRY);
+        gtk_widget_path_iter_set_object_name(path.get(), 1, "selection");
+
+        gtk_style_context_set_path(context.get(), path.get());
+    }
+#endif
+
     gtk_style_context_set_state(context.get(), state);
 
     GdkRGBA gdkRGBAColor;
     if (colorType == StyleColorBackground)
-        gtk_style_context_get_background_color(context.get(), gtk_style_context_get_state(context.get()), &gdkRGBAColor);
+        gtk_style_context_get_background_color(context.get(), state, &gdkRGBAColor);
     else
-        gtk_style_context_get_color(context.get(), gtk_style_context_get_state(context.get()), &gdkRGBAColor);
+        gtk_style_context_get_color(context.get(), state, &gdkRGBAColor);
     return gdkRGBAColor;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to