Ignore:
Timestamp:
Oct 22, 2018, 11:10:59 PM (7 years ago)
Author:
[email protected]
Message:

Registered custom properties should support syntax parameter for <length> and *
https://bugs.webkit.org/show_bug.cgi?id=190039

Patch by Justin Michaud <Justin Michaud> on 2018-10-22
Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

Update WPT test results to fail in a new way.

  • web-platform-tests/css/css-properties-values-api/register-property-syntax-parsing-expected.txt:
  • web-platform-tests/css/css-properties-values-api/registered-properties-inheritance-expected.txt:
  • web-platform-tests/css/css-properties-values-api/registered-property-cssom-expected.txt:
  • web-platform-tests/css/css-properties-values-api/typedom.tentative-expected.txt:
  • web-platform-tests/css/css-properties-values-api/var-reference-registered-properties-cycles-expected.txt:
  • web-platform-tests/css/css-properties-values-api/var-reference-registered-properties-expected.txt:

Source/WebCore:

Refactor code so that:

  • All properties applied in StyleResolver::applyMatchedProperties are only applied once.
  • Custom properties are only resolved once, in StyleResolver, when they are applied to the RenderStyle. They were previously resolved every time they were referenced, and again in RenderStyle.
  • The font-size property is applied after its variable references, but before custom properties that depend on it.
  • Cycles are detected at the same time as resolution.
  • MutableStyleProperties' custom properties cannot be set from Javascript or WebKitLegacy if they do not parse for the property's type. If they contain var(--...) references, however, then they can be set because we cannot check if the references are valid from setProperty. This behaviour matches chrome, but is not documented in the spec.
  • Custom property values have more explicit resolved/unresolved state.
  • RenderStyle only ever holds resolved custom properties, and StyleResolver::CascadedProperties only holds unresolved properties.

Tests: css-custom-properties-api/crash.html

css-custom-properties-api/cycles.html
css-custom-properties-api/inline.html

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::ComputedStyleExtractor::customPropertyValue):

  • css/CSSCustomPropertyValue.cpp:

(WebCore::CSSCustomPropertyValue::equals const):
(WebCore::CSSCustomPropertyValue::customCSSText const):
(WebCore::CSSCustomPropertyValue::tokens const):
(WebCore::CSSCustomPropertyValue::checkVariablesForCycles const): Deleted.
(WebCore::CSSCustomPropertyValue::resolveVariableReferences const): Deleted.
(WebCore::CSSCustomPropertyValue::setResolvedTypedValue): Deleted.

  • css/CSSCustomPropertyValue.h:
  • css/CSSRegisteredCustomProperty.cpp:

(WebCore::CSSRegisteredCustomProperty::CSSRegisteredCustomProperty):

  • css/CSSRegisteredCustomProperty.h:
  • css/CSSStyleSheet.h:
  • css/CSSVariableData.cpp:

(WebCore::CSSVariableData::CSSVariableData):
(WebCore::CSSVariableData::consumeAndUpdateTokens): Deleted.
(WebCore::CSSVariableData::checkVariablesForCycles const): Deleted.
(WebCore::CSSVariableData::checkVariablesForCyclesWithRange const): Deleted.
(WebCore::CSSVariableData::resolveVariableFallback const): Deleted.
(WebCore::CSSVariableData::resolveVariableReference const): Deleted.
(WebCore::CSSVariableData::resolveVariableReferences const): Deleted.
(WebCore::CSSVariableData::resolveTokenRange const): Deleted.

  • css/CSSVariableData.h:

(WebCore::CSSVariableData::create):
(WebCore::CSSVariableData::createResolved): Deleted.
(WebCore::CSSVariableData::needsVariableResolution const): Deleted.
(WebCore::CSSVariableData::CSSVariableData): Deleted.

  • css/CSSVariableReferenceValue.cpp:

(WebCore::resolveVariableFallback):
(WebCore::resolveVariableReference):
(WebCore::resolveTokenRange):
(WebCore::CSSVariableReferenceValue::resolveVariableReferences const):
(WebCore::CSSVariableReferenceValue::checkVariablesForCycles const): Deleted.

  • css/CSSVariableReferenceValue.h:

(WebCore::CSSVariableReferenceValue::create):
(WebCore::CSSVariableReferenceValue::equals const):
(WebCore::CSSVariableReferenceValue::variableDataValue const): Deleted.

  • css/DOMCSSRegisterCustomProperty.cpp:

