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

Side by Side Diff: sky/engine/core/css/resolver/StyleResolver.cpp

Issue 837883002: Store features in the ScopedStyleResoolver. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Simpler even. Created 5 years, 11 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
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 styleSheet->parseString(cssText); 119 styleSheet->parseString(cssText);
120 120
121 ruleSet = RuleSet::create(); 121 ruleSet = RuleSet::create();
122 ruleSet->addRulesFromSheet(styleSheet.get()); 122 ruleSet->addRulesFromSheet(styleSheet.get());
123 123
124 return *ruleSet; 124 return *ruleSet;
125 } 125 }
126 126
127 StyleResolver::StyleResolver(Document& document) 127 StyleResolver::StyleResolver(Document& document)
128 : m_document(document) 128 : m_document(document)
129 , m_needCollectFeatures(false)
130 , m_printMediaType(false) 129 , m_printMediaType(false)
131 , m_styleResourceLoader(document.fetcher()) 130 , m_styleResourceLoader(document.fetcher())
132 , m_styleSharingDepth(0) 131 , m_styleSharingDepth(0)
133 , m_styleResolverStatsSequence(0) 132 , m_styleResolverStatsSequence(0)
134 , m_accessCount(0) 133 , m_accessCount(0)
135 { 134 {
136 FrameView* view = document.view(); 135 FrameView* view = document.view();
137 if (view) { 136 if (view) {
138 m_medium = adoptPtr(new MediaQueryEvaluator(&view->frame())); 137 m_medium = adoptPtr(new MediaQueryEvaluator(&view->frame()));
139 m_printMediaType = equalIgnoringCase(view->mediaType(), MediaTypeNames:: print); 138 m_printMediaType = equalIgnoringCase(view->mediaType(), MediaTypeNames:: print);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 { 182 {
184 // This handles sheets added to the end of the stylesheet list only. In othe r cases the style resolver 183 // This handles sheets added to the end of the stylesheet list only. In othe r cases the style resolver
185 // needs to be reconstructed. To handle insertions too the rule order number s would need to be updated. 184 // needs to be reconstructed. To handle insertions too the rule order number s would need to be updated.
186 unsigned size = styleSheets.size(); 185 unsigned size = styleSheets.size();
187 for (unsigned i = 0; i < size; ++i) 186 for (unsigned i = 0; i < size; ++i)
188 appendCSSStyleSheet(styleSheets[i].get()); 187 appendCSSStyleSheet(styleSheets[i].get());
189 } 188 }
190 189
191 void StyleResolver::finishAppendAuthorStyleSheets() 190 void StyleResolver::finishAppendAuthorStyleSheets()
192 { 191 {
193 collectFeatures();
194
195 if (document().renderView() && document().renderView()->style()) 192 if (document().renderView() && document().renderView()->style())
196 document().renderView()->style()->font().update(document().styleEngine() ->fontSelector()); 193 document().renderView()->style()->font().update(document().styleEngine() ->fontSelector());
197 } 194 }
198 195
199 void StyleResolver::resetRuleFeatures()
200 {
201 // Need to recreate RuleFeatureSet.
202 m_features.clear();
203 m_needCollectFeatures = true;
204 }
205
206 void StyleResolver::processScopedRules(const RuleSet& authorRules, CSSStyleSheet * parentStyleSheet, unsigned parentIndex, ContainerNode& scope) 196 void StyleResolver::processScopedRules(const RuleSet& authorRules, CSSStyleSheet * parentStyleSheet, unsigned parentIndex, ContainerNode& scope)
207 { 197 {
208 const Vector<RawPtr<StyleRuleKeyframes> > keyframesRules = authorRules.keyfr amesRules(); 198 const Vector<RawPtr<StyleRuleKeyframes> > keyframesRules = authorRules.keyfr amesRules();
209 ScopedStyleResolver* resolver = &scope.treeScope().scopedStyleResolver(); 199 ScopedStyleResolver* resolver = &scope.treeScope().scopedStyleResolver();
210 for (unsigned i = 0; i < keyframesRules.size(); ++i) 200 for (unsigned i = 0; i < keyframesRules.size(); ++i)
211 resolver->addKeyframeStyle(keyframesRules[i]); 201 resolver->addKeyframeStyle(keyframesRules[i]);
212 202
213 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo r the moment. 203 // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets fo r the moment.
214 if (scope.isDocumentNode()) { 204 if (scope.isDocumentNode()) {
215 const Vector<RawPtr<StyleRuleFontFace> > fontFaceRules = authorRules.fon tFaceRules(); 205 const Vector<RawPtr<StyleRuleFontFace> > fontFaceRules = authorRules.fon tFaceRules();
216 for (unsigned i = 0; i < fontFaceRules.size(); ++i) 206 for (unsigned i = 0; i < fontFaceRules.size(); ++i)
217 addFontFaceRule(m_document, document().styleEngine()->fontSelector() , fontFaceRules[i]); 207 addFontFaceRule(m_document, document().styleEngine()->fontSelector() , fontFaceRules[i]);
218 if (fontFaceRules.size()) 208 if (fontFaceRules.size())
219 invalidateMatchedPropertiesCache(); 209 invalidateMatchedPropertiesCache();
220 } 210 }
221 } 211 }
222 212
223 void StyleResolver::resetAuthorStyle(TreeScope& treeScope)
224 {
225 treeScope.scopedStyleResolver().resetAuthorStyle();
226 resetRuleFeatures();
227 }
228
229 void StyleResolver::collectFeatures()
230 {
231 m_features.clear();
232 m_features.add(defaultStyles().features());
233
234 document().styleEngine()->collectScopedStyleFeaturesTo(m_features);
235
236 m_needCollectFeatures = false;
237 }
238
239 bool StyleResolver::hasRulesForId(const AtomicString& id) const
240 {
241 return m_features.hasSelectorForId(id);
242 }
243
244 void StyleResolver::addToStyleSharingList(Element& element) 213 void StyleResolver::addToStyleSharingList(Element& element)
245 { 214 {
246 // Never add elements to the style sharing list if we're not in a recalcStyl e, 215 // Never add elements to the style sharing list if we're not in a recalcStyl e,
247 // otherwise we could leave stale pointers in there. 216 // otherwise we could leave stale pointers in there.
248 if (!document().inStyleRecalc()) 217 if (!document().inStyleRecalc())
249 return; 218 return;
250 ASSERT(element.supportsStyleSharing()); 219 ASSERT(element.supportsStyleSharing());
251 INCREMENT_STYLE_STATS_COUNTER(*this, sharedStyleCandidates); 220 INCREMENT_STYLE_STATS_COUNTER(*this, sharedStyleCandidates);
252 StyleSharingList& list = styleSharingList(); 221 StyleSharingList& list = styleSharingList();
253 if (list.size() >= styleSharingListSize) 222 if (list.size() >= styleSharingListSize)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources()); 357 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources());
389 document().styleEngine()->fontSelector()->fontLoader()->loadPendingFonts(); 358 document().styleEngine()->fontSelector()->fontLoader()->loadPendingFonts();
390 } 359 }
391 360
392 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS tyle* defaultParent, StyleSharingBehavior sharingBehavior, 361 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS tyle* defaultParent, StyleSharingBehavior sharingBehavior,
393 RuleMatchingBehavior matchingBehavior) 362 RuleMatchingBehavior matchingBehavior)
394 { 363 {
395 ASSERT(document().frame()); 364 ASSERT(document().frame());
396 ASSERT(document().settings()); 365 ASSERT(document().settings());
397 ASSERT(!hasPendingAuthorStyleSheets()); 366 ASSERT(!hasPendingAuthorStyleSheets());
398 ASSERT(!m_needCollectFeatures);
399 367
400 // Once an element has a renderer, we don't try to destroy it, since otherwi se the renderer 368 // Once an element has a renderer, we don't try to destroy it, since otherwi se the renderer
401 // will vanish if a style recalc happens during loading. 369 // will vanish if a style recalc happens during loading.
402 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() & & !element->renderer()) { 370 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() & & !element->renderer()) {
403 if (!s_styleNotYetAvailable) { 371 if (!s_styleNotYetAvailable) {
404 s_styleNotYetAvailable = RenderStyle::create().leakRef(); 372 s_styleNotYetAvailable = RenderStyle::create().leakRef();
405 s_styleNotYetAvailable->setDisplay(NONE); 373 s_styleNotYetAvailable->setDisplay(NONE);
406 s_styleNotYetAvailable->font().update(document().styleEngine()->font Selector()); 374 s_styleNotYetAvailable->font().update(document().styleEngine()->font Selector());
407 } 375 }
408 376
409 document().setHasNodesWithPlaceholderStyle(); 377 document().setHasNodesWithPlaceholderStyle();
410 return s_styleNotYetAvailable; 378 return s_styleNotYetAvailable;
411 } 379 }
412 380
413 didAccess(); 381 didAccess();
414 382
415 if (element == document().documentElement()) 383 if (element == document().documentElement())
416 document().setDirectionSetOnDocumentElement(false); 384 document().setDirectionSetOnDocumentElement(false);
417 StyleResolverState state(document(), element, defaultParent); 385 StyleResolverState state(document(), element, defaultParent);
418 386
419 if (sharingBehavior == AllowStyleSharing && state.parentStyle()) { 387 if (sharingBehavior == AllowStyleSharing && state.parentStyle()) {
420 SharedStyleFinder styleFinder(state.elementContext(), m_features, *this) ; 388 SharedStyleFinder styleFinder(state.elementContext(), *this);
421 if (RefPtr<RenderStyle> sharedStyle = styleFinder.findSharedStyle()) 389 if (RefPtr<RenderStyle> sharedStyle = styleFinder.findSharedStyle())
422 return sharedStyle.release(); 390 return sharedStyle.release();
423 } 391 }
424 392
425 if (state.parentStyle()) { 393 if (state.parentStyle()) {
426 state.setStyle(RenderStyle::create()); 394 state.setStyle(RenderStyle::create());
427 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); 395 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
428 } else { 396 } else {
429 state.setStyle(defaultStyleForElement()); 397 state.setStyle(defaultStyleForElement());
430 state.setParentStyle(RenderStyle::clone(state.style())); 398 state.setParentStyle(RenderStyle::clone(state.style()));
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 bool StyleResolver::mediaQueryAffectedByViewportChange() const 879 bool StyleResolver::mediaQueryAffectedByViewportChange() const
912 { 880 {
913 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) { 881 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) {
914 if (m_medium->eval(m_viewportDependentMediaQueryResults[i]->expression() ) != m_viewportDependentMediaQueryResults[i]->result()) 882 if (m_medium->eval(m_viewportDependentMediaQueryResults[i]->expression() ) != m_viewportDependentMediaQueryResults[i]->result())
915 return true; 883 return true;
916 } 884 }
917 return false; 885 return false;
918 } 886 }
919 887
920 } // namespace blink 888 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698