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

Side by Side Diff: sky/engine/core/css/ElementRuleCollector.cpp

Issue 772363002: Remove code to collect rules when matching. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « sky/engine/core/css/ElementRuleCollector.h ('k') | sky/engine/core/css/SelectorChecker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 ElementRuleCollector::~ElementRuleCollector() 55 ElementRuleCollector::~ElementRuleCollector()
56 { 56 {
57 } 57 }
58 58
59 MatchResult& ElementRuleCollector::matchedResult() 59 MatchResult& ElementRuleCollector::matchedResult()
60 { 60 {
61 return m_result; 61 return m_result;
62 } 62 }
63 63
64 PassRefPtr<StyleRuleList> ElementRuleCollector::matchedStyleRuleList()
65 {
66 ASSERT(m_mode == SelectorChecker::CollectingStyleRules);
67 return m_styleRuleList.release();
68 }
69
70 PassRefPtr<CSSRuleList> ElementRuleCollector::matchedCSSRuleList()
71 {
72 ASSERT(m_mode == SelectorChecker::CollectingCSSRules);
73 return m_cssRuleList.release();
74 }
75
76 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, CascadeSc ope cascadeScope, CascadeOrder cascadeOrder, unsigned styleSheetIndex, const CSS StyleSheet* parentStyleSheet) 64 inline void ElementRuleCollector::addMatchedRule(const RuleData* rule, CascadeSc ope cascadeScope, CascadeOrder cascadeOrder, unsigned styleSheetIndex, const CSS StyleSheet* parentStyleSheet)
77 { 65 {
78 if (!m_matchedRules) 66 if (!m_matchedRules)
79 m_matchedRules = adoptPtr(new Vector<MatchedRule, 32>); 67 m_matchedRules = adoptPtr(new Vector<MatchedRule, 32>);
80 m_matchedRules->append(MatchedRule(rule, cascadeScope, cascadeOrder, styleSh eetIndex, parentStyleSheet)); 68 m_matchedRules->append(MatchedRule(rule, cascadeScope, cascadeOrder, styleSh eetIndex, parentStyleSheet));
81 } 69 }
82 70
83 void ElementRuleCollector::clearMatchedRules() 71 void ElementRuleCollector::clearMatchedRules()
84 { 72 {
85 if (!m_matchedRules) 73 if (!m_matchedRules)
86 return; 74 return;
87 m_matchedRules->clear(); 75 m_matchedRules->clear();
88 } 76 }
89 77
90 inline StyleRuleList* ElementRuleCollector::ensureStyleRuleList()
91 {
92 if (!m_styleRuleList)
93 m_styleRuleList = StyleRuleList::create();
94 return m_styleRuleList.get();
95 }
96
97 inline StaticCSSRuleList* ElementRuleCollector::ensureRuleList()
98 {
99 if (!m_cssRuleList)
100 m_cssRuleList = StaticCSSRuleList::create();
101 return m_cssRuleList.get();
102 }
103
104 void ElementRuleCollector::addElementStyleProperties(const StylePropertySet* pro pertySet, bool isCacheable) 78 void ElementRuleCollector::addElementStyleProperties(const StylePropertySet* pro pertySet, bool isCacheable)
105 { 79 {
106 if (!propertySet) 80 if (!propertySet)
107 return; 81 return;
108 m_result.ranges.lastAuthorRule = m_result.matchedProperties.size(); 82 m_result.ranges.lastAuthorRule = m_result.matchedProperties.size();
109 if (m_result.ranges.firstAuthorRule == -1) 83 if (m_result.ranges.firstAuthorRule == -1)
110 m_result.ranges.firstAuthorRule = m_result.ranges.lastAuthorRule; 84 m_result.ranges.firstAuthorRule = m_result.ranges.lastAuthorRule;
111 m_result.addMatchedProperties(propertySet); 85 m_result.addMatchedProperties(propertySet);
112 if (!isCacheable) 86 if (!isCacheable)
113 m_result.isCacheable = false; 87 m_result.isCacheable = false;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS tyleResolution()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleR ange); 127 collectMatchingRulesForList(matchRequest.ruleSet->idRules(element.idForS tyleResolution()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleR ange);
154 if (element.isStyledElement() && element.hasClass()) { 128 if (element.isStyledElement() && element.hasClass()) {
155 for (size_t i = 0; i < element.classNames().size(); ++i) 129 for (size_t i = 0; i < element.classNames().size(); ++i)
156 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element .classNames()[i]), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleR ange); 130 collectMatchingRulesForList(matchRequest.ruleSet->classRules(element .classNames()[i]), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleR ange);
157 } 131 }
158 132
159 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName ()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange); 133 collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element.localName ()), contextFlags, cascadeScope, cascadeOrder, matchRequest, ruleRange);
160 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), contextF lags, cascadeScope, cascadeOrder, matchRequest, ruleRange); 134 collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), contextF lags, cascadeScope, cascadeOrder, matchRequest, ruleRange);
161 } 135 }
162 136
163 CSSRuleList* ElementRuleCollector::nestedRuleList(CSSRule* rule)
164 {
165 switch (rule->type()) {
166 case CSSRule::MEDIA_RULE:
167 return toCSSMediaRule(rule)->cssRules();
168 case CSSRule::KEYFRAMES_RULE:
169 return toCSSKeyframesRule(rule)->cssRules();
170 case CSSRule::SUPPORTS_RULE:
171 return toCSSSupportsRule(rule)->cssRules();
172 default:
173 return 0;
174 }
175 }
176
177 template<class CSSRuleCollection>
178 CSSRule* ElementRuleCollector::findStyleRule(CSSRuleCollection* cssRules, StyleR ule* styleRule)
179 {
180 if (!cssRules)
181 return 0;
182 CSSRule* result = 0;
183 for (unsigned i = 0; i < cssRules->length() && !result; ++i) {
184 CSSRule* cssRule = cssRules->item(i);
185 CSSRule::Type cssRuleType = cssRule->type();
186 if (cssRuleType == CSSRule::STYLE_RULE) {
187 CSSStyleRule* cssStyleRule = toCSSStyleRule(cssRule);
188 if (cssStyleRule->styleRule() == styleRule)
189 result = cssRule;
190 } else {
191 result = findStyleRule(nestedRuleList(cssRule), styleRule);
192 }
193 }
194 return result;
195 }
196
197 void ElementRuleCollector::appendCSSOMWrapperForRule(CSSStyleSheet* parentStyleS heet, StyleRule* rule)
198 {
199 // |parentStyleSheet| is 0 if and only if the |rule| is coming from User Age nt. In this case,
200 // it is safe to create CSSOM wrappers without parentStyleSheets as they wil l be used only
201 // by inspector which will not try to edit them.
202 RefPtr<CSSRule> cssRule = nullptr;
203 if (parentStyleSheet)
204 cssRule = findStyleRule(parentStyleSheet, rule);
205 else
206 cssRule = rule->createCSSOMWrapper();
207 ASSERT(!parentStyleSheet || cssRule);
208 ensureRuleList()->rules().append(cssRule);
209 }
210
211 void ElementRuleCollector::sortAndTransferMatchedRules() 137 void ElementRuleCollector::sortAndTransferMatchedRules()
212 { 138 {
213 if (!m_matchedRules || m_matchedRules->isEmpty()) 139 if (!m_matchedRules || m_matchedRules->isEmpty())
214 return; 140 return;
215 141
216 sortMatchedRules(); 142 sortMatchedRules();
217 143
218 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules; 144 Vector<MatchedRule, 32>& matchedRules = *m_matchedRules;
219 if (m_mode == SelectorChecker::CollectingStyleRules) {
220 for (unsigned i = 0; i < matchedRules.size(); ++i)
221 ensureStyleRuleList()->m_list.append(matchedRules[i].ruleData()->rul e());
222 return;
223 }
224
225 if (m_mode == SelectorChecker::CollectingCSSRules) {
226 for (unsigned i = 0; i < matchedRules.size(); ++i)
227 appendCSSOMWrapperForRule(const_cast<CSSStyleSheet*>(matchedRules[i] .parentStyleSheet()), matchedRules[i].ruleData()->rule());
228 return;
229 }
230 145
231 // Now transfer the set of matched rules over to our list of declarations. 146 // Now transfer the set of matched rules over to our list of declarations.
232 for (unsigned i = 0; i < matchedRules.size(); i++) { 147 for (unsigned i = 0; i < matchedRules.size(); i++) {
233 // FIXME: Matching should not modify the style directly. 148 // FIXME: Matching should not modify the style directly.
234 const RuleData* ruleData = matchedRules[i].ruleData(); 149 const RuleData* ruleData = matchedRules[i].ruleData();
235 if (m_style && ruleData->containsAttributeSelector()) 150 if (m_style && ruleData->containsAttributeSelector())
236 m_style->setUnique(); 151 m_style->setUnique();
237 m_result.addMatchedProperties(&ruleData->rule()->properties()); 152 m_result.addMatchedProperties(&ruleData->rule()->properties());
238 } 153 }
239 } 154 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // information about "scope". 206 // information about "scope".
292 int firstRuleIndex = -1, lastRuleIndex = -1; 207 int firstRuleIndex = -1, lastRuleIndex = -1;
293 RuleRange ruleRange(firstRuleIndex, lastRuleIndex); 208 RuleRange ruleRange(firstRuleIndex, lastRuleIndex);
294 // FIXME: Verify whether it's ok to ignore CascadeScope here. 209 // FIXME: Verify whether it's ok to ignore CascadeScope here.
295 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Defa ultBehavior); 210 collectMatchingRules(MatchRequest(ruleSet), ruleRange, SelectorChecker::Defa ultBehavior);
296 211
297 return m_matchedRules && !m_matchedRules->isEmpty(); 212 return m_matchedRules && !m_matchedRules->isEmpty();
298 } 213 }
299 214
300 } // namespace blink 215 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/css/ElementRuleCollector.h ('k') | sky/engine/core/css/SelectorChecker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698