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/ElementShadow.h" |
| 36 #include "core/dom/shadow/ShadowRoot.h" |
34 | 37 |
35 namespace WebCore { | 38 namespace WebCore { |
36 | 39 |
37 void TreeBoundaryCrossingRules::addRule(StyleRule* rule, size_t selectorIndex, C
ontainerNode* scopingNode, AddRuleFlags addRuleFlags) | 40 void TreeBoundaryCrossingRules::addTreeBoundaryCrossingRules(const RuleSet& rule
s, ContainerNode* scope, CSSStyleSheet* parentStyleSheet) |
38 { | 41 { |
39 if (m_treeBoundaryCrossingRuleSetMap.contains(scopingNode)) { | 42 addRules(rules.treeBoundaryCrossingRules(), scope, parentStyleSheet); |
40 m_treeBoundaryCrossingRuleSetMap.get(scopingNode)->addRule(rule, selecto
rIndex, addRuleFlags); | 43 if (scope && !scope->isDocumentNode()) |
41 } else { | 44 addRules(rules.shadowDistributedRules(), scope, parentStyleSheet); |
42 OwnPtrWillBeRawPtr<RuleSet> ruleSetForScope = RuleSet::create(); | 45 } |
43 ruleSetForScope->addRule(rule, selectorIndex, addRuleFlags); | 46 |
44 m_treeBoundaryCrossingRuleSetMap.add(scopingNode, ruleSetForScope.releas
e()); | 47 void TreeBoundaryCrossingRules::addRules(const WillBeHeapVector<MinimalRuleData>
& rules, ContainerNode* scopingNode, CSSStyleSheet* parentStyleSheet) |
| 48 { |
| 49 if (!m_treeBoundaryCrossingRuleSetMap.contains(scopingNode)) { |
| 50 OwnPtrWillBeRawPtr<CSSStyleSheetRuleSubSet> styleSheetRuleSubSetForScope
= adoptPtr(new CSSStyleSheetRuleSubSet()); |
| 51 m_treeBoundaryCrossingRuleSetMap.add(scopingNode, styleSheetRuleSubSetFo
rScope.release()); |
45 m_scopingNodes.add(scopingNode); | 52 m_scopingNodes.add(scopingNode); |
46 } | 53 } |
| 54 CSSStyleSheetRuleSubSet* ruleSubSet = m_treeBoundaryCrossingRuleSetMap.get(s
copingNode); |
| 55 |
| 56 OwnPtrWillBeRawPtr<RuleSet> ruleSetForScope = RuleSet::create(); |
| 57 for (unsigned i = 0; i < rules.size(); ++i) { |
| 58 const MinimalRuleData& info = rules[i]; |
| 59 ruleSetForScope->addRule(info.m_rule, info.m_selectorIndex, info.m_flags
); |
| 60 } |
| 61 ruleSubSet->append(std::make_pair(parentStyleSheet, ruleSetForScope.release(
))); |
47 } | 62 } |
48 | 63 |
49 void TreeBoundaryCrossingRules::reset(const ContainerNode* scopingNode) | 64 void TreeBoundaryCrossingRules::reset(const ContainerNode* scopingNode) |
50 { | 65 { |
51 m_treeBoundaryCrossingRuleSetMap.remove(scopingNode); | 66 m_treeBoundaryCrossingRuleSetMap.remove(scopingNode); |
52 m_scopingNodes.remove(scopingNode); | 67 m_scopingNodes.remove(scopingNode); |
53 } | 68 } |
54 | 69 |
| 70 void TreeBoundaryCrossingRules::collectFeaturesFromStyleSheetSubSet(TreeBoundary
CrossingRules::CSSStyleSheetRuleSubSet* styleSheetSubSet, RuleFeatureSet& featur
es) |
| 71 { |
| 72 for (TreeBoundaryCrossingRules::CSSStyleSheetRuleSubSet::iterator it = style
SheetSubSet->begin(); it != styleSheetSubSet->end(); ++it) { |
| 73 RuleSet* ruleSet = it->second.get(); |
| 74 features.add(ruleSet->features()); |
| 75 } |
| 76 } |
| 77 |
55 void TreeBoundaryCrossingRules::collectFeaturesTo(RuleFeatureSet& features) | 78 void TreeBoundaryCrossingRules::collectFeaturesTo(RuleFeatureSet& features) |
56 { | 79 { |
57 for (TreeBoundaryCrossingRuleSetMap::iterator::Values it = m_treeBoundaryCro
ssingRuleSetMap.values().begin(); it != m_treeBoundaryCrossingRuleSetMap.values(
).end(); ++it) { | 80 for (TreeBoundaryCrossingRuleSetMap::iterator::Values it = m_treeBoundaryCro
ssingRuleSetMap.values().begin(); it != m_treeBoundaryCrossingRuleSetMap.values(
).end(); ++it) { |
58 RuleSet* ruleSet = it->get(); | 81 CSSStyleSheetRuleSubSet* styleSheetSubSet = it->get(); |
59 features.add(ruleSet->features()); | 82 collectFeaturesFromStyleSheetSubSet(styleSheetSubSet, features); |
60 } | 83 } |
61 } | 84 } |
62 | 85 |
| 86 void TreeBoundaryCrossingRules::collectTreeBoundaryCrossingRules(Element* elemen
t, ElementRuleCollector& collector, bool includeEmptyRules) |
| 87 { |
| 88 if (m_treeBoundaryCrossingRuleSetMap.isEmpty()) |
| 89 return; |
| 90 |
| 91 RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange(); |
| 92 |
| 93 // When comparing rules declared in outer treescopes, outer's rules win. |
| 94 CascadeOrder outerCascadeOrder = size() + size(); |
| 95 // When comparing rules declared in inner treescopes, inner's rules win. |
| 96 CascadeOrder innerCascadeOrder = size(); |
| 97 |
| 98 for (DocumentOrderedList::iterator it = m_scopingNodes.begin(); it != m_scop
ingNodes.end(); ++it) { |
| 99 const ContainerNode* scopingNode = toContainerNode(*it); |
| 100 |
| 101 if (ShadowRoot* shadowRoot = scopingNode->containingShadowRoot()) { |
| 102 if (!shadowRoot->isActiveForStyling()) |
| 103 continue; |
| 104 } |
| 105 |
| 106 TreeBoundaryCrossingRules::CSSStyleSheetRuleSubSet* styleSheetsRuleSubSe
ts = m_treeBoundaryCrossingRuleSetMap.get(scopingNode); |
| 107 unsigned boundaryBehavior = SelectorChecker::ScopeContainsLastMatchedEle
ment; |
| 108 bool isInnerTreeScope = element->treeScope().isInclusiveAncestorOf(scopi
ngNode->treeScope()); |
| 109 |
| 110 // If a given scoping node is a shadow root and a given element is in a
descendant tree of tree hosted by |
| 111 // the scoping node's shadow host, we should use ScopeIsShadowHost. |
| 112 if (scopingNode && scopingNode->isShadowRoot()) { |
| 113 if (element->isInDescendantTreeOf(toShadowRoot(scopingNode)->host())
) |
| 114 boundaryBehavior |= SelectorChecker::ScopeIsShadowHost; |
| 115 scopingNode = toShadowRoot(scopingNode)->host(); |
| 116 } |
| 117 |
| 118 CascadeOrder cascadeOrder = isInnerTreeScope ? innerCascadeOrder : outer
CascadeOrder; |
| 119 for (CSSStyleSheetRuleSubSet::iterator it = styleSheetsRuleSubSets->begi
n(); it != styleSheetsRuleSubSets->end(); ++it) { |
| 120 CSSStyleSheet* parentStyleSheet = it->first; |
| 121 RuleSet* ruleSet = it->second.get(); |
| 122 collector.collectMatchingRules(MatchRequest(ruleSet, includeEmptyRul
es, scopingNode, parentStyleSheet), ruleRange, static_cast<SelectorChecker::Beha
viorAtBoundary>(boundaryBehavior), ignoreCascadeScope, cascadeOrder); |
| 123 } |
| 124 ++innerCascadeOrder; |
| 125 --outerCascadeOrder; |
| 126 } |
| 127 } |
| 128 |
| 129 |
63 } // namespace WebCore | 130 } // namespace WebCore |
OLD | NEW |