Title: [209318] trunk/Source/WebCore
Revision
209318
Author
[email protected]
Date
2016-12-05 09:13:42 -0800 (Mon, 05 Dec 2016)

Log Message

[CSS Parser] Add parseValue support to new parser. Use new parser for UA sheet too if useNewParser is set.
https://bugs.webkit.org/show_bug.cgi?id=165376

Reviewed by Zalan Bujtas.

* css/StyleColor.cpp:
(WebCore::StyleColor::isColorKeyword):
Include system colors when using the fast parseValue path.

* css/parser/CSSParser.cpp:
(WebCore::CSSParser::setupParser):
Add an assert to catch any code path using the old parser when the new parser flag is set.

(WebCore::CSSParser::parseSheet):
(WebCore::CSSParser::parseRule):
(WebCore::CSSParser::parseKeyframeRule):
(WebCore::CSSParser::parseSupportsCondition):
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseSelector):
(WebCore::CSSParser::parseDeclaration):
Patched to use the new parser in UASheetMode as well as other modes when the new parser flag
is set. parseValue is patched to use the new parser's fast paths and to call into CSSParserImpl's
parseValue.

* css/parser/CSSParserFastPaths.cpp:
(WebCore::isSimpleLengthPropertyID):
Support CSSPropertyShapeMargin in the fast path since the old parser did in its fast path.

(WebCore::parseSimpleLengthValue):
Don't ever return unitless numbers. If we accept a unitless number, convert the unit to PX still.

(WebCore::CSSParserFastPaths::parseColor):
Use the CSSValuePool when creating colors on the fast path.

* css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::parseValue):
* css/parser/CSSParserImpl.h:
Change the return type to be compatible with the old parser's ParseResult flag.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (209317 => 209318)


--- trunk/Source/WebCore/ChangeLog	2016-12-05 17:06:28 UTC (rev 209317)
+++ trunk/Source/WebCore/ChangeLog	2016-12-05 17:13:42 UTC (rev 209318)
@@ -1,3 +1,44 @@
+2016-12-05  Dave Hyatt  <[email protected]>
+
+        [CSS Parser] Add parseValue support to new parser. Use new parser for UA sheet too if useNewParser is set.
+        https://bugs.webkit.org/show_bug.cgi?id=165376
+
+        Reviewed by Zalan Bujtas.
+
+        * css/StyleColor.cpp:
+        (WebCore::StyleColor::isColorKeyword):
+        Include system colors when using the fast parseValue path.
+
+        * css/parser/CSSParser.cpp:
+        (WebCore::CSSParser::setupParser):
+        Add an assert to catch any code path using the old parser when the new parser flag is set.
+
+        (WebCore::CSSParser::parseSheet):
+        (WebCore::CSSParser::parseRule):
+        (WebCore::CSSParser::parseKeyframeRule):
+        (WebCore::CSSParser::parseSupportsCondition):
+        (WebCore::CSSParser::parseValue):
+        (WebCore::CSSParser::parseSelector):
+        (WebCore::CSSParser::parseDeclaration):
+        Patched to use the new parser in UASheetMode as well as other modes when the new parser flag
+        is set. parseValue is patched to use the new parser's fast paths and to call into CSSParserImpl's
+        parseValue.
+
+        * css/parser/CSSParserFastPaths.cpp:
+        (WebCore::isSimpleLengthPropertyID):
+        Support CSSPropertyShapeMargin in the fast path since the old parser did in its fast path.
+
+        (WebCore::parseSimpleLengthValue):
+        Don't ever return unitless numbers. If we accept a unitless number, convert the unit to PX still.
+
+        (WebCore::CSSParserFastPaths::parseColor):
+        Use the CSSValuePool when creating colors on the fast path.
+
+        * css/parser/CSSParserImpl.cpp:
+        (WebCore::CSSParserImpl::parseValue):
+        * css/parser/CSSParserImpl.h:
+        Change the return type to be compatible with the old parser's ParseResult flag.
+
 2016-12-05  Konstantin Tokarev  <[email protected]>
 
         Removed MediaPlayerPrivateTaskTimer

Modified: trunk/Source/WebCore/css/StyleColor.cpp (209317 => 209318)


--- trunk/Source/WebCore/css/StyleColor.cpp	2016-12-05 17:06:28 UTC (rev 209317)
+++ trunk/Source/WebCore/css/StyleColor.cpp	2016-12-05 17:13:42 UTC (rev 209318)
@@ -50,7 +50,7 @@
 {
     return (id >= CSSValueAlpha && id <= CSSValueWebkitText)
         || (id >= CSSValueAliceblue && id <= CSSValueYellowgreen)
-        || id == CSSValueMenu;
+        || id == CSSValueMenu || isSystemColor(id);
 }
 
 bool StyleColor::isSystemColor(CSSValueID id)

Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (209317 => 209318)