(WebCore::DOMCSSRegisterCustomProperty::registerProperty):

  • css/PropertySetCSSStyleDeclaration.cpp:

(WebCore::PropertySetCSSStyleDeclaration::setProperty):

  • css/StyleBuilderCustom.h:

(WebCore::StyleBuilderCustom::applyInitialCustomProperty):
(WebCore::StyleBuilderCustom::applyValueCustomProperty):

  • css/StyleProperties.cpp:

(WebCore::MutableStyleProperties::setCustomProperty):

  • css/StyleProperties.h:
  • css/StyleResolver.cpp:

(WebCore::StyleResolver::State::setStyle):
(WebCore::StyleResolver::styleForKeyframe):
(WebCore::StyleResolver::styleForPage):
(WebCore::StyleResolver::applyMatchedProperties):
(WebCore::StyleResolver::applyPropertyToCurrentStyle):
(WebCore::StyleResolver::applyProperty):
(WebCore::StyleResolver::resolvedVariableValue const):
(WebCore::StyleResolver::CascadedProperties::applyDeferredProperties):
(WebCore::StyleResolver::CascadedProperties::Property::apply):
(WebCore::StyleResolver::applyCascadedCustomProperty):
(WebCore::StyleResolver::applyCascadedProperties):

  • css/StyleResolver.h:
  • css/parser/CSSParser.cpp:

(WebCore::CSSParser::parseValueWithVariableReferences):

  • css/parser/CSSParser.h:
  • css/parser/CSSPropertyParser.cpp:

(WebCore::CSSPropertyParser::CSSPropertyParser):
(WebCore::CSSPropertyParser::canParseTypedCustomPropertyValue):
(WebCore::CSSPropertyParser::parseTypedCustomPropertyValue):
(WebCore::CSSPropertyParser::collectParsedCustomPropertyValueDependencies):
(WebCore::CSSPropertyParser::parseValueStart):
(WebCore::CSSPropertyParser::parseSingleValue):

  • css/parser/CSSPropertyParser.h:
  • css/parser/CSSVariableParser.cpp:

(WebCore::CSSVariableParser::parseDeclarationValue):

  • dom/ConstantPropertyMap.cpp:

(WebCore::ConstantPropertyMap::setValueForProperty):
(WebCore::variableDataForPositivePixelLength):
(WebCore::variableDataForPositiveDuration):

  • rendering/style/RenderStyle.cpp:

(WebCore::RenderStyle::checkVariablesInCustomProperties): Deleted.

  • rendering/style/RenderStyle.h:

(WebCore::RenderStyle::setInheritedCustomPropertyValue):
(WebCore::RenderStyle::setNonInheritedCustomPropertyValue):

  • rendering/style/StyleCustomPropertyData.h:

(WebCore::StyleCustomPropertyData::operator== const):
(WebCore::StyleCustomPropertyData::setCustomPropertyValue):
(WebCore::StyleCustomPropertyData::StyleCustomPropertyData):
(): Deleted.

LayoutTests:

Add tests for inline styles, font-size cycles with custom properties, and a crash that was reported.

  • css-custom-properties-api/crash-expected.txt: Added.
  • css-custom-properties-api/crash.html: Added.
  • css-custom-properties-api/cycles-expected.txt: Added.
  • css-custom-properties-api/cycles.html: Added.
  • css-custom-properties-api/inline-expected.txt: Added.
  • css-custom-properties-api/inline.html: Added.
File:
1 edited

