2016-05-09 02:08:26 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
- implement GtkTextDirection
|
|
|
|
- implement StyleFlags
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "WidgetStyleCache.h"
|
|
|
|
#include "gtkdrawing.h"
|
|
|
|
|
|
|
|
static GtkWidget* sWidgetStorage[MOZ_GTK_WIDGET_NODE_COUNT];
|
|
|
|
static GtkStyleContext* sStyleStorage[MOZ_GTK_WIDGET_NODE_COUNT];
|
|
|
|
|
|
|
|
static bool sStyleContextNeedsRestore;
|
|
|
|
#ifdef DEBUG
|
|
|
|
static GtkStyleContext* sCurrentStyleContext;
|
|
|
|
#endif
|
|
|
|
static GtkStyleContext*
|
2016-06-07 03:49:00 +03:00
|
|
|
GetCssNodeStyleInternal(WidgetNodeType aNodeType);
|
2016-05-09 02:08:26 +03:00
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
CreateWindowWidget()
|
|
|
|
{
|
|
|
|
GtkWidget *widget = gtk_window_new(GTK_WINDOW_POPUP);
|
|
|
|
gtk_widget_realize(widget);
|
|
|
|
gtk_widget_set_name(widget, "MozillaGtkWidget");
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
CreateWindowContainerWidget()
|
|
|
|
{
|
|
|
|
GtkWidget *widget = gtk_fixed_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(GetWidget(MOZ_GTK_WINDOW)), widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AddToWindowContainer(GtkWidget* widget)
|
|
|
|
{
|
|
|
|
gtk_container_add(GTK_CONTAINER(GetWidget(MOZ_GTK_WINDOW_CONTAINER)), widget);
|
|
|
|
gtk_widget_realize(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
CreateScrollbarWidget(WidgetNodeType aWidgetType, GtkOrientation aOrientation)
|
|
|
|
{
|
|
|
|
GtkWidget* widget = gtk_scrollbar_new(aOrientation, nullptr);
|
|
|
|
AddToWindowContainer(widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2016-05-13 02:59:17 +03:00
|
|
|
static GtkWidget*
|
|
|
|
CreateCheckboxWidget()
|
|
|
|
{
|
|
|
|
GtkWidget* widget = gtk_check_button_new_with_label("M");
|
|
|
|
AddToWindowContainer(widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
CreateRadiobuttonWidget()
|
|
|
|
{
|
|
|
|
GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "M");
|
|
|
|
AddToWindowContainer(widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2016-05-17 09:24:55 +03:00
|
|
|
static GtkWidget*
|
|
|
|
CreateMenuBarWidget()
|
|
|
|
{
|
|
|
|
GtkWidget* widget = gtk_menu_bar_new();
|
|
|
|
AddToWindowContainer(widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
CreateMenuPopupWidget()
|
|
|
|
{
|
|
|
|
GtkWidget* widget = gtk_menu_new();
|
|
|
|
gtk_menu_attach_to_widget(GTK_MENU(widget), GetWidget(MOZ_GTK_WINDOW),
|
|
|
|
nullptr);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
CreateMenuItemWidget(WidgetNodeType aShellType)
|
|
|
|
{
|
|
|
|
GtkWidget* widget = gtk_menu_item_new();
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(GetWidget(aShellType)), widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2016-05-24 14:43:00 +03:00
|
|
|
static GtkWidget*
|
|
|
|
CreateProgressWidget()
|
|
|
|
{
|
|
|
|
GtkWidget* widget = gtk_progress_bar_new();
|
|
|
|
AddToWindowContainer(widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2016-06-07 07:22:00 +03:00
|
|
|
static GtkWidget*
|
|
|
|
CreateTooltipWidget()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(gtk_check_version(3, 20, 0) != nullptr,
|
|
|
|
"CreateTooltipWidget should be used for Gtk < 3.20 only.");
|
|
|
|
GtkWidget* widget = CreateWindowWidget();
|
|
|
|
GtkStyleContext* style = gtk_widget_get_style_context(widget);
|
|
|
|
gtk_style_context_add_class(style, GTK_STYLE_CLASS_TOOLTIP);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2016-07-18 05:27:00 +03:00
|
|
|
static GtkWidget*
|
|
|
|
CreateExpanderWidget()
|
|
|
|
{
|
|
|
|
GtkWidget* widget = gtk_expander_new("M");
|
|
|
|
AddToWindowContainer(widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2016-07-18 06:29:00 +03:00
|
|
|
static GtkWidget*
|
|
|
|
CreateFrameWidget()
|
|
|
|
{
|
|
|
|
GtkWidget* widget = gtk_frame_new(nullptr);
|
|
|
|
AddToWindowContainer(widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
CreateGripperWidget()
|
|
|
|
{
|
|
|
|
GtkWidget* widget = gtk_handle_box_new();
|
|
|
|
AddToWindowContainer(widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
CreateToolbarWidget()
|
|
|
|
{
|
|
|
|
GtkWidget* widget = gtk_toolbar_new();
|
|
|
|
gtk_container_add(GTK_CONTAINER(GetWidget(MOZ_GTK_GRIPPER)), widget);
|
|
|
|
gtk_widget_realize(widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
CreateToolbarSeparatorWidget()
|
|
|
|
{
|
|
|
|
GtkWidget* widget = GTK_WIDGET(gtk_separator_tool_item_new());
|
|
|
|
AddToWindowContainer(widget);
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2016-05-09 02:08:26 +03:00
|
|
|
static GtkWidget*
|
|
|
|
CreateWidget(WidgetNodeType aWidgetType)
|
|
|
|
{
|
|
|
|
switch (aWidgetType) {
|
|
|
|
case MOZ_GTK_WINDOW:
|
|
|
|
return CreateWindowWidget();
|
|
|
|
case MOZ_GTK_WINDOW_CONTAINER:
|
|
|
|
return CreateWindowContainerWidget();
|
2016-05-24 14:43:00 +03:00
|
|
|
case MOZ_GTK_CHECKBUTTON_CONTAINER:
|
|
|
|
return CreateCheckboxWidget();
|
|
|
|
case MOZ_GTK_PROGRESSBAR:
|
|
|
|
return CreateProgressWidget();
|
|
|
|
case MOZ_GTK_RADIOBUTTON_CONTAINER:
|
|
|
|
return CreateRadiobuttonWidget();
|
2016-05-09 02:08:26 +03:00
|
|
|
case MOZ_GTK_SCROLLBAR_HORIZONTAL:
|
|
|
|
return CreateScrollbarWidget(aWidgetType,
|
|
|
|
GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
case MOZ_GTK_SCROLLBAR_VERTICAL:
|
|
|
|
return CreateScrollbarWidget(aWidgetType,
|
|
|
|
GTK_ORIENTATION_VERTICAL);
|
2016-05-17 09:24:55 +03:00
|
|
|
case MOZ_GTK_MENUBAR:
|
|
|
|
return CreateMenuBarWidget();
|
|
|
|
case MOZ_GTK_MENUPOPUP:
|
|
|
|
return CreateMenuPopupWidget();
|
|
|
|
case MOZ_GTK_MENUBARITEM:
|
|
|
|
return CreateMenuItemWidget(MOZ_GTK_MENUBAR);
|
|
|
|
case MOZ_GTK_MENUITEM:
|
|
|
|
return CreateMenuItemWidget(MOZ_GTK_MENUPOPUP);
|
2016-07-18 05:27:00 +03:00
|
|
|
case MOZ_GTK_EXPANDER:
|
|
|
|
return CreateExpanderWidget();
|
2016-07-18 06:29:00 +03:00
|
|
|
case MOZ_GTK_FRAME:
|
|
|
|
return CreateFrameWidget();
|
|
|
|
case MOZ_GTK_GRIPPER:
|
|
|
|
return CreateGripperWidget();
|
|
|
|
case MOZ_GTK_TOOLBAR:
|
|
|
|
return CreateToolbarWidget();
|
|
|
|
case MOZ_GTK_TOOLBAR_SEPARATOR:
|
|
|
|
return CreateToolbarSeparatorWidget();
|
2016-05-09 02:08:26 +03:00
|
|
|
default:
|
|
|
|
/* Not implemented */
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget*
|
|
|
|
GetWidget(WidgetNodeType aWidgetType)
|
|
|
|
{
|
|
|
|
GtkWidget* widget = sWidgetStorage[aWidgetType];
|
|
|
|
if (!widget) {
|
|
|
|
widget = CreateWidget(aWidgetType);
|
|
|
|
sWidgetStorage[aWidgetType] = widget;
|
|
|
|
}
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2016-06-07 09:06:04 +03:00
|
|
|
GtkStyleContext*
|
|
|
|
CreateStyleForWidget(GtkWidget* aWidget, GtkStyleContext* aParentStyle)
|
|
|
|
{
|
2016-06-22 07:46:24 +03:00
|
|
|
GtkWidgetPath* path = aParentStyle ?
|
|
|
|
gtk_widget_path_copy(gtk_style_context_get_path(aParentStyle)) :
|
|
|
|
gtk_widget_path_new();
|
2016-06-07 09:06:04 +03:00
|
|
|
|
|
|
|
// Work around https://bugzilla.gnome.org/show_bug.cgi?id=767312
|
|
|
|
// which exists in GTK+ 3.20.
|
|
|
|
gtk_widget_get_style_context(aWidget);
|
|
|
|
|
|
|
|
gtk_widget_path_append_for_widget(path, aWidget);
|
|
|
|
// Release any floating reference on aWidget.
|
|
|
|
g_object_ref_sink(aWidget);
|
|
|
|
g_object_unref(aWidget);
|
|
|
|
|
|
|
|
GtkStyleContext *context = gtk_style_context_new();
|
|
|
|
gtk_style_context_set_path(context, path);
|
|
|
|
gtk_style_context_set_parent(context, aParentStyle);
|
|
|
|
gtk_widget_path_unref(path);
|
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2016-06-07 03:49:00 +03:00
|
|
|
GtkStyleContext*
|
|
|
|
CreateCSSNode(const char* aName, GtkStyleContext* aParentStyle, GType aType)
|
2016-05-09 02:08:26 +03:00
|
|
|
{
|
|
|
|
static auto sGtkWidgetPathIterSetObjectName =
|
|
|
|
reinterpret_cast<void (*)(GtkWidgetPath *, gint, const char *)>
|
|
|
|
(dlsym(RTLD_DEFAULT, "gtk_widget_path_iter_set_object_name"));
|
|
|
|
|
2016-06-07 03:49:00 +03:00
|
|
|
GtkWidgetPath* path = aParentStyle ?
|
|
|
|
gtk_widget_path_copy(gtk_style_context_get_path(aParentStyle)) :
|
|
|
|
gtk_widget_path_new();
|
2016-05-09 02:08:26 +03:00
|
|
|
|
2016-06-07 03:49:00 +03:00
|
|
|
gtk_widget_path_append_type(path, aType);
|
2016-05-09 02:08:26 +03:00
|
|
|
|
|
|
|
(*sGtkWidgetPathIterSetObjectName)(path, -1, aName);
|
|
|
|
|
|
|
|
GtkStyleContext *context = gtk_style_context_new();
|
|
|
|
gtk_style_context_set_path(context, path);
|
|
|
|
gtk_style_context_set_parent(context, aParentStyle);
|
|
|
|
gtk_widget_path_unref(path);
|
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkStyleContext*
|
2016-06-07 03:49:00 +03:00
|
|
|
CreateChildCSSNode(const char* aName, WidgetNodeType aParentNodeType)
|
2016-05-09 02:08:26 +03:00
|
|
|
{
|
2016-06-07 03:49:00 +03:00
|
|
|
return CreateCSSNode(aName, GetCssNodeStyleInternal(aParentNodeType));
|
2016-05-09 02:08:26 +03:00
|
|
|
}
|
|
|
|
|
2016-07-18 06:29:00 +03:00
|
|
|
static GtkStyleContext*
|
|
|
|
GetWidgetStyleWithClass(WidgetNodeType aWidgetType, const gchar* aStyleClass)
|
|
|
|
{
|
|
|
|
GtkStyleContext* style = gtk_widget_get_style_context(GetWidget(aWidgetType));
|
|
|
|
gtk_style_context_save(style);
|
|
|
|
MOZ_ASSERT(!sStyleContextNeedsRestore);
|
|
|
|
sStyleContextNeedsRestore = true;
|
|
|
|
gtk_style_context_add_class(style, aStyleClass);
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2016-06-07 03:49:00 +03:00
|
|
|
/* GetCssNodeStyleInternal is used by Gtk >= 3.20 */
|
2016-05-09 02:08:26 +03:00
|
|
|
static GtkStyleContext*
|
2016-06-07 03:49:00 +03:00
|
|
|
GetCssNodeStyleInternal(WidgetNodeType aNodeType)
|
2016-05-09 02:08:26 +03:00
|
|
|
{
|
2016-06-07 03:49:00 +03:00
|
|
|
GtkStyleContext* style = sStyleStorage[aNodeType];
|
|
|
|
if (style)
|
|
|
|
return style;
|
|
|
|
|
2016-05-09 02:08:26 +03:00
|
|
|
switch (aNodeType) {
|
2016-06-13 05:35:00 +03:00
|
|
|
case MOZ_GTK_SCROLLBAR_CONTENTS_HORIZONTAL:
|
|
|
|
style = CreateChildCSSNode("contents",
|
|
|
|
MOZ_GTK_SCROLLBAR_HORIZONTAL);
|
|
|
|
break;
|
2016-05-09 02:08:26 +03:00
|
|
|
case MOZ_GTK_SCROLLBAR_TROUGH_HORIZONTAL:
|
2016-06-07 03:49:00 +03:00
|
|
|
style = CreateChildCSSNode(GTK_STYLE_CLASS_TROUGH,
|
2016-06-13 05:35:00 +03:00
|
|
|
MOZ_GTK_SCROLLBAR_CONTENTS_HORIZONTAL);
|
2016-06-07 03:49:00 +03:00
|
|
|
break;
|
2016-05-09 02:08:26 +03:00
|
|
|
case MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL:
|
2016-06-07 03:49:00 +03:00
|
|
|
style = CreateChildCSSNode(GTK_STYLE_CLASS_SLIDER,
|
|
|
|
MOZ_GTK_SCROLLBAR_TROUGH_HORIZONTAL);
|
2016-05-13 02:59:17 +03:00
|
|
|
break;
|
2016-06-13 05:35:00 +03:00
|
|
|
case MOZ_GTK_SCROLLBAR_CONTENTS_VERTICAL:
|
|
|
|
style = CreateChildCSSNode("contents",
|
|
|
|
MOZ_GTK_SCROLLBAR_VERTICAL);
|
|
|
|
break;
|
2016-05-09 02:08:26 +03:00
|
|
|
case MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL:
|
2016-06-07 03:49:00 +03:00
|
|
|
style = CreateChildCSSNode(GTK_STYLE_CLASS_TROUGH,
|
2016-06-13 05:35:00 +03:00
|
|
|
MOZ_GTK_SCROLLBAR_CONTENTS_VERTICAL);
|
2016-06-07 03:49:00 +03:00
|
|
|
break;
|
2016-05-09 02:08:26 +03:00
|
|
|
case MOZ_GTK_SCROLLBAR_THUMB_VERTICAL:
|
2016-06-07 03:49:00 +03:00
|
|
|
style = CreateChildCSSNode(GTK_STYLE_CLASS_SLIDER,
|
|
|
|
MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL);
|
2016-05-13 02:59:17 +03:00
|
|
|
break;
|
|
|
|
case MOZ_GTK_RADIOBUTTON:
|
2016-06-07 03:49:00 +03:00
|
|
|
style = CreateChildCSSNode(GTK_STYLE_CLASS_RADIO,
|
|
|
|
MOZ_GTK_RADIOBUTTON_CONTAINER);
|
2016-05-13 02:59:17 +03:00
|
|
|
break;
|
|
|
|
case MOZ_GTK_CHECKBUTTON:
|
2016-06-07 03:49:00 +03:00
|
|
|
style = CreateChildCSSNode(GTK_STYLE_CLASS_CHECK,
|
|
|
|
MOZ_GTK_CHECKBUTTON_CONTAINER);
|
2016-05-24 14:43:00 +03:00
|
|
|
break;
|
|
|
|
case MOZ_GTK_PROGRESS_TROUGH:
|
|
|
|
/* Progress bar background (trough) */
|
2016-06-07 03:49:00 +03:00
|
|
|
style = CreateChildCSSNode(GTK_STYLE_CLASS_TROUGH,
|
|
|
|
MOZ_GTK_PROGRESSBAR);
|
|
|
|
break;
|
2016-05-24 14:43:00 +03:00
|
|
|
case MOZ_GTK_PROGRESS_CHUNK:
|
2016-06-07 03:49:00 +03:00
|
|
|
style = CreateChildCSSNode("progress",
|
|
|
|
MOZ_GTK_PROGRESS_TROUGH);
|
2016-05-13 02:59:17 +03:00
|
|
|
break;
|
2016-06-07 07:22:00 +03:00
|
|
|
case MOZ_GTK_TOOLTIP:
|
|
|
|
// We create this from the path because GtkTooltipWindow is not public.
|
|
|
|
style = CreateCSSNode("tooltip", nullptr, GTK_TYPE_TOOLTIP);
|
|
|
|
gtk_style_context_add_class(style, GTK_STYLE_CLASS_BACKGROUND);
|
|
|
|
break;
|
2016-07-18 06:29:00 +03:00
|
|
|
case MOZ_GTK_GRIPPER:
|
|
|
|
// TODO - create from CSS node
|
|
|
|
return GetWidgetStyleWithClass(MOZ_GTK_GRIPPER,
|
|
|
|
GTK_STYLE_CLASS_GRIP);
|
2016-06-07 03:49:00 +03:00
|
|
|
default:
|
|
|
|
// TODO - create style from style path
|
|
|
|
GtkWidget* widget = GetWidget(aNodeType);
|
|
|
|
return gtk_widget_get_style_context(widget);
|
2016-05-09 02:08:26 +03:00
|
|
|
}
|
2016-05-13 02:59:17 +03:00
|
|
|
|
2016-06-22 07:46:24 +03:00
|
|
|
MOZ_ASSERT(style, "missing style context for node type");
|
|
|
|
sStyleStorage[aNodeType] = style;
|
|
|
|
return style;
|
2016-05-09 02:08:26 +03:00
|
|
|
}
|
|
|
|
|
2016-06-07 03:49:00 +03:00
|
|
|
/* GetWidgetStyleInternal is used by Gtk < 3.20 */
|
|
|
|
static GtkStyleContext*
|
|
|
|
GetWidgetStyleInternal(WidgetNodeType aNodeType)
|
|
|
|
{
|
|
|
|
switch (aNodeType) {
|
|
|
|
case MOZ_GTK_SCROLLBAR_TROUGH_HORIZONTAL:
|
|
|
|
return GetWidgetStyleWithClass(MOZ_GTK_SCROLLBAR_HORIZONTAL,
|
|
|
|
GTK_STYLE_CLASS_TROUGH);
|
|
|
|
case MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL:
|
|
|
|
return GetWidgetStyleWithClass(MOZ_GTK_SCROLLBAR_HORIZONTAL,
|
|
|
|
GTK_STYLE_CLASS_SLIDER);
|
|
|
|
case MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL:
|
|
|
|
return GetWidgetStyleWithClass(MOZ_GTK_SCROLLBAR_VERTICAL,
|
|
|
|
GTK_STYLE_CLASS_TROUGH);
|
|
|
|
case MOZ_GTK_SCROLLBAR_THUMB_VERTICAL:
|
|
|
|
return GetWidgetStyleWithClass(MOZ_GTK_SCROLLBAR_VERTICAL,
|
|
|
|
GTK_STYLE_CLASS_SLIDER);
|
|
|
|
case MOZ_GTK_RADIOBUTTON:
|
|
|
|
return GetWidgetStyleWithClass(MOZ_GTK_RADIOBUTTON_CONTAINER,
|
|
|
|
GTK_STYLE_CLASS_RADIO);
|
|
|
|
case MOZ_GTK_CHECKBUTTON:
|
|
|
|
return GetWidgetStyleWithClass(MOZ_GTK_CHECKBUTTON_CONTAINER,
|
|
|
|
GTK_STYLE_CLASS_CHECK);
|
|
|
|
case MOZ_GTK_PROGRESS_TROUGH:
|
|
|
|
return GetWidgetStyleWithClass(MOZ_GTK_PROGRESSBAR,
|
|
|
|
GTK_STYLE_CLASS_TROUGH);
|
2016-06-22 07:46:24 +03:00
|
|
|
case MOZ_GTK_TOOLTIP: {
|
|
|
|
GtkStyleContext* style = sStyleStorage[aNodeType];
|
|
|
|
if (style)
|
|
|
|
return style;
|
|
|
|
|
|
|
|
// The tooltip style class is added first in CreateTooltipWidget() so
|
|
|
|
// that gtk_widget_path_append_for_widget() in CreateStyleForWidget()
|
|
|
|
// will find it.
|
|
|
|
GtkWidget* tooltipWindow = CreateTooltipWidget();
|
|
|
|
style = CreateStyleForWidget(tooltipWindow, nullptr);
|
|
|
|
gtk_widget_destroy(tooltipWindow); // Release GtkWindow self-reference.
|
|
|
|
sStyleStorage[aNodeType] = style;
|
|
|
|
return style;
|
|
|
|
}
|
2016-07-18 06:29:00 +03:00
|
|
|
case MOZ_GTK_GRIPPER:
|
|
|
|
return GetWidgetStyleWithClass(MOZ_GTK_GRIPPER,
|
|
|
|
GTK_STYLE_CLASS_GRIP);
|
2016-06-07 03:49:00 +03:00
|
|
|
default:
|
|
|
|
GtkWidget* widget = GetWidget(aNodeType);
|
|
|
|
MOZ_ASSERT(widget);
|
|
|
|
return gtk_widget_get_style_context(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-09 02:08:26 +03:00
|
|
|
void
|
|
|
|
ResetWidgetCache(void)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!sStyleContextNeedsRestore);
|
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT(!sCurrentStyleContext);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (int i = 0; i < MOZ_GTK_WIDGET_NODE_COUNT; i++) {
|
|
|
|
if (sStyleStorage[i])
|
|
|
|
g_object_unref(sStyleStorage[i]);
|
|
|
|
}
|
2016-05-09 19:50:00 +03:00
|
|
|
mozilla::PodArrayZero(sStyleStorage);
|
2016-05-09 02:08:26 +03:00
|
|
|
|
|
|
|
/* This will destroy all of our widgets */
|
|
|
|
if (sWidgetStorage[MOZ_GTK_WINDOW])
|
|
|
|
gtk_widget_destroy(sWidgetStorage[MOZ_GTK_WINDOW]);
|
|
|
|
|
|
|
|
/* Clear already freed arrays */
|
2016-05-09 19:50:00 +03:00
|
|
|
mozilla::PodArrayZero(sWidgetStorage);
|
2016-05-09 02:08:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkStyleContext*
|
|
|
|
ClaimStyleContext(WidgetNodeType aNodeType, GtkTextDirection aDirection,
|
2016-05-17 22:52:04 +03:00
|
|
|
GtkStateFlags aStateFlags, StyleFlags aFlags)
|
2016-05-09 02:08:26 +03:00
|
|
|
{
|
2016-05-17 09:15:12 +03:00
|
|
|
MOZ_ASSERT(!sStyleContextNeedsRestore);
|
2016-06-07 03:49:00 +03:00
|
|
|
GtkStyleContext* style;
|
|
|
|
if (gtk_check_version(3, 20, 0) != nullptr) {
|
|
|
|
style = GetWidgetStyleInternal(aNodeType);
|
|
|
|
} else {
|
|
|
|
style = GetCssNodeStyleInternal(aNodeType);
|
|
|
|
}
|
2016-05-09 02:08:26 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT(!sCurrentStyleContext);
|
|
|
|
sCurrentStyleContext = style;
|
|
|
|
#endif
|
2016-05-17 09:15:12 +03:00
|
|
|
GtkStateFlags oldState = gtk_style_context_get_state(style);
|
|
|
|
GtkTextDirection oldDirection = gtk_style_context_get_direction(style);
|
|
|
|
if (oldState != aStateFlags || oldDirection != aDirection) {
|
|
|
|
// From GTK 3.8, set_state() will overwrite the direction, so set
|
|
|
|
// direction after state.
|
|
|
|
gtk_style_context_set_state(style, aStateFlags);
|
|
|
|
gtk_style_context_set_direction(style, aDirection);
|
|
|
|
|
|
|
|
// This invalidate is necessary for unsaved style contexts from GtkWidgets
|
|
|
|
// in pre-3.18 GTK, because automatic invalidation of such contexts
|
|
|
|
// was delayed until a resize event runs.
|
|
|
|
//
|
|
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1272194#c7
|
|
|
|
//
|
|
|
|
// Avoid calling invalidate on saved contexts to avoid performing
|
|
|
|
// build_properties() (in 3.16 stylecontext.c) unnecessarily early.
|
|
|
|
if (!sStyleContextNeedsRestore) {
|
|
|
|
gtk_style_context_invalidate(style);
|
|
|
|
}
|
|
|
|
}
|
2016-05-09 02:08:26 +03:00
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ReleaseStyleContext(GtkStyleContext* aStyleContext)
|
|
|
|
{
|
|
|
|
if (sStyleContextNeedsRestore) {
|
|
|
|
gtk_style_context_restore(aStyleContext);
|
|
|
|
}
|
|
|
|
sStyleContextNeedsRestore = false;
|
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT(sCurrentStyleContext == aStyleContext);
|
|
|
|
sCurrentStyleContext = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|