[CSS Parser] Fix ::cue parsing
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Nov 2016 21:04:05 +0000 (21:04 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Nov 2016 21:04:05 +0000 (21:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165152

Reviewed by Zalan Bujtas.

* css/parser/CSSParserValues.h:
(WebCore::CSSParserSelector::setPseudoElementType):
* css/parser/CSSSelectorParser.cpp:
(WebCore::isOnlyPseudoClassFunction):
(WebCore::isOnlyPseudoElementFunction):
(WebCore::CSSSelectorParser::consumePseudo):
(WebCore::isPseudoClassFunction): Deleted.
(WebCore::isPseudoElementFunction): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@209085 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/parser/CSSParserValues.h
Source/WebCore/css/parser/CSSSelectorParser.cpp

index 23c5879..a705f05 100644 (file)
@@ -1,3 +1,19 @@
+2016-11-29  Dave Hyatt  <hyatt@apple.com>
+
+        [CSS Parser] Fix ::cue parsing
+        https://bugs.webkit.org/show_bug.cgi?id=165152
+
+        Reviewed by Zalan Bujtas.
+
+        * css/parser/CSSParserValues.h:
+        (WebCore::CSSParserSelector::setPseudoElementType):
+        * css/parser/CSSSelectorParser.cpp:
+        (WebCore::isOnlyPseudoClassFunction):
+        (WebCore::isOnlyPseudoElementFunction):
+        (WebCore::CSSSelectorParser::consumePseudo):
+        (WebCore::isPseudoClassFunction): Deleted.
+        (WebCore::isPseudoElementFunction): Deleted.
+
 2016-11-28  Gavin Barraclough  <barraclough@apple.com>
 
         HTMLMediaElement::updateVolume should updateIsPlayingMedia
index 6c7c41b..9097017 100644 (file)
@@ -235,6 +235,8 @@ public:
     CSSSelector::Match match() const { return m_selector->match(); }
     CSSSelector::PseudoElementType pseudoElementType() const { return m_selector->pseudoElementType(); }
     const CSSSelectorList* selectorList() const { return m_selector->selectorList(); }
+    
+    void setPseudoElementType(CSSSelector::PseudoElementType type) { m_selector->setPseudoElementType(type); }
 
     void adoptSelectorVector(Vector<std::unique_ptr<CSSParserSelector>>& selectorVector);
     void setLangArgumentList(const Vector<CSSParserString>& stringVector);
index 6549540..0a2f31f 100644 (file)
@@ -461,7 +461,7 @@ std::unique_ptr<CSSParserSelector> CSSSelectorParser::consumeAttribute(CSSParser
     return selector;
 }
 
-static bool isPseudoClassFunction(CSSSelector::PseudoClassType pseudoClassType)
+static bool isOnlyPseudoClassFunction(CSSSelector::PseudoClassType pseudoClassType)
 {
     switch (pseudoClassType) {
     case CSSSelector::PseudoClassNot:
@@ -483,12 +483,10 @@ static bool isPseudoClassFunction(CSSSelector::PseudoClassType pseudoClassType)
     return false;
 }
     
-static bool isPseudoElementFunction(CSSSelector::PseudoElementType pseudoElementType)
+static bool isOnlyPseudoElementFunction(CSSSelector::PseudoElementType pseudoElementType)
 {
+    // Note that we omit cue since it can be both an ident or a function.
     switch (pseudoElementType) {
-#if ENABLE(VIDEO_TRACK)
-    case CSSSelector::PseudoElementCue:
-#endif
     case CSSSelector::PseudoElementSlotted:
         return true;
     default:
@@ -533,16 +531,30 @@ std::unique_ptr<CSSParserSelector> CSSSelectorParser::consumePseudo(CSSParserTok
 
     if (colons == 1)
         selector = std::unique_ptr<CSSParserSelector>(CSSParserSelector::parsePseudoClassSelectorFromStringView(value));
-    else
+    else {
         selector = std::unique_ptr<CSSParserSelector>(CSSParserSelector::parsePseudoElementSelectorFromStringView(value));
+        if (selector && selector->match() == CSSSelector::PseudoElement && selector->pseudoElementType() == CSSSelector::PseudoElementWebKitCustom) {
+            // FIXME-NEWPARSER: The old parser treats cue as two pseudo-element types, because it
+            // is unable to handle a dual pseudo-element (one that can be both an ident or a
+            // function) without splitting them up.
+            //
+            // This means that "cue" is being parsed as PseudoElementWebkitCustom when used as an
+            // identifier, and it's being parsed as PseudoElementCue when used as a function.
+            //
+            // We have to mimic this behavior until the old parser is gone, at which point we can
+            // make all code use PseudoElementCue.
+            if (token.type() == FunctionToken && value.startsWithIgnoringASCIICase("cue"))
+                selector->setPseudoElementType(CSSSelector::PseudoElementCue);
+        }
+    }
 
     if (!selector || (selector->match() == CSSSelector::PseudoElement && m_disallowPseudoElements))
         return nullptr;
 
     if (token.type() == IdentToken) {
         range.consume();
-        if ((selector->match() == CSSSelector::PseudoElement && (selector->pseudoElementType() == CSSSelector::PseudoElementUnknown || isPseudoElementFunction(selector->pseudoElementType())))
-            || (selector->match() == CSSSelector::PseudoClass && (selector->pseudoClassType() == CSSSelector::PseudoClassUnknown || isPseudoClassFunction(selector->pseudoClassType()))))
+        if ((selector->match() == CSSSelector::PseudoElement && (selector->pseudoElementType() == CSSSelector::PseudoElementUnknown || isOnlyPseudoElementFunction(selector->pseudoElementType())))
+            || (selector->match() == CSSSelector::PseudoClass && (selector->pseudoClassType() == CSSSelector::PseudoClassUnknown || isOnlyPseudoClassFunction(selector->pseudoClassType()))))
             return nullptr;
         return selector;
     }