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" |
11 #include "platform/RuntimeEnabledFeatures.h" | 11 #include "platform/RuntimeEnabledFeatures.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
| 15 static void recordSelectorStats(const CSSParserContext& context, const CSSSelect
orList& selectorList) |
| 16 { |
| 17 if (!context.useCounter()) |
| 18 return; |
| 19 |
| 20 for (const CSSSelector* selector = selectorList.first(); selector; selector
= CSSSelectorList::next(*selector)) { |
| 21 for (const CSSSelector* current = selector; current ; current = current-
>tagHistory()) { |
| 22 UseCounter::Feature feature = UseCounter::NumberOfFeatures; |
| 23 switch (current->pseudoType()) { |
| 24 case CSSSelector::PseudoUnresolved: |
| 25 feature = UseCounter::CSSSelectorPseudoUnresolved; |
| 26 break; |
| 27 case CSSSelector::PseudoShadow: |
| 28 feature = UseCounter::CSSSelectorPseudoShadow; |
| 29 break; |
| 30 case CSSSelector::PseudoContent: |
| 31 feature = UseCounter::CSSSelectorPseudoContent; |
| 32 break; |
| 33 case CSSSelector::PseudoHost: |
| 34 feature = UseCounter::CSSSelectorPseudoHost; |
| 35 break; |
| 36 case CSSSelector::PseudoHostContext: |
| 37 feature = UseCounter::CSSSelectorPseudoHostContext; |
| 38 break; |
| 39 case CSSSelector::PseudoFullScreenDocument: |
| 40 feature = UseCounter::CSSSelectorPseudoFullScreenDocument; |
| 41 break; |
| 42 case CSSSelector::PseudoFullScreenAncestor: |
| 43 feature = UseCounter::CSSSelectorPseudoFullScreenAncestor; |
| 44 break; |
| 45 case CSSSelector::PseudoFullScreen: |
| 46 feature = UseCounter::CSSSelectorPseudoFullScreen; |
| 47 break; |
| 48 default: |
| 49 break; |
| 50 } |
| 51 if (feature != UseCounter::NumberOfFeatures) |
| 52 context.useCounter()->count(feature); |
| 53 if (current->relation() == CSSSelector::ShadowDeep) |
| 54 context.useCounter()->count(UseCounter::CSSDeepCombinator); |
| 55 if (current->selectorList()) |
| 56 recordSelectorStats(context, *current->selectorList()); |
| 57 } |
| 58 } |
| 59 } |
| 60 |
15 void CSSSelectorParser::parseSelector(CSSParserTokenRange range, const CSSParser
Context& context, const AtomicString& defaultNamespace, StyleSheetContents* styl
eSheet, CSSSelectorList& output) | 61 void CSSSelectorParser::parseSelector(CSSParserTokenRange range, const CSSParser
Context& context, const AtomicString& defaultNamespace, StyleSheetContents* styl
eSheet, CSSSelectorList& output) |
16 { | 62 { |
17 CSSSelectorParser parser(context, defaultNamespace, styleSheet); | 63 CSSSelectorParser parser(context, defaultNamespace, styleSheet); |
18 range.consumeWhitespace(); | 64 range.consumeWhitespace(); |
19 CSSSelectorList result; | 65 CSSSelectorList result; |
20 parser.consumeComplexSelectorList(range, result); | 66 parser.consumeComplexSelectorList(range, result); |
21 if (range.atEnd()) { | 67 if (range.atEnd()) { |
22 output.adopt(result); | 68 output.adopt(result); |
23 recordSelectorStats(context, output); | 69 recordSelectorStats(context, output); |
24 } | 70 } |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 relation = CSSSelector::ShadowPseudo; | 677 relation = CSSSelector::ShadowPseudo; |
632 compoundSelector->insertTagHistory(CSSSelector::SubSelector, simpleSelec
tor, relation); | 678 compoundSelector->insertTagHistory(CSSSelector::SubSelector, simpleSelec
tor, relation); |
633 return compoundSelector; | 679 return compoundSelector; |
634 } | 680 } |
635 | 681 |
636 // All other simple selectors are added to the end of the compound. | 682 // All other simple selectors are added to the end of the compound. |
637 compoundSelector->appendTagHistory(CSSSelector::SubSelector, simpleSelector)
; | 683 compoundSelector->appendTagHistory(CSSSelector::SubSelector, simpleSelector)
; |
638 return compoundSelector; | 684 return compoundSelector; |
639 } | 685 } |
640 | 686 |
641 void CSSSelectorParser::recordSelectorStats(const CSSParserContext& context, con
st CSSSelectorList& selectorList) | |
642 { | |
643 if (!context.useCounter()) | |
644 return; | |
645 | |
646 for (const CSSSelector* selector = selectorList.first(); selector; selector
= CSSSelectorList::next(*selector)) { | |
647 for (const CSSSelector* current = selector; current ; current = current-
>tagHistory()) { | |
648 UseCounter::Feature feature = UseCounter::NumberOfFeatures; | |
649 switch (current->pseudoType()) { | |
650 case CSSSelector::PseudoUnresolved: | |
651 feature = UseCounter::CSSSelectorPseudoUnresolved; | |
652 break; | |
653 case CSSSelector::PseudoShadow: | |
654 feature = UseCounter::CSSSelectorPseudoShadow; | |
655 break; | |
656 case CSSSelector::PseudoContent: | |
657 feature = UseCounter::CSSSelectorPseudoContent; | |
658 break; | |
659 case CSSSelector::PseudoHost: | |
660 feature = UseCounter::CSSSelectorPseudoHost; | |
661 break; | |
662 case CSSSelector::PseudoHostContext: | |
663 feature = UseCounter::CSSSelectorPseudoHostContext; | |
664 break; | |
665 case CSSSelector::PseudoFullScreenDocument: | |
666 feature = UseCounter::CSSSelectorPseudoFullScreenDocument; | |
667 break; | |
668 case CSSSelector::PseudoFullScreenAncestor: | |
669 feature = UseCounter::CSSSelectorPseudoFullScreenAncestor; | |
670 break; | |
671 case CSSSelector::PseudoFullScreen: | |
672 feature = UseCounter::CSSSelectorPseudoFullScreen; | |
673 break; | |
674 default: | |
675 break; | |
676 } | |
677 if (feature != UseCounter::NumberOfFeatures) | |
678 context.useCounter()->count(feature); | |
679 if (current->relation() == CSSSelector::ShadowDeep) | |
680 context.useCounter()->count(UseCounter::CSSDeepCombinator); | |
681 if (current->selectorList()) | |
682 recordSelectorStats(context, *current->selectorList()); | |
683 } | |
684 } | |
685 } | |
686 | |
687 } // namespace blink | 687 } // namespace blink |
OLD | NEW |