Changeset 236379 in webkit
- Timestamp:
- Sep 21, 2018 6:03:48 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r236377 r236379 1 2018-09-21 Justin Michaud <justin_michaud@apple.com> 2 3 Implement initialValue support for CSS Custom Properties and Values API 4 https://bugs.webkit.org/show_bug.cgi?id=189819 5 6 Reviewed by Simon Fraser. 7 8 * css-custom-properties-api/initialValue-expected.html: Added. 9 * css-custom-properties-api/initialValue.html: Added. 10 * css-custom-properties-api/initialValueJS-expected.txt: Added. 11 * css-custom-properties-api/initialValueJS.html: Added. 12 * css-custom-properties-api/registerProperty-expected.txt: 13 * css-custom-properties-api/registerProperty.html: 14 * platform/win/TestExpectations: 15 1 16 2018-09-21 Ryan Haddad <ryanhaddad@apple.com> 2 17 -
trunk/LayoutTests/css-custom-properties-api/registerProperty-expected.txt
r236273 r236379 2 2 PASS registerProperty requires a Dictionary type 3 3 PASS registerProperty requires a name matching <custom-property-name> 4 PASS registerProperty only allows omitting initialValue is syntax is '*' 4 PASS registerProperty always allows omitting initialValue and syntax, requires name and inherits 5 PASS registerProperty requires inherits and name 5 6 -
trunk/LayoutTests/css-custom-properties-api/registerProperty.html
r236273 r236379 19 19 CSS.registerProperty({name: ['--name', 3], inherits: false}); 20 20 // Invalid property names 21 assert_throws(new TypeError(), () => CSS.registerProperty({}));22 assert_throws(new TypeError(), () => CSS.registerProperty({name: '--no-inherits'}));23 21 //assert_throws(new SyntaxError(), () => CSS.registerProperty({name: 'no-leading-dash', inherits: false})); 24 22 //assert_throws(new SyntaxError(), () => CSS.registerProperty({name: '', inherits: false})); … … 28 26 CSS.registerProperty({name: '--syntax-test-1', inherits: false, syntax: '*'}); 29 27 CSS.registerProperty({name: '--syntax-test-2', inherits: false, syntax: ' * '}); 30 /*assert_throws(new SyntaxError(), 31 () => CSS.registerProperty({name: '--syntax-test-3', syntax: 'length'}));*/ 32 }, "registerProperty only allows omitting initialValue is syntax is '*'"); 28 CSS.registerProperty({name: '--syntax-test-3', inherits: false, initialValue: '500px'}); 29 assert_throws(new TypeError(), () => CSS.registerProperty({})); 30 assert_throws(new TypeError(), () => CSS.registerProperty({name: '--no-inherits'})); 31 assert_throws(new TypeError(), () => CSS.registerProperty({inherits: false})); 32 // Repeated name 33 assert_throws(null, 34 () => CSS.registerProperty({name: '--syntax-test-3', inherits: false, initialValue: '500px'})); 35 }, "registerProperty always allows omitting initialValue and syntax, requires name and inherits"); 36 test(function() { 37 CSS.registerProperty({name: '--syntax-test-4', inherits: false, syntax: '*'}); 38 CSS.registerProperty({name: '--syntax-test-5', inherits: false, syntax: ' * '}); 39 }, "registerProperty requires inherits and name"); 33 40 </script> -
trunk/LayoutTests/platform/win/TestExpectations
r236360 r236379 4161 4161 imported/blink/http/tests/security/mixedContent/websocket [ Skip ] 4162 4162 4163 # Feature flag only enabled for wk2 4164 css-custom-properties-api [ Skip ] 4165 4163 4166 editing/pasteboard/drag-and-drop-color-input-events.html [ Skip ] 4164 4167 -
trunk/Source/WebCore/ChangeLog
r236378 r236379 1 2018-09-21 Justin Michaud <justin_michaud@apple.com> 2 3 Implement initialValue support for CSS Custom Properties and Values API 4 https://bugs.webkit.org/show_bug.cgi?id=189819 5 6 Reviewed by Simon Fraser. 7 8 * css/CSSComputedStyleDeclaration.cpp: 9 (WebCore::ComputedStyleExtractor::customPropertyValue): 10 * css/CSSCustomPropertyValue.cpp: 11 (WebCore::CSSCustomPropertyValue::resolveVariableReferences const): 12 * css/CSSCustomPropertyValue.h: 13 * css/CSSRegisteredCustomProperty.h: 14 * css/CSSVariableData.cpp: 15 (WebCore::CSSVariableData::resolveVariableFallback const): 16 (WebCore::CSSVariableData::resolveVariableReference const): 17 (WebCore::CSSVariableData::resolveVariableReferences const): 18 (WebCore::CSSVariableData::resolveTokenRange const): 19 * css/CSSVariableData.h: 20 * css/DOMCSSRegisterCustomProperty.cpp: 21 (WebCore::DOMCSSRegisterCustomProperty::registerProperty): 22 * css/DOMCSSRegisterCustomProperty.h: 23 * css/DOMCSSRegisterCustomProperty.idl: 24 * css/StyleResolver.cpp: 25 (WebCore::StyleResolver::resolvedVariableValue): 26 (WebCore::StyleResolver::applyCascadedProperties): 27 * css/parser/CSSParser.cpp: 28 (WebCore::CSSParser::parseValueWithVariableReferences): 29 * css/parser/CSSParser.h: 30 * dom/Document.h: 31 (WebCore::Document::getCSSRegisteredCustomPropertySet const): 32 * rendering/style/RenderStyle.cpp: 33 (WebCore::RenderStyle::checkVariablesInCustomProperties): 34 * rendering/style/RenderStyle.h: 35 1 36 2018-09-21 Dean Jackson <dino@apple.com> 2 37 -
trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
r234798 r236379 2625 2625 return nullptr; 2626 2626 2627 return style->customProperties().get(propertyName); 2627 auto* value = style->customProperties().get(propertyName); 2628 if (value) 2629 return value; 2630 2631 auto* registered = styledElement->document().getCSSRegisteredCustomPropertySet().get(propertyName); 2632 if (registered && registered->initialValue) 2633 return registered->initialValue; 2634 2635 return nullptr; 2628 2636 } 2629 2637 -
trunk/Source/WebCore/css/CSSCustomPropertyValue.cpp
r218890 r236379 38 38 } 39 39 40 void CSSCustomPropertyValue::resolveVariableReferences(const CustomPropertyValueMap& customProperties, Vector<Ref<CSSCustomPropertyValue>>& resolvedValues) const40 void CSSCustomPropertyValue::resolveVariableReferences(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties, Vector<Ref<CSSCustomPropertyValue>>& resolvedValues) const 41 41 { 42 42 ASSERT(containsVariables()); … … 45 45 46 46 ASSERT(m_value->needsVariableResolution()); 47 RefPtr<CSSVariableData> resolvedData = m_value->resolveVariableReferences(customProperties );47 RefPtr<CSSVariableData> resolvedData = m_value->resolveVariableReferences(customProperties, registeredProperties); 48 48 if (resolvedData) 49 49 resolvedValues.append(CSSCustomPropertyValue::createWithVariableData(m_name, resolvedData.releaseNonNull())); -
trunk/Source/WebCore/css/CSSCustomPropertyValue.h
r209666 r236379 26 26 #pragma once 27 27 28 #include "CSSRegisteredCustomProperty.h" 28 29 #include "CSSValue.h" 29 30 #include "CSSVariableData.h" … … 71 72 bool checkVariablesForCycles(const AtomicString& name, CustomPropertyValueMap&, HashSet<AtomicString>& seenProperties, HashSet<AtomicString>& invalidProperties) const; 72 73 73 void resolveVariableReferences(const CustomPropertyValueMap&, Vector<Ref<CSSCustomPropertyValue>>&) const;74 void resolveVariableReferences(const CustomPropertyValueMap&, const CSSRegisteredCustomPropertySet&, Vector<Ref<CSSCustomPropertyValue>>&) const; 74 75 75 76 CSSValueID valueID() const { return m_valueId; } -
trunk/Source/WebCore/css/CSSRegisteredCustomProperty.h
r236273 r236379 30 30 namespace WebCore { 31 31 32 class CSSCustomPropertyValue; 33 32 34 struct CSSRegisteredCustomProperty { 33 35 const String name; 34 /* TODO syntax, inherits, initialValue */ 36 /* TODO syntax, inherits */ 37 const RefPtr<CSSCustomPropertyValue> initialValue; 35 38 }; 36 39 40 using CSSRegisteredCustomPropertySet = HashMap<String, std::unique_ptr<CSSRegisteredCustomProperty>>; 41 37 42 } -
trunk/Source/WebCore/css/CSSVariableData.cpp
r222627 r236379 126 126 } 127 127 128 bool CSSVariableData::resolveVariableFallback(const CustomPropertyValueMap& customProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const128 bool CSSVariableData::resolveVariableFallback(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const 129 129 { 130 130 if (range.atEnd()) … … 132 132 ASSERT(range.peek().type() == CommaToken); 133 133 range.consume(); 134 return resolveTokenRange(customProperties, r ange, result);134 return resolveTokenRange(customProperties, registeredProperties, range, result); 135 135 } 136 137 bool CSSVariableData::resolveVariableReference(const CustomPropertyValueMap& customProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const136 137 bool CSSVariableData::resolveVariableReference(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const 138 138 { 139 139 range.consumeWhitespace(); … … 143 143 144 144 RefPtr<CSSCustomPropertyValue> property = customProperties.get(variableName); 145 if (!property || !property->value()) 146 return resolveVariableFallback(customProperties, range, result); 145 if (!property || !property->value()) { 146 auto* registered = registeredProperties.get(variableName); 147 if (registered && registered->initialValue) 148 property = registered->initialValue; 149 else 150 return resolveVariableFallback(customProperties, registeredProperties, range, result); 151 } 152 ASSERT(property); 147 153 148 154 if (property->containsVariables()) { 149 155 // FIXME: Avoid doing this work more than once. 150 RefPtr<CSSVariableData> resolvedData = property->value()->resolveVariableReferences(customProperties );156 RefPtr<CSSVariableData> resolvedData = property->value()->resolveVariableReferences(customProperties, registeredProperties); 151 157 if (!resolvedData) 152 158 return false; … … 158 164 } 159 165 160 RefPtr<CSSVariableData> CSSVariableData::resolveVariableReferences(const CustomPropertyValueMap& customProperties ) const166 RefPtr<CSSVariableData> CSSVariableData::resolveVariableReferences(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties) const 161 167 { 162 168 Vector<CSSParserToken> resolvedTokens; 163 169 CSSParserTokenRange range = m_tokens; 164 if (!resolveTokenRange(customProperties, r ange, resolvedTokens))170 if (!resolveTokenRange(customProperties, registeredProperties, range, resolvedTokens)) 165 171 return nullptr; 166 172 return CSSVariableData::createResolved(resolvedTokens, *this); 167 173 } 168 174 169 bool CSSVariableData::resolveTokenRange(const CustomPropertyValueMap& customProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const175 bool CSSVariableData::resolveTokenRange(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties, CSSParserTokenRange range, Vector<CSSParserToken>& result) const 170 176 { 171 177 bool success = true; 172 178 while (!range.atEnd()) { 173 179 if (range.peek().functionId() == CSSValueVar || range.peek().functionId() == CSSValueEnv) 174 success &= resolveVariableReference(customProperties, r ange.consumeBlock(), result);180 success &= resolveVariableReference(customProperties, registeredProperties, range.consumeBlock(), result); 175 181 else 176 182 result.append(range.consume()); -
trunk/Source/WebCore/css/CSSVariableData.h
r218588 r236379 32 32 #include "CSSParserToken.h" 33 33 #include "CSSParserTokenRange.h" 34 #include "CSSRegisteredCustomProperty.h" 34 35 #include <wtf/HashSet.h> 35 36 #include <wtf/text/WTFString.h> … … 63 64 bool checkVariablesForCycles(const AtomicString& name, CustomPropertyValueMap&, HashSet<AtomicString>& seenProperties, HashSet<AtomicString>& invalidProperties) const; 64 65 65 RefPtr<CSSVariableData> resolveVariableReferences(const CustomPropertyValueMap& customProperties ) const;66 bool resolveTokenRange(const CustomPropertyValueMap&, CSSParserTokenRange, Vector<CSSParserToken>&) const;66 RefPtr<CSSVariableData> resolveVariableReferences(const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet&) const; 67 bool resolveTokenRange(const CustomPropertyValueMap&, const CSSRegisteredCustomPropertySet&, CSSParserTokenRange, Vector<CSSParserToken>&) const; 67 68 68 69 private: … … 83 84 84 85 bool checkVariablesForCyclesWithRange(CSSParserTokenRange, CustomPropertyValueMap&, HashSet<AtomicString>& seenProperties, HashSet<AtomicString>& invalidProperties) const; 85 bool resolveVariableReference(const CustomPropertyValueMap&, CSSParserTokenRange, Vector<CSSParserToken>&) const;86 bool resolveVariableFallback(const CustomPropertyValueMap&, CSSParserTokenRange, Vector<CSSParserToken>&) const;86 bool resolveVariableReference(const CustomPropertyValueMap&, const CSSRegisteredCustomPropertySet&, CSSParserTokenRange, Vector<CSSParserToken>&) const; 87 bool resolveVariableFallback(const CustomPropertyValueMap&, const CSSRegisteredCustomPropertySet&, CSSParserTokenRange, Vector<CSSParserToken>&) const; 87 88 88 89 String m_backingString; -
trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.cpp
r236273 r236379 27 27 #include "DOMCSSRegisterCustomProperty.h" 28 28 29 #include "CSSCustomPropertyValue.h" 29 30 #include "CSSRegisteredCustomProperty.h" 31 #include "CSSTokenizer.h" 30 32 #include "DOMCSSNamespace.h" 31 33 #include "Document.h" … … 34 36 namespace WebCore { 35 37 36 voidDOMCSSRegisterCustomProperty::registerProperty(Document& document, const DOMCSSCustomPropertyDescriptor& descriptor)38 ExceptionOr<void> DOMCSSRegisterCustomProperty::registerProperty(Document& document, const DOMCSSCustomPropertyDescriptor& descriptor) 37 39 { 38 CSSRegisteredCustomProperty property { descriptor.name }; 39 if (!document.registerCSSProperty(WTFMove(property))) { 40 /* TODO throw JS exception */ 41 return; 42 } 40 CSSTokenizer tokenizer(descriptor.initialValue); 41 RefPtr<CSSCustomPropertyValue> initialValue; 42 if (!tokenizer.tokenRange().atEnd()) 43 initialValue = CSSCustomPropertyValue::createWithVariableData(descriptor.name, CSSVariableData::create(tokenizer.tokenRange(), false)); 44 45 CSSRegisteredCustomProperty property { descriptor.name, WTFMove(initialValue) }; 46 if (!document.registerCSSProperty(WTFMove(property))) 47 return Exception { InvalidModificationError, "This property has already been registered." }; 48 49 return { }; 43 50 } 44 51 -
trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.h
r236273 r236379 27 27 28 28 #include "DOMCSSCustomPropertyDescriptor.h" 29 #include "ExceptionOr.h" 29 30 #include "Supplementable.h" 30 31 … … 38 39 explicit DOMCSSRegisterCustomProperty(DOMCSSNamespace&) { } 39 40 40 static voidregisterProperty(Document&, const DOMCSSCustomPropertyDescriptor&);41 static ExceptionOr<void> registerProperty(Document&, const DOMCSSCustomPropertyDescriptor&); 41 42 42 43 private: -
trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.idl
r236273 r236379 27 27 EnabledAtRuntime=CSSCustomPropertiesAndValues 28 28 ] partial interface DOMCSSNamespace { 29 [CallWith=Document ] static void registerProperty(DOMCSSCustomPropertyDescriptor descriptor);29 [CallWith=Document, MayThrowException] static void registerProperty(DOMCSSCustomPropertyDescriptor descriptor); 30 30 }; -
trunk/Source/WebCore/css/StyleResolver.cpp
r236341 r236379 1709 1709 { 1710 1710 CSSParser parser(document()); 1711 return parser.parseValueWithVariableReferences(propID, value, m_state.style()->customProperties(), m_state.style()->direction(), m_state.style()->writingMode());1711 return parser.parseValueWithVariableReferences(propID, value, m_state.style()->customProperties(), document().getCSSRegisteredCustomPropertySet(), m_state.style()->direction(), m_state.style()->writingMode()); 1712 1712 } 1713 1713 … … 2286 2286 2287 2287 if (firstProperty == CSSPropertyCustom) 2288 m_state.style()->checkVariablesInCustomProperties( );2288 m_state.style()->checkVariablesInCustomProperties(document().getCSSRegisteredCustomPropertySet()); 2289 2289 } 2290 2290 -
trunk/Source/WebCore/css/parser/CSSParser.cpp
r235560 r236379 176 176 } 177 177 178 RefPtr<CSSValue> CSSParser::parseValueWithVariableReferences(CSSPropertyID propID, const CSSValue& value, const CustomPropertyValueMap& customProperties, TextDirection direction, WritingMode writingMode)178 RefPtr<CSSValue> CSSParser::parseValueWithVariableReferences(CSSPropertyID propID, const CSSValue& value, const CustomPropertyValueMap& customProperties, const CSSRegisteredCustomPropertySet& registeredProperties, TextDirection direction, WritingMode writingMode) 179 179 { 180 180 if (value.isPendingSubstitutionValue()) { … … 190 190 191 191 Vector<CSSParserToken> resolvedTokens; 192 if (!variableData->resolveTokenRange(customProperties, variableData->tokens(), resolvedTokens))192 if (!variableData->resolveTokenRange(customProperties, registeredProperties, variableData->tokens(), resolvedTokens)) 193 193 return nullptr; 194 194 … … 211 211 212 212 Vector<CSSParserToken> resolvedTokens; 213 if (!variableData->resolveTokenRange(customProperties, variableData->tokens(), resolvedTokens))213 if (!variableData->resolveTokenRange(customProperties, registeredProperties, variableData->tokens(), resolvedTokens)) 214 214 return nullptr; 215 215 -
trunk/Source/WebCore/css/parser/CSSParser.h
r233520 r236379 24 24 25 25 #include "CSSParserContext.h" 26 #include "CSSRegisteredCustomProperty.h" 26 27 #include "CSSValue.h" 27 28 #include "WritingMode.h" … … 76 77 void parseSelector(const String&, CSSSelectorList&); 77 78 78 RefPtr<CSSValue> parseValueWithVariableReferences(CSSPropertyID, const CSSValue&, const CustomPropertyValueMap& customProperties, TextDirection, WritingMode);79 RefPtr<CSSValue> parseValueWithVariableReferences(CSSPropertyID, const CSSValue&, const CustomPropertyValueMap&, const CSSRegisteredCustomPropertySet&, TextDirection, WritingMode); 79 80 80 81 static Color parseColor(const String&, bool strict = false); -
trunk/Source/WebCore/dom/Document.h
r236273 r236379 1493 1493 bool hasMainArticleElement() const { return !!m_mainArticleElement; } 1494 1494 1495 const CSSRegisteredCustomPropertySet& getCSSRegisteredCustomPropertySet() const { return m_CSSRegisteredPropertySet; } 1495 1496 bool registerCSSProperty(CSSRegisteredCustomProperty&&); 1496 1497 … … 2027 2028 std::unique_ptr<UserGestureIndicator> m_temporaryUserGesture; 2028 2029 2029 HashMap<String, std::unique_ptr<CSSRegisteredCustomProperty>>m_CSSRegisteredPropertySet;2030 CSSRegisteredCustomPropertySet m_CSSRegisteredPropertySet; 2030 2031 2031 2032 bool m_isRunningUserScripts { false }; -
trunk/Source/WebCore/rendering/style/RenderStyle.cpp
r235560 r236379 2243 2243 } 2244 2244 2245 void RenderStyle::checkVariablesInCustomProperties( )2245 void RenderStyle::checkVariablesInCustomProperties(const CSSRegisteredCustomPropertySet& registeredProperties) 2246 2246 { 2247 2247 if (!m_rareInheritedData->customProperties->containsVariables) … … 2274 2274 if (!entry.value->containsVariables()) 2275 2275 continue; 2276 entry.value->resolveVariableReferences(customProperties, re solvedValues);2276 entry.value->resolveVariableReferences(customProperties, registeredProperties, resolvedValues); 2277 2277 } 2278 2278 -
trunk/Source/WebCore/rendering/style/RenderStyle.h
r235539 r236379 793 793 #endif 794 794 795 void checkVariablesInCustomProperties( );795 void checkVariablesInCustomProperties(const CSSRegisteredCustomPropertySet&); 796 796 797 797 // attribute setter methods
Note: See TracChangeset
for help on using the changeset viewer.