bug 1396722 remove no-op ReleaseStyleContext() r=stransky+263117
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 05 Sep 2017 09:16:01 +1200
changeset 429095 f7475262b1cfe886391d2affc7bf9fef8e1cfea6
parent 429094 d731723c09f704c5063140644b5916615261307e
child 429096 3781d3cf10ffdea9447866301d69a7817cb907d0
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstransky
bugs1396722, 263117
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1396722 remove no-op ReleaseStyleContext() r=stransky+263117 MozReview-Commit-ID: DgKM0wrStrk
widget/gtk/WidgetStyleCache.cpp
widget/gtk/WidgetStyleCache.h
widget/gtk/gtk3drawing.cpp
widget/gtk/nsLookAndFeel.cpp
--- a/widget/gtk/WidgetStyleCache.cpp
+++ b/widget/gtk/WidgetStyleCache.cpp
@@ -1215,18 +1215,18 @@ ResetWidgetCache(void)
   if (sWidgetStorage[MOZ_GTK_WINDOW])
     gtk_widget_destroy(sWidgetStorage[MOZ_GTK_WINDOW]);
 
   /* Clear already freed arrays */
   mozilla::PodArrayZero(sWidgetStorage);
 }
 
 GtkStyleContext*
-ClaimStyleContext(WidgetNodeType aNodeType, GtkTextDirection aDirection,
-                  GtkStateFlags aStateFlags, StyleFlags aFlags)
+GetStyleContext(WidgetNodeType aNodeType, GtkTextDirection aDirection,
+                GtkStateFlags aStateFlags, StyleFlags aFlags)
 {
   GtkStyleContext* style;
   if (gtk_check_version(3, 20, 0) != nullptr) {
     style = GetWidgetStyleInternal(aNodeType);
   } else {
     style = GetCssNodeStyleInternal(aNodeType);
   }
   bool stateChanged = false;
@@ -1271,13 +1271,8 @@ ClaimStyleContext(WidgetNodeType aNodeTy
   // Avoid calling invalidate on contexts that are not owned and constructed
   // by widgets to avoid performing build_properties() (in 3.16 stylecontext.c)
   // unnecessarily early.
   if (stateChanged && sWidgetStorage[aNodeType]) {
     gtk_style_context_invalidate(style);
   }
   return style;
 }
-
-void
-ReleaseStyleContext(GtkStyleContext* aStyleContext)
-{
-}
--- a/widget/gtk/WidgetStyleCache.h
+++ b/widget/gtk/WidgetStyleCache.h
@@ -28,21 +28,22 @@ GetWidget(WidgetNodeType aNodeType);
 GtkStyleContext*
 CreateStyleForWidget(GtkWidget* aWidget, GtkStyleContext* aParentStyle);
 
 GtkStyleContext*
 CreateCSSNode(const char*      aName,
               GtkStyleContext* aParentStyle,
               GType            aType = G_TYPE_NONE);
 
-// Callers must call ReleaseStyleContext() on the returned context.
+/*
+ * Returns a pointer to a style context for the specified node and state.
+ * The context is owned by WidgetStyleCache.  Do not unref.
+ */
 GtkStyleContext*
-ClaimStyleContext(WidgetNodeType aNodeType,
-                  GtkTextDirection aDirection = GTK_TEXT_DIR_NONE,
-                  GtkStateFlags aStateFlags = GTK_STATE_FLAG_NORMAL,
-                  StyleFlags aFlags = NO_STYLE_FLAGS);
-void
-ReleaseStyleContext(GtkStyleContext* style);
+GetStyleContext(WidgetNodeType aNodeType,
+                GtkTextDirection aDirection = GTK_TEXT_DIR_NONE,
+                GtkStateFlags aStateFlags = GTK_STATE_FLAG_NORMAL,
+                StyleFlags aFlags = NO_STYLE_FLAGS);
 
 void
 ResetWidgetCache(void);
 
 #endif // WidgetStyleCache_h
--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -95,20 +95,19 @@ moz_gtk_init()
 
 void
 moz_gtk_refresh()
 {
     if (gtk_check_version(3, 12, 0) == nullptr &&
         gtk_check_version(3, 20, 0) != nullptr)
     {
         // Deprecated for Gtk >= 3.20+
-        GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_TAB_TOP);
+        GtkStyleContext *style = GetStyleContext(MOZ_GTK_TAB_TOP);
         gtk_style_context_get_style(style,
                                     "has-tab-gap", &notebook_has_tab_gap, NULL);
-        ReleaseStyleContext(style);
     }
     else {
         notebook_has_tab_gap = true;
     }
 
     sScrollbarMetrics[GTK_ORIENTATION_HORIZONTAL].initialized = false;
     sScrollbarMetrics[GTK_ORIENTATION_VERTICAL].initialized = false;
 }
