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

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: 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 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 if (!s_styleNotYetAvailable) { 1007 if (!s_styleNotYetAvailable) {
1008 s_styleNotYetAvailable = RenderStyle::create().leakRef(); 1008 s_styleNotYetAvailable = RenderStyle::create().leakRef();
1009 s_styleNotYetAvailable->setDisplay(NONE); 1009 s_styleNotYetAvailable->setDisplay(NONE);
1010 s_styleNotYetAvailable->font().update(m_fontSelector); 1010 s_styleNotYetAvailable->font().update(m_fontSelector);
1011 } 1011 }
1012 element->document()->setHasNodesWithPlaceholderStyle(); 1012 element->document()->setHasNodesWithPlaceholderStyle();
1013 return s_styleNotYetAvailable; 1013 return s_styleNotYetAvailable;
1014 } 1014 }
1015 1015
1016 StyleResolverState& state = m_state; 1016 StyleResolverState& state = m_state;
1017 state.initForStyleResolve(document(), element, defaultParent, regionForStyli ng); 1017 ScopedStyleResolution resolution(&state, document(), element, defaultParent, regionForStyling);
1018 if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoi nt() && state.parentStyle()) { 1018 if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoi nt() && state.parentStyle()) {
1019 RenderStyle* sharedStyle = locateSharedStyle(state.elementContext()); 1019 RefPtr<RenderStyle> sharedStyle = locateSharedStyle(state.elementContext ());
1020 if (sharedStyle) { 1020 if (sharedStyle)
1021 state.clear(); 1021 return sharedStyle.release();
1022 return sharedStyle;
1023 }
1024 } 1022 }
1025 1023
1026 if (state.parentStyle()) { 1024 if (state.parentStyle()) {
1027 state.setStyle(RenderStyle::create()); 1025 state.setStyle(RenderStyle::create());
1028 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); 1026 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
1029 } else { 1027 } else {
1030 state.setStyle(defaultStyleForElement()); 1028 state.setStyle(defaultStyleForElement());
1031 state.setParentStyle(RenderStyle::clone(state.style())); 1029 state.setParentStyle(RenderStyle::clone(state.style()));
1032 } 1030 }
1033 // contenteditable attribute (implemented by -webkit-user-modify) should 1031 // contenteditable attribute (implemented by -webkit-user-modify) should
(...skipping 30 matching lines...) Expand all
1064 if (matchingBehavior == MatchOnlyUserAgentRules) 1062 if (matchingBehavior == MatchOnlyUserAgentRules)
1065 matchUARules(collector); 1063 matchUARules(collector);
1066 else 1064 else
1067 matchAllRules(collector, m_matchAuthorAndUserStyles, matchingBehavio r != MatchAllRulesExcludingSMIL); 1065 matchAllRules(collector, m_matchAuthorAndUserStyles, matchingBehavio r != MatchAllRulesExcludingSMIL);
1068 1066
1069 applyMatchedProperties(collector.matchedResult(), element); 1067 applyMatchedProperties(collector.matchedResult(), element);
1070 } 1068 }
1071 // Clean up our style object's display and text decorations (among other fix ups). 1069 // Clean up our style object's display and text decorations (among other fix ups).
1072 adjustRenderStyle(state.style(), state.parentStyle(), element); 1070 adjustRenderStyle(state.style(), state.parentStyle(), element);
1073 1071
1074 state.clear(); // Clear out for the next resolve.
1075
1076 document()->didAccessStyleResolver(); 1072 document()->didAccessStyleResolver();
1077 1073
1078 // FIXME: Shouldn't this be on RenderBody::styleDidChange? 1074 // FIXME: Shouldn't this be on RenderBody::styleDidChange?
1079 if (element->hasTagName(bodyTag)) 1075 if (element->hasTagName(bodyTag))
1080 document()->textLinkColors().setTextColor(state.style()->visitedDependen tColor(CSSPropertyColor)); 1076 document()->textLinkColors().setTextColor(state.style()->visitedDependen tColor(CSSPropertyColor));
1081 1077
1082 // Now return the style. 1078 // Now return the style.
1083 return state.takeStyle(); 1079 return state.takeStyle();
1084 } 1080 }
1085 1081
1086 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(const RenderStyle* eleme ntStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue) 1082 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* e, const Render Style* elementStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue )
1087 { 1083 {
1084 ScopedStyleResolution resolution(&m_state, document(), e);
1085
1088 MatchResult result; 1086 MatchResult result;
1089 if (keyframe->properties()) 1087 if (keyframe->properties())
1090 result.addMatchedProperties(keyframe->properties()); 1088 result.addMatchedProperties(keyframe->properties());
1091 1089
1092 StyleResolverState& state = m_state; 1090 StyleResolverState& state = m_state;
1093 ASSERT(!state.style()); 1091 ASSERT(!state.style());
1094 1092
1095 // Create the style 1093 // Create the style
1096 state.setStyle(RenderStyle::clone(elementStyle)); 1094 state.setStyle(RenderStyle::clone(elementStyle));
1097 state.setLineHeightValue(0); 1095 state.setLineHeightValue(0);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(list.animationName() .impl()); 1151 KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(list.animationName() .impl());
1154 if (it == m_keyframesRuleMap.end()) 1152 if (it == m_keyframesRuleMap.end())
1155 return; 1153 return;
1156 1154
1157 const StyleRuleKeyframes* keyframesRule = it->value.get(); 1155 const StyleRuleKeyframes* keyframesRule = it->value.get();
1158 1156
1159 // Construct and populate the style for each keyframe 1157 // Construct and populate the style for each keyframe
1160 const Vector<RefPtr<StyleKeyframe> >& keyframes = keyframesRule->keyframes() ; 1158 const Vector<RefPtr<StyleKeyframe> >& keyframes = keyframesRule->keyframes() ;
1161 for (unsigned i = 0; i < keyframes.size(); ++i) { 1159 for (unsigned i = 0; i < keyframes.size(); ++i) {
1162 // Apply the declaration to the style. This is a simplified version of t he logic in styleForElement 1160 // Apply the declaration to the style. This is a simplified version of t he logic in styleForElement
1163 m_state.initForStyleResolve(document(), e);
1164
1165 const StyleKeyframe* keyframe = keyframes[i].get(); 1161 const StyleKeyframe* keyframe = keyframes[i].get();
1166 1162
1167 KeyframeValue keyframeValue(0, 0); 1163 KeyframeValue keyframeValue(0, 0);
1168 keyframeValue.setStyle(styleForKeyframe(elementStyle, keyframe, keyframe Value)); 1164 keyframeValue.setStyle(styleForKeyframe(e, elementStyle, keyframe, keyfr ameValue));
1169 1165
1170 // Add this keyframe style to all the indicated key times 1166 // Add this keyframe style to all the indicated key times
1171 Vector<float> keys; 1167 Vector<float> keys;
1172 keyframe->getKeys(keys); 1168 keyframe->getKeys(keys);
1173 for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) { 1169 for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) {
1174 keyframeValue.setKey(keys[keyIndex]); 1170 keyframeValue.setKey(keys[keyIndex]);
1175 list.insert(keyframeValue); 1171 list.insert(keyframeValue);
1176 } 1172 }
1177 } 1173 }
1178 1174
1179 // If the 0% keyframe is missing, create it (but only if there is at least o ne other keyframe) 1175 // If the 0% keyframe is missing, create it (but only if there is at least o ne other keyframe)
1180 int initialListSize = list.size(); 1176 int initialListSize = list.size();
1181 if (initialListSize > 0 && list[0].key()) { 1177 if (initialListSize > 0 && list[0].key()) {
1182 static StyleKeyframe* zeroPercentKeyframe; 1178 static StyleKeyframe* zeroPercentKeyframe;
1183 if (!zeroPercentKeyframe) { 1179 if (!zeroPercentKeyframe) {
1184 zeroPercentKeyframe = StyleKeyframe::create().leakRef(); 1180 zeroPercentKeyframe = StyleKeyframe::create().leakRef();
1185 zeroPercentKeyframe->setKeyText("0%"); 1181 zeroPercentKeyframe->setKeyText("0%");
1186 } 1182 }
1187 KeyframeValue keyframeValue(0, 0); 1183 KeyframeValue keyframeValue(0, 0);
1188 keyframeValue.setStyle(styleForKeyframe(elementStyle, zeroPercentKeyfram e, keyframeValue)); 1184 keyframeValue.setStyle(styleForKeyframe(e, elementStyle, zeroPercentKeyf rame, keyframeValue));
1189 list.insert(keyframeValue); 1185 list.insert(keyframeValue);
1190 } 1186 }
1191 1187
1192 // If the 100% keyframe is missing, create it (but only if there is at least one other keyframe) 1188 // If the 100% keyframe is missing, create it (but only if there is at least one other keyframe)
1193 if (initialListSize > 0 && (list[list.size() - 1].key() != 1)) { 1189 if (initialListSize > 0 && (list[list.size() - 1].key() != 1)) {
1194 static StyleKeyframe* hundredPercentKeyframe; 1190 static StyleKeyframe* hundredPercentKeyframe;
1195 if (!hundredPercentKeyframe) { 1191 if (!hundredPercentKeyframe) {
1196 hundredPercentKeyframe = StyleKeyframe::create().leakRef(); 1192 hundredPercentKeyframe = StyleKeyframe::create().leakRef();
1197 hundredPercentKeyframe->setKeyText("100%"); 1193 hundredPercentKeyframe->setKeyText("100%");
1198 } 1194 }
1199 KeyframeValue keyframeValue(1, 0); 1195 KeyframeValue keyframeValue(1, 0);
1200 keyframeValue.setStyle(styleForKeyframe(elementStyle, hundredPercentKeyf rame, keyframeValue)); 1196 keyframeValue.setStyle(styleForKeyframe(e, elementStyle, hundredPercentK eyframe, keyframeValue));
1201 list.insert(keyframeValue); 1197 list.insert(keyframeValue);
1202 } 1198 }
1203 } 1199 }
1204 1200
1205 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const P seudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle) 1201 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const P seudoStyleRequest& pseudoStyleRequest, RenderStyle* parentStyle)
1206 { 1202 {
1207 ASSERT(parentStyle); 1203 ASSERT(parentStyle);
1208 if (!e) 1204 if (!e)
1209 return 0; 1205 return 0;
1210 1206
1211 StyleResolverState& state = m_state; 1207 StyleResolverState& state = m_state;
1212 1208
1213 state.initForStyleResolve(document(), e, parentStyle); 1209 ScopedStyleResolution resolution(&state, document(), e, parentStyle);
1214 1210
1215 if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) { 1211 if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) {
1216 state.setStyle(RenderStyle::create()); 1212 state.setStyle(RenderStyle::create());
1217 state.style()->inheritFrom(state.parentStyle()); 1213 state.style()->inheritFrom(state.parentStyle());
1218 } else { 1214 } else {
1219 state.setStyle(defaultStyleForElement()); 1215 state.setStyle(defaultStyleForElement());
1220 state.setParentStyle(RenderStyle::clone(state.style())); 1216 state.setParentStyle(RenderStyle::clone(state.style()));
1221 } 1217 }
1222 1218
1223 // Since we don't use pseudo-elements in any of our quirk/print 1219 // Since we don't use pseudo-elements in any of our quirk/print
(...skipping 24 matching lines...) Expand all
1248 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources()); 1244 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources());
1249 1245
1250 document()->didAccessStyleResolver(); 1246 document()->didAccessStyleResolver();
1251 1247
1252 // Now return the style. 1248 // Now return the style.
1253 return state.takeStyle(); 1249 return state.takeStyle();
1254 } 1250 }
1255 1251
1256 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex) 1252 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex)
1257 { 1253 {
1258 m_state.initForStyleResolve(document(), document()->documentElement()); // m _rootElementStyle will be set to the document style. 1254 ScopedStyleResolution resolution(&m_state, document(), document()->documentE lement()); // m_rootElementStyle will be set to the document style.
1259 1255
1260 m_state.setStyle(RenderStyle::create()); 1256 m_state.setStyle(RenderStyle::create());
1261 m_state.style()->inheritFrom(m_state.rootElementStyle()); 1257 m_state.style()->inheritFrom(m_state.rootElementStyle());
1262 1258
1263 PageRuleCollector collector(m_state, pageIndex); 1259 PageRuleCollector collector(m_state, pageIndex);
1264 1260
1265 collector.matchPageRules(CSSDefaultStyleSheets::defaultPrintStyle); 1261 collector.matchPageRules(CSSDefaultStyleSheets::defaultPrintStyle);
1266 collector.matchPageRules(m_ruleSets.userStyle()); 1262 collector.matchPageRules(m_ruleSets.userStyle());
1267 1263
1268 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor Document()) 1264 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor Document())
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 PassRefPtr<CSSRuleList> StyleResolver::styleRulesForElement(Element* e, unsigned rulesToInclude) 1700 PassRefPtr<CSSRuleList> StyleResolver::styleRulesForElement(Element* e, unsigned rulesToInclude)
1705 { 1701 {
1706 return pseudoStyleRulesForElement(e, NOPSEUDO, rulesToInclude); 1702 return pseudoStyleRulesForElement(e, NOPSEUDO, rulesToInclude);
1707 } 1703 }
1708 1704
1709 PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, Ps eudoId pseudoId, unsigned rulesToInclude) 1705 PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, Ps eudoId pseudoId, unsigned rulesToInclude)
1710 { 1706 {
1711 if (!e || !e->document()->haveStylesheetsLoaded()) 1707 if (!e || !e->document()->haveStylesheetsLoaded())
1712 return 0; 1708 return 0;
1713 1709
1714 m_state.initForStyleResolve(document(), e); 1710 ScopedStyleResolution resolution(&m_state, document(), e);
1715 1711
1716 ElementRuleCollector collector(m_state.elementContext(), m_selectorFilter, m _state.style(), m_inspectorCSSOMWrappers); 1712 ElementRuleCollector collector(m_state.elementContext(), m_selectorFilter, m _state.style(), m_inspectorCSSOMWrappers);
1717 collector.setMode(SelectorChecker::CollectingRules); 1713 collector.setMode(SelectorChecker::CollectingRules);
1718 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); 1714 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId));
1719 1715
1720 if (rulesToInclude & UAAndUserCSSRules) { 1716 if (rulesToInclude & UAAndUserCSSRules) {
1721 // First we match rules from the user agent sheet. 1717 // First we match rules from the user agent sheet.
1722 matchUARules(collector); 1718 matchUARules(collector);
1723 1719
1724 // Now we check user sheet rules. 1720 // Now we check user sheet rules.
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 2026
2031 ASSERT(!state.fontDirty()); 2027 ASSERT(!state.fontDirty());
2032 2028
2033 if (cachedMatchedProperties || !cacheHash) 2029 if (cachedMatchedProperties || !cacheHash)
2034 return; 2030 return;
2035 if (!MatchedPropertiesCache::isCacheable(state.element(), state.style(), sta te.parentStyle())) 2031 if (!MatchedPropertiesCache::isCacheable(state.element(), state.style(), sta te.parentStyle()))
2036 return; 2032 return;
2037 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHash, matchResult); 2033 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHash, matchResult);
2038 } 2034 }
2039 2035
2040 void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, Rend erStyle* style) 2036 CSSPropertyValue::CSSPropertyValue(CSSPropertyID id, const StylePropertySet& pro pertySet)
2037 : property(id), value(propertySet.getPropertyCSSValue(id).get())
2038 { }
2039
2040 void StyleResolver::applyPropertiesToStyle(const CSSPropertyValue* properties, s ize_t count, RenderStyle* style)
2041 { 2041 {
2042 m_state.initForStyleResolve(document(), 0, style); 2042 ScopedStyleResolution resolution(&m_state, document(), 0, style);
2043 m_state.setStyle(style); 2043 m_state.setStyle(style);
2044 applyPropertyToCurrentStyle(id, value); 2044 for (size_t i = 0; i < count; ++i) {
2045 } 2045 if (properties[i].value) {
2046 2046 // As described in BUG66291, setting font-size and line-height on a font may entail a CSSPrimitiveValue::computeLengthDouble call,
2047 void StyleResolver::applyPropertyToCurrentStyle(CSSPropertyID id, CSSValue* valu e) 2047 // which assumes the fontMetrics are available for the affected font , otherwise a crash occurs (see http://trac.webkit.org/changeset/96122).
2048 { 2048 // The updateFont() call below updates the fontMetrics and ensure th e proper setting of font-size and line-height.
2049 if (value) 2049 switch (properties[i].property) {
2050 applyProperty(id, value); 2050 case CSSPropertyFontSize:
2051 case CSSPropertyLineHeight:
2052 updateFont();
2053 break;
2054 default:
2055 break;
2056 }
2057 applyProperty(properties[i].property, properties[i].value);
2058 }
2059 }
2051 } 2060 }
2052 2061
2053 static bool hasVariableReference(CSSValue* value) 2062 static bool hasVariableReference(CSSValue* value)
2054 { 2063 {
2055 if (value->isPrimitiveValue()) { 2064 if (value->isPrimitiveValue()) {
2056 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 2065 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
2057 return primitiveValue->hasVariableReference(); 2066 return primitiveValue->hasVariableReference();
2058 } 2067 }
2059 2068
2060 if (value->isCalculationValue()) 2069 if (value->isCalculationValue())
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 info.addMember(m_state, "state"); 2273 info.addMember(m_state, "state");
2265 2274
2266 // FIXME: move this to a place where it would be called only once? 2275 // FIXME: move this to a place where it would be called only once?
2267 info.addMember(CSSDefaultStyleSheets::defaultStyle, "defaultStyle"); 2276 info.addMember(CSSDefaultStyleSheets::defaultStyle, "defaultStyle");
2268 info.addMember(CSSDefaultStyleSheets::defaultQuirksStyle, "defaultQuirksStyl e"); 2277 info.addMember(CSSDefaultStyleSheets::defaultQuirksStyle, "defaultQuirksStyl e");
2269 info.addMember(CSSDefaultStyleSheets::defaultPrintStyle, "defaultPrintStyle" ); 2278 info.addMember(CSSDefaultStyleSheets::defaultPrintStyle, "defaultPrintStyle" );
2270 info.addMember(CSSDefaultStyleSheets::defaultViewSourceStyle, "defaultViewSo urceStyle"); 2279 info.addMember(CSSDefaultStyleSheets::defaultViewSourceStyle, "defaultViewSo urceStyle");
2271 } 2280 }
2272 2281
2273 } // namespace WebCore 2282 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698