[webkit-changes] [WebKit/WebKit] 3caad3: sfgate.com is unreadable when dark mode is forced ...

Aditya Keerthi noreply at github.com
Wed Mar 22 09:23:30 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 3caad3cea6986d04c33e2bf76c52a1ebff9964c4
      https://github.com/WebKit/WebKit/commit/3caad3cea6986d04c33e2bf76c52a1ebff9964c4
  Author: Aditya Keerthi <akeerthi at apple.com>
  Date:   2023-03-22 (Wed, 22 Mar 2023)

  Changed paths:
    M Source/WebCore/css/query/MediaQueryFeatures.cpp
    M Source/WebCore/dom/Document.cpp
    M Source/WebCore/page/Page.cpp
    M Tools/TestWebKitAPI/Tests/WebKit/color-scheme.html
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm

  Log Message:
  -----------
  sfgate.com is unreadable when dark mode is forced using `-[WKWebpagePreferences _setColorSchemePreference:]`
https://bugs.webkit.org/show_bug.cgi?id=254239
rdar://106873224

Reviewed by Wenson Hsieh.

245233 at main added `WKWebpagePreferences` SPI to support a user-specified
color-scheme preference. The intent of the preference is to override the
system color-scheme preference.

However, the current implementation is flawed, as it not only overrides the
system preference, but also forces sites to opt-in to the user-specified
color scheme.

`Document::useDarkAppearance` is used to determine whether or not
a site supports a dark color-scheme. The value is derived from the `color-scheme`
CSS property or `<meta>` tag. If a dark-color scheme is declared as supported,
all semantic colors will be resolved with a dark color-scheme. By default,
the root background and text colors are semantic.

sfgate.com does not support a dark color-scheme. They do not modify the root
background color, but use custom text colors. Consequently, forcing dark mode
makes the text unreadable, as the background adapts to dark mode, but the text
does not. This is one of many possible sources of compatibility issues when
forcing a used color-scheme value on a page.

To fix, do not modify the site's used color-scheme when the SPI is used.
Instead, simply report the user's preferred color-scheme as the overridden
value, exposed only via media queries. This change carries no compatibility
risk, as users are free to change their preferred color-scheme at a global level.

* Source/WebCore/css/query/MediaQueryFeatures.cpp:
(WebCore::MQ::Features::prefersColorScheme):

`Page::useDarkAppearance` will report the overridden value if there is one, and
will otherwise fall back to the system value, so the removed code is redundant.

* Source/WebCore/dom/Document.cpp:
(WebCore::Document::useDarkAppearance const):

Remove problematic logic that was forcing sites to opt-in to dark mode.

* Source/WebCore/page/Page.cpp:
(WebCore::Page::useDarkAppearance const):

Report the user's preferred color-scheme with an override if one is specified.

* Tools/TestWebKitAPI/Tests/WebKit/color-scheme.html:

Update test page to use a semantic color that can be read.

* Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:

Added a new test to ensure that content is not forced into dark mode when the
user preference is overridden.

Moved an existing test to be closer to another similar test.

Canonical link: https://commits.webkit.org/261967@main




More information about the webkit-changes mailing list