Ignore:
Timestamp:
Feb 27, 2021, 11:51:44 AM (4 years ago)
Author:
[email protected]
Message:

Source/WebCore:
Remove support for 'pixel' and 'pos' CSSOM prefixes
https://bugs.webkit.org/show_bug.cgi?id=119712
<rdar://problem/70660490>

Reviewed by Simon Fraser.

Remove support for pixel/pos prefixed properties of CSSStyleDeclaration which
are no longer supported by any other browser.

  • css/CSSStyleDeclaration.cpp:

(WebCore::CSSStyleDeclaration::getCSSPropertyIDFromJavaScriptPropertyName):
(WebCore::CSSStyleDeclaration::namedItem):
(WebCore::CSSStyleDeclaration::setNamedItem):

LayoutTests:

Remove support for 'pixel' and 'pos' CSSOM prefixes
https://bugs.webkit.org/show_bug.cgi?id=119712

Reviewed by Simon Fraser.

  • fast/dom/CSSStyleDeclaration/css-properties-case-sensitive-expected.txt:
  • fast/dom/CSSStyleDeclaration/css-properties-case-sensitive.html:

Update test to reflect removal of pos/pixel prefixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSStyleDeclaration.cpp

    r273592 r273627  
    4444namespace {
    4545
    46 enum class PropertyNamePrefix {
    47     None,
    48     Epub,
    49     Pixel,
    50     Pos,
    51     WebKit
    52 };
     46enum class PropertyNamePrefix { None, Epub, WebKit };
    5347
    5448template<size_t prefixCStringLength>
     
    9387        if (matchesCSSPropertyNamePrefix(propertyName, "epub"))
    9488            return PropertyNamePrefix::Epub;
    95         break;
    96     case 'p':
    97         if (matchesCSSPropertyNamePrefix(propertyName, "pos"))
    98             return PropertyNamePrefix::Pos;
    99         if (matchesCSSPropertyNamePrefix(propertyName, "pixel"))
    100             return PropertyNamePrefix::Pixel;
    10189        break;
    10290    case 'w':
     
    132120}
    133121
    134 struct CSSPropertyInfo {
    135     CSSPropertyID propertyID;
    136     bool hadPixelOrPosPrefix;
    137 };
    138 
    139 static CSSPropertyInfo parseJavaScriptCSSPropertyName(const AtomString& propertyName)
    140 {
    141     using CSSPropertyInfoMap = HashMap<String, CSSPropertyInfo>;
    142     static NeverDestroyed<CSSPropertyInfoMap> propertyInfoCache;
    143 
    144     CSSPropertyInfo propertyInfo = { CSSPropertyInvalid, false };
     122static CSSPropertyID parseJavaScriptCSSPropertyName(const AtomString& propertyName)
     123{
     124    using CSSPropertyIDMap = HashMap<String, CSSPropertyID>;
     125    static NeverDestroyed<CSSPropertyIDMap> propertyIDCache;
    145126
    146127    auto* propertyNameString = propertyName.impl();
    147128    if (!propertyNameString)
    148         return propertyInfo;
     129        return CSSPropertyInvalid;
     130
    149131    unsigned length = propertyNameString->length();
    150132    if (!length)
    151         return propertyInfo;
    152 
    153     propertyInfo = propertyInfoCache.get().get(propertyNameString);
    154     if (propertyInfo.propertyID)
    155         return propertyInfo;
    156 
    157     bool hadPixelOrPosPrefix = false;
     133        return CSSPropertyInvalid;
     134
     135    if (auto id = propertyIDCache.get().get(propertyNameString))
     136        return id;
    158137
    159138    constexpr size_t bufferSize = maxCSSPropertyNameLength + 1;
     
    163142
    164143    unsigned i = 0;
    165     // Prefixes Pixel and Pos are ignored.
    166     // Prefixes Apple, KHTML and Webkit are transposed to "-webkit-".
    167     // The prefix "Epub" becomes "-epub-".
    168144    switch (propertyNamePrefix(*propertyNameString)) {
    169145    case PropertyNamePrefix::None:
    170146        if (isASCIIUpper((*propertyNameString)[0]))
    171             return propertyInfo;
    172         break;
    173     case PropertyNamePrefix::Pixel:
    174         i += 5;
    175         hadPixelOrPosPrefix = true;
    176         break;
    177     case PropertyNamePrefix::Pos:
    178         i += 3;
    179         hadPixelOrPosPrefix = true;
     147            return CSSPropertyInvalid;
    180148        break;
    181149    case PropertyNamePrefix::Epub:
     
    196164    size_t propertySizeLeft = length - i;
    197165    if (propertySizeLeft > bufferSizeLeft)
    198         return propertyInfo;
     166        return CSSPropertyInvalid;
    199167
    200168    for (; i < length; ++i) {
    201169        UChar c = (*propertyNameString)[i];
    202170        if (!c || !isASCII(c))
    203             return propertyInfo; // illegal character
     171            return CSSPropertyInvalid; // illegal character
    204172        if (isASCIIUpper(c)) {
    205173            size_t bufferSizeLeft = stringEnd - bufferPtr;
    206174            size_t propertySizeLeft = length - i + 1;
    207175            if (propertySizeLeft > bufferSizeLeft)
    208                 return propertyInfo;
     176                return CSSPropertyInvalid;
    209177            *bufferPtr++ = '-';
    210178            *bufferPtr++ = toASCIILowerUnchecked(c);
     
    221189#endif
    222190
    223     auto* hashTableEntry = findProperty(name, outputLength);
    224     if (auto propertyID = hashTableEntry ? hashTableEntry->id : 0) {
    225         auto id = static_cast<CSSPropertyID>(propertyID);
    226         propertyInfo.hadPixelOrPosPrefix = hadPixelOrPosPrefix;
    227         propertyInfo.propertyID = id;
    228         propertyInfoCache.get().add(propertyNameString, propertyInfo);
    229     }
    230     return propertyInfo;
    231 }
    232 
    233 static CSSPropertyInfo propertyInfoFromJavaScriptCSSPropertyName(const AtomString& propertyName, const Settings* settings)
    234 {
    235     auto propertyInfo = parseJavaScriptCSSPropertyName(propertyName);
    236     auto id = propertyInfo.propertyID;
     191    auto hashTableEntry = findProperty(name, outputLength);
     192    if (!hashTableEntry)
     193        return CSSPropertyInvalid;
     194
     195    auto id = static_cast<CSSPropertyID>(hashTableEntry->id);
     196    if (!id)
     197        return CSSPropertyInvalid;
     198
     199    propertyIDCache.get().add(propertyNameString, id);
     200    return id;
     201}
     202
     203static CSSPropertyID propertyIDFromJavaScriptCSSPropertyName(const AtomString& propertyName, const Settings* settings)
     204{
     205    auto id = parseJavaScriptCSSPropertyName(propertyName);
    237206    if (!isEnabledCSSProperty(id) || !isCSSPropertyEnabledBySettings(id, settings))
    238         return { CSSPropertyInvalid, false };
    239     return propertyInfo;
     207        return CSSPropertyInvalid;
     208    return id;
    240209}
    241210
     
    244213CSSPropertyID CSSStyleDeclaration::getCSSPropertyIDFromJavaScriptPropertyName(const AtomString& propertyName)
    245214{
    246     return propertyInfoFromJavaScriptCSSPropertyName(propertyName, nullptr).propertyID;
     215    // FIXME: This is going to return incorrect results for css properties disabled by Settings.
     216    return propertyIDFromJavaScriptCSSPropertyName(propertyName, nullptr);
    247217}
    248218
     
    254224Optional<Variant<String, double>> CSSStyleDeclaration::namedItem(const AtomString& propertyName)
    255225{
    256     auto propertyInfo = propertyInfoFromJavaScriptCSSPropertyName(propertyName, settings());
    257     if (!propertyInfo.propertyID)
     226    // FIXME: This is going to return incorrect results for css properties disabled by Settings if settings() returns nullptr.
     227    auto propertyID = propertyIDFromJavaScriptCSSPropertyName(propertyName, settings());
     228    if (!propertyID)
    258229        return WTF::nullopt;
    259230
    260     auto value = getPropertyCSSValueInternal(propertyInfo.propertyID);
    261     if (!value) {
    262         // If the property is a shorthand property (such as "padding"), it can only be accessed using getPropertyValue.
    263         return Variant<String, double> { getPropertyValueInternal(propertyInfo.propertyID) };
    264     }
    265    
    266     if (propertyInfo.hadPixelOrPosPrefix && is<CSSPrimitiveValue>(*value)) {
    267         // Call this version of the getter so that, e.g., pixelTop returns top as a number
    268         // in pixel units and posTop should does the same _if_ this is a positioned element.
    269         // FIXME: If not a positioned element, MSIE documentation says posTop should return 0; this rule is not implemented.
    270         return Variant<String, double> { downcast<CSSPrimitiveValue>(*value).floatValue(CSSUnitType::CSS_PX) };
    271     }
    272 
    273     return Variant<String, double> { value->cssText() };
     231    if (auto value = getPropertyCSSValueInternal(propertyID))
     232        return Variant<String, double> { value->cssText() };
     233
     234    // If the property is a shorthand property (such as "padding"), it can only be accessed using getPropertyValue.
     235    return Variant<String, double> { getPropertyValueInternal(propertyID) };
    274236}
    275237
    276238ExceptionOr<void> CSSStyleDeclaration::setNamedItem(const AtomString& propertyName, String value, bool& propertySupported)
    277239{
    278     auto propertyInfo = propertyInfoFromJavaScriptCSSPropertyName(propertyName, settings());
    279     if (!propertyInfo.propertyID) {
     240    // FIXME: This is going to return incorrect results for css properties disabled by Settings if settings() returns nullptr.
     241    auto propertyID = propertyIDFromJavaScriptCSSPropertyName(propertyName, settings());
     242    if (!propertyID) {
    280243        propertySupported = false;
    281244        return { };
     
    283246
    284247    propertySupported = true;
    285 
    286     if (propertyInfo.hadPixelOrPosPrefix)
    287         value.append("px");
    288248
    289249    bool important = false;
     
    296256    }
    297257
    298     auto setPropertyInternalResult = setPropertyInternal(propertyInfo.propertyID, value, important);
     258    auto setPropertyInternalResult = setPropertyInternal(propertyID, value, important);
    299259    if (setPropertyInternalResult.hasException())
    300260        return setPropertyInternalResult.releaseException();
Note: See TracChangeset for help on using the changeset viewer.