<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[193896] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/193896">193896</a></dd>
<dt>Author</dt> <dd>mcatanzaro@igalia.com</dd>
<dt>Date</dt> <dd>2015-12-10 02:15:36 -0800 (Thu, 10 Dec 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] RenderThemeGtk::platformActiveSelectionBackgroundColor, et. al. should not clobber state of cached GtkStyleContexts
https://bugs.webkit.org/show_bug.cgi?id=151533

Reviewed by Carlos Garcia Campos.

Remove the style context cache to simplify the code, drastically reduce the number of
expensive save/restore operations performed on style contexts, and avoid unwanted
side-effects in RenderThemeGtk::styleColor. This is also a speculative fix for improper
button rendering with certain custom themes, and a simplification that will make it easier
to fix bug #150550.

This change does have performance implications, which I intend to check on the perf bot
after landing to ensure that removing the cache does not have a significant negative impact
on performance; I have no clue whether this will be a net performance win or loss. However,
this is a bit tricky, because the bot is running GTK+ 3.16, whereas I expect save/restore
might be much more expensive in GTK+ 3.20, and I do not want to make performance decisions
except based on the latest GTK+ due to large changes in the implementation of
GtkStyleContext.

* rendering/RenderThemeGtk.cpp:
(WebCore::createStyleContext):
(WebCore::getStockIconForWidgetType):
(WebCore::getStockSymbolicIconForWidgetType):
(WebCore::RenderThemeGtk::initMediaColors):
(WebCore::RenderThemeGtk::adjustRepaintRect):
(WebCore::setToggleSize):
(WebCore::paintToggle):
(WebCore::RenderThemeGtk::setCheckboxSize):
(WebCore::RenderThemeGtk::setRadioSize):
(WebCore::RenderThemeGtk::paintButton):
(WebCore::getComboBoxMetrics):
(WebCore::RenderThemeGtk::paintMenuList):
(WebCore::RenderThemeGtk::paintTextField):
(WebCore::RenderThemeGtk::paintSliderTrack):
(WebCore::RenderThemeGtk::paintSliderThumb):
(WebCore::RenderThemeGtk::adjustSliderThumbSize):
(WebCore::RenderThemeGtk::paintProgressBar):
(WebCore::RenderThemeGtk::adjustInnerSpinButtonStyle):
(WebCore::RenderThemeGtk::paintInnerSpinButton):
(WebCore::styleColor):
(WebCore::gtkStyleChangedCallback): Deleted.
(WebCore::styleContextMap): Deleted.
(WebCore::getStyleContext): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderThemeGtkcpp">trunk/Source/WebCore/rendering/RenderThemeGtk.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (193895 => 193896)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-12-10 09:20:01 UTC (rev 193895)
+++ trunk/Source/WebCore/ChangeLog        2015-12-10 10:15:36 UTC (rev 193896)
</span><span class="lines">@@ -1,3 +1,49 @@
</span><ins>+2015-12-10  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
+
+        [GTK] RenderThemeGtk::platformActiveSelectionBackgroundColor, et. al. should not clobber state of cached GtkStyleContexts
+        https://bugs.webkit.org/show_bug.cgi?id=151533
+
+        Reviewed by Carlos Garcia Campos.
+
+        Remove the style context cache to simplify the code, drastically reduce the number of
+        expensive save/restore operations performed on style contexts, and avoid unwanted
+        side-effects in RenderThemeGtk::styleColor. This is also a speculative fix for improper
+        button rendering with certain custom themes, and a simplification that will make it easier
+        to fix bug #150550.
+
+        This change does have performance implications, which I intend to check on the perf bot
+        after landing to ensure that removing the cache does not have a significant negative impact
+        on performance; I have no clue whether this will be a net performance win or loss. However,
+        this is a bit tricky, because the bot is running GTK+ 3.16, whereas I expect save/restore
+        might be much more expensive in GTK+ 3.20, and I do not want to make performance decisions
+        except based on the latest GTK+ due to large changes in the implementation of
+        GtkStyleContext.
+
+        * rendering/RenderThemeGtk.cpp:
+        (WebCore::createStyleContext):
+        (WebCore::getStockIconForWidgetType):
+        (WebCore::getStockSymbolicIconForWidgetType):
+        (WebCore::RenderThemeGtk::initMediaColors):
+        (WebCore::RenderThemeGtk::adjustRepaintRect):
+        (WebCore::setToggleSize):
+        (WebCore::paintToggle):
+        (WebCore::RenderThemeGtk::setCheckboxSize):
+        (WebCore::RenderThemeGtk::setRadioSize):
+        (WebCore::RenderThemeGtk::paintButton):
+        (WebCore::getComboBoxMetrics):
+        (WebCore::RenderThemeGtk::paintMenuList):
+        (WebCore::RenderThemeGtk::paintTextField):
+        (WebCore::RenderThemeGtk::paintSliderTrack):
+        (WebCore::RenderThemeGtk::paintSliderThumb):
+        (WebCore::RenderThemeGtk::adjustSliderThumbSize):
+        (WebCore::RenderThemeGtk::paintProgressBar):
+        (WebCore::RenderThemeGtk::adjustInnerSpinButtonStyle):
+        (WebCore::RenderThemeGtk::paintInnerSpinButton):
+        (WebCore::styleColor):
+        (WebCore::gtkStyleChangedCallback): Deleted.
+        (WebCore::styleContextMap): Deleted.
+        (WebCore::getStyleContext): Deleted.
+
</ins><span class="cx"> 2015-12-10  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         font-variant-caps does not work if the font does not support font features
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderThemeGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderThemeGtk.cpp (193895 => 193896)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderThemeGtk.cpp        2015-12-10 09:20:01 UTC (rev 193895)
+++ trunk/Source/WebCore/rendering/RenderThemeGtk.cpp        2015-12-10 10:15:36 UTC (rev 193896)
</span><span class="lines">@@ -136,20 +136,14 @@
</span><span class="cx"> // This is the default value defined by GTK+, where it was defined as MIN_ARROW_WIDTH in gtkspinbutton.c.
</span><span class="cx"> static const int minSpinButtonArrowSize = 6;
</span><span class="cx"> 
</span><del>-typedef HashMap&lt;GType, GRefPtr&lt;GtkStyleContext&gt;&gt; StyleContextMap;
-static StyleContextMap&amp; styleContextMap();
-
</del><span class="cx"> static void gtkStyleChangedCallback(GObject*, GParamSpec*)
</span><span class="cx"> {
</span><del>-    for (const auto&amp; styleContext : styleContextMap())
-        gtk_style_context_invalidate(styleContext.value.get());
</del><span class="cx">     static_cast&lt;ScrollbarThemeGtk&amp;&gt;(ScrollbarTheme::theme()).themeChanged();
</span><span class="cx">     Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static StyleContextMap&amp; styleContextMap()
</del><ins>+static GRefPtr&lt;GtkStyleContext&gt; createStyleContext(GType widgetType)
</ins><span class="cx"> {
</span><del>-    static NeverDestroyed&lt;StyleContextMap&gt; map;
</del><span class="cx">     static bool initialized = false;
</span><span class="cx">     if (!initialized) {
</span><span class="cx">         GtkSettings* settings = gtk_settings_get_default();
</span><span class="lines">@@ -157,15 +151,7 @@
</span><span class="cx">         g_signal_connect(settings, &quot;notify::gtk-color-scheme&quot;, G_CALLBACK(gtkStyleChangedCallback), nullptr);
</span><span class="cx">         initialized = true;
</span><span class="cx">     }
</span><del>-    return map;
-}
</del><span class="cx"> 
</span><del>-static GtkStyleContext* getStyleContext(GType widgetType)
-{
-    StyleContextMap::AddResult result = styleContextMap().add(widgetType, nullptr);
-    if (!result.isNewEntry)
-        return result.iterator-&gt;value.get();
-
</del><span class="cx">     GtkWidgetPath* path = gtk_widget_path_new();
</span><span class="cx">     gtk_widget_path_append_type(path, widgetType);
</span><span class="cx"> 
</span><span class="lines">@@ -195,57 +181,48 @@
</span><span class="cx">     gtk_style_context_set_path(context.get(), path);
</span><span class="cx">     gtk_widget_path_free(path);
</span><span class="cx"> 
</span><del>-    result.iterator-&gt;value = context;
-    return context.get();
</del><ins>+    return context;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static GRefPtr&lt;GdkPixbuf&gt; getStockIconForWidgetType(GType widgetType, const char* iconName, gint direction, gint state, gint iconSize)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(iconName);
</span><span class="cx"> 
</span><del>-    GtkStyleContext* context = getStyleContext(widgetType);
-    GtkIconSet* iconSet = gtk_style_context_lookup_icon_set(context, iconName);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(widgetType);
+    GtkIconSet* iconSet = gtk_style_context_lookup_icon_set(context.get(), iconName);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_save(context);
-
</del><span class="cx">     guint flags = 0;
</span><span class="cx">     if (state == GTK_STATE_PRELIGHT)
</span><span class="cx">         flags |= GTK_STATE_FLAG_PRELIGHT;
</span><span class="cx">     else if (state == GTK_STATE_INSENSITIVE)
</span><span class="cx">         flags |= GTK_STATE_FLAG_INSENSITIVE;
</span><span class="cx"> 
</span><del>-    gtk_style_context_set_state(context, static_cast&lt;GtkStateFlags&gt;(flags));
-    gtk_style_context_set_direction(context, static_cast&lt;GtkTextDirection&gt;(direction));
-    GdkPixbuf* icon = gtk_icon_set_render_icon_pixbuf(iconSet, context, static_cast&lt;GtkIconSize&gt;(iconSize));
</del><ins>+    gtk_style_context_set_state(context.get(), static_cast&lt;GtkStateFlags&gt;(flags));
+    gtk_style_context_set_direction(context.get(), static_cast&lt;GtkTextDirection&gt;(direction));
+    GdkPixbuf* icon = gtk_icon_set_render_icon_pixbuf(iconSet, context.get(), static_cast&lt;GtkIconSize&gt;(iconSize));
</ins><span class="cx"> 
</span><del>-    gtk_style_context_restore(context);
-
</del><span class="cx">     return adoptGRef(icon);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static GRefPtr&lt;GdkPixbuf&gt; getStockSymbolicIconForWidgetType(GType widgetType, const char* symbolicIconName, const char* fallbackStockIconName, gint direction, gint state, gint iconSize)
</span><span class="cx"> {
</span><del>-    GtkStyleContext* context = getStyleContext(widgetType);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(widgetType);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_save(context);
-
</del><span class="cx">     guint flags = 0;
</span><span class="cx">     if (state == GTK_STATE_PRELIGHT)
</span><span class="cx">         flags |= GTK_STATE_FLAG_PRELIGHT;
</span><span class="cx">     else if (state == GTK_STATE_INSENSITIVE)
</span><span class="cx">         flags |= GTK_STATE_FLAG_INSENSITIVE;
</span><span class="cx"> 
</span><del>-    gtk_style_context_set_state(context, static_cast&lt;GtkStateFlags&gt;(flags));
-    gtk_style_context_set_direction(context, static_cast&lt;GtkTextDirection&gt;(direction));
</del><ins>+    gtk_style_context_set_state(context.get(), static_cast&lt;GtkStateFlags&gt;(flags));
+    gtk_style_context_set_direction(context.get(), static_cast&lt;GtkTextDirection&gt;(direction));
</ins><span class="cx"> 
</span><span class="cx">     GUniquePtr&lt;GtkIconInfo&gt; info(gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), symbolicIconName, iconSize,
</span><span class="cx">         static_cast&lt;GtkIconLookupFlags&gt;(GTK_ICON_LOOKUP_FORCE_SVG | GTK_ICON_LOOKUP_FORCE_SIZE)));
</span><span class="cx">     GdkPixbuf* icon = nullptr;
</span><span class="cx">     if (info)
</span><del>-        icon = gtk_icon_info_load_symbolic_for_context(info.get(), context, nullptr, nullptr);
</del><ins>+        icon = gtk_icon_info_load_symbolic_for_context(info.get(), context.get(), nullptr, nullptr);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_restore(context);
-
</del><span class="cx">     if (!icon) {
</span><span class="cx">         if (!fallbackStockIconName)
</span><span class="cx">             return nullptr;
</span><span class="lines">@@ -271,21 +248,17 @@
</span><span class="cx"> void RenderThemeGtk::initMediaColors()
</span><span class="cx"> {
</span><span class="cx">     GdkRGBA color;
</span><del>-    GtkStyleContext* containerContext = getStyleContext(GTK_TYPE_CONTAINER);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; containerContext = createStyleContext(GTK_TYPE_CONTAINER);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_save(containerContext);
-
-    gtk_style_context_set_state(containerContext, GTK_STATE_FLAG_NORMAL);
-    gtk_style_context_get_background_color(containerContext, gtk_style_context_get_state(containerContext), &amp;color);
</del><ins>+    gtk_style_context_set_state(containerContext.get(), GTK_STATE_FLAG_NORMAL);
+    gtk_style_context_get_background_color(containerContext.get(), gtk_style_context_get_state(containerContext.get()), &amp;color);
</ins><span class="cx">     m_panelColor = color;
</span><del>-    gtk_style_context_set_state(containerContext, GTK_STATE_FLAG_ACTIVE);
-    gtk_style_context_get_background_color(containerContext, gtk_style_context_get_state(containerContext), &amp;color);
</del><ins>+    gtk_style_context_set_state(containerContext.get(), GTK_STATE_FLAG_ACTIVE);
+    gtk_style_context_get_background_color(containerContext.get(), gtk_style_context_get_state(containerContext.get()), &amp;color);
</ins><span class="cx">     m_sliderColor = color;
</span><del>-    gtk_style_context_set_state(containerContext, GTK_STATE_FLAG_SELECTED);
-    gtk_style_context_get_background_color(containerContext, gtk_style_context_get_state(containerContext), &amp;color);
</del><ins>+    gtk_style_context_set_state(containerContext.get(), GTK_STATE_FLAG_SELECTED);
+    gtk_style_context_get_background_color(containerContext.get(), gtk_style_context_get_state(containerContext.get()), &amp;color);
</ins><span class="cx">     m_sliderThumbColor = color;
</span><del>-
-    gtk_style_context_restore(containerContext);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void RenderThemeGtk::initMediaButtons()
</span><span class="lines">@@ -422,32 +395,32 @@
</span><span class="cx"> 
</span><span class="cx"> void RenderThemeGtk::adjustRepaintRect(const RenderObject&amp; renderObject, FloatRect&amp; rect)
</span><span class="cx"> {
</span><del>-    GtkStyleContext* context = 0;
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context;
</ins><span class="cx">     bool checkInteriorFocus = false;
</span><span class="cx">     ControlPart part = renderObject.style().appearance();
</span><span class="cx">     switch (part) {
</span><span class="cx">     case CheckboxPart:
</span><span class="cx">     case RadioPart:
</span><del>-        context = getStyleContext(part == CheckboxPart ? GTK_TYPE_CHECK_BUTTON : GTK_TYPE_RADIO_BUTTON);
</del><ins>+        context = createStyleContext(part == CheckboxPart ? GTK_TYPE_CHECK_BUTTON : GTK_TYPE_RADIO_BUTTON);
</ins><span class="cx"> 
</span><span class="cx">         gint indicatorSpacing;
</span><del>-        gtk_style_context_get_style(context, &quot;indicator-spacing&quot;, &amp;indicatorSpacing, nullptr);
</del><ins>+        gtk_style_context_get_style(context.get(), &quot;indicator-spacing&quot;, &amp;indicatorSpacing, nullptr);
</ins><span class="cx">         rect.inflate(indicatorSpacing);
</span><span class="cx"> 
</span><span class="cx">         return;
</span><span class="cx">     case SliderVerticalPart:
</span><span class="cx">     case SliderHorizontalPart:
</span><del>-        context = getStyleContext(GTK_TYPE_SCALE);
</del><ins>+        context = createStyleContext(GTK_TYPE_SCALE);
</ins><span class="cx">         break;
</span><span class="cx">     case ButtonPart:
</span><span class="cx">     case MenulistButtonPart:
</span><span class="cx">     case MenulistPart:
</span><del>-        context = getStyleContext(GTK_TYPE_BUTTON);
</del><ins>+        context = createStyleContext(GTK_TYPE_BUTTON);
</ins><span class="cx">         checkInteriorFocus = true;
</span><span class="cx">         break;
</span><span class="cx">     case TextFieldPart:
</span><span class="cx">     case TextAreaPart:
</span><del>-        context = getStyleContext(GTK_TYPE_ENTRY);
</del><ins>+        context = createStyleContext(GTK_TYPE_ENTRY);
</ins><span class="cx">         checkInteriorFocus = true;
</span><span class="cx">         break;
</span><span class="cx">     default:
</span><span class="lines">@@ -457,11 +430,11 @@
</span><span class="cx">     ASSERT(context);
</span><span class="cx">     if (checkInteriorFocus) {
</span><span class="cx">         gboolean interiorFocus;
</span><del>-        gtk_style_context_get_style(context, &quot;interior-focus&quot;, &amp;interiorFocus, nullptr);
</del><ins>+        gtk_style_context_get_style(context.get(), &quot;interior-focus&quot;, &amp;interiorFocus, nullptr);
</ins><span class="cx">         if (interiorFocus)
</span><span class="cx">             return;
</span><span class="cx">     }
</span><del>-    adjustRectForFocus(context, rect);
</del><ins>+    adjustRectForFocus(context.get(), rect);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void RenderThemeGtk::adjustButtonStyle(StyleResolver&amp;, RenderStyle&amp; style, Element*) const
</span><span class="lines">@@ -471,8 +444,10 @@
</span><span class="cx">         style.setLineHeight(RenderStyle::initialLineHeight());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void setToggleSize(GtkStyleContext* context, RenderStyle&amp; style)
</del><ins>+static void setToggleSize(GType widgetType, RenderStyle&amp; style)
</ins><span class="cx"> {
</span><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(widgetType);
+
</ins><span class="cx">     // The width and height are both specified, so we shouldn't change them.
</span><span class="cx">     if (!style.width().isIntrinsicOrAuto() &amp;&amp; !style.height().isAuto())
</span><span class="cx">         return;
</span><span class="lines">@@ -481,7 +456,7 @@
</span><span class="cx">     // GTK+ users tend to demand the native look.
</span><span class="cx">     // It could be made a configuration option values other than 13 actually break site compatibility.
</span><span class="cx">     gint indicatorSize;
</span><del>-    gtk_style_context_get_style(context, &quot;indicator-size&quot;, &amp;indicatorSize, nullptr);
</del><ins>+    gtk_style_context_get_style(context.get(), &quot;indicator-size&quot;, &amp;indicatorSize, nullptr);
</ins><span class="cx"> 
</span><span class="cx">     if (style.width().isIntrinsicOrAuto())
</span><span class="cx">         style.setWidth(Length(indicatorSize, Fixed));
</span><span class="lines">@@ -492,15 +467,14 @@
</span><span class="cx"> 
</span><span class="cx"> static void paintToggle(const RenderThemeGtk* theme, GType widgetType, const RenderObject&amp; renderObject, const PaintInfo&amp; paintInfo, const IntRect&amp; fullRect)
</span><span class="cx"> {
</span><del>-    GtkStyleContext* context = getStyleContext(widgetType);
-    gtk_style_context_save(context);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(widgetType);
</ins><span class="cx"> 
</span><span class="cx">     // Some themes do not render large toggle buttons properly, so we simply
</span><span class="cx">     // shrink the rectangle back down to the default size and then center it
</span><span class="cx">     // in the full toggle button region. The reason for not simply forcing toggle
</span><span class="cx">     // buttons to be a smaller size is that we don't want to break site layouts.
</span><span class="cx">     gint indicatorSize;
</span><del>-    gtk_style_context_get_style(context, &quot;indicator-size&quot;, &amp;indicatorSize, nullptr);
</del><ins>+    gtk_style_context_get_style(context.get(), &quot;indicator-size&quot;, &amp;indicatorSize, nullptr);
</ins><span class="cx">     IntRect rect(fullRect);
</span><span class="cx">     if (rect.width() &gt; indicatorSize) {
</span><span class="cx">         rect.inflateX(-(rect.width() - indicatorSize) / 2);
</span><span class="lines">@@ -512,8 +486,8 @@
</span><span class="cx">         rect.setHeight(indicatorSize); // In case rect.height() was equal to indicatorSize + 1.
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    gtk_style_context_set_direction(context, static_cast&lt;GtkTextDirection&gt;(gtkTextDirection(renderObject.style().direction())));
-    gtk_style_context_add_class(context, widgetType == GTK_TYPE_CHECK_BUTTON ? GTK_STYLE_CLASS_CHECK : GTK_STYLE_CLASS_RADIO);
</del><ins>+    gtk_style_context_set_direction(context.get(), static_cast&lt;GtkTextDirection&gt;(gtkTextDirection(renderObject.style().direction())));
+    gtk_style_context_add_class(context.get(), widgetType == GTK_TYPE_CHECK_BUTTON ? GTK_STYLE_CLASS_CHECK : GTK_STYLE_CLASS_RADIO);
</ins><span class="cx"> 
</span><span class="cx">     guint flags = 0;
</span><span class="cx">     if (!theme-&gt;isEnabled(renderObject))
</span><span class="lines">@@ -530,28 +504,26 @@
</span><span class="cx"> #endif
</span><span class="cx">     if (theme-&gt;isPressed(renderObject))
</span><span class="cx">         flags |= GTK_STATE_FLAG_SELECTED;
</span><del>-    gtk_style_context_set_state(context, static_cast&lt;GtkStateFlags&gt;(flags));
</del><ins>+    gtk_style_context_set_state(context.get(), static_cast&lt;GtkStateFlags&gt;(flags));
</ins><span class="cx"> 
</span><span class="cx">     if (widgetType == GTK_TYPE_CHECK_BUTTON)
</span><del>-        gtk_render_check(context, paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
</del><ins>+        gtk_render_check(context.get(), paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
</ins><span class="cx">     else
</span><del>-        gtk_render_option(context, paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
</del><ins>+        gtk_render_option(context.get(), paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
</ins><span class="cx"> 
</span><span class="cx">     if (theme-&gt;isFocused(renderObject)) {
</span><span class="cx">         IntRect indicatorRect(rect);
</span><span class="cx">         gint indicatorSpacing;
</span><del>-        gtk_style_context_get_style(context, &quot;indicator-spacing&quot;, &amp;indicatorSpacing, nullptr);
</del><ins>+        gtk_style_context_get_style(context.get(), &quot;indicator-spacing&quot;, &amp;indicatorSpacing, nullptr);
</ins><span class="cx">         indicatorRect.inflate(indicatorSpacing);
</span><del>-        gtk_render_focus(context, paintInfo.context().platformContext()-&gt;cr(), indicatorRect.x(), indicatorRect.y(),
</del><ins>+        gtk_render_focus(context.get(), paintInfo.context().platformContext()-&gt;cr(), indicatorRect.x(), indicatorRect.y(),
</ins><span class="cx">             indicatorRect.width(), indicatorRect.height());
</span><span class="cx">     }
</span><del>-
-    gtk_style_context_restore(context);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void RenderThemeGtk::setCheckboxSize(RenderStyle&amp; style) const
</span><span class="cx"> {
</span><del>-    setToggleSize(getStyleContext(GTK_TYPE_CHECK_BUTTON), style);
</del><ins>+    setToggleSize(GTK_TYPE_CHECK_BUTTON, style);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool RenderThemeGtk::paintCheckbox(const RenderObject&amp; renderObject, const PaintInfo&amp; paintInfo, const IntRect&amp; rect)
</span><span class="lines">@@ -562,7 +534,7 @@
</span><span class="cx"> 
</span><span class="cx"> void RenderThemeGtk::setRadioSize(RenderStyle&amp; style) const
</span><span class="cx"> {
</span><del>-    setToggleSize(getStyleContext(GTK_TYPE_RADIO_BUTTON), style);
</del><ins>+    setToggleSize(GTK_TYPE_RADIO_BUTTON, style);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool RenderThemeGtk::paintRadio(const RenderObject&amp; renderObject, const PaintInfo&amp; paintInfo, const IntRect&amp; rect)
</span><span class="lines">@@ -639,16 +611,13 @@
</span><span class="cx"> }
</span><span class="cx"> bool RenderThemeGtk::paintButton(const RenderObject&amp; renderObject, const PaintInfo&amp; paintInfo, const IntRect&amp; rect)
</span><span class="cx"> {
</span><del>-    GtkStyleContext* context = getStyleContext(GTK_TYPE_BUTTON);
-    gtk_style_context_save(context);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(GTK_TYPE_BUTTON);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_set_direction(context, static_cast&lt;GtkTextDirection&gt;(gtkTextDirection(renderObject.style().direction())));
-    gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON);
</del><ins>+    gtk_style_context_set_direction(context.get(), static_cast&lt;GtkTextDirection&gt;(gtkTextDirection(renderObject.style().direction())));
+    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_BUTTON);
</ins><span class="cx"> 
</span><del>-    renderButton(this, context, renderObject, paintInfo, rect);
</del><ins>+    renderButton(this, context.get(), renderObject, paintInfo, rect);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_restore(context);
-
</del><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -673,40 +642,34 @@
</span><span class="cx">     if (style.appearance() == NoControlPart)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    GtkStyleContext* context = getStyleContext(GTK_TYPE_COMBO_BOX);
-    gtk_style_context_save(context);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(GTK_TYPE_COMBO_BOX);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON);
-    gtk_style_context_set_direction(context, static_cast&lt;GtkTextDirection&gt;(gtkTextDirection(style.direction())));
</del><ins>+    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_BUTTON);
+    gtk_style_context_set_direction(context.get(), static_cast&lt;GtkTextDirection&gt;(gtkTextDirection(style.direction())));
</ins><span class="cx"> 
</span><del>-    gtk_style_context_set_state(context, static_cast&lt;GtkStateFlags&gt;(0));
-    gtk_style_context_get_border(context, gtk_style_context_get_state(context), &amp;border);
</del><ins>+    gtk_style_context_set_state(context.get(), static_cast&lt;GtkStateFlags&gt;(0));
+    gtk_style_context_get_border(context.get(), gtk_style_context_get_state(context.get()), &amp;border);
</ins><span class="cx"> 
</span><span class="cx">     gboolean interiorFocus;
</span><span class="cx">     gint focusWidth, focusPad;
</span><del>-    gtk_style_context_get_style(context, &quot;interior-focus&quot;, &amp;interiorFocus, &quot;focus-line-width&quot;, &amp;focusWidth, &quot;focus-padding&quot;, &amp;focusPad, nullptr);
</del><ins>+    gtk_style_context_get_style(context.get(), &quot;interior-focus&quot;, &amp;interiorFocus, &quot;focus-line-width&quot;, &amp;focusWidth, &quot;focus-padding&quot;, &amp;focusPad, nullptr);
</ins><span class="cx">     focus = interiorFocus ? focusWidth + focusPad : 0;
</span><span class="cx"> 
</span><del>-    gtk_style_context_restore(context);
</del><ins>+    context = createStyleContext(GTK_TYPE_SEPARATOR);
</ins><span class="cx"> 
</span><del>-    context = getStyleContext(GTK_TYPE_SEPARATOR);
-    gtk_style_context_save(context);
-
</del><span class="cx">     GtkTextDirection direction = static_cast&lt;GtkTextDirection&gt;(gtkTextDirection(style.direction()));
</span><del>-    gtk_style_context_set_direction(context, direction);
-    gtk_style_context_add_class(context, &quot;separator&quot;);
</del><ins>+    gtk_style_context_set_direction(context.get(), direction);
+    gtk_style_context_add_class(context.get(), &quot;separator&quot;);
</ins><span class="cx"> 
</span><span class="cx">     gboolean wideSeparators;
</span><span class="cx">     gint separatorWidth;
</span><del>-    gtk_style_context_get_style(context, &quot;wide-separators&quot;, &amp;wideSeparators, &quot;separator-width&quot;, &amp;separatorWidth, nullptr);
</del><ins>+    gtk_style_context_get_style(context.get(), &quot;wide-separators&quot;, &amp;wideSeparators, &quot;separator-width&quot;, &amp;separatorWidth, nullptr);
</ins><span class="cx"> 
</span><span class="cx">     // GTK+ always uses border.left, regardless of text direction. See gtkseperator.c.
</span><span class="cx">     if (!wideSeparators)
</span><span class="cx">         separatorWidth = border.left;
</span><span class="cx"> 
</span><span class="cx">     separator = separatorWidth;
</span><del>-
-    gtk_style_context_restore(context);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> int RenderThemeGtk::popupInternalPaddingLeft(RenderStyle&amp; style) const
</span><span class="lines">@@ -756,25 +719,24 @@
</span><span class="cx">     GtkTextDirection direction = static_cast&lt;GtkTextDirection&gt;(gtkTextDirection(renderObject.style().direction()));
</span><span class="cx"> 
</span><span class="cx">     // Paint the button.
</span><del>-    GtkStyleContext* buttonStyleContext = getStyleContext(GTK_TYPE_BUTTON);
-    gtk_style_context_save(buttonStyleContext);
-    gtk_style_context_set_direction(buttonStyleContext, direction);
-    gtk_style_context_add_class(buttonStyleContext, GTK_STYLE_CLASS_BUTTON);
-    renderButton(this, buttonStyleContext, renderObject, paintInfo, rect);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; buttonStyleContext = createStyleContext(GTK_TYPE_BUTTON);
+    gtk_style_context_set_direction(buttonStyleContext.get(), direction);
+    gtk_style_context_add_class(buttonStyleContext.get(), GTK_STYLE_CLASS_BUTTON);
+    renderButton(this, buttonStyleContext.get(), renderObject, paintInfo, rect);
</ins><span class="cx"> 
</span><span class="cx">     // Get the inner rectangle.
</span><span class="cx">     gint focusWidth, focusPad;
</span><span class="cx">     GtkBorder* innerBorderPtr = 0;
</span><span class="cx">     GtkBorder innerBorder = { 1, 1, 1, 1 };
</span><del>-    gtk_style_context_get_style(buttonStyleContext, &quot;inner-border&quot;, &amp;innerBorderPtr, &quot;focus-line-width&quot;, &amp;focusWidth, &quot;focus-padding&quot;, &amp;focusPad, nullptr);
</del><ins>+    gtk_style_context_get_style(buttonStyleContext.get(), &quot;inner-border&quot;, &amp;innerBorderPtr, &quot;focus-line-width&quot;, &amp;focusWidth, &quot;focus-padding&quot;, &amp;focusPad, nullptr);
</ins><span class="cx">     if (innerBorderPtr) {
</span><span class="cx">         innerBorder = *innerBorderPtr;
</span><span class="cx">         gtk_border_free(innerBorderPtr);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     GtkBorder borderWidth;
</span><del>-    GtkStateFlags state = gtk_style_context_get_state(buttonStyleContext);
-    gtk_style_context_get_border(buttonStyleContext, state, &amp;borderWidth);
</del><ins>+    GtkStateFlags state = gtk_style_context_get_state(buttonStyleContext.get());
+    gtk_style_context_get_border(buttonStyleContext.get(), state, &amp;borderWidth);
</ins><span class="cx"> 
</span><span class="cx">     focusWidth += focusPad;
</span><span class="cx">     IntRect innerRect(
</span><span class="lines">@@ -786,24 +748,21 @@
</span><span class="cx">     if (isPressed(renderObject)) {
</span><span class="cx">         gint childDisplacementX;
</span><span class="cx">         gint childDisplacementY;
</span><del>-        gtk_style_context_get_style(buttonStyleContext, &quot;child-displacement-x&quot;, &amp;childDisplacementX, &quot;child-displacement-y&quot;, &amp;childDisplacementY, nullptr);
</del><ins>+        gtk_style_context_get_style(buttonStyleContext.get(), &quot;child-displacement-x&quot;, &amp;childDisplacementX, &quot;child-displacement-y&quot;, &amp;childDisplacementY, nullptr);
</ins><span class="cx">         innerRect.move(childDisplacementX, childDisplacementY);
</span><span class="cx">     }
</span><span class="cx">     innerRect.setWidth(std::max(1, innerRect.width()));
</span><span class="cx">     innerRect.setHeight(std::max(1, innerRect.height()));
</span><span class="cx"> 
</span><del>-    gtk_style_context_restore(buttonStyleContext);
-
</del><span class="cx">     // Paint the arrow.
</span><del>-    GtkStyleContext* arrowStyleContext = getStyleContext(GTK_TYPE_ARROW);
-    gtk_style_context_save(arrowStyleContext);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; arrowStyleContext = createStyleContext(GTK_TYPE_ARROW);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_set_direction(arrowStyleContext, direction);
-    gtk_style_context_add_class(arrowStyleContext, &quot;arrow&quot;);
-    gtk_style_context_add_class(arrowStyleContext, GTK_STYLE_CLASS_BUTTON);
</del><ins>+    gtk_style_context_set_direction(arrowStyleContext.get(), direction);
+    gtk_style_context_add_class(arrowStyleContext.get(), &quot;arrow&quot;);
+    gtk_style_context_add_class(arrowStyleContext.get(), GTK_STYLE_CLASS_BUTTON);
</ins><span class="cx"> 
</span><span class="cx">     gfloat arrowScaling;
</span><del>-    gtk_style_context_get_style(arrowStyleContext, &quot;arrow-scaling&quot;, &amp;arrowScaling, nullptr);
</del><ins>+    gtk_style_context_get_style(arrowStyleContext.get(), &quot;arrow-scaling&quot;, &amp;arrowScaling, nullptr);
</ins><span class="cx"> 
</span><span class="cx">     IntSize arrowSize(minArrowSize, innerRect.height());
</span><span class="cx">     FloatPoint arrowPosition(innerRect.location());
</span><span class="lines">@@ -815,27 +774,22 @@
</span><span class="cx">     gint extent = std::min(arrowSize.width(), arrowSize.height()) * arrowScaling;
</span><span class="cx">     arrowPosition.move((arrowSize.width() - extent) / 2, (arrowSize.height() - extent) / 2);
</span><span class="cx"> 
</span><del>-    gtk_style_context_set_state(arrowStyleContext, state);
-    gtk_render_arrow(arrowStyleContext, cairoContext, G_PI, arrowPosition.x(), arrowPosition.y(), extent);
</del><ins>+    gtk_style_context_set_state(arrowStyleContext.get(), state);
+    gtk_render_arrow(arrowStyleContext.get(), cairoContext, G_PI, arrowPosition.x(), arrowPosition.y(), extent);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_restore(arrowStyleContext);
-
</del><span class="cx">     // Paint the separator if needed.
</span><del>-    GtkStyleContext* separatorStyleContext = getStyleContext(GTK_TYPE_COMBO_BOX);
-    gtk_style_context_save(separatorStyleContext);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; separatorStyleContext = createStyleContext(GTK_TYPE_COMBO_BOX);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_set_direction(separatorStyleContext, direction);
-    gtk_style_context_add_class(separatorStyleContext, &quot;separator&quot;);
</del><ins>+    gtk_style_context_set_direction(separatorStyleContext.get(), direction);
+    gtk_style_context_add_class(separatorStyleContext.get(), &quot;separator&quot;);
</ins><span class="cx"> 
</span><span class="cx">     gboolean wideSeparators;
</span><span class="cx">     gint separatorWidth;
</span><del>-    gtk_style_context_get_style(separatorStyleContext, &quot;wide-separators&quot;, &amp;wideSeparators, &quot;separator-width&quot;, &amp;separatorWidth, nullptr);
-    if (wideSeparators &amp;&amp; !separatorWidth) {
-        gtk_style_context_restore(separatorStyleContext);
</del><ins>+    gtk_style_context_get_style(separatorStyleContext.get(), &quot;wide-separators&quot;, &amp;wideSeparators, &quot;separator-width&quot;, &amp;separatorWidth, nullptr);
+    if (wideSeparators &amp;&amp; !separatorWidth)
</ins><span class="cx">         return false;
</span><del>-    }
</del><span class="cx"> 
</span><del>-    gtk_style_context_set_state(separatorStyleContext, state);
</del><ins>+    gtk_style_context_set_state(separatorStyleContext.get(), state);
</ins><span class="cx">     IntPoint separatorPosition(arrowPosition.x(), innerRect.y());
</span><span class="cx">     if (wideSeparators) {
</span><span class="cx">         if (direction == GTK_TEXT_DIR_LTR)
</span><span class="lines">@@ -843,12 +797,12 @@
</span><span class="cx">         else
</span><span class="cx">             separatorPosition.move(arrowSize.width(), 0);
</span><span class="cx"> 
</span><del>-        gtk_render_frame(separatorStyleContext, cairoContext, separatorPosition.x(), separatorPosition.y(), separatorWidth, innerRect.height());
</del><ins>+        gtk_render_frame(separatorStyleContext.get(), cairoContext, separatorPosition.x(), separatorPosition.y(), separatorWidth, innerRect.height());
</ins><span class="cx">     } else {
</span><span class="cx">         GtkBorder padding;
</span><del>-        gtk_style_context_get_padding(separatorStyleContext, gtk_style_context_get_state(separatorStyleContext), &amp;padding);
</del><ins>+        gtk_style_context_get_padding(separatorStyleContext.get(), gtk_style_context_get_state(separatorStyleContext.get()), &amp;padding);
</ins><span class="cx">         GtkBorder border;
</span><del>-        gtk_style_context_get_border(separatorStyleContext, gtk_style_context_get_state(separatorStyleContext), &amp;border);
</del><ins>+        gtk_style_context_get_border(separatorStyleContext.get(), gtk_style_context_get_state(separatorStyleContext.get()), &amp;border);
</ins><span class="cx"> 
</span><span class="cx">         if (direction == GTK_TEXT_DIR_LTR)
</span><span class="cx">             separatorPosition.move(-(padding.left + border.left), 0);
</span><span class="lines">@@ -860,11 +814,10 @@
</span><span class="cx">         // An extra clip prevents the separator bleeding outside of the specified rectangle because of subpixel positioning.
</span><span class="cx">         cairo_rectangle(cairoContext, separatorPosition.x(), separatorPosition.y(), border.left, innerRect.height());
</span><span class="cx">         cairo_clip(cairoContext);
</span><del>-        gtk_render_line(separatorStyleContext, cairoContext, separatorPosition.x(), separatorPosition.y(), separatorPosition.x(), innerRect.maxY());
</del><ins>+        gtk_render_line(separatorStyleContext.get(), cairoContext, separatorPosition.x(), separatorPosition.y(), separatorPosition.x(), innerRect.maxY());
</ins><span class="cx">         cairo_restore(cairoContext);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    gtk_style_context_restore(separatorStyleContext);
</del><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -875,35 +828,32 @@
</span><span class="cx"> 
</span><span class="cx"> bool RenderThemeGtk::paintTextField(const RenderObject&amp; renderObject, const PaintInfo&amp; paintInfo, const FloatRect&amp; rect)
</span><span class="cx"> {
</span><del>-    GtkStyleContext* context = getStyleContext(GTK_TYPE_ENTRY);
-    gtk_style_context_save(context);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(GTK_TYPE_ENTRY);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_set_direction(context, static_cast&lt;GtkTextDirection&gt;(gtkTextDirection(renderObject.style().direction())));
-    gtk_style_context_add_class(context, GTK_STYLE_CLASS_ENTRY);
</del><ins>+    gtk_style_context_set_direction(context.get(), static_cast&lt;GtkTextDirection&gt;(gtkTextDirection(renderObject.style().direction())));
+    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_ENTRY);
</ins><span class="cx"> 
</span><span class="cx">     guint flags = 0;
</span><span class="cx">     if (!isEnabled(renderObject) || isReadOnlyControl(renderObject))
</span><span class="cx">         flags |= GTK_STATE_FLAG_INSENSITIVE;
</span><span class="cx">     else if (isFocused(renderObject))
</span><span class="cx">         flags |= GTK_STATE_FLAG_FOCUSED;
</span><del>-    gtk_style_context_set_state(context, static_cast&lt;GtkStateFlags&gt;(flags));
</del><ins>+    gtk_style_context_set_state(context.get(), static_cast&lt;GtkStateFlags&gt;(flags));
</ins><span class="cx"> 
</span><del>-    gtk_render_background(context, paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
-    gtk_render_frame(context, paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
</del><ins>+    gtk_render_background(context.get(), paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
+    gtk_render_frame(context.get(), paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
</ins><span class="cx"> 
</span><span class="cx">     if (isFocused(renderObject) &amp;&amp; isEnabled(renderObject)) {
</span><span class="cx">         gboolean interiorFocus;
</span><span class="cx">         gint focusWidth, focusPad;
</span><del>-        gtk_style_context_get_style(context, &quot;interior-focus&quot;, &amp;interiorFocus, &quot;focus-line-width&quot;, &amp;focusWidth, &quot;focus-padding&quot;, &amp;focusPad, nullptr);
</del><ins>+        gtk_style_context_get_style(context.get(), &quot;interior-focus&quot;, &amp;interiorFocus, &quot;focus-line-width&quot;, &amp;focusWidth, &quot;focus-padding&quot;, &amp;focusPad, nullptr);
</ins><span class="cx">         if (!interiorFocus) {
</span><span class="cx">             IntRect focusRect(rect);
</span><span class="cx">             focusRect.inflate(focusWidth + focusPad);
</span><del>-            gtk_render_focus(context, paintInfo.context().platformContext()-&gt;cr(), focusRect.x(), focusRect.y(), focusRect.width(), focusRect.height());
</del><ins>+            gtk_render_focus(context.get(), paintInfo.context().platformContext()-&gt;cr(), focusRect.x(), focusRect.y(), focusRect.width(), focusRect.height());
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    gtk_style_context_restore(context);
-
</del><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1103,28 +1053,26 @@
</span><span class="cx">     ControlPart part = renderObject.style().appearance();
</span><span class="cx">     ASSERT_UNUSED(part, part == SliderHorizontalPart || part == SliderVerticalPart || part == MediaVolumeSliderPart);
</span><span class="cx"> 
</span><del>-    GtkStyleContext* context = getStyleContext(GTK_TYPE_SCALE);
-    gtk_style_context_save(context);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(GTK_TYPE_SCALE);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_set_direction(context, gtkTextDirection(renderObject.style().direction()));
-    applySliderStyleContextClasses(context, part);
-    gtk_style_context_add_class(context, GTK_STYLE_CLASS_TROUGH);
</del><ins>+    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_TROUGH);
</ins><span class="cx"> 
</span><span class="cx">     if (!isEnabled(renderObject))
</span><del>-        gtk_style_context_set_state(context, GTK_STATE_FLAG_INSENSITIVE);
</del><ins>+        gtk_style_context_set_state(context.get(), GTK_STATE_FLAG_INSENSITIVE);
</ins><span class="cx"> 
</span><del>-    gtk_render_background(context, paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
-    gtk_render_frame(context, paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
</del><ins>+    gtk_render_background(context.get(), paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
+    gtk_render_frame(context.get(), paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
</ins><span class="cx"> 
</span><span class="cx">     if (isFocused(renderObject)) {
</span><span class="cx">         gint focusWidth, focusPad;
</span><del>-        gtk_style_context_get_style(context, &quot;focus-line-width&quot;, &amp;focusWidth, &quot;focus-padding&quot;, &amp;focusPad, nullptr);
</del><ins>+        gtk_style_context_get_style(context.get(), &quot;focus-line-width&quot;, &amp;focusWidth, &quot;focus-padding&quot;, &amp;focusPad, nullptr);
</ins><span class="cx">         IntRect focusRect(rect);
</span><span class="cx">         focusRect.inflate(focusWidth + focusPad);
</span><del>-        gtk_render_focus(context, paintInfo.context().platformContext()-&gt;cr(), focusRect.x(), focusRect.y(), focusRect.width(), focusRect.height());
</del><ins>+        gtk_render_focus(context.get(), paintInfo.context().platformContext()-&gt;cr(), focusRect.x(), focusRect.y(), focusRect.width(), focusRect.height());
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    gtk_style_context_restore(context);
</del><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1133,12 +1081,11 @@
</span><span class="cx">     ControlPart part = renderObject.style().appearance();
</span><span class="cx">     ASSERT(part == SliderThumbHorizontalPart || part == SliderThumbVerticalPart || part == MediaVolumeSliderThumbPart);
</span><span class="cx"> 
</span><del>-    GtkStyleContext* context = getStyleContext(GTK_TYPE_SCALE);
-    gtk_style_context_save(context);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(GTK_TYPE_SCALE);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_set_direction(context, gtkTextDirection(renderObject.style().direction()));
-    applySliderStyleContextClasses(context, part);
-    gtk_style_context_add_class(context, GTK_STYLE_CLASS_SLIDER);
</del><ins>+    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);
</ins><span class="cx"> 
</span><span class="cx">     guint flags = 0;
</span><span class="cx">     if (!isEnabled(renderObject))
</span><span class="lines">@@ -1147,13 +1094,11 @@
</span><span class="cx">         flags |= GTK_STATE_FLAG_PRELIGHT;
</span><span class="cx">     if (isPressed(renderObject))
</span><span class="cx">         flags |= GTK_STATE_FLAG_ACTIVE;
</span><del>-    gtk_style_context_set_state(context, static_cast&lt;GtkStateFlags&gt;(flags));
</del><ins>+    gtk_style_context_set_state(context.get(), static_cast&lt;GtkStateFlags&gt;(flags));
</ins><span class="cx"> 
</span><del>-    gtk_render_slider(context, paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height(),
</del><ins>+    gtk_render_slider(context.get(), paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height(),
</ins><span class="cx">         part == SliderThumbHorizontalPart ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL);
</span><span class="cx"> 
</span><del>-    gtk_style_context_restore(context);
-
</del><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1163,8 +1108,9 @@
</span><span class="cx">     if (part != SliderThumbHorizontalPart &amp;&amp; part != SliderThumbVerticalPart)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(GTK_TYPE_SCALE);
</ins><span class="cx">     gint sliderWidth, sliderLength;
</span><del>-    gtk_style_context_get_style(getStyleContext(GTK_TYPE_SCALE), &quot;slider-width&quot;, &amp;sliderWidth, &quot;slider-length&quot;, &amp;sliderLength, nullptr);
</del><ins>+    gtk_style_context_get_style(context.get(), &quot;slider-width&quot;, &amp;sliderWidth, &quot;slider-length&quot;, &amp;sliderLength, nullptr);
</ins><span class="cx">     if (part == SliderThumbHorizontalPart) {
</span><span class="cx">         style.setWidth(Length(sliderLength, Fixed));
</span><span class="cx">         style.setHeight(Length(sliderWidth, Fixed));
</span><span class="lines">@@ -1180,22 +1126,21 @@
</span><span class="cx">     if (!renderObject.isProgress())
</span><span class="cx">         return true;
</span><span class="cx"> 
</span><del>-    GtkStyleContext* context = getStyleContext(GTK_TYPE_PROGRESS_BAR);
-    gtk_style_context_save(context);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(GTK_TYPE_PROGRESS_BAR);
+    gtk_style_context_save(context.get());
</ins><span class="cx"> 
</span><del>-    gtk_style_context_add_class(context, GTK_STYLE_CLASS_TROUGH);
</del><ins>+    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_TROUGH);
</ins><span class="cx"> 
</span><del>-    gtk_render_background(context, paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
-    gtk_render_frame(context, paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
</del><ins>+    gtk_render_background(context.get(), paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
+    gtk_render_frame(context.get(), paintInfo.context().platformContext()-&gt;cr(), rect.x(), rect.y(), rect.width(), rect.height());
</ins><span class="cx"> 
</span><del>-    gtk_style_context_restore(context);
</del><ins>+    gtk_style_context_restore(context.get());
</ins><span class="cx"> 
</span><del>-    gtk_style_context_save(context);
-    gtk_style_context_add_class(context, GTK_STYLE_CLASS_PROGRESSBAR);
-    gtk_style_context_set_state(context, static_cast&lt;GtkStateFlags&gt;(0));
</del><ins>+    gtk_style_context_add_class(context.get(), GTK_STYLE_CLASS_PROGRESSBAR);
+    gtk_style_context_set_state(context.get(), static_cast&lt;GtkStateFlags&gt;(0));
</ins><span class="cx"> 
</span><span class="cx">     GtkBorder padding;
</span><del>-    gtk_style_context_get_padding(context, gtk_style_context_get_state(context), &amp;padding);
</del><ins>+    gtk_style_context_get_padding(context.get(), gtk_style_context_get_state(context.get()), &amp;padding);
</ins><span class="cx">     IntRect progressRect(
</span><span class="cx">         rect.x() + padding.left,
</span><span class="cx">         rect.y() + padding.top,
</span><span class="lines">@@ -1205,14 +1150,13 @@
</span><span class="cx"> 
</span><span class="cx">     if (!progressRect.isEmpty()) {
</span><span class="cx"> #if GTK_CHECK_VERSION(3, 13, 7)
</span><del>-        gtk_render_background(context, paintInfo.context().platformContext()-&gt;cr(), progressRect.x(), progressRect.y(), progressRect.width(), progressRect.height());
-        gtk_render_frame(context, paintInfo.context().platformContext()-&gt;cr(), progressRect.x(), progressRect.y(), progressRect.width(), progressRect.height());
</del><ins>+        gtk_render_background(context.get(), paintInfo.context().platformContext()-&gt;cr(), progressRect.x(), progressRect.y(), progressRect.width(), progressRect.height());
+        gtk_render_frame(context.get(), paintInfo.context().platformContext()-&gt;cr(), progressRect.x(), progressRect.y(), progressRect.width(), progressRect.height());
</ins><span class="cx"> #else
</span><del>-        gtk_render_activity(context, paintInfo.context().platformContext()-&gt;cr(), progressRect.x(), progressRect.y(), progressRect.width(), progressRect.height());
</del><ins>+        gtk_render_activity(context.get(), paintInfo.context().platformContext()-&gt;cr(), progressRect.x(), progressRect.y(), progressRect.width(), progressRect.height());
</ins><span class="cx"> #endif
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    gtk_style_context_restore(context);
</del><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1229,12 +1173,12 @@
</span><span class="cx"> 
</span><span class="cx"> void RenderThemeGtk::adjustInnerSpinButtonStyle(StyleResolver&amp;, RenderStyle&amp; style, Element*) const
</span><span class="cx"> {
</span><del>-    GtkStyleContext* context = getStyleContext(GTK_TYPE_SPIN_BUTTON);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(GTK_TYPE_SPIN_BUTTON);
</ins><span class="cx"> 
</span><span class="cx">     GtkBorder padding;
</span><del>-    gtk_style_context_get_padding(context, gtk_style_context_get_state(context), &amp;padding);
</del><ins>+    gtk_style_context_get_padding(context.get(), gtk_style_context_get_state(context.get()), &amp;padding);
</ins><span class="cx"> 
</span><del>-    int width = spinButtonArrowSize(context) + padding.left + padding.right;
</del><ins>+    int width = spinButtonArrowSize(context.get()) + padding.left + padding.right;
</ins><span class="cx">     style.setWidth(Length(width, Fixed));
</span><span class="cx">     style.setMinWidth(Length(width, Fixed));
</span><span class="cx"> }
</span><span class="lines">@@ -1307,25 +1251,22 @@
</span><span class="cx"> 
</span><span class="cx"> bool RenderThemeGtk::paintInnerSpinButton(const RenderObject&amp; renderObject, const PaintInfo&amp; paintInfo, const IntRect&amp; rect)
</span><span class="cx"> {
</span><del>-    GtkStyleContext* context = getStyleContext(GTK_TYPE_SPIN_BUTTON);
-    gtk_style_context_save(context);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(GTK_TYPE_SPIN_BUTTON);
</ins><span class="cx"> 
</span><span class="cx">     GtkTextDirection direction = static_cast&lt;GtkTextDirection&gt;(gtkTextDirection(renderObject.style().direction()));
</span><del>-    gtk_style_context_set_direction(context, direction);
</del><ins>+    gtk_style_context_set_direction(context.get(), direction);
</ins><span class="cx"> 
</span><span class="cx">     guint flags = 0;
</span><span class="cx">     if (!isEnabled(renderObject) || isReadOnlyControl(renderObject))
</span><span class="cx">         flags |= GTK_STATE_FLAG_INSENSITIVE;
</span><span class="cx">     else if (isFocused(renderObject))
</span><span class="cx">         flags |= GTK_STATE_FLAG_FOCUSED;
</span><del>-    gtk_style_context_set_state(context, static_cast&lt;GtkStateFlags&gt;(flags));
-    gtk_style_context_remove_class(context, GTK_STYLE_CLASS_ENTRY);
</del><ins>+    gtk_style_context_set_state(context.get(), static_cast&lt;GtkStateFlags&gt;(flags));
+    gtk_style_context_remove_class(context.get(), GTK_STYLE_CLASS_ENTRY);
</ins><span class="cx"> 
</span><del>-    paintSpinArrowButton(this, context, renderObject, paintInfo, rect, GTK_ARROW_UP);
-    paintSpinArrowButton(this, context, renderObject, paintInfo, rect, GTK_ARROW_DOWN);
</del><ins>+    paintSpinArrowButton(this, context.get(), renderObject, paintInfo, rect, GTK_ARROW_UP);
+    paintSpinArrowButton(this, context.get(), renderObject, paintInfo, rect, GTK_ARROW_DOWN);
</ins><span class="cx"> 
</span><del>-    gtk_style_context_restore(context);
-
</del><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1349,15 +1290,15 @@
</span><span class="cx"> static Color styleColor(GType widgetType, GtkStateFlags state, StyleColorType colorType)
</span><span class="cx"> {
</span><span class="cx"> 
</span><del>-    GtkStyleContext* context = getStyleContext(widgetType);
</del><ins>+    GRefPtr&lt;GtkStyleContext&gt; context = createStyleContext(widgetType);
</ins><span class="cx">     // Recent GTK+ versions (&gt; 3.14) require to explicitly set the state before getting the color.
</span><del>-    gtk_style_context_set_state(context, state);
</del><ins>+    gtk_style_context_set_state(context.get(), state);
</ins><span class="cx"> 
</span><span class="cx">     GdkRGBA gdkRGBAColor;
</span><span class="cx">     if (colorType == StyleColorBackground)
</span><del>-        gtk_style_context_get_background_color(context, gtk_style_context_get_state(context), &amp;gdkRGBAColor);
</del><ins>+        gtk_style_context_get_background_color(context.get(), gtk_style_context_get_state(context.get()), &amp;gdkRGBAColor);
</ins><span class="cx">     else
</span><del>-        gtk_style_context_get_color(context, gtk_style_context_get_state(context), &amp;gdkRGBAColor);
</del><ins>+        gtk_style_context_get_color(context.get(), gtk_style_context_get_state(context.get()), &amp;gdkRGBAColor);
</ins><span class="cx">     return gdkRGBAColor;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>