variable-presentation-attribute.html (8754B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>CSS Variables and SVG presentation attributes</title> 5 6 <meta rel="author" title="Kevin Babbitt"> 7 <meta rel="author" title="Greg Whitworth"> 8 <link rel="author" title="Microsoft Corporation" href="http://microsoft.com" /> 9 <!-- This is not directly specified in the spec but should work --> 10 <link rel="help" href="http://www.w3.org/TR/css-variables-1/#defining-variables"> 11 12 <script src="/resources/testharness.js"></script> 13 <script src="/resources/testharnessreport.js"></script> 14 <style> 15 body { 16 --stroke3: 5px 17 } 18 </style> 19 </head> 20 <body style="--prop: ;"> 21 <svg id="svg" width="300px" height="100px"> 22 <defs> 23 <linearGradient id="gradient"> 24 <stop offset="0" stop-color="#ff8800"></stop> 25 <stop offset="1" stop-color="#ffff00"></stop> 26 </linearGradient> 27 </defs> 28 <rect id="box1" x="15" y="15" width="50" height="50" fill="lightgreen" stroke-width="var(--stroke1)" stroke="green" style="--stroke1: 10px"></rect> 29 <rect id="box2" x="115" y="15" width="50" height="50" fill="lightgreen" stroke-width="var(--stroke2)" stroke="green" style="--stroke2: 20px"></rect> 30 <rect id="box3" x="215" y="15" width="50" height="50" fill="lightgreen" stroke-width="var(--stroke3)" stroke="green"></rect> 31 <symbol id="test4" clip="var(--clip)" style="--clip: rect(1px 10em 3rem 2ch)"></symbol> 32 </svg> 33 34 <script> 35 "use strict"; 36 37 var testcases = [ 38 { element: "box1", property:"stroke-width", expectedPropertyValue: "10px" }, 39 { element: "box2", property:"stroke-width", expectedPropertyValue: "20px" }, 40 { element: "box3", property:"stroke-width", expectedPropertyValue: "5px" }, 41 { element: "test4", property:"clip", expectedPropertyValue: "rect(1px, 160px, 48px, 16px)" }, 42 ]; 43 44 testcases.forEach(function (testcase) { 45 test( function () { 46 var element = document.getElementById(testcase.element); 47 var computedStyle = window.getComputedStyle(element); 48 var computedPropertyValue = computedStyle.getPropertyValue(testcase.property); 49 assert_equals(computedPropertyValue, testcase.expectedPropertyValue); 50 }, "Testing '" + testcase.property + "' on '#" + testcase.element + "'."); 51 }); 52 53 let testproperties = [ 54 { property: "alignment-baseline", valuesToTest:["baseline", "before-edge", "text-before-edge", "middle", "central", "after-edge", "text-after-edge", "ideographic", "alphabetic", "hanging", "mathematical"], default: "baseline" }, 55 { property: "baseline-shift", valuesToTest:["baseline", "sub", "super", "13%", "28px"], default: "baseline" }, 56 { property: "clip-rule", valuesToTest:["nonzero", "evenodd"], default: "nonzero" }, 57 { property: "color", valuesToTest:["rgb(128, 0, 128)"], default: "rgb(0, 0, 0)" }, 58 { property: "color-interpolation-filters", valuesToTest:["auto", "sRGB", "linearRGB"], default: "" }, 59 { property: "cursor", valuesToTest:["auto", "crosshair", "default", "pointer", "move", "e-resize", "ne-resize", "nw-resize", "n-resize", "se-resize", "sw-resize", "s-resize", "w-resize", "text", "wait", "help"], default: "auto" }, 60 { property: "direction", valuesToTest:["ltr", "rtl"], default: "ltr" }, 61 { property: "display", valuesToTest:["inline", "block", "list-item", "table", "inline-table", "table-row-group", "table-header-group", "table-footer-group", "table-row", "table-column-group", "table-column", "table-cell", "table-caption", "none"], default: "inline" }, 62 { property: "dominant-baseline", valuesToTest:["auto", "ideographic", "alphabetic", "hanging", "mathematical", "central", "middle", "text-after-edge", "text-before-edge"], default: "auto" }, 63 { property: "fill", valuesToTest:["red", "url(#gradient) black"], default: "black" }, 64 { property: "fill-opacity", valuesToTest:["0.8"], default: "1" }, 65 { property: "fill-rule", valuesToTest:["nonzero", "evenodd"], default: "nonzero" }, 66 { property: "filter", valuesToTest:["none"], default: "none" }, 67 { property: "flood-color", valuesToTest:["currentColor", "green"], default: "" }, 68 { property: "flood-opacity", valuesToTest:["0.7"], default: "1" }, 69 { property: "font-family", valuesToTest:["Arial", "Times New Roman"], default: "Times New Roman" }, 70 { property: "font-size", valuesToTest:["31px"], default: "16px" }, 71 { property: "font-size-adjust", valuesToTest:["22", "none"], default: "none" }, 72 { property: "font-stretch", valuesToTest:["100%", "50%", "62.5%", "75%", "87.5%", "112.5%", "125%", "150%", "200%"], default: "100%" }, 73 { property: "font-style", valuesToTest:["normal", "italic"], default: "normal" }, 74 { property: "font-weight", valuesToTest:["100", "200", "300", "400", "500", "600", "700", "800", "900"], default: "400" }, 75 { property: "glyph-orientation-horizontal", valuesToTest:["13deg"], default: "0deg" }, 76 { property: "glyph-orientation-vertical", valuesToTest:["auto", "19deg"], default: "auto" }, 77 { property: "kerning", valuesToTest:["auto", "15"], default: "auto" }, 78 { property: "letter-spacing", valuesToTest:["normal", "21px"], default: "normal" }, 79 { property: "lighting-color", valuesToTest:["currentColor", "pink"], default: "" }, 80 { property: "opacity", valuesToTest:["0.11"], default: "1" }, 81 { property: "overflow", valuesToTest:["visible", "hidden", "scroll", "auto"], default: "visible" }, 82 { property: "pointer-events", valuesToTest:["visiblePainted", "visibleFill", "visibleStroke", "visible", "painted", "fill", "stroke", "all", "none"], default: "visiblePainted" }, 83 { property: "stop-color", valuesToTest:["currentColor", "maroon"], default: "" }, 84 { property: "stop-opacity", valuesToTest:["0.225"], default: "1" }, 85 { property: "stroke", valuesToTest:["green", "url(#gradient)"], default: "" }, 86 { property: "stroke-dasharray", valuesToTest:["none", "2px"], default: "none" }, 87 { property: "stroke-dashoffset", valuesToTest:["14%", "98px"], default: "0px" }, 88 { property: "stroke-linecap", valuesToTest:["butt", "round", "square"], default: "butt" }, 89 { property: "stroke-linejoin", valuesToTest:["miter", "round", "bevel"], default: "miter" }, 90 { property: "stroke-miterlimit", valuesToTest:["2"], default: "4" }, 91 { property: "stroke-opacity", valuesToTest:["0.221"], default: "1" }, 92 { property: "stroke-width", valuesToTest:["88%", "31px"], default: "1px" }, 93 { property: "text-anchor", valuesToTest:["start", "middle", "end"], default: "start" }, 94 { property: "text-decoration-line", valuesToTest:["none", "underline", "overline", "line-through"], default: "none" }, 95 { property: "text-decoration-style", valuesToTest:["solid", "double", "dotted", "dashed", "wavy"], default: "solid" }, 96 { property: "visibility", valuesToTest:["visible", "hidden", "collapse"], default: "visible" }, 97 { property: "word-spacing", valuesToTest:["31px"], default: "0px" }, 98 { property: "writing-mode", valuesToTest:["lr-tb", "rl-tb"], default: "lr-tb" }, 99 ]; 100 101 testproperties.forEach(function (testcase) { 102 test( function () { 103 let svg = document.getElementById("svg"); 104 let rect = document.createElement("rect"); 105 svg.appendChild(rect); 106 let computedStyle = window.getComputedStyle(rect); 107 let expectedDefaultValue = testcase.default ? testcase.default : ""; 108 let actualValue = computedStyle.getPropertyValue(testcase.property); 109 assert_equals(actualValue, expectedDefaultValue, "Default value."); 110 rect.style.cssText = testcase.property + ":var(--prop);"; 111 112 for (var value of testcase.valuesToTest) 113 { 114 document.body.style.setProperty("--prop", value); 115 computedStyle = window.getComputedStyle(rect); 116 let actualValue = computedStyle.getPropertyValue(testcase.property); 117 assert_equals(actualValue, value, "Value Test."); 118 } 119 120 svg.removeChild(rect); 121 }, "Testing '" + testcase.property + "'."); 122 }); 123 </script> 124 </body> 125 </html>