OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/css/parser/CSSSelectorParser.h" | 6 #include "core/css/parser/CSSSelectorParser.h" |
7 | 7 |
8 #include "core/css/CSSSelectorList.h" | 8 #include "core/css/CSSSelectorList.h" |
9 #include "core/css/StyleSheetContents.h" | 9 #include "core/css/StyleSheetContents.h" |
10 #include "core/frame/UseCounter.h" | 10 #include "core/frame/UseCounter.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 if (m_context.isHTMLDocument()) | 150 if (m_context.isHTMLDocument()) |
151 elementName = elementName.lower(); | 151 elementName = elementName.lower(); |
152 | 152 |
153 while (OwnPtr<CSSParserSelector> simpleSelector = consumeSimpleSelector(rang
e)) { | 153 while (OwnPtr<CSSParserSelector> simpleSelector = consumeSimpleSelector(rang
e)) { |
154 if (compoundSelector) | 154 if (compoundSelector) |
155 compoundSelector = addSimpleSelectorToCompound(compoundSelector.rele
ase(), simpleSelector.release()); | 155 compoundSelector = addSimpleSelectorToCompound(compoundSelector.rele
ase(), simpleSelector.release()); |
156 else | 156 else |
157 compoundSelector = simpleSelector.release(); | 157 compoundSelector = simpleSelector.release(); |
158 } | 158 } |
159 | 159 |
160 if (!compoundSelector) | 160 if (!compoundSelector) { |
161 return CSSParserSelector::create(determineNameInNamespace(namespacePrefi
x, elementName)); | 161 AtomicString namespaceURI = determineNamespace(namespacePrefix); |
| 162 if (namespaceURI.isNull()) |
| 163 return nullptr; |
| 164 return CSSParserSelector::create(QualifiedName(namespacePrefix, elementN
ame, namespaceURI)); |
| 165 } |
162 prependTypeSelectorIfNeeded(namespacePrefix, elementName, compoundSelector.g
et()); | 166 prependTypeSelectorIfNeeded(namespacePrefix, elementName, compoundSelector.g
et()); |
163 return compoundSelector.release(); | 167 return compoundSelector.release(); |
164 } | 168 } |
165 | 169 |
166 PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumeSimpleSelector(CSSParser
TokenRange& range) | 170 PassOwnPtr<CSSParserSelector> CSSSelectorParser::consumeSimpleSelector(CSSParser
TokenRange& range) |
167 { | 171 { |
168 const CSSParserToken& token = range.peek(); | 172 const CSSParserToken& token = range.peek(); |
169 OwnPtr<CSSParserSelector> selector; | 173 OwnPtr<CSSParserSelector> selector; |
170 if (token.type() == HashToken) | 174 if (token.type() == HashToken) |
171 selector = consumeId(range); | 175 selector = consumeId(range); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 264 |
261 AtomicString namespacePrefix; | 265 AtomicString namespacePrefix; |
262 AtomicString attributeName; | 266 AtomicString attributeName; |
263 if (!consumeName(block, attributeName, namespacePrefix)) | 267 if (!consumeName(block, attributeName, namespacePrefix)) |
264 return nullptr; | 268 return nullptr; |
265 block.consumeWhitespace(); | 269 block.consumeWhitespace(); |
266 | 270 |
267 if (m_context.isHTMLDocument()) | 271 if (m_context.isHTMLDocument()) |
268 attributeName = attributeName.lower(); | 272 attributeName = attributeName.lower(); |
269 | 273 |
| 274 AtomicString namespaceURI = determineNamespace(namespacePrefix); |
| 275 if (namespaceURI.isNull()) |
| 276 return nullptr; |
| 277 |
270 QualifiedName qualifiedName = namespacePrefix.isNull() | 278 QualifiedName qualifiedName = namespacePrefix.isNull() |
271 ? QualifiedName(nullAtom, attributeName, nullAtom) | 279 ? QualifiedName(nullAtom, attributeName, nullAtom) |
272 : determineNameInNamespace(namespacePrefix, attributeName); | 280 : QualifiedName(namespacePrefix, attributeName, namespaceURI); |
273 | 281 |
274 OwnPtr<CSSParserSelector> selector = CSSParserSelector::create(); | 282 OwnPtr<CSSParserSelector> selector = CSSParserSelector::create(); |
275 | 283 |
276 if (block.atEnd()) { | 284 if (block.atEnd()) { |
277 selector->setAttribute(qualifiedName, CSSSelector::CaseSensitive); | 285 selector->setAttribute(qualifiedName, CSSSelector::CaseSensitive); |
278 selector->setMatch(CSSSelector::AttributeSet); | 286 selector->setMatch(CSSSelector::AttributeSet); |
279 return selector.release(); | 287 return selector.release(); |
280 } | 288 } |
281 | 289 |
282 selector->setMatch(consumeAttributeMatch(block)); | 290 selector->setMatch(consumeAttributeMatch(block)); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 return true; | 537 return true; |
530 } | 538 } |
531 | 539 |
532 const AtomicString& CSSSelectorParser::defaultNamespace() const | 540 const AtomicString& CSSSelectorParser::defaultNamespace() const |
533 { | 541 { |
534 if (!m_styleSheet) | 542 if (!m_styleSheet) |
535 return starAtom; | 543 return starAtom; |
536 return m_styleSheet->defaultNamespace(); | 544 return m_styleSheet->defaultNamespace(); |
537 } | 545 } |
538 | 546 |
539 QualifiedName CSSSelectorParser::determineNameInNamespace(const AtomicString& pr
efix, const AtomicString& localName) | 547 const AtomicString& CSSSelectorParser::determineNamespace(const AtomicString& pr
efix) |
540 { | 548 { |
541 if (!m_styleSheet) | 549 if (!m_styleSheet) |
542 return QualifiedName(prefix, localName, defaultNamespace()); | 550 return defaultNamespace(); |
543 return QualifiedName(prefix, localName, m_styleSheet->determineNamespace(pre
fix)); | 551 return m_styleSheet->determineNamespace(prefix); |
544 } | 552 } |
545 | 553 |
546 void CSSSelectorParser::prependTypeSelectorIfNeeded(const AtomicString& namespac
ePrefix, const AtomicString& elementName, CSSParserSelector* compoundSelector) | 554 void CSSSelectorParser::prependTypeSelectorIfNeeded(const AtomicString& namespac
ePrefix, const AtomicString& elementName, CSSParserSelector* compoundSelector) |
547 { | 555 { |
548 if (elementName.isNull() && defaultNamespace() == starAtom && !compoundSelec
tor->crossesTreeScopes()) | 556 if (elementName.isNull() && defaultNamespace() == starAtom && !compoundSelec
tor->crossesTreeScopes()) |
549 return; | 557 return; |
550 | 558 |
551 AtomicString determinedElementName = elementName.isNull() ? starAtom : eleme
ntName; | 559 AtomicString determinedElementName = elementName.isNull() ? starAtom : eleme
ntName; |
552 QualifiedName tag = determineNameInNamespace(namespacePrefix, determinedElem
entName); | 560 AtomicString namespaceURI = determineNamespace(namespacePrefix); |
| 561 if (namespaceURI.isNull()) |
| 562 return; |
| 563 QualifiedName tag = QualifiedName(namespacePrefix, determinedElementName, na
mespaceURI); |
553 | 564 |
554 if (compoundSelector->crossesTreeScopes()) | 565 if (compoundSelector->crossesTreeScopes()) |
555 return rewriteSpecifiersWithElementNameForCustomPseudoElement(tag, compo
undSelector, elementName.isNull()); | 566 return rewriteSpecifiersWithElementNameForCustomPseudoElement(tag, compo
undSelector, elementName.isNull()); |
556 | 567 |
557 if (compoundSelector->pseudoType() == CSSSelector::PseudoContent) | 568 if (compoundSelector->pseudoType() == CSSSelector::PseudoContent) |
558 return rewriteSpecifiersWithElementNameForContentPseudoElement(tag, comp
oundSelector, elementName.isNull()); | 569 return rewriteSpecifiersWithElementNameForContentPseudoElement(tag, comp
oundSelector, elementName.isNull()); |
559 | 570 |
560 // *:host never matches, so we can't discard the * otherwise we can't tell t
he | 571 // *:host never matches, so we can't discard the * otherwise we can't tell t
he |
561 // difference between *:host and just :host. | 572 // difference between *:host and just :host. |
562 if (tag == anyQName() && !compoundSelector->hasHostPseudoSelector()) | 573 if (tag == anyQName() && !compoundSelector->hasHostPseudoSelector()) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 compoundSelector->insertTagHistory(CSSSelector::SubSelector, simpleSelec
tor, relation); | 664 compoundSelector->insertTagHistory(CSSSelector::SubSelector, simpleSelec
tor, relation); |
654 return compoundSelector; | 665 return compoundSelector; |
655 } | 666 } |
656 | 667 |
657 // All other simple selectors are added to the end of the compound. | 668 // All other simple selectors are added to the end of the compound. |
658 compoundSelector->appendTagHistory(CSSSelector::SubSelector, simpleSelector)
; | 669 compoundSelector->appendTagHistory(CSSSelector::SubSelector, simpleSelector)
; |
659 return compoundSelector; | 670 return compoundSelector; |
660 } | 671 } |
661 | 672 |
662 } // namespace blink | 673 } // namespace blink |
OLD | NEW |