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

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

Issue 20560008: Don't assume so easily that RenderStyle data can be shared. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 5 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
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | no next file » | 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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 598
599 { 599 {
600 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, state.style(), m_inspectorCSSOMWrappers); 600 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, state.style(), m_inspectorCSSOMWrappers);
601 collector.setRegionForStyling(regionForStyling); 601 collector.setRegionForStyling(regionForStyling);
602 602
603 if (matchingBehavior == MatchOnlyUserAgentRules) 603 if (matchingBehavior == MatchOnlyUserAgentRules)
604 matchUARules(collector); 604 matchUARules(collector);
605 else 605 else
606 matchAllRules(state, collector, m_matchAuthorAndUserStyles, matching Behavior != MatchAllRulesExcludingSMIL); 606 matchAllRules(state, collector, m_matchAuthorAndUserStyles, matching Behavior != MatchAllRulesExcludingSMIL);
607 607
608 applyMatchedProperties(state, collector.matchedResult(), element); 608 applyMatchedProperties(state, collector.matchedResult());
609 } 609 }
610 { 610 {
611 StyleAdjuster adjuster(state.cachedUAStyle(), m_document->inQuirksMode() ); 611 StyleAdjuster adjuster(state.cachedUAStyle(), m_document->inQuirksMode() );
612 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), element); 612 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), element);
613 } 613 }
614 document()->didAccessStyleResolver(); 614 document()->didAccessStyleResolver();
615 615
616 // FIXME: Shouldn't this be on RenderBody::styleDidChange? 616 // FIXME: Shouldn't this be on RenderBody::styleDidChange?
617 if (element->hasTagName(bodyTag)) 617 if (element->hasTagName(bodyTag))
618 document()->textLinkColors().setTextColor(state.style()->visitedDependen tColor(CSSPropertyColor)); 618 document()->textLinkColors().setTextColor(state.style()->visitedDependen tColor(CSSPropertyColor));
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 if (m_matchAuthorAndUserStyles) { 793 if (m_matchAuthorAndUserStyles) {
794 matchUserRules(collector, false); 794 matchUserRules(collector, false);
795 matchAuthorRules(state.element(), collector, false); 795 matchAuthorRules(state.element(), collector, false);
796 } 796 }
797 797
798 if (collector.matchedResult().matchedProperties.isEmpty()) 798 if (collector.matchedResult().matchedProperties.isEmpty())
799 return 0; 799 return 0;
800 800
801 state.style()->setStyleType(pseudoStyleRequest.pseudoId); 801 state.style()->setStyleType(pseudoStyleRequest.pseudoId);
802 802
803 applyMatchedProperties(state, collector.matchedResult(), e); 803 applyMatchedProperties(state, collector.matchedResult());
804 } 804 }
805 { 805 {
806 StyleAdjuster adjuster(state.cachedUAStyle(), m_document->inQuirksMode() ); 806 StyleAdjuster adjuster(state.cachedUAStyle(), m_document->inQuirksMode() );
807 // FIXME: Passing 0 as the Element* introduces a lot of complexity 807 // FIXME: Passing 0 as the Element* introduces a lot of complexity
808 // in the adjustRenderStyle code. 808 // in the adjustRenderStyle code.
809 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), 0); 809 adjuster.adjustRenderStyle(state.style(), state.parentStyle(), 0);
810 } 810 }
811 811
812 // Start loading resources referenced by this style. 812 // Start loading resources referenced by this style.
813 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources()); 813 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources());
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 static unsigned computeMatchedPropertiesHash(const MatchedProperties* properties , unsigned size) 1181 static unsigned computeMatchedPropertiesHash(const MatchedProperties* properties , unsigned size)
1182 { 1182 {
1183 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size ); 1183 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size );
1184 } 1184 }
1185 1185
1186 void StyleResolver::invalidateMatchedPropertiesCache() 1186 void StyleResolver::invalidateMatchedPropertiesCache()
1187 { 1187 {
1188 m_matchedPropertiesCache.clear(); 1188 m_matchedPropertiesCache.clear();
1189 } 1189 }
1190 1190
1191 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult, const Element* element) 1191 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult)
1192 { 1192 {
1193 const Element* element = state.element();
1193 ASSERT(element); 1194 ASSERT(element);
1194 STYLE_STATS_ADD_MATCHED_PROPERTIES_SEARCH(); 1195 STYLE_STATS_ADD_MATCHED_PROPERTIES_SEARCH();
1195 1196
1196 unsigned cacheHash = matchResult.isCacheable ? computeMatchedPropertiesHash( matchResult.matchedProperties.data(), matchResult.matchedProperties.size()) : 0; 1197 unsigned cacheHash = matchResult.isCacheable ? computeMatchedPropertiesHash( matchResult.matchedProperties.data(), matchResult.matchedProperties.size()) : 0;
1197 bool applyInheritedOnly = false; 1198 bool applyInheritedOnly = false;
1198 const CachedMatchedProperties* cachedMatchedProperties = 0; 1199 const CachedMatchedProperties* cachedMatchedProperties = 0;
1199 1200
1200 if (cacheHash && (cachedMatchedProperties = m_matchedPropertiesCache.find(ca cheHash, state, matchResult))) { 1201 if (cacheHash && (cachedMatchedProperties = m_matchedPropertiesCache.find(ca cheHash, state, matchResult))
1202 && MatchedPropertiesCache::isCacheable(element, state.style(), state.par entStyle())) {
ojan 2013/07/28 17:42:31 Not a big deal, but it'd be nice if we saved the i
1201 STYLE_STATS_ADD_MATCHED_PROPERTIES_HIT(); 1203 STYLE_STATS_ADD_MATCHED_PROPERTIES_HIT();
1202 // We can build up the style by copying non-inherited properties from an earlier style object built using the same exact 1204 // We can build up the style by copying non-inherited properties from an earlier style object built using the same exact
1203 // style declarations. We then only need to apply the inherited properti es, if any, as their values can depend on the 1205 // style declarations. We then only need to apply the inherited properti es, if any, as their values can depend on the
1204 // element context. This is fast and saves memory by reusing the style d ata structures. 1206 // element context. This is fast and saves memory by reusing the style d ata structures.
1205 state.style()->copyNonInheritedFrom(cachedMatchedProperties->renderStyle .get()); 1207 state.style()->copyNonInheritedFrom(cachedMatchedProperties->renderStyle .get());
1206 if (state.parentStyle()->inheritedDataShared(cachedMatchedProperties->pa rentRenderStyle.get()) && !isAtShadowBoundary(element)) { 1208 if (state.parentStyle()->inheritedDataShared(cachedMatchedProperties->pa rentRenderStyle.get()) && !isAtShadowBoundary(element)) {
1207 STYLE_STATS_ADD_MATCHED_PROPERTIES_HIT_SHARED_INHERITED(); 1209 STYLE_STATS_ADD_MATCHED_PROPERTIES_HIT_SHARED_INHERITED();
1208 1210
1209 EInsideLink linkStatus = state.style()->insideLink(); 1211 EInsideLink linkStatus = state.style()->insideLink();
1210 // If the cache item parent style has identical inherited properties to the current parent style then the 1212 // If the cache item parent style has identical inherited properties to the current parent style then the
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 1281
1280 ASSERT(!state.fontBuilder().fontDirty()); 1282 ASSERT(!state.fontBuilder().fontDirty());
1281 1283
1282 #ifdef STYLE_STATS 1284 #ifdef STYLE_STATS
1283 if (!cachedMatchedProperties) 1285 if (!cachedMatchedProperties)
1284 STYLE_STATS_ADD_MATCHED_PROPERTIES_TO_CACHE(); 1286 STYLE_STATS_ADD_MATCHED_PROPERTIES_TO_CACHE();
1285 #endif 1287 #endif
1286 1288
1287 if (cachedMatchedProperties || !cacheHash) 1289 if (cachedMatchedProperties || !cacheHash)
1288 return; 1290 return;
1289 if (!MatchedPropertiesCache::isCacheable(state.element(), state.style(), sta te.parentStyle())) 1291 if (!MatchedPropertiesCache::isCacheable(element, state.style(), state.paren tStyle()))
1290 return; 1292 return;
1291 STYLE_STATS_ADD_MATCHED_PROPERTIES_ENTERED_INTO_CACHE(); 1293 STYLE_STATS_ADD_MATCHED_PROPERTIES_ENTERED_INTO_CACHE();
1292 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHash, matchResult); 1294 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHash, matchResult);
1293 } 1295 }
1294 1296
1295 CSSPropertyValue::CSSPropertyValue(CSSPropertyID id, const StylePropertySet& pro pertySet) 1297 CSSPropertyValue::CSSPropertyValue(CSSPropertyID id, const StylePropertySet& pro pertySet)
1296 : property(id), value(propertySet.getPropertyCSSValue(id).get()) 1298 : property(id), value(propertySet.getPropertyCSSValue(id).get())
1297 { } 1299 { }
1298 1300
1299 void StyleResolver::applyPropertiesToStyle(const CSSPropertyValue* properties, s ize_t count, RenderStyle* style) 1301 void StyleResolver::applyPropertiesToStyle(const CSSPropertyValue* properties, s ize_t count, RenderStyle* style)
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che); 1460 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che);
1459 1461
1460 fprintf(stderr, "Total:\n"); 1462 fprintf(stderr, "Total:\n");
1461 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing, 1463 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing,
1462 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache); 1464 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache);
1463 fprintf(stderr, "----------------------------------------------------------- ---------------------\n"); 1465 fprintf(stderr, "----------------------------------------------------------- ---------------------\n");
1464 } 1466 }
1465 #endif 1467 #endif
1466 1468
1467 } // namespace WebCore 1469 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698