Title: [208130] trunk/Source/WebCore
Revision
208130
Author
[email protected]
Date
2016-10-30 11:48:09 -0700 (Sun, 30 Oct 2016)

Log Message

[CSS Parser] Clean up the two types of descendant relations in CSSSelector
https://bugs.webkit.org/show_bug.cgi?id=164203

Reviewed by Zalan Bujtas.

This patch gets rid of the separate boolean for double child and allows it
to be a unique relation type. Rename Descendant to DescendantSpace and
name the new relation DescendantDoubleChild.

* css/CSSSelector.cpp:
(WebCore::CSSSelector::CSSSelector):
(WebCore::CSSSelector::selectorText):
* css/CSSSelector.h:
(WebCore::CSSSelector::hasDescendantRelation):
(WebCore::CSSSelector::hasDescendantOrChildRelation):
(WebCore::CSSSelector::CSSSelector):
(WebCore::CSSSelector::setDescendantUseDoubleChildSyntax): Deleted.
* css/RuleFeature.cpp:
(WebCore::RuleFeatureSet::recursivelyCollectFeaturesFromSelector):
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::matchRecursively):
(WebCore::SelectorChecker::determineLinkMatchType):
* css/SelectorFilter.cpp:
(WebCore::SelectorFilter::collectIdentifierHashes):
* css/parser/CSSParserValues.cpp:
(WebCore::CSSParserSelector::appendTagHistory):
* css/parser/CSSParserValues.h:
(WebCore::CSSParserSelector::setDescendantUseDoubleChildSyntax): Deleted.
* css/parser/CSSSelectorParser.cpp:
(WebCore::isDescendantCombinator):
(WebCore::CSSSelectorParser::consumeComplexSelector):
(WebCore::CSSSelectorParser::consumeCombinator):
* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::fragmentRelationForSelectorRelation):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (208129 => 208130)


--- trunk/Source/WebCore/ChangeLog	2016-10-30 16:35:12 UTC (rev 208129)
+++ trunk/Source/WebCore/ChangeLog	2016-10-30 18:48:09 UTC (rev 208130)
@@ -1,3 +1,40 @@
+2016-10-30  Dave Hyatt  <[email protected]>
+
+        [CSS Parser] Clean up the two types of descendant relations in CSSSelector
+        https://bugs.webkit.org/show_bug.cgi?id=164203
+
+        Reviewed by Zalan Bujtas.
+
+        This patch gets rid of the separate boolean for double child and allows it
+        to be a unique relation type. Rename Descendant to DescendantSpace and
+        name the new relation DescendantDoubleChild.
+
+        * css/CSSSelector.cpp:
+        (WebCore::CSSSelector::CSSSelector):
+        (WebCore::CSSSelector::selectorText):
+        * css/CSSSelector.h:
+        (WebCore::CSSSelector::hasDescendantRelation):
+        (WebCore::CSSSelector::hasDescendantOrChildRelation):
+        (WebCore::CSSSelector::CSSSelector):
+        (WebCore::CSSSelector::setDescendantUseDoubleChildSyntax): Deleted.
+        * css/RuleFeature.cpp:
+        (WebCore::RuleFeatureSet::recursivelyCollectFeaturesFromSelector):
+        * css/SelectorChecker.cpp:
+        (WebCore::SelectorChecker::matchRecursively):
+        (WebCore::SelectorChecker::determineLinkMatchType):
+        * css/SelectorFilter.cpp:
+        (WebCore::SelectorFilter::collectIdentifierHashes):
+        * css/parser/CSSParserValues.cpp:
+        (WebCore::CSSParserSelector::appendTagHistory):
+        * css/parser/CSSParserValues.h:
+        (WebCore::CSSParserSelector::setDescendantUseDoubleChildSyntax): Deleted.
+        * css/parser/CSSSelectorParser.cpp:
+        (WebCore::isDescendantCombinator):
+        (WebCore::CSSSelectorParser::consumeComplexSelector):
+        (WebCore::CSSSelectorParser::consumeCombinator):
+        * cssjit/SelectorCompiler.cpp:
+        (WebCore::SelectorCompiler::fragmentRelationForSelectorRelation):
+
 2016-10-30  Frederic Wang  <[email protected]>
 
         Unreviewed gardening

Modified: trunk/Source/WebCore/css/CSSSelector.cpp (208129 => 208130)


--- trunk/Source/WebCore/css/CSSSelector.cpp	2016-10-30 16:35:12 UTC (rev 208129)
+++ trunk/Source/WebCore/css/CSSSelector.cpp	2016-10-30 18:48:09 UTC (rev 208130)
@@ -50,7 +50,7 @@
 static_assert(sizeof(CSSSelector) == sizeof(SameSizeAsCSSSelector), "CSSSelector should remain small.");
 
 CSSSelector::CSSSelector(const QualifiedName& tagQName, bool tagIsForNamespaceRule)
-    : m_relation(Descendant)
+    : m_relation(DescendantSpace)
     , m_match(Tag)
     , m_pseudoType(0)
     , m_parsedNth(false)
@@ -60,9 +60,6 @@
     , m_hasNameWithCase(false)
     , m_isForPage(false)
     , m_tagIsForNamespaceRule(tagIsForNamespaceRule)
-#if ENABLE(CSS_SELECTORS_LEVEL4)
-    , m_descendantDoubleChildSyntax(false)
-#endif
     , m_caseInsensitiveAttributeValueMatching(false)
 #if !ASSERT_WITH_SECURITY_IMPLICATION_DISABLED
     , m_destructorHasBeenCalled(false)
@@ -728,11 +725,7 @@
 
     if (const CSSSelector* tagHistory = cs->tagHistory()) {
         switch (cs->relation()) {
-        case CSSSelector::Descendant:
-#if ENABLE(CSS_SELECTORS_LEVEL4)
-            if (cs->m_descendantDoubleChildSyntax)
-                return tagHistory->selectorText(" >> " + str.toString() + rightSide);
-#endif
+        case CSSSelector::DescendantSpace:
             return tagHistory->selectorText(" " + str.toString() + rightSide);
         case CSSSelector::Child:
             return tagHistory->selectorText(" > " + str.toString() + rightSide);
@@ -742,6 +735,10 @@
             return tagHistory->selectorText(" + " + str.toString() + rightSide);
         case CSSSelector::IndirectAdjacent:
             return tagHistory->selectorText(" ~ " + str.toString() + rightSide);
+#if ENABLE(CSS_SELECTORS_LEVEL4)
+        case CSSSelector::DescendantDoubleChild:
+            return tagHistory->selectorText(" >> " + str.toString() + rightSide);
+#endif
         case CSSSelector::Subselector:
             ASSERT_NOT_REACHED();
 #if ASSERT_DISABLED

Modified: trunk/Source/WebCore/css/CSSSelector.h (208129 => 208130)


--- trunk/Source/WebCore/css/CSSSelector.h	2016-10-30 16:35:12 UTC (rev 208129)
+++ trunk/Source/WebCore/css/CSSSelector.h	2016-10-30 18:48:09 UTC (rev 208130)
@@ -83,10 +83,13 @@
 
         enum RelationType {
             Subselector,
-            Descendant,
+            DescendantSpace,
             Child,
             DirectAdjacent,
             IndirectAdjacent,
+#if ENABLE(CSS_SELECTORS_LEVEL4)
+            DescendantDoubleChild,
+#endif
             ShadowDescendant, // FIXME-NEWPARSER: Remove this in favor of the new shadow values below.
             ShadowPseudo, // Special case of shadow DOM pseudo elements / shadow pseudo element
             ShadowDeep, // /deep/ combinator
@@ -259,6 +262,14 @@
         int nthA() const;
         int nthB() const;
 
+#if ENABLE(CSS_SELECTORS_LEVEL4)
+        bool hasDescendantRelation() const { return relation() == DescendantSpace || relation() == DescendantDoubleChild; }
+#else
+        bool hasDescendantRelation() const { return relation() == DescendantSpace; }
+#endif
+
+        bool hasDescendantOrChildRelation() const { return relation() == Child || hasDescendantRelation(); }
+
         PseudoClassType pseudoClassType() const
         {
             ASSERT(match() == PseudoClass);
@@ -306,14 +317,6 @@
             ASSERT(m_relation == relation);
         }
 
-#if ENABLE(CSS_SELECTORS_LEVEL4)
-        void setDescendantUseDoubleChildSyntax()
-        {
-            ASSERT(relation() == Descendant);
-            m_descendantDoubleChildSyntax = true;
-        }
-#endif
-
         Match match() const { return static_cast<Match>(m_match); }
         void setMatch(Match match)
         {
@@ -330,7 +333,7 @@
         void setForPage() { m_isForPage = true; }
 
     private:
-        unsigned m_relation              : 3; // enum RelationType.
+        unsigned m_relation              : 4; // enum RelationType.
         mutable unsigned m_match         : 4; // enum Match.
         mutable unsigned m_pseudoType    : 8; // PseudoType.
         mutable unsigned m_parsedNth     : 1; // Used for :nth-*.
@@ -340,9 +343,6 @@
         unsigned m_hasNameWithCase       : 1;
         unsigned m_isForPage             : 1;
         unsigned m_tagIsForNamespaceRule : 1;
-#if ENABLE(CSS_SELECTORS_LEVEL4)
-        unsigned m_descendantDoubleChildSyntax : 1;
-#endif
         unsigned m_caseInsensitiveAttributeValueMatching : 1;
 #if !ASSERT_WITH_SECURITY_IMPLICATION_DISABLED
         unsigned m_destructorHasBeenCalled : 1;
@@ -483,7 +483,7 @@
 }
 
 inline CSSSelector::CSSSelector()
-    : m_relation(Descendant)
+    : m_relation(DescendantSpace)
     , m_match(Unknown)
     , m_pseudoType(0)
     , m_parsedNth(false)
@@ -493,9 +493,6 @@
     , m_hasNameWithCase(false)
     , m_isForPage(false)
     , m_tagIsForNamespaceRule(false)
-#if ENABLE(CSS_SELECTORS_LEVEL4)
-    , m_descendantDoubleChildSyntax(false)
-#endif
     , m_caseInsensitiveAttributeValueMatching(false)
 #if !ASSERT_WITH_SECURITY_IMPLICATION_DISABLED
     , m_destructorHasBeenCalled(false)
@@ -514,9 +511,6 @@
     , m_hasNameWithCase(o.m_hasNameWithCase)
     , m_isForPage(o.m_isForPage)
     , m_tagIsForNamespaceRule(o.m_tagIsForNamespaceRule)
-#if ENABLE(CSS_SELECTORS_LEVEL4)
-    , m_descendantDoubleChildSyntax(o.m_descendantDoubleChildSyntax)
-#endif
     , m_caseInsensitiveAttributeValueMatching(o.m_caseInsensitiveAttributeValueMatching)
 #if !ASSERT_WITH_SECURITY_IMPLICATION_DISABLED
     , m_destructorHasBeenCalled(false)

Modified: trunk/Source/WebCore/css/RuleFeature.cpp (208129 => 208130)


--- trunk/Source/WebCore/css/RuleFeature.cpp	2016-10-30 16:35:12 UTC (rev 208129)
+++ trunk/Source/WebCore/css/RuleFeature.cpp	2016-10-30 18:48:09 UTC (rev 208130)
@@ -77,7 +77,7 @@
                 recursivelyCollectFeaturesFromSelector(selectorFeatures, *subSelector, matchesAncestor);
             }
         }
-        if (selector->relation() == CSSSelector::Child || selector->relation() == CSSSelector::Descendant)
+        if (selector->hasDescendantOrChildRelation())
             matchesAncestor = true;
 
         selector = selector->tagHistory();

Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (208129 => 208130)


--- trunk/Source/WebCore/css/SelectorChecker.cpp	2016-10-30 16:35:12 UTC (rev 208129)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp	2016-10-30 18:48:09 UTC (rev 208130)
@@ -320,7 +320,7 @@
             return MatchResult::fails(Match::SelectorFailsCompletely);
 
         // Disable :visited matching when we try to match anything else than an ancestors.
-        if (relation != CSSSelector::Descendant && relation != CSSSelector::Child)
+        if (!context.selector->hasDescendantOrChildRelation())
             nextContext.visitedMatchType = VisitedMatchType::Disabled;
 
         nextContext.pseudoId = NOPSEUDO;
@@ -330,7 +330,10 @@
     }
 
     switch (relation) {
-    case CSSSelector::Descendant:
+    case CSSSelector::DescendantSpace:
+#if ENABLE_CSS_SELECTORS_LEVEL4
+    case CSSSelector::DescendantDoubleChild:
+#endif
         nextContext = localContextForParent(nextContext);
         nextContext.firstSelectorOfTheFragment = nextContext.selector;
         for (; nextContext.element; nextContext = localContextForParent(nextContext)) {
@@ -1197,7 +1200,7 @@
         auto relation = selector->relation();
         if (relation == CSSSelector::Subselector)
             continue;
-        if (relation != CSSSelector::Descendant && relation != CSSSelector::Child)
+        if (!selector->hasDescendantOrChildRelation())
             return linkMatchType;
         if (linkMatchType != MatchAll)
             return linkMatchType;

Modified: trunk/Source/WebCore/css/SelectorFilter.cpp (208129 => 208130)


--- trunk/Source/WebCore/css/SelectorFilter.cpp	2016-10-30 16:35:12 UTC (rev 208129)
+++ trunk/Source/WebCore/css/SelectorFilter.cpp	2016-10-30 18:48:09 UTC (rev 208130)
@@ -142,7 +142,10 @@
             // Disable fastRejectSelector.
             *identifierHashes = 0;
             return;
-        case CSSSelector::Descendant:
+        case CSSSelector::DescendantSpace:
+#if ENABLE_CSS_SELECTORS_LEVEL4
+        case CSSSelector::DescendantDoubleChild:
+#endif
         case CSSSelector::Child:
         case CSSSelector::ShadowPseudo:
         case CSSSelector::ShadowDeep:

Modified: trunk/Source/WebCore/css/parser/CSSParserValues.cpp (208129 => 208130)


--- trunk/Source/WebCore/css/parser/CSSParserValues.cpp	2016-10-30 16:35:12 UTC (rev 208129)
+++ trunk/Source/WebCore/css/parser/CSSParserValues.cpp	2016-10-30 18:48:09 UTC (rev 208130)
@@ -481,11 +481,11 @@
         selectorRelation = CSSSelector::Child;
         break;
     case CSSParserSelectorCombinator::DescendantSpace:
-        selectorRelation = CSSSelector::Descendant;
+        selectorRelation = CSSSelector::DescendantSpace;
         break;
 #if ENABLE(CSS_SELECTORS_LEVEL4)
     case CSSParserSelectorCombinator::DescendantDoubleChild:
-        selectorRelation = CSSSelector::Descendant;
+        selectorRelation = CSSSelector::DescendantDoubleChild;
         break;
 #endif
     case CSSParserSelectorCombinator::DirectAdjacent:
@@ -505,12 +505,6 @@
         break;
     }
     end->setRelation(selectorRelation);
-
-#if ENABLE(CSS_SELECTORS_LEVEL4)
-    if (relation == CSSParserSelectorCombinator::DescendantDoubleChild)
-        end->setDescendantUseDoubleChildSyntax();
-#endif
-
     end->setTagHistory(WTFMove(selector));
 }
 

Modified: trunk/Source/WebCore/css/parser/CSSParserValues.h (208129 => 208130)


--- trunk/Source/WebCore/css/parser/CSSParserValues.h	2016-10-30 16:35:12 UTC (rev 208129)
+++ trunk/Source/WebCore/css/parser/CSSParserValues.h	2016-10-30 18:48:09 UTC (rev 208130)
@@ -275,10 +275,6 @@
     std::unique_ptr<CSSParserSelector> releaseTagHistory();
 
 private:
-#if ENABLE(CSS_SELECTORS_LEVEL4)
-    void setDescendantUseDoubleChildSyntax() { m_selector->setDescendantUseDoubleChildSyntax(); }
-#endif
-
     std::unique_ptr<CSSSelector> m_selector;
     std::unique_ptr<CSSParserSelector> m_tagHistory;
 };

Modified: trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp (208129 => 208130)


--- trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp	2016-10-30 16:35:12 UTC (rev 208129)
+++ trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp	2016-10-30 18:48:09 UTC (rev 208130)
@@ -149,6 +149,14 @@
 
 } // namespace
 
+static bool isDescendantCombinator(CSSSelector::RelationType relation)
+{
+#if ENABLE(CSS_SELECTORS_LEVEL4)
+    return relation == CSSSelector::DescendantSpace || relation == CSSSelector::DescendantDoubleChild;
+#else
+    return relation == CSSSelector::DescendantSpace;
+#endif
+}
 std::unique_ptr<CSSParserSelector> CSSSelectorParser::consumeComplexSelector(CSSParserTokenRange& range)
 {
     std::unique_ptr<CSSParserSelector> selector = consumeCompoundSelector(range);
@@ -163,7 +171,7 @@
     while (auto combinator = consumeCombinator(range)) {
         std::unique_ptr<CSSParserSelector> nextSelector = consumeCompoundSelector(range);
         if (!nextSelector)
-            return combinator == CSSSelector::Descendant ? WTFMove(selector) : nullptr;
+            return isDescendantCombinator(combinator) ? WTFMove(selector) : nullptr;
         if (previousCompoundFlags & HasPseudoElementForRightmostCompound)
             return nullptr;
         CSSParserSelector* end = nextSelector.get();
@@ -648,7 +656,7 @@
     auto fallbackResult = CSSSelector::Subselector;
     while (range.peek().type() == WhitespaceToken) {
         range.consume();
-        fallbackResult = CSSSelector::Descendant;
+        fallbackResult = CSSSelector::DescendantSpace;
     }
 
     if (range.peek().type() != DelimiterToken)
@@ -663,10 +671,9 @@
         if (delimiter == '~')
             return CSSSelector::IndirectAdjacent;
 #if ENABLE_CSS_SELECTORS_LEVEL4
-        // FIXME-NEWPARSER: Need to set that this was a >> so serialization is correct
         if (delimiter == '>' && range.peek().type() == DelimiterToken && range.peek().delimiter() == '>') {
             range.consumeIncludingWhitespace();
-            return CSSSelector::Descendant;
+            return CSSSelector::DescendantDoubleChild;
         }
 #endif
         return CSSSelector::Child;

Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.cpp (208129 => 208130)


--- trunk/Source/WebCore/cssjit/SelectorCompiler.cpp	2016-10-30 16:35:12 UTC (rev 208129)
+++ trunk/Source/WebCore/cssjit/SelectorCompiler.cpp	2016-10-30 18:48:09 UTC (rev 208130)
@@ -401,7 +401,10 @@
 static inline FragmentRelation fragmentRelationForSelectorRelation(CSSSelector::RelationType relation)
 {
     switch (relation) {
-    case CSSSelector::Descendant:
+    case CSSSelector::DescendantSpace:
+#if ENABLE_CSS_SELECTORS_LEVEL4
+    case CSSSelector::DescendantDoubleChild:
+#endif
         return FragmentRelation::Descendant;
     case CSSSelector::Child:
         return FragmentRelation::Child;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to