Bug 1277818 - exports CreateCSSNode() and divides pre/post 3.20 styles construction, r=karlt

This commit is contained in:
Martin Stransky 2016-06-07 02:49:00 +02:00
Родитель 73652c8a4f
Коммит 30edd2be74
2 изменённых файлов: 98 добавлений и 87 удалений

Просмотреть файл

@ -22,7 +22,7 @@ static bool sStyleContextNeedsRestore;
static GtkStyleContext* sCurrentStyleContext;
#endif
static GtkStyleContext*
GetStyleInternal(WidgetNodeType aNodeType);
GetCssNodeStyleInternal(WidgetNodeType aNodeType);
static GtkWidget*
CreateWindowWidget()
@ -150,17 +150,18 @@ GetWidget(WidgetNodeType aWidgetType)
return widget;
}
static GtkStyleContext*
CreateCSSNode(const char* aName, GtkStyleContext *aParentStyle)
GtkStyleContext*
CreateCSSNode(const char* aName, GtkStyleContext* aParentStyle, GType aType)
{
static auto sGtkWidgetPathIterSetObjectName =
reinterpret_cast<void (*)(GtkWidgetPath *, gint, const char *)>
(dlsym(RTLD_DEFAULT, "gtk_widget_path_iter_set_object_name"));
GtkWidgetPath* path =
gtk_widget_path_copy(gtk_style_context_get_path(aParentStyle));
GtkWidgetPath* path = aParentStyle ?
gtk_widget_path_copy(gtk_style_context_get_path(aParentStyle)) :
gtk_widget_path_new();
gtk_widget_path_append_type(path, G_TYPE_NONE);
gtk_widget_path_append_type(path, aType);
(*sGtkWidgetPathIterSetObjectName)(path, -1, aName);
@ -173,113 +174,112 @@ CreateCSSNode(const char* aName, GtkStyleContext *aParentStyle)
}
static GtkStyleContext*
GetChildNodeStyle(WidgetNodeType aStyleType,
WidgetNodeType aWidgetType,
const gchar* aStyleClass,
WidgetNodeType aParentNodeType)
CreateChildCSSNode(const char* aName, WidgetNodeType aParentNodeType)
{
GtkStyleContext* style;
if (gtk_check_version(3, 20, 0) != nullptr) {
style = gtk_widget_get_style_context(sWidgetStorage[aWidgetType]);
gtk_style_context_save(style);
MOZ_ASSERT(!sStyleContextNeedsRestore);
sStyleContextNeedsRestore = true;
gtk_style_context_add_class(style, aStyleClass);
}
else {
style = sStyleStorage[aStyleType];
if (!style) {
style = CreateCSSNode(aStyleClass, GetStyleInternal(aParentNodeType));
MOZ_ASSERT(!sStyleContextNeedsRestore);
sStyleStorage[aStyleType] = style;
}
}
return style;
return CreateCSSNode(aName, GetCssNodeStyleInternal(aParentNodeType));
}
/* GetCssNodeStyleInternal is used by Gtk >= 3.20 */
static GtkStyleContext*
GetStyleInternal(WidgetNodeType aNodeType)
GetCssNodeStyleInternal(WidgetNodeType aNodeType)
{
GtkStyleContext* style = sStyleStorage[aNodeType];
if (style)
return style;
switch (aNodeType) {
case MOZ_GTK_SCROLLBAR_HORIZONTAL:
/* Root CSS node / widget for scrollbars */
break;
case MOZ_GTK_SCROLLBAR_TROUGH_HORIZONTAL:
return GetChildNodeStyle(aNodeType,
MOZ_GTK_SCROLLBAR_HORIZONTAL,
GTK_STYLE_CLASS_TROUGH,
MOZ_GTK_SCROLLBAR_HORIZONTAL);
style = CreateChildCSSNode(GTK_STYLE_CLASS_TROUGH,
MOZ_GTK_SCROLLBAR_HORIZONTAL);
break;
case MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL:
return GetChildNodeStyle(aNodeType,
MOZ_GTK_SCROLLBAR_HORIZONTAL,
GTK_STYLE_CLASS_SLIDER,
MOZ_GTK_SCROLLBAR_TROUGH_HORIZONTAL);
case MOZ_GTK_SCROLLBAR_VERTICAL:
/* Root CSS node / widget for scrollbars */
style = CreateChildCSSNode(GTK_STYLE_CLASS_SLIDER,
MOZ_GTK_SCROLLBAR_TROUGH_HORIZONTAL);
break;
case MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL:
return GetChildNodeStyle(aNodeType,
MOZ_GTK_SCROLLBAR_VERTICAL,
GTK_STYLE_CLASS_TROUGH,
MOZ_GTK_SCROLLBAR_VERTICAL);
style = CreateChildCSSNode(GTK_STYLE_CLASS_TROUGH,
MOZ_GTK_SCROLLBAR_VERTICAL);
break;
case MOZ_GTK_SCROLLBAR_THUMB_VERTICAL:
return GetChildNodeStyle(aNodeType,
MOZ_GTK_SCROLLBAR_VERTICAL,
GTK_STYLE_CLASS_SLIDER,
MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL);
case MOZ_GTK_RADIOBUTTON_CONTAINER:
/* Root CSS node / widget for checkboxes */
style = CreateChildCSSNode(GTK_STYLE_CLASS_SLIDER,
MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL);
break;
case MOZ_GTK_RADIOBUTTON:
return GetChildNodeStyle(aNodeType,
MOZ_GTK_RADIOBUTTON_CONTAINER,
GTK_STYLE_CLASS_RADIO,
MOZ_GTK_RADIOBUTTON_CONTAINER);
case MOZ_GTK_CHECKBUTTON_CONTAINER:
/* Root CSS node / widget for radiobuttons */
style = CreateChildCSSNode(GTK_STYLE_CLASS_RADIO,
MOZ_GTK_RADIOBUTTON_CONTAINER);
break;
case MOZ_GTK_CHECKBUTTON:
return GetChildNodeStyle(aNodeType,
MOZ_GTK_CHECKBUTTON_CONTAINER,
GTK_STYLE_CLASS_CHECK,
MOZ_GTK_CHECKBUTTON_CONTAINER);
case MOZ_GTK_PROGRESSBAR:
/* Root CSS node / widget for progress bars */
style = CreateChildCSSNode(GTK_STYLE_CLASS_CHECK,
MOZ_GTK_CHECKBUTTON_CONTAINER);
break;
case MOZ_GTK_PROGRESS_TROUGH:
/* Progress bar background (trough) */
return GetChildNodeStyle(aNodeType,
MOZ_GTK_PROGRESSBAR,
GTK_STYLE_CLASS_TROUGH,
MOZ_GTK_PROGRESSBAR);
case MOZ_GTK_PROGRESS_CHUNK:
/* Actual progress bar indicator for Gtk3.20+ only. */
return GetChildNodeStyle(MOZ_GTK_PROGRESS_CHUNK,
MOZ_GTK_PROGRESSBAR,
"progress",
MOZ_GTK_PROGRESS_TROUGH);
default:
style = CreateChildCSSNode(GTK_STYLE_CLASS_TROUGH,
MOZ_GTK_PROGRESSBAR);
break;
case MOZ_GTK_PROGRESS_CHUNK:
style = CreateChildCSSNode("progress",
MOZ_GTK_PROGRESS_TROUGH);
break;
default:
// TODO - create style from style path
GtkWidget* widget = GetWidget(aNodeType);
return gtk_widget_get_style_context(widget);
}
GtkWidget* widget = GetWidget(aNodeType);
if (widget) {
return gtk_widget_get_style_context(widget);
if (style) {
sStyleStorage[aNodeType] = style;
return style;
}
MOZ_ASSERT_UNREACHABLE("missing style context for node type");
return nullptr;
}
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;
}
/* 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);
default:
GtkWidget* widget = GetWidget(aNodeType);
MOZ_ASSERT(widget);
return gtk_widget_get_style_context(widget);
}
}
void
ResetWidgetCache(void)
{
@ -307,7 +307,12 @@ ClaimStyleContext(WidgetNodeType aNodeType, GtkTextDirection aDirection,
GtkStateFlags aStateFlags, StyleFlags aFlags)
{
MOZ_ASSERT(!sStyleContextNeedsRestore);
GtkStyleContext* style = GetStyleInternal(aNodeType);
GtkStyleContext* style;
if (gtk_check_version(3, 20, 0) != nullptr) {
style = GetWidgetStyleInternal(aNodeType);
} else {
style = GetCssNodeStyleInternal(aNodeType);
}
#ifdef DEBUG
MOZ_ASSERT(!sCurrentStyleContext);
sCurrentStyleContext = style;

Просмотреть файл

@ -21,6 +21,12 @@ enum : StyleFlags {
GtkWidget*
GetWidget(WidgetNodeType aNodeType);
// CreateCSSNode is implemented for gtk >= 3.20 only.
GtkStyleContext*
CreateCSSNode(const char* aName,
GtkStyleContext* aParentStyle,
GType aType = G_TYPE_NONE);
// Callers must call ReleaseStyleContext() on the returned context.
GtkStyleContext*
ClaimStyleContext(WidgetNodeType aNodeType,