Chromium Code Reviews| Index: Source/core/css/resolver/StyleResolver.cpp |
| diff --git a/Source/core/css/resolver/StyleResolver.cpp b/Source/core/css/resolver/StyleResolver.cpp |
| index 514ed369fdae71b51d3270bd2083b2e66729e5c4..936062282a4c39519672c5098339b509b137b3fe 100644 |
| --- a/Source/core/css/resolver/StyleResolver.cpp |
| +++ b/Source/core/css/resolver/StyleResolver.cpp |
| @@ -1013,13 +1013,11 @@ PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS |
| } |
| StyleResolverState& state = m_state; |
| - state.initForStyleResolve(document(), element, childIndex, defaultParent, regionForStyling); |
| + StyleResolverState::ScopedStyleResolution resolution(&state, document(), element, childIndex, defaultParent, regionForStyling); |
| if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoint()) { |
| - RenderStyle* sharedStyle = locateSharedStyle(); |
| - if (sharedStyle) { |
| - state.clear(); |
| - return sharedStyle; |
| - } |
| + RefPtr<RenderStyle> sharedStyle = locateSharedStyle(); |
| + if (sharedStyle) |
| + return sharedStyle.release(); |
| } |
| if (state.parentStyle()) { |
| @@ -1069,8 +1067,6 @@ PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS |
| // Clean up our style object's display and text decorations (among other fixups). |
| adjustRenderStyle(state.style(), state.parentStyle(), element); |
| - state.clear(); // Clear out for the next resolve. |
| - |
| document()->didAccessStyleResolver(); |
| if (element->hasTagName(bodyTag)) |
| @@ -1080,8 +1076,10 @@ PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS |
| return state.takeStyle(); |
| } |
| -PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(const RenderStyle* elementStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue) |
| +PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(Element* e, const RenderStyle* 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
|
| { |
| + StyleResolverState::ScopedStyleResolution resolution(&m_state, document(), e); |
| + |
| MatchResult result; |
| if (keyframe->properties()) |
| result.addMatchedProperties(keyframe->properties()); |
| @@ -1157,12 +1155,10 @@ void StyleResolver::keyframeStylesForAnimation(Element* e, const RenderStyle* el |
| const Vector<RefPtr<StyleKeyframe> >& keyframes = keyframesRule->keyframes(); |
| for (unsigned i = 0; i < keyframes.size(); ++i) { |
| // Apply the declaration to the style. This is a simplified version of the logic in styleForElement |
| - m_state.initForStyleResolve(document(), e); |
| - |
| const StyleKeyframe* keyframe = keyframes[i].get(); |
| KeyframeValue keyframeValue(0, 0); |
| - keyframeValue.setStyle(styleForKeyframe(elementStyle, keyframe, keyframeValue)); |
| + keyframeValue.setStyle(styleForKeyframe(e, elementStyle, keyframe, keyframeValue)); |
| // Add this keyframe style to all the indicated key times |
| Vector<float> keys; |
| @@ -1182,7 +1178,7 @@ void StyleResolver::keyframeStylesForAnimation(Element* e, const RenderStyle* el |
| zeroPercentKeyframe->setKeyText("0%"); |
| } |
| KeyframeValue keyframeValue(0, 0); |
| - keyframeValue.setStyle(styleForKeyframe(elementStyle, zeroPercentKeyframe, keyframeValue)); |
| + keyframeValue.setStyle(styleForKeyframe(e, elementStyle, zeroPercentKeyframe, keyframeValue)); |
| list.insert(keyframeValue); |
| } |
| @@ -1194,7 +1190,7 @@ void StyleResolver::keyframeStylesForAnimation(Element* e, const RenderStyle* el |
| hundredPercentKeyframe->setKeyText("100%"); |
| } |
| KeyframeValue keyframeValue(1, 0); |
| - keyframeValue.setStyle(styleForKeyframe(elementStyle, hundredPercentKeyframe, keyframeValue)); |
| + keyframeValue.setStyle(styleForKeyframe(e, elementStyle, hundredPercentKeyframe, keyframeValue)); |
| list.insert(keyframeValue); |
| } |
| } |
| @@ -1207,7 +1203,7 @@ PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const P |
| StyleResolverState& state = m_state; |
| - state.initForStyleResolve(document(), e, 0, parentStyle); |
| + StyleResolverState::ScopedStyleResolution resolution(&state, document(), e, 0, parentStyle); |
| if (pseudoStyleRequest.allowsInheritance(state.parentStyle())) { |
| state.setStyle(RenderStyle::create()); |
| @@ -1251,7 +1247,7 @@ PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const P |
| PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex) |
| { |
| - m_state.initForStyleResolve(document(), document()->documentElement()); // m_rootElementStyle will be set to the document style. |
| + StyleResolverState::ScopedStyleResolution resolution(&m_state, document(), document()->documentElement()); // m_rootElementStyle will be set to the document style. |
| m_state.setStyle(RenderStyle::create()); |
| m_state.style()->inheritFrom(m_state.rootElementStyle()); |
| @@ -1707,7 +1703,7 @@ PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, Ps |
| if (!e || !e->document()->haveStylesheetsLoaded()) |
| return 0; |
| - m_state.initForStyleResolve(document(), e); |
| + StyleResolverState::ScopedStyleResolution resolution(&m_state, document(), e); |
| ElementRuleCollector collector(this, m_state); |
| collector.setMode(SelectorChecker::CollectingRules); |
| @@ -2058,17 +2054,30 @@ void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const |
| m_matchedPropertiesCache.add(state.style(), state.parentStyle(), cacheHash, matchResult); |
| } |
| -void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, RenderStyle* style) |
| -{ |
| - m_state.initForStyleResolve(document(), 0, 0, style); |
| - m_state.setStyle(style); |
| - applyPropertyToCurrentStyle(id, value); |
| -} |
| +StyleResolver::PropertyValue::PropertyValue(CSSPropertyID id, const StylePropertySet& propertySet) |
| + : property(id), value(propertySet.getPropertyCSSValue(id).get()) |
| +{ } |
| -void StyleResolver::applyPropertyToCurrentStyle(CSSPropertyID id, CSSValue* value) |
| +void StyleResolver::applyPropertiesToStyle(const PropertyValue* properties, size_t count, RenderStyle* style) |
| { |
| - if (value) |
| - applyProperty(id, value); |
| + StyleResolverState::ScopedStyleResolution resolution(&m_state, document(), 0, 0, style); |
| + m_state.setStyle(style); |
| + for (size_t i = 0; i < count; ++i) { |
| + if (properties[i].value) { |
| + // As described in BUG66291, setting font-size and line-height on a font may entail a CSSPrimitiveValue::computeLengthDouble call, |
| + // which assumes the fontMetrics are available for the affected font, otherwise a crash occurs (see http://trac.webkit.org/changeset/96122). |
| + // The updateFont() call below updates the fontMetrics and ensure the proper setting of font-size and line-height. |
| + switch (properties[i].property) { |
| + case CSSPropertyFontSize: |
| + case CSSPropertyLineHeight: |
| + updateFont(); |
| + break; |
| + default: |
| + break; |
| + } |
| + applyProperty(properties[i].property, properties[i].value); |
| + } |
| + } |
| } |
| static bool hasVariableReference(CSSValue* value) |