gradient-interpolation-method-computed.html (5641B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>CSS Images Module Level 4: parsing gradients with color interpolation methods</title> 6 <link rel="author" title="Sam Weinig" href="mailto:weinig@apple.com"> 7 <link rel="help" href="https://drafts.csswg.org/css-images-4/#gradients"> 8 <link rel="help" href="https://drafts.csswg.org/css-color-4/#color-interpolation-method"> 9 <meta name="assert" content="gradients supports the addition of color-interpolation-method to the grammar"> 10 <script src="/resources/testharness.js"></script> 11 <script src="/resources/testharnessreport.js"></script> 12 <script src="/css/support/computed-testcommon.js"></script> 13 </head> 14 <body> 15 <div id="target"></div> 16 <div id="computedStyleTarget"></div> 17 <script> 18 19 const LINEAR_GRADIENT_SPECIFIERS = [ 20 { input: '30deg' }, 21 { input: 'to right bottom' }, 22 ]; 23 24 const RADIAL_GRADIENT_SPECIFIERS = [ 25 { input: '50px' }, 26 { input: 'ellipse 50% 40em', output: '50% 640px' }, 27 { input: 'at right center', output: 'at 100% 50%' }, 28 ]; 29 30 const CONIC_GRADIENT_SPECIFIERS = [ 31 { input: 'from 30deg' }, 32 { input: 'at left 10px top 50em', output: 'at 10px 800px' }, 33 ]; 34 35 const legacy_stops = "red, blue" 36 const non_legacy_stops = "color(srgb 1 0 0), blue" 37 38 // getComputedStyle can return different values than input 39 function get_computed_style_value_for_stops(stops) { 40 const div = document.getElementById("computedStyleTarget"); 41 computedColors = []; 42 stops.split(",").forEach(stop => { 43 div.style["color"] = stop; 44 computedColors.push(getComputedStyle(div)["color"]); 45 }); 46 return computedColors.join(", "); 47 } 48 const legacy_stops_computed_style = get_computed_style_value_for_stops(legacy_stops); 49 const non_legacy_stops_computed_style = get_computed_style_value_for_stops(non_legacy_stops); 50 51 function test_gradients_no_specified_interpolation_method(gradientFunction, specifiers, stops, computed_stops) 52 { 53 for (const specifier of specifiers) { 54 const input = specifier.input 55 const output = specifier.output ? specifier.output : specifier.input 56 test_computed_value(`background-image`, `${gradientFunction}(${input}, ${stops})`, `${gradientFunction}(${output}, ${computed_stops})`) 57 } 58 } 59 60 function test_gradients(gradientFunction, colorInterpolationMethod, colorInterpolationMethodResult, specifiers, stops, computed_stops) { 61 const resultForNoSpecifierCase = (colorInterpolationMethodResult == "") ? "" : `in ${colorInterpolationMethodResult}, ` 62 test_computed_value(`background-image`, `${gradientFunction}(in ${colorInterpolationMethod}, ${stops})`, `${gradientFunction}(${resultForNoSpecifierCase}${computed_stops})`) 63 64 for (const specifier of specifiers) { 65 const input = specifier.input 66 const output = specifier.output ? specifier.output : specifier.input 67 const result = colorInterpolationMethodResult == "" ? ", " : ` in ${colorInterpolationMethodResult}, ` 68 test_computed_value(`background-image`, `${gradientFunction}(${input} in ${colorInterpolationMethod}, ${stops})`, `${gradientFunction}(${output}${result}${computed_stops})`) 69 test_computed_value(`background-image`, `${gradientFunction}(in ${colorInterpolationMethod} ${input}, ${stops})`, `${gradientFunction}(${output}${result}${computed_stops})`) 70 } 71 } 72 73 function test_gradient_with_interpolation_method(gradientFunction, colorInterpolationMethod, colorInterpolationMethodResult, specifiers, stops, computed_stops) { 74 const colorInterpolationMethodResultForLegacyStops = (colorInterpolationMethodResult == "srgb") ? "" : colorInterpolationMethodResult; 75 test_gradients(gradientFunction, colorInterpolationMethod, colorInterpolationMethodResultForLegacyStops, specifiers, legacy_stops, legacy_stops_computed_style); 76 77 const colorInterpolationMethodResultForNonLegacyStops = (colorInterpolationMethodResult == "oklab") ? "" : colorInterpolationMethodResult; 78 test_gradients(gradientFunction, colorInterpolationMethod, colorInterpolationMethodResultForNonLegacyStops, specifiers, non_legacy_stops, non_legacy_stops_computed_style); 79 } 80 81 function test_each_interpolation_method(gradientFunction, specifiers) { 82 test_gradients_no_specified_interpolation_method(gradientFunction, specifiers, legacy_stops, legacy_stops_computed_style); 83 test_gradients_no_specified_interpolation_method(gradientFunction, specifiers, non_legacy_stops, non_legacy_stops_computed_style); 84 85 for (const colorSpace of [ "lab", "oklab", "srgb", "srgb-linear", "xyz", "xyz-d50", "xyz-d65" ]) { 86 const colorInterpolationMethod = colorSpace 87 const colorInterpolationMethodResult = colorSpace == "xyz" ? "xyz-d65" : colorInterpolationMethod 88 89 test_gradient_with_interpolation_method(gradientFunction, colorInterpolationMethod, colorInterpolationMethodResult, specifiers) 90 } 91 92 for (const colorSpace of [ "hsl", "hwb", "lch", "oklch" ]) { 93 for (const hueInterpolationMethod of [ "", " shorter hue", " longer hue", " increasing hue", " decreasing hue" ]) { 94 const colorInterpolationMethod = `${colorSpace}${hueInterpolationMethod}` 95 const colorInterpolationMethodResult = hueInterpolationMethod == " shorter hue" ? colorSpace : colorInterpolationMethod 96 97 test_gradient_with_interpolation_method(gradientFunction, colorInterpolationMethod, colorInterpolationMethodResult, specifiers) 98 } 99 } 100 } 101 102 test_each_interpolation_method("linear-gradient", LINEAR_GRADIENT_SPECIFIERS) 103 test_each_interpolation_method("radial-gradient", RADIAL_GRADIENT_SPECIFIERS) 104 test_each_interpolation_method("conic-gradient", CONIC_GRADIENT_SPECIFIERS) 105 106 </script> 107 </body> 108 </html>