Bug 248638

Summary: Initial value for -webkit-line-clamp can't be expressed with its grammar
Product: WebKit Reporter: Oriol Brufau <obrufau>
Component: CSSAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: sam, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=248659

Description Oriol Brufau 2022-12-01 16:35:35 PST
-webkit-line-clamp is defined with https://searchfox.org/wubkat/rev/2cf89aa97e32bfcb31d92b41d7b17875e9a5dafd/Source/WebCore/css/CSSProperties.json#7185

    "parser-grammar": ["<percentage [0,inf]>", "<integer [1,inf]>"]

With this mappings: https://searchfox.org/wubkat/rev/2cf89aa97e32bfcb31d92b41d7b17875e9a5dafd/Source/WebCore/css/CSSPrimitiveValueMappings.h#130-134

    if (primitiveType() == CSSUnitType::CSS_INTEGER)
        return LineClampValue(value<int>(), LineClamp::LineCount);

    if (primitiveType() == CSSUnitType::CSS_PERCENTAGE)
        return LineClampValue(value<int>(), LineClamp::Percentage);

However, the initial value is https://searchfox.org/wubkat/rev/2cf89aa97e32bfcb31d92b41d7b17875e9a5dafd/Source/WebCore/rendering/style/RenderStyle.h#1857

    static LineClampValue initialLineClamp() { return LineClampValue(); }

Defined as https://searchfox.org/wubkat/rev/2cf89aa97e32bfcb31d92b41d7b17875e9a5dafd/Source/WebCore/rendering/style/LineClampValue.h#33-35

    LineClampValue()
        : m_type(LineClamp::LineCount)
        , m_value(-1)

So this value can't be represented with a non-negative integer/percentage.

Note that LineClampValue uses isNone() to refer to that https://searchfox.org/wubkat/rev/2cf89aa97e32bfcb31d92b41d7b17875e9a5dafd/Source/WebCore/rendering/style/LineClampValue.h#49

    bool isNone() const { return m_value == -1; }

And in getComputedStyle() is serializes as "none": https://searchfox.org/wubkat/rev/2cf89aa97e32bfcb31d92b41d7b17875e9a5dafd/Source/WebCore/css/ComputedStyleExtractor.cpp#3348-3349

        if (style.lineClamp().isNone())
            return cssValuePool.createIdentifierValue(CSSValueNone);

So I guess -webkit-line-clamp:none should be valid?

Now it's broken:

    document.body.style.webkitLineClamp = "initial";
    getComputedStyle(document.body).webkitLineClamp; // "none"
    CSS.supports("-webkit-line-clamp", "none"); // false
Comment 1 Radar WebKit Bug Importer 2022-12-08 16:36:16 PST
<rdar://problem/103158259>