Changeset 285837 in webkit


Ignore:
Timestamp:
Nov 15, 2021 2:41:10 PM (8 months ago)
Author:
commit-queue@webkit.org
Message:

Add helper to add CSS property with implicit default
https://bugs.webkit.org/show_bug.cgi?id=233108

Patch by Kiet Ho <Kiet Ho> on 2021-11-15
Reviewed by Myles C. Maxfield.

Add a helper in CSSPropertyParser to add a property with implicit default. This helper
accepts a RefPtr<> value and a Ref<> default. If the value is a null pointer, the
default is added, and the implicit flag is set. Otherwise, the value is added. This is
useful for parsing shorthands, because the CSS spec requires that missing value be
set to its default value, and WebCore additionally requires the implicit flag to be set.
This helper handles both of them.

No functional changes; no tests needed.

  • css/parser/CSSPropertyParser.cpp:

(WebCore::CSSPropertyParser::addPropertyWithImplicitDefault):
(WebCore::CSSPropertyParser::consumeTransformOrigin):
(WebCore::CSSPropertyParser::consumeFont):
(WebCore::CSSPropertyParser::consumeFontVariantShorthand):
(WebCore::CSSPropertyParser::consumeColumns):
(WebCore::CSSPropertyParser::consumeShorthandGreedily):
(WebCore::CSSPropertyParser::consumeBorderImage):

  • css/parser/CSSPropertyParser.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r285827 r285837  
     12021-11-15  Kiet Ho  <tho22@apple.com>
     2
     3        Add helper to add CSS property with implicit default
     4        https://bugs.webkit.org/show_bug.cgi?id=233108
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        Add a helper in CSSPropertyParser to add a property with implicit default. This helper
     9        accepts a RefPtr<> value and a Ref<> default. If the value is a null pointer, the
     10        default is added, and the implicit flag is set. Otherwise, the value is added. This is
     11        useful for parsing shorthands, because the CSS spec requires that missing value be
     12        set to its default value, and WebCore additionally requires the implicit flag to be set.
     13        This helper handles both of them.
     14
     15        No functional changes; no tests needed.
     16
     17        * css/parser/CSSPropertyParser.cpp:
     18        (WebCore::CSSPropertyParser::addPropertyWithImplicitDefault):
     19        (WebCore::CSSPropertyParser::consumeTransformOrigin):
     20        (WebCore::CSSPropertyParser::consumeFont):
     21        (WebCore::CSSPropertyParser::consumeFontVariantShorthand):
     22        (WebCore::CSSPropertyParser::consumeColumns):
     23        (WebCore::CSSPropertyParser::consumeShorthandGreedily):
     24        (WebCore::CSSPropertyParser::consumeBorderImage):
     25        * css/parser/CSSPropertyParser.h:
     26
    1272021-11-15  Antti Koivisto  <antti@apple.com>
    228
  • trunk/Source/WebCore/css/parser/CSSPropertyParser.cpp

    r285822 r285837  
    225225}
    226226
     227void CSSPropertyParser::addPropertyWithImplicitDefault(CSSPropertyID property, CSSPropertyID currentShorthand, RefPtr<CSSValue>&& value, Ref<CSSValue>&& implicitDefault, bool important)
     228{
     229    if (value)
     230        addProperty(property, currentShorthand, value.releaseNonNull(), important, false);
     231    else
     232        addProperty(property, currentShorthand, WTFMove(implicitDefault), important, true);
     233}
     234
    227235void CSSPropertyParser::addExpandedPropertyForValue(CSSPropertyID property, Ref<CSSValue>&& value, bool important)
    228236{
     
    356364        bool atEnd = m_range.atEnd();
    357365        auto resultZ = consumeLength(m_range, m_context.mode, ValueRange::All);
    358         bool hasZ = resultZ;
    359         if ((!hasZ && !atEnd) || !m_range.atEnd())
     366        if ((!resultZ && !atEnd) || !m_range.atEnd())
    360367            return false;
    361368        addProperty(CSSPropertyTransformOriginX, CSSPropertyTransformOrigin, WTFMove(resultXY->x), important);
    362369        addProperty(CSSPropertyTransformOriginY, CSSPropertyTransformOrigin, WTFMove(resultXY->y), important);
    363         addProperty(CSSPropertyTransformOriginZ, CSSPropertyTransformOrigin, resultZ ? resultZ.releaseNonNull() : CSSValuePool::singleton().createValue(0, CSSUnitType::CSS_PX), important, !hasZ);
     370        addPropertyWithImplicitDefault(CSSPropertyTransformOriginZ, CSSPropertyTransformOrigin, resultZ, CSSValuePool::singleton().createValue(0, CSSUnitType::CSS_PX), important);
    364371       
    365372        return true;
     
    50225029            return false;
    50235030    }
     5031
    50245032    // Optional font-style, font-variant, font-stretch and font-weight.
    50255033    RefPtr<CSSFontStyleValue> fontStyle;
     
    50585066        return false;
    50595067
    5060     bool hasStyle = fontStyle;
    5061     bool hasVariant = fontVariantCaps;
    5062     bool hasWeight = fontWeight;
    5063     bool hasStretch = fontStretch;
    5064 
    5065     if (!fontStyle)
    5066         fontStyle = CSSFontStyleValue::create(CSSValuePool::singleton().createIdentifierValue(CSSValueNormal));
    5067    
    5068     addProperty(CSSPropertyFontStyle, CSSPropertyFont, fontStyle.releaseNonNull(), important, !hasStyle);
    5069     addProperty(CSSPropertyFontVariantCaps, CSSPropertyFont, fontVariantCaps ? fontVariantCaps.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, !hasVariant);
     5068    auto& valuePool = CSSValuePool::singleton();
     5069
     5070    addPropertyWithImplicitDefault(CSSPropertyFontStyle, CSSPropertyFont, fontStyle, CSSFontStyleValue::create(valuePool.createIdentifierValue(CSSValueNormal)), important);
     5071    addPropertyWithImplicitDefault(CSSPropertyFontVariantCaps, CSSPropertyFont, fontVariantCaps, valuePool.createIdentifierValue(CSSValueNormal), important);
    50705072/* 
    50715073    // FIXME-NEWPARSER: What do we do with these? They aren't part of our fontShorthand().
     
    50745076*/
    50755077
    5076     addProperty(CSSPropertyFontWeight, CSSPropertyFont, fontWeight ? fontWeight.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, !hasWeight);
    5077     addProperty(CSSPropertyFontStretch, CSSPropertyFont, fontStretch ? fontStretch.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, !hasStretch);
     5078    addPropertyWithImplicitDefault(CSSPropertyFontWeight, CSSPropertyFont, fontWeight, valuePool.createIdentifierValue(CSSValueNormal), important);
     5079    addPropertyWithImplicitDefault(CSSPropertyFontStretch, CSSPropertyFont, fontStretch, valuePool.createIdentifierValue(CSSValueNormal), important);
    50785080
    50795081    // Now a font size _must_ come.
     
    50825084        return false;
    50835085
    5084     addProperty(CSSPropertyFontSize, CSSPropertyFont, *fontSize, important);
    5085 
     5086    addProperty(CSSPropertyFontSize, CSSPropertyFont, fontSize.releaseNonNull(), important);
     5087
     5088    RefPtr<CSSPrimitiveValue> lineHeight;
    50865089    if (consumeSlashIncludingWhitespace(m_range)) {
    5087         RefPtr<CSSPrimitiveValue> lineHeight = consumeLineHeight(m_range, m_context.mode);
     5090        lineHeight = consumeLineHeight(m_range, m_context.mode);
    50885091        if (!lineHeight)
    50895092            return false;
    5090         addProperty(CSSPropertyLineHeight, CSSPropertyFont, lineHeight.releaseNonNull(), important);
    5091     } else
    5092         addProperty(CSSPropertyLineHeight, CSSPropertyFont, CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, true);
     5093    }
     5094    addPropertyWithImplicitDefault(CSSPropertyLineHeight, CSSPropertyFont, lineHeight, valuePool.createIdentifierValue(CSSValueNormal), important);
    50935095
    50945096    // Font family must come now.
     
    51685170    addProperty(CSSPropertyFontVariantLigatures, CSSPropertyFontVariant, ligaturesParser.finalizeValue().releaseNonNull(), important, implicitLigatures);
    51695171    addProperty(CSSPropertyFontVariantNumeric, CSSPropertyFontVariant, numericParser.finalizeValue().releaseNonNull(), important, implicitNumeric);
    5170     bool implicitCaps = !capsValue;
    5171     addProperty(CSSPropertyFontVariantCaps, CSSPropertyFontVariant, capsValue ? capsValue.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, implicitCaps);
    5172     bool implicitAlternates = !alternatesValue;
    5173     addProperty(CSSPropertyFontVariantAlternates, CSSPropertyFontVariant, alternatesValue ? alternatesValue.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, implicitAlternates);
    5174     bool implicitPosition = !positionValue;
    5175     addProperty(CSSPropertyFontVariantPosition, CSSPropertyFontVariant, positionValue ? positionValue.releaseNonNull() : CSSValuePool::singleton().createIdentifierValue(CSSValueNormal), important, implicitPosition);
    5176 
    5177     bool implicitEastAsian = !eastAsianValue;
    5178     if (!eastAsianValue)
    5179         eastAsianValue = CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
    5180     addProperty(CSSPropertyFontVariantEastAsian, CSSPropertyFontVariant, eastAsianValue.releaseNonNull(), important, implicitEastAsian);
    5181    
     5172
     5173    auto& valuePool = CSSValuePool::singleton();
     5174    addPropertyWithImplicitDefault(CSSPropertyFontVariantCaps, CSSPropertyFontVariant, capsValue, valuePool.createIdentifierValue(CSSValueNormal), important);
     5175    addPropertyWithImplicitDefault(CSSPropertyFontVariantAlternates, CSSPropertyFontVariant, alternatesValue, valuePool.createIdentifierValue(CSSValueNormal), important);
     5176    addPropertyWithImplicitDefault(CSSPropertyFontVariantPosition, CSSPropertyFontVariant, positionValue, valuePool.createIdentifierValue(CSSValueNormal), important);
     5177    addPropertyWithImplicitDefault(CSSPropertyFontVariantEastAsian, CSSPropertyFontVariant, WTFMove(eastAsianValue), valuePool.createIdentifierValue(CSSValueNormal), important);
     5178
    51825179    return true;
    51835180}
     
    52265223    if (!m_range.atEnd())
    52275224        return false;
    5228    
     5225
    52295226    // Any unassigned property at this point will become implicit 'auto'.
    52305227    if (columnWidth)
     
    52625259
    52635260    for (size_t i = 0; i < shorthand.length(); ++i) {
    5264         if (longhands[i])
    5265             addProperty(shorthandProperties[i], shorthand.id(), longhands[i].releaseNonNull(), important);
    5266         else
    5267             addProperty(shorthandProperties[i], shorthand.id(), CSSValuePool::singleton().createImplicitInitialValue(), important);
     5261        addPropertyWithImplicitDefault(shorthandProperties[i], shorthand.id(), WTFMove(longhands[i]), CSSValuePool::singleton().createImplicitInitialValue(), important);
    52685262    }
    52695263    return true;
     
    54255419   
    54265420    if (consumeBorderImageComponents(property, m_range, m_context, source, slice, width, outset, repeat)) {
    5427         if (!source)
    5428             source = CSSValuePool::singleton().createImplicitInitialValue();
    5429         if (!slice)
    5430             slice = CSSValuePool::singleton().createImplicitInitialValue();
    5431         if (!width)
    5432             width = CSSValuePool::singleton().createImplicitInitialValue();
    5433         if (!outset)
    5434             outset = CSSValuePool::singleton().createImplicitInitialValue();
    5435         if (!repeat)
    5436             repeat = CSSValuePool::singleton().createImplicitInitialValue();
     5421        auto& valuePool = CSSValuePool::singleton();
    54375422        switch (property) {
    54385423        case CSSPropertyWebkitMaskBoxImage:
    5439             addProperty(CSSPropertyWebkitMaskBoxImageSource, CSSPropertyWebkitMaskBoxImage, source.releaseNonNull(), important);
    5440             addProperty(CSSPropertyWebkitMaskBoxImageSlice, CSSPropertyWebkitMaskBoxImage, slice.releaseNonNull(), important);
    5441             addProperty(CSSPropertyWebkitMaskBoxImageWidth, CSSPropertyWebkitMaskBoxImage, width.releaseNonNull(), important);
    5442             addProperty(CSSPropertyWebkitMaskBoxImageOutset, CSSPropertyWebkitMaskBoxImage, outset.releaseNonNull(), important);
    5443             addProperty(CSSPropertyWebkitMaskBoxImageRepeat, CSSPropertyWebkitMaskBoxImage, repeat.releaseNonNull(), important);
     5424            addPropertyWithImplicitDefault(CSSPropertyWebkitMaskBoxImageSource, CSSPropertyWebkitMaskBoxImage, WTFMove(source), valuePool.createImplicitInitialValue(), important);
     5425            addPropertyWithImplicitDefault(CSSPropertyWebkitMaskBoxImageSlice, CSSPropertyWebkitMaskBoxImage, WTFMove(slice), valuePool.createImplicitInitialValue(), important);
     5426            addPropertyWithImplicitDefault(CSSPropertyWebkitMaskBoxImageWidth, CSSPropertyWebkitMaskBoxImage, WTFMove(width), valuePool.createImplicitInitialValue(), important);
     5427            addPropertyWithImplicitDefault(CSSPropertyWebkitMaskBoxImageOutset, CSSPropertyWebkitMaskBoxImage, WTFMove(outset), valuePool.createImplicitInitialValue(), important);
     5428            addPropertyWithImplicitDefault(CSSPropertyWebkitMaskBoxImageRepeat, CSSPropertyWebkitMaskBoxImage, WTFMove(repeat), valuePool.createImplicitInitialValue(), important);
    54445429            return true;
    54455430        case CSSPropertyBorderImage:
    5446             addProperty(CSSPropertyBorderImageSource, CSSPropertyBorderImage, source.releaseNonNull(), important);
    5447             addProperty(CSSPropertyBorderImageSlice, CSSPropertyBorderImage, slice.releaseNonNull(), important);
    5448             addProperty(CSSPropertyBorderImageWidth, CSSPropertyBorderImage, width.releaseNonNull() , important);
    5449             addProperty(CSSPropertyBorderImageOutset, CSSPropertyBorderImage, outset.releaseNonNull(), important);
    5450             addProperty(CSSPropertyBorderImageRepeat, CSSPropertyBorderImage, repeat.releaseNonNull(), important);
     5431            addPropertyWithImplicitDefault(CSSPropertyBorderImageSource, CSSPropertyBorderImage, WTFMove(source), valuePool.createImplicitInitialValue(), important);
     5432            addPropertyWithImplicitDefault(CSSPropertyBorderImageSlice, CSSPropertyBorderImage, WTFMove(slice), valuePool.createImplicitInitialValue(), important);
     5433            addPropertyWithImplicitDefault(CSSPropertyBorderImageWidth, CSSPropertyBorderImage, WTFMove(width), valuePool.createImplicitInitialValue(), important);
     5434            addPropertyWithImplicitDefault(CSSPropertyBorderImageOutset, CSSPropertyBorderImage, WTFMove(outset), valuePool.createImplicitInitialValue(), important);
     5435            addPropertyWithImplicitDefault(CSSPropertyBorderImageRepeat, CSSPropertyBorderImage, WTFMove(repeat), valuePool.createImplicitInitialValue(), important);
    54515436            return true;
    54525437        default:
  • trunk/Source/WebCore/css/parser/CSSPropertyParser.h

    r282806 r285837  
    7878
    7979    void addProperty(CSSPropertyID, CSSPropertyID, Ref<CSSValue>&&, bool important, bool implicit = false);
     80    void addPropertyWithImplicitDefault(CSSPropertyID, CSSPropertyID, RefPtr<CSSValue>&&, Ref<CSSValue>&& implicitDefault, bool important);
    8081    void addExpandedPropertyForValue(CSSPropertyID propId, Ref<CSSValue>&&, bool);
    8182
Note: See TracChangeset for help on using the changeset viewer.