@@ -144,55 +143,51 @@ moz_gtk_get_focus_outline_size(GtkStyleC
     *focus_h_width = border.left + padding.left;
     *focus_v_width = border.top + padding.top;
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_get_focus_outline_size(gint* focus_h_width, gint* focus_v_width)
 {
-    GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_ENTRY);
+    GtkStyleContext *style = GetStyleContext(MOZ_GTK_ENTRY);
     moz_gtk_get_focus_outline_size(style, focus_h_width, focus_v_width);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_menuitem_get_horizontal_padding(gint* horizontal_padding)
 {
-    GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_MENUITEM);
+    GtkStyleContext *style = GetStyleContext(MOZ_GTK_MENUITEM);
     gtk_style_context_get_style(style,
                                 "horizontal-padding", horizontal_padding,
                                 nullptr);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_checkmenuitem_get_horizontal_padding(gint* horizontal_padding)
 {
-    GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_CHECKMENUITEM);
+    GtkStyleContext *style = GetStyleContext(MOZ_GTK_CHECKMENUITEM);
     gtk_style_context_get_style(style,
                                 "horizontal-padding", horizontal_padding,
                                 nullptr);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_button_get_default_overflow(gint* border_top, gint* border_left,
                                     gint* border_bottom, gint* border_right)
 {
     GtkBorder* default_outside_border;
 
-    GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_BUTTON);
+    GtkStyleContext *style = GetStyleContext(MOZ_GTK_BUTTON);
     gtk_style_context_get_style(style,
                                 "default-outside-border", &default_outside_border,
                                 NULL);
-    ReleaseStyleContext(style);
 
     if (default_outside_border) {
         *border_top = default_outside_border->top;
         *border_left = default_outside_border->left;
         *border_bottom = default_outside_border->bottom;
         *border_right = default_outside_border->right;
         gtk_border_free(default_outside_border);
     } else {
@@ -202,21 +197,20 @@ moz_gtk_button_get_default_overflow(gint
 }
 
 static gint
 moz_gtk_button_get_default_border(gint* border_top, gint* border_left,
                                   gint* border_bottom, gint* border_right)
 {
     GtkBorder* default_border;
 
-    GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_BUTTON);
+    GtkStyleContext *style = GetStyleContext(MOZ_GTK_BUTTON);
     gtk_style_context_get_style(style,
                                 "default-border", &default_border,
                                 NULL);
-    ReleaseStyleContext(style);
 
     if (default_border) {
         *border_top = default_border->top;
         *border_left = default_border->left;
         *border_bottom = default_border->bottom;
         *border_right = default_border->right;
         gtk_border_free(default_border);
     } else {
@@ -226,38 +220,35 @@ moz_gtk_button_get_default_border(gint* 
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_splitter_get_metrics(gint orientation, gint* size)
 {
     GtkStyleContext *style;
     if (orientation == GTK_ORIENTATION_HORIZONTAL) {
-        style = ClaimStyleContext(MOZ_GTK_SPLITTER_HORIZONTAL);
+        style = GetStyleContext(MOZ_GTK_SPLITTER_HORIZONTAL);
     } else {
-        style = ClaimStyleContext(MOZ_GTK_SPLITTER_VERTICAL);
+        style = GetStyleContext(MOZ_GTK_SPLITTER_VERTICAL);
     }
     gtk_style_context_get_style(style, "handle_size", size, NULL);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_window_paint(cairo_t *cr, GdkRectangle* rect,
                      GtkTextDirection direction)
 {
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_WINDOW, direction);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_WINDOW, direction);
 
     gtk_style_context_save(style);
     gtk_style_context_add_class(style, GTK_STYLE_CLASS_BACKGROUND);
     gtk_render_background(style, cr, rect->x, rect->y, rect->width, rect->height);
     gtk_style_context_restore(style);
 
-    ReleaseStyleContext(style);
-
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_button_paint(cairo_t *cr, GdkRectangle* rect,
                      GtkWidgetState* state,
                      GtkReliefStyle relief, GtkWidget* widget,
                      GtkTextDirection direction)
@@ -346,19 +337,18 @@ moz_gtk_toggle_paint(cairo_t *cr, GdkRec
     focus_height = height + 2 * indicator_spacing;
 
     if (selected)
         state_flags = static_cast<GtkStateFlags>(state_flags|checkbox_check_state);
 
     if (inconsistent)
         state_flags = static_cast<GtkStateFlags>(state_flags|GTK_STATE_FLAG_INCONSISTENT);
 
-    style = ClaimStyleContext(isradio ? MOZ_GTK_RADIOBUTTON :
-                                        MOZ_GTK_CHECKBUTTON,
-                              direction, state_flags);
+    style = GetStyleContext(isradio ? MOZ_GTK_RADIOBUTTON : MOZ_GTK_CHECKBUTTON,
+                            direction, state_flags);
 
     if (gtk_check_version(3, 20, 0) == nullptr) {
         gtk_render_background(style, cr, x, y, width, height);
         gtk_render_frame(style, cr, x, y, width, height);
     }
 
     if (isradio) {
         gtk_render_option(style, cr, x, y, width, height);
@@ -370,18 +360,16 @@ moz_gtk_toggle_paint(cairo_t *cr, GdkRec
     else {
         gtk_render_check(style, cr, x, y, width, height);
         if (state->focused) {
             gtk_render_focus(style, cr,
                              focus_x, focus_y, focus_width, focus_height);
         }
     }
 
-    ReleaseStyleContext(style);
-
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 calculate_button_inner_rect(GtkWidget* button, GdkRectangle* rect,
                             GdkRectangle* inner_rect,
                             GtkTextDirection direction)
 {
@@ -455,28 +443,27 @@ GetMinContentBox(GtkStyleContext* style)
 /**
  * Get minimum widget size as sum of margin, padding, border and
  * min-width/min-height.
  */
 static void
 moz_gtk_get_widget_min_size(WidgetNodeType aGtkWidgetType, int* width,
                             int* height)
 {
-  GtkStyleContext* style = ClaimStyleContext(aGtkWidgetType);
+  GtkStyleContext* style = GetStyleContext(aGtkWidgetType);
   GtkStateFlags state_flags = gtk_style_context_get_state(style);
   gtk_style_context_get(style, state_flags,
                         "min-height", height,
                         "min-width", width,
                         nullptr);
 
   GtkBorder border, padding, margin;
   gtk_style_context_get_border(style, state_flags, &border);
   gtk_style_context_get_padding(style, state_flags, &padding);
   gtk_style_context_get_margin(style, state_flags,  &margin);
-  ReleaseStyleContext(style);
 
   *width += border.left + border.right + margin.left + margin.right +
             padding.left + padding.right;
   *height += border.top + border.bottom + margin.top + margin.bottom +
              padding.top + padding.bottom;
 }
 
 static MozGtkSize
@@ -661,104 +648,99 @@ moz_gtk_scrollbar_trough_paint(WidgetNod
     GdkRectangle rect = *aRect;
     GtkStyleContext* style;
 
     if (gtk_get_minor_version() >= 20) {
         WidgetNodeType thumb = widget == MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL ?
             MOZ_GTK_SCROLLBAR_THUMB_VERTICAL :
             MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL;
         MozGtkSize thumbSize = GetMinMarginBox(thumb);
-        style = ClaimStyleContext(widget, direction);
+        style = GetStyleContext(widget, direction);
         MozGtkSize trackSize = GetMinContentBox(style);
         trackSize.Include(thumbSize);
         trackSize += GetMarginBorderPadding(style);
         // Gecko's trough |aRect| fills available breadth, but GTK's trough is
         // centered in the contents_gadget.  The centering here round left
         // and up, like gtk_box_gadget_allocate_child().
         if (widget == MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL) {
             rect.x += (rect.width - trackSize.width)/2;
             rect.width = trackSize.width;
         } else {
             rect.y += (rect.height - trackSize.height)/2;
             rect.height = trackSize.height;
         }
     } else {
-        style = ClaimStyleContext(widget, direction);
+        style = GetStyleContext(widget, direction);
     }
 
     moz_gtk_draw_styled_frame(style, cr, &rect, state->focused);
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_scrollbar_paint(WidgetNodeType widget,
                         cairo_t *cr, const GdkRectangle* rect,
                         GtkWidgetState* state,
                         GtkTextDirection direction)
 {
-    GtkStyleContext* style = ClaimStyleContext(widget, direction);
+    GtkStyleContext* style = GetStyleContext(widget, direction);
     moz_gtk_update_scrollbar_style(style, widget, direction);
 
     moz_gtk_draw_styled_frame(style, cr, rect, state->focused);
 
-    ReleaseStyleContext(style);
-    style = ClaimStyleContext((widget == MOZ_GTK_SCROLLBAR_HORIZONTAL) ?
-                              MOZ_GTK_SCROLLBAR_CONTENTS_HORIZONTAL :
-                              MOZ_GTK_SCROLLBAR_CONTENTS_VERTICAL,
-                              direction);
+    style = GetStyleContext((widget == MOZ_GTK_SCROLLBAR_HORIZONTAL) ?
+                            MOZ_GTK_SCROLLBAR_CONTENTS_HORIZONTAL :
+                            MOZ_GTK_SCROLLBAR_CONTENTS_VERTICAL,
+                            direction);
     moz_gtk_draw_styled_frame(style, cr, rect, state->focused);
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_scrollbar_thumb_paint(WidgetNodeType widget,
                               cairo_t *cr, const GdkRectangle* aRect,
                               GtkWidgetState* state,
                               GtkTextDirection direction)
 {
     GtkStateFlags state_flags = GetStateFlagsFromGtkWidgetState(state);
 
     GdkRectangle rect = *aRect;
-    GtkStyleContext* style = ClaimStyleContext(widget, direction, state_flags);
+    GtkStyleContext* style = GetStyleContext(widget, direction, state_flags);
     InsetByMargin(&rect, style);
 
     gtk_render_slider(style, cr,
                       rect.x,
                       rect.y,
                       rect.width,
                       rect.height,
                      (widget == MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL) ?
                      GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL);
 
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_spin_paint(cairo_t *cr, GdkRectangle* rect,
                    GtkTextDirection direction)
 {
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_SPINBUTTON, direction);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_SPINBUTTON, direction);
     gtk_render_background(style, cr, rect->x, rect->y, rect->width, rect->height);
     gtk_render_frame(style, cr, rect->x, rect->y, rect->width, rect->height);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_spin_updown_paint(cairo_t *cr, GdkRectangle* rect,
                           gboolean isDown, GtkWidgetState* state,
                           GtkTextDirection direction)
 {
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_SPINBUTTON, direction,
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_SPINBUTTON, direction,
                                  GetStateFlagsFromGtkWidgetState(state));
 
     gtk_render_background(style, cr, rect->x, rect->y, rect->width, rect->height);
     gtk_render_frame(style, cr, rect->x, rect->y, rect->width, rect->height);
 
     /* hard code these values */
     GdkRectangle arrow_rect;
     arrow_rect.width = 6;
@@ -767,17 +749,16 @@ moz_gtk_spin_updown_paint(cairo_t *cr, G
     arrow_rect.y = rect->y + (rect->height - arrow_rect.height) / 2;
     arrow_rect.y += isDown ? -1 : 1;
 
     gtk_render_arrow(style, cr, 
                     isDown ? ARROW_DOWN : ARROW_UP,
                     arrow_rect.x, arrow_rect.y,
                     arrow_rect.width);
 
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 /* See gtk_range_draw() for reference.
 */
 static gint
 moz_gtk_scale_paint(cairo_t *cr, GdkRectangle* rect,
                     GtkWidgetState* state,
@@ -788,17 +769,17 @@ moz_gtk_scale_paint(cairo_t *cr, GdkRect
   GtkStyleContext* style;
   GtkBorder margin;
 
   moz_gtk_get_scale_metrics(flags, &min_width, &min_height);
 
   WidgetNodeType widget = (flags == GTK_ORIENTATION_HORIZONTAL) ?
                           MOZ_GTK_SCALE_TROUGH_HORIZONTAL :
                           MOZ_GTK_SCALE_TROUGH_VERTICAL;
-  style = ClaimStyleContext(widget, direction, state_flags);
+  style = GetStyleContext(widget, direction, state_flags);
   gtk_style_context_get_margin(style, state_flags, &margin);
 
   // Clamp the dimension perpendicular to the direction that the slider crosses
   // to the minimum size.
   if (flags == GTK_ORIENTATION_HORIZONTAL) {
     width = rect->width - (margin.left + margin.right);
     height = min_height - (margin.top + margin.bottom);
     x = rect->x + margin.left;
@@ -812,17 +793,16 @@ moz_gtk_scale_paint(cairo_t *cr, GdkRect
 
   gtk_render_background(style, cr, x, y, width, height);
   gtk_render_frame(style, cr, x, y, width, height);
 
   if (state->focused)
     gtk_render_focus(style, cr, 
                     rect->x, rect->y, rect->width, rect->height);
 
-  ReleaseStyleContext(style);
   return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_scale_thumb_paint(cairo_t *cr, GdkRectangle* rect,
                           GtkWidgetState* state,
                           GtkOrientation flags, GtkTextDirection direction)
 {
@@ -841,62 +821,58 @@ moz_gtk_scale_thumb_paint(cairo_t *cr, G
     moz_gtk_get_scalethumb_metrics(GTK_ORIENTATION_VERTICAL, &thumb_height, &thumb_width);
     x = rect->x + (rect->width - thumb_width) / 2;
     y = rect->y;
   }
 
   WidgetNodeType widget = (flags == GTK_ORIENTATION_HORIZONTAL) ?
                           MOZ_GTK_SCALE_THUMB_HORIZONTAL :
                           MOZ_GTK_SCALE_THUMB_VERTICAL;
-  style = ClaimStyleContext(widget, direction, state_flags);
+  style = GetStyleContext(widget, direction, state_flags);
   gtk_render_slider(style, cr, x, y, thumb_width, thumb_height, flags);
-  ReleaseStyleContext(style);
 
   return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_gripper_paint(cairo_t *cr, GdkRectangle* rect,
                       GtkWidgetState* state,
                       GtkTextDirection direction)
 {
     GtkStyleContext* style =
-            ClaimStyleContext(MOZ_GTK_GRIPPER, direction,
-                              GetStateFlagsFromGtkWidgetState(state));
+            GetStyleContext(MOZ_GTK_GRIPPER, direction,
+                            GetStateFlagsFromGtkWidgetState(state));
     gtk_render_background(style, cr, rect->x, rect->y, rect->width, rect->height);
     gtk_render_frame(style, cr, rect->x, rect->y, rect->width, rect->height);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_hpaned_paint(cairo_t *cr, GdkRectangle* rect,
                      GtkWidgetState* state)
 {
     GtkStyleContext* style =
-        ClaimStyleContext(MOZ_GTK_SPLITTER_SEPARATOR_HORIZONTAL,
-                          GTK_TEXT_DIR_LTR,
-                          GetStateFlagsFromGtkWidgetState(state));
+        GetStyleContext(MOZ_GTK_SPLITTER_SEPARATOR_HORIZONTAL,
+                        GTK_TEXT_DIR_LTR,
+                        GetStateFlagsFromGtkWidgetState(state));
     gtk_render_handle(style, cr,
                       rect->x, rect->y, rect->width, rect->height);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_vpaned_paint(cairo_t *cr, GdkRectangle* rect,
                      GtkWidgetState* state)
 {
     GtkStyleContext* style =
-        ClaimStyleContext(MOZ_GTK_SPLITTER_SEPARATOR_VERTICAL,
-                          GTK_TEXT_DIR_LTR,
-                          GetStateFlagsFromGtkWidgetState(state));
+        GetStyleContext(MOZ_GTK_SPLITTER_SEPARATOR_VERTICAL,
+                        GTK_TEXT_DIR_LTR,
+                        GetStateFlagsFromGtkWidgetState(state));
     gtk_render_handle(style, cr,
                       rect->x, rect->y, rect->width, rect->height);                     
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 // See gtk_entry_draw() for reference.
 static gint
 moz_gtk_entry_paint(cairo_t *cr, GdkRectangle* rect,
                     GtkWidgetState* state,
                     GtkStyleContext* style)
@@ -934,36 +910,32 @@ moz_gtk_text_view_paint(cairo_t *cr, Gdk
     // some themes as GtkTextView backgrounds do not typically render
     // differently with focus.
     GtkStateFlags state_flags =
         state->disabled ? GTK_STATE_FLAG_INSENSITIVE :
         state->focused ? GTK_STATE_FLAG_FOCUSED :
         GTK_STATE_FLAG_NORMAL;
 
     GtkStyleContext* style_frame =
-        ClaimStyleContext(MOZ_GTK_SCROLLED_WINDOW, direction, state_flags);
+        GetStyleContext(MOZ_GTK_SCROLLED_WINDOW, direction, state_flags);
     gtk_render_frame(style_frame, cr,
                      aRect->x, aRect->y, aRect->width, aRect->height);
 
     GdkRectangle rect = *aRect;
     InsetByBorderPadding(&rect, style_frame);
 
-    ReleaseStyleContext(style_frame);
-
     GtkStyleContext* style =
-        ClaimStyleContext(MOZ_GTK_TEXT_VIEW, direction, state_flags);
+        GetStyleContext(MOZ_GTK_TEXT_VIEW, direction, state_flags);
     gtk_render_background(style, cr, rect.x, rect.y, rect.width, rect.height);
-    ReleaseStyleContext(style);
     // There is a separate "text" window, which usually provides the
     // background behind the text.  However, this is transparent in Ambiance
     // for GTK 3.20, in which case the MOZ_GTK_TEXT_VIEW background is
     // visible.
-    style = ClaimStyleContext(MOZ_GTK_TEXT_VIEW_TEXT, direction, state_flags);
+    style = GetStyleContext(MOZ_GTK_TEXT_VIEW_TEXT, direction, state_flags);
     gtk_render_background(style, cr, rect.x, rect.y, rect.width, rect.height);
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint 
 moz_gtk_treeview_paint(cairo_t *cr, GdkRectangle* rect,
                        GtkWidgetState* state,
                        GtkTextDirection direction)
@@ -973,33 +945,30 @@ moz_gtk_treeview_paint(cairo_t *cr, GdkR
     GtkStyleContext *style_tree;
     GtkStateFlags state_flags;
     GtkBorder border;
 
     /* only handle disabled and normal states, otherwise the whole background
      * area will be painted differently with other states */
     state_flags = state->disabled ? GTK_STATE_FLAG_INSENSITIVE : GTK_STATE_FLAG_NORMAL;
 
-    style = ClaimStyleContext(MOZ_GTK_SCROLLED_WINDOW, direction);
+    style = GetStyleContext(MOZ_GTK_SCROLLED_WINDOW, direction);
     gtk_style_context_get_border(style, state_flags, &border);
     xthickness = border.left;
     ythickness = border.top;    
-    ReleaseStyleContext(style);
-
-    style_tree = ClaimStyleContext(MOZ_GTK_TREEVIEW_VIEW, direction);
+
+    style_tree = GetStyleContext(MOZ_GTK_TREEVIEW_VIEW, direction);
     gtk_render_background(style_tree, cr,
                           rect->x + xthickness, rect->y + ythickness,
                           rect->width - 2 * xthickness,
                           rect->height - 2 * ythickness);
-    ReleaseStyleContext(style_tree);
-
-    style = ClaimStyleContext(MOZ_GTK_SCROLLED_WINDOW, direction);
+
+    style = GetStyleContext(MOZ_GTK_SCROLLED_WINDOW, direction);
     gtk_render_frame(style, cr, 
                      rect->x, rect->y, rect->width, rect->height); 
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_tree_header_cell_paint(cairo_t *cr, GdkRectangle* rect,
                                GtkWidgetState* state,
                                gboolean isSorted, GtkTextDirection direction)
 {
@@ -1017,18 +986,18 @@ moz_gtk_tree_header_sort_arrow_paint(cai
     gdouble arrow_angle;
     GtkStyleContext* style;
 
     /* hard code these values */
     arrow_rect.width = 11;
     arrow_rect.height = 11;
     arrow_rect.x = rect->x + (rect->width - arrow_rect.width) / 2;
     arrow_rect.y = rect->y + (rect->height - arrow_rect.height) / 2;
-    style = ClaimStyleContext(MOZ_GTK_TREE_HEADER_SORTARROW, direction,
-                              GetStateFlagsFromGtkWidgetState(state));
+    style = GetStyleContext(MOZ_GTK_TREE_HEADER_SORTARROW, direction,
+                            GetStateFlagsFromGtkWidgetState(state));
     switch (arrow_type) {
     case GTK_ARROW_LEFT:
         arrow_angle = ARROW_LEFT;
         break;
     case GTK_ARROW_RIGHT:
         arrow_angle = ARROW_RIGHT;
         break;
     case GTK_ARROW_DOWN:
@@ -1037,17 +1006,16 @@ moz_gtk_tree_header_sort_arrow_paint(cai
     default:
         arrow_angle = ARROW_UP;
         break;
     }
     if (arrow_type != GTK_ARROW_NONE)
         gtk_render_arrow(style, cr, arrow_angle,
                          arrow_rect.x, arrow_rect.y,
                          arrow_rect.width);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 /* See gtk_expander_paint() for reference. 
  */
 static gint
 moz_gtk_treeview_expander_paint(cairo_t *cr, GdkRectangle* rect,
                                 GtkWidgetState* state,
@@ -1062,25 +1030,24 @@ moz_gtk_treeview_expander_paint(cairo_t 
     /* GTK_STATE_FLAG_ACTIVE controls expanded/colapsed state rendering
      * in gtk_render_expander()
      */
     if (expander_state == GTK_EXPANDER_EXPANDED)
         state_flags = static_cast<GtkStateFlags>(state_flags|checkbox_check_state);
     else
         state_flags = static_cast<GtkStateFlags>(state_flags&~(checkbox_check_state));
 
-    GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_TREEVIEW_EXPANDER,
-                                               direction, state_flags);
+    GtkStyleContext *style = GetStyleContext(MOZ_GTK_TREEVIEW_EXPANDER,
+                                             direction, state_flags);
     gtk_render_expander(style, cr,
                         rect->x,
                         rect->y,
                         rect->width,
                         rect->height);
 
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 /* See gtk_separator_draw() for reference.
 */
 static gint
 moz_gtk_combo_box_paint(cairo_t *cr, GdkRectangle* rect,
                         GtkWidgetState* state,
@@ -1107,21 +1074,20 @@ moz_gtk_combo_box_paint(cairo_t *cr, Gdk
 
     if (direction == GTK_TEXT_DIR_LTR)
         arrow_rect.x += arrow_rect.width - arrow_req.width;
     arrow_rect.width = arrow_req.width;
 
     calculate_arrow_rect(comboBoxArrow,
                          &arrow_rect, &real_arrow_rect, direction);
 
-    style = ClaimStyleContext(MOZ_GTK_COMBOBOX_ARROW);
+    style = GetStyleContext(MOZ_GTK_COMBOBOX_ARROW);
     gtk_render_arrow(style, cr, ARROW_DOWN,
                      real_arrow_rect.x, real_arrow_rect.y,
                      real_arrow_rect.width);
-    ReleaseStyleContext(style);
 
     /* If there is no separator in the theme, there's nothing left to do. */
     GtkWidget* widget = GetWidget(MOZ_GTK_COMBOBOX_SEPARATOR);
     if (!widget)
         return MOZ_GTK_SUCCESS;
     style = gtk_widget_get_style_context(widget);
     gtk_style_context_get_style(style,
                                 "wide-separators", &wide_separators,
@@ -1182,21 +1148,20 @@ moz_gtk_arrow_paint(cairo_t *cr, GdkRect
         break;
     }
     if (arrow_type == GTK_ARROW_NONE)
         return MOZ_GTK_SUCCESS;
 
     calculate_arrow_rect(GetWidget(MOZ_GTK_BUTTON_ARROW), rect, &arrow_rect,
                          direction);
     GtkStateFlags state_flags = GetStateFlagsFromGtkWidgetState(state);
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_BUTTON_ARROW,
-                                               direction, state_flags);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_BUTTON_ARROW,
+                                             direction, state_flags);
     gtk_render_arrow(style, cr, arrow_angle,
                      arrow_rect.x, arrow_rect.y, arrow_rect.width);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_combo_box_entry_button_paint(cairo_t *cr, GdkRectangle* rect,
                                      GtkWidgetState* state,
                                      gboolean input_focus,
                                      GtkTextDirection direction)
@@ -1219,72 +1184,67 @@ moz_gtk_combo_box_entry_button_paint(cai
                                     NULL);
         arrow_rect.x += x_displacement;
         arrow_rect.y += y_displacement;
     }
 
     calculate_arrow_rect(GetWidget(MOZ_GTK_COMBOBOX_ENTRY_ARROW),
                          &arrow_rect, &real_arrow_rect, direction);
 
-    style = ClaimStyleContext(MOZ_GTK_COMBOBOX_ENTRY_ARROW);
+    style = GetStyleContext(MOZ_GTK_COMBOBOX_ENTRY_ARROW);
     gtk_render_arrow(style, cr, ARROW_DOWN,
                     real_arrow_rect.x, real_arrow_rect.y,
                     real_arrow_rect.width);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_container_paint(cairo_t *cr, GdkRectangle* rect,
                         GtkWidgetState* state, 
                         WidgetNodeType  widget_type,
                         GtkTextDirection direction)
 {
     GtkStateFlags state_flags = GetStateFlagsFromGtkWidgetState(state);
-    GtkStyleContext* style = ClaimStyleContext(widget_type, direction,
-                                               state_flags);
+    GtkStyleContext* style = GetStyleContext(widget_type, direction,
+                                             state_flags);
     /* this is for drawing a prelight box */
     if (state_flags & GTK_STATE_FLAG_PRELIGHT) {
         gtk_render_background(style, cr,
                               rect->x, rect->y, rect->width, rect->height);
     }
 
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_toggle_label_paint(cairo_t *cr, GdkRectangle* rect,
                            GtkWidgetState* state, 
                            gboolean isradio, GtkTextDirection direction)
 {
     if (!state->focused)
         return MOZ_GTK_SUCCESS;
 
     GtkStyleContext *style =
-        ClaimStyleContext(isradio ? MOZ_GTK_RADIOBUTTON_CONTAINER :
-                                    MOZ_GTK_CHECKBUTTON_CONTAINER,
-                          direction,
-                          GetStateFlagsFromGtkWidgetState(state));
+        GetStyleContext(isradio ? MOZ_GTK_RADIOBUTTON_CONTAINER :
+                                  MOZ_GTK_CHECKBUTTON_CONTAINER,
+                        direction,
+                        GetStateFlagsFromGtkWidgetState(state));
     gtk_render_focus(style, cr,
                     rect->x, rect->y, rect->width, rect->height);
 
-    ReleaseStyleContext(style);
-
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_toolbar_paint(cairo_t *cr, GdkRectangle* rect,
                       GtkTextDirection direction)
 {
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_TOOLBAR, direction);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_TOOLBAR, direction);
     gtk_render_background(style, cr, rect->x, rect->y, rect->width, rect->height);
     gtk_render_frame(style, cr, rect->x, rect->y, rect->width, rect->height);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 /* See _gtk_toolbar_paint_space_line() for reference.
 */
 static gint
 moz_gtk_toolbar_separator_paint(cairo_t *cr, GdkRectangle* rect,
                                 GtkTextDirection direction)
@@ -1292,24 +1252,23 @@ moz_gtk_toolbar_separator_paint(cairo_t 
     gint     separator_width;
     gint     paint_width;
     gboolean wide_separators;
     
     /* Defined as constants in GTK+ 2.10.14 */
     const double start_fraction = 0.2;
     const double end_fraction = 0.8;
 
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_TOOLBAR);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_TOOLBAR);
     gtk_style_context_get_style(style,
                                 "wide-separators", &wide_separators,
                                 "separator-width", &separator_width,
                                 NULL);
-    ReleaseStyleContext(style);
-
-    style = ClaimStyleContext(MOZ_GTK_TOOLBAR_SEPARATOR, direction);
+
+    style = GetStyleContext(MOZ_GTK_TOOLBAR_SEPARATOR, direction);
     if (wide_separators) {
         if (separator_width > rect->width)
             separator_width = rect->width;
         
         gtk_render_frame(style, cr,
                           rect->x + (rect->width - separator_width) / 2,
                           rect->y + rect->height * start_fraction,
                           separator_width,
@@ -1323,126 +1282,119 @@ moz_gtk_toolbar_separator_paint(cairo_t 
             paint_width = rect->width;
         
         gtk_render_line(style, cr, 
                         rect->x + (rect->width - paint_width) / 2,
                         rect->y + rect->height * start_fraction,
                         rect->x + (rect->width - paint_width) / 2,
                         rect->y + rect->height * end_fraction);
     }
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_tooltip_paint(cairo_t *cr, const GdkRectangle* aRect,
                       GtkTextDirection direction)
 {
     // Tooltip widget is made in GTK3 as following tree:
     // Tooltip window
     //   Horizontal Box
     //     Icon (not supported by Firefox)
     //     Label
     // Each element can be fully styled by CSS of GTK theme.
     // We have to draw all elements with appropriate offset and right dimensions.
 
     // Tooltip drawing
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_TOOLTIP, direction);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_TOOLTIP, direction);
     GdkRectangle rect = *aRect;
     gtk_render_background(style, cr, rect.x, rect.y, rect.width, rect.height);
     gtk_render_frame(style, cr, rect.x, rect.y, rect.width, rect.height);
-    ReleaseStyleContext(style);
 
     // Horizontal Box drawing
     //
     // The box element has hard-coded 6px margin-* GtkWidget properties, which
     // are added between the window dimensions and the CSS margin box of the
     // horizontal box.  The frame of the tooltip window is drawn in the
     // 6px margin.
     // For drawing Horizontal Box we have to inset drawing area by that 6px
     // plus its CSS margin.
-    GtkStyleContext* boxStyle = ClaimStyleContext(MOZ_GTK_TOOLTIP_BOX, direction);
+    GtkStyleContext* boxStyle = GetStyleContext(MOZ_GTK_TOOLTIP_BOX, direction);
 
     rect.x += 6;
     rect.y += 6;
     rect.width -= 12;
     rect.height -= 12;
 
     InsetByMargin(&rect, boxStyle);
     gtk_render_background(boxStyle, cr, rect.x, rect.y, rect.width, rect.height);
     gtk_render_frame(boxStyle, cr, rect.x, rect.y, rect.width, rect.height);
 
     // Label drawing
     InsetByBorderPadding(&rect, boxStyle);
-    ReleaseStyleContext(boxStyle);
 
     GtkStyleContext* labelStyle =
-        ClaimStyleContext(MOZ_GTK_TOOLTIP_BOX_LABEL, direction);
+        GetStyleContext(MOZ_GTK_TOOLTIP_BOX_LABEL, direction);
     moz_gtk_draw_styled_frame(labelStyle, cr, &rect, false);
-    ReleaseStyleContext(labelStyle);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_resizer_paint(cairo_t *cr, GdkRectangle* rect,
                       GtkWidgetState* state,
                       GtkTextDirection direction)
 {
     GtkStyleContext* style =
-        ClaimStyleContext(MOZ_GTK_RESIZER, GTK_TEXT_DIR_LTR,
-                          GetStateFlagsFromGtkWidgetState(state));
+        GetStyleContext(MOZ_GTK_RESIZER, GTK_TEXT_DIR_LTR,
+                        GetStateFlagsFromGtkWidgetState(state));
 
     // Workaround unico not respecting the text direction for resizers.
     // See bug 1174248.
     cairo_save(cr);
     if (direction == GTK_TEXT_DIR_RTL) {
       cairo_matrix_t mat;
       cairo_matrix_init_translate(&mat, 2 * rect->x + rect->width, 0);
       cairo_matrix_scale(&mat, -1, 1);
       cairo_transform(cr, &mat);
     }
 
     gtk_render_handle(style, cr, rect->x, rect->y, rect->width, rect->height);
     cairo_restore(cr);
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_frame_paint(cairo_t *cr, GdkRectangle* rect,
                     GtkTextDirection direction)
 {
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_FRAME, direction);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_FRAME, direction);
     gtk_render_frame(style, cr, rect->x, rect->y, rect->width, rect->height);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_progressbar_paint(cairo_t *cr, GdkRectangle* rect,
                           GtkTextDirection direction)
 {
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_PROGRESS_TROUGH,
-                                               direction);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_PROGRESS_TROUGH,
+                                             direction);
     gtk_render_background(style, cr, rect->x, rect->y, rect->width, rect->height);
     gtk_render_frame(style, cr, rect->x, rect->y, rect->width, rect->height);
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_progress_chunk_paint(cairo_t *cr, GdkRectangle* rect,
                              GtkTextDirection direction,
                              WidgetNodeType widget)
 {
     GtkStyleContext* style =
-        ClaimStyleContext(MOZ_GTK_PROGRESS_CHUNK, direction);
+        GetStyleContext(MOZ_GTK_PROGRESS_CHUNK, direction);
 
     if (widget == MOZ_GTK_PROGRESS_CHUNK_INDETERMINATE ||
         widget == MOZ_GTK_PROGRESS_CHUNK_VERTICAL_INDETERMINATE) {
       /**
        * The bar's size and the bar speed are set depending of the progress'
        * size. These could also be constant for all progress bars easily.
        */
       gboolean vertical = (widget == MOZ_GTK_PROGRESS_CHUNK_VERTICAL_INDETERMINATE);
@@ -1476,17 +1428,16 @@ moz_gtk_progress_chunk_paint(cairo_t *cr
     // gtk_render_activity was used to render progress chunks on GTK versions
     // before 3.13.7, see bug 1173907.
     if (!gtk_check_version(3, 13, 7)) {
       gtk_render_background(style, cr, rect->x, rect->y, rect->width, rect->height);
       gtk_render_frame(style, cr, rect->x, rect->y, rect->width, rect->height);
     } else {
       gtk_render_activity(style, cr, rect->x, rect->y, rect->width, rect->height);
     }
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_get_tab_thickness(GtkStyleContext *style)
 {
     if (!notebook_has_tab_gap)
@@ -1498,19 +1449,18 @@ moz_gtk_get_tab_thickness(GtkStyleContex
         return 2; /* some themes don't set ythickness correctly */
 
     return border.top;
 }
 
 gint
 moz_gtk_get_tab_thickness(WidgetNodeType aNodeType)
 {
-    GtkStyleContext *style = ClaimStyleContext(aNodeType);
+    GtkStyleContext *style = GetStyleContext(aNodeType);
     int thickness = moz_gtk_get_tab_thickness(style);
-    ReleaseStyleContext(style);
     return thickness;
 }
 
 /* actual small tabs */
 static gint
 moz_gtk_tab_paint(cairo_t *cr, GdkRectangle* rect,
                   GtkWidgetState* state,
                   GtkTabFlags flags, GtkTextDirection direction,
@@ -1523,18 +1473,18 @@ moz_gtk_tab_paint(cairo_t *cr, GdkRectan
 
     GtkStyleContext* style;
     GdkRectangle tabRect;
     GdkRectangle focusRect;
     GdkRectangle backRect;
     int initial_gap = 0;
     bool isBottomTab = (widget == MOZ_GTK_TAB_BOTTOM);
 
-    style = ClaimStyleContext(widget, direction,
-                              GetStateFlagsFromGtkTabFlags(flags));
+    style = GetStyleContext(widget, direction,
+                            GetStateFlagsFromGtkTabFlags(flags));
     tabRect = *rect;
 
     if (flags & MOZ_GTK_TAB_FIRST) {
         gtk_style_context_get_style(style, "initial-gap", &initial_gap, NULL);
         tabRect.width -= initial_gap;
 
         if (direction != GTK_TEXT_DIR_RTL) {
             tabRect.x += initial_gap;
@@ -1601,17 +1551,17 @@ moz_gtk_tab_paint(cairo_t *cr, GdkRectan
             if (flags & MOZ_GTK_TAB_FIRST) {
                 if (direction == GTK_TEXT_DIR_RTL)
                     gap_roffset = initial_gap;
                 else
                     gap_loffset = initial_gap;
             }
 
             GtkStyleContext* panelStyle =
-                ClaimStyleContext(MOZ_GTK_TABPANELS, direction);
+                GetStyleContext(MOZ_GTK_TABPANELS, direction);
 
             if (isBottomTab) {
                 /* Draw the tab on bottom */
                 focusRect.y += gap_voffset;
                 focusRect.height -= gap_voffset;
 
                 gtk_render_extension(style, cr,
                                      tabRect.x, tabRect.y + gap_voffset, tabRect.width,
@@ -1676,27 +1626,26 @@ moz_gtk_tab_paint(cairo_t *cr, GdkRectan
       focusRect.x += padding.left;
       focusRect.width -= (padding.left + padding.right);
       focusRect.y += padding.top;
       focusRect.height -= (padding.top + padding.bottom);
 
       gtk_render_focus(style, cr,
                       focusRect.x, focusRect.y, focusRect.width, focusRect.height);
     }
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 /* tab area*/
 static gint
 moz_gtk_tabpanels_paint(cairo_t *cr, GdkRectangle* rect,
                         GtkTextDirection direction)
 {
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_TABPANELS, direction);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_TABPANELS, direction);
     gtk_render_background(style, cr, rect->x, rect->y, 
                           rect->width, rect->height);
     /*
      * The gap size is not needed in moz_gtk_tabpanels_paint because 
      * the gap will be painted with the foreground tab in moz_gtk_tab_paint.
      *
      * However, if moz_gtk_tabpanels_paint just uses gtk_render_frame(), 
      * the theme will think that there are no tabs and may draw something 
@@ -1723,17 +1672,16 @@ moz_gtk_tabpanels_paint(cairo_t *cr, Gdk
                     rect->y + rect->height);
     cairo_clip(cr);
     gtk_render_frame_gap(style, cr,
                          rect->x, rect->y,
                          rect->width, rect->height,
                          GTK_POS_TOP, 0, 1);
     cairo_restore(cr);
 
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_tab_scroll_arrow_paint(cairo_t *cr, GdkRectangle* rect,
                                GtkWidgetState* state,
                                GtkArrowType arrow_type,
                                GtkTextDirection direction)
@@ -1758,21 +1706,20 @@ moz_gtk_tab_scroll_arrow_paint(cairo_t *
     case GTK_ARROW_DOWN:
         arrow_angle = ARROW_DOWN;
         break;
     default:
         arrow_angle = ARROW_UP;
         break;      
     }
     if (arrow_type != GTK_ARROW_NONE)  {        
-        style = ClaimStyleContext(MOZ_GTK_TAB_SCROLLARROW, direction,
-                                  GetStateFlagsFromGtkWidgetState(state));
+        style = GetStyleContext(MOZ_GTK_TAB_SCROLLARROW, direction,
+                                GetStateFlagsFromGtkWidgetState(state));
         gtk_render_arrow(style, cr, arrow_angle,
                          x, y, arrow_size);
-        ReleaseStyleContext(style);
     }
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_menu_bar_paint(cairo_t *cr, GdkRectangle* rect,
                        GtkTextDirection direction)
 {
@@ -1828,17 +1775,17 @@ moz_gtk_menu_separator_paint(cairo_t *cr
         return MOZ_GTK_SUCCESS;
 
     GtkStyleContext* style;
     gboolean wide_separators;
     gint separator_height;
     gint x, y, w;
     GtkBorder padding;
 
-    style = ClaimStyleContext(MOZ_GTK_MENUSEPARATOR, direction);
+    style = GetStyleContext(MOZ_GTK_MENUSEPARATOR, direction);
     gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
 
     x = rect->x;
     y = rect->y;
     w = rect->width;
 
     gtk_style_context_save(style);
     gtk_style_context_add_class(style, GTK_STYLE_CLASS_SEPARATOR);
@@ -1858,17 +1805,16 @@ moz_gtk_menu_separator_paint(cairo_t *cr
       gtk_render_line(style, cr,
                       x + padding.left,
                       y + padding.top,
                       x + w - padding.right - 1,
                       y + padding.top);
     }
 
     gtk_style_context_restore(style);
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 // See gtk_menu_item_draw() for reference.
 static gint
 moz_gtk_menu_item_paint(WidgetNodeType widget, cairo_t *cr, GdkRectangle* rect,
                         GtkWidgetState* state, GtkTextDirection direction)
@@ -1878,17 +1824,17 @@ moz_gtk_menu_item_paint(WidgetNodeType w
     GtkStateFlags state_flags = GetStateFlagsFromGtkWidgetState(state);
 
     // GTK versions prior to 3.8 render the background and frame only when not
     // a separator and in hover prelight.
     if (minorVersion < 8 && (widget == MOZ_GTK_MENUSEPARATOR ||
                              !(state_flags & GTK_STATE_FLAG_PRELIGHT)))
         return MOZ_GTK_SUCCESS;
 
-    GtkStyleContext* style = ClaimStyleContext(widget, direction, state_flags);
+    GtkStyleContext* style = GetStyleContext(widget, direction, state_flags);
 
     if (minorVersion < 6) {
         // GTK+ 3.4 saves the style context and adds the menubar class to
         // menubar children, but does each of these only when drawing, not
         // during layout.
         gtk_style_context_save(style);
         if (widget == MOZ_GTK_MENUBARITEM) {
             gtk_style_context_add_class(style, GTK_STYLE_CLASS_MENUBAR);
@@ -1901,33 +1847,31 @@ moz_gtk_menu_item_paint(WidgetNodeType w
     h = rect->height;
 
     gtk_render_background(style, cr, x, y, w, h);
     gtk_render_frame(style, cr, x, y, w, h);
 
     if (minorVersion < 6) {
         gtk_style_context_restore(style);
     }
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_menu_arrow_paint(cairo_t *cr, GdkRectangle* rect,
                          GtkWidgetState* state,
                          GtkTextDirection direction)
 {
     GtkStateFlags state_flags = GetStateFlagsFromGtkWidgetState(state);
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_MENUITEM,
-                                               direction, state_flags);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_MENUITEM,
+                                             direction, state_flags);
     gtk_render_arrow(style, cr,
                     (direction == GTK_TEXT_DIR_LTR) ? ARROW_RIGHT : ARROW_LEFT,
                     rect->x, rect->y, rect->width);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 // For reference, see gtk_check_menu_item_size_allocate() in GTK versions after
 // 3.20 and gtk_real_check_menu_item_draw_indicator() in earlier versions.
 static gint
 moz_gtk_check_menu_item_paint(WidgetNodeType widgetType,
                               cairo_t *cr, GdkRectangle* rect,
@@ -1942,37 +1886,36 @@ moz_gtk_check_menu_item_paint(WidgetNode
     moz_gtk_menu_item_paint(MOZ_GTK_MENUITEM, cr, rect, state, direction);
 
     if (checked) {
       state_flags = static_cast<GtkStateFlags>(state_flags|checkbox_check_state);
     }
 
     bool pre_3_20 = gtk_get_minor_version() < 20;
     gint offset;
-    style = ClaimStyleContext(widgetType, direction);
+    style = GetStyleContext(widgetType, direction);
     gtk_style_context_get_style(style,
                                 "indicator-size", &indicator_size,
                                 "horizontal-padding", &horizontal_padding,
                                 NULL);
     if (pre_3_20) {
         GtkBorder padding;
         gtk_style_context_get_padding(style, state_flags, &padding);
         offset = horizontal_padding + padding.left + 2;
     } else {
         GdkRectangle r = { 0 };
         InsetByMargin(&r, style);
         InsetByBorderPadding(&r, style);
         offset = r.x;
     }
-    ReleaseStyleContext(style);
 
     bool isRadio = (widgetType == MOZ_GTK_RADIOMENUITEM);
     WidgetNodeType indicatorType = isRadio ? MOZ_GTK_RADIOMENUITEM_INDICATOR
                                            : MOZ_GTK_CHECKMENUITEM_INDICATOR;
-    style = ClaimStyleContext(indicatorType, direction, state_flags);
+    style = GetStyleContext(indicatorType, direction, state_flags);
 
     if (direction == GTK_TEXT_DIR_RTL) {
         x = rect->width - indicator_size - offset;
     }
     else {
         x = rect->x + offset;
     }
     y = rect->y + (rect->height - indicator_size) / 2;
@@ -1982,32 +1925,30 @@ moz_gtk_check_menu_item_paint(WidgetNode
         gtk_render_frame(style, cr, x, y, indicator_size, indicator_size);
     }
 
     if (isRadio) {
       gtk_render_option(style, cr, x, y, indicator_size, indicator_size);
     } else {
       gtk_render_check(style, cr, x, y, indicator_size, indicator_size);
     }
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static gint
 moz_gtk_info_bar_paint(cairo_t *cr, GdkRectangle* rect,
                        GtkWidgetState* state)
 {
     GtkStyleContext *style =
-        ClaimStyleContext(MOZ_GTK_INFO_BAR, GTK_TEXT_DIR_LTR,
-                          GetStateFlagsFromGtkWidgetState(state));
+        GetStyleContext(MOZ_GTK_INFO_BAR, GTK_TEXT_DIR_LTR,
+                        GetStateFlagsFromGtkWidgetState(state));
     gtk_render_background(style, cr, rect->x, rect->y, rect->width,
                           rect->height);
     gtk_render_frame(style, cr, rect->x, rect->y, rect->width, rect->height);
-    ReleaseStyleContext(style);
 
     return MOZ_GTK_SUCCESS;
 }
 
 static void
 moz_gtk_add_style_margin(GtkStyleContext* style,
                          gint* left, gint* top, gint* right, gint* bottom)
 {
@@ -2082,72 +2023,68 @@ moz_gtk_get_widget_border(WidgetNodeType
     GtkWidget* w;
     GtkStyleContext* style;
     *left = *top = *right = *bottom = 0;
 
     switch (widget) {
     case MOZ_GTK_BUTTON:
     case MOZ_GTK_TOOLBAR_BUTTON:
         {
-            style = ClaimStyleContext(MOZ_GTK_BUTTON);
+            style = GetStyleContext(MOZ_GTK_BUTTON);
 
             *left = *top = *right = *bottom =
                 gtk_container_get_border_width(GTK_CONTAINER(GetWidget(MOZ_GTK_BUTTON)));
 
             if (widget == MOZ_GTK_TOOLBAR_BUTTON) {
                 gtk_style_context_save(style);
                 gtk_style_context_add_class(style, "image-button");
             }
 
             moz_gtk_add_style_padding(style, left, top, right, bottom);
 
             if (widget == MOZ_GTK_TOOLBAR_BUTTON)
                 gtk_style_context_restore(style);
 
             moz_gtk_add_style_border(style, left, top, right, bottom);
 
-            ReleaseStyleContext(style);
             return MOZ_GTK_SUCCESS;
         }
     case MOZ_GTK_ENTRY:
         {
-            style = ClaimStyleContext(MOZ_GTK_ENTRY);
+            style = GetStyleContext(MOZ_GTK_ENTRY);
 
             // XXX: Subtract 1 pixel from the padding to account for the default
             // padding in forms.css. See bug 1187385.
             *left = *top = *right = *bottom = -1;
             moz_gtk_add_style_padding(style, left, top, right, bottom);
             moz_gtk_add_style_border(style, left, top, right, bottom);
 
-            ReleaseStyleContext(style);
             return MOZ_GTK_SUCCESS;
         }
     case MOZ_GTK_TEXT_VIEW:
     case MOZ_GTK_TREEVIEW:
         {
-            style = ClaimStyleContext(MOZ_GTK_SCROLLED_WINDOW);
+            style = GetStyleContext(MOZ_GTK_SCROLLED_WINDOW);
             moz_gtk_add_style_border(style, left, top, right, bottom);
-            ReleaseStyleContext(style);
             return MOZ_GTK_SUCCESS;
         }
     case MOZ_GTK_TREE_HEADER_CELL:
         {
             /* A Tree Header in GTK is just a different styled button
              * It must be placed in a TreeView for getting the correct style
              * assigned.
              * That is why the following code is the same as for MOZ_GTK_BUTTON.
              * */
             *left = *top = *right = *bottom =
                 gtk_container_get_border_width(GTK_CONTAINER(
                                                GetWidget(MOZ_GTK_TREE_HEADER_CELL)));
 
-            style = ClaimStyleContext(MOZ_GTK_TREE_HEADER_CELL);
+            style = GetStyleContext(MOZ_GTK_TREE_HEADER_CELL);
             moz_gtk_add_style_border(style, left, top, right, bottom);
             moz_gtk_add_style_padding(style, left, top, right, bottom);
-            ReleaseStyleContext(style);
             return MOZ_GTK_SUCCESS;
         }
     case MOZ_GTK_TREE_HEADER_SORTARROW:
         w = GetWidget(MOZ_GTK_TREE_HEADER_SORTARROW);
         break;
     case MOZ_GTK_DROPDOWN_ENTRY:
         w = GetWidget(MOZ_GTK_COMBOBOX_ENTRY_TEXTAREA);
         break;
@@ -2162,20 +2099,19 @@ moz_gtk_get_widget_border(WidgetNodeType
             gboolean wide_separators;
             gint separator_width;
             GtkRequisition arrow_req;
             GtkBorder border;
 
             *left = *top = *right = *bottom =
                 gtk_container_get_border_width(GTK_CONTAINER(
                                                GetWidget(MOZ_GTK_COMBOBOX_BUTTON)));
-            style = ClaimStyleContext(MOZ_GTK_COMBOBOX_BUTTON);
+            style = GetStyleContext(MOZ_GTK_COMBOBOX_BUTTON);
             moz_gtk_add_style_padding(style, left, top, right, bottom);
             moz_gtk_add_style_border(style, left, top, right, bottom);
-            ReleaseStyleContext(style);
 
             /* If there is no separator, don't try to count its width. */
             separator_width = 0;
             GtkWidget* comboBoxSeparator = GetWidget(MOZ_GTK_COMBOBOX_SEPARATOR);
             if (comboBoxSeparator) {
                 style = gtk_widget_get_style_context(comboBoxSeparator);
                 gtk_style_context_get_style(style,
                                             "wide-separators", &wide_separators,
@@ -2236,49 +2172,46 @@ moz_gtk_get_widget_border(WidgetNodeType
     case MOZ_GTK_MENUBARITEM:
     case MOZ_GTK_MENUITEM:
     case MOZ_GTK_CHECKMENUITEM:
     case MOZ_GTK_RADIOMENUITEM:
         {
             // Bug 1274143 for MOZ_GTK_MENUBARITEM
             WidgetNodeType type =
                 widget == MOZ_GTK_MENUBARITEM ? MOZ_GTK_MENUITEM : widget;
-            style = ClaimStyleContext(type);
+            style = GetStyleContext(type);
 
             if (gtk_get_minor_version() < 20) {
                 moz_gtk_add_style_padding(style, left, top, right, bottom);
             } else {
                 moz_gtk_add_margin_border_padding(style,
                                                   left, top, right, bottom);
             }
-            ReleaseStyleContext(style);
             return MOZ_GTK_SUCCESS;
         }
     case MOZ_GTK_INFO_BAR:
         w = GetWidget(MOZ_GTK_INFO_BAR);
         break;
     case MOZ_GTK_TOOLTIP:
         {
             // In GTK 3 there are 6 pixels of additional margin around the box.
             // See details there:
             // https://github.com/GNOME/gtk/blob/5ea69a136bd7e4970b3a800390e20314665aaed2/gtk/ui/gtktooltipwindow.ui#L11
             *left = *right = *top = *bottom = 6;
 
             // We also need to add margin/padding/borders from Tooltip content.
             // Tooltip contains horizontal box, where icon and label is put.
             // We ignore icon as long as we don't have support for it.
-            GtkStyleContext* boxStyle = ClaimStyleContext(MOZ_GTK_TOOLTIP_BOX);
+            GtkStyleContext* boxStyle = GetStyleContext(MOZ_GTK_TOOLTIP_BOX);
             moz_gtk_add_margin_border_padding(boxStyle,
                                               left, top, right, bottom);
-            ReleaseStyleContext(boxStyle);
-
-            GtkStyleContext* labelStyle = ClaimStyleContext(MOZ_GTK_TOOLTIP_BOX_LABEL);
+
+            GtkStyleContext* labelStyle = GetStyleContext(MOZ_GTK_TOOLTIP_BOX_LABEL);
             moz_gtk_add_margin_border_padding(labelStyle,
                                               left, top, right, bottom);
-            ReleaseStyleContext(labelStyle);
 
             return MOZ_GTK_SUCCESS;
         }
 
     /* These widgets have no borders, since they are not containers. */
     case MOZ_GTK_CHECKBUTTON_LABEL:
     case MOZ_GTK_RADIOBUTTON_LABEL:
     case MOZ_GTK_SPLITTER_HORIZONTAL:
@@ -2319,17 +2252,17 @@ moz_gtk_get_widget_border(WidgetNodeType
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_get_tab_border(gint* left, gint* top, gint* right, gint* bottom, 
                        GtkTextDirection direction, GtkTabFlags flags, 
                        WidgetNodeType widget)
 {
-    GtkStyleContext* style = ClaimStyleContext(widget, direction,
+    GtkStyleContext* style = GetStyleContext(widget, direction,
                               GetStateFlagsFromGtkTabFlags(flags));
 
     *left = *top = *right = *bottom = 0;
     moz_gtk_add_style_padding(style, left, top, right, bottom);
 
     // Gtk >= 3.20 does not use those styles
     if (gtk_check_version(3, 20, 0) != nullptr) {
         int tab_curvature;
@@ -2349,25 +2282,23 @@ moz_gtk_get_tab_border(gint* left, gint*
     } else {
         GtkBorder margin;
 
         gtk_style_context_get_margin(style, GTK_STATE_FLAG_NORMAL, &margin);
         *left += margin.left;
         *right += margin.right;
 
         if (flags & MOZ_GTK_TAB_FIRST) {
-            ReleaseStyleContext(style);
-            style = ClaimStyleContext(MOZ_GTK_NOTEBOOK_HEADER, direction);
+            style = GetStyleContext(MOZ_GTK_NOTEBOOK_HEADER, direction);
             gtk_style_context_get_margin(style, GTK_STATE_FLAG_NORMAL, &margin);
             *left += margin.left;
             *right += margin.right;
         }
     }
 
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_get_combo_box_entry_button_size(gint* width, gint* height)
 {
     /*
      * We get the requisition of the drop down button, which includes
@@ -2384,21 +2315,20 @@ moz_gtk_get_combo_box_entry_button_size(
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_get_tab_scroll_arrow_size(gint* width, gint* height)
 {
     gint arrow_size;
 
-    GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_TABPANELS);
+    GtkStyleContext *style = GetStyleContext(MOZ_GTK_TABPANELS);
     gtk_style_context_get_style(style,
                                 "scroll-arrow-hlength", &arrow_size,
                                 NULL);
-    ReleaseStyleContext(style);
 
     *height = *width = arrow_size;
 
     return MOZ_GTK_SUCCESS;
 }
 
 void
 moz_gtk_get_arrow_size(WidgetNodeType widgetType, gint* width, gint* height)
@@ -2421,147 +2351,140 @@ moz_gtk_get_arrow_size(WidgetNodeType wi
 
 gint
 moz_gtk_get_toolbar_separator_width(gint* size)
 {
     gboolean wide_separators;
     gint separator_width;
     GtkBorder border;
 
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_TOOLBAR);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_TOOLBAR);
     gtk_style_context_get_style(style,
                                 "space-size", size,
                                 "wide-separators",  &wide_separators,
                                 "separator-width", &separator_width,
                                 NULL);
     /* Just in case... */
     gtk_style_context_get_border(style, GTK_STATE_FLAG_NORMAL, &border);
     *size = MAX(*size, (wide_separators ? separator_width : border.left));
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_get_expander_size(gint* size)
 {
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_EXPANDER);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_EXPANDER);
     gtk_style_context_get_style(style,
                                 "expander-size", size,
                                 NULL);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 gint
 moz_gtk_get_treeview_expander_size(gint* size)
 {
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_TREEVIEW);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_TREEVIEW);
     gtk_style_context_get_style(style, "expander-size", size, NULL);
-    ReleaseStyleContext(style);
     return MOZ_GTK_SUCCESS;
 }
 
 // See gtk_menu_item_draw() for reference.
 gint
 moz_gtk_get_menu_separator_height(gint *size)
 {
     gboolean  wide_separators;
     gint      separator_height;
     GtkBorder padding;
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_MENUSEPARATOR);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_MENUSEPARATOR);
     gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
 
     gtk_style_context_save(style);
     gtk_style_context_add_class(style, GTK_STYLE_CLASS_SEPARATOR);
 
     gtk_style_context_get_style(style,
                                 "wide-separators",  &wide_separators,
                                 "separator-height", &separator_height,
                                 NULL);
 
     gtk_style_context_restore(style);
-    ReleaseStyleContext(style);
 
     *size = padding.top + padding.bottom;
     *size += (wide_separators) ? separator_height : 1;
 
     return MOZ_GTK_SUCCESS;
 }
 
 void
 moz_gtk_get_entry_min_height(gint* height)
 {
-    GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_ENTRY);
+    GtkStyleContext* style = GetStyleContext(MOZ_GTK_ENTRY);
     if (!gtk_check_version(3, 20, 0)) {
         gtk_style_context_get(style, gtk_style_context_get_state(style),
                               "min-height", height,
                               nullptr);
     } else {
         *height = 0;
     }
 
     GtkBorder border;
     GtkBorder padding;
     gtk_style_context_get_border(style, GTK_STATE_FLAG_NORMAL, &border);
     gtk_style_context_get_padding(style, GTK_STATE_FLAG_NORMAL, &padding);
 
     *height += (border.top + border.bottom + padding.top + padding.bottom);
-    ReleaseStyleContext(style);
 }
 
 void
 moz_gtk_get_scale_metrics(GtkOrientation orient, gint* scale_width,
                           gint* scale_height)
 {
   if (gtk_check_version(3, 20, 0) != nullptr) {
       WidgetNodeType widget = (orient == GTK_ORIENTATION_HORIZONTAL) ?
                                MOZ_GTK_SCALE_HORIZONTAL :
                                MOZ_GTK_SCALE_VERTICAL;
 
       gint thumb_length, thumb_height, trough_border;
       moz_gtk_get_scalethumb_metrics(orient, &thumb_length, &thumb_height);
 
-      GtkStyleContext* style = ClaimStyleContext(widget);
+      GtkStyleContext* style = GetStyleContext(widget);
       gtk_style_context_get_style(style, "trough-border", &trough_border, NULL);
 
       if (orient == GTK_ORIENTATION_HORIZONTAL) {
           *scale_width = thumb_length + trough_border * 2;
           *scale_height = thumb_height + trough_border * 2;
       } else {
           *scale_width = thumb_height + trough_border * 2;
           *scale_height = thumb_length + trough_border * 2;
       }
-      ReleaseStyleContext(style);
   } else {
       WidgetNodeType widget = (orient == GTK_ORIENTATION_HORIZONTAL) ?
                                MOZ_GTK_SCALE_TROUGH_HORIZONTAL :
                                MOZ_GTK_SCALE_TROUGH_VERTICAL;
       moz_gtk_get_widget_min_size(widget, scale_width, scale_height);
   }
 }
 
 gint
 moz_gtk_get_scalethumb_metrics(GtkOrientation orient, gint* thumb_length, gint* thumb_height)
 {
 
   if (gtk_check_version(3, 20, 0) != nullptr) {
       WidgetNodeType widget = (orient == GTK_ORIENTATION_HORIZONTAL) ?
                                MOZ_GTK_SCALE_HORIZONTAL:
                                MOZ_GTK_SCALE_VERTICAL;
-      GtkStyleContext* style = ClaimStyleContext(widget);
+      GtkStyleContext* style = GetStyleContext(widget);
       gtk_style_context_get_style(style,
                                   "slider_length", thumb_length,
                                   "slider_width", thumb_height,
                                   NULL);
-      ReleaseStyleContext(style);
   } else {
       WidgetNodeType widget = (orient == GTK_ORIENTATION_HORIZONTAL) ?
                                MOZ_GTK_SCALE_THUMB_HORIZONTAL:
                                MOZ_GTK_SCALE_THUMB_VERTICAL;
-      GtkStyleContext* style = ClaimStyleContext(widget);
+      GtkStyleContext* style = GetStyleContext(widget);
 
       gint min_width, min_height;
       GtkStateFlags state = gtk_style_context_get_state(style);
       gtk_style_context_get(style, state,
                             "min-width", &min_width,
                             "min-height", &min_height,
                              nullptr);
       GtkBorder margin;
@@ -2573,18 +2496,16 @@ moz_gtk_get_scalethumb_metrics(GtkOrient
       // so use bigger of those two values.
       if (min_width < -margin_width)
           min_width = -margin_width;
       if (min_height < -margin_height)
           min_height = -margin_height;
 
       *thumb_length = min_width;
       *thumb_height = min_height;
-
-      ReleaseStyleContext(style);
   }
 
   return MOZ_GTK_SUCCESS;
 }
 
 static MozGtkSize
 SizeFromLengthAndBreadth(GtkOrientation aOrientation,
                          gint aLength, gint aBreadth)
@@ -2601,17 +2522,17 @@ GetScrollbarMetrics(GtkOrientation aOrie
         return metrics;
 
     metrics->initialized = true;
 
     WidgetNodeType scrollbar = aOrientation == GTK_ORIENTATION_HORIZONTAL ?
         MOZ_GTK_SCROLLBAR_HORIZONTAL : MOZ_GTK_SCROLLBAR_VERTICAL;
 
     gboolean backward, forward, secondary_backward, secondary_forward;
-    GtkStyleContext* style = ClaimStyleContext(scrollbar);
+    GtkStyleContext* style = GetStyleContext(scrollbar);
     gtk_style_context_get_style(style,
                                 "has-backward-stepper", &backward,
                                 "has-forward-stepper", &forward,
                                 "has-secondary-backward-stepper",
                                 &secondary_backward,
                                 "has-secondary-forward-stepper",
                                 &secondary_forward, nullptr);
     bool hasButtons =
@@ -2621,17 +2542,16 @@ GetScrollbarMetrics(GtkOrientation aOrie
         gint slider_width, trough_border, stepper_size, min_slider_size;
 
         gtk_style_context_get_style(style,
                                     "slider-width", &slider_width,
                                     "trough-border", &trough_border,
                                     "stepper-size", &stepper_size,
                                     "min-slider-length", &min_slider_size,
                                     nullptr);
-        ReleaseStyleContext(style);
 
         metrics->size.thumb =
             SizeFromLengthAndBreadth(aOrientation, min_slider_size, slider_width);
         metrics->size.button =
             SizeFromLengthAndBreadth(aOrientation, stepper_size, slider_width);
         // overall scrollbar
         gint breadth = slider_width + 2 * trough_border;
         // Require room for the slider in the track if we don't have buttons.
@@ -2658,35 +2578,33 @@ GetScrollbarMetrics(GtkOrientation aOrie
         }
 
         return metrics;
     }
 
     // GTK version > 3.20
     // scrollbar
     metrics->border.scrollbar = GetMarginBorderPadding(style);
-    ReleaseStyleContext(style);
 
     WidgetNodeType contents, track, thumb;
     if (aOrientation == GTK_ORIENTATION_HORIZONTAL) {
         contents = MOZ_GTK_SCROLLBAR_CONTENTS_HORIZONTAL;
         track = MOZ_GTK_SCROLLBAR_TROUGH_HORIZONTAL;
         thumb = MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL;
     } else {
         contents = MOZ_GTK_SCROLLBAR_CONTENTS_VERTICAL;
         track = MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL;
         thumb = MOZ_GTK_SCROLLBAR_THUMB_VERTICAL;
     }
     // thumb
     metrics->size.thumb = GetMinMarginBox(thumb);
     // track
-    style = ClaimStyleContext(track);
+    style = GetStyleContext(track);
     metrics->border.track = GetMarginBorderPadding(style);
     MozGtkSize trackMinSize = GetMinContentBox(style) + metrics->border.track;
-    ReleaseStyleContext(style);
     MozGtkSize trackSizeForThumb = metrics->size.thumb + metrics->border.track;
     // button
     if (hasButtons) {
         metrics->size.button = GetMinMarginBox(MOZ_GTK_SCROLLBAR_BUTTON);
     } else {
         metrics->size.button = {0, 0};
     }
     if (aOrientation == GTK_ORIENTATION_HORIZONTAL) {
@@ -2714,19 +2632,18 @@ GetScrollbarMetrics(GtkOrientation aOrie
             // If extra is odd, then the thumb is 0.5 pixels to the left
             // of center as in gtk_range_compute_slider_position().
             metrics->border.track.left += extra / 2;
             metrics->border.track.right += extra - extra / 2;
             trackSizeForThumb.width += extra;
         }
     }
 
-    style = ClaimStyleContext(contents);
+    style = GetStyleContext(contents);
     GtkBorder contentsBorder = GetMarginBorderPadding(style);
-    ReleaseStyleContext(style);
 
     metrics->size.scrollbar =
         trackSizeForThumb + contentsBorder + metrics->border.scrollbar;
 
     return metrics;
 }
 
 /* cairo_t *cr argument has to be a system-cairo. */
@@ -2766,20 +2683,19 @@ moz_gtk_widget_paint(WidgetNodeType widg
         return moz_gtk_scrollbar_button_paint(cr, rect, state,
                                               (GtkScrollbarButtonFlags) flags,
                                               direction);
         break;
     case MOZ_GTK_SCROLLBAR_HORIZONTAL:
     case MOZ_GTK_SCROLLBAR_VERTICAL:
         if (flags & MOZ_GTK_TRACK_OPAQUE) {
             GtkStyleContext* style =
-                ClaimStyleContext(MOZ_GTK_WINDOW, direction);
+                GetStyleContext(MOZ_GTK_WINDOW, direction);
             gtk_render_background(style, cr,
                                   rect->x, rect->y, rect->width, rect->height);
-            ReleaseStyleContext(style);
         }
         if (gtk_check_version(3,20,0) == nullptr) {
           return moz_gtk_scrollbar_paint(widget, cr, rect, state, direction);
         } else {
           WidgetNodeType trough_widget = (widget == MOZ_GTK_SCROLLBAR_HORIZONTAL) ?
               MOZ_GTK_SCROLLBAR_TROUGH_HORIZONTAL : MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL;
           return moz_gtk_scrollbar_trough_paint(trough_widget, cr, rect,
                                                 state, direction);
@@ -2813,20 +2729,20 @@ moz_gtk_widget_paint(WidgetNodeType widg
     case MOZ_GTK_SPINBUTTON_UP:
     case MOZ_GTK_SPINBUTTON_DOWN:
         return moz_gtk_spin_updown_paint(cr, rect,
                                          (widget == MOZ_GTK_SPINBUTTON_DOWN),
                                          state, direction);
         break;
     case MOZ_GTK_SPINBUTTON_ENTRY:
         {
-            GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_SPINBUTTON_ENTRY,
-                                     direction, GetStateFlagsFromGtkWidgetState(state));
+            GtkStyleContext* style =
+                GetStyleContext(MOZ_GTK_SPINBUTTON_ENTRY, direction,
+                                GetStateFlagsFromGtkWidgetState(state));
             gint ret = moz_gtk_entry_paint(cr, rect, state, style);
-            ReleaseStyleContext(style);
             return ret;
         }
         break;
     case MOZ_GTK_GRIPPER:
         return moz_gtk_gripper_paint(cr, rect, state,
                                      direction);
         break;
     case MOZ_GTK_TREEVIEW:
@@ -2844,38 +2760,38 @@ moz_gtk_widget_paint(WidgetNodeType widg
                                                     direction);
         break;
     case MOZ_GTK_TREEVIEW_EXPANDER:
         return moz_gtk_treeview_expander_paint(cr, rect, state,
                                                (GtkExpanderStyle) flags, direction);
         break;
     case MOZ_GTK_ENTRY:
         {
-            GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_ENTRY,
-                                     direction, GetStateFlagsFromGtkWidgetState(state));
+            GtkStyleContext* style =
+                GetStyleContext(MOZ_GTK_ENTRY, direction,
+                                GetStateFlagsFromGtkWidgetState(state));
             gint ret = moz_gtk_entry_paint(cr, rect, state, style);
-            ReleaseStyleContext(style);
             return ret;
         }
     case MOZ_GTK_TEXT_VIEW:
         return moz_gtk_text_view_paint(cr, rect, state, direction);
         break;
     case MOZ_GTK_DROPDOWN:
         return moz_gtk_combo_box_paint(cr, rect, state, direction);
         break;
     case MOZ_GTK_DROPDOWN_ARROW:
         return moz_gtk_combo_box_entry_button_paint(cr, rect,
                                                     state, flags, direction);
         break;
     case MOZ_GTK_DROPDOWN_ENTRY:
         {
-            GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_COMBOBOX_ENTRY_TEXTAREA,
-                                     direction, GetStateFlagsFromGtkWidgetState(state));
+            GtkStyleContext* style =
+                GetStyleContext(MOZ_GTK_COMBOBOX_ENTRY_TEXTAREA, direction,
+                                GetStateFlagsFromGtkWidgetState(state));
             gint ret = moz_gtk_entry_paint(cr, rect, state, style);
-            ReleaseStyleContext(style);
             return ret;
         }
         break;
     case MOZ_GTK_CHECKBUTTON_CONTAINER:
     case MOZ_GTK_RADIOBUTTON_CONTAINER:
         return moz_gtk_container_paint(cr, rect, state, widget, direction);
         break;
     case MOZ_GTK_CHECKBUTTON_LABEL:
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -295,45 +295,42 @@ nsLookAndFeel::NativeGetColor(ColorID aI
         break;
     case eColorID_SpellCheckerUnderline:
       aColor = NS_RGB(0xff, 0, 0);
       break;
 
         // css2  http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
     case eColorID_activeborder: {
         // active window border
-        GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_WINDOW);
+        GtkStyleContext *style = GetStyleContext(MOZ_GTK_WINDOW);
         gtk_style_context_get_border_color(style,
                                            GTK_STATE_FLAG_NORMAL, &gdk_color);
         aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
-        ReleaseStyleContext(style);
         break;
     }
     case eColorID_inactiveborder: {
         // inactive window border
-        GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_WINDOW);
+        GtkStyleContext *style = GetStyleContext(MOZ_GTK_WINDOW);
         gtk_style_context_get_border_color(style,
                                            GTK_STATE_FLAG_INSENSITIVE,
                                            &gdk_color);
         aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
-        ReleaseStyleContext(style);
         break;
     }
     case eColorID_graytext: // disabled text in windows, menus, etc.
     case eColorID_inactivecaptiontext: // text in inactive window caption
         aColor = sMenuTextInactive;
         break;
     case eColorID_inactivecaption: {
         // inactive window caption
-        GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_WINDOW);
+        GtkStyleContext *style = GetStyleContext(MOZ_GTK_WINDOW);
         gtk_style_context_get_background_color(style,
                                                GTK_STATE_FLAG_INSENSITIVE, 
                                                &gdk_color);
         aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
-        ReleaseStyleContext(style);
         break;
     }
     case eColorID_infobackground:
         // tooltip background color
         aColor = sInfoBackground;
         break;
     case eColorID_infotext:
         // tooltip text color
@@ -389,30 +386,28 @@ nsLookAndFeel::NativeGetColor(ColorID aI
     case eColorID__moz_field:
         aColor = sMozFieldBackground;
         break;
     case eColorID__moz_fieldtext:
         aColor = sMozFieldText;
         break;
     case eColorID__moz_buttondefault: {
         // default button border color
-        GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_BUTTON);
+        GtkStyleContext *style = GetStyleContext(MOZ_GTK_BUTTON);
         gtk_style_context_get_border_color(style,
                                            GTK_STATE_FLAG_NORMAL, &gdk_color);
         aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
-        ReleaseStyleContext(style);
         break;
     }
     case eColorID__moz_buttonhoverface: {
-        GtkStyleContext *style = ClaimStyleContext(MOZ_GTK_BUTTON);
+        GtkStyleContext *style = GetStyleContext(MOZ_GTK_BUTTON);
         gtk_style_context_get_background_color(style,
                                                GTK_STATE_FLAG_PRELIGHT, 
                                                &gdk_color);
         aColor = GDK_RGBA_TO_NS_RGBA(gdk_color);
-        ReleaseStyleContext(style);
         break;
     }
     case eColorID__moz_buttonhovertext:
         aColor = sButtonHoverText;
         break;
     case eColorID__moz_menuhover:
         aColor = sMenuHover;
         break;
@@ -853,73 +848,65 @@ nsLookAndFeel::EnsureInit()
 
     // The label is not added to a parent widget, but shared for constructing
     // different style contexts.  The node hierarchy is constructed only on
     // the label style context.
     GtkWidget *labelWidget = gtk_label_new("M");
     g_object_ref_sink(labelWidget);
 
     // Scrollbar colors
-    style = ClaimStyleContext(MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL);
+    style = GetStyleContext(MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sMozScrollbar = GDK_RGBA_TO_NS_RGBA(color);
-    ReleaseStyleContext(style);
 
     // Window colors
-    style = ClaimStyleContext(MOZ_GTK_WINDOW);
+    style = GetStyleContext(MOZ_GTK_WINDOW);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sMozWindowBackground = GDK_RGBA_TO_NS_RGBA(color);
     gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sMozWindowText = GDK_RGBA_TO_NS_RGBA(color);
-    ReleaseStyleContext(style);
-    style = ClaimStyleContext(MOZ_GTK_WINDOW_CONTAINER);
+    style = GetStyleContext(MOZ_GTK_WINDOW_CONTAINER);
     {
         GtkStyleContext* labelStyle = CreateStyleForWidget(labelWidget, style);
         GetSystemFontInfo(labelStyle, &mDefaultFontName, &mDefaultFontStyle);
         g_object_unref(labelStyle);
     }
-    ReleaseStyleContext(style);
 
     // tooltip foreground and background
-    style = ClaimStyleContext(MOZ_GTK_TOOLTIP);
+    style = GetStyleContext(MOZ_GTK_TOOLTIP);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sInfoBackground = GDK_RGBA_TO_NS_RGBA(color);
-    ReleaseStyleContext(style);
 
-    style = ClaimStyleContext(MOZ_GTK_TOOLTIP_BOX_LABEL);
+    style = GetStyleContext(MOZ_GTK_TOOLTIP_BOX_LABEL);
     gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sInfoText = GDK_RGBA_TO_NS_RGBA(color);
-    ReleaseStyleContext(style);
 
-    style = ClaimStyleContext(MOZ_GTK_MENUITEM);
+    style = GetStyleContext(MOZ_GTK_MENUITEM);
     {
         GtkStyleContext* accelStyle =
             CreateStyleForWidget(gtk_accel_label_new("M"), style);
 
         GetSystemFontInfo(accelStyle, &mMenuFontName, &mMenuFontStyle);
 
         gtk_style_context_get_color(accelStyle, GTK_STATE_FLAG_NORMAL, &color);
         sMenuText = GDK_RGBA_TO_NS_RGBA(color);
         gtk_style_context_get_color(accelStyle, GTK_STATE_FLAG_INSENSITIVE, &color);
         sMenuTextInactive = GDK_RGBA_TO_NS_RGBA(color);
         g_object_unref(accelStyle);
     }
-    ReleaseStyleContext(style);
 
-    style = ClaimStyleContext(MOZ_GTK_MENUPOPUP);
+    style = GetStyleContext(MOZ_GTK_MENUPOPUP);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sMenuBackground = GDK_RGBA_TO_NS_RGBA(color);
-    ReleaseStyleContext(style);
 
-    style = ClaimStyleContext(MOZ_GTK_MENUITEM);
+    style = GetStyleContext(MOZ_GTK_MENUITEM);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
     sMenuHover = GDK_RGBA_TO_NS_RGBA(color);
     gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
     sMenuHoverText = GDK_RGBA_TO_NS_RGBA(color);
-    ReleaseStyleContext(style);
 
     GtkWidget *parent = gtk_fixed_new();
     GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
     GtkWidget *treeView = gtk_tree_view_new();
     GtkWidget *linkButton = gtk_link_button_new("http://example.com/");
     GtkWidget *menuBar = gtk_menu_bar_new();
     GtkWidget *menuBarItem = gtk_menu_item_new();
     GtkWidget *entry = gtk_entry_new();
@@ -932,97 +919,89 @@ nsLookAndFeel::EnsureInit()
     gtk_container_add(GTK_CONTAINER(window), parent);
     gtk_container_add(GTK_CONTAINER(parent), entry);
     gtk_container_add(GTK_CONTAINER(parent), textView);
     
     // Text colors
     GdkRGBA bgColor;
     // If the text window background is translucent, then the background of
     // the textview root node is visible.
-    style = ClaimStyleContext(MOZ_GTK_TEXT_VIEW);
+    style = GetStyleContext(MOZ_GTK_TEXT_VIEW);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL,
                                            &bgColor);
-    ReleaseStyleContext(style);
 
-    style = ClaimStyleContext(MOZ_GTK_TEXT_VIEW_TEXT);
+    style = GetStyleContext(MOZ_GTK_TEXT_VIEW_TEXT);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL,
                                            &color);
     ApplyColorOver(color, &bgColor);
     sMozFieldBackground = GDK_RGBA_TO_NS_RGBA(bgColor);
     gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sMozFieldText = GDK_RGBA_TO_NS_RGBA(color);
 
     // Selected text and background
     gtk_style_context_get_background_color(style,
         static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_SELECTED),
         &color);
     sTextSelectedBackground = GDK_RGBA_TO_NS_RGBA(color);
     gtk_style_context_get_color(style,
         static_cast<GtkStateFlags>(GTK_STATE_FLAG_FOCUSED|GTK_STATE_FLAG_SELECTED),
         &color);
     sTextSelectedText = GDK_RGBA_TO_NS_RGBA(color);
-    ReleaseStyleContext(style);
 
     // Button text color
-    style = ClaimStyleContext(MOZ_GTK_BUTTON);
+    style = GetStyleContext(MOZ_GTK_BUTTON);
     {
         GtkStyleContext* labelStyle = CreateStyleForWidget(labelWidget, style);
 
         GetSystemFontInfo(labelStyle, &mButtonFontName, &mButtonFontStyle);
 
         gtk_style_context_get_color(labelStyle, GTK_STATE_FLAG_NORMAL, &color);
         sButtonText = GDK_RGBA_TO_NS_RGBA(color);
         gtk_style_context_get_color(labelStyle, GTK_STATE_FLAG_PRELIGHT, &color);
         sButtonHoverText = GDK_RGBA_TO_NS_RGBA(color);
         g_object_unref(labelStyle);
     }
-    ReleaseStyleContext(style);
 
     // Combobox text color
-    style = ClaimStyleContext(MOZ_GTK_COMBOBOX_ENTRY_TEXTAREA);
+    style = GetStyleContext(MOZ_GTK_COMBOBOX_ENTRY_TEXTAREA);
     gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sComboBoxText = GDK_RGBA_TO_NS_RGBA(color);
-    ReleaseStyleContext(style);
 
     // Menubar text and hover text colors    
-    style = ClaimStyleContext(MOZ_GTK_MENUBARITEM);
+    style = GetStyleContext(MOZ_GTK_MENUBARITEM);
     gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sMenuBarText = GDK_RGBA_TO_NS_RGBA(color);
     gtk_style_context_get_color(style, GTK_STATE_FLAG_PRELIGHT, &color);
     sMenuBarHoverText = GDK_RGBA_TO_NS_RGBA(color);
-    ReleaseStyleContext(style);
 
     // GTK's guide to fancy odd row background colors:
     // 1) Check if a theme explicitly defines an odd row color
     // 2) If not, check if it defines an even row color, and darken it
     //    slightly by a hardcoded value (gtkstyle.c)
     // 3) If neither are defined, take the base background color and
     //    darken that by a hardcoded value
-    style = ClaimStyleContext(MOZ_GTK_TREEVIEW);
+    style = GetStyleContext(MOZ_GTK_TREEVIEW);
 
     // Get odd row background color
     gtk_style_context_save(style);
     gtk_style_context_add_region(style, GTK_STYLE_REGION_ROW, GTK_REGION_ODD);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &color);
     sOddCellBackground = GDK_RGBA_TO_NS_RGBA(color);
     gtk_style_context_restore(style);
-    ReleaseStyleContext(style);
 
     // GtkFrame has a "border" subnode on which Adwaita draws the border.
     // Some themes do not draw on this node but draw a border on the widget
     // root node, so check the root node if no border is found on the border
     // node.
-    style = ClaimStyleContext(MOZ_GTK_FRAME_BORDER);
+    style = GetStyleContext(MOZ_GTK_FRAME_BORDER);
     bool themeUsesColors =
         GetBorderColors(style, &sFrameOuterLightBorder, &sFrameInnerDarkBorder);
-    ReleaseStyleContext(style);
     if (!themeUsesColors) {
-        style = ClaimStyleContext(MOZ_GTK_FRAME);
+        style = GetStyleContext(MOZ_GTK_FRAME);
         GetBorderColors(style, &sFrameOuterLightBorder, &sFrameInnerDarkBorder);
-        ReleaseStyleContext(style);
     }
 
     // GtkInfoBar
     // TODO - Use WidgetCache for it?
     GtkWidget* infoBar = gtk_info_bar_new();
     GtkWidget* infoBarContent = gtk_info_bar_get_content_area(GTK_INFO_BAR(infoBar));
     GtkWidget* infoBarLabel = gtk_label_new(nullptr);
     gtk_container_add(GTK_CONTAINER(parent), infoBar);