alignment-parsing-utils.js (6668B)
1 var selfPositionClasses = {"Start":"start", "End":"end", "SelfStart":"self-start", "SelfEnd":"self-end", "Center":"center", "FlexStart":"flex-start", "FlexEnd":"flex-end"}; 2 var contentPositionClasses = {"Start":"start", "End":"end", "Center":"center", "FlexStart":"flex-start", "FlexEnd":"flex-end"}; 3 var distributionClasses = {"Stretch":"stretch", "SpaceAround":"space-around", "SpaceBetween":"space-between", "SpaceEvenly":"space-evenly"}; 4 var baselineClasses = {"Baseline":"baseline", "FirstBaseline":"first baseline", "LastBaseline":"last baseline"}; 5 var overflowClasses = {"SafeFlexEnd":"safe flex-end", "UnsafeEnd":"unsafe end", "SafeEnd":"safe end", "UnsafeFlexStart":"unsafe flex-start", "SafeCenter":"safe center"}; 6 var legacyClasses = {"LegacyLeft":"legacy left", "LegacyCenter":"legacy center", "LegacyRight":"legacy right"}; 7 8 var invalidPositionValues = ["auto safe", "auto left", "normal unsafe", "normal stretch", "baseline normal", 9 "baseline center", "first baseline center", "last baseline center", "baseline last", 10 "baseline first", "stretch unsafe", "stretch right", "unsafe unsafe", "unsafe safe", 11 "center start", "unsafe stretch", "safe stretch", "baseline safe", "unsafe baseline", 12 "unsafe safe left", "unsafe left safe", "left safe unsafe safe", "start safe", "safe"]; 13 var invalidLegacyValues = ["legacy start", "legacy end", "legacy right unsafe", "legacy auto", "legacy stretch", 14 "legacy left right"]; 15 var invalidDistributionValues = ["space-between left", "space-around center", "space-evenly right", 16 "stretch safe start", "space-around unsafe", "space-evenly safe flex-start", 17 "space-between safe", "space-between stretch", "stretch start", 18 "stretch baseline", "first baseline space-around"]; 19 20 function checkPlaceShorhand(shorthand, shorthandValue, alignValue, justifyValue) 21 { 22 var div = document.createElement("div"); 23 div.style[shorthand] = shorthandValue; 24 document.body.appendChild(div); 25 26 if (alignValue === "first baseline") 27 alignValue = "baseline"; 28 if (justifyValue === "first baseline") 29 justifyValue = "baseline"; 30 if (justifyValue === "") 31 justifyValue = alignValue; 32 33 let specifiedValue = (alignValue + " " + justifyValue).trim(); 34 if (alignValue === justifyValue) 35 specifiedValue = alignValue; 36 37 var resolvedValue = getComputedStyle(div).getPropertyValue(shorthand); 38 var expectedResolvedValue = (alignValue + " " + justifyValue).trim(); 39 if (alignValue === justifyValue) 40 expectedResolvedValue = alignValue; 41 42 assert_equals(div.style[shorthand], specifiedValue, shorthandValue + " specified value"); 43 // FIXME: We need https://github.com/w3c/csswg-drafts/issues/1041 to clarify which 44 // value is expected for the shorthand's 'resolved value". 45 assert_in_array(resolvedValue, ["", expectedResolvedValue], shorthand + " resolved value"); 46 } 47 48 function checkPlaceShorhandLonghands(shorthand, alignLonghand, justifyLonghand, alignValue, justifyValue = "") 49 { 50 var div = document.createElement("div"); 51 div.setAttribute("style", shorthand + ": " + alignValue + " " + justifyValue); 52 document.body.appendChild(div); 53 if (alignValue === "first baseline") 54 alignValue = "baseline"; 55 if (justifyValue === "first baseline") 56 justifyValue = "baseline"; 57 if (justifyValue === "") 58 justifyValue = alignValue; 59 assert_equals(div.style[alignLonghand], 60 alignValue, alignLonghand + " expanded value"); 61 assert_equals(div.style[justifyLonghand], 62 justifyValue, justifyLonghand + " expanded value"); 63 } 64 65 function checkPlaceShorthandInvalidValues(shorthand, alignLonghand, justifyLonghand, value) 66 { 67 var div = document.createElement("div"); 68 var css = alignLonghand + ": start; " + justifyLonghand + ": end;" + shorthand + ": " + value; 69 div.setAttribute("style", css); 70 document.body.appendChild(div); 71 assert_equals(div.style[alignLonghand], 72 "start", alignLonghand + " expanded value"); 73 assert_equals(div.style[justifyLonghand], 74 "end", justifyLonghand + " expanded value"); 75 } 76 77 function checkValues(element, property, propertyID, value, computedValue) 78 { 79 window.element = element; 80 var elementID = element.id || "element"; 81 assert_equals(eval('element.style.' + property), value, propertyID + ' specified value is not what it should.'); 82 assert_equals(eval("window.getComputedStyle(" + elementID + ", '').getPropertyValue('" + propertyID + "')"), computedValue, propertyID + " computed style is not what is should."); 83 } 84 85 function checkBadValues(element, property, propertyID, value) 86 { 87 var elementID = element.id || "element"; 88 element.style[property] = ""; 89 var initialValue = eval("window.getComputedStyle(" + elementID + " , '').getPropertyValue('" + propertyID + "')"); 90 element.style[property] = value; 91 checkValues(element, property, propertyID, "", initialValue); 92 } 93 94 function checkInitialValues(element, property, propertyID, value, initial) 95 { 96 element.style[property] = value; 97 checkValues(element, property, propertyID, value, value); 98 element.style[property] = "initial"; 99 checkValues(element, property, propertyID, "initial", initial); 100 } 101 102 function checkInheritValues(property, propertyID, value) 103 { 104 var parentElement = document.createElement("div"); 105 document.body.appendChild(parentElement); 106 parentElement.style[property] = value; 107 checkValues(parentElement, property, propertyID, value, value); 108 109 var element = document.createElement("div"); 110 parentElement.appendChild(element); 111 element.style[property] = "inherit"; 112 checkValues(element, property, propertyID, "inherit", value); 113 } 114 115 function checkLegacyValues(property, propertyID, value) 116 { 117 var parentElement = document.createElement("div"); 118 document.body.appendChild(parentElement); 119 parentElement.style[property] = value; 120 checkValues(parentElement, property, propertyID, value, value); 121 122 var element = document.createElement("div"); 123 parentElement.appendChild(element); 124 checkValues(element, property, propertyID, "", value); 125 } 126 127 function checkSupportedValues(elementID, property) 128 { 129 var value = eval("window.getComputedStyle(" + elementID + " , '').getPropertyValue('" + property + "')"); 130 var value1 = eval("window.getComputedStyle(" + elementID + " , '')"); 131 shouldBeTrue("CSS.supports('" + property + "', '" + value + "')"); 132 }