Changeset 237347 in webkit for trunk/Source/WebCore/css/CSSCustomPropertyValue.cpp
- Timestamp:
- Oct 22, 2018, 11:10:59 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/css/CSSCustomPropertyValue.cpp
r236895 r237347 28 28 #include "CSSTokenizer.h" 29 29 30 namespace WebCore { 30 31 31 namespace WebCore { 32 bool 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 } 32 47 33 48 String CSSCustomPropertyValue::customCSSText() const … … 35 50 if (!m_serialized) { 36 51 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); 45 63 } 46 64 return m_stringValue; 47 65 } 48 66 49 Vector<CSSParserToken> CSSCustomPropertyValue::tokens( const CSSRegisteredCustomPropertySet& registeredProperties, const RenderStyle& style) const67 Vector<CSSParserToken> CSSCustomPropertyValue::tokens() const 50 68 { 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&) { 53 78 CSSTokenizer tokenizer(cssText()); 54 79 … … 56 81 while (!tokenizerRange.atEnd()) 57 82 result.append(tokenizerRange.consume()); 83 }); 84 WTF::visit(visitor, m_value); 58 85 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; 104 87 } 105 88
Note:
See TracChangeset
for help on using the changeset viewer.