--- a/widget/gtk/gtk3drawing.cpp
+++ b/widget/gtk/gtk3drawing.cpp
@@ -13,17 +13,16 @@
#include <string.h>
#include "gtkdrawing.h"
#include "mozilla/Assertions.h"
#include "prinrval.h"
#include "WidgetStyleCache.h"
#include <math.h>
-static GtkWidget* gProtoWindow;
static GtkWidget* gProtoLayout;
static GtkWidget* gButtonWidget;
static GtkWidget* gToggleButtonWidget;
static GtkWidget* gButtonArrowWidget;
static GtkWidget* gSpinWidget;
static GtkWidget* gHScaleWidget;
static GtkWidget* gVScaleWidget;
static GtkWidget* gEntryWidget;
@@ -101,25 +100,16 @@ moz_gtk_set_widget_name(GtkWidget* widge
gint
moz_gtk_enable_style_props(style_prop_t styleGetProp)
{
style_prop_func = styleGetProp;
return MOZ_GTK_SUCCESS;
}
static gint
-ensure_window_widget()
-{
- if (!gProtoWindow) {
- gProtoWindow = GetWidget(MOZ_GTK_WINDOW);
- }
- return MOZ_GTK_SUCCESS;
-}
-
-static gint
setup_widget_prototype(GtkWidget* widget)
{
if (!gProtoLayout) {
gProtoLayout = GetWidget(MOZ_GTK_WINDOW_CONTAINER);
}
gtk_container_add(GTK_CONTAINER(gProtoLayout), widget);
return MOZ_GTK_SUCCESS;
}
@@ -215,17 +205,17 @@ ensure_entry_widget()
/* We need to have pointers to the inner widgets (button, separator, arrow)
* of the ComboBox to get the correct rendering from theme engines which
* special cases their look. Since the inner layout can change, we ask GTK
* to NULL our pointers when they are about to become invalid because the
* corresponding widgets don't exist anymore. It's the role of
* g_object_add_weak_pointer().
* Note that if we don't find the inner widgets (which shouldn't happen), we
* fallback to use generic "non-inner" widgets, and they don't need that kind
- * of weak pointer since they are explicit children of gProtoWindow and as
+ * of weak pointer since they are explicit children of gProtoLayout and as
* such GTK holds a strong reference to them. */
static void
moz_gtk_get_combo_box_inner_button(GtkWidget *widget, gpointer client_data)
{
if (GTK_IS_TOGGLE_BUTTON(widget)) {
gComboBoxButtonWidget = widget;
g_object_add_weak_pointer(G_OBJECT(widget),
(gpointer *) &gComboBoxButtonWidget);
@@ -323,17 +313,17 @@ ensure_info_bar()
/* We need to have pointers to the inner widgets (entry, button, arrow) of
* the ComboBoxEntry to get the correct rendering from theme engines which
* special cases their look. Since the inner layout can change, we ask GTK
* to NULL our pointers when they are about to become invalid because the
* corresponding widgets don't exist anymore. It's the role of
* g_object_add_weak_pointer().
* Note that if we don't find the inner widgets (which shouldn't happen), we
* fallback to use generic "non-inner" widgets, and they don't need that kind
- * of weak pointer since they are explicit children of gProtoWindow and as
+ * of weak pointer since they are explicit children of gProtoLayout and as
* such GTK holds a strong reference to them. */
static void
moz_gtk_get_combo_box_entry_inner_widgets(GtkWidget *widget,
gpointer client_data)
{
if (GTK_IS_TOGGLE_BUTTON(widget)) {
gComboBoxEntryButtonWidget = widget;
g_object_add_weak_pointer(G_OBJECT(widget),
@@ -757,27 +747,25 @@ moz_gtk_splitter_get_metrics(gint orient
}
return MOZ_GTK_SUCCESS;
}
static gint
moz_gtk_window_paint(cairo_t *cr, GdkRectangle* rect,
GtkTextDirection direction)
{
- GtkStyleContext* style;
-
- ensure_window_widget();
- gtk_widget_set_direction(gProtoWindow, direction);
-
- style = gtk_widget_get_style_context(gProtoWindow);
+ GtkStyleContext* style = ClaimStyleContext(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)
@@ -1052,19 +1040,20 @@ moz_gtk_scrollbar_button_paint(cairo_t *
static gint
moz_gtk_scrollbar_trough_paint(WidgetNodeType widget,
cairo_t *cr, GdkRectangle* rect,
GtkWidgetState* state,
GtkScrollbarTrackFlags flags,
GtkTextDirection direction)
{
if (flags & MOZ_GTK_TRACK_OPAQUE) {
- GtkStyleContext* style =
- gtk_widget_get_style_context(GTK_WIDGET(gProtoWindow));
- gtk_render_background(style, cr, rect->x, rect->y, rect->width, rect->height);
+ GtkStyleContext* style = ClaimStyleContext(MOZ_GTK_WINDOW, direction);
+ gtk_render_background(style, cr,
+ rect->x, rect->y, rect->width, rect->height);
+ ReleaseStyleContext(style);
}
GtkStyleContext* style =
ClaimStyleContext(widget == MOZ_GTK_SCROLLBAR_HORIZONTAL ?
MOZ_GTK_SCROLLBAR_TROUGH_HORIZONTAL :
MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL,
direction);
@@ -3303,17 +3292,16 @@ moz_gtk_shutdown()
/* This will destroy all of our widgets */
ResetWidgetCache();
/* TODO - replace it with appropriate widget */
if (gTreeHeaderSortArrowWidget)
gtk_widget_destroy(gTreeHeaderSortArrowWidget);
- gProtoWindow = NULL;
gProtoLayout = NULL;
gButtonWidget = NULL;
gToggleButtonWidget = NULL;
gButtonArrowWidget = NULL;
gSpinWidget = NULL;
gHScaleWidget = NULL;
gVScaleWidget = NULL;
gEntryWidget = NULL;