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

Side by Side Diff: Source/core/css/resolver/StyleResolver.cpp

Issue 418833002: Remove all members in ScopedStyleTree for preparing class removal (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix destructor Created 6 years, 4 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, 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 , m_styleSharingDepth(0) 136 , m_styleSharingDepth(0)
137 , m_styleResolverStatsSequence(0) 137 , m_styleResolverStatsSequence(0)
138 , m_accessCount(0) 138 , m_accessCount(0)
139 { 139 {
140 FrameView* view = document.view(); 140 FrameView* view = document.view();
141 if (view) 141 if (view)
142 m_medium = adoptPtr(new MediaQueryEvaluator(&view->frame())); 142 m_medium = adoptPtr(new MediaQueryEvaluator(&view->frame()));
143 else 143 else
144 m_medium = adoptPtr(new MediaQueryEvaluator("all")); 144 m_medium = adoptPtr(new MediaQueryEvaluator("all"));
145 145
146 m_styleTree.ensureScopedStyleResolver(document); 146 m_scopedStyleResolvers.add(&document.ensureScopedStyleResolver());
147 147
148 initWatchedSelectorRules(CSSSelectorWatch::from(document).watchedCallbackSel ectors()); 148 initWatchedSelectorRules(CSSSelectorWatch::from(document).watchedCallbackSel ectors());
149 149
150 #if ENABLE(SVG_FONTS) 150 #if ENABLE(SVG_FONTS)
151 if (document.svgExtensions()) { 151 if (document.svgExtensions()) {
152 const WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> >& svgFon tFaceElements = document.svgExtensions()->svgFontFaceElements(); 152 const WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> >& svgFon tFaceElements = document.svgExtensions()->svgFontFaceElements();
153 WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> >::const_iterat or end = svgFontFaceElements.end(); 153 WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> >::const_iterat or end = svgFontFaceElements.end();
154 for (WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> >::const_i terator it = svgFontFaceElements.begin(); it != end; ++it) 154 for (WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> >::const_i terator it = svgFontFaceElements.begin(); it != end; ++it)
155 addFontFaceRule(&document, document.styleEngine()->fontSelector(), ( *it)->fontFaceRule()); 155 addFontFaceRule(&document, document.styleEngine()->fontSelector(), ( *it)->fontFaceRule());
156 } 156 }
(...skipping 26 matching lines...) Expand all
183 { 183 {
184 ASSERT(cssSheet); 184 ASSERT(cssSheet);
185 ASSERT(!cssSheet->disabled()); 185 ASSERT(!cssSheet->disabled());
186 if (cssSheet->mediaQueries() && !m_medium->eval(cssSheet->mediaQueries(), &m _viewportDependentMediaQueryResults)) 186 if (cssSheet->mediaQueries() && !m_medium->eval(cssSheet->mediaQueries(), &m _viewportDependentMediaQueryResults))
187 return; 187 return;
188 188
189 ContainerNode* scopingNode = ScopedStyleResolver::scopingNodeFor(document(), cssSheet); 189 ContainerNode* scopingNode = ScopedStyleResolver::scopingNodeFor(document(), cssSheet);
190 if (!scopingNode) 190 if (!scopingNode)
191 return; 191 return;
192 192
193 ScopedStyleResolver* resolver = m_styleTree.ensureScopedStyleResolver(*scopi ngNode); 193 ScopedStyleResolver* resolver = &scopingNode->treeScope().ensureScopedStyleR esolver();
194 m_scopedStyleResolvers.add(resolver);
194 ASSERT(resolver); 195 ASSERT(resolver);
195 resolver->addRulesFromSheet(cssSheet, *m_medium, this); 196 resolver->addRulesFromSheet(cssSheet, *m_medium, this);
196 } 197 }
197 198
198 void StyleResolver::appendPendingAuthorStyleSheets() 199 void StyleResolver::appendPendingAuthorStyleSheets()
199 { 200 {
200 for (WillBeHeapListHashSet<RawPtrWillBeMember<CSSStyleSheet>, 16>::iterator it = m_pendingStyleSheets.begin(); it != m_pendingStyleSheets.end(); ++it) 201 for (WillBeHeapListHashSet<RawPtrWillBeMember<CSSStyleSheet>, 16>::iterator it = m_pendingStyleSheets.begin(); it != m_pendingStyleSheets.end(); ++it)
201 appendCSSStyleSheet(*it); 202 appendCSSStyleSheet(*it);
202 203
203 m_pendingStyleSheets.clear(); 204 m_pendingStyleSheets.clear();
(...skipping 26 matching lines...) Expand all
230 // Need to recreate RuleFeatureSet. 231 // Need to recreate RuleFeatureSet.
231 m_features.clear(); 232 m_features.clear();
232 m_siblingRuleSet.clear(); 233 m_siblingRuleSet.clear();
233 m_uncommonAttributeRuleSet.clear(); 234 m_uncommonAttributeRuleSet.clear();
234 m_needCollectFeatures = true; 235 m_needCollectFeatures = true;
235 } 236 }
236 237
237 void StyleResolver::processScopedRules(const RuleSet& authorRules, CSSStyleSheet * parentStyleSheet, ContainerNode& scope) 238 void StyleResolver::processScopedRules(const RuleSet& authorRules, CSSStyleSheet * parentStyleSheet, ContainerNode& scope)
238 { 239 {
239 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes> > keyframesRul es = authorRules.keyframesRules(); 240 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleKeyframes> > keyframesRul es = authorRules.keyframesRules();
241 ScopedStyleResolver* resolver = &scope.treeScope().ensureScopedStyleResolver ();
242 m_scopedStyleResolvers.add(resolver);
240 for (unsigned i = 0; i < keyframesRules.size(); ++i) 243 for (unsigned i = 0; i < keyframesRules.size(); ++i)
241 m_styleTree.ensureScopedStyleResolver(scope)->addKeyframeStyle(keyframes Rules[i]); 244 resolver->addKeyframeStyle(keyframesRules[i]);
242 245
243 m_treeBoundaryCrossingRules.addTreeBoundaryCrossingRules(authorRules, scope, parentStyleSheet); 246 m_treeBoundaryCrossingRules.addTreeBoundaryCrossingRules(authorRules, scope, parentStyleSheet);
244 247
245 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo r the moment. 248 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo r the moment.
246 if (scope.isDocumentNode()) { 249 if (scope.isDocumentNode()) {
247 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace> > fontFaceR ules = authorRules.fontFaceRules(); 250 const WillBeHeapVector<RawPtrWillBeMember<StyleRuleFontFace> > fontFaceR ules = authorRules.fontFaceRules();
248 for (unsigned i = 0; i < fontFaceRules.size(); ++i) 251 for (unsigned i = 0; i < fontFaceRules.size(); ++i)
249 addFontFaceRule(&m_document, document().styleEngine()->fontSelector( ), fontFaceRules[i]); 252 addFontFaceRule(&m_document, document().styleEngine()->fontSelector( ), fontFaceRules[i]);
250 if (fontFaceRules.size()) 253 if (fontFaceRules.size())
251 invalidateMatchedPropertiesCache(); 254 invalidateMatchedPropertiesCache();
252 } 255 }
253 } 256 }
254 257
255 void StyleResolver::resetAuthorStyle(const ContainerNode* scopingNode) 258 void StyleResolver::resetAuthorStyle(TreeScope& treeScope)
256 { 259 {
257 ScopedStyleResolver* resolver = scopingNode ? scopingNode->treeScope().scope dStyleResolver() : m_document.scopedStyleResolver(); 260 ScopedStyleResolver* resolver = treeScope.scopedStyleResolver();
258 if (!resolver) 261 if (!resolver)
259 return; 262 return;
260 263
261 m_treeBoundaryCrossingRules.reset(scopingNode); 264 m_treeBoundaryCrossingRules.reset(&treeScope.rootNode());
262 265
263 resolver->resetAuthorStyle(); 266 resolver->resetAuthorStyle();
264 resetRuleFeatures(); 267 resetRuleFeatures();
265 if (!scopingNode) 268 if (treeScope.rootNode().isDocumentNode())
266 return; 269 return;
267 270
268 m_styleTree.remove(scopingNode); 271 // resolver is going to be freed below.
272 m_scopedStyleResolvers.remove(resolver);
273 treeScope.clearScopedStyleResolver();
269 } 274 }
270 275
271 static PassOwnPtrWillBeRawPtr<RuleSet> makeRuleSet(const WillBeHeapVector<RuleFe ature>& rules) 276 static PassOwnPtrWillBeRawPtr<RuleSet> makeRuleSet(const WillBeHeapVector<RuleFe ature>& rules)
272 { 277 {
273 size_t size = rules.size(); 278 size_t size = rules.size();
274 if (!size) 279 if (!size)
275 return nullptr; 280 return nullptr;
276 OwnPtrWillBeRawPtr<RuleSet> ruleSet = RuleSet::create(); 281 OwnPtrWillBeRawPtr<RuleSet> ruleSet = RuleSet::create();
277 for (size_t i = 0; i < size; ++i) 282 for (size_t i = 0; i < size; ++i)
278 ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, rules[i].hasDocu mentSecurityOrigin ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState); 283 ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, rules[i].hasDocu mentSecurityOrigin ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState);
(...skipping 14 matching lines...) Expand all
293 m_features.add(defaultStyleSheets.defaultViewSourceStyle()->features()); 298 m_features.add(defaultStyleSheets.defaultViewSourceStyle()->features());
294 299
295 if (document().isTransitionDocument()) 300 if (document().isTransitionDocument())
296 m_features.add(defaultStyleSheets.defaultTransitionStyle()->features()); 301 m_features.add(defaultStyleSheets.defaultTransitionStyle()->features());
297 302
298 if (m_watchedSelectorsRules) 303 if (m_watchedSelectorsRules)
299 m_features.add(m_watchedSelectorsRules->features()); 304 m_features.add(m_watchedSelectorsRules->features());
300 305
301 m_treeBoundaryCrossingRules.collectFeaturesTo(m_features); 306 m_treeBoundaryCrossingRules.collectFeaturesTo(m_features);
302 307
303 m_styleTree.collectFeaturesTo(m_features); 308 HashSet<const StyleSheetContents*> visitedSharedStyleSheetContents;
309 for (WillBeHeapHashSet<RawPtrWillBeMember<const ScopedStyleResolver> >::iter ator it = m_scopedStyleResolvers.begin(); it != m_scopedStyleResolvers.end(); ++ it)
310 (*it)->collectFeaturesTo(m_features, visitedSharedStyleSheetContents);
304 311
305 m_siblingRuleSet = makeRuleSet(m_features.siblingRules); 312 m_siblingRuleSet = makeRuleSet(m_features.siblingRules);
306 m_uncommonAttributeRuleSet = makeRuleSet(m_features.uncommonAttributeRules); 313 m_uncommonAttributeRuleSet = makeRuleSet(m_features.uncommonAttributeRules);
307 m_needCollectFeatures = false; 314 m_needCollectFeatures = false;
308 } 315 }
309 316
310 bool StyleResolver::hasRulesForId(const AtomicString& id) const 317 bool StyleResolver::hasRulesForId(const AtomicString& id) const
311 { 318 {
312 return m_features.hasSelectorForId(id); 319 return m_features.hasSelectorForId(id);
313 } 320 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 const ContainerNode* parentsParent = parent.parentOrShadowHostElement(); 355 const ContainerNode* parentsParent = parent.parentOrShadowHostElement();
349 356
350 // We are not always invoked consistently. For example, script execution can cause us to enter 357 // We are not always invoked consistently. For example, script execution can cause us to enter
351 // style recalc in the middle of tree building. We may also be invoked from somewhere within the tree. 358 // style recalc in the middle of tree building. We may also be invoked from somewhere within the tree.
352 // Reset the stack in this case, or if we see a new root element. 359 // Reset the stack in this case, or if we see a new root element.
353 // Otherwise just push the new parent. 360 // Otherwise just push the new parent.
354 if (!parentsParent || m_selectorFilter.parentStackIsEmpty()) 361 if (!parentsParent || m_selectorFilter.parentStackIsEmpty())
355 m_selectorFilter.setupParentStack(parent); 362 m_selectorFilter.setupParentStack(parent);
356 else 363 else
357 m_selectorFilter.pushParent(parent); 364 m_selectorFilter.pushParent(parent);
358
359 // Note: We mustn't skip ShadowRoot nodes for the scope stack.
360 m_styleTree.pushStyleCache(parent, parent.parentOrShadowHostNode());
361 } 365 }
362 366
363 void StyleResolver::popParentElement(Element& parent) 367 void StyleResolver::popParentElement(Element& parent)
364 { 368 {
365 // Note that we may get invoked for some random elements in some wacky cases during style resolve. 369 // Note that we may get invoked for some random elements in some wacky cases during style resolve.
366 // Pause maintaining the stack in this case. 370 // Pause maintaining the stack in this case.
367 if (m_selectorFilter.parentStackIsConsistent(&parent)) 371 if (m_selectorFilter.parentStackIsConsistent(&parent))
368 m_selectorFilter.popParent(); 372 m_selectorFilter.popParent();
369
370 m_styleTree.popStyleCache(parent);
371 }
372
373 void StyleResolver::pushParentShadowRoot(const ShadowRoot& shadowRoot)
374 {
375 ASSERT(shadowRoot.host());
376 m_styleTree.pushStyleCache(shadowRoot, shadowRoot.host());
377 }
378
379 void StyleResolver::popParentShadowRoot(const ShadowRoot& shadowRoot)
380 {
381 ASSERT(shadowRoot.host());
382 m_styleTree.popStyleCache(shadowRoot);
383 } 373 }
384 374
385 StyleResolver::~StyleResolver() 375 StyleResolver::~StyleResolver()
386 { 376 {
387 } 377 }
388 378
389 static inline bool applyAuthorStylesOf(const Element* element) 379 static inline bool applyAuthorStylesOf(const Element* element)
390 { 380 {
391 return element->treeScope().applyAuthorStyles(); 381 return element->treeScope().applyAuthorStyles();
392 } 382 }
(...skipping 19 matching lines...) Expand all
412 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec tor, includeEmptyRules); 402 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, collec tor, includeEmptyRules);
413 collector.sortAndTransferMatchedRules(); 403 collector.sortAndTransferMatchedRules();
414 } 404 }
415 405
416 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col lector, bool includeEmptyRules) 406 void StyleResolver::matchAuthorRules(Element* element, ElementRuleCollector& col lector, bool includeEmptyRules)
417 { 407 {
418 collector.clearMatchedRules(); 408 collector.clearMatchedRules();
419 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult(). matchedProperties.size() - 1; 409 collector.matchedResult().ranges.lastAuthorRule = collector.matchedResult(). matchedProperties.size() - 1;
420 410
421 bool applyAuthorStyles = applyAuthorStylesOf(element); 411 bool applyAuthorStyles = applyAuthorStylesOf(element);
422 if (m_styleTree.hasOnlyScopedResolverForDocument()) { 412 if (m_scopedStyleResolvers.size() == 1) {
423 m_document.scopedStyleResolver()->collectMatchingAuthorRules(collector, includeEmptyRules, applyAuthorStyles, ignoreCascadeScope); 413 m_document.scopedStyleResolver()->collectMatchingAuthorRules(collector, includeEmptyRules, applyAuthorStyles, ignoreCascadeScope);
424 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, co llector, includeEmptyRules); 414 m_treeBoundaryCrossingRules.collectTreeBoundaryCrossingRules(element, co llector, includeEmptyRules);
425 collector.sortAndTransferMatchedRules(); 415 collector.sortAndTransferMatchedRules();
426 return; 416 return;
427 } 417 }
428 418
429 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers; 419 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolvers;
430 m_styleTree.resolveScopedStyles(element, resolvers); 420 m_styleTree.resolveScopedStyles(element, resolvers);
431 421
432 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolversInShad owTree; 422 WillBeHeapVector<RawPtrWillBeMember<ScopedStyleResolver>, 8> resolversInShad owTree;
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 visitor->trace(m_matchedPropertiesCache); 1556 visitor->trace(m_matchedPropertiesCache);
1567 visitor->trace(m_viewportDependentMediaQueryResults); 1557 visitor->trace(m_viewportDependentMediaQueryResults);
1568 visitor->trace(m_viewportStyleResolver); 1558 visitor->trace(m_viewportStyleResolver);
1569 visitor->trace(m_features); 1559 visitor->trace(m_features);
1570 visitor->trace(m_siblingRuleSet); 1560 visitor->trace(m_siblingRuleSet);
1571 visitor->trace(m_uncommonAttributeRuleSet); 1561 visitor->trace(m_uncommonAttributeRuleSet);
1572 visitor->trace(m_watchedSelectorsRules); 1562 visitor->trace(m_watchedSelectorsRules);
1573 visitor->trace(m_treeBoundaryCrossingRules); 1563 visitor->trace(m_treeBoundaryCrossingRules);
1574 visitor->trace(m_pendingStyleSheets); 1564 visitor->trace(m_pendingStyleSheets);
1575 visitor->trace(m_styleTree); 1565 visitor->trace(m_styleTree);
1566 visitor->trace(m_scopedStyleResolvers);
1576 #endif 1567 #endif
1577 } 1568 }
1578 1569
1579 } // namespace blink 1570 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698