Backed out 2 changesets (bug 1716462) for Build bustages. CLOSED TREE

Backed out changeset da9c8170a934 (bug 1716462)
Backed out changeset 42abdfd99cb4 (bug 1716462)
This commit is contained in:
Dorel Luca 2021-06-16 18:50:02 +03:00
parent e08677cb3c
commit b5d072edbd
3 changed files with 50 additions and 45 deletions

View File

@ -431,9 +431,33 @@ static GtkWidget* CreateNotebookWidget() {
return widget;
}
static void CreateHeaderBarWidget(WidgetNodeType aAppearance,
bool aIsSolidCSDStyleUsed) {
sWidgetStorage[aAppearance] = gtk_header_bar_new();
void GtkWindowSetTitlebar(GtkWindow* aWindow, GtkWidget* aWidget) {
static auto sGtkWindowSetTitlebar = (void (*)(GtkWindow*, GtkWidget*))dlsym(
RTLD_DEFAULT, "gtk_window_set_titlebar");
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);
@ -452,7 +476,7 @@ static void CreateHeaderBarWidget(WidgetNodeType aAppearance,
// Headerbar has to be placed to window with csd or solid-csd style
// to properly draw the decorated.
gtk_style_context_add_class(style,
aIsSolidCSDStyleUsed ? "solid-csd" : "csd");
IsSolidCSDStyleUsed() ? "solid-csd" : "csd");
GtkWidget* fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), fixed);
@ -504,18 +528,18 @@ static void LoadWidgetIconPixbuf(GtkWidget* aWidgetIcon) {
gdk_cairo_surface_create_from_pixbuf(iconPixbuf, scale, nullptr);
g_object_unref(iconPixbuf);
nsPrintfCString surfaceName("MozillaIconSurface%d", scale);
nsAutoCString surfaceName;
surfaceName = nsPrintfCString("MozillaIconSurface%d", scale);
g_object_set_data_full(G_OBJECT(aWidgetIcon), surfaceName.get(),
iconSurface, (GDestroyNotify)cairo_surface_destroy);
}
}
cairo_surface_t* GetWidgetIconSurface(GtkWidget* aWidgetIcon, int aScale) {
if (aScale > ICON_SCALE_VARIANTS) {
aScale = ICON_SCALE_VARIANTS;
}
if (aScale > ICON_SCALE_VARIANTS) aScale = ICON_SCALE_VARIANTS;
nsPrintfCString surfaceName("MozillaIconSurface%d", aScale);
nsAutoCString surfaceName;
surfaceName = nsPrintfCString("MozillaIconSurface%d", aScale);
return (cairo_surface_t*)g_object_get_data(G_OBJECT(aWidgetIcon),
surfaceName.get());
}
@ -634,18 +658,8 @@ static void CreateHeaderBarButtons() {
}
static void CreateHeaderBar() {
const bool isSolidCSDStyleUsed = []() {
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_titlebar(GTK_WINDOW(window), gtk_header_bar_new());
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;
}();
CreateHeaderBarWidget(MOZ_GTK_HEADER_BAR, isSolidCSDStyleUsed);
CreateHeaderBarWidget(MOZ_GTK_HEADER_BAR_MAXIMIZED, isSolidCSDStyleUsed);
CreateHeaderBarWidget(MOZ_GTK_HEADER_BAR);
CreateHeaderBarWidget(MOZ_GTK_HEADER_BAR_MAXIMIZED);
CreateHeaderBarButtons();
}

View File

@ -373,7 +373,7 @@ static void CalculateToolbarButtonSpacing(WidgetNodeType aAppearance,
g_object_get(GetWidget(MOZ_GTK_HEADER_BAR), "spacing", &buttonSpacing,
nullptr);
// We apply spacing as a margin equally to both adjacent buttons.
// We apply spacing as a margin equaly to both adjacent buttons.
buttonSpacing /= 2;
if (!aMetrics->firstButton) {
@ -594,8 +594,13 @@ static gint moz_gtk_header_bar_button_paint(cairo_t* cr,
GetToolbarButtonMetrics(buttonWidgetType);
/* This is available since Gtk+ 3.10 as well as GtkHeaderBar */
gtk_render_icon_surface(style, cr, surface, rect.x + metrics->iconXPosition,
rect.y + metrics->iconYPosition);
static auto sGtkRenderIconSurfacePtr =
(void (*)(GtkStyleContext*, cairo_t*, cairo_surface_t*, gdouble,
gdouble))dlsym(RTLD_DEFAULT, "gtk_render_icon_surface");
sGtkRenderIconSurfacePtr(style, cr, surface,
rect.x + metrics->iconXPosition,
rect.y + metrics->iconYPosition);
gtk_style_context_restore(style);
}

View File

@ -1032,23 +1032,19 @@ static bool IsGtkThemeCompatibleWithHTMLColors() {
return HasGoodContrastVisibility(backgroundColor, black);
}
static nsCString GetGtkSettingsStringKey(const char* aKey) {
static nsCString GetGtkTheme() {
MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
nsCString ret;
GtkSettings* settings = gtk_settings_get_default();
char* value = nullptr;
g_object_get(settings, aKey, &value, nullptr);
if (value) {
ret.Assign(value);
g_free(value);
char* themeName = nullptr;
g_object_get(settings, "gtk-theme-name", &themeName, nullptr);
if (themeName) {
ret.Assign(themeName);
g_free(themeName);
}
return ret;
}
static nsCString GetGtkTheme() {
return GetGtkSettingsStringKey("gtk-theme-name");
}
static bool GetPreferDarkTheme() {
GtkSettings* settings = gtk_settings_get_default();
gboolean preferDarkTheme = FALSE;
@ -1078,9 +1074,6 @@ void nsLookAndFeel::ConfigureTheme(const LookAndFeelTheme& aTheme) {
}
void nsLookAndFeel::RestoreSystemTheme() {
LOGLNF(("RestoreSystemTheme(%s, %d)\n", mSystemTheme.mName.get(),
mSystemTheme.mPreferDarkTheme));
// Available on Gtk 3.20+.
static auto sGtkSettingsResetProperty =
(void (*)(GtkSettings*, const gchar*))dlsym(
@ -1323,10 +1316,6 @@ bool nsLookAndFeel::MatchFirefoxThemeIfNeeded() {
}();
const bool usingSystem = GetThemeIsDark() == mSystemTheme.mIsDark;
LOGLNF(("MatchFirefoxThemeIfNeeded(matchesSystem=%d, usingSystem=%d)\n",
matchesSystem, usingSystem));
if (usingSystem == matchesSystem) {
return false;
}
@ -1334,9 +1323,6 @@ bool nsLookAndFeel::MatchFirefoxThemeIfNeeded() {
if (matchesSystem) {
RestoreSystemTheme();
} else {
LOGLNF(("Setting theme %s, %d\n", mAltTheme.mName.get(),
mAltTheme.mPreferDarkTheme));
GtkSettings* settings = gtk_settings_get_default();
if (mSystemTheme.mName == mAltTheme.mName) {
// Prefer setting only gtk-application-prefer-dark-theme, so we can still
@ -1417,7 +1403,7 @@ void nsLookAndFeel::PerThemeData::Init() {
GtkStyleContext* style;
mHighContrast = StaticPrefs::widget_content_gtk_high_contrast_enabled() &&
mName.Find("HighContrast"_ns) >= 0;
GetGtkTheme().Find("HighContrast"_ns) >= 0;
mPreferDarkTheme = GetPreferDarkTheme();