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