--- trunk/Source/WebCore/css/parser/CSSParser.cpp	2016-12-05 17:06:28 UTC (rev 209317)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp	2016-12-05 17:13:42 UTC (rev 209318)
@@ -312,6 +312,8 @@
 
 void CSSParser::setupParser(const char* prefix, unsigned prefixLength, StringView string, const char* suffix, unsigned suffixLength)
 {
+    ASSERT(!m_context.useNewParser);
+
     m_parsedTextPrefixLength = prefixLength;
     unsigned stringLength = string.length();
     unsigned length = stringLength + m_parsedTextPrefixLength + suffixLength + 1;
@@ -368,7 +370,7 @@
     // FIXME-NEWPARSER: It's easier for testing to let the entire UA sheet parse with the old
     // parser. That way we can still have the default styles look correct while we add in support for
     // properties.
-    if (m_context.useNewParser && m_context.mode != UASheetMode)
+    if (m_context.useNewParser)
         return CSSParserImpl::parseStyleSheet(string, m_context, sheet);
     
     setStyleSheet(sheet);
@@ -400,7 +402,7 @@
 
 RefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const String& string)
 {
-    if (m_context.useNewParser && m_context.mode != UASheetMode)
+    if (m_context.useNewParser)
         return CSSParserImpl::parseRule(string, m_context, sheet, CSSParserImpl::AllowImportRules);
     setStyleSheet(sheet);
     m_allowNamespaceDeclarations = false;
@@ -411,7 +413,7 @@
 
 RefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet, const String& string)
 {
-    if (m_context.useNewParser && m_context.mode != UASheetMode) {
+    if (m_context.useNewParser) {
         RefPtr<StyleRuleBase> keyframe = CSSParserImpl::parseRule(string, m_context, nullptr, CSSParserImpl::KeyframeRules);
         return downcast<StyleKeyframe>(keyframe.get());
     }
@@ -424,10 +426,10 @@
 
 bool CSSParser::parseSupportsCondition(const String& condition)
 {
-    if (m_context.useNewParser && m_context.mode != UASheetMode) {
+    if (m_context.useNewParser) {
         CSSTokenizer::Scope scope(condition);
         CSSParserTokenRange range = scope.tokenRange();
-        CSSParserImpl parser(strictCSSParserContext());
+        CSSParserImpl parser(m_context);
         return CSSSupportsParser::supportsCondition(range, parser) == CSSSupportsParser::Supported;
     }
 
@@ -1334,21 +1336,28 @@
 CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important, const CSSParserContext& context, StyleSheetContents* contextStyleSheet)
 {
     ASSERT(!string.isEmpty());
-    CSSParser::ParseResult result = parseSimpleLengthValue(declaration, propertyID, string, important, context.mode);
-    if (result != ParseResult::Error)
-        return result;
+    if (context.useNewParser) {
+        RefPtr<CSSValue> value = CSSParserFastPaths::maybeParseValue(propertyID, string, context.mode, contextStyleSheet);
+        if (value)
+            return declaration.addParsedProperty(CSSProperty(propertyID, WTFMove(value), important)) ? CSSParser::ParseResult::Changed : CSSParser::ParseResult::Unchanged;
+    } else {
+        // FIXME-NEWPARSER: Remove all this code when the old parser goes away.
+        CSSParser::ParseResult result = parseSimpleLengthValue(declaration, propertyID, string, important, context.mode);
+        if (result != ParseResult::Error)
+            return result;
 
-    result = parseColorValue(declaration, propertyID, string, important,  context.mode);
-    if (result != ParseResult::Error)
-        return result;
+        result = parseColorValue(declaration, propertyID, string, important,  context.mode);
+        if (result != ParseResult::Error)
+            return result;
 
-    result = parseKeywordValue(declaration, propertyID, string, important, context, contextStyleSheet);
-    if (result != ParseResult::Error)
-        return result;
+        result = parseKeywordValue(declaration, propertyID, string, important, context, contextStyleSheet);
+        if (result != ParseResult::Error)
+            return result;
 
-    result = parseTranslateTransformValue(declaration, propertyID, string, important);
-    if (result != ParseResult::Error)
-        return result;
+        result = parseTranslateTransformValue(declaration, propertyID, string, important);
+        if (result != ParseResult::Error)
+            return result;
+    }
 
     CSSParser parser(context);
     return parser.parseValue(declaration, propertyID, string, important, contextStyleSheet);
@@ -1363,6 +1372,9 @@
 
 CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration, CSSPropertyID propertyID, const String& string, bool important, StyleSheetContents* contextStyleSheet)
 {
+    if (m_context.useNewParser)
+        return CSSParserImpl::parseValue(&declaration, propertyID, string, important, m_context);
+
     setStyleSheet(contextStyleSheet);
 
     setupParser("@-webkit-value{", string, "} ");
@@ -1436,7 +1448,7 @@
 
 void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
 {
-    if (m_context.useNewParser && m_context.mode != UASheetMode) {
+    if (m_context.useNewParser) {
         CSSTokenizer::Scope scope(string);
         selectorList = CSSSelectorParser::parseSelector(scope.tokenRange(), m_context, nullptr);
         return;
@@ -1480,7 +1492,7 @@
 
 bool CSSParser::parseDeclaration(MutableStyleProperties& declaration, const String& string, RefPtr<CSSRuleSourceData>&& ruleSourceData, StyleSheetContents* contextStyleSheet)
 {
-    if (m_context.useNewParser && m_context.mode != UASheetMode)
+    if (m_context.useNewParser)
         return CSSParserImpl::parseDeclarationList(&declaration, string, m_context);
 
     // Length of the "@-webkit-decls{" prefix.

Modified: trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp (209317 => 209318)


--- trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp	2016-12-05 17:06:28 UTC (rev 209317)
+++ trunk/Source/WebCore/css/parser/CSSParserFastPaths.cpp	2016-12-05 17:13:42 UTC (rev 209318)
@@ -70,7 +70,7 @@
     case CSSPropertyWebkitPaddingBefore:
     case CSSPropertyWebkitPaddingEnd:
     case CSSPropertyWebkitPaddingStart:
-  //  case CSSPropertyShapeMargin:
+    case CSSPropertyShapeMargin:
     case CSSPropertyR:
     case CSSPropertyRx:
     case CSSPropertyRy:
@@ -84,7 +84,6 @@
     case CSSPropertyMarginLeft:
     case CSSPropertyMarginRight:
     case CSSPropertyMarginTop:
- //   case CSSPropertyMotionOffset:
     case CSSPropertyRight:
     case CSSPropertyTop:
     case CSSPropertyWebkitMarginAfter:
@@ -144,10 +143,9 @@
     }
 
     if (unit == CSSPrimitiveValue::UnitTypes::CSS_NUMBER) {
-        if (!number)
-            unit = CSSPrimitiveValue::UnitTypes::CSS_PX;
-        else if (cssParserMode != SVGAttributeMode)
+        if (number && cssParserMode != SVGAttributeMode)
             return nullptr;
+        unit = CSSPrimitiveValue::UnitTypes::CSS_PX;
     }
 
     if (number < 0 && !acceptsNegativeNumbers)
@@ -481,7 +479,7 @@
     if (StyleColor::isColorKeyword(valueID)) {
         if (!isValueAllowedInMode(valueID, parserMode))
             return nullptr;
-        return CSSPrimitiveValue::createIdentifier(valueID);
+        return CSSValuePool::singleton().createIdentifierValue(valueID);
     }
 
     bool quirksMode = isQuirksModeBehavior(parserMode);

Modified: trunk/Source/WebCore/css/parser/CSSParserImpl.cpp (209317 => 209318)


--- trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2016-12-05 17:06:28 UTC (rev 209317)
+++ trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2016-12-05 17:13:42 UTC (rev 209318)
@@ -62,7 +62,7 @@
 {
 }
 
-bool CSSParserImpl::parseValue(MutableStyleProperties* declaration, CSSPropertyID propertyID, const String& string, bool important, const CSSParserContext& context)
+CSSParser::ParseResult CSSParserImpl::parseValue(MutableStyleProperties* declaration, CSSPropertyID propertyID, const String& string, bool important, const CSSParserContext& context)
 {
     CSSParserImpl parser(context);
     StyleRule::Type ruleType = StyleRule::Style;
@@ -73,8 +73,8 @@
     CSSTokenizer::Scope scope(string);
     parser.consumeDeclarationValue(scope.tokenRange(), propertyID, important, ruleType);
     if (parser.m_parsedProperties.isEmpty())
-        return false;
-    return declaration->addParsedProperties(parser.m_parsedProperties);
+        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)

Modified: trunk/Source/WebCore/css/parser/CSSParserImpl.h (209317 => 209318)


--- trunk/Source/WebCore/css/parser/CSSParserImpl.h	2016-12-05 17:06:28 UTC (rev 209317)
+++ trunk/Source/WebCore/css/parser/CSSParserImpl.h	2016-12-05 17:13:42 UTC (rev 209318)
@@ -29,6 +29,7 @@
 
 #pragma once
 
+#include "CSSParser.h"
 #include "CSSParserMode.h"
 #include "CSSParserTokenRange.h"
 #include "CSSProperty.h"
@@ -61,7 +62,7 @@
 class ImmutableStyleProperties;
 class Element;
 class MutableStyleProperties;
-
+    
 class CSSParserImpl {
     WTF_MAKE_NONCOPYABLE(CSSParserImpl);
 public:
@@ -82,7 +83,7 @@
         NoRules, // For parsing at-rules inside declaration lists
     };
 
-    static bool parseValue(MutableStyleProperties*, CSSPropertyID, const String&, bool important, const CSSParserContext&);
+    static CSSParser::ParseResult parseValue(MutableStyleProperties*, CSSPropertyID, 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);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to