[Webkit-unassigned] [Bug 196685] [GTK] Support prefers-color-scheme media query

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu May 16 07:48:54 PDT 2019


https://bugs.webkit.org/show_bug.cgi?id=196685

--- Comment #15 from Timothy Hatcher <timothy at apple.com> ---
Comment on attachment 368221
  --> https://bugs.webkit.org/attachment.cgi?id=368221
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=368221&action=review

>>>> Source/WebCore/testing/InternalSettings.cpp:531
>>>> +            g_object_set(settings, "gtk-application-prefer-dark-theme", useDarkAppearance, nullptr);
>>> 
>>> Honestly, after talking with Cassidy today, I think we did this wrong. Cassidy actually liked your approach, but I don't anymore. Problem is gtk-application-prefer-dark-theme is used by apps that always want to be dark, e.g. Photos or Videos, to force dark theme. For Epiphany, it's guaranteed to be false, because Epiphany doesn't want to force dark theme.
>>> 
>>> But the theme could still be dark. And if the theme is dark, then we need this media query to reflect that, or websites will draw dark text on dark background. If the media query doesn't actually reflect whether the theme is dark, then we will wind up with unreadable text and no hope of web compat.
>>> 
>>> So your implementation is surely not going to be web-compatible. Instead, we should use a heuristic to guess whether the current GTK theme is dark or not, e.g. "does the current theme name end in the string 'dark'?" This is the only way dark themes will ever be usable without breaking the web. Cassidy points out there's no way to make that work for themes named, say, "Midnight." But there's not really anything we can do about that.
>>> 
>>> I know just fixing the media query is not enough. We need to support the color-schemes property too, the one formerly supported-color-schemes, which I know you said we might not be able to do. But anyway, this bug is about the media query, and what we have here just isn't going to work well.
>> 
>> Er, yeah I really misread this patch, sorry. I see this is only testing code.
>> 
>> What, then, decides whether the media query is true or false? Where is the logic that decides whether prefers-color-scheme is true or false? How can you have enabled this without any platform implementation for it?
> 
> It was done in r244635. What we do there is ensuring dark mode is enabled when the current theme is dark. We use heuristics indeed, see:
> 
> bool PageClientImpl::effectiveAppearanceIsDark() const
> {
>     auto* settings = gtk_widget_get_settings(m_viewWidget);
>     gboolean preferDarkTheme;
>     g_object_get(settings, "gtk-application-prefer-dark-theme", &preferDarkTheme, nullptr);
>     if (preferDarkTheme)
>         return true;
> 
>     GUniqueOutPtr<char> themeName;
>     g_object_get(settings, "gtk-theme-name", &themeName.outPtr(), nullptr);
>     if (g_str_has_suffix(themeName.get(), "-dark"))
>         return true;
> 
>     if (auto* themeNameEnv = g_getenv("GTK_THEME"))
>         return g_str_has_suffix(themeNameEnv, ":dark");
> 
>     return false;
> }

Couldn't you check the color value for text and/or a background for light or dark? That would catch more cases like Midnight, etc.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20190516/5a93f08d/attachment-0001.html>


More information about the webkit-unassigned mailing list