Title: [257698] trunk/Source/WebCore
Revision
257698
Author
[email protected]
Date
2020-03-01 16:43:28 -0800 (Sun, 01 Mar 2020)

Log Message

Slim down some CSS parsing code
https://bugs.webkit.org/show_bug.cgi?id=208418

Reviewed by Anders Carlsson.

* css/CSSPrimitiveValue.h: Remove unused createAllowingMarginQuirk function
and the FIXME-NEWPARSER that said we wouldn't need it any more and the
no-longer-needed isQuirkValue function.

* css/CSSValue.h: Remove m_isQuirkValue.

* css/parser/CSSParser.cpp:
(WebCore::CSSParser::parseSelector): Call parseCSSSelector instead of
CSSSelectorParser::parseSelector, because that's the public function now.
* css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::consumeStyleRule): Ditto.

* css/parser/CSSPropertyParserHelpers.h: Removed a FIXME-NEWPARSER that is
now obsolete.

* css/parser/CSSSelectorParser.cpp: Moved the entire CSSSelectorParser class here from
the header, because the only thing used outside this file is the entry point, the
now renamed parseCSSSelector function.
(WebCore::CSSSelectorParser::DisallowPseudoElementsScope::DisallowPseudoElementsScope):
Changed this class to use a reference instead of a pointer.
(WebCore::parseCSSSelector): Renamed CSSSelectorParser::parseSelector to this.
(WebCore::CSSSelectorParser::consumeComplexSelectorList): Use auto to make some
unique_ptr code less verbose.
(WebCore::CSSSelectorParser::consumeCompoundSelectorList): Ditto. Removed the check of
m_failed. Only the parser entry point function needs that check, and that is the
consumeComplexSelectorList function above.
(WebCore::extractCompoundFlags): Use static instead of anonymous namespace. Use enum
class instead of enum, and use OptionSet instead of unsigned.
(WebCore::CSSSelectorParser::consumeComplexSelector): Updated for the above. This
refactoring exposed a strangeness in the simple selector loop; for now maintained
behavior rather than changing it to do something more logical.
(WebCore::isScrollbarPseudoClass): Use static instead of anonymous namespace.
(WebCore::isUserActionPseudoClass): Ditto.
(WebCore::isPseudoClassValidAfterPseudoElement): Ditto.
(WebCore::isSimpleSelectorValidAfterPseudoElement): Ditto.
(WebCore::CSSSelectorParser::consumeCompoundSelector): Use auto to make unique_ptr
code less verbose. Also inlined the one line applySimpleSelectorToCompound function,
because that name didn't document much thus having a function obscured rather than
clarifying what was going on. Also use makeUnique instead of new.
(WebCore::CSSSelectorParser::consumeId): Use makeUnique instead of new.
(WebCore::CSSSelectorParser::consumeClass): Ditto.
(WebCore::CSSSelectorParser::consumeAttribute): Ditto.
(WebCore::isOnlyPseudoElementFunction): Tweaked a comment.
(WebCore::CSSSelectorParser::consumePseudo): Update use of DisallowPseudoElementsScope
to use a reference, use auto to make unique_ptr code less verbose, use makeUnique
instead of new.
(WebCore::consumeANPlusB): Converted to a file-level static function rather than
a static member function.
(WebCore::CSSSelectorParser::prependTypeSelectorIfNeeded): Changed type from
pointer to reference
(WebCore::CSSSelectorParser::addSimpleSelectorToCompound): Deleted.

* css/parser/CSSSelectorParser.h: Removed most of the contents of this file, leaving
only the function that is the parser entry point.

* style/StyleBuilderConverter.h:
(WebCore::Style::BuilderConverter::convertLength): This si the one place that sets
the quirk on a Length value. It now checks for CSS_QUIRKY_EMS directly rather than
using a helper function.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (257697 => 257698)


--- trunk/Source/WebCore/ChangeLog	2020-03-02 00:42:28 UTC (rev 257697)
+++ trunk/Source/WebCore/ChangeLog	2020-03-02 00:43:28 UTC (rev 257698)
@@ -1,5 +1,72 @@
 2020-02-29  Darin Adler  <[email protected]>
 
+        Slim down some CSS parsing code
+        https://bugs.webkit.org/show_bug.cgi?id=208418
+
+        Reviewed by Anders Carlsson.
+
+        * css/CSSPrimitiveValue.h: Remove unused createAllowingMarginQuirk function
+        and the FIXME-NEWPARSER that said we wouldn't need it any more and the
+        no-longer-needed isQuirkValue function.
+
+        * css/CSSValue.h: Remove m_isQuirkValue.
+
+        * css/parser/CSSParser.cpp:
+        (WebCore::CSSParser::parseSelector): Call parseCSSSelector instead of
+        CSSSelectorParser::parseSelector, because that's the public function now.
+        * css/parser/CSSParserImpl.cpp:
+        (WebCore::CSSParserImpl::consumeStyleRule): Ditto.
+
+        * css/parser/CSSPropertyParserHelpers.h: Removed a FIXME-NEWPARSER that is
+        now obsolete.
+
+        * css/parser/CSSSelectorParser.cpp: Moved the entire CSSSelectorParser class here from
+        the header, because the only thing used outside this file is the entry point, the
+        now renamed parseCSSSelector function.
+        (WebCore::CSSSelectorParser::DisallowPseudoElementsScope::DisallowPseudoElementsScope):
+        Changed this class to use a reference instead of a pointer.
+        (WebCore::parseCSSSelector): Renamed CSSSelectorParser::parseSelector to this.
+        (WebCore::CSSSelectorParser::consumeComplexSelectorList): Use auto to make some
+        unique_ptr code less verbose.
+        (WebCore::CSSSelectorParser::consumeCompoundSelectorList): Ditto. Removed the check of
+        m_failed. Only the parser entry point function needs that check, and that is the
+        consumeComplexSelectorList function above.
+        (WebCore::extractCompoundFlags): Use static instead of anonymous namespace. Use enum
+        class instead of enum, and use OptionSet instead of unsigned.
+        (WebCore::CSSSelectorParser::consumeComplexSelector): Updated for the above. This
+        refactoring exposed a strangeness in the simple selector loop; for now maintained
+        behavior rather than changing it to do something more logical.
+        (WebCore::isScrollbarPseudoClass): Use static instead of anonymous namespace.
+        (WebCore::isUserActionPseudoClass): Ditto.
+        (WebCore::isPseudoClassValidAfterPseudoElement): Ditto.
+        (WebCore::isSimpleSelectorValidAfterPseudoElement): Ditto.
+        (WebCore::CSSSelectorParser::consumeCompoundSelector): Use auto to make unique_ptr
+        code less verbose. Also inlined the one line applySimpleSelectorToCompound function,
+        because that name didn't document much thus having a function obscured rather than
+        clarifying what was going on. Also use makeUnique instead of new.
+        (WebCore::CSSSelectorParser::consumeId): Use makeUnique instead of new.
+        (WebCore::CSSSelectorParser::consumeClass): Ditto.
+        (WebCore::CSSSelectorParser::consumeAttribute): Ditto.
+        (WebCore::isOnlyPseudoElementFunction): Tweaked a comment.
+        (WebCore::CSSSelectorParser::consumePseudo): Update use of DisallowPseudoElementsScope
+        to use a reference, use auto to make unique_ptr code less verbose, use makeUnique
+        instead of new.
+        (WebCore::consumeANPlusB): Converted to a file-level static function rather than
+        a static member function.
+        (WebCore::CSSSelectorParser::prependTypeSelectorIfNeeded): Changed type from
+        pointer to reference
+        (WebCore::CSSSelectorParser::addSimpleSelectorToCompound): Deleted.
+
+        * css/parser/CSSSelectorParser.h: Removed most of the contents of this file, leaving
+        only the function that is the parser entry point.
+
+        * style/StyleBuilderConverter.h:
+        (WebCore::Style::BuilderConverter::convertLength): This si the one place that sets
+        the quirk on a Length value. It now checks for CSS_QUIRKY_EMS directly rather than
+        using a helper function.
+
+2020-02-29  Darin Adler  <[email protected]>
+
         Tighten up CSSPendingSubstitutionValue
         https://bugs.webkit.org/show_bug.cgi?id=208421
 

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.h (257697 => 257698)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.h	2020-03-02 00:42:28 UTC (rev 257697)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.h	2020-03-02 00:43:28 UTC (rev 257698)
@@ -127,12 +127,6 @@
 
     template<typename T> static Ref<CSSPrimitiveValue> create(T&&);
 
-    // This value is used to handle quirky margins in reflow roots (body, td, and th) like WinIE.
-    // The basic idea is that a stylesheet can use the value __qem (for quirky em) instead of em.
-    // When the quirky value is used, if you're in quirks mode, the margin will collapse away
-    // inside a table cell.
-    static Ref<CSSPrimitiveValue> createAllowingMarginQuirk(double value, CSSUnitType);
-
     ~CSSPrimitiveValue();
 
     void cleanup();
@@ -188,9 +182,6 @@
 
     String customCSSText() const;
 
-    // FIXME-NEWPARSER: Can ditch the boolean and just use the unit type once old parser is gone.
-    bool isQuirkValue() const { return m_isQuirkValue || primitiveType() == CSSUnitType::CSS_QUIRKY_EMS; }
-
     bool equals(const CSSPrimitiveValue&) const;
 
     static double conversionToCanonicalUnitsScaleFactor(CSSUnitType);
@@ -294,13 +285,6 @@
     return adoptRef(*new CSSPrimitiveValue(std::forward<T>(value)));
 }
 
-inline Ref<CSSPrimitiveValue> CSSPrimitiveValue::createAllowingMarginQuirk(double value, CSSUnitType type)
-{
-    auto result = adoptRef(*new CSSPrimitiveValue(value, type));
-    result->m_isQuirkValue = true;
-    return result;
-}
-
 template<typename T, CSSPrimitiveValue::TimeUnit timeUnit> inline T CSSPrimitiveValue::computeTime() const
 {
     if (timeUnit == Seconds && primitiveType() == CSSUnitType::CSS_S)

Modified: trunk/Source/WebCore/css/CSSValue.h (257697 => 257698)


--- trunk/Source/WebCore/css/CSSValue.h	2020-03-02 00:42:28 UTC (rev 257697)
+++ trunk/Source/WebCore/css/CSSValue.h	2020-03-02 00:43:28 UTC (rev 257698)
@@ -237,7 +237,6 @@
     explicit CSSValue(ClassType classType)
         : m_primitiveUnitType(0)
         , m_hasCachedCSSText(false)
-        , m_isQuirkValue(false)
         , m_valueListSeparator(SpaceSeparator)
         , m_classType(classType)
     {
@@ -263,7 +262,6 @@
     // CSSPrimitiveValue bits:
     unsigned m_primitiveUnitType : 7; // CSSUnitType
     mutable unsigned m_hasCachedCSSText : 1;
-    unsigned m_isQuirkValue : 1;
 
     unsigned m_valueListSeparator : ValueListSeparatorBits;
 

Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (257697 => 257698)


--- trunk/Source/WebCore/css/parser/CSSParser.cpp	2020-03-02 00:42:28 UTC (rev 257697)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp	2020-03-02 00:43:28 UTC (rev 257698)
@@ -182,8 +182,7 @@
 
 void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
 {
-    CSSTokenizer tokenizer(string);
-    selectorList = CSSSelectorParser::parseSelector(tokenizer.tokenRange(), m_context, nullptr);
+    selectorList = parseCSSSelector(CSSTokenizer(string).tokenRange(), m_context, nullptr);
 }
 
 Ref<ImmutableStyleProperties> CSSParser::parseInlineStyleDeclaration(const String& string, const Element* element)

Modified: trunk/Source/WebCore/css/parser/CSSParserImpl.cpp (257697 => 257698)


--- trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2020-03-02 00:42:28 UTC (rev 257697)
+++ trunk/Source/WebCore/css/parser/CSSParserImpl.cpp	2020-03-02 00:43:28 UTC (rev 257698)
@@ -689,7 +689,7 @@
 
 RefPtr<StyleRule> CSSParserImpl::consumeStyleRule(CSSParserTokenRange prelude, CSSParserTokenRange block)
 {
-    CSSSelectorList selectorList = CSSSelectorParser::parseSelector(prelude, m_context, m_styleSheet.get());
+    CSSSelectorList selectorList = parseCSSSelector(prelude, m_context, m_styleSheet.get());
     if (!selectorList.isValid())
         return nullptr; // Parse error, invalid selector list
 

Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h (257697 => 257698)


--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h	2020-03-02 00:42:28 UTC (rev 257697)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.h	2020-03-02 00:43:28 UTC (rev 257698)
@@ -115,7 +115,6 @@
     return id == head || identMatches<tail...>(id);
 }
 
-// FIXME-NEWPARSER - converted to a RefPtr return type from a raw ptr.
 template<CSSValueID... names> RefPtr<CSSPrimitiveValue> consumeIdent(CSSParserTokenRange& range)
 {
     if (range.peek().type() != IdentToken || !identMatches<names...>(range.peek().id()))

Modified: trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp (257697 => 257698)


--- trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp	2020-03-02 00:42:28 UTC (rev 257697)
+++ trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp	2020-03-02 00:43:28 UTC (rev 257698)
@@ -1,5 +1,5 @@
 // Copyright 2014 The Chromium Authors. All rights reserved.
-// Copyright (C) 2016 Apple Inc. All rights reserved.
+// Copyright (C) 2016-2020 Apple Inc. All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
@@ -31,6 +31,7 @@
 #include "CSSSelectorParser.h"
 
 #include "CSSParserContext.h"
+#include "CSSParserSelector.h"
 #include "CSSSelectorList.h"
 #include "StyleSheetContents.h"
 #include <memory>
@@ -37,7 +38,67 @@
 
 namespace WebCore {
 
-CSSSelectorList CSSSelectorParser::parseSelector(CSSParserTokenRange range, const CSSParserContext& context, StyleSheetContents* styleSheet)
+class CSSSelectorParser {
+public:
+    CSSSelectorParser(const CSSParserContext&, StyleSheetContents*);
+
+    CSSSelectorList consumeComplexSelectorList(CSSParserTokenRange&);
+
+private:
+    CSSSelectorList consumeCompoundSelectorList(CSSParserTokenRange&);
+
+    std::unique_ptr<CSSParserSelector> consumeComplexSelector(CSSParserTokenRange&);
+    std::unique_ptr<CSSParserSelector> consumeCompoundSelector(CSSParserTokenRange&);
+
+    // This doesn't include element names, since they're handled specially.
+    std::unique_ptr<CSSParserSelector> consumeSimpleSelector(CSSParserTokenRange&);
+
+    bool consumeName(CSSParserTokenRange&, AtomString& name, AtomString& namespacePrefix);
+
+    // These will return nullptr when the selector is invalid.
+    std::unique_ptr<CSSParserSelector> consumeId(CSSParserTokenRange&);
+    std::unique_ptr<CSSParserSelector> consumeClass(CSSParserTokenRange&);
+    std::unique_ptr<CSSParserSelector> consumePseudo(CSSParserTokenRange&);
+    std::unique_ptr<CSSParserSelector> consumeAttribute(CSSParserTokenRange&);
+
+    CSSSelector::RelationType consumeCombinator(CSSParserTokenRange&);
+    CSSSelector::Match consumeAttributeMatch(CSSParserTokenRange&);
+    CSSSelector::AttributeMatchType consumeAttributeFlags(CSSParserTokenRange&);
+
+    const AtomString& defaultNamespace() const;
+    const AtomString& determineNamespace(const AtomString& prefix);
+    void prependTypeSelectorIfNeeded(const AtomString& namespacePrefix, const AtomString& elementName, CSSParserSelector&);
+    static std::unique_ptr<CSSParserSelector> splitCompoundAtImplicitShadowCrossingCombinator(std::unique_ptr<CSSParserSelector> compoundSelector, const CSSParserContext&);
+
+    class DisallowPseudoElementsScope;
+
+    const CSSParserContext& m_context;
+    const RefPtr<StyleSheetContents> m_styleSheet;
+    bool m_failedParsing { false };
+    bool m_disallowPseudoElements { false };
+};
+
+class CSSSelectorParser::DisallowPseudoElementsScope {
+public:
+    explicit DisallowPseudoElementsScope(CSSSelectorParser& parser)
+        : m_parser(parser)
+        , m_wasDisallowed(std::exchange(m_parser.m_disallowPseudoElements, true))
+    {
+    }
+
+    ~DisallowPseudoElementsScope()
+    {
+        m_parser.m_disallowPseudoElements = m_wasDisallowed;
+    }
+
+private:
+    CSSSelectorParser& m_parser;
+    bool m_wasDisallowed;
+};
+
+static bool consumeANPlusB(CSSParserTokenRange&, std::pair<int, int>&);
+
+CSSSelectorList parseCSSSelector(CSSParserTokenRange range, const CSSParserContext& context, StyleSheetContents* styleSheet)
 {
     CSSSelectorParser parser(context, styleSheet);
     range.consumeWhitespace();
@@ -56,7 +117,7 @@
 CSSSelectorList CSSSelectorParser::consumeComplexSelectorList(CSSParserTokenRange& range)
 {
     Vector<std::unique_ptr<CSSParserSelector>> selectorList;
-    std::unique_ptr<CSSParserSelector> selector = consumeComplexSelector(range);
+    auto selector = consumeComplexSelector(range);
     if (!selector)
         return CSSSelectorList();
     selectorList.append(WTFMove(selector));
@@ -67,7 +128,6 @@
             return CSSSelectorList();
         selectorList.append(WTFMove(selector));
     }
-
     if (m_failedParsing)
         return { };
     return CSSSelectorList { WTFMove(selectorList) };
@@ -76,7 +136,7 @@
 CSSSelectorList CSSSelectorParser::consumeCompoundSelectorList(CSSParserTokenRange& range)
 {
     Vector<std::unique_ptr<CSSParserSelector>> selectorList;
-    std::unique_ptr<CSSParserSelector> selector = consumeCompoundSelector(range);
+    auto selector = consumeCompoundSelector(range);
     range.consumeWhitespace();
     if (!selector)
         return CSSSelectorList();
@@ -89,9 +149,6 @@
             return CSSSelectorList();
         selectorList.append(WTFMove(selector));
     }
-
-    if (m_failedParsing)
-        return { };
     return CSSSelectorList { WTFMove(selectorList) };
 }
 
@@ -117,28 +174,24 @@
     return range.atEnd();
 }
 
-namespace {
-
-enum CompoundSelectorFlags {
+enum class CompoundSelectorFlag {
     HasPseudoElementForRightmostCompound = 1 << 0,
-    HasContentPseudoElement = 1 << 1
 };
 
-unsigned extractCompoundFlags(const CSSParserSelector& simpleSelector, CSSParserMode parserMode)
+static OptionSet<CompoundSelectorFlag> extractCompoundFlags(const CSSParserSelector& simpleSelector, CSSParserMode parserMode)
 {
     if (simpleSelector.match() != CSSSelector::PseudoElement)
-        return 0;
+        return { };
     
     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=161747
     // The UASheetMode check is a work-around to allow this selector in mediaControls(New).css:
     // input[type="range" i]::-webkit-media-slider-container > div {
     if (parserMode == UASheetMode && simpleSelector.pseudoElementType() == CSSSelector::PseudoElementWebKitCustom)
-        return 0;
-    return HasPseudoElementForRightmostCompound;
+        return { };
+
+    return CompoundSelectorFlag::HasPseudoElementForRightmostCompound;
 }
 
-} // namespace
-
 static bool isDescendantCombinator(CSSSelector::RelationType relation)
 {
     return relation == CSSSelector::DescendantSpace;
@@ -146,26 +199,26 @@
 
 std::unique_ptr<CSSParserSelector> CSSSelectorParser::consumeComplexSelector(CSSParserTokenRange& range)
 {
-    std::unique_ptr<CSSParserSelector> selector = consumeCompoundSelector(range);
+    auto selector = consumeCompoundSelector(range);
     if (!selector)
         return nullptr;
 
-    unsigned previousCompoundFlags = 0;
+    OptionSet<CompoundSelectorFlag> previousCompoundFlags;
 
     for (CSSParserSelector* simple = selector.get(); simple && !previousCompoundFlags; simple = simple->tagHistory())
-        previousCompoundFlags |= extractCompoundFlags(*simple, m_context.mode);
+        previousCompoundFlags = extractCompoundFlags(*simple, m_context.mode);
 
     while (auto combinator = consumeCombinator(range)) {
-        std::unique_ptr<CSSParserSelector> nextSelector = consumeCompoundSelector(range);
+        auto nextSelector = consumeCompoundSelector(range);
         if (!nextSelector)
             return isDescendantCombinator(combinator) ? WTFMove(selector) : nullptr;
-        if (previousCompoundFlags & HasPseudoElementForRightmostCompound)
+        if (previousCompoundFlags.contains(CompoundSelectorFlag::HasPseudoElementForRightmostCompound))
             return nullptr;
         CSSParserSelector* end = nextSelector.get();
-        unsigned compoundFlags = extractCompoundFlags(*end, m_context.mode);
+        auto compoundFlags = extractCompoundFlags(*end, m_context.mode);
         while (end->tagHistory()) {
             end = end->tagHistory();
-            compoundFlags |= extractCompoundFlags(*end, m_context.mode);
+            compoundFlags.add(extractCompoundFlags(*end, m_context.mode));
         }
         end->setRelation(combinator);
         previousCompoundFlags = compoundFlags;
@@ -177,9 +230,7 @@
     return selector;
 }
 
-namespace {
-
-bool isScrollbarPseudoClass(CSSSelector::PseudoClassType pseudo)
+static bool isScrollbarPseudoClass(CSSSelector::PseudoClassType pseudo)
 {
     switch (pseudo) {
     case CSSSelector::PseudoClassEnabled:
@@ -203,7 +254,7 @@
     }
 }
 
-bool isUserActionPseudoClass(CSSSelector::PseudoClassType pseudo)
+static bool isUserActionPseudoClass(CSSSelector::PseudoClassType pseudo)
 {
     switch (pseudo) {
     case CSSSelector::PseudoClassHover:
@@ -216,7 +267,7 @@
     }
 }
 
-bool isPseudoClassValidAfterPseudoElement(CSSSelector::PseudoClassType pseudoClass, CSSSelector::PseudoElementType compoundPseudoElement)
+static bool isPseudoClassValidAfterPseudoElement(CSSSelector::PseudoClassType pseudoClass, CSSSelector::PseudoElementType compoundPseudoElement)
 {
     switch (compoundPseudoElement) {
     case CSSSelector::PseudoElementPart:
@@ -239,7 +290,7 @@
     }
 }
 
-bool isSimpleSelectorValidAfterPseudoElement(const CSSParserSelector& simpleSelector, CSSSelector::PseudoElementType compoundPseudoElement)
+static bool isSimpleSelectorValidAfterPseudoElement(const CSSParserSelector& simpleSelector, CSSSelector::PseudoElementType compoundPseudoElement)
 {
     if (compoundPseudoElement == CSSSelector::PseudoElementUnknown)
         return true;
@@ -258,8 +309,6 @@
     return isPseudoClassValidAfterPseudoElement(pseudo, compoundPseudoElement);
 }
 
-} // namespace
-
 std::unique_ptr<CSSParserSelector> CSSSelectorParser::consumeCompoundSelector(CSSParserTokenRange& range)
 {
     std::unique_ptr<CSSParserSelector> compoundSelector;
@@ -275,7 +324,7 @@
             compoundPseudoElement = compoundSelector->pseudoElementType();
     }
 
-    while (std::unique_ptr<CSSParserSelector> simpleSelector = consumeSimpleSelector(range)) {
+    while (auto simpleSelector = consumeSimpleSelector(range)) {
         // FIXME: https://bugs.webkit.org/show_bug.cgi?id=161747
         // The UASheetMode check is a work-around to allow this selector in mediaControls(New).css:
         // video::-webkit-media-text-track-region-container.scrolling
@@ -287,7 +336,7 @@
             compoundPseudoElement = simpleSelector->pseudoElementType();
 
         if (compoundSelector)
-            compoundSelector = addSimpleSelectorToCompound(WTFMove(compoundSelector), WTFMove(simpleSelector));
+            compoundSelector->appendTagHistory(CSSSelector::Subselector, WTFMove(simpleSelector));
         else
             compoundSelector = WTFMove(simpleSelector);
     }
@@ -301,11 +350,9 @@
         if (namespaceURI == defaultNamespace())
             namespacePrefix = nullAtom();
         
-        CSSParserSelector* rawSelector = new CSSParserSelector(QualifiedName(namespacePrefix, elementName, namespaceURI));
-        std::unique_ptr<CSSParserSelector> selector = std::unique_ptr<CSSParserSelector>(rawSelector);
-        return selector;
+        return makeUnique<CSSParserSelector>(QualifiedName(namespacePrefix, elementName, namespaceURI));
     }
-    prependTypeSelectorIfNeeded(namespacePrefix, elementName, compoundSelector.get());
+    prependTypeSelectorIfNeeded(namespacePrefix, elementName, *compoundSelector);
     return splitCompoundAtImplicitShadowCrossingCombinator(WTFMove(compoundSelector), m_context);
 }
 
@@ -370,7 +417,8 @@
     ASSERT(range.peek().type() == HashToken);
     if (range.peek().getHashTokenType() != HashTokenId)
         return nullptr;
-    std::unique_ptr<CSSParserSelector> selector = std::unique_ptr<CSSParserSelector>(new CSSParserSelector());
+
+    auto selector = makeUnique<CSSParserSelector>();
     selector->setMatch(CSSSelector::Id);
     
     // FIXME-NEWPARSER: Avoid having to do this, but the old parser does and we need
@@ -387,7 +435,8 @@
     range.consume();
     if (range.peek().type() != IdentToken)
         return nullptr;
-    std::unique_ptr<CSSParserSelector> selector = std::unique_ptr<CSSParserSelector>(new CSSParserSelector());
+
+    auto selector = makeUnique<CSSParserSelector>();
     selector->setMatch(CSSSelector::Class);
     
     // FIXME-NEWPARSER: Avoid having to do this, but the old parser does and we need
@@ -418,7 +467,7 @@
         ? QualifiedName(nullAtom(), attributeName, nullAtom())
         : QualifiedName(namespacePrefix, attributeName, namespaceURI);
 
-    std::unique_ptr<CSSParserSelector> selector = std::unique_ptr<CSSParserSelector>(new CSSParserSelector());
+    auto selector = makeUnique<CSSParserSelector>();
 
     if (block.atEnd()) {
         selector->setAttribute(qualifiedName, m_context.isHTMLDocument, CSSSelector::CaseSensitive);
@@ -464,7 +513,7 @@
     
 static bool isOnlyPseudoElementFunction(CSSSelector::PseudoElementType pseudoElementType)
 {
-    // Note that we omit cue since it can be both an ident or a function.
+    // Note that we omit cue since it can be either an ident or a function.
     switch (pseudoElementType) {
     case CSSSelector::PseudoElementPart:
     case CSSSelector::PseudoElementSlotted:
@@ -534,8 +583,8 @@
     if (selector->match() == CSSSelector::PseudoClass) {
         switch (selector->pseudoClassType()) {
         case CSSSelector::PseudoClassNot: {
-            DisallowPseudoElementsScope scope(this);
-            std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
+            DisallowPseudoElementsScope scope(*this);
+            auto selectorList = makeUnique<CSSSelectorList>();
             *selectorList = consumeComplexSelectorList(block);
             if (!selectorList->first() || !block.atEnd())
                 return nullptr;
@@ -562,9 +611,9 @@
                     return nullptr;
                 if (block.peek().type() != WhitespaceToken)
                     return nullptr;
-                DisallowPseudoElementsScope scope(this);
+                DisallowPseudoElementsScope scope(*this);
                 block.consumeWhitespace();
-                std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
+                auto selectorList = makeUnique<CSSSelectorList>();
                 *selectorList = consumeComplexSelectorList(block);
                 if (!selectorList->first() || !block.atEnd())
                     return nullptr;
@@ -582,7 +631,7 @@
             return selector;
         }
         case CSSSelector::PseudoClassMatches: {
-            std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
+            auto selectorList = makeUnique<CSSSelectorList>();
             *selectorList = consumeComplexSelectorList(block);
             if (!selectorList->first() || !block.atEnd())
                 return nullptr;
@@ -591,7 +640,7 @@
         }
         case CSSSelector::PseudoClassAny:
         case CSSSelector::PseudoClassHost: {
-            std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
+            auto selectorList = makeUnique<CSSSelectorList>();
             *selectorList = consumeCompoundSelectorList(block);
             if (!selectorList->first() || !block.atEnd())
                 return nullptr;
@@ -617,8 +666,8 @@
         switch (selector->pseudoElementType()) {
 #if ENABLE(VIDEO_TRACK)
         case CSSSelector::PseudoElementCue: {
-            DisallowPseudoElementsScope scope(this);
-            std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList());
+            DisallowPseudoElementsScope scope(*this);
+            auto selectorList = makeUnique<CSSSelectorList>();
             *selectorList = consumeCompoundSelectorList(block);
             if (!selectorList->isValid() || !block.atEnd())
                 return nullptr;
@@ -627,7 +676,7 @@
         }
 #endif
         case CSSSelector::PseudoElementHighlight: {
-            DisallowPseudoElementsScope scope(this);
+            DisallowPseudoElementsScope scope(*this);
 
             auto& ident = block.consumeIncludingWhitespace();
             if (ident.type() != IdentToken || !block.atEnd())
@@ -652,9 +701,9 @@
             return selector;
         }
         case CSSSelector::PseudoElementSlotted: {
-            DisallowPseudoElementsScope scope(this);
+            DisallowPseudoElementsScope scope(*this);
 
-            std::unique_ptr<CSSParserSelector> innerSelector = consumeCompoundSelector(block);
+            auto innerSelector = consumeCompoundSelector(block);
             block.consumeWhitespace();
             if (!innerSelector || !block.atEnd())
                 return nullptr;
@@ -729,7 +778,7 @@
     return CSSSelector::CaseSensitive;
 }
 
-bool CSSSelectorParser::consumeANPlusB(CSSParserTokenRange& range, std::pair<int, int>& result)
+static bool consumeANPlusB(CSSParserTokenRange& range, std::pair<int, int>& result)
 {
     const CSSParserToken& token = range.consume();
     if (token.type() == NumberToken && token.numericValueType() == IntegerValueType) {
@@ -827,9 +876,9 @@
     return m_styleSheet->namespaceURIFromPrefix(prefix);
 }
 
-void CSSSelectorParser::prependTypeSelectorIfNeeded(const AtomString& namespacePrefix, const AtomString& elementName, CSSParserSelector* compoundSelector)
+void CSSSelectorParser::prependTypeSelectorIfNeeded(const AtomString& namespacePrefix, const AtomString& elementName, CSSParserSelector& compoundSelector)
 {
-    bool isShadowDOM = compoundSelector->needsImplicitShadowCombinatorForMatching();
+    bool isShadowDOM = compoundSelector.needsImplicitShadowCombinatorForMatching();
     
     if (elementName.isNull() && defaultNamespace() == starAtom() && !isShadowDOM)
         return;
@@ -843,7 +892,7 @@
     AtomString determinedPrefix = namespacePrefix;
     if (namespaceURI == defaultNamespace())
         determinedPrefix = nullAtom();
-    QualifiedName tag = QualifiedName(determinedPrefix, determinedElementName, namespaceURI);
+    QualifiedName tag(determinedPrefix, determinedElementName, namespaceURI);
 
     // *:host never matches, so we can't discard the *,
     // otherwise we can't tell the difference between *:host and just :host.
@@ -853,17 +902,11 @@
     // ::cue), we need a universal selector to set the combinator
     // (relation) on in the cases where there are no simple selectors preceding
     // the pseudo element.
-    bool explicitForHost = compoundSelector->isHostPseudoSelector() && !elementName.isNull();
+    bool explicitForHost = compoundSelector.isHostPseudoSelector() && !elementName.isNull();
     if (tag != anyQName() || explicitForHost || isShadowDOM)
-        compoundSelector->prependTagSelector(tag, determinedPrefix == nullAtom() && determinedElementName == starAtom() && !explicitForHost);
+        compoundSelector.prependTagSelector(tag, determinedPrefix == nullAtom() && determinedElementName == starAtom() && !explicitForHost);
 }
 
-std::unique_ptr<CSSParserSelector> CSSSelectorParser::addSimpleSelectorToCompound(std::unique_ptr<CSSParserSelector> compoundSelector, std::unique_ptr<CSSParserSelector> simpleSelector)
-{
-    compoundSelector->appendTagHistory(CSSSelector::Subselector, WTFMove(simpleSelector));
-    return compoundSelector;
-}
-
 std::unique_ptr<CSSParserSelector> CSSSelectorParser::splitCompoundAtImplicitShadowCrossingCombinator(std::unique_ptr<CSSParserSelector> compoundSelector, const CSSParserContext& context)
 {
     // The tagHistory is a linked list that stores combinator separated compound selectors
@@ -882,7 +925,7 @@
     CSSParserSelector* splitAfter = compoundSelector.get();
     while (splitAfter->tagHistory() && !splitAfter->tagHistory()->needsImplicitShadowCombinatorForMatching())
         splitAfter = splitAfter->tagHistory();
-    
+
     if (!splitAfter || !splitAfter->tagHistory())
         return compoundSelector;
 

Modified: trunk/Source/WebCore/css/parser/CSSSelectorParser.h (257697 => 257698)


--- trunk/Source/WebCore/css/parser/CSSSelectorParser.h	2020-03-02 00:42:28 UTC (rev 257697)
+++ trunk/Source/WebCore/css/parser/CSSSelectorParser.h	2020-03-02 00:43:28 UTC (rev 257698)
@@ -1,5 +1,5 @@
 // Copyright 2014 The Chromium Authors. All rights reserved.
-// Copyright (C) 2016 Apple Inc. All rights reserved.
+// Copyright (C) 2016-2020 Apple Inc. All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
@@ -29,80 +29,13 @@
 
 #pragma once
 
-#include "CSSParserSelector.h"
-#include "CSSParserTokenRange.h"
-#include <memory>
-
 namespace WebCore {
 
-struct CSSParserContext;
-class CSSSelectorList;
+class CSSParserTokenRange;
 class StyleSheetContents;
 
-// FIXME: We should consider building CSSSelectors directly instead of using
-// the intermediate CSSParserSelector.
-class CSSSelectorParser {
-public:
-    static CSSSelectorList parseSelector(CSSParserTokenRange, const CSSParserContext&, StyleSheetContents*);
+struct CSSParserContext;
 
-    static bool consumeANPlusB(CSSParserTokenRange&, std::pair<int, int>&);
+CSSSelectorList parseCSSSelector(CSSParserTokenRange, const CSSParserContext&, StyleSheetContents*);
 
-private:
-    CSSSelectorParser(const CSSParserContext&, StyleSheetContents*);
-
-    // These will all consume trailing comments if successful
-
-    CSSSelectorList consumeComplexSelectorList(CSSParserTokenRange&);
-    CSSSelectorList consumeCompoundSelectorList(CSSParserTokenRange&);
-
-    std::unique_ptr<CSSParserSelector> consumeComplexSelector(CSSParserTokenRange&);
-    std::unique_ptr<CSSParserSelector> consumeCompoundSelector(CSSParserTokenRange&);
-    // This doesn't include element names, since they're handled specially
-    std::unique_ptr<CSSParserSelector> consumeSimpleSelector(CSSParserTokenRange&);
-
-    bool consumeName(CSSParserTokenRange&, AtomString& name, AtomString& namespacePrefix);
-
-    // These will return nullptr when the selector is invalid
-    std::unique_ptr<CSSParserSelector> consumeId(CSSParserTokenRange&);
-    std::unique_ptr<CSSParserSelector> consumeClass(CSSParserTokenRange&);
-    std::unique_ptr<CSSParserSelector> consumePseudo(CSSParserTokenRange&);
-    std::unique_ptr<CSSParserSelector> consumeAttribute(CSSParserTokenRange&);
-
-    CSSSelector::RelationType consumeCombinator(CSSParserTokenRange&);
-    CSSSelector::Match consumeAttributeMatch(CSSParserTokenRange&);
-    CSSSelector::AttributeMatchType consumeAttributeFlags(CSSParserTokenRange&);
-
-    const AtomString& defaultNamespace() const;
-    const AtomString& determineNamespace(const AtomString& prefix);
-    void prependTypeSelectorIfNeeded(const AtomString& namespacePrefix, const AtomString& elementName, CSSParserSelector*);
-    static std::unique_ptr<CSSParserSelector> addSimpleSelectorToCompound(std::unique_ptr<CSSParserSelector> compoundSelector, std::unique_ptr<CSSParserSelector> simpleSelector);
-    static std::unique_ptr<CSSParserSelector> splitCompoundAtImplicitShadowCrossingCombinator(std::unique_ptr<CSSParserSelector> compoundSelector, const CSSParserContext&);
-
-    const CSSParserContext& m_context;
-    RefPtr<StyleSheetContents> m_styleSheet; // FIXME: Should be const
-
-    bool m_failedParsing = false;
-    bool m_disallowPseudoElements = false;
-
-    class DisallowPseudoElementsScope {
-        WTF_MAKE_NONCOPYABLE(DisallowPseudoElementsScope);
-    public:
-        DisallowPseudoElementsScope(CSSSelectorParser* parser)
-            : m_parser(parser), m_wasDisallowed(m_parser->m_disallowPseudoElements)
-        {
-            m_parser->m_disallowPseudoElements = true;
-        }
-
-        ~DisallowPseudoElementsScope()
-        {
-            m_parser->m_disallowPseudoElements = m_wasDisallowed;
-        }
-
-    private:
-        CSSSelectorParser* m_parser;
-        bool m_wasDisallowed;
-    };
-};
-
 } // namespace WebCore
-

Modified: trunk/Source/WebCore/style/StyleBuilderConverter.h (257697 => 257698)


--- trunk/Source/WebCore/style/StyleBuilderConverter.h	2020-03-02 00:42:28 UTC (rev 257697)
+++ trunk/Source/WebCore/style/StyleBuilderConverter.h	2020-03-02 00:43:28 UTC (rev 257698)
@@ -203,7 +203,7 @@
 
     if (primitiveValue.isLength()) {
         Length length = primitiveValue.computeLength<Length>(conversionData);
-        length.setHasQuirk(primitiveValue.isQuirkValue());
+        length.setHasQuirk(primitiveValue.primitiveType() == CSSUnitType::CSS_QUIRKY_EMS);
         return length;
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to