Legend:

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

    r236895 r237347  
    2828#include "CSSTokenizer.h"
    2929
     30namespace WebCore {
    3031
    31 namespace WebCore {
     32bool CSSCustomPropertyValue::equals(const CSSCustomPropertyValue& other) const
     33{
     34    if (m_name != other.m_name || m_value.index() != other.m_value.index())
     35        return false;
     36    auto visitor = WTF::makeVisitor([&](const Ref<CSSVariableReferenceValue>& value) {
     37        return value.get() == WTF::get<Ref<CSSVariableReferenceValue>>(other.m_value).get();
     38    }, [&](const CSSValueID& value) {
     39        return value == WTF::get<CSSValueID>(other.m_value);
     40    }, [&](const Ref<CSSVariableData>& value) {
     41        return value.get() == WTF::get<Ref<CSSVariableData>>(other.m_value).get();
     42    }, [&](const Length& value) {
     43        return value == WTF::get<Length>(other.m_value);
     44    });
     45    return WTF::visit(visitor, m_value);
     46}
    3247
    3348String CSSCustomPropertyValue::customCSSText() const
     
    3550    if (!m_serialized) {
    3651        m_serialized = true;
    37         if (m_resolvedTypedValue) // FIXME: Unit should be based on syntax.
    38             m_stringValue = CSSPrimitiveValue::create(m_resolvedTypedValue->value(), CSSPrimitiveValue::CSS_PX)->cssText();
    39         else if (m_value)
    40             m_stringValue = m_value->tokenRange().serialize();
    41         else if (m_valueId != CSSValueInvalid)
    42             m_stringValue = getValueName(m_valueId);
    43         else
    44             m_stringValue = emptyString();
     52
     53        auto visitor = WTF::makeVisitor([&](const Ref<CSSVariableReferenceValue>& value) {
     54            m_stringValue = value->cssText();
     55        }, [&](const CSSValueID& value) {
     56            m_stringValue = getValueName(value);
     57        }, [&](const Ref<CSSVariableData>& value) {
     58            m_stringValue = value->tokenRange().serialize();
     59        }, [&](const Length& value) {
     60            m_stringValue = CSSPrimitiveValue::create(value.value(), CSSPrimitiveValue::CSS_PX)->cssText();
     61        });
     62        WTF::visit(visitor, m_value);
    4563    }
    4664    return m_stringValue;
    4765}
    4866
    49 Vector<CSSParserToken> CSSCustomPropertyValue::tokens(const CSSRegisteredCustomPropertySet& registeredProperties, const RenderStyle& style) const
     67Vector<CSSParserToken> CSSCustomPropertyValue::tokens() const
    5068{
    51     if (m_resolvedTypedValue) {
    52         Vector<CSSParserToken> result;
     69    Vector<CSSParserToken> result;
     70
     71    auto visitor = WTF::makeVisitor([&](const Ref<CSSVariableReferenceValue>&) {
     72        ASSERT_NOT_REACHED();
     73    }, [&](const CSSValueID&) {
     74        // Do nothing
     75    }, [&](const Ref<CSSVariableData>& value) {
     76        result.appendVector(value->tokens());
     77    }, [&](const Length&) {
    5378        CSSTokenizer tokenizer(cssText());
    5479
     
    5681        while (!tokenizerRange.atEnd())
    5782            result.append(tokenizerRange.consume());
     83    });
     84    WTF::visit(visitor, m_value);
    5885
    59         return result;
    60     }
    61 
    62     if (!m_value)
    63         return { };
    64 
    65     if (m_containsVariables) {
    66         Vector<CSSParserToken> result;
    67         // FIXME: Avoid doing this work more than once.
    68         RefPtr<CSSVariableData> resolvedData = m_value->resolveVariableReferences(registeredProperties, style);
    69         if (resolvedData)
    70             result.appendVector(resolvedData->tokens());
    71 
    72         return result;
    73     }
    74 
    75     return m_value->tokens();
    76 }
    77 
    78 bool CSSCustomPropertyValue::checkVariablesForCycles(const AtomicString& name, const RenderStyle& style, HashSet<AtomicString>& seenProperties, HashSet<AtomicString>& invalidProperties) const
    79 {
    80     ASSERT(containsVariables());
    81     if (m_value)
    82         return m_value->checkVariablesForCycles(name, style, seenProperties, invalidProperties);
    83     return true;
    84 }
    85 
    86 void CSSCustomPropertyValue::resolveVariableReferences(const CSSRegisteredCustomPropertySet& registeredProperties, Vector<Ref<CSSCustomPropertyValue>>& resolvedValues, const RenderStyle& style) const
    87 {
    88     ASSERT(containsVariables());
    89     if (!m_value)
    90         return;
    91    
    92     ASSERT(m_value->needsVariableResolution());
    93     RefPtr<CSSVariableData> resolvedData = m_value->resolveVariableReferences(registeredProperties, style);
    94     if (resolvedData)
    95         resolvedValues.append(CSSCustomPropertyValue::createWithVariableData(m_name, resolvedData.releaseNonNull()));
    96     else
    97         resolvedValues.append(CSSCustomPropertyValue::createWithID(m_name, CSSValueInvalid));
    98 }
    99 
    100 void CSSCustomPropertyValue::setResolvedTypedValue(Length length)
    101 {
    102     ASSERT(length.isSpecified());
    103     m_resolvedTypedValue = WTFMove(length);
     86    return result;
    10487}
    10588
Note: See TracChangeset for help on using the changeset viewer.