Title: [238200] trunk
Revision
238200
Author
[email protected]
Date
2018-11-14 14:24:09 -0800 (Wed, 14 Nov 2018)

Log Message

Update prefers-color-scheme media query matching based on GitHub issue #3278.
https://bugs.webkit.org/show_bug.cgi?id=191654
rdar://problem/46074307

Reviewed by Simon Fraser.

Source/WebCore:

Test: css-dark-mode/prefers-color-scheme.html

* css/MediaQueryEvaluator.cpp:
(WebCore::prefersColorSchemeEvaluate): Return true when there is no value. Return false
for `no-preference` since there is no macOS option for no user preference.
* css/MediaQueryExpression.cpp:
(WebCore::isFeatureValidWithoutValue): Added prefers-color-scheme.

LayoutTests:

* css-dark-mode/prefers-color-scheme-expected.txt: Rebaseline.
* css-dark-mode/prefers-color-scheme.html: Updates to better match the spec.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (238199 => 238200)


--- trunk/LayoutTests/ChangeLog	2018-11-14 22:03:14 UTC (rev 238199)
+++ trunk/LayoutTests/ChangeLog	2018-11-14 22:24:09 UTC (rev 238200)
@@ -1,3 +1,14 @@
+2018-11-14  Timothy Hatcher  <[email protected]>
+
+        Update prefers-color-scheme media query matching based on GitHub issue #3278.
+        https://bugs.webkit.org/show_bug.cgi?id=191654
+        rdar://problem/46074307
+
+        Reviewed by Simon Fraser.
+
+        * css-dark-mode/prefers-color-scheme-expected.txt: Rebaseline.
+        * css-dark-mode/prefers-color-scheme.html: Updates to better match the spec.
+
 2018-11-14  Devin Rousso  <[email protected]>
 
         Web Inspector: Canvas: send a call stack with each action instead of an array of call frames

Modified: trunk/LayoutTests/css-dark-mode/prefers-color-scheme-expected.txt (238199 => 238200)


--- trunk/LayoutTests/css-dark-mode/prefers-color-scheme-expected.txt	2018-11-14 22:03:14 UTC (rev 238199)
+++ trunk/LayoutTests/css-dark-mode/prefers-color-scheme-expected.txt	2018-11-14 22:24:09 UTC (rev 238200)
@@ -1,5 +1,7 @@
 
 PASS Element colors are correct in light color scheme 
+PASS Element colors are correct in light color scheme with boolean context query 
 PASS Dark color scheme enabled 
 PASS Element colors are correct in dark color scheme 
+PASS Element colors are correct in dark color scheme with boolean context query 
 

Modified: trunk/LayoutTests/css-dark-mode/prefers-color-scheme.html (238199 => 238200)


--- trunk/LayoutTests/css-dark-mode/prefers-color-scheme.html	2018-11-14 22:03:14 UTC (rev 238199)
+++ trunk/LayoutTests/css-dark-mode/prefers-color-scheme.html	2018-11-14 22:24:09 UTC (rev 238200)
@@ -6,7 +6,7 @@
 <script src=""
 
 <style>
-#test1 {
+div {
     background-color: red;
     color: text;
 }
@@ -23,6 +23,13 @@
     }
 }
 
+@media (prefers-color-scheme: no-preference) {
+    /* This is valid, but should not apply for us since there is no option for no user preference. */
+    #test1 {
+        background-color: cyan;
+    }
+}
+
 @media (prefers-color-scheme: foo) {
     /* This is invalid and should not apply. */
     #test1 {
@@ -31,14 +38,15 @@
 }
 
 @media (prefers-color-scheme) {
-    /* This is invalid and should not apply. */
-    #test1 {
-        background-color: orange;
+    /* This is valid and should always apply for us, since there is always a user preference currently. */
+    #test2 {
+        background-color: lime;
     }
 }
 </style>
 
 <div id="test1"></div>
+<div id="test2"></div>
 
 <script>
 function test_prop(id, prop, expected) {
@@ -54,6 +62,14 @@
 }, "Element colors are correct in light color scheme");
 
 test(function() {
+    // Styled background-color in media query should be lime green.
+    test_prop("test2", "background-color", "rgb(0, 255, 0)");
+
+    // The semantic text color should be black.
+    test_prop("test2", "color", "rgb(0, 0, 0)");
+}, "Element colors are correct in light color scheme with boolean context query");
+
+test(function() {
     if (window.internals)
         internals.settings.setUseDarkAppearance(true);
 }, "Dark color scheme enabled");
@@ -65,4 +81,12 @@
     // The semantic text color should be black, and not change.
     test_prop("test1", "color", "rgb(0, 0, 0)");
 }, "Element colors are correct in dark color scheme");
+
+test(function() {
+    // Styled background-color in media query should be lime green.
+    test_prop("test2", "background-color", "rgb(0, 255, 0)");
+
+    // The semantic text color should be black.
+    test_prop("test2", "color", "rgb(0, 0, 0)");
+}, "Element colors are correct in dark color scheme with boolean context query");
 </script>

Modified: trunk/Source/WebCore/ChangeLog (238199 => 238200)


--- trunk/Source/WebCore/ChangeLog	2018-11-14 22:03:14 UTC (rev 238199)
+++ trunk/Source/WebCore/ChangeLog	2018-11-14 22:24:09 UTC (rev 238200)
@@ -1,3 +1,19 @@
+2018-11-14  Timothy Hatcher  <[email protected]>
+
+        Update prefers-color-scheme media query matching based on GitHub issue #3278.
+        https://bugs.webkit.org/show_bug.cgi?id=191654
+        rdar://problem/46074307
+
+        Reviewed by Simon Fraser.
+
+        Test: css-dark-mode/prefers-color-scheme.html
+
+        * css/MediaQueryEvaluator.cpp:
+        (WebCore::prefersColorSchemeEvaluate): Return true when there is no value. Return false
+        for `no-preference` since there is no macOS option for no user preference.
+        * css/MediaQueryExpression.cpp:
+        (WebCore::isFeatureValidWithoutValue): Added prefers-color-scheme.
+
 2018-11-14  Devin Rousso  <[email protected]>
 
         Web Inspector: Canvas: send a call stack with each action instead of an array of call frames

Modified: trunk/Source/WebCore/css/MediaQueryEvaluator.cpp (238199 => 238200)


--- trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2018-11-14 22:03:14 UTC (rev 238199)
+++ trunk/Source/WebCore/css/MediaQueryEvaluator.cpp	2018-11-14 22:24:09 UTC (rev 238200)
@@ -745,6 +745,9 @@
 {
     ASSERT(RuntimeEnabledFeatures::sharedFeatures().darkModeCSSEnabled());
 
+    if (!value)
+        return true;
+
     if (!is<CSSPrimitiveValue>(value))
         return false;
 
@@ -753,7 +756,7 @@
 
     switch (keyword) {
     case CSSValueNoPreference:
-        return true;
+        return false;
     case CSSValueDark:
         return useDarkAppearance;
     case CSSValueLight:

Modified: trunk/Source/WebCore/css/MediaQueryExpression.cpp (238199 => 238200)


--- trunk/Source/WebCore/css/MediaQueryExpression.cpp	2018-11-14 22:03:14 UTC (rev 238199)
+++ trunk/Source/WebCore/css/MediaQueryExpression.cpp	2018-11-14 22:24:09 UTC (rev 238200)
@@ -167,6 +167,9 @@
         || mediaFeature == MediaFeatureNames::pointer
         || mediaFeature == MediaFeatureNames::prefersReducedMotion
         || (mediaFeature == MediaFeatureNames::prefersDarkInterface && (context.useSystemAppearance || isUASheetBehavior(context.mode)))
+#if ENABLE(DARK_MODE_CSS)
+        || (mediaFeature == MediaFeatureNames::prefersColorScheme && RuntimeEnabledFeatures::sharedFeatures().darkModeCSSEnabled())
+#endif
         || mediaFeature == MediaFeatureNames::devicePixelRatio
         || mediaFeature == MediaFeatureNames::resolution
 #if ENABLE(APPLICATION_MANIFEST)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to