Treat supported-color-schemes as the second highest priority property.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2018 18:44:25 +0000 (18:44 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2018 18:44:25 +0000 (18:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191556
rdar://problem/46000076

Reviewed by Dean Jackson.

Source/WebCore:

Test: css-dark-mode/supported-color-schemes-priority.html

* css/CSSProperties.json: Make supported-color-schemes high-priority and add a comment.
* css/StyleResolver.cpp:
(WebCore::StyleResolver::applyMatchedProperties): Manually handle supported-color-schemes
after -webkit-ruby-position, before other properties, so it can affect resolved colors.

LayoutTests:

* css-dark-mode/supported-color-schemes-priority-expected.txt: Added.
* css-dark-mode/supported-color-schemes-priority.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238138 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/css-dark-mode/supported-color-schemes-priority-expected.txt [new file with mode: 0644]
LayoutTests/css-dark-mode/supported-color-schemes-priority.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSProperties.json
Source/WebCore/css/StyleResolver.cpp

index cf4de2e..82fc5ca 100644 (file)
@@ -1,3 +1,14 @@
+2018-11-13  Timothy Hatcher  <timothy@apple.com>
+
+        Treat supported-color-schemes as the second highest priority property.
+        https://bugs.webkit.org/show_bug.cgi?id=191556
+        rdar://problem/46000076
+
+        Reviewed by Dean Jackson.
+
+        * css-dark-mode/supported-color-schemes-priority-expected.txt: Added.
+        * css-dark-mode/supported-color-schemes-priority.html: Added.
+
 2018-11-13  Youenn Fablet  <youenn@apple.com>
 
         Refresh WPT webrtc tests to ToT
diff --git a/LayoutTests/css-dark-mode/supported-color-schemes-priority-expected.txt b/LayoutTests/css-dark-mode/supported-color-schemes-priority-expected.txt
new file mode 100644 (file)
index 0000000..fd772b9
--- /dev/null
@@ -0,0 +1,5 @@
+
+PASS Element colors are correct in light color scheme with light and dark supported color scheme 
+PASS Dark color scheme enabled 
+PASS Element colors are correct in dark color scheme with light and dark supported color scheme 
+
diff --git a/LayoutTests/css-dark-mode/supported-color-schemes-priority.html b/LayoutTests/css-dark-mode/supported-color-schemes-priority.html
new file mode 100644 (file)
index 0000000..b0441d8
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+
+<!-- webkit-test-runner [ experimental:DarkModeCSSEnabled=true ] -->
+
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+
+<style>
+#test1 {
+    supported-color-schemes: light dark;
+    color: text;
+}
+</style>
+
+<div id="test1"></div>
+
+<script>
+function test_prop(id, prop, expected) {
+    assert_equals(window.getComputedStyle(document.getElementById(id)).getPropertyValue(prop), expected);
+}
+
+function test_color_is_white(id) {
+    test_prop("test1", "color", "rgb(255, 255, 255)");
+}
+
+function test_color_is_black(id) {
+    test_prop("test1", "color", "rgb(0, 0, 0)");
+}
+
+test(function() {
+    // The semantic text color should be black.
+    test_color_is_black("test1");
+}, "Element colors are correct in light color scheme with light and dark supported color scheme");
+
+test(function() {
+    if (window.internals)
+        internals.settings.setUseDarkAppearance(true);
+}, "Dark color scheme enabled");
+
+test(function() {
+    // The semantic text color should be white.
+    test_color_is_white("test1");
+}, "Element colors are correct in dark color scheme with light and dark supported color scheme");
+</script>
index 9626777..9ef3c84 100644 (file)
@@ -1,3 +1,18 @@
+2018-11-13  Timothy Hatcher  <timothy@apple.com>
+
+        Treat supported-color-schemes as the second highest priority property.
+        https://bugs.webkit.org/show_bug.cgi?id=191556
+        rdar://problem/46000076
+
+        Reviewed by Dean Jackson.
+
+        Test: css-dark-mode/supported-color-schemes-priority.html
+
+        * css/CSSProperties.json: Make supported-color-schemes high-priority and add a comment.
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::applyMatchedProperties): Manually handle supported-color-schemes
+        after -webkit-ruby-position, before other properties, so it can affect resolved colors.
+
 2018-11-13  Charlie Turner  <cturner@igalia.com>
 
         [EME][GStreamer] Make CDMInstance's available in decryptors, and factor out some EME utility classes.
index 18c42ff..3540092 100644 (file)
             ],
             "codegen-properties": {
                 "converter": "SupportedColorSchemes",
-                "enable-if": "ENABLE_DARK_MODE_CSS"
+                "comment": "This is the second highest priority property, to ensure that its value can be checked when resolving colors.",
+                "enable-if": "ENABLE_DARK_MODE_CSS",
+                "high-priority": true
             },
             "status": {
                 "status": "non-standard"
index fe45581..c7ab3bb 100644 (file)
@@ -1379,6 +1379,11 @@ void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const
         applyCascadedProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition, applyState);
         adjustStyleForInterCharacterRuby();
 
+#if ENABLE(DARK_MODE_CSS)
+        // Supported color schemes can affect resolved colors, so we need to apply that property before any color properties.
+        applyCascadedProperties(CSSPropertySupportedColorSchemes, CSSPropertySupportedColorSchemes, applyState);
+#endif
+
         applyCascadedProperties(firstCSSProperty, lastHighPriorityProperty, applyState);
 
         // If our font got dirtied, update it now.
@@ -1398,12 +1403,16 @@ void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const
     cascade.addImportantMatches(matchResult, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
     cascade.addImportantMatches(matchResult, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
 
-
     ApplyCascadedPropertyState applyState { this, &cascade, &matchResult };
 
     applyCascadedProperties(CSSPropertyWebkitRubyPosition, CSSPropertyWebkitRubyPosition, applyState);
     adjustStyleForInterCharacterRuby();
 
+#if ENABLE(DARK_MODE_CSS)
+    // Supported color schemes can affect resolved colors, so we need to apply that property before any color properties.
+    applyCascadedProperties(CSSPropertySupportedColorSchemes, CSSPropertySupportedColorSchemes, applyState);
+#endif
+
     applyCascadedProperties(firstCSSProperty, lastHighPriorityProperty, applyState);
 
     // If the effective zoom value changes, we can't use the matched properties cache. Start over.