OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r
ights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r
ights reserved. |
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
orchmobile.com/) |
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "core/css/RuleFeature.h" | 30 #include "core/css/RuleFeature.h" |
31 | 31 |
32 #include "HTMLNames.h" | 32 #include "HTMLNames.h" |
33 #include "core/css/CSSSelector.h" | 33 #include "core/css/CSSSelector.h" |
34 #include "core/css/CSSSelectorList.h" | 34 #include "core/css/CSSSelectorList.h" |
35 | 35 |
36 namespace WebCore { | 36 namespace WebCore { |
37 | 37 |
38 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector* selector) | 38 void RuleFeatureSet::collectFeaturesFromSelector(const CSSSelector* selector, Ha
shSet<AtomicString>* classesInRulesArg) |
39 { | 39 { |
40 if (selector->m_match == CSSSelector::Id) | 40 if (selector->m_match == CSSSelector::Id) |
41 idsInRules.add(selector->value()); | 41 idsInRules.add(selector->value()); |
42 else if (selector->m_match == CSSSelector::Class) | 42 else if (selector->m_match == CSSSelector::Class) { |
43 classesInRules.add(selector->value()); | 43 classesInRules.add(selector->value()); |
44 else if (selector->isAttributeSelector()) | 44 if (classesInRulesArg) |
| 45 classesInRulesArg->add(selector->value()); |
| 46 } else if (selector->isAttributeSelector()) |
45 attrsInRules.add(selector->attribute().localName()); | 47 attrsInRules.add(selector->attribute().localName()); |
46 switch (selector->pseudoType()) { | 48 switch (selector->pseudoType()) { |
47 case CSSSelector::PseudoFirstLine: | 49 case CSSSelector::PseudoFirstLine: |
48 m_usesFirstLineRules = true; | 50 m_usesFirstLineRules = true; |
49 break; | 51 break; |
50 break; | 52 break; |
51 case CSSSelector::PseudoHost: | 53 case CSSSelector::PseudoHost: |
52 collectFeaturesFromSelectorList(selector->selectorList()); | 54 collectFeaturesFromSelectorList(selector->selectorList(), classesInRules
Arg); |
53 break; | 55 break; |
54 default: | 56 default: |
55 break; | 57 break; |
56 } | 58 } |
57 } | 59 } |
58 | 60 |
59 void RuleFeatureSet::collectFeaturesFromSelectorList(const CSSSelectorList* sele
ctorList) | 61 void RuleFeatureSet::collectFeaturesFromSelectorList(const CSSSelectorList* sele
ctorList, HashSet<AtomicString>* classesInRulesArg) |
60 { | 62 { |
61 if (!selectorList) | 63 if (!selectorList) |
62 return; | 64 return; |
63 | 65 |
64 for (const CSSSelector* selector = selectorList->first(); selector; selector
= CSSSelectorList::next(selector)) { | 66 for (const CSSSelector* selector = selectorList->first(); selector; selector
= CSSSelectorList::next(selector)) { |
65 for (const CSSSelector* subSelector = selector; subSelector; subSelector
= subSelector->tagHistory()) | 67 for (const CSSSelector* subSelector = selector; subSelector; subSelector
= subSelector->tagHistory()) |
66 collectFeaturesFromSelector(subSelector); | 68 collectFeaturesFromSelector(subSelector, classesInRulesArg); |
67 } | 69 } |
68 } | 70 } |
69 | 71 |
70 void RuleFeatureSet::add(const RuleFeatureSet& other) | 72 void RuleFeatureSet::add(const RuleFeatureSet& other) |
71 { | 73 { |
| 74 if (RuleSetAnalyzer* otherAnalyzer = other.getRuleSetAnalyzer()) |
| 75 ensureRuleSetAnalyzer()->combine(*otherAnalyzer); |
| 76 |
72 HashSet<AtomicString>::const_iterator end = other.idsInRules.end(); | 77 HashSet<AtomicString>::const_iterator end = other.idsInRules.end(); |
73 for (HashSet<AtomicString>::const_iterator it = other.idsInRules.begin(); it
!= end; ++it) | 78 for (HashSet<AtomicString>::const_iterator it = other.idsInRules.begin(); it
!= end; ++it) |
74 idsInRules.add(*it); | 79 idsInRules.add(*it); |
75 end = other.classesInRules.end(); | 80 end = other.classesInRules.end(); |
76 for (HashSet<AtomicString>::const_iterator it = other.classesInRules.begin()
; it != end; ++it) | 81 for (HashSet<AtomicString>::const_iterator it = other.classesInRules.begin()
; it != end; ++it) |
77 classesInRules.add(*it); | 82 classesInRules.add(*it); |
78 end = other.attrsInRules.end(); | 83 end = other.attrsInRules.end(); |
79 for (HashSet<AtomicString>::const_iterator it = other.attrsInRules.begin();
it != end; ++it) | 84 for (HashSet<AtomicString>::const_iterator it = other.attrsInRules.begin();
it != end; ++it) |
80 attrsInRules.add(*it); | 85 attrsInRules.add(*it); |
81 siblingRules.append(other.siblingRules); | 86 siblingRules.append(other.siblingRules); |
82 uncommonAttributeRules.append(other.uncommonAttributeRules); | 87 uncommonAttributeRules.append(other.uncommonAttributeRules); |
83 m_usesFirstLineRules = m_usesFirstLineRules || other.m_usesFirstLineRules; | 88 m_usesFirstLineRules = m_usesFirstLineRules || other.m_usesFirstLineRules; |
84 m_maxDirectAdjacentSelectors = std::max(m_maxDirectAdjacentSelectors, other.
maxDirectAdjacentSelectors()); | 89 m_maxDirectAdjacentSelectors = std::max(m_maxDirectAdjacentSelectors, other.
maxDirectAdjacentSelectors()); |
85 } | 90 } |
86 | 91 |
87 void RuleFeatureSet::clear() | 92 void RuleFeatureSet::clear() |
88 { | 93 { |
89 idsInRules.clear(); | 94 idsInRules.clear(); |
90 classesInRules.clear(); | 95 classesInRules.clear(); |
91 attrsInRules.clear(); | 96 attrsInRules.clear(); |
92 siblingRules.clear(); | 97 siblingRules.clear(); |
93 uncommonAttributeRules.clear(); | 98 uncommonAttributeRules.clear(); |
94 m_usesFirstLineRules = false; | 99 m_usesFirstLineRules = false; |
95 m_maxDirectAdjacentSelectors = 0; | 100 m_maxDirectAdjacentSelectors = 0; |
96 } | 101 } |
97 | 102 |
| 103 RuleSetAnalyzer* RuleFeatureSet::getRuleSetAnalyzer() const |
| 104 { |
| 105 return ruleSetAnalyzer.get(); |
| 106 } |
| 107 |
| 108 RuleSetAnalyzer* RuleFeatureSet::ensureRuleSetAnalyzer() |
| 109 { |
| 110 if (!ruleSetAnalyzer) |
| 111 ruleSetAnalyzer = RuleSetAnalyzer::create(); |
| 112 return ruleSetAnalyzer.get(); |
| 113 } |
| 114 |
98 } // namespace WebCore | 115 } // namespace WebCore |
OLD | NEW |