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

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

Issue 5216392399814656: Clear StyleResolverState after each resolve. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: You people refactor too quickly. (Sync ;) 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
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 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 if (!s_styleNotYetAvailable) { 1006 if (!s_styleNotYetAvailable) {
1007 s_styleNotYetAvailable = RenderStyle::create().leakRef(); 1007 s_styleNotYetAvailable = RenderStyle::create().leakRef();
1008 s_styleNotYetAvailable->setDisplay(NONE); 1008 s_styleNotYetAvailable->setDisplay(NONE);
1009 s_styleNotYetAvailable->font().update(m_fontSelector); 1009 s_styleNotYetAvailable->font().update(m_fontSelector);
1010 } 1010 }
1011 element->document()->setHasNodesWithPlaceholderStyle(); 1011 element->document()->setHasNodesWithPlaceholderStyle();
1012 return s_styleNotYetAvailable; 1012 return s_styleNotYetAvailable;
1013 } 1013 }
1014 1014
1015 StyleResolverState& state = m_state; 1015 StyleResolverState& state = m_state;
1016 state.initForStyleResolve(document(), element, childIndex, defaultParent, re gionForStyling); 1016 StyleResolverState::ScopedStyleResolution resolution(&state, document(), ele ment, childIndex, defaultParent, regionForStyling);
1017 if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoi nt()) { 1017 if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoi nt()) {
1018 RenderStyle* sharedStyle = locateSharedStyle(); 1018 RefPtr<RenderStyle> sharedStyle = locateSharedStyle();
1019 if (sharedStyle) { 1019 if (sharedStyle)
1020 state.clear(); 1020 return sharedStyle.release();
1021 return sharedStyle;
1022 }
1023 } 1021 }
1024 1022
1025 if (state.parentStyle()) { 1023 if (state.parentStyle()) {
1026 state.setStyle(RenderStyle::create()); 1024 state.setStyle(RenderStyle::create());
1027 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); 1025 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
1028 } else { 1026 } else {
1029 state.setStyle(defaultStyleForElement()); 1027 state.setStyle(defaultStyleForElement());
1030 state.setParentStyle(RenderStyle::clone(state.style())); 1028 state.setParentStyle(RenderStyle::clone(state.style()));
1031 } 1029 }
1032 // contenteditable attribute (implemented by -webkit-user-modify) should 1030 // contenteditable attribute (implemented by -webkit-user-modify) should
(...skipping 29 matching lines...) Expand all
1062 if (matchingBehavior == MatchOnlyUserAgentRules) 1060 if (matchingBehavior == MatchOnlyUserAgentRules)
1063 matchUARules(collector); 1061 matchUARules(collector);
1064 else 1062 else
1065 matchAllRules(collector, m_matchAuthorAndUserStyles, matchingBehavior != MatchAllRulesExcludingSMIL); 1063 matchAllRules(collector, m_matchAuthorAndUserStyles, matchingBehavior != MatchAllRulesExcludingSMIL);
1066 1064
1067 applyMatchedProperties(collector.matchedResult(), element); 1065 applyMatchedProperties(collector.matchedResult(), element);
1068 1066
1069 // Clean up our style object's display and text decorations (among other fix ups). 1067 // Clean up our style object's display and text decorations (among other fix ups).
1070 adjustRenderStyle(state.style(), state.parentStyle(), element); 1068 adjustRenderStyle(state.style(), state.parentStyle(), element);
1071 1069
1072 state.clear(); // Clear out for the next resolve.
1073
1074 document()->didAccessStyleResolver(); 1070 document()->didAccessStyleResolver();
1075 1071
1076 if (element->hasTagName(bodyTag)) 1072 if (element->hasTagName(bodyTag))
1077 document()->textLinkColors().setTextColor(state.style()->visitedDependen tColor(CSSPropertyColor)); 1073 document()->textLinkColors().setTextColor(state.style()->visitedDependen tColor(CSSPropertyColor));
1078 1074
1079 // Now return the style. 1075 // Now return the style.
1080 return state.takeStyle(); 1076 return state.takeStyle();
1081 } 1077 }
1082 1078
1083 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(const RenderStyle* eleme ntStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue) 1079 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* e, const Render Style* elementStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue )
dglazkov 2013/07/12 16:45:47 we can get elementStyle from element, right? Why p
Jeffrey Yasskin 2013/07/12 19:41:28 keyframeStylesForAnimation takes both rather than
1084 { 1080 {
1081 StyleResolverState::ScopedStyleResolution resolution(&m_state, document(), e );
1082
1085 MatchResult result; 1083 MatchResult result;
1086 if (keyframe->properties()) 1084 if (keyframe->properties())
1087 result.addMatchedProperties(keyframe->properties()); 1085 result.addMatchedProperties(keyframe->properties());
1088 1086
1089 StyleResolverState& state = m_state; 1087 StyleResolverState& state = m_state;
1090 ASSERT(!state.style()); 1088 ASSERT(!state.style());
1091 1089
1092 // Create the style 1090 // Create the style
1093 state.setStyle(RenderStyle::clone(elementStyle)); 1091 state.setStyle(RenderStyle::clone(elementStyle));
1094 state.setLineHeightValue(0); 1092 state.setLineHeightValue(0);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(list.animationName() .impl()); 1148 KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(list.animationName() .impl());
1151 if (it == m_keyframesRuleMap.end()) 1149 if (it == m_keyframesRuleMap.end())
1152 return; 1150 return;
1153 1151
1154 const StyleRuleKeyframes* keyframesRule = it->value.get(); 1152 const StyleRuleKeyframes* keyframesRule = it->value.get();
1155 1153
1156 // Construct and populate the style for each keyframe 1154 // Construct and populate the style for each keyframe
1157 const Vector<RefPtr<StyleKeyframe> >& keyframes = keyframesRule->keyframes() ; 1155 const Vector<RefPtr<StyleKeyframe> >& keyframes = keyframesRule->keyframes() ;
1158 for (unsigned i = 0; i < keyframes.size(); ++i) { 1156 for (unsigned i = 0; i < keyframes.size(); ++i) {
1159 // Apply the declaration to the style. This is a simplified version of t he logic in styleForElement 1157 // Apply the declaration to the style. This is a simplified version of t he logic in styleForElement
1160 m_state.initForStyleResolve(document(), e);
1161
1162 const StyleKeyframe* keyframe = keyframes[i].get(); 1158 const StyleKeyframe* keyframe = keyframes[i].get();
1163 1159
1164 KeyframeValue keyframeValue(0, 0); 1160 KeyframeValue keyframeValue(0, 0);
1165 keyframeValue.setStyle(styleForKeyframe(elementStyle, keyframe, keyframe Value)); 1161 keyframeValue.setStyle(styleForKeyframe(e, elementStyle, keyframe, keyfr ameValue));
1166 1162
1167 // Add this keyframe style to all the indicated key times 1163 // Add this keyframe style to all the indicated key times
1168 Vector<float> keys; 1164 Vector<float> keys;
1169 keyframe->getKeys(keys); 1165 keyframe->getKeys(keys);
1170 for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) { 1166 for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) {
1171 keyframeValue.setKey(keys[keyIndex]); 1167 keyframeValue.setKey(keys[keyIndex]);
1172 list.insert(keyframeValue); 1168 list.insert(keyframeValue);
1173 } 1169 }
1174 } 1170 }
1175 1171
1176 // If the 0% keyframe is missing, create it (but only if there is at least o ne other keyframe) 1172 // If the 0% keyframe is missing, create it (but only if there is at least o ne other keyframe)
1177 int initialListSize = list.size(); 1173 int initialListSize = list.size();
1178 if (initialListSize > 0 && list[0].key()) { 1174 if (initialListSize > 0 && list[0].key()) {
1179 static StyleKeyframe* zeroPercentKeyframe; 1175 static StyleKeyframe* zeroPercentKeyframe;
1180 if (!zeroPercentKeyframe) { 1176 if (!zeroPercentKeyframe) {
1181 zeroPercentKeyframe = StyleKeyframe::create().leakRef(); 1177 zeroPercentKeyframe = StyleKeyframe::create().leakRef();
1182 zeroPercentKeyframe->setKeyText("0%"); 1178 zeroPercentKeyframe->setKeyText("0%");
1183 } 1179 }
1184 KeyframeValue keyframeValue(0, 0); 1180 KeyframeValue keyframeValue(0, 0);
1185 keyframeValue.setStyle(styleForKeyframe(elementStyle, zeroPercentKeyfram e, keyframeValue)); 1181 keyframeValue.setStyle(styleForKeyframe(e, elementStyle, zeroPercentKeyf rame, keyframeValue));
1186 list.insert(keyframeValue); 1182 list.insert(keyframeValue);
1187 } 1183 }
1188 1184
1189 // If the 100% keyframe is missing, create it (but only if there is at least one other keyframe) 1185 // If the 100% keyframe is missing, create it (but only if there is at least one other keyframe)
1190 if (initialListSize > 0 && (list[list.size() - 1].key() != 1)) { 1186 if (initialListSize > 0 && (list[list.size() - 1].key() != 1)) {
1191 static StyleKeyframe* hundredPercentKeyframe; 1187 static StyleKeyframe* hundredPercentKeyframe;
1192 if (!hundredPercentKeyframe) { 1188 if (!hundredPercentKeyframe) {
1193 hundredPercentKeyframe = StyleKeyframe::create().leakRef(); 1189 hundredPercentKeyframe = StyleKeyframe::create().leakRef();
1194 hundredPercentKeyframe->setKeyText("100%"); 1190 hundredPercentKeyframe->setKeyText("100%");
1195 } 1191 }
1196 KeyframeValue keyframeValue(1, 0); 1192 KeyframeValue keyframeValue(1, 0);
1197 keyframeValue.setStyle(styleForKeyframe(elementStyle, hundredPercentKeyf rame, keyframeValue)); 1193 keyframeValue.setStyle(styleForKeyframe(e, elementStyle, hundredPercentK eyframe, keyframeValue));
1198 list.insert(keyframeValue); 1194 list.insert(keyframeValue);
1199 } 1195 }
1200 } 1196 }
1201 1197
1202 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const P seudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle) 1198 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const P seudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle)
1203 { 1199 {
1204 ASSERT(parentStyle); 1200 ASSERT(parentStyle);
1205 if (!e) 1201 if (!e)
1206 return 0; 1202 return 0;
1207 1203
1208 StyleResolverState& state = m_state; 1204 StyleResolverState& state = m_state;
1209 1205
1210 state.initForStyleResolve(document(), e, 0, parentStyle); 1206 StyleResolverState::ScopedStyleResolution resolution(&state, document(), e, 0, parentStyle);
1211 1207
1212 if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) { 1208 if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) {
1213 state.setStyle(RenderStyle::create()); 1209 state.setStyle(RenderStyle::create());
1214 state.style()->inheritFrom(state.parentStyle()); 1210 state.style()->inheritFrom(state.parentStyle());
1215 } else { 1211 } else {
1216 state.setStyle(defaultStyleForElement()); 1212 state.setStyle(defaultStyleForElement());
1217 state.setParentStyle(RenderStyle::clone(state.style())); 1213 state.setParentStyle(RenderStyle::clone(state.style()));
1218 } 1214 }
1219 1215
1220 // Since we don't use pseudo-elements in any of our quirk/print user agent r ules, don't waste time walking 1216 // Since we don't use pseudo-elements in any of our quirk/print user agent r ules, don't waste time walking
(...skipping 23 matching lines...) Expand all
1244 m_styleResourceLoader.loadPendingResources(m_state.style(), m_state.elementS tyleResources()); 1240 m_styleResourceLoader.loadPendingResources(m_state.style(), m_state.elementS tyleResources());
1245 1241
1246 document()->didAccessStyleResolver(); 1242 document()->didAccessStyleResolver();
1247 1243
1248 // Now return the style. 1244 // Now return the style.
1249 return state.takeStyle(); 1245 return state.takeStyle();
1250 } 1246 }
1251 1247
1252 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex) 1248 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex)
1253 { 1249 {
1254 m_state.initForStyleResolve(document(), document()->documentElement()); // m _rootElementStyle will be set to the document style. 1250 StyleResolverState::ScopedStyleResolution resolution(&m_state, document(), d ocument()->documentElement()); // m_rootElementStyle will be set to the document style.
1255 1251
1256 m_state.setStyle(RenderStyle::create()); 1252 m_state.setStyle(RenderStyle::create());
1257 m_state.style()->inheritFrom(m_state.rootElementStyle()); 1253 m_state.style()->inheritFrom(m_state.rootElementStyle());
1258 1254
1259 PageRuleCollector collector(m_state, pageIndex); 1255 PageRuleCollector collector(m_state, pageIndex);
1260 1256
1261 collector.matchPageRules(CSSDefaultStyleSheets::defaultPrintStyle); 1257 collector.matchPageRules(CSSDefaultStyleSheets::defaultPrintStyle);
1262 collector.matchPageRules(m_ruleSets.userStyle()); 1258 collector.matchPageRules(m_ruleSets.userStyle());
1263 1259
1264 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor Document()) 1260 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor Document())
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 PassRefPtr<CSSRuleList> StyleResolver::styleRulesForElement(Element* e, unsigned rulesToInclude) 1696 PassRefPtr<CSSRuleList> StyleResolver::styleRulesForElement(Element* e, unsigned rulesToInclude)
1701 { 1697 {
1702 return pseudoStyleRulesForElement(e, NOPSEUDO, rulesToInclude); 1698 return pseudoStyleRulesForElement(e, NOPSEUDO, rulesToInclude);
1703 } 1699 }
1704 1700
1705 PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, Ps eudoId pseudoId, unsigned rulesToInclude) 1701 PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, Ps eudoId pseudoId, unsigned rulesToInclude)
1706 { 1702 {
1707 if (!e || !e->document()->haveStylesheetsLoaded()) 1703 if (!e || !e->document()->haveStylesheetsLoaded())
1708 return 0; 1704 return 0;
1709 1705
1710 m_state.initForStyleResolve(document(), e); 1706 StyleResolverState::ScopedStyleResolution resolution(&m_state, document(), e );
1711 1707
1712 ElementRuleCollector collector(this, m_state); 1708 ElementRuleCollector collector(this, m_state);
1713 collector.setMode(SelectorChecker::CollectingRules); 1709 collector.setMode(SelectorChecker::CollectingRules);
1714 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); 1710 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId));
1715 1711
1716 if (rulesToInclude & UAAndUserCSSRules) { 1712 if (rulesToInclude & UAAndUserCSSRules) {
1717 // First we match rules from the user agent sheet. 1713 // First we match rules from the user agent sheet.
1718 matchUARules(collector); 1714 matchUARules(collector);
1719 1715
1720 // Now we check user sheet rules. 1716 // Now we check user sheet rules.
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 2047
2052 ASSERT(!state.fontDirty()); 2048 ASSERT(!state.fontDirty());
2053 2049
2054 if (cachedMatchedProperties || !cacheHash) 2050 if (cachedMatchedProperties || !cacheHash)
2055 return; 2051 return;
2056 if (!MatchedPropertiesCache::isCacheable(state.element(), state.style(), sta te.parentStyle())) 2052 if (!MatchedPropertiesCache::isCacheable(state.element(), state.style(), sta te.parentStyle()))
2057 return; 2053 return;
2058 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHash, matchResult); 2054 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHash, matchResult);
2059 } 2055 }
2060 2056
2061 void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, Rend erStyle* style) 2057 StyleResolver::PropertyValue::PropertyValue(CSSPropertyID id, const StylePropert ySet& propertySet)
2058 : property(id), value(propertySet.getPropertyCSSValue(id).get())
2059 { }
2060
2061 void StyleResolver::applyPropertiesToStyle(const PropertyValue* properties, size _t count, RenderStyle* style)
2062 { 2062 {
2063 m_state.initForStyleResolve(document(), 0, 0, style); 2063 StyleResolverState::ScopedStyleResolution resolution(&m_state, document(), 0 , 0, style);
2064 m_state.setStyle(style); 2064 m_state.setStyle(style);
2065 applyPropertyToCurrentStyle(id, value); 2065 for (size_t i = 0; i < count; ++i) {
2066 } 2066 if (properties[i].value) {
2067 2067 // As described in BUG66291, setting font-size and line-height on a font may entail a CSSPrimitiveValue::computeLengthDouble call,
2068 void StyleResolver::applyPropertyToCurrentStyle(CSSPropertyID id, CSSValue* valu e) 2068 // which assumes the fontMetrics are available for the affected font , otherwise a crash occurs (see http://trac.webkit.org/changeset/96122).
2069 { 2069 // The updateFont() call below updates the fontMetrics and ensure th e proper setting of font-size and line-height.
2070 if (value) 2070 switch (properties[i].property) {
2071 applyProperty(id, value); 2071 case CSSPropertyFontSize:
2072 case CSSPropertyLineHeight:
2073 updateFont();
2074 break;
2075 default:
2076 break;
2077 }
2078 applyProperty(properties[i].property, properties[i].value);
2079 }
2080 }
2072 } 2081 }
2073 2082
2074 static bool hasVariableReference(CSSValue* value) 2083 static bool hasVariableReference(CSSValue* value)
2075 { 2084 {
2076 if (value->isPrimitiveValue()) { 2085 if (value->isPrimitiveValue()) {
2077 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 2086 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
2078 return primitiveValue->hasVariableReference(); 2087 return primitiveValue->hasVariableReference();
2079 } 2088 }
2080 2089
2081 if (value->isCalculationValue()) 2090 if (value->isCalculationValue())
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
2404 void CachedMatchedProperties::reportMemoryUsage(MemoryObjectInfo* memoryObjectIn fo) const 2413 void CachedMatchedProperties::reportMemoryUsage(MemoryObjectInfo* memoryObjectIn fo) const
2405 { 2414 {
2406 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); 2415 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
2407 info.addMember(matchedProperties, "matchedProperties"); 2416 info.addMember(matchedProperties, "matchedProperties");
2408 info.addMember(ranges, "ranges"); 2417 info.addMember(ranges, "ranges");
2409 info.addMember(renderStyle, "renderStyle"); 2418 info.addMember(renderStyle, "renderStyle");
2410 info.addMember(parentRenderStyle, "parentRenderStyle"); 2419 info.addMember(parentRenderStyle, "parentRenderStyle");
2411 } 2420 }
2412 2421
2413 } // namespace WebCore 2422 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698