prefers-color-scheme media query no longer reflects user's preference for dark theme

VERIFIED FIXED in Firefox 68

Status

()

defect
P2
normal
VERIFIED FIXED
3 months ago
2 months ago

People

(Reporter: dbaron, Assigned: stransky)

Tracking

(Blocks 2 bugs, Regression, {regression})

unspecified
mozilla69
Points:
---
Dependency tree / graph
Bug Flags:
qe-verify +

Firefox Tracking Flags

(firefox-esr60 unaffected, firefox67 unaffected, firefox67.0.1 unaffected, firefox68 verified, firefox69 verified)

Details

Attachments

(1 attachment)

I believe this is a regression from bug 1527048, and is related to bug 1554047 (in that at least some of the possible fixes for one would also fix the other).

Following the landing of bug 1527048, the prefers-color-scheme media query (see implementation no longer reflects the user's preference for dark GTK themes because the widget code that reflects whether the user has a dark theme is affected by the fix to bug 1527048.

I believe the intent of prefers-color-scheme is that it should still be dark if the user has a dark theme, even when we're using light controls. There are other standard mechanisms in development for pages to opt in to dark controls, but because many pages would be broken by them, those are opt-in. (We should probably consider implementing them at some point.) But I think it's entirely consistent with the idea of prefers-color-scheme for it to be dark while the browser is using light controls; I believe that's how it works in Gecko on Mac and Windows.

Here's a simple test page saying which prefers-color-scheme is being reported.

The steps to reproduce are to set the system theme to Adwaita-dark (I don't actually remember how to do that!) and then load the above test page. It should show the line that says the user has prefers-color-scheme: dark, but instead it shows the one for light.

Has STR: --- → yes

The test page seems broken, it shows "The browser reports prefers-color-scheme: light.", despite that I have the "Dark Website Forcer" addon installed and Bugzilla here is dark.

From what I see on bugzilla for instance when a web site honors 'prefers-color-scheme' it does not use system widget styling and vice versa.
When I set 'prefers-color-scheme: dark' while content Gtk theme is light, bugzilla is shown in dark colors but other pages uses light (system) theme.
So it looks to me that we can safely export the real system theme style to allow pages with 'prefers-color-scheme' pick the right page style.

Priority: -- → P1
Assignee: nobody → stransky
Priority: P1 → P2

Pushed by dvarga@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/1731c1e39b8c
Export correct user's preference for dark theme by prefers-color-scheme media query, r=mats

Keywords: checkin-needed

Also caused browser-chrome failures: https://treeherder.mozilla.org/#/jobs?repo=autoland&resultStatus=testfailed%2Cbusted%2Cexception&fromchange=f257594fa2949a008ca356c461c995e0f03ed3bb&selectedJob=250605875&searchStr=bc9

Failure log: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=250605875&repo=autoland&lineNumber=4367

[task 2019-06-07T14:00:10.333Z] 14:00:10     INFO - TEST-START | browser/components/translation/test/browser_translation_bing.js
[task 2019-06-07T14:00:12.407Z] 14:00:12     INFO -  (xpcshell:3154): Gtk-CRITICAL **: gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
[task 2019-06-07T14:00:12.409Z] 14:00:12     INFO -  (xpcshell:3154): GLib-GObject-CRITICAL **: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed
[task 2019-06-07T14:00:12.409Z] 14:00:12     INFO -  AddressSanitizer:DEADLYSIGNAL
[task 2019-06-07T14:00:12.409Z] 14:00:12     INFO -  =================================================================
[task 2019-06-07T14:00:12.409Z] 14:00:12    ERROR -  ==3154==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f960cc79d99 bp 0x000000000000 sp 0x7ffd9dff4690 T0)
[task 2019-06-07T14:00:12.409Z] 14:00:12     INFO -  ==3154==The signal is caused by a READ memory access.
[task 2019-06-07T14:00:12.409Z] 14:00:12     INFO -  ==3154==Hint: address points to the zero page.
[task 2019-06-07T14:00:12.729Z] 14:00:12     INFO -      #0 0x7f960cc79d98  (/usr/lib/x86_64-linux-gnu/libgtk-3.so.0+0x2bad98)
[task 2019-06-07T14:00:12.729Z] 14:00:12     INFO -      #1 0x7f960cb287c7  (/usr/lib/x86_64-linux-gnu/libgtk-3.so.0+0x1697c7)
[task 2019-06-07T14:00:12.731Z] 14:00:12     INFO -      #2 0x7f960cb3c412  (/usr/lib/x86_64-linux-gnu/libgtk-3.so.0+0x17d412)
[task 2019-06-07T14:00:12.731Z] 14:00:12     INFO -      #3 0x7f960cb29b1b  (/usr/lib/x86_64-linux-gnu/libgtk-3.so.0+0x16ab1b)
[task 2019-06-07T14:00:12.733Z] 14:00:12     INFO -      #4 0x7f960cb3c308  (/usr/lib/x86_64-linux-gnu/libgtk-3.so.0+0x17d308)
[task 2019-06-07T14:00:12.733Z] 14:00:12     INFO -      #5 0x7f960cb3c3a3  (/usr/lib/x86_64-linux-gnu/libgtk-3.so.0+0x17d3a3)
[task 2019-06-07T14:00:12.734Z] 14:00:12     INFO -      #6 0x7f960cb2a691  (/usr/lib/x86_64-linux-gnu/libgtk-3.so.0+0x16b691)
[task 2019-06-07T14:00:12.735Z] 14:00:12     INFO -      #7 0x7f960b37f316 in g_type_create_instance (/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x33316)
[task 2019-06-07T14:00:12.736Z] 14:00:12     INFO -      #8 0x7f960b36131a  (/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x1531a)
[task 2019-06-07T14:00:12.737Z] 14:00:12     INFO -      #9 0x7f960b362c00 in g_object_newv (/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x16c00)
[task 2019-06-07T14:00:12.737Z] 14:00:12     INFO -      #10 0x7f960b363533 in g_object_new (/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x17533)
[task 2019-06-07T14:00:12.738Z] 14:00:12     INFO -      #11 0x7f960cb44429  (/usr/lib/x86_64-linux-gnu/libgtk-3.so.0+0x185429)
[task 2019-06-07T14:00:12.739Z] 14:00:12     INFO -      #12 0x7f960cd0d7ab  (/usr/lib/x86_64-linux-gnu/libgtk-3.so.0+0x34e7ab)
[task 2019-06-07T14:00:12.740Z] 14:00:12     INFO -      #13 0x7f960b37f316 in g_type_create_instance (/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x33316)
[task 2019-06-07T14:00:12.742Z] 14:00:12     INFO -      #14 0x7f960b36131a  (/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x1531a)
[task 2019-06-07T14:00:12.743Z] 14:00:12     INFO -      #15 0x7f960b3631b4 in g_object_new_valist (/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x171b4)
[task 2019-06-07T14:00:12.744Z] 14:00:12     INFO -      #16 0x7f960b363520 in g_object_new (/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0+0x17520)
[task 2019-06-07T14:00:13.285Z] 14:00:13     INFO -      #17 0x7f9617bc8d1e in CreateWindowWidget /builds/worker/workspace/build/src/widget/gtk/WidgetStyleCache.cpp:27:23
[task 2019-06-07T14:00:13.286Z] 14:00:13     INFO -      #18 0x7f9617bc8d1e in CreateWidget(WidgetNodeType) /builds/worker/workspace/build/src/widget/gtk/WidgetStyleCache.cpp:667
[task 2019-06-07T14:00:13.287Z] 14:00:13     INFO -      #19 0x7f9617bd63aa in GetWidget /builds/worker/workspace/build/src/widget/gtk/WidgetStyleCache.cpp:762:14
[task 2019-06-07T14:00:13.288Z] 14:00:13     INFO -      #20 0x7f9617bd63aa in GetWidgetRootStyle(WidgetNodeType) /builds/worker/workspace/build/src/widget/gtk/WidgetStyleCache.cpp:935
[task 2019-06-07T14:00:13.289Z] 14:00:13     INFO -      #21 0x7f9617bca385 in GetWidgetStyleInternal /builds/worker/workspace/build/src/widget/gtk/WidgetStyleCache.cpp:1318:14
[task 2019-06-07T14:00:13.289Z] 14:00:13     INFO -      #22 0x7f9617bca385 in GetStyleContext(WidgetNodeType, int, GtkTextDirection, GtkStateFlags) /builds/worker/workspace/build/src/widget/gtk/WidgetStyleCache.cpp:1352
[task 2019-06-07T14:00:13.290Z] 14:00:13     INFO -      #23 0x7f9617c3c6d5 in nsLookAndFeel::EnsureInit() /builds/worker/workspace/build/src/widget/gtk/nsLookAndFeel.cpp:917:11
[task 2019-06-07T14:00:13.291Z] 14:00:13     INFO -      #24 0x7f9617c3ff46 in nsLookAndFeel::NativeGetColor(mozilla::StyleSystemColor, unsigned int&) /builds/worker/workspace/build/src/widget/gtk/nsLookAndFeel.cpp:266:3
[task 2019-06-07T14:00:13.307Z] 14:00:13     INFO -      #25 0x7f9617b63a81 in nsXPLookAndFeel::GetColorImpl(mozilla::StyleSystemColor, bool, unsigned int&) /builds/worker/workspace/build/src/widget/nsXPLookAndFeel.cpp:885:27
[task 2019-06-07T14:00:13.309Z] 14:00:13     INFO -      #26 0x7f9617fc381c in GetColor /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/LookAndFeel.h:445:9
[task 2019-06-07T14:00:13.310Z] 14:00:13     INFO -      #27 0x7f9617fc381c in mozilla::PreferenceSheet::Prefs::Load(bool) /builds/worker/workspace/build/src/layout/style/PreferenceSheet.cpp:72
[task 2019-06-07T14:00:13.311Z] 14:00:13     INFO -      #28 0x7f9617fc4ed5 in mozilla::PreferenceSheet::Initialize() /builds/worker/workspace/build/src/layout/style/PreferenceSheet.cpp:98:16
[task 2019-06-07T14:00:13.312Z] 14:00:13     INFO -      #29 0x7f9617fccad3 in EnsureInitialized /builds/worker/workspace/build/src/layout/style/PreferenceSheet.h:50:5
[task 2019-06-07T14:00:13.313Z] 14:00:13     INFO -      #30 0x7f9617fccad3 in mozilla::ServoStyleSet::ServoStyleSet(mozilla::dom::Document&) /builds/worker/workspace/build/src/layout/style/ServoStyleSet.cpp:98
[task 2019-06-07T14:00:13.378Z] 14:00:13     INFO -      #31 0x7f9612b01d45 in MakeUnique<mozilla::ServoStyleSet, mozilla::dom::Document &> /builds/worker/workspace/build/src/obj-firefox/dist/include/mozilla/UniquePtr.h:617:27
[task 2019-06-07T14:00:13.379Z] 14:00:13     INFO -      #32 0x7f9612b01d45 in mozilla::dom::Document::Init() /builds/worker/workspace/build/src/dom/base/Document.cpp:2040
[task 2019-06-07T14:00:13.387Z] 14:00:13     INFO -      #33 0x7f96174e1ec5 in NS_NewXMLDocument /builds/worker/workspace/build/src/dom/xml/XMLDocument.cpp:187:22
[task 2019-06-07T14:00:13.388Z] 14:00:13     INFO -      #34 0x7f96174e1ec5 in NS_NewDOMDocument(mozilla::dom::Document**, nsTSubstring<char16_t> const&, nsTSubstring<char16_t> const&, mozilla::dom::DocumentType*, nsIURI*, nsIURI*, nsIPrincipal*, bool, nsIGlobalObject*, DocumentFlavor) /builds/worker/workspace/build/src/dom/xml/XMLDocument.cpp:116
[task 2019-06-07T14:00:13.404Z] 14:00:13     INFO -      #35 0x7f9612a5caa2 in mozilla::dom::DOMParser::SetUpDocument(DocumentFlavor, mozilla::ErrorResult&) /builds/worker/workspace/build/src/dom/base/DOMParser.cpp:291:17
[task 2019-06-07T14:00:13.405Z] 14:00:13     INFO -      #36 0x7f9612a5cf25 in mozilla::dom::DOMParser::ParseFromStream(nsIInputStream*, nsTSubstring<char16_t> const&, int, mozilla::dom::SupportedType, mozilla::ErrorResult&) /builds/worker/workspace/build/src/dom/base/DOMParser.cpp:157:7
Flags: needinfo?(stransky)
Keywords: checkin-needed

Pushed by apavel@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/c6de66b4781f
Export correct user's preference for dark theme by prefers-color-scheme media query, r=mats

Keywords: checkin-needed
Status: NEW → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla69
Status: RESOLVED → VERIFIED

Comment on attachment 9068629 [details]
Bug 1555565 - Export correct user's preference for dark theme by prefers-color-scheme media query, r=dao

Beta/Release Uplift Approval Request

  • User impact if declined: It's needed for Bug 1527048. When global dark theme is used system wide and light theme is used for web content then custom themed pages with 'prefers-color-scheme' will also have light theming despite the global dark theme.
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: Yes
  • If yes, steps to reproduce: 1) Make system use dark theme (Adwaita-dark, Yaru-dark, Arc-dark)
  1. Browse to bugzilla.mozilla.org and check that bugzilla dark theme is also used
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Gtk/Linux theme fix.
  • String changes made/needed:
Attachment #9068629 - Flags: approval-mozilla-beta?
Flags: qe-verify+
QA Whiteboard: [qa-triaged]

I would like some clear and easy steps to reproduce in order to reproduce the issue and validate the fix. David, can you help?

Flags: needinfo?(dbaron)

Steps to reproduce:

  1. Install Ubuntu 18.04 LTS
  2. install the gnome-tweaks package if it's not already installed with "sudo apt install gnome-tweaks"
  3. press the menu key and type "Tweaks"
  4. In the first tab ("Appearance") in the top section "Theme", change the "Applications" theme to Adwaita-dark
  5. Install the version of Firefox that you want to test.
  6. load this bug (bug 1555565)

Expected results: This bug has a dark background and light text.

Actual results: This bug has a light background and dark text.

Flags: needinfo?(dbaron)

(The test case in comment 1 is a more stable but less obvious alternative test page instead of this bug, if you prefer.)

Are you moving the early returns ahead of setting mInitialized on purpose?

Flags: needinfo?(stransky)

(In reply to Julien Cristau [:jcristau] from comment #15)

Are you moving the early returns ahead of setting mInitialized on purpose?

Yes, that's for case when it's called too early and there's no sceeen/settings yet.

Flags: needinfo?(stransky)

Comment on attachment 9068629 [details]
Bug 1555565 - Export correct user's preference for dark theme by prefers-color-scheme media query, r=dao

approved for 68.0b12

Attachment #9068629 - Flags: approval-mozilla-beta? → approval-mozilla-beta+

When attempting to use the test case in comment 1, the issue still occurs on Nightly v69.0a1 (2019-06-18). The "Rendered view" section displays the text "The browser reports prefers-color-scheme: dark.", but the section is displaying a light colored theme (dark colored font on white background).

When attempting to use test case received in comment 13, then the bug appears fixed in Nightly v69.0a1 (2019-06-18). The Bugzilla bug page is displayed with light colored font on dark background.

Since the fix only reaches Beta12, I have attempted to reproduce the issue on Firefox Beta v68.0b11 using the test case received in comment 13 and it appears that it does NOT reproduce. It appears to behave the same as the latest Nightly. The test case in comment 1 also behaves the same in both the latest Nightly (fixed build) and latest Beta (affected build).

This being said, I don't know whether the test cases are invalid or the fix in incorrect. Please advice. Thank you.

Flags: needinfo?(stransky)

I tried recent nightly and beta and it's fixed here. I use Yaru-dark theme and load bugzilla front page and it's shown in dark colors. Maybe you should create a new profile for testing?

Flags: needinfo?(stransky)

I have managed to reproduce your issue with Ubuntu 18.04.2 in Nightly v69.0a1 (2019-05-29), but with the Yaru-dark theme, not the Adwaita-dark theme (mentioned in STR of comment 13). The issue is fixed in latest Nightly v69.0a1 (2019-06-21) and latest Beta v68.0b12.

I deem this bug verified. Thank you.

You need to log in before you can comment on or make changes to this bug.