Bug 1489499 - Don't call gtk_header_bar_get_decoration_layout() to get titlebar layout, r=jhorak

We don't set gtk_header_bar_set_decoration_layout() so we don't need to query the layout
by gtk_header_bar_get_decoration_layout(). That means we don't need to create the GtkHeaderBar
at startup when titlebar rendering is disabled.

Also unify window/header bar construction at CreateHeaderBarWidget() and assert when the widgets
are already created.

Differential Revision: https://phabricator.services.mozilla.com/D5417

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Martin Stransky 2018-09-11 08:56:13 +00:00
Родитель 811a32c96f
Коммит 7aca24afe9
2 изменённых файлов: 14 добавлений и 27 удалений

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

@ -528,23 +528,31 @@ CreateNotebookWidget()
return widget;
}
static GtkWidget*
static void
CreateHeaderBarWidget(WidgetNodeType aWidgetType)
{
MOZ_ASSERT(gtk_check_version(3, 10, 0) == nullptr,
"GtkHeaderBar is only available on GTK 3.10+.");
MOZ_ASSERT(sWidgetStorage[aWidgetType] == nullptr,
"Header bar widget is already created!");
static auto sGtkHeaderBarNewPtr = (GtkWidget* (*)())
dlsym(RTLD_DEFAULT, "gtk_header_bar_new");
GtkWidget* headerbar = sGtkHeaderBarNewPtr();
sWidgetStorage[aWidgetType] = headerbar;
GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
GtkStyleContext* style = gtk_widget_get_style_context(window);
if (aWidgetType == MOZ_GTK_HEADER_BAR_MAXIMIZED) {
gtk_style_context_add_class(style, "maximized");
MOZ_ASSERT(sWidgetStorage[MOZ_GTK_HEADERBAR_WINDOW_MAXIMIZED] == nullptr,
"Window widget is already created!");
sWidgetStorage[MOZ_GTK_HEADERBAR_WINDOW_MAXIMIZED] = window;
} else {
MOZ_ASSERT(sWidgetStorage[MOZ_GTK_HEADERBAR_WINDOW] == nullptr,
"Window widget is already created!");
sWidgetStorage[MOZ_GTK_HEADERBAR_WINDOW] = window;
}
@ -571,8 +579,6 @@ CreateHeaderBarWidget(WidgetNodeType aWidgetType)
// We need to fix titlebar size calculation to also include
// titlebar button sizes. (Bug 1419442)
gtk_style_context_add_class(style, "default-decoration");
return headerbar;
}
#define ICON_SCALE_VARIANTS 2
@ -761,15 +767,8 @@ CreateHeaderBarButtons()
static void
CreateHeaderBar()
{
MOZ_ASSERT(sWidgetStorage[MOZ_GTK_HEADER_BAR] == nullptr &&
sWidgetStorage[MOZ_GTK_HEADER_BAR_MAXIMIZED] == nullptr,
"Header bar widget is already created!");
sWidgetStorage[MOZ_GTK_HEADER_BAR] =
CreateHeaderBarWidget(MOZ_GTK_HEADER_BAR);
sWidgetStorage[MOZ_GTK_HEADER_BAR_MAXIMIZED] =
CreateHeaderBarWidget(MOZ_GTK_HEADER_BAR_MAXIMIZED);
CreateHeaderBarButtons();
}

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

@ -428,22 +428,10 @@ GetGtkHeaderBarButtonLayout(WidgetNodeType* aButtonLayout, int aMaxButtonNums)
NS_ASSERTION(aMaxButtonNums >= TOOLBAR_BUTTONS,
"Requested number of buttons is higher than storage capacity!");
static auto sGtkHeaderBarGetDecorationLayoutPtr =
(const gchar* (*)(GtkWidget*))
dlsym(RTLD_DEFAULT, "gtk_header_bar_get_decoration_layout");
const gchar* decorationLayout = nullptr;
if (sGtkHeaderBarGetDecorationLayoutPtr) {
GtkWidget* headerBar = GetWidget(MOZ_GTK_HEADER_BAR);
decorationLayout = sGtkHeaderBarGetDecorationLayoutPtr(headerBar);
if (!decorationLayout) {
GtkSettings *settings = gtk_settings_get_for_screen(
gdk_screen_get_default());
g_object_get(settings, "gtk-decoration-layout",
&decorationLayout,
nullptr);
}
}
GtkSettings *settings =
gtk_settings_get_for_screen(gdk_screen_get_default());
g_object_get(settings, "gtk-decoration-layout", &decorationLayout, nullptr);
// Use a default layout
if (!decorationLayout) {