⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 288245 in webkit


Ignore:
Timestamp:
Jan 19, 2022, 3:13:41 PM (5 years ago)
Author:
Sam Sneddon
Message:

Limit the deprecated CSSOMPrimitiveValue to formerly standardized unit types
​https://bugs.webkit.org/show_bug.cgi?id=233651
<rdar://problem/85878291>

Reviewed by Darin Adler.

Source/WebCore:

This removes support, and makes it clear that these deprecated APIs shouldn't be exposing
anything more modern than what is standardized in DOM Level 2 Style. Hopefully this avoids
others in future adding support for new units.

Other changes included as they are necessary to make improved test not assert.

Test: fast/css/CSSPrimitiveValue-modern-length.html

  • css/CSSUnits.cpp:

(WebCore::unitCategory): Ensure this is complete for all units.
(WebCore::canonicalUnitTypeForCategory): Ensure this is complete for all unit categories.

  • css/DeprecatedCSSOMPrimitiveValue.cpp:

(WebCore::DeprecatedCSSOMPrimitiveValue::primitiveType const): Remove post-DOM Level 2 Style values.
(WebCore::DeprecatedCSSOMPrimitiveValue::getFloatValue const): Remove post-DOM Level 2 Style values.
(WebCore::DeprecatedCSSOMPrimitiveValue::getStringValue const): Add comment.

  • css/DeprecatedCSSOMPrimitiveValue.h: Remove post-DOM Level 2 Style constants.
  • css/DeprecatedCSSOMPrimitiveValue.idl: Remove post-DOM Level 2 Style constants.
  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor): Change to return std::optional, making explicit when there is no scaling factor.
(WebCore::CSSPrimitiveValue::doubleValueInternal const): Handle std::optional return.

  • css/CSSPrimitiveValue.h:

(WebCore::CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor): Change to return std::optional, making explicit when there is no scaling factor.

  • page/PrintContext.cpp:

(WebCore::PrintContext::computedPageMargin): Handle std::optional return.

LayoutTests:

Updated/moved test to cover all modern length units, not just ic.

  • fast/css/CSSPrimitiveValue-ic-expected.txt: Removed.
  • fast/css/CSSPrimitiveValue-ic.html: Removed.
  • fast/css/CSSPrimitiveValue-modern-length-expected.txt: Added.
  • fast/css/CSSPrimitiveValue-modern-length.html: Added.
Location:
trunk
Files:
2 added
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r288244 r288245  
     12022-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
    1162022-01-19  Jon Lee  <jonlee554@gmail.com>
    217
  • trunk/Source/WebCore/ChangeLog

    r288240 r288245  
     12022-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
    1342022-01-19  Said Abou-Hallawa  <said@apple.com>
    235
  • trunk/Source/WebCore/css/CSSPrimitiveValue.cpp

    r288200 r288245  
    963963}
    964964
    965 double CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(CSSUnitType unitType)
    966 {
    967     double factor = 1.0;
     965std::optional<double> CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(CSSUnitType unitType)
     966{
    968967    // FIXME: the switch can be replaced by an array of scale factors.
    969968    switch (unitType) {
    … …  
    974973    case CSSUnitType::CSS_HZ:
    975974    case CSSUnitType::CSS_DPPX:
    976         break;
     975        return 1.0;
     976
    977977    case CSSUnitType::CSS_X:
    978978        // This is semantically identical to (canonical) dppx
    979         break;
     979        return 1.0;
     980
    980981    case CSSUnitType::CSS_CM:
    981         factor = cssPixelsPerInch / cmPerInch;
    982         break;
     982        return cssPixelsPerInch / cmPerInch;
     983
    983984    case CSSUnitType::CSS_DPCM:
    984         factor = cmPerInch / cssPixelsPerInch; // (2.54 cm/in)
    985         break;
     985        return cmPerInch / cssPixelsPerInch; // (2.54 cm/in)
     986
    986987    case CSSUnitType::CSS_MM:
    987         factor = cssPixelsPerInch / mmPerInch;
    988         break;
     988        return cssPixelsPerInch / mmPerInch;
     989
    989990    case CSSUnitType::CSS_Q:
    990         factor = cssPixelsPerInch / QPerInch;
    991         break;
     991        return cssPixelsPerInch / QPerInch;
     992
    992993    case CSSUnitType::CSS_IN:
    993         factor = cssPixelsPerInch;
    994         break;
     994        return cssPixelsPerInch;
     995
    995996    case CSSUnitType::CSS_DPI:
    996         factor = 1 / cssPixelsPerInch;
    997         break;
     997        return 1 / cssPixelsPerInch;
     998
    998999    case CSSUnitType::CSS_PT:
    999         factor = cssPixelsPerInch / 72.0;
    1000         break;
     1000        return cssPixelsPerInch / 72.0;
     1001
    10011002    case CSSUnitType::CSS_PC:
    1002         factor = cssPixelsPerInch * 12.0 / 72.0; // 1 pc == 12 pt
    1003         break;
     1003        return cssPixelsPerInch * 12.0 / 72.0; // 1 pc == 12 pt
     1004
    10041005    case CSSUnitType::CSS_RAD:
    1005         factor = degreesPerRadianDouble;
    1006         break;
     1006        return degreesPerRadianDouble;
     1007
    10071008    case CSSUnitType::CSS_GRAD:
    1008         factor = degreesPerGradientDouble;
    1009         break;
     1009        return degreesPerGradientDouble;
     1010
    10101011    case CSSUnitType::CSS_TURN:
    1011         factor = degreesPerTurnDouble;
    1012         break;
     1012        return degreesPerTurnDouble;
     1013
    10131014    case CSSUnitType::CSS_S:
    10141015    case CSSUnitType::CSS_KHZ:
    1015         factor = 1000;
    1016         break;
     1016        return 1000;
     1017
    10171018    default:
    1018         break;
    1019     }
    1020 
    1021     return factor;
     1019        return std::nullopt;
     1020    }
    10221021}
    10231022
    … …  
    11161115    double convertedValue = doubleValue();
    11171116
     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
    11181121    // 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();
    11211126
    11221127    // 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();
    11251132
    11261133    return convertedValue;
  • trunk/Source/WebCore/css/CSSPrimitiveValue.h

    r287909 r288245  
    195195    bool equals(const CSSPrimitiveValue&) const;
    196196
    197     static double conversionToCanonicalUnitsScaleFactor(CSSUnitType);
     197    static std::optional<double> conversionToCanonicalUnitsScaleFactor(CSSUnitType);
    198198    static String unitTypeString(CSSUnitType);
    199199
  • trunk/Source/WebCore/css/CSSUnits.cpp

    r287909 r288245  
    4242    case CSSUnitType::CSS_Q:
    4343    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:
    4474        return CSSUnitCategory::Length;
    4575    case CSSUnitType::CSS_MS:
    … …  
    5989    case CSSUnitType::CSS_DPCM:
    6090        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:
    62114        return CSSUnitCategory::Other;
    63115    }
    … …  
    81133    case CSSUnitCategory::Resolution:
    82134        return CSSUnitType::CSS_DPPX;
    83     default:
     135    case CSSUnitCategory::Other:
    84136        return CSSUnitType::CSS_UNKNOWN;
    85137    }
  • trunk/Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.cpp

    r287909 r288245  
    3535unsigned short DeprecatedCSSOMPrimitiveValue::primitiveType() const
    3636{
    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 
    4037    switch (m_value->primitiveType()) {
    4138    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;
    4639    case CSSUnitType::CSS_IC:                           return CSS_UNKNOWN;
    4740    case CSSUnitType::CSS_CM:                           return CSS_CM;
    4841    case CSSUnitType::CSS_COUNTER:                      return CSS_COUNTER;
    49     case CSSUnitType::CSS_COUNTER_NAME:                 return 110;
    5042    case CSSUnitType::CSS_DEG:                          return CSS_DEG;
    5143    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;
    5544    case CSSUnitType::CSS_EMS:                          return CSS_EMS;
    5645    case CSSUnitType::CSS_EXS:                          return CSS_EXS;
    5746    case CSSUnitType::CSS_FONT_FAMILY:                  return CSS_STRING;
    58     case CSSUnitType::CSS_FR:                           return 33;
    5947    case CSSUnitType::CSS_GRAD:                         return CSS_GRAD;
    6048    case CSSUnitType::CSS_HZ:                           return CSS_HZ;
    … …  
    6452    case CSSUnitType::CSS_IN:                           return CSS_IN;
    6553    case CSSUnitType::CSS_KHZ:                          return CSS_KHZ;
    66     case CSSUnitType::CSS_LHS:                          return 35;
    6754    case CSSUnitType::CSS_MM:                           return CSS_MM;
    6855    case CSSUnitType::CSS_MS:                           return CSS_MS;
    6956    case CSSUnitType::CSS_NUMBER:                       return CSS_NUMBER;
    70     case CSSUnitType::CSS_PAIR:                         return 100;
    7157    case CSSUnitType::CSS_PC:                           return CSS_PC;
    7258    case CSSUnitType::CSS_PERCENTAGE:                   return CSS_PERCENTAGE;
    … …  
    7460    case CSSUnitType::CSS_PT:                           return CSS_PT;
    7561    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;
    7962    case CSSUnitType::CSS_RAD:                          return CSS_RAD;
    8063    case CSSUnitType::CSS_RECT:                         return CSS_RECT;
    81     case CSSUnitType::CSS_REMS:                         return 108;
    8264    case CSSUnitType::CSS_RGBCOLOR:                     return CSS_RGBCOLOR;
    83     case CSSUnitType::CSS_RLHS:                         return 36;
    8465    case CSSUnitType::CSS_S:                            return CSS_S;
    85     case CSSUnitType::CSS_SHAPE:                        return 111;
    8666    case CSSUnitType::CSS_STRING:                       return CSS_STRING;
    87     case CSSUnitType::CSS_TURN:                         return 107;
    88     case CSSUnitType::CSS_UNICODE_RANGE:                return 102;
    8967    case CSSUnitType::CSS_UNKNOWN:                      return CSS_UNKNOWN;
    9068    case CSSUnitType::CSS_URI:                          return CSS_URI;
    9169    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;
    9770
     71    // All other, including newer types, should return UNKNOWN.
    9872    default:                                            return CSS_UNKNOWN;
    9973    }
    … …  
    10276ExceptionOr<float> DeprecatedCSSOMPrimitiveValue::getFloatValue(unsigned short unitType) const
    10377{
    104     // FIXME: Some of these values do not need to be exposed as a destination type. Remove cases below and give InvalidAccessError instead.
    105 
    10678    switch (unitType) {
    10779    case CSS_CM:            return m_value->getFloatValue(CSSUnitType::CSS_CM);
    … …  
    12395    case CSS_RAD:           return m_value->getFloatValue(CSSUnitType::CSS_RAD);
    12496    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);
    12997
    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.
    14699    default:                return Exception { InvalidAccessError };
    147100    }
    … …  
    155108    case CSS_STRING:    return m_value->stringValue();
    156109    case CSS_URI:       return m_value->stringValue();
     110
     111    // All other, including newer types, should raise an exception.
    157112    default:            return Exception { InvalidAccessError };
    158113    }
  • trunk/Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.h

    r285373 r288245  
    6464        CSS_COUNTER = 23,
    6565        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.
    7168    };
    7269
  • trunk/Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.idl

    r288118 r288245  
    4949    const unsigned short CSS_RECT = 24;
    5050    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.
    5552   
    5653    readonly attribute unsigned short primitiveType;
  • trunk/Source/WebCore/page/PrintContext.cpp

    r282860 r288245  
    9090    auto style = frame()->document()->styleScope().resolver().styleForPage(0);
    9191
    92     float pixelToPointScaleFactor = 1 / CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(CSSUnitType::CSS_PT);
     92    float pixelToPointScaleFactor = 1 / CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor(CSSUnitType::CSS_PT).value();
    9393    return { style->marginTop().isAuto() ? printMargin.top() : style->marginTop().value() * pixelToPointScaleFactor,
    9494        style->marginRight().isAuto() ? printMargin.right() : style->marginRight().value() * pixelToPointScaleFactor,
Note: See TracChangeset for help on using the changeset viewer.