зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1652220 [Linux] Create titlebar style from actual widget, r=jhorak
Differential Revision: https://phabricator.services.mozilla.com/D98597
This commit is contained in:
Родитель
80b8ba4acd
Коммит
3fd5700719
|
@ -437,25 +437,37 @@ static GtkWidget* CreateNotebookWidget() {
|
|||
return widget;
|
||||
}
|
||||
|
||||
static void CreateHeaderBarWidget(WidgetNodeType aAppearance) {
|
||||
MOZ_ASSERT(sWidgetStorage[aAppearance] == nullptr,
|
||||
"Header bar widget is already created!");
|
||||
|
||||
static auto sGtkHeaderBarNewPtr =
|
||||
(GtkWidget * (*)()) dlsym(RTLD_DEFAULT, "gtk_header_bar_new");
|
||||
|
||||
GtkWidget* headerbar = sGtkHeaderBarNewPtr();
|
||||
sWidgetStorage[aAppearance] = headerbar;
|
||||
|
||||
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
void GtkWindowSetTitlebar(GtkWindow* aWindow, GtkWidget* aWidget) {
|
||||
static auto sGtkWindowSetTitlebar = (void (*)(GtkWindow*, GtkWidget*))dlsym(
|
||||
RTLD_DEFAULT, "gtk_window_set_titlebar");
|
||||
MOZ_ASSERT(sGtkWindowSetTitlebar,
|
||||
"Missing gtk_window_set_titlebar(), old Gtk+ library?");
|
||||
sGtkWindowSetTitlebar(GTK_WINDOW(window), headerbar);
|
||||
gtk_widget_realize(window);
|
||||
sGtkWindowSetTitlebar(aWindow, aWidget);
|
||||
}
|
||||
|
||||
GtkWidget* GtkHeaderBarNew() {
|
||||
static auto sGtkHeaderBarNewPtr =
|
||||
(GtkWidget * (*)()) dlsym(RTLD_DEFAULT, "gtk_header_bar_new");
|
||||
return sGtkHeaderBarNewPtr();
|
||||
}
|
||||
|
||||
bool IsSolidCSDStyleUsed() {
|
||||
static bool isSolidCSDStyleUsed = []() {
|
||||
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
GtkWindowSetTitlebar(GTK_WINDOW(window), GtkHeaderBarNew());
|
||||
gtk_widget_realize(window);
|
||||
GtkStyleContext* windowStyle = gtk_widget_get_style_context(window);
|
||||
bool ret = gtk_style_context_has_class(windowStyle, "solid-csd");
|
||||
gtk_widget_destroy(window);
|
||||
return ret;
|
||||
}();
|
||||
return isSolidCSDStyleUsed;
|
||||
}
|
||||
|
||||
static void CreateHeaderBarWidget(WidgetNodeType aAppearance) {
|
||||
sWidgetStorage[aAppearance] = GtkHeaderBarNew();
|
||||
|
||||
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
GtkStyleContext* style = gtk_widget_get_style_context(window);
|
||||
|
||||
if (aAppearance == MOZ_GTK_HEADER_BAR_MAXIMIZED) {
|
||||
gtk_style_context_add_class(style, "maximized");
|
||||
MOZ_ASSERT(sWidgetStorage[MOZ_GTK_HEADERBAR_WINDOW_MAXIMIZED] == nullptr,
|
||||
|
@ -467,8 +479,17 @@ static void CreateHeaderBarWidget(WidgetNodeType aAppearance) {
|
|||
sWidgetStorage[MOZ_GTK_HEADERBAR_WINDOW] = window;
|
||||
}
|
||||
|
||||
// Headerbar has to be placed to window with csd or solid-csd style
|
||||
// to properly draw the decorated.
|
||||
gtk_style_context_add_class(style,
|
||||
IsSolidCSDStyleUsed() ? "solid-csd" : "csd");
|
||||
|
||||
GtkWidget* fixed = gtk_fixed_new();
|
||||
gtk_container_add(GTK_CONTAINER(window), fixed);
|
||||
gtk_container_add(GTK_CONTAINER(fixed), sWidgetStorage[aAppearance]);
|
||||
|
||||
// Emulate what create_titlebar() at gtkwindow.c does.
|
||||
style = gtk_widget_get_style_context(headerbar);
|
||||
style = gtk_widget_get_style_context(sWidgetStorage[aAppearance]);
|
||||
gtk_style_context_add_class(style, "titlebar");
|
||||
|
||||
// TODO: Define default-decoration titlebar style as workaround
|
||||
|
|
|
@ -52,6 +52,8 @@ GtkStyleContext* CreateStyleContextWithStates(
|
|||
|
||||
void ResetWidgetCache(void);
|
||||
|
||||
bool IsSolidCSDStyleUsed();
|
||||
|
||||
void StyleContextSetScale(GtkStyleContext* style, gint aScaleFactor);
|
||||
|
||||
#endif // WidgetStyleCache_h
|
||||
|
|
Загрузка…
Ссылка в новой задаче