Changeset 207536 in webkit
- Timestamp:
- Oct 19, 2016 8:07:19 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207535 r207536 1 2016-10-18 Dave Hyatt <hyatt@apple.com> 2 3 [CSS Parser] Fix compound selector parsing. 4 https://bugs.webkit.org/show_bug.cgi?id=163649 5 6 Reviewed by Darin Adler. 7 8 The new CSS parser is failing to handle compound selectors. The code has an assumption that the 9 first value in the RelationType enum is SubSelector. This patch changes the enum to have the same 10 name used in Blink, RelationType, and to make the ordering be exactly the same. 11 12 * css/CSSSelector.h: 13 (WebCore::CSSSelector::relation): 14 (WebCore::CSSSelector::setRelation): 15 * css/SelectorChecker.cpp: 16 (WebCore::SelectorChecker::matchRecursively): 17 (WebCore::canMatchHoverOrActiveInQuirksMode): 18 (WebCore::SelectorChecker::determineLinkMatchType): 19 * css/SelectorFilter.cpp: 20 (WebCore::SelectorFilter::collectIdentifierHashes): 21 * css/parser/CSSParserValues.cpp: 22 (WebCore::CSSParserSelector::insertTagHistory): 23 (WebCore::CSSParserSelector::appendTagHistory): 24 * css/parser/CSSParserValues.h: 25 (WebCore::CSSParserSelector::setRelation): 26 * css/parser/CSSSelectorParser.cpp: 27 (WebCore::CSSSelectorParser::consumeComplexSelector): 28 (WebCore::CSSSelectorParser::consumeCombinator): 29 * css/parser/CSSSelectorParser.h: 30 * cssjit/SelectorCompiler.cpp: 31 (WebCore::SelectorCompiler::fragmentRelationForSelectorRelation): 32 (WebCore::SelectorCompiler::constructFragmentsInternal): 33 1 34 2016-10-19 Javier Fernandez <jfernandez@igalia.com> 2 35 -
trunk/Source/WebCore/css/CSSSelector.cpp
r205660 r207536 47 47 }; 48 48 49 static_assert(CSSSelector::RelationType::Subselector == 0, "Subselector must be 0 for consumeCombinator."); 49 50 static_assert(sizeof(CSSSelector) == sizeof(SameSizeAsCSSSelector), "CSSSelector should remain small."); 50 51 … … 721 722 } 722 723 723 if (cs->relation() != CSSSelector::Sub Selector || !cs->tagHistory())724 if (cs->relation() != CSSSelector::Subselector || !cs->tagHistory()) 724 725 break; 725 726 cs = cs->tagHistory(); … … 742 743 case CSSSelector::IndirectAdjacent: 743 744 return tagHistory->selectorText(" ~ " + str.toString() + rightSide); 744 case CSSSelector::Sub Selector:745 case CSSSelector::Subselector: 745 746 ASSERT_NOT_REACHED(); 746 747 #if ASSERT_DISABLED -
trunk/Source/WebCore/css/CSSSelector.h
r205660 r207536 82 82 }; 83 83 84 enum Relation { 85 Descendant = 0, 84 enum RelationType { 85 Subselector, 86 Descendant, 86 87 Child, 87 88 DirectAdjacent, 88 89 IndirectAdjacent, 89 SubSelector,90 90 ShadowDescendant, // FIXME-NEWPARSER: Remove this in favor of the new shadow values below. 91 91 ShadowPseudo, // Special case of shadow DOM pseudo elements / shadow pseudo element … … 296 296 bool isAttributeSelector() const; 297 297 298 Relation relation() const { return static_cast<Relation>(m_relation); }299 void setRelation(Relation relation)298 RelationType relation() const { return static_cast<RelationType>(m_relation); } 299 void setRelation(RelationType relation) 300 300 { 301 301 m_relation = relation; … … 327 327 328 328 private: 329 unsigned m_relation : 3; // enum Relation .329 unsigned m_relation : 3; // enum RelationType. 330 330 mutable unsigned m_match : 4; // enum Match. 331 331 mutable unsigned m_pseudoType : 8; // PseudoType. -
trunk/Source/WebCore/css/CSSSelectorList.cpp
r204591 r207536 132 132 void CSSSelectorList::buildSelectorsText(StringBuilder& stringBuilder) const 133 133 { 134 const CSSSelector* firstSub Selector = first();135 for (const CSSSelector* subSelector = firstSub Selector; subSelector; subSelector = CSSSelectorList::next(subSelector)) {136 if (subSelector != firstSub Selector)134 const CSSSelector* firstSubselector = first(); 135 for (const CSSSelector* subSelector = firstSubselector; subSelector; subSelector = CSSSelectorList::next(subSelector)) { 136 if (subSelector != firstSubselector) 137 137 stringBuilder.appendLiteral(", "); 138 138 stringBuilder.append(subSelector->selectorText()); -
trunk/Source/WebCore/css/RuleSet.cpp
r207077 r207536 123 123 } 124 124 125 if (selector->relation() != CSSSelector::Sub Selector)125 if (selector->relation() != CSSSelector::Subselector) 126 126 matchesRightmostElement = false; 127 127 … … 269 269 return; 270 270 } 271 if (selector->relation() != CSSSelector::Sub Selector)271 if (selector->relation() != CSSSelector::Subselector) 272 272 break; 273 273 selector = selector->tagHistory(); -
trunk/Source/WebCore/css/SelectorChecker.cpp
r207513 r207536 312 312 313 313 // The rest of the selectors has to match 314 CSSSelector::Relationrelation = context.selector->relation();314 auto relation = context.selector->relation(); 315 315 316 316 // Prepare next selector … … 322 322 nextContext.selector = leftSelector; 323 323 324 if (relation != CSSSelector::Sub Selector) {324 if (relation != CSSSelector::Subselector) { 325 325 // Bail-out if this selector is irrelevant for the pseudoId 326 326 if (context.pseudoId != NOPSEUDO && !dynamicPseudoIdSet.has(context.pseudoId)) … … 417 417 return MatchResult::fails(Match::SelectorFailsAllSiblings); 418 418 419 case CSSSelector::Sub Selector:419 case CSSSelector::Subselector: 420 420 { 421 421 // a selector is invalid if something follows a pseudo-element … … 635 635 } 636 636 637 CSSSelector::Relationrelation = selector->relation();637 auto relation = selector->relation(); 638 638 if (relation == CSSSelector::ShadowDescendant) 639 639 return true; 640 640 641 if (relation != CSSSelector::Sub Selector)641 if (relation != CSSSelector::Subselector) 642 642 return false; 643 643 } … … 1202 1202 } 1203 1203 } 1204 CSSSelector::Relationrelation = selector->relation();1205 if (relation == CSSSelector::Sub Selector)1204 auto relation = selector->relation(); 1205 if (relation == CSSSelector::Subselector) 1206 1206 continue; 1207 1207 if (relation != CSSSelector::Descendant && relation != CSSSelector::Child) -
trunk/Source/WebCore/css/SelectorFilter.cpp
r205660 r207536 123 123 unsigned* hash = identifierHashes; 124 124 unsigned* end = identifierHashes + maximumIdentifierCount; 125 CSSSelector::Relationrelation = selector->relation();125 auto relation = selector->relation(); 126 126 127 127 // Skip the topmost selector. It is handled quickly by the rule hashes. … … 130 130 // Only collect identifiers that match ancestors. 131 131 switch (relation) { 132 case CSSSelector::Sub Selector:132 case CSSSelector::Subselector: 133 133 if (!skipOverSubselectors) 134 134 collectDescendantSelectorIdentifierHashes(selector, hash); -
trunk/Source/WebCore/css/parser/CSSParser.cpp
r207499 r207536 12982 12982 if (specifiers->isCustomPseudoElement()) { 12983 12983 // Specifiers for unknown pseudo element go right behind it in the chain. 12984 specifiers->insertTagHistory(CSSSelector::Sub Selector, WTFMove(newSpecifier), CSSSelector::ShadowDescendant);12984 specifiers->insertTagHistory(CSSSelector::Subselector, WTFMove(newSpecifier), CSSSelector::ShadowDescendant); 12985 12985 return specifiers; 12986 12986 } 12987 specifiers->appendTagHistory(CSSSelector::Sub Selector, WTFMove(newSpecifier));12987 specifiers->appendTagHistory(CSSSelector::Subselector, WTFMove(newSpecifier)); 12988 12988 return specifiers; 12989 12989 } -
trunk/Source/WebCore/css/parser/CSSParserValues.cpp
r207513 r207536 448 448 } 449 449 450 void CSSParserSelector::insertTagHistory(CSSSelector::Relation before, std::unique_ptr<CSSParserSelector> selector, CSSSelector::Relationafter)450 void CSSParserSelector::insertTagHistory(CSSSelector::RelationType before, std::unique_ptr<CSSParserSelector> selector, CSSSelector::RelationType after) 451 451 { 452 452 if (m_tagHistory) … … 457 457 } 458 458 459 void CSSParserSelector::appendTagHistory(CSSSelector::Relation relation, std::unique_ptr<CSSParserSelector> selector)459 void CSSParserSelector::appendTagHistory(CSSSelector::RelationType relation, std::unique_ptr<CSSParserSelector> selector) 460 460 { 461 461 CSSParserSelector* end = this; … … 473 473 end = end->tagHistory(); 474 474 475 CSSSelector::Relation selectorRelation;475 CSSSelector::RelationType selectorRelation; 476 476 switch (relation) { 477 477 case CSSParserSelectorCombinator::Child: … … 520 520 521 521 m_selector = std::make_unique<CSSSelector>(tagQName, tagIsForNamespaceRule); 522 m_selector->setRelation(CSSSelector::Sub Selector);522 m_selector->setRelation(CSSSelector::Subselector); 523 523 } 524 524 525 525 std::unique_ptr<CSSParserSelector> CSSParserSelector::releaseTagHistory() 526 526 { 527 setRelation(CSSSelector::Sub Selector);527 setRelation(CSSSelector::Subselector); 528 528 return WTFMove(m_tagHistory); 529 529 } -
trunk/Source/WebCore/css/parser/CSSParserValues.h
r207513 r207536 227 227 void setAttributeValueMatchingIsCaseInsensitive(bool isCaseInsensitive) { m_selector->setAttributeValueMatchingIsCaseInsensitive(isCaseInsensitive); } 228 228 void setMatch(CSSSelector::Match value) { m_selector->setMatch(value); } 229 void setRelation(CSSSelector::Relation value) { m_selector->setRelation(value); }229 void setRelation(CSSSelector::RelationType value) { m_selector->setRelation(value); } 230 230 void setForPage() { m_selector->setForPage(); } 231 231 … … 262 262 void setTagHistory(std::unique_ptr<CSSParserSelector> selector) { m_tagHistory = WTFMove(selector); } 263 263 void clearTagHistory() { m_tagHistory.reset(); } 264 void insertTagHistory(CSSSelector::Relation before, std::unique_ptr<CSSParserSelector>, CSSSelector::Relationafter);265 void appendTagHistory(CSSSelector::Relation , std::unique_ptr<CSSParserSelector>);264 void insertTagHistory(CSSSelector::RelationType before, std::unique_ptr<CSSParserSelector>, CSSSelector::RelationType after); 265 void appendTagHistory(CSSSelector::RelationType, std::unique_ptr<CSSParserSelector>); 266 266 void appendTagHistory(CSSParserSelectorCombinator, std::unique_ptr<CSSParserSelector>); 267 267 void prependTagSelector(const QualifiedName&, bool tagIsForNamespaceRule = false); -
trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp
r207513 r207536 133 133 return nullptr; 134 134 135 136 135 unsigned previousCompoundFlags = 0; 137 136 … … 139 138 previousCompoundFlags |= extractCompoundFlags(*simple, m_context.mode); 140 139 141 while ( CSSSelector::Relationcombinator = consumeCombinator(range)) {140 while (auto combinator = consumeCombinator(range)) { 142 141 std::unique_ptr<CSSParserSelector> nextSelector = consumeCompoundSelector(range); 143 142 if (!nextSelector) … … 534 533 } 535 534 536 CSSSelector::Relation CSSSelectorParser::consumeCombinator(CSSParserTokenRange& range)537 { 538 CSSSelector::Relation fallbackResult = CSSSelector::SubSelector;535 CSSSelector::RelationType CSSSelectorParser::consumeCombinator(CSSParserTokenRange& range) 536 { 537 auto fallbackResult = CSSSelector::Subselector; 539 538 while (range.peek().type() == WhitespaceToken) { 540 539 range.consume(); … … 733 732 std::unique_ptr<CSSParserSelector> CSSSelectorParser::addSimpleSelectorToCompound(std::unique_ptr<CSSParserSelector> compoundSelector, std::unique_ptr<CSSParserSelector> simpleSelector) 734 733 { 735 compoundSelector->appendTagHistory(CSSSelector::Sub Selector, WTFMove(simpleSelector));734 compoundSelector->appendTagHistory(CSSSelector::Subselector, WTFMove(simpleSelector)); 736 735 return compoundSelector; 737 736 } … … 744 743 // 745 744 // ".a.b > div#id" is stored in a tagHistory as [div, #id, .a, .b], each element in the 746 // list stored with an associated relation (combinator or Sub Selector).745 // list stored with an associated relation (combinator or Subselector). 747 746 // 748 747 // ::cue, ::shadow, and custom pseudo elements have an implicit ShadowPseudo combinator -
trunk/Source/WebCore/css/parser/CSSSelectorParser.h
r205660 r207536 69 69 std::unique_ptr<CSSParserSelector> consumeAttribute(CSSParserTokenRange&); 70 70 71 CSSSelector::Relation consumeCombinator(CSSParserTokenRange&);71 CSSSelector::RelationType consumeCombinator(CSSParserTokenRange&); 72 72 CSSSelector::Match consumeAttributeMatch(CSSParserTokenRange&); 73 73 CSSSelector::AttributeMatchType consumeAttributeFlags(CSSParserTokenRange&); -
trunk/Source/WebCore/cssjit/SelectorCompiler.cpp
r205660 r207536 399 399 } 400 400 401 static inline FragmentRelation fragmentRelationForSelectorRelation(CSSSelector::Relation relation)401 static inline FragmentRelation fragmentRelationForSelectorRelation(CSSSelector::RelationType relation) 402 402 { 403 403 switch (relation) { … … 410 410 case CSSSelector::IndirectAdjacent: 411 411 return FragmentRelation::IndirectAdjacent; 412 case CSSSelector::Sub Selector:412 case CSSSelector::Subselector: 413 413 case CSSSelector::ShadowDescendant: 414 414 case CSSSelector::ShadowPseudo: … … 999 999 } 1000 1000 1001 CSSSelector::Relationrelation = selector->relation();1002 if (relation == CSSSelector::Sub Selector)1001 auto relation = selector->relation(); 1002 if (relation == CSSSelector::Subselector) 1003 1003 continue; 1004 1004 -
trunk/Source/WebCore/dom/SelectorQuery.cpp
r207396 r207536 71 71 return IdMatchingType::Filter; 72 72 } 73 if (selector->relation() != CSSSelector::Sub Selector)73 if (selector->relation() != CSSSelector::Subselector) 74 74 inRightmost = false; 75 75 } … … 205 205 if (canBeUsedForIdFastPath(*selector)) 206 206 return selector; 207 if (selector->relation() != CSSSelector::Sub Selector)207 if (selector->relation() != CSSSelector::Subselector) 208 208 break; 209 209 } … … 257 257 do { 258 258 ASSERT(!canBeUsedForIdFastPath(*selector)); 259 if (selector->relation() != CSSSelector::Sub Selector)259 if (selector->relation() != CSSSelector::Subselector) 260 260 break; 261 261 selector = selector->tagHistory(); … … 275 275 } 276 276 } 277 if (selector->relation() == CSSSelector::Sub Selector)277 if (selector->relation() == CSSSelector::Subselector) 278 278 continue; 279 279 if (selector->relation() == CSSSelector::DirectAdjacent || selector->relation() == CSSSelector::IndirectAdjacent)
Note: See TracChangeset
for help on using the changeset viewer.