Title: [209370] trunk/Source/WebCore
Revision
209370
Author
[email protected]
Date
2016-12-05 17:45:29 -0800 (Mon, 05 Dec 2016)

Log Message

[CSS Parser] Support setting of custom properties from the CSS OM
https://bugs.webkit.org/show_bug.cgi?id=165442

Reviewed by Tim Horton.

* css/parser/CSSParser.cpp:
(WebCore::CSSParser::parseCustomPropertyValue):
Call in to a new function in CSSParserImpl that can handle
custom property parsing.

* css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::parseCustomPropertyValue):
New function that is similar to parseValue, but handling custom
properties.

(WebCore::CSSParserImpl::consumeDeclaration):
(WebCore::CSSParserImpl::consumeCustomPropertyValue):
(WebCore::CSSParserImpl::consumeVariableValue): Deleted.
* css/parser/CSSParserImpl.h:
Rename consumeVariableValue to consumeCustomPropertyValue, since that
is more clear. consumeVariableValue sounds like you might be resolving
a variable reference rather than parsing a custom property's value.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (209369 => 209370)


--- trunk/Source/WebCore/ChangeLog	2016-12-06 01:07:04 UTC (rev 209369)
+++ trunk/Source/WebCore/ChangeLog	2016-12-06 01:45:29 UTC (rev 209370)
@@ -1,3 +1,28 @@
+2016-12-05  Dave Hyatt  <[email protected]>
+
+        [CSS Parser] Support setting of custom properties from the CSS OM
+        https://bugs.webkit.org/show_bug.cgi?id=165442
+
+        Reviewed by Tim Horton.
+
+        * css/parser/CSSParser.cpp:
+        (WebCore::CSSParser::parseCustomPropertyValue):
+        Call in to a new function in CSSParserImpl that can handle
+        custom property parsing.
+
+        * css/parser/CSSParserImpl.cpp:
+        (WebCore::CSSParserImpl::parseCustomPropertyValue):
+        New function that is similar to parseValue, but handling custom
+        properties.
+
+        (WebCore::CSSParserImpl::consumeDeclaration):
+        (WebCore::CSSParserImpl::consumeCustomPropertyValue):
+        (WebCore::CSSParserImpl::consumeVariableValue): Deleted.
+        * css/parser/CSSParserImpl.h:
+        Rename consumeVariableValue to consumeCustomPropertyValue, since that
+        is more clear. consumeVariableValue sounds like you might be resolving
+        a variable reference rather than parsing a custom property's value.
+
 2016-12-05  Tim Horton  <[email protected]>
 
         Adopt CAMachPort-as-layer-contents

Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (209369 => 209370)


--- trunk/Source/WebCore/css/parser/CSSParser.cpp	2016-12-06 01:07:04 UTC (rev 209369)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp	2016-12-06 01:45:29 UTC (rev 209370)
@@ -1368,6 +1368,9 @@
 
 CSSParser::ParseResult CSSParser::parseCustomPropertyValue(MutableStyleProperties& declaration, const AtomicString& propertyName, const String& string, bool important, const CSSParserContext& context, StyleSheetContents* contextStyleSheet)
 {
+    if (context.useNewParser)
+        return CSSParserImpl::parseCustomPropertyValue(&declaration, propertyName, string, important, context);
+
     CSSParser parser(context);
     parser.setCustomPropertyName(propertyName);
     return parser.parseValue(declaration, CSSPropertyCustom, string, important, contextStyleSheet);

Modified: trunk/Source/WebCore/css/parser/CSSParserImpl.cpp (209369 => 209370)


--- trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2016-12-06 01:07:04 UTC (rev 209369)
+++ trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2016-12-06 01:45:29 UTC (rev 209370)
@@ -77,6 +77,16 @@
     return declaration->addParsedProperties(parser.m_parsedProperties) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
 }
 
+CSSParser::ParseResult CSSParserImpl::parseCustomPropertyValue(MutableStyleProperties* declaration, const AtomicString& propertyName, const String& string, bool important, const CSSParserContext& context)
+{
+    CSSParserImpl parser(context);
+    CSSTokenizer::Scope scope(string);
+    parser.consumeCustomPropertyValue(scope.tokenRange(), propertyName, important);
+    if (parser.m_parsedProperties.isEmpty())
+        return CSSParser::ParseResult::Error;
+    return declaration->addParsedProperties(parser.m_parsedProperties) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
+}
+
 static inline void filterProperties(bool important, const ParsedPropertyVector& input, ParsedPropertyVector& output, size_t& unusedEntries, std::bitset<numCSSProperties>& seenProperties, HashSet<AtomicString>& seenCustomProperties)
 {
     // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
@@ -774,7 +784,7 @@
     size_t propertiesCount = m_parsedProperties.size();
     if (propertyID == CSSPropertyInvalid && CSSVariableParser::isValidVariableName(token)) {
         AtomicString variableName = token.value().toAtomicString();
-        consumeVariableValue(range.makeSubRange(&range.peek(), declarationValueEnd), variableName, important);
+        consumeCustomPropertyValue(range.makeSubRange(&range.peek(), declarationValueEnd), variableName, important);
     }
 
     if (important && (ruleType == StyleRule::FontFace || ruleType == StyleRule::Keyframe))
@@ -790,7 +800,7 @@
     }
 }
 
-void CSSParserImpl::consumeVariableValue(CSSParserTokenRange range, const AtomicString& variableName, bool important)
+void CSSParserImpl::consumeCustomPropertyValue(CSSParserTokenRange range, const AtomicString& variableName, bool important)
 {
     if (RefPtr<CSSCustomPropertyValue> value = CSSVariableParser::parseDeclarationValue(variableName, range))
         m_parsedProperties.append(CSSProperty(CSSPropertyCustom, WTFMove(value), important));

Modified: trunk/Source/WebCore/css/parser/CSSParserImpl.h (209369 => 209370)


--- trunk/Source/WebCore/css/parser/CSSParserImpl.h	2016-12-06 01:07:04 UTC (rev 209369)
+++ trunk/Source/WebCore/css/parser/CSSParserImpl.h	2016-12-06 01:45:29 UTC (rev 209370)
@@ -84,6 +84,7 @@
     };
 
     static CSSParser::ParseResult parseValue(MutableStyleProperties*, CSSPropertyID, const String&, bool important, const CSSParserContext&);
+    static CSSParser::ParseResult parseCustomPropertyValue(MutableStyleProperties*, const AtomicString& propertyName, const String&, bool important, const CSSParserContext&);
     static Ref<ImmutableStyleProperties> parseInlineStyleDeclaration(const String&, Element*);
     static bool parseDeclarationList(MutableStyleProperties*, const String&, const CSSParserContext&);
     static RefPtr<StyleRuleBase> parseRule(const String&, const CSSParserContext&, StyleSheetContents*, AllowedRulesType);
@@ -135,7 +136,7 @@
     void consumeDeclarationList(CSSParserTokenRange, StyleRule::Type);
     void consumeDeclaration(CSSParserTokenRange, StyleRule::Type);
     void consumeDeclarationValue(CSSParserTokenRange, CSSPropertyID, bool important, StyleRule::Type);
-    void consumeVariableValue(CSSParserTokenRange, const AtomicString& propertyName, bool important);
+    void consumeCustomPropertyValue(CSSParserTokenRange, const AtomicString& propertyName, bool important);
 
     static std::unique_ptr<Vector<double>> consumeKeyframeKeyList(CSSParserTokenRange);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to