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 11 matching lines...) Expand all Loading... | |
22 * | 22 * |
23 * You should have received a copy of the GNU Library General Public License | 23 * You should have received a copy of the GNU Library General Public License |
24 * along with this library; see the file COPYING.LIB. If not, write to | 24 * along with this library; see the file COPYING.LIB. If not, write to |
25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 25 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 * Boston, MA 02110-1301, USA. | 26 * Boston, MA 02110-1301, USA. |
27 */ | 27 */ |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 #include "core/css/TreeBoundaryCrossingRules.h" | 30 #include "core/css/TreeBoundaryCrossingRules.h" |
31 | 31 |
32 #include "core/css/ElementRuleCollector.h" | |
32 #include "core/css/RuleFeature.h" | 33 #include "core/css/RuleFeature.h" |
33 #include "core/dom/StyleEngine.h" | 34 #include "core/dom/StyleEngine.h" |
35 #include "core/dom/shadow/ShadowRoot.h" | |
34 | 36 |
35 namespace WebCore { | 37 namespace WebCore { |
36 | 38 |
37 void TreeBoundaryCrossingRules::addRule(StyleRule* rule, size_t selectorIndex, C ontainerNode* scopingNode, AddRuleFlags addRuleFlags) | 39 static void addRules(RuleSet* ruleSet, const WillBeHeapVector<MinimalRuleData>& rules) |
38 { | 40 { |
39 if (m_treeBoundaryCrossingRuleSetMap.contains(scopingNode)) { | 41 for (unsigned i = 0; i < rules.size(); ++i) { |
40 m_treeBoundaryCrossingRuleSetMap.get(scopingNode)->addRule(rule, selecto rIndex, addRuleFlags); | 42 const MinimalRuleData& info = rules[i]; |
41 } else { | 43 ruleSet->addRule(info.m_rule, info.m_selectorIndex, info.m_flags); |
42 OwnPtrWillBeRawPtr<RuleSet> ruleSetForScope = RuleSet::create(); | 44 } |
43 ruleSetForScope->addRule(rule, selectorIndex, addRuleFlags); | 45 } |
44 m_treeBoundaryCrossingRuleSetMap.add(scopingNode, ruleSetForScope.releas e()); | 46 |
47 void TreeBoundaryCrossingRules::addTreeBoundaryCrossingRules(const RuleSet& auth orRules, ContainerNode* scopingNode, CSSStyleSheet* parentStyleSheet) | |
48 { | |
49 OwnPtrWillBeRawPtr<RuleSet> ruleSetForScope = RuleSet::create(); | |
50 addRules(ruleSetForScope.get(), authorRules.treeBoundaryCrossingRules()); | |
51 if (scopingNode && !scopingNode->isDocumentNode()) | |
52 addRules(ruleSetForScope.get(), authorRules.shadowDistributedRules()); | |
53 if (!ruleSetForScope->ruleCount()) | |
54 return; | |
esprehn
2014/04/03 09:57:17
How did the old code deal with this being empty? I
lushnikov
2014/04/03 13:53:13
The old code here was "addRule" method which was c
| |
55 | |
56 if (!m_treeBoundaryCrossingRuleSetMap.contains(scopingNode)) { | |
esprehn
2014/04/03 09:57:17
Can scopingNode actually be null? You check it abo
lushnikov
2014/04/03 13:53:13
My bad; it cannot be null. Removed checking for nu
| |
57 m_treeBoundaryCrossingRuleSetMap.add(scopingNode, adoptPtr(new CSSStyleS heetRuleSubSet())); | |
45 m_scopingNodes.add(scopingNode); | 58 m_scopingNodes.add(scopingNode); |
46 } | 59 } |
60 CSSStyleSheetRuleSubSet* ruleSubSet = m_treeBoundaryCrossingRuleSetMap.get(s copingNode); | |
61 ruleSubSet->append(std::make_pair(parentStyleSheet, ruleSetForScope.release( ))); | |
62 } | |
63 | |
64 void TreeBoundaryCrossingRules::collectTreeBoundaryCrossingRules(Element* elemen t, ElementRuleCollector& collector, bool includeEmptyRules) | |
65 { | |
66 if (m_treeBoundaryCrossingRuleSetMap.isEmpty()) | |
67 return; | |
68 | |
69 RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); | |
70 | |
71 // When comparing rules declared in outer treescopes, outer's rules win. | |
72 CascadeOrder outerCascadeOrder = size() + size(); | |
73 // When comparing rules declared in inner treescopes, inner's rules win. | |
74 CascadeOrder innerCascadeOrder = size(); | |
75 | |
76 for (DocumentOrderedList::iterator it = m_scopingNodes.begin(); it != m_scop ingNodes.end(); ++it) { | |
77 const ContainerNode* scopingNode = toContainerNode(*it); | |
78 CSSStyleSheetRuleSubSet* ruleSubSet = m_treeBoundaryCrossingRuleSetMap.g et(scopingNode); | |
79 unsigned boundaryBehavior = SelectorChecker::ScopeContainsLastMatchedEle ment; | |
80 bool isInnerTreeScope = element->treeScope().isInclusiveAncestorOf(scopi ngNode->treeScope()); | |
81 | |
82 // If a given scoping node is a shadow root and a given element is in a descendant tree of tree hosted by | |
83 // the scoping node's shadow host, we should use ScopeIsShadowHost. | |
84 if (scopingNode && scopingNode->isShadowRoot()) { | |
85 if (element->isInDescendantTreeOf(toShadowRoot(scopingNode)->host()) ) | |
86 boundaryBehavior |= SelectorChecker::ScopeIsShadowHost; | |
87 scopingNode = toShadowRoot(scopingNode)->host(); | |
88 } | |
89 | |
90 CascadeOrder cascadeOrder = isInnerTreeScope ? innerCascadeOrder : outer CascadeOrder; | |
91 for (CSSStyleSheetRuleSubSet::iterator it = ruleSubSet->begin(); it != r uleSubSet->end(); ++it) { | |
92 CSSStyleSheet* parentStyleSheet = it->first; | |
93 RuleSet* ruleSet = it->second.get(); | |
94 collector.collectMatchingRules(MatchRequest(ruleSet, includeEmptyRul es, scopingNode, parentStyleSheet), ruleRange, static_cast<SelectorChecker::Beha viorAtBoundary>(boundaryBehavior), ignoreCascadeScope, cascadeOrder); | |
95 } | |
96 ++innerCascadeOrder; | |
97 --outerCascadeOrder; | |
98 } | |
47 } | 99 } |
48 | 100 |
49 void TreeBoundaryCrossingRules::reset(const ContainerNode* scopingNode) | 101 void TreeBoundaryCrossingRules::reset(const ContainerNode* scopingNode) |
50 { | 102 { |
51 m_treeBoundaryCrossingRuleSetMap.remove(scopingNode); | 103 m_treeBoundaryCrossingRuleSetMap.remove(scopingNode); |
52 m_scopingNodes.remove(scopingNode); | 104 m_scopingNodes.remove(scopingNode); |
53 } | 105 } |
54 | 106 |
107 void TreeBoundaryCrossingRules::collectFeaturesFromRuleSubSet(CSSStyleSheetRuleS ubSet* ruleSubSet, RuleFeatureSet& features) | |
108 { | |
109 for (CSSStyleSheetRuleSubSet::iterator it = ruleSubSet->begin(); it != ruleS ubSet->end(); ++it) { | |
110 RuleSet* ruleSet = it->second.get(); | |
111 features.add(ruleSet->features()); | |
esprehn
2014/04/03 09:57:17
I'd just do it->second->features() and make this o
lushnikov
2014/04/03 13:53:13
Done.
| |
112 } | |
113 } | |
114 | |
55 void TreeBoundaryCrossingRules::collectFeaturesTo(RuleFeatureSet& features) | 115 void TreeBoundaryCrossingRules::collectFeaturesTo(RuleFeatureSet& features) |
56 { | 116 { |
57 for (TreeBoundaryCrossingRuleSetMap::iterator::Values it = m_treeBoundaryCro ssingRuleSetMap.values().begin(); it != m_treeBoundaryCrossingRuleSetMap.values( ).end(); ++it) { | 117 for (TreeBoundaryCrossingRuleSetMap::iterator::Values it = m_treeBoundaryCro ssingRuleSetMap.values().begin(); it != m_treeBoundaryCrossingRuleSetMap.values( ).end(); ++it) { |
58 RuleSet* ruleSet = it->get(); | 118 CSSStyleSheetRuleSubSet* ruleSubSet = it->get(); |
59 features.add(ruleSet->features()); | 119 collectFeaturesFromRuleSubSet(ruleSubSet, features); |
esprehn
2014/04/03 09:57:17
Same, this can be one line and remove the braces
lushnikov
2014/04/03 13:53:13
Done.
| |
60 } | 120 } |
61 } | 121 } |
62 | 122 |
63 } // namespace WebCore | 123 } // namespace WebCore |
OLD | NEW |