Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: Source/core/css/TreeBoundaryCrossingRules.cpp

Issue 931143002: Start moving tree-boundary-crossing rules to ScopedStyleResolver. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 12 matching lines...) Expand all
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/ElementRuleCollector.h"
33 #include "core/css/RuleFeature.h" 33 #include "core/css/resolver/ScopedStyleResolver.h"
34 #include "core/dom/StyleEngine.h"
35 #include "core/dom/shadow/ShadowRoot.h"
36 34
37 namespace blink { 35 namespace blink {
38 36
39 static void addRules(RuleSet* ruleSet, const WillBeHeapVector<MinimalRuleData>& rules)
40 {
41 for (unsigned i = 0; i < rules.size(); ++i) {
42 const MinimalRuleData& info = rules[i];
43 ruleSet->addRule(info.m_rule, info.m_selectorIndex, info.m_flags);
44 }
45 }
46
47 void TreeBoundaryCrossingRules::addTreeBoundaryCrossingRules(const RuleSet& auth orRules, CSSStyleSheet* parentStyleSheet, unsigned parentIndex, ContainerNode& s copingNode)
48 {
49 if (authorRules.treeBoundaryCrossingRules().isEmpty() && (scopingNode.isDocu mentNode() || authorRules.shadowDistributedRules().isEmpty()))
50 return;
51 OwnPtrWillBeRawPtr<RuleSet> ruleSetForScope = RuleSet::create();
52 addRules(ruleSetForScope.get(), authorRules.treeBoundaryCrossingRules());
53 if (!scopingNode.isDocumentNode())
54 addRules(ruleSetForScope.get(), authorRules.shadowDistributedRules());
55
56 if (!m_treeBoundaryCrossingRuleSetMap.contains(&scopingNode)) {
57 m_treeBoundaryCrossingRuleSetMap.add(&scopingNode, adoptPtrWillBeNoop(ne w CSSStyleSheetRuleSubSet()));
58 m_scopingNodes.add(&scopingNode);
59 }
60 CSSStyleSheetRuleSubSet* ruleSubSet = m_treeBoundaryCrossingRuleSetMap.get(& scopingNode);
61 ruleSubSet->append(RuleSubSet::create(parentStyleSheet, parentIndex, ruleSet ForScope.release()));
62 }
63
64 void TreeBoundaryCrossingRules::collectTreeBoundaryCrossingRules(Element* elemen t, ElementRuleCollector& collector, bool includeEmptyRules) 37 void TreeBoundaryCrossingRules::collectTreeBoundaryCrossingRules(Element* elemen t, ElementRuleCollector& collector, bool includeEmptyRules)
65 { 38 {
66 if (m_treeBoundaryCrossingRuleSetMap.isEmpty()) 39 if (m_scopingNodes.isEmpty())
67 return; 40 return;
68 41
69 RuleRange ruleRange = collector.matchedResult().ranges.authorRuleRange();
70
71 // When comparing rules declared in outer treescopes, outer's rules win. 42 // When comparing rules declared in outer treescopes, outer's rules win.
72 CascadeOrder outerCascadeOrder = size() + size(); 43 CascadeOrder outerCascadeOrder = size() + size();
73 // When comparing rules declared in inner treescopes, inner's rules win. 44 // When comparing rules declared in inner treescopes, inner's rules win.
74 CascadeOrder innerCascadeOrder = size(); 45 CascadeOrder innerCascadeOrder = size();
75 46
76 ASSERT(!collector.scopeContainsLastMatchedElement()); 47 ASSERT(!collector.scopeContainsLastMatchedElement());
77 collector.setScopeContainsLastMatchedElement(true); 48 collector.setScopeContainsLastMatchedElement(true);
49
78 for (const auto& scope : m_scopingNodes) { 50 for (const auto& scope : m_scopingNodes) {
79 const ContainerNode* scopingNode = toContainerNode(scope);
80 CSSStyleSheetRuleSubSet* ruleSubSet = m_treeBoundaryCrossingRuleSetMap.g et(scopingNode);
81 bool isInnerTreeScope = element->treeScope().isInclusiveAncestorOf(scopi ngNode->treeScope());
82 51
52 bool isInnerTreeScope = element->treeScope().isInclusiveAncestorOf(scope ->treeScope());
83 CascadeOrder cascadeOrder = isInnerTreeScope ? innerCascadeOrder : outer CascadeOrder; 53 CascadeOrder cascadeOrder = isInnerTreeScope ? innerCascadeOrder : outer CascadeOrder;
84 for (const auto& rules : *ruleSubSet) { 54
85 MatchRequest request(rules->ruleSet.get(), includeEmptyRules, scopin gNode, rules->parentStyleSheet, rules->parentIndex); 55 scope->treeScope().scopedStyleResolver()->collectMatchingTreeBoundaryCro ssingRules(collector, includeEmptyRules, cascadeOrder);
86 collector.collectMatchingRules(request, ruleRange, cascadeOrder, tru e); 56
87 }
88 ++innerCascadeOrder; 57 ++innerCascadeOrder;
89 --outerCascadeOrder; 58 --outerCascadeOrder;
90 } 59 }
60
91 collector.setScopeContainsLastMatchedElement(false); 61 collector.setScopeContainsLastMatchedElement(false);
92 } 62 }
93 63
94 void TreeBoundaryCrossingRules::reset(const ContainerNode* scopingNode) 64 void TreeBoundaryCrossingRules::addScope(ContainerNode& scopingNode)
95 { 65 {
96 m_treeBoundaryCrossingRuleSetMap.remove(scopingNode); 66 m_scopingNodes.add(&scopingNode);
97 m_scopingNodes.remove(scopingNode);
98 } 67 }
99 68
100 void TreeBoundaryCrossingRules::collectFeaturesFromRuleSubSet(CSSStyleSheetRuleS ubSet* ruleSubSet, RuleFeatureSet& features) 69 void TreeBoundaryCrossingRules::removeScope(const ContainerNode& scopingNode)
101 { 70 {
102 for (const auto& rules : *ruleSubSet) 71 m_scopingNodes.remove(&scopingNode);
103 features.add(rules->ruleSet->features());
104 }
105
106 void TreeBoundaryCrossingRules::collectFeaturesTo(RuleFeatureSet& features)
107 {
108 for (const auto& value : m_treeBoundaryCrossingRuleSetMap.values())
109 collectFeaturesFromRuleSubSet(value.get(), features);
110 } 72 }
111 73
112 void TreeBoundaryCrossingRules::trace(Visitor* visitor) 74 void TreeBoundaryCrossingRules::trace(Visitor* visitor)
113 { 75 {
114 #if ENABLE(OILPAN) 76 #if ENABLE(OILPAN)
115 visitor->trace(m_treeBoundaryCrossingRuleSetMap);
116 visitor->trace(m_scopingNodes); 77 visitor->trace(m_scopingNodes);
117 #endif 78 #endif
118 } 79 }
119 80
120 void TreeBoundaryCrossingRules::RuleSubSet::trace(Visitor* visitor)
121 {
122 visitor->trace(ruleSet);
123 }
124
125 } // namespace blink 81 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/TreeBoundaryCrossingRules.h ('k') | Source/core/css/resolver/ScopedStyleResolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698