Changeset 288245 in webkit
- Timestamp:
- Jan 19, 2022, 3:13:41 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 2 deleted
- 9 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/css/CSSPrimitiveValue-ic-expected.txt (deleted)
-
LayoutTests/fast/css/CSSPrimitiveValue-ic.html (deleted)
-
LayoutTests/fast/css/CSSPrimitiveValue-modern-length-expected.txt (added)
-
LayoutTests/fast/css/CSSPrimitiveValue-modern-length.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/css/CSSPrimitiveValue.cpp (modified) (3 diffs)
-
Source/WebCore/css/CSSPrimitiveValue.h (modified) (1 diff)
-
Source/WebCore/css/CSSUnits.cpp (modified) (3 diffs)
-
Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.cpp (modified) (6 diffs)
-
Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.h (modified) (1 diff)
-
Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.idl (modified) (1 diff)
-
Source/WebCore/page/PrintContext.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r288244 r288245 1 2022-01-19 Sam Sneddon <gsnedders@apple.com> 2 3 Limit the deprecated CSSOMPrimitiveValue to formerly standardized unit types 4 https://bugs.webkit.org/show_bug.cgi?id=233651 5 <rdar://problem/85878291> 6 7 Reviewed by Darin Adler. 8 9 Updated/moved test to cover all modern length units, not just ic. 10 11 * fast/css/CSSPrimitiveValue-ic-expected.txt: Removed. 12 * fast/css/CSSPrimitiveValue-ic.html: Removed. 13 * fast/css/CSSPrimitiveValue-modern-length-expected.txt: Added. 14 * fast/css/CSSPrimitiveValue-modern-length.html: Added. 15 1 16 2022-01-19 Jon Lee <jonlee554@gmail.com> 2 17 -
trunk/Source/WebCore/ChangeLog
r288240 r288245 1 2022-01-19 Sam Sneddon <gsnedders@apple.com> 2 3 Limit the deprecated CSSOMPrimitiveValue to formerly standardized unit types 4 https://bugs.webkit.org/show_bug.cgi?id=233651 5 <rdar://problem/85878291> 6 7 Reviewed by Darin Adler. 8 9 This removes support, and makes it clear that these deprecated APIs shouldn't be exposing 10 anything more modern than what is standardized in DOM Level 2 Style. Hopefully this avoids 11 others in future adding support for new units. 12 13 Other changes included as they are necessary to make improved test not assert. 14 15 Test: fast/css/CSSPrimitiveValue-modern-length.html 16 17 * css/CSSUnits.cpp: 18 (WebCore::unitCategory): Ensure this is complete for all units. 19 (WebCore::canonicalUnitTypeForCategory): Ensure this is complete for all unit categories. 20 * css/DeprecatedCSSOMPrimitiveValue.cpp: 21 (WebCore::DeprecatedCSSOMPrimitiveValue::primitiveType const): Remove post-DOM Level 2 Style values. 22 (WebCore::DeprecatedCSSOMPrimitiveValue::getFloatValue const): Remove post-DOM Level 2 Style values. 23 (WebCore::DeprecatedCSSOMPrimitiveValue::getStringValue const): Add comment. 24 * css/DeprecatedCSSOMPrimitiveValue.h: Remove post-DOM Level 2 Style constants. 25 * css/DeprecatedCSSOMPrimitiveValue.idl: Remove post-DOM Level 2 Style constants. 26 * css/CSSPrimitiveValue.cpp: 27 (WebCore::CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor): Change to return std::optional, making explicit when there is no scaling factor. 28 (WebCore::CSSPrimitiveValue::doubleValueInternal const): Handle std::optional return. 29 * css/CSSPrimitiveValue.h: 30 (WebCore::CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor): Change to return std::optional, making explicit when there is no scaling factor. 31 * page/PrintContext.cpp: 32 (WebCore::PrintContext::computedPageMargin): Handle std::optional return. 33 1 34 2022-01-19 Said Abou-Hallawa <said@apple.com> 2 35 -
trunk/Source/WebCore/css/CSSPrimitiveValue.cpp
r288200 r288245 963 963 } 964 964 965 double CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(CSSUnitType unitType) 966 { 967 double factor = 1.0; 965 std::optional<double> CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(CSSUnitType unitType) 966 { 968 967 // FIXME: the switch can be replaced by an array of scale factors. 969 968 switch (unitType) { … … 974 973 case CSSUnitType::CSS_HZ: 975 974 case CSSUnitType::CSS_DPPX: 976 break; 975 return 1.0; 976 977 977 case CSSUnitType::CSS_X: 978 978 // This is semantically identical to (canonical) dppx 979 break; 979 return 1.0; 980 980 981 case CSSUnitType::CSS_CM: 981 factor =cssPixelsPerInch / cmPerInch;982 break; 982 return cssPixelsPerInch / cmPerInch; 983 983 984 case CSSUnitType::CSS_DPCM: 984 factor =cmPerInch / cssPixelsPerInch; // (2.54 cm/in)985 break; 985 return cmPerInch / cssPixelsPerInch; // (2.54 cm/in) 986 986 987 case CSSUnitType::CSS_MM: 987 factor =cssPixelsPerInch / mmPerInch;988 break; 988 return cssPixelsPerInch / mmPerInch; 989 989 990 case CSSUnitType::CSS_Q: 990 factor =cssPixelsPerInch / QPerInch;991 break; 991 return cssPixelsPerInch / QPerInch; 992 992 993 case CSSUnitType::CSS_IN: 993 factor =cssPixelsPerInch;994 break; 994 return cssPixelsPerInch; 995 995 996 case CSSUnitType::CSS_DPI: 996 factor =1 / cssPixelsPerInch;997 break; 997 return 1 / cssPixelsPerInch; 998 998 999 case CSSUnitType::CSS_PT: 999 factor =cssPixelsPerInch / 72.0;1000 break; 1000 return cssPixelsPerInch / 72.0; 1001 1001 1002 case CSSUnitType::CSS_PC: 1002 factor =cssPixelsPerInch * 12.0 / 72.0; // 1 pc == 12 pt1003 break; 1003 return cssPixelsPerInch * 12.0 / 72.0; // 1 pc == 12 pt 1004 1004 1005 case CSSUnitType::CSS_RAD: 1005 factor =degreesPerRadianDouble;1006 break; 1006 return degreesPerRadianDouble; 1007 1007 1008 case CSSUnitType::CSS_GRAD: 1008 factor =degreesPerGradientDouble;1009 break; 1009 return degreesPerGradientDouble; 1010 1010 1011 case CSSUnitType::CSS_TURN: 1011 factor =degreesPerTurnDouble;1012 break; 1012 return degreesPerTurnDouble; 1013 1013 1014 case CSSUnitType::CSS_S: 1014 1015 case CSSUnitType::CSS_KHZ: 1015 factor =1000;1016 break; 1016 return 1000; 1017 1017 1018 default: 1018 break; 1019 } 1020 1021 return factor; 1019 return std::nullopt; 1020 } 1022 1021 } 1023 1022 … … 1116 1115 double convertedValue = doubleValue(); 1117 1116 1117 // If we don't need to scale it, don't worry about if we can scale it. 1118 if (sourceUnitType == targetUnitType) 1119 return convertedValue; 1120 1118 1121 // First convert the value from primitiveUnitType() to canonical type. 1119 double factor = conversionToCanonicalUnitsScaleFactor(sourceUnitType); 1120 convertedValue *= factor; 1122 auto sourceFactor = conversionToCanonicalUnitsScaleFactor(sourceUnitType); 1123 if (!sourceFactor.has_value()) 1124 return std::nullopt; 1125 convertedValue *= sourceFactor.value(); 1121 1126 1122 1127 // Now convert from canonical type to the target unitType. 1123 factor = conversionToCanonicalUnitsScaleFactor(targetUnitType); 1124 convertedValue /= factor; 1128 auto targetFactor = conversionToCanonicalUnitsScaleFactor(targetUnitType); 1129 if (!targetFactor.has_value()) 1130 return std::nullopt; 1131 convertedValue /= targetFactor.value(); 1125 1132 1126 1133 return convertedValue; -
trunk/Source/WebCore/css/CSSPrimitiveValue.h
r287909 r288245 195 195 bool equals(const CSSPrimitiveValue&) const; 196 196 197 static doubleconversionToCanonicalUnitsScaleFactor(CSSUnitType);197 static std::optional<double> conversionToCanonicalUnitsScaleFactor(CSSUnitType); 198 198 static String unitTypeString(CSSUnitType); 199 199 -
trunk/Source/WebCore/css/CSSUnits.cpp
r287909 r288245 42 42 case CSSUnitType::CSS_Q: 43 43 case CSSUnitType::CSS_IC: 44 case CSSUnitType::CSS_EMS: 45 case CSSUnitType::CSS_EXS: 46 case CSSUnitType::CSS_CHS: 47 case CSSUnitType::CSS_REMS: 48 case CSSUnitType::CSS_LHS: 49 case CSSUnitType::CSS_RLHS: 50 case CSSUnitType::CSS_VW: 51 case CSSUnitType::CSS_VH: 52 case CSSUnitType::CSS_VMIN: 53 case CSSUnitType::CSS_VMAX: 54 case CSSUnitType::CSS_VB: 55 case CSSUnitType::CSS_VI: 56 case CSSUnitType::CSS_SVW: 57 case CSSUnitType::CSS_SVH: 58 case CSSUnitType::CSS_SVMIN: 59 case CSSUnitType::CSS_SVMAX: 60 case CSSUnitType::CSS_SVB: 61 case CSSUnitType::CSS_SVI: 62 case CSSUnitType::CSS_LVW: 63 case CSSUnitType::CSS_LVH: 64 case CSSUnitType::CSS_LVMIN: 65 case CSSUnitType::CSS_LVMAX: 66 case CSSUnitType::CSS_LVB: 67 case CSSUnitType::CSS_LVI: 68 case CSSUnitType::CSS_DVW: 69 case CSSUnitType::CSS_DVH: 70 case CSSUnitType::CSS_DVMIN: 71 case CSSUnitType::CSS_DVMAX: 72 case CSSUnitType::CSS_DVB: 73 case CSSUnitType::CSS_DVI: 44 74 return CSSUnitCategory::Length; 45 75 case CSSUnitType::CSS_MS: … … 59 89 case CSSUnitType::CSS_DPCM: 60 90 return CSSUnitCategory::Resolution; 61 default: 91 case CSSUnitType::CSS_ATTR: 92 case CSSUnitType::CSS_CALC: 93 case CSSUnitType::CSS_CALC_PERCENTAGE_WITH_LENGTH: 94 case CSSUnitType::CSS_CALC_PERCENTAGE_WITH_NUMBER: 95 case CSSUnitType::CSS_COUNTER: 96 case CSSUnitType::CSS_COUNTER_NAME: 97 case CSSUnitType::CSS_DIMENSION: 98 case CSSUnitType::CSS_FONT_FAMILY: 99 case CSSUnitType::CSS_FR: 100 case CSSUnitType::CSS_IDENT: 101 case CSSUnitType::CSS_PAIR: 102 case CSSUnitType::CSS_PROPERTY_ID: 103 case CSSUnitType::CSS_QUAD: 104 case CSSUnitType::CSS_QUIRKY_EMS: 105 case CSSUnitType::CSS_RECT: 106 case CSSUnitType::CSS_RGBCOLOR: 107 case CSSUnitType::CSS_SHAPE: 108 case CSSUnitType::CSS_STRING: 109 case CSSUnitType::CSS_UNICODE_RANGE: 110 case CSSUnitType::CSS_UNKNOWN: 111 case CSSUnitType::CSS_URI: 112 case CSSUnitType::CSS_VALUE_ID: 113 case CSSUnitType::CustomIdent: 62 114 return CSSUnitCategory::Other; 63 115 } … … 81 133 case CSSUnitCategory::Resolution: 82 134 return CSSUnitType::CSS_DPPX; 83 default:135 case CSSUnitCategory::Other: 84 136 return CSSUnitType::CSS_UNKNOWN; 85 137 } -
trunk/Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.cpp
r287909 r288245 35 35 unsigned short DeprecatedCSSOMPrimitiveValue::primitiveType() const 36 36 { 37 // FIXME: Some of these are never exposed to the web because code elsewhere prevents it. We can ASSERT_NOT_REACHED for those.38 // FIXME: Some of these should return CSS_UNKNOWN instead of hard-coded numbers not mentioned in the IDL file.39 40 37 switch (m_value->primitiveType()) { 41 38 case CSSUnitType::CSS_ATTR: return CSS_ATTR; 42 case CSSUnitType::CSS_CALC: return 113;43 case CSSUnitType::CSS_CALC_PERCENTAGE_WITH_LENGTH: return 115;44 case CSSUnitType::CSS_CALC_PERCENTAGE_WITH_NUMBER: return 114;45 case CSSUnitType::CSS_CHS: return 109;46 39 case CSSUnitType::CSS_IC: return CSS_UNKNOWN; 47 40 case CSSUnitType::CSS_CM: return CSS_CM; 48 41 case CSSUnitType::CSS_COUNTER: return CSS_COUNTER; 49 case CSSUnitType::CSS_COUNTER_NAME: return 110;50 42 case CSSUnitType::CSS_DEG: return CSS_DEG; 51 43 case CSSUnitType::CSS_DIMENSION: return CSS_DIMENSION; 52 case CSSUnitType::CSS_DPCM: return 32;53 case CSSUnitType::CSS_DPI: return 31;54 case CSSUnitType::CSS_DPPX: return 30;55 44 case CSSUnitType::CSS_EMS: return CSS_EMS; 56 45 case CSSUnitType::CSS_EXS: return CSS_EXS; 57 46 case CSSUnitType::CSS_FONT_FAMILY: return CSS_STRING; 58 case CSSUnitType::CSS_FR: return 33;59 47 case CSSUnitType::CSS_GRAD: return CSS_GRAD; 60 48 case CSSUnitType::CSS_HZ: return CSS_HZ; … … 64 52 case CSSUnitType::CSS_IN: return CSS_IN; 65 53 case CSSUnitType::CSS_KHZ: return CSS_KHZ; 66 case CSSUnitType::CSS_LHS: return 35;67 54 case CSSUnitType::CSS_MM: return CSS_MM; 68 55 case CSSUnitType::CSS_MS: return CSS_MS; 69 56 case CSSUnitType::CSS_NUMBER: return CSS_NUMBER; 70 case CSSUnitType::CSS_PAIR: return 100;71 57 case CSSUnitType::CSS_PC: return CSS_PC; 72 58 case CSSUnitType::CSS_PERCENTAGE: return CSS_PERCENTAGE; … … 74 60 case CSSUnitType::CSS_PT: return CSS_PT; 75 61 case CSSUnitType::CSS_PX: return CSS_PX; 76 case CSSUnitType::CSS_Q: return 34;77 case CSSUnitType::CSS_QUAD: return 112;78 case CSSUnitType::CSS_QUIRKY_EMS: return 120;79 62 case CSSUnitType::CSS_RAD: return CSS_RAD; 80 63 case CSSUnitType::CSS_RECT: return CSS_RECT; 81 case CSSUnitType::CSS_REMS: return 108;82 64 case CSSUnitType::CSS_RGBCOLOR: return CSS_RGBCOLOR; 83 case CSSUnitType::CSS_RLHS: return 36;84 65 case CSSUnitType::CSS_S: return CSS_S; 85 case CSSUnitType::CSS_SHAPE: return 111;86 66 case CSSUnitType::CSS_STRING: return CSS_STRING; 87 case CSSUnitType::CSS_TURN: return 107;88 case CSSUnitType::CSS_UNICODE_RANGE: return 102;89 67 case CSSUnitType::CSS_UNKNOWN: return CSS_UNKNOWN; 90 68 case CSSUnitType::CSS_URI: return CSS_URI; 91 69 case CSSUnitType::CSS_VALUE_ID: return CSS_IDENT; 92 case CSSUnitType::CSS_VH: return CSS_VH;93 case CSSUnitType::CSS_VMAX: return CSS_VMAX;94 case CSSUnitType::CSS_VMIN: return CSS_VMIN;95 case CSSUnitType::CSS_VW: return CSS_VW;96 case CSSUnitType::CSS_X: return 37;97 70 71 // All other, including newer types, should return UNKNOWN. 98 72 default: return CSS_UNKNOWN; 99 73 } … … 102 76 ExceptionOr<float> DeprecatedCSSOMPrimitiveValue::getFloatValue(unsigned short unitType) const 103 77 { 104 // FIXME: Some of these values do not need to be exposed as a destination type. Remove cases below and give InvalidAccessError instead.105 106 78 switch (unitType) { 107 79 case CSS_CM: return m_value->getFloatValue(CSSUnitType::CSS_CM); … … 123 95 case CSS_RAD: return m_value->getFloatValue(CSSUnitType::CSS_RAD); 124 96 case CSS_S: return m_value->getFloatValue(CSSUnitType::CSS_S); 125 case CSS_VH: return m_value->getFloatValue(CSSUnitType::CSS_VH);126 case CSS_VMAX: return m_value->getFloatValue(CSSUnitType::CSS_VMAX);127 case CSS_VMIN: return m_value->getFloatValue(CSSUnitType::CSS_VMIN);128 case CSS_VW: return m_value->getFloatValue(CSSUnitType::CSS_VW);129 97 130 case 30: return m_value->getFloatValue(CSSUnitType::CSS_DPPX); 131 case 31: return m_value->getFloatValue(CSSUnitType::CSS_DPI); 132 case 32: return m_value->getFloatValue(CSSUnitType::CSS_DPCM); 133 case 33: return m_value->getFloatValue(CSSUnitType::CSS_FR); 134 case 34: return m_value->getFloatValue(CSSUnitType::CSS_Q); 135 case 35: return m_value->getFloatValue(CSSUnitType::CSS_LHS); 136 case 36: return m_value->getFloatValue(CSSUnitType::CSS_RLHS); 137 case 37: return m_value->getFloatValue(CSSUnitType::CSS_X); 138 case 107: return m_value->getFloatValue(CSSUnitType::CSS_TURN); 139 case 108: return m_value->getFloatValue(CSSUnitType::CSS_REMS); 140 case 109: return m_value->getFloatValue(CSSUnitType::CSS_CHS); 141 case 113: return m_value->getFloatValue(CSSUnitType::CSS_CALC); 142 case 114: return m_value->getFloatValue(CSSUnitType::CSS_CALC_PERCENTAGE_WITH_NUMBER); 143 case 115: return m_value->getFloatValue(CSSUnitType::CSS_CALC_PERCENTAGE_WITH_LENGTH); 144 case 120: return m_value->getFloatValue(CSSUnitType::CSS_QUIRKY_EMS); 145 98 // All other, including newer types, should raise an exception. 146 99 default: return Exception { InvalidAccessError }; 147 100 } … … 155 108 case CSS_STRING: return m_value->stringValue(); 156 109 case CSS_URI: return m_value->stringValue(); 110 111 // All other, including newer types, should raise an exception. 157 112 default: return Exception { InvalidAccessError }; 158 113 } -
trunk/Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.h
r285373 r288245 64 64 CSS_COUNTER = 23, 65 65 CSS_RECT = 24, 66 CSS_RGBCOLOR = 25, 67 CSS_VW = 26, 68 CSS_VH = 27, 69 CSS_VMIN = 28, 70 CSS_VMAX = 29 66 CSS_RGBCOLOR = 25 67 // Do not add new units here; this is deprecated and we shouldn't expose anything not in DOM Level 2 Style. 71 68 }; 72 69 -
trunk/Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.idl
r288118 r288245 49 49 const unsigned short CSS_RECT = 24; 50 50 const unsigned short CSS_RGBCOLOR = 25; 51 const unsigned short CSS_VW = 26; 52 const unsigned short CSS_VH = 27; 53 const unsigned short CSS_VMIN = 28; 54 const unsigned short CSS_VMAX = 29; 51 // Do not add new units here; this is deprecated and we shouldn't expose anything not in DOM Level 2 Style. 55 52 56 53 readonly attribute unsigned short primitiveType; -
trunk/Source/WebCore/page/PrintContext.cpp
r282860 r288245 90 90 auto style = frame()->document()->styleScope().resolver().styleForPage(0); 91 91 92 float pixelToPointScaleFactor = 1 / CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(CSSUnitType::CSS_PT) ;92 float pixelToPointScaleFactor = 1 / CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(CSSUnitType::CSS_PT).value(); 93 93 return { style->marginTop().isAuto() ? printMargin.top() : style->marginTop().value() * pixelToPointScaleFactor, 94 94 style->marginRight().isAuto() ? printMargin.right() : style->marginRight().value() * pixelToPointScaleFactor,
Note:
See TracChangeset
for help on using the changeset viewer.