I think that the answer is located in the file /widget/gtk/nsLookAndFeel.cpp
.
Lines 1190-1200 in the latest stable code:
// It seems GTK doesn't have an API to query if the current theme is "light" or
// "dark", so we synthesize it from the CSS2 Window/WindowText colors instead,
// by comparing their luminosity.
static bool GetThemeIsDark() {
GdkRGBA bg, fg;
GtkStyleContext* style = GetStyleContext(MOZ_GTK_WINDOW);
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &bg);
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &fg);
return RelativeLuminanceUtils::Compute(GDK_RGBA_TO_NS_RGBA(bg)) <
RelativeLuminanceUtils::Compute(GDK_RGBA_TO_NS_RGBA(fg));
}
The function GDK_RGBA_TO_NS_RGBA()
can be simplified as:
(Note that this is not the actual implementation)
#define GDK_RGBA_TO_NS_RGBA(c) \
( \
((c.alpha * 255) << 24) \
| ((c.blue * 255) << 16) \
| ((c.green * 255) << 8) \
| (c.red * 255) \
)
The functions gtk_style_context_get_background_color()
and gtk_style_context_get_color()
returns the background and foreground colors for a given state (respectively).
So apparently the answer is by checking which integer value is bigger, the background or the foreground, and deciding based on that whether the theme is dark or not.