Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, defaultParent, regionForStyli ng); | 1016 state.initForStyleResolve(document(), element, defaultParent, regionForStyli ng); |
| 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 state.clear(); |
| 1021 return sharedStyle; | 1021 return sharedStyle.release(); |
| 1022 } | 1022 } |
| 1023 } | 1023 } |
| 1024 | 1024 |
| 1025 if (state.parentStyle()) { | 1025 if (state.parentStyle()) { |
| 1026 state.setStyle(RenderStyle::create()); | 1026 state.setStyle(RenderStyle::create()); |
| 1027 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); | 1027 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); |
| 1028 } else { | 1028 } else { |
| 1029 state.setStyle(defaultStyleForElement()); | 1029 state.setStyle(defaultStyleForElement()); |
| 1030 state.setParentStyle(RenderStyle::clone(state.style())); | 1030 state.setParentStyle(RenderStyle::clone(state.style())); |
| 1031 } | 1031 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1062 if (matchingBehavior == MatchOnlyUserAgentRules) | 1062 if (matchingBehavior == MatchOnlyUserAgentRules) |
| 1063 matchUARules(collector); | 1063 matchUARules(collector); |
| 1064 else | 1064 else |
| 1065 matchAllRules(collector, m_matchAuthorAndUserStyles, matchingBehavior != MatchAllRulesExcludingSMIL); | 1065 matchAllRules(collector, m_matchAuthorAndUserStyles, matchingBehavior != MatchAllRulesExcludingSMIL); |
| 1066 | 1066 |
| 1067 applyMatchedProperties(collector.matchedResult(), element); | 1067 applyMatchedProperties(collector.matchedResult(), element); |
| 1068 | 1068 |
| 1069 // 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). |
| 1070 adjustRenderStyle(state.style(), state.parentStyle(), element); | 1070 adjustRenderStyle(state.style(), state.parentStyle(), element); |
| 1071 | 1071 |
| 1072 state.clear(); // Clear out for the next resolve. | |
| 1073 | |
| 1074 document()->didAccessStyleResolver(); | 1072 document()->didAccessStyleResolver(); |
| 1075 | 1073 |
| 1076 if (element->hasTagName(bodyTag)) | 1074 if (element->hasTagName(bodyTag)) |
| 1077 document()->textLinkColors().setTextColor(state.style()->visitedDependen tColor(CSSPropertyColor)); | 1075 document()->textLinkColors().setTextColor(state.style()->visitedDependen tColor(CSSPropertyColor)); |
| 1078 | 1076 |
| 1079 // Now return the style. | 1077 // Now return the style and clear out for the next resolve. |
| 1080 return state.takeStyle(); | 1078 return state.takeStyleAndClear(); |
| 1081 } | 1079 } |
| 1082 | 1080 |
| 1083 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(const RenderStyle* eleme ntStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue) | 1081 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(const RenderStyle* eleme ntStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue) |
| 1084 { | 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()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1147 KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(list.animationName() .impl()); | 1145 KeyframesRuleMap::iterator it = m_keyframesRuleMap.find(list.animationName() .impl()); |
| 1148 if (it == m_keyframesRuleMap.end()) | 1146 if (it == m_keyframesRuleMap.end()) |
| 1149 return; | 1147 return; |
| 1150 | 1148 |
| 1151 const StyleRuleKeyframes* keyframesRule = it->value.get(); | 1149 const StyleRuleKeyframes* keyframesRule = it->value.get(); |
| 1152 | 1150 |
| 1153 // Construct and populate the style for each keyframe | 1151 // Construct and populate the style for each keyframe |
| 1154 const Vector<RefPtr<StyleKeyframe> >& keyframes = keyframesRule->keyframes() ; | 1152 const Vector<RefPtr<StyleKeyframe> >& keyframes = keyframesRule->keyframes() ; |
| 1155 for (unsigned i = 0; i < keyframes.size(); ++i) { | 1153 for (unsigned i = 0; i < keyframes.size(); ++i) { |
| 1156 // Apply the declaration to the style. This is a simplified version of t he logic in styleForElement | 1154 // Apply the declaration to the style. This is a simplified version of t he logic in styleForElement |
| 1157 m_state.initForStyleResolve(document(), e); | 1155 m_state.initForStyleResolve(document(), e); |
|
Jeffrey Yasskin
2013/07/11 21:24:05
This initForStyleResolve in a loop looks weird to
| |
| 1158 | 1156 |
| 1159 const StyleKeyframe* keyframe = keyframes[i].get(); | 1157 const StyleKeyframe* keyframe = keyframes[i].get(); |
| 1160 | 1158 |
| 1161 KeyframeValue keyframeValue(0, 0); | 1159 KeyframeValue keyframeValue(0, 0); |
| 1162 keyframeValue.setStyle(styleForKeyframe(elementStyle, keyframe, keyframe Value)); | 1160 keyframeValue.setStyle(styleForKeyframe(elementStyle, keyframe, keyframe Value)); |
| 1163 | 1161 |
| 1164 // Add this keyframe style to all the indicated key times | 1162 // Add this keyframe style to all the indicated key times |
| 1165 Vector<float> keys; | 1163 Vector<float> keys; |
| 1166 keyframe->getKeys(keys); | 1164 keyframe->getKeys(keys); |
| 1167 for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) { | 1165 for (size_t keyIndex = 0; keyIndex < keys.size(); ++keyIndex) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1187 if (initialListSize > 0 && (list[list.size() - 1].key() != 1)) { | 1185 if (initialListSize > 0 && (list[list.size() - 1].key() != 1)) { |
| 1188 static StyleKeyframe* hundredPercentKeyframe; | 1186 static StyleKeyframe* hundredPercentKeyframe; |
| 1189 if (!hundredPercentKeyframe) { | 1187 if (!hundredPercentKeyframe) { |
| 1190 hundredPercentKeyframe = StyleKeyframe::create().leakRef(); | 1188 hundredPercentKeyframe = StyleKeyframe::create().leakRef(); |
| 1191 hundredPercentKeyframe->setKeyText("100%"); | 1189 hundredPercentKeyframe->setKeyText("100%"); |
| 1192 } | 1190 } |
| 1193 KeyframeValue keyframeValue(1, 0); | 1191 KeyframeValue keyframeValue(1, 0); |
| 1194 keyframeValue.setStyle(styleForKeyframe(elementStyle, hundredPercentKeyf rame, keyframeValue)); | 1192 keyframeValue.setStyle(styleForKeyframe(elementStyle, hundredPercentKeyf rame, keyframeValue)); |
| 1195 list.insert(keyframeValue); | 1193 list.insert(keyframeValue); |
| 1196 } | 1194 } |
| 1195 m_state.clear(); | |
| 1197 } | 1196 } |
| 1198 | 1197 |
| 1199 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) |
| 1200 { | 1199 { |
| 1201 ASSERT(parentStyle); | 1200 ASSERT(parentStyle); |
| 1202 if (!e) | 1201 if (!e) |
| 1203 return 0; | 1202 return 0; |
| 1204 | 1203 |
| 1205 StyleResolverState& state = m_state; | 1204 StyleResolverState& state = m_state; |
| 1206 | 1205 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1220 // Check UA, user and author rules. | 1219 // Check UA, user and author rules. |
| 1221 ElementRuleCollector collector(this, state); | 1220 ElementRuleCollector collector(this, state); |
| 1222 collector.setPseudoStyleRequest(pseudoStyleRequest); | 1221 collector.setPseudoStyleRequest(pseudoStyleRequest); |
| 1223 matchUARules(collector); | 1222 matchUARules(collector); |
| 1224 | 1223 |
| 1225 if (m_matchAuthorAndUserStyles) { | 1224 if (m_matchAuthorAndUserStyles) { |
| 1226 matchUserRules(collector, false); | 1225 matchUserRules(collector, false); |
| 1227 matchAuthorRules(collector, false); | 1226 matchAuthorRules(collector, false); |
| 1228 } | 1227 } |
| 1229 | 1228 |
| 1230 if (collector.matchedResult().matchedProperties.isEmpty()) | 1229 if (collector.matchedResult().matchedProperties.isEmpty()) { |
| 1230 state.clear(); | |
|
Jeffrey Yasskin
2013/07/11 21:24:05
This .clear() on an early return is a good sign th
| |
| 1231 return 0; | 1231 return 0; |
| 1232 } | |
| 1232 | 1233 |
| 1233 state.style()->setStyleType(pseudoStyleRequest.pseudoId); | 1234 state.style()->setStyleType(pseudoStyleRequest.pseudoId); |
| 1234 | 1235 |
| 1235 applyMatchedProperties(collector.matchedResult(), e); | 1236 applyMatchedProperties(collector.matchedResult(), e); |
| 1236 | 1237 |
| 1237 // Clean up our style object's display and text decorations (among other fix ups). | 1238 // Clean up our style object's display and text decorations (among other fix ups). |
| 1238 adjustRenderStyle(state.style(), m_state.parentStyle(), 0); | 1239 adjustRenderStyle(state.style(), m_state.parentStyle(), 0); |
| 1239 | 1240 |
| 1240 // Start loading resources referenced by this style. | 1241 // Start loading resources referenced by this style. |
| 1241 m_styleResourceLoader.loadPendingResources(m_state.style(), m_state.elementS tyleResources()); | 1242 m_styleResourceLoader.loadPendingResources(m_state.style(), m_state.elementS tyleResources()); |
| 1242 | 1243 |
| 1243 document()->didAccessStyleResolver(); | 1244 document()->didAccessStyleResolver(); |
| 1244 | 1245 |
| 1245 // Now return the style. | 1246 // Now return the style. |
| 1246 return state.takeStyle(); | 1247 return state.takeStyleAndClear(); |
| 1247 } | 1248 } |
| 1248 | 1249 |
| 1249 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex) | 1250 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex) |
| 1250 { | 1251 { |
| 1251 m_state.initForStyleResolve(document(), document()->documentElement()); // m _rootElementStyle will be set to the document style. | 1252 m_state.initForStyleResolve(document(), document()->documentElement()); // m _rootElementStyle will be set to the document style. |
| 1252 | 1253 |
| 1253 m_state.setStyle(RenderStyle::create()); | 1254 m_state.setStyle(RenderStyle::create()); |
| 1254 m_state.style()->inheritFrom(m_state.rootElementStyle()); | 1255 m_state.style()->inheritFrom(m_state.rootElementStyle()); |
| 1255 | 1256 |
| 1256 PageRuleCollector collector(m_state, pageIndex); | 1257 PageRuleCollector collector(m_state, pageIndex); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1276 applyProperty(CSSPropertyLineHeight, m_state.lineHeightValue()); | 1277 applyProperty(CSSPropertyLineHeight, m_state.lineHeightValue()); |
| 1277 | 1278 |
| 1278 applyMatchedProperties<LowPriorityProperties>(result, false, 0, result.match edProperties.size() - 1, inheritedOnly); | 1279 applyMatchedProperties<LowPriorityProperties>(result, false, 0, result.match edProperties.size() - 1, inheritedOnly); |
| 1279 | 1280 |
| 1280 // Start loading resources referenced by this style. | 1281 // Start loading resources referenced by this style. |
| 1281 m_styleResourceLoader.loadPendingResources(m_state.style(), m_state.elementS tyleResources()); | 1282 m_styleResourceLoader.loadPendingResources(m_state.style(), m_state.elementS tyleResources()); |
| 1282 | 1283 |
| 1283 document()->didAccessStyleResolver(); | 1284 document()->didAccessStyleResolver(); |
| 1284 | 1285 |
| 1285 // Now return the style. | 1286 // Now return the style. |
| 1286 return m_state.takeStyle(); | 1287 return m_state.takeStyleAndClear(); |
| 1287 } | 1288 } |
| 1288 | 1289 |
| 1289 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() | 1290 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() |
| 1290 { | 1291 { |
| 1291 m_state.setStyle(RenderStyle::create()); | 1292 m_state.setStyle(RenderStyle::create()); |
| 1292 // Make sure our fonts are initialized if we don't inherit them from our par ent style. | 1293 // Make sure our fonts are initialized if we don't inherit them from our par ent style. |
| 1293 if (Settings* settings = documentSettings()) { | 1294 if (Settings* settings = documentSettings()) { |
| 1294 initializeFontStyle(settings); | 1295 initializeFontStyle(settings); |
| 1295 m_state.style()->font().update(fontSelector()); | 1296 m_state.style()->font().update(fontSelector()); |
| 1296 } else | 1297 } else |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1719 matchUserRules(collector, rulesToInclude & EmptyCSSRules); | 1720 matchUserRules(collector, rulesToInclude & EmptyCSSRules); |
| 1720 } | 1721 } |
| 1721 | 1722 |
| 1722 if (m_matchAuthorAndUserStyles && (rulesToInclude & AuthorCSSRules)) { | 1723 if (m_matchAuthorAndUserStyles && (rulesToInclude & AuthorCSSRules)) { |
| 1723 collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules)); | 1724 collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules)); |
| 1724 | 1725 |
| 1725 // Check the rules in author sheets. | 1726 // Check the rules in author sheets. |
| 1726 matchAuthorRules(collector, rulesToInclude & EmptyCSSRules); | 1727 matchAuthorRules(collector, rulesToInclude & EmptyCSSRules); |
| 1727 } | 1728 } |
| 1728 | 1729 |
| 1730 m_state.clear(); | |
| 1729 return collector.matchedRuleList(); | 1731 return collector.matchedRuleList(); |
| 1730 } | 1732 } |
| 1731 | 1733 |
| 1732 // ----------------------------------------------------------------------------- -------- | 1734 // ----------------------------------------------------------------------------- -------- |
| 1733 // this is mostly boring stuff on how to apply a certain rule to the renderstyle ... | 1735 // this is mostly boring stuff on how to apply a certain rule to the renderstyle ... |
| 1734 | 1736 |
| 1735 template <StyleResolver::StyleApplicationPass pass> | 1737 template <StyleResolver::StyleApplicationPass pass> |
| 1736 void StyleResolver::applyAnimatedProperties(const Element* target) | 1738 void StyleResolver::applyAnimatedProperties(const Element* target) |
| 1737 { | 1739 { |
| 1738 if (!target->hasActiveAnimations()) | 1740 if (!target->hasActiveAnimations()) |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2047 if (!MatchedPropertiesCache::isCacheable(state.element(), state.style(), sta te.parentStyle())) | 2049 if (!MatchedPropertiesCache::isCacheable(state.element(), state.style(), sta te.parentStyle())) |
| 2048 return; | 2050 return; |
| 2049 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHash, matchResult); | 2051 m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHash, matchResult); |
| 2050 } | 2052 } |
| 2051 | 2053 |
| 2052 void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, Rend erStyle* style) | 2054 void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, Rend erStyle* style) |
| 2053 { | 2055 { |
| 2054 m_state.initForStyleResolve(document(), 0, style); | 2056 m_state.initForStyleResolve(document(), 0, style); |
| 2055 m_state.setStyle(style); | 2057 m_state.setStyle(style); |
| 2056 applyPropertyToCurrentStyle(id, value); | 2058 applyPropertyToCurrentStyle(id, value); |
| 2059 m_state.clear(); | |
| 2057 } | 2060 } |
| 2058 | 2061 |
| 2059 void StyleResolver::applyPropertyToCurrentStyle(CSSPropertyID id, CSSValue* valu e) | 2062 void StyleResolver::applyPropertyToCurrentStyle(CSSPropertyID id, CSSValue* valu e) |
| 2060 { | 2063 { |
| 2061 if (value) | 2064 if (value) |
| 2062 applyProperty(id, value); | 2065 applyProperty(id, value); |
| 2063 } | 2066 } |
| 2064 | 2067 |
| 2065 static bool hasVariableReference(CSSValue* value) | 2068 static bool hasVariableReference(CSSValue* value) |
| 2066 { | 2069 { |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2395 void CachedMatchedProperties::reportMemoryUsage(MemoryObjectInfo* memoryObjectIn fo) const | 2398 void CachedMatchedProperties::reportMemoryUsage(MemoryObjectInfo* memoryObjectIn fo) const |
| 2396 { | 2399 { |
| 2397 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); | 2400 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); |
| 2398 info.addMember(matchedProperties, "matchedProperties"); | 2401 info.addMember(matchedProperties, "matchedProperties"); |
| 2399 info.addMember(ranges, "ranges"); | 2402 info.addMember(ranges, "ranges"); |
| 2400 info.addMember(renderStyle, "renderStyle"); | 2403 info.addMember(renderStyle, "renderStyle"); |
| 2401 info.addMember(parentRenderStyle, "parentRenderStyle"); | 2404 info.addMember(parentRenderStyle, "parentRenderStyle"); |
| 2402 } | 2405 } |
| 2403 | 2406 |
| 2404 } // namespace WebCore | 2407 } // namespace WebCore |
| OLD | NEW |