Changeset 143556 in webkit


Ignore:
Timestamp:
Feb 20, 2013 7:39:42 PM (11 years ago)
Author:
tasak@google.com
Message:

[Refactoring] Make m_state an on-stack object
https://bugs.webkit.org/show_bug.cgi?id=109909

Reviewed by Antti Koivisto.

Mode m_state, an instance of StyleResolver::State, an on-stack object.
The state is only required in styleForElement, styleForKeyframe and
so on. No need to keep the state outside of those methods.

No new tests, because just refactoring.

  • css/BasicShapeFunctions.cpp:

(WebCore::convertToLength):
(WebCore::basicShapeForValue):

  • css/BasicShapeFunctions.h:

(WebCore):
Replaced StyleResolver* with StyleResolver::State&.

  • css/CSSGradientValue.cpp:

(WebCore::CSSGradientValue::gradientWithStylesResolved):

  • css/CSSGradientValue.h:

(CSSGradientValue):
Replaced StyleResolver* with StyleResolver::State&.

  • css/CSSToStyleMap.cpp:

(WebCore::CSSToStyleMap::style):
(WebCore::CSSToStyleMap::rootElementStyle):
(WebCore::CSSToStyleMap::useSVGZoomRules):
(WebCore::CSSToStyleMap::styleImage):

  • css/CSSToStyleMap.h:

(WebCore):
(WebCore::CSSToStyleMap::CSSToStyleMap):
(CSSToStyleMap):
Replaced StyleResolver* with StyleResolver::State&.

  • css/SVGCSSStyleSelector.cpp:

(WebCore::StyleResolver::applySVGProperty):
Replaced m_state with state which is given as an argument of
applySVGProperty.

  • css/StyleBuilder.cpp:

(WebCore::ApplyPropertyExpanding::applyInheritValue):
(WebCore::ApplyPropertyExpanding::applyInitialValue):
(WebCore::ApplyPropertyExpanding::applyValue):
(WebCore::ApplyPropertyDefaultBase::applyInheritValue):
(WebCore::ApplyPropertyDefaultBase::applyInitialValue):
(WebCore::ApplyPropertyDefaultBase::applyValue):
(WebCore::ApplyPropertyDefault::applyValue):
(WebCore::ApplyPropertyNumber::applyValue):
(WebCore::ApplyPropertyStyleImage::applyValue):
(WebCore::ApplyPropertyAuto::applyInheritValue):
(WebCore::ApplyPropertyAuto::applyInitialValue):
(WebCore::ApplyPropertyAuto::applyValue):
(WebCore::ApplyPropertyClip::convertToLength):
(WebCore::ApplyPropertyClip::applyInheritValue):
(WebCore::ApplyPropertyClip::applyInitialValue):
(WebCore::ApplyPropertyClip::applyValue):
(WebCore::ApplyPropertyColor::applyInheritValue):
(WebCore::ApplyPropertyColor::applyInitialValue):
(WebCore::ApplyPropertyColor::applyValue):
(WebCore::ApplyPropertyColor::applyColorValue):
(WebCore::ApplyPropertyDirection::applyValue):
(WebCore::ApplyPropertyLength::applyValue):
(WebCore::ApplyPropertyString::applyValue):
(WebCore::ApplyPropertyBorderRadius::applyValue):
(WebCore::ApplyPropertyFillLayer::applyInheritValue):
(WebCore::ApplyPropertyFillLayer::applyInitialValue):
(WebCore::ApplyPropertyFillLayer::applyValue):
(WebCore::ApplyPropertyComputeLength::applyValue):
(WebCore::ApplyPropertyFont::applyInheritValue):
(WebCore::ApplyPropertyFont::applyInitialValue):
(WebCore::ApplyPropertyFont::applyValue):
(WebCore::ApplyPropertyFontSize::applyInheritValue):
(WebCore::ApplyPropertyFontSize::applyInitialValue):
(WebCore::ApplyPropertyFontSize::applyValue):
(WebCore::ApplyPropertyFontWeight::applyValue):
(WebCore::ApplyPropertyFontVariantLigatures::applyInheritValue):
(WebCore::ApplyPropertyFontVariantLigatures::applyInitialValue):
(WebCore::ApplyPropertyFontVariantLigatures::applyValue):
(WebCore::ApplyPropertyBorderImage::applyValue):
(WebCore::ApplyPropertyBorderImageModifier::applyInheritValue):
(WebCore::ApplyPropertyBorderImageModifier::applyInitialValue):
(WebCore::ApplyPropertyBorderImageModifier::applyValue):
(WebCore::ApplyPropertyBorderImageSource::applyValue):
(WebCore::ApplyPropertyCounter::emptyFunction):
(WebCore::ApplyPropertyCounter::applyInheritValue):
(WebCore::ApplyPropertyCounter::applyValue):
(WebCore::ApplyPropertyCursor::applyInheritValue):
(WebCore::ApplyPropertyCursor::applyInitialValue):
(WebCore::ApplyPropertyCursor::applyValue):
(WebCore::ApplyPropertyTextAlign::applyValue):
(WebCore::ApplyPropertyTextDecoration::applyValue):
(WebCore::ApplyPropertyLineHeight::applyValue):
(WebCore::ApplyPropertyPageSize::applyInheritValue):
(WebCore::ApplyPropertyPageSize::applyInitialValue):
(WebCore::ApplyPropertyPageSize::applyValue):
(WebCore::ApplyPropertyTextEmphasisStyle::applyInheritValue):
(WebCore::ApplyPropertyTextEmphasisStyle::applyInitialValue):
(WebCore::ApplyPropertyTextEmphasisStyle::applyValue):
(WebCore::ApplyPropertyAnimation::map):
(WebCore::ApplyPropertyAnimation::applyInheritValue):
(WebCore::ApplyPropertyAnimation::applyInitialValue):
(WebCore::ApplyPropertyAnimation::applyValue):
(WebCore::ApplyPropertyOutlineStyle::applyInheritValue):
(WebCore::ApplyPropertyOutlineStyle::applyInitialValue):
(WebCore::ApplyPropertyOutlineStyle::applyValue):
(WebCore::ApplyPropertyResize::applyValue):
(WebCore::ApplyPropertyVerticalAlign::applyValue):
(WebCore::ApplyPropertyAspectRatio::applyInheritValue):
(WebCore::ApplyPropertyAspectRatio::applyInitialValue):
(WebCore::ApplyPropertyAspectRatio::applyValue):
(WebCore::ApplyPropertyZoom::resetEffectiveZoom):
(WebCore::ApplyPropertyZoom::applyInheritValue):
(WebCore::ApplyPropertyZoom::applyInitialValue):
(WebCore::ApplyPropertyZoom::applyValue):
(WebCore::ApplyPropertyDisplay::isValidDisplayValue):
(WebCore::ApplyPropertyDisplay::applyInheritValue):
(WebCore::ApplyPropertyDisplay::applyInitialValue):
(WebCore::ApplyPropertyDisplay::applyValue):
(WebCore::ApplyPropertyClipPath::applyValue):
(WebCore::ApplyPropertyExclusionShape::applyValue):
(WebCore::ApplyPropertyImageResolution::applyInheritValue):
(WebCore::ApplyPropertyImageResolution::applyInitialValue):
(WebCore::ApplyPropertyImageResolution::applyValue):

  • css/StyleBuilder.h:

(WebCore):
(PropertyHandler):
(WebCore::PropertyHandler::applyInheritValue):
(WebCore::PropertyHandler::applyInitialValue):
(WebCore::PropertyHandler::applyValue):
Replaced StyleResolver* with StyleResolver::State&.

  • css/StyleResolver.cpp:

(WebCore):
(WebCore::StyleResolver::StyleResolver):
Removed m_styleMap. Now m_styleMap is an on-stack object.
(WebCore::StyleResolver::collectMatchingRules):
(WebCore::StyleResolver::collectMatchingRulesForRegion):
(WebCore::StyleResolver::sortAndTransferMatchedRules):
(WebCore::StyleResolver::matchScopedAuthorRules):
(WebCore::StyleResolver::styleSharingCandidateMatchesHostRules):
(WebCore::StyleResolver::matchHostRules):
(WebCore::StyleResolver::matchAuthorRules):
(WebCore::StyleResolver::matchUserRules):
(WebCore::StyleResolver::matchUARules):
(WebCore::StyleResolver::collectMatchingRulesForList):
(WebCore::StyleResolver::sortMatchedRules):
(WebCore::StyleResolver::matchAllRules):
(WebCore::StyleResolver::initElement):
(WebCore::StyleResolver::styleSharingCandidateMatchesRuleSet):
(WebCore::StyleResolver::canShareStyleWithControl):
(WebCore::StyleResolver::sharingCandidateHasIdenticalStyleAffectingAttributes):
(WebCore::StyleResolver::canShareStyleWithElement):
(WebCore::StyleResolver::findSiblingForStyleSharing):
(WebCore::StyleResolver::locateSharedStyle):
(WebCore::StyleResolver::styleForElement):
(WebCore::StyleResolver::styleForKeyframe):
(WebCore::StyleResolver::keyframeStylesForAnimation):
(WebCore::StyleResolver::pseudoStyleForElement):
(WebCore::StyleResolver::styleForPage):
(WebCore::StyleResolver::defaultStyleForElement):
(WebCore::StyleResolver::adjustRenderStyle):
(WebCore::StyleResolver::updateFont):
(WebCore::StyleResolver::pseudoStyleRulesForElement):
(WebCore::StyleResolver::ruleMatches):
(WebCore::StyleResolver::checkRegionSelector):
(WebCore::StyleResolver::applyProperties):
(WebCore::StyleResolver::applyMatchedProperties):
(WebCore::StyleResolver::isLeftPage):
(WebCore::StyleResolver::applyPropertyWithNullCheck):
(WebCore::StyleResolver::applyFontPropertyToStyle):
(WebCore::StyleResolver::resolveVariables):
(WebCore::StyleResolver::applyProperty):
(WebCore::StyleResolver::styleImage):
(WebCore::StyleResolver::cachedOrPendingFromValue):
(WebCore::StyleResolver::generatedOrPendingFromValue):
(WebCore::StyleResolver::setOrPendingFromValue):
(WebCore::StyleResolver::cursorOrPendingFromValue):
(WebCore::StyleResolver::checkForTextSizeAdjust):
(WebCore::StyleResolver::checkForZoomChange):
(WebCore::StyleResolver::checkForGenericFamilyChange):
(WebCore::StyleResolver::initializeFontStyle):
(WebCore::StyleResolver::setFontSize):
(WebCore::StyleResolver::colorFromPrimitiveValue):
(WebCore::StyleResolver::loadPendingSVGDocuments):
(WebCore::StyleResolver::styleShader):
(WebCore::StyleResolver::cachedOrPendingStyleShaderFromValue):
(WebCore::StyleResolver::loadPendingShaders):
(WebCore::StyleResolver::parseCustomFilterTransformParameter):
(WebCore::StyleResolver::parseCustomFilterParameter):
(WebCore::StyleResolver::parseCustomFilterParameterList):
(WebCore::StyleResolver::createCustomFilterOperationWithInlineSyntax):
(WebCore::StyleResolver::createCustomFilterOperation):
(WebCore::StyleResolver::createFilterOperations):
(WebCore::StyleResolver::loadPendingImage):
(WebCore::StyleResolver::loadPendingImages):
(WebCore::StyleResolver::loadPendingResources):
Just replaced m_state with state and added one more parameter to
provide the state.
(WebCore::StyleResolver::reportMemoryUsage):
Since m_state was removed, removed a code for reporting m_state's
memory usage.

  • css/StyleResolver.h:

(StyleResolver):
(WebCore::StyleResolver::isRightPage):
(WebCore::StyleResolver::State::State):
(WebCore::StyleResolver::State::document):
Since State::m_element is not always available (sometimes, 0),
added m_document to State and modified to return the m_document.
(WebCore::StyleResolver::State::useSVGZoomRules):
Moved StyleResolver to State.
(State):

  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::setFont):
Moved the code, updating a style by using a given StylePropertySet,
to StyleResolver.

Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r143555 r143556  
     12013-02-20  Takashi Sakamoto  <tasak@google.com>
     2
     3        [Refactoring] Make m_state an on-stack object
     4        https://bugs.webkit.org/show_bug.cgi?id=109909
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Mode m_state, an instance of StyleResolver::State, an on-stack object.
     9        The state is only required in styleForElement, styleForKeyframe and
     10        so on. No need to keep the state outside of those methods.
     11
     12        No new tests, because just refactoring.
     13
     14        * css/BasicShapeFunctions.cpp:
     15        (WebCore::convertToLength):
     16        (WebCore::basicShapeForValue):
     17        * css/BasicShapeFunctions.h:
     18        (WebCore):
     19        Replaced StyleResolver* with StyleResolver::State&.
     20        * css/CSSGradientValue.cpp:
     21        (WebCore::CSSGradientValue::gradientWithStylesResolved):
     22        * css/CSSGradientValue.h:
     23        (CSSGradientValue):
     24        Replaced StyleResolver* with StyleResolver::State&.
     25        * css/CSSToStyleMap.cpp:
     26        (WebCore::CSSToStyleMap::style):
     27        (WebCore::CSSToStyleMap::rootElementStyle):
     28        (WebCore::CSSToStyleMap::useSVGZoomRules):
     29        (WebCore::CSSToStyleMap::styleImage):
     30        * css/CSSToStyleMap.h:
     31        (WebCore):
     32        (WebCore::CSSToStyleMap::CSSToStyleMap):
     33        (CSSToStyleMap):
     34        Replaced StyleResolver* with StyleResolver::State&.
     35        * css/SVGCSSStyleSelector.cpp:
     36        (WebCore::StyleResolver::applySVGProperty):
     37        Replaced m_state with state which is given as an argument of
     38        applySVGProperty.
     39        * css/StyleBuilder.cpp:
     40        (WebCore::ApplyPropertyExpanding::applyInheritValue):
     41        (WebCore::ApplyPropertyExpanding::applyInitialValue):
     42        (WebCore::ApplyPropertyExpanding::applyValue):
     43        (WebCore::ApplyPropertyDefaultBase::applyInheritValue):
     44        (WebCore::ApplyPropertyDefaultBase::applyInitialValue):
     45        (WebCore::ApplyPropertyDefaultBase::applyValue):
     46        (WebCore::ApplyPropertyDefault::applyValue):
     47        (WebCore::ApplyPropertyNumber::applyValue):
     48        (WebCore::ApplyPropertyStyleImage::applyValue):
     49        (WebCore::ApplyPropertyAuto::applyInheritValue):
     50        (WebCore::ApplyPropertyAuto::applyInitialValue):
     51        (WebCore::ApplyPropertyAuto::applyValue):
     52        (WebCore::ApplyPropertyClip::convertToLength):
     53        (WebCore::ApplyPropertyClip::applyInheritValue):
     54        (WebCore::ApplyPropertyClip::applyInitialValue):
     55        (WebCore::ApplyPropertyClip::applyValue):
     56        (WebCore::ApplyPropertyColor::applyInheritValue):
     57        (WebCore::ApplyPropertyColor::applyInitialValue):
     58        (WebCore::ApplyPropertyColor::applyValue):
     59        (WebCore::ApplyPropertyColor::applyColorValue):
     60        (WebCore::ApplyPropertyDirection::applyValue):
     61        (WebCore::ApplyPropertyLength::applyValue):
     62        (WebCore::ApplyPropertyString::applyValue):
     63        (WebCore::ApplyPropertyBorderRadius::applyValue):
     64        (WebCore::ApplyPropertyFillLayer::applyInheritValue):
     65        (WebCore::ApplyPropertyFillLayer::applyInitialValue):
     66        (WebCore::ApplyPropertyFillLayer::applyValue):
     67        (WebCore::ApplyPropertyComputeLength::applyValue):
     68        (WebCore::ApplyPropertyFont::applyInheritValue):
     69        (WebCore::ApplyPropertyFont::applyInitialValue):
     70        (WebCore::ApplyPropertyFont::applyValue):
     71        (WebCore::ApplyPropertyFontSize::applyInheritValue):
     72        (WebCore::ApplyPropertyFontSize::applyInitialValue):
     73        (WebCore::ApplyPropertyFontSize::applyValue):
     74        (WebCore::ApplyPropertyFontWeight::applyValue):
     75        (WebCore::ApplyPropertyFontVariantLigatures::applyInheritValue):
     76        (WebCore::ApplyPropertyFontVariantLigatures::applyInitialValue):
     77        (WebCore::ApplyPropertyFontVariantLigatures::applyValue):
     78        (WebCore::ApplyPropertyBorderImage::applyValue):
     79        (WebCore::ApplyPropertyBorderImageModifier::applyInheritValue):
     80        (WebCore::ApplyPropertyBorderImageModifier::applyInitialValue):
     81        (WebCore::ApplyPropertyBorderImageModifier::applyValue):
     82        (WebCore::ApplyPropertyBorderImageSource::applyValue):
     83        (WebCore::ApplyPropertyCounter::emptyFunction):
     84        (WebCore::ApplyPropertyCounter::applyInheritValue):
     85        (WebCore::ApplyPropertyCounter::applyValue):
     86        (WebCore::ApplyPropertyCursor::applyInheritValue):
     87        (WebCore::ApplyPropertyCursor::applyInitialValue):
     88        (WebCore::ApplyPropertyCursor::applyValue):
     89        (WebCore::ApplyPropertyTextAlign::applyValue):
     90        (WebCore::ApplyPropertyTextDecoration::applyValue):
     91        (WebCore::ApplyPropertyLineHeight::applyValue):
     92        (WebCore::ApplyPropertyPageSize::applyInheritValue):
     93        (WebCore::ApplyPropertyPageSize::applyInitialValue):
     94        (WebCore::ApplyPropertyPageSize::applyValue):
     95        (WebCore::ApplyPropertyTextEmphasisStyle::applyInheritValue):
     96        (WebCore::ApplyPropertyTextEmphasisStyle::applyInitialValue):
     97        (WebCore::ApplyPropertyTextEmphasisStyle::applyValue):
     98        (WebCore::ApplyPropertyAnimation::map):
     99        (WebCore::ApplyPropertyAnimation::applyInheritValue):
     100        (WebCore::ApplyPropertyAnimation::applyInitialValue):
     101        (WebCore::ApplyPropertyAnimation::applyValue):
     102        (WebCore::ApplyPropertyOutlineStyle::applyInheritValue):
     103        (WebCore::ApplyPropertyOutlineStyle::applyInitialValue):
     104        (WebCore::ApplyPropertyOutlineStyle::applyValue):
     105        (WebCore::ApplyPropertyResize::applyValue):
     106        (WebCore::ApplyPropertyVerticalAlign::applyValue):
     107        (WebCore::ApplyPropertyAspectRatio::applyInheritValue):
     108        (WebCore::ApplyPropertyAspectRatio::applyInitialValue):
     109        (WebCore::ApplyPropertyAspectRatio::applyValue):
     110        (WebCore::ApplyPropertyZoom::resetEffectiveZoom):
     111        (WebCore::ApplyPropertyZoom::applyInheritValue):
     112        (WebCore::ApplyPropertyZoom::applyInitialValue):
     113        (WebCore::ApplyPropertyZoom::applyValue):
     114        (WebCore::ApplyPropertyDisplay::isValidDisplayValue):
     115        (WebCore::ApplyPropertyDisplay::applyInheritValue):
     116        (WebCore::ApplyPropertyDisplay::applyInitialValue):
     117        (WebCore::ApplyPropertyDisplay::applyValue):
     118        (WebCore::ApplyPropertyClipPath::applyValue):
     119        (WebCore::ApplyPropertyExclusionShape::applyValue):
     120        (WebCore::ApplyPropertyImageResolution::applyInheritValue):
     121        (WebCore::ApplyPropertyImageResolution::applyInitialValue):
     122        (WebCore::ApplyPropertyImageResolution::applyValue):
     123        * css/StyleBuilder.h:
     124        (WebCore):
     125        (PropertyHandler):
     126        (WebCore::PropertyHandler::applyInheritValue):
     127        (WebCore::PropertyHandler::applyInitialValue):
     128        (WebCore::PropertyHandler::applyValue):
     129        Replaced StyleResolver* with StyleResolver::State&.
     130        * css/StyleResolver.cpp:
     131        (WebCore):
     132        (WebCore::StyleResolver::StyleResolver):
     133        Removed m_styleMap. Now m_styleMap is an on-stack object.
     134        (WebCore::StyleResolver::collectMatchingRules):
     135        (WebCore::StyleResolver::collectMatchingRulesForRegion):
     136        (WebCore::StyleResolver::sortAndTransferMatchedRules):
     137        (WebCore::StyleResolver::matchScopedAuthorRules):
     138        (WebCore::StyleResolver::styleSharingCandidateMatchesHostRules):
     139        (WebCore::StyleResolver::matchHostRules):
     140        (WebCore::StyleResolver::matchAuthorRules):
     141        (WebCore::StyleResolver::matchUserRules):
     142        (WebCore::StyleResolver::matchUARules):
     143        (WebCore::StyleResolver::collectMatchingRulesForList):
     144        (WebCore::StyleResolver::sortMatchedRules):
     145        (WebCore::StyleResolver::matchAllRules):
     146        (WebCore::StyleResolver::initElement):
     147        (WebCore::StyleResolver::styleSharingCandidateMatchesRuleSet):
     148        (WebCore::StyleResolver::canShareStyleWithControl):
     149        (WebCore::StyleResolver::sharingCandidateHasIdenticalStyleAffectingAttributes):
     150        (WebCore::StyleResolver::canShareStyleWithElement):
     151        (WebCore::StyleResolver::findSiblingForStyleSharing):
     152        (WebCore::StyleResolver::locateSharedStyle):
     153        (WebCore::StyleResolver::styleForElement):
     154        (WebCore::StyleResolver::styleForKeyframe):
     155        (WebCore::StyleResolver::keyframeStylesForAnimation):
     156        (WebCore::StyleResolver::pseudoStyleForElement):
     157        (WebCore::StyleResolver::styleForPage):
     158        (WebCore::StyleResolver::defaultStyleForElement):
     159        (WebCore::StyleResolver::adjustRenderStyle):
     160        (WebCore::StyleResolver::updateFont):
     161        (WebCore::StyleResolver::pseudoStyleRulesForElement):
     162        (WebCore::StyleResolver::ruleMatches):
     163        (WebCore::StyleResolver::checkRegionSelector):
     164        (WebCore::StyleResolver::applyProperties):
     165        (WebCore::StyleResolver::applyMatchedProperties):
     166        (WebCore::StyleResolver::isLeftPage):
     167        (WebCore::StyleResolver::applyPropertyWithNullCheck):
     168        (WebCore::StyleResolver::applyFontPropertyToStyle):
     169        (WebCore::StyleResolver::resolveVariables):
     170        (WebCore::StyleResolver::applyProperty):
     171        (WebCore::StyleResolver::styleImage):
     172        (WebCore::StyleResolver::cachedOrPendingFromValue):
     173        (WebCore::StyleResolver::generatedOrPendingFromValue):
     174        (WebCore::StyleResolver::setOrPendingFromValue):
     175        (WebCore::StyleResolver::cursorOrPendingFromValue):
     176        (WebCore::StyleResolver::checkForTextSizeAdjust):
     177        (WebCore::StyleResolver::checkForZoomChange):
     178        (WebCore::StyleResolver::checkForGenericFamilyChange):
     179        (WebCore::StyleResolver::initializeFontStyle):
     180        (WebCore::StyleResolver::setFontSize):
     181        (WebCore::StyleResolver::colorFromPrimitiveValue):
     182        (WebCore::StyleResolver::loadPendingSVGDocuments):
     183        (WebCore::StyleResolver::styleShader):
     184        (WebCore::StyleResolver::cachedOrPendingStyleShaderFromValue):
     185        (WebCore::StyleResolver::loadPendingShaders):
     186        (WebCore::StyleResolver::parseCustomFilterTransformParameter):
     187        (WebCore::StyleResolver::parseCustomFilterParameter):
     188        (WebCore::StyleResolver::parseCustomFilterParameterList):
     189        (WebCore::StyleResolver::createCustomFilterOperationWithInlineSyntax):
     190        (WebCore::StyleResolver::createCustomFilterOperation):
     191        (WebCore::StyleResolver::createFilterOperations):
     192        (WebCore::StyleResolver::loadPendingImage):
     193        (WebCore::StyleResolver::loadPendingImages):
     194        (WebCore::StyleResolver::loadPendingResources):
     195        Just replaced m_state with state and added one more parameter to
     196        provide the state.
     197        (WebCore::StyleResolver::reportMemoryUsage):
     198        Since m_state was removed, removed a code for reporting m_state's
     199        memory usage.
     200        * css/StyleResolver.h:
     201        (StyleResolver):
     202        (WebCore::StyleResolver::isRightPage):
     203        (WebCore::StyleResolver::State::State):
     204        (WebCore::StyleResolver::State::document):
     205        Since State::m_element is not always available (sometimes, 0),
     206        added m_document to State and modified to return the m_document.
     207        (WebCore::StyleResolver::State::useSVGZoomRules):
     208        Moved StyleResolver to State.
     209        (State):
     210        * html/canvas/CanvasRenderingContext2D.cpp:
     211        (WebCore::CanvasRenderingContext2D::setFont):
     212        Moved the code, updating a style by using a given StylePropertySet,
     213        to StyleResolver.
     214
    12152013-02-20  Ojan Vafai  <ojan@chromium.org>
    2216
  • trunk/Source/WebCore/css/BasicShapeFunctions.cpp

    r127155 r143556  
    3535#include "CSSPrimitiveValueMappings.h"
    3636#include "CSSValuePool.h"
    37 #include "StyleResolver.h"
    3837
    3938namespace WebCore {
     
    101100}
    102101
    103 static Length convertToLength(const StyleResolver* styleResolver, CSSPrimitiveValue* value)
     102static Length convertToLength(const StyleResolver::State& state, CSSPrimitiveValue* value)
    104103{
    105     return value->convertToLength<FixedIntegerConversion | FixedFloatConversion | PercentConversion | ViewportPercentageConversion>(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom());
     104    return value->convertToLength<FixedIntegerConversion | FixedFloatConversion | PercentConversion | ViewportPercentageConversion>(state.style(), state.rootElementStyle(), state.style()->effectiveZoom());
    106105}
    107106
    108 PassRefPtr<BasicShape> basicShapeForValue(const StyleResolver* styleResolver, const CSSBasicShape* basicShapeValue)
     107PassRefPtr<BasicShape> basicShapeForValue(const StyleResolver::State& state, const CSSBasicShape* basicShapeValue)
    109108{
    110109    RefPtr<BasicShape> basicShape;
     
    115114        RefPtr<BasicShapeRectangle> rect = BasicShapeRectangle::create();
    116115
    117         rect->setX(convertToLength(styleResolver, rectValue->x()));
    118         rect->setY(convertToLength(styleResolver, rectValue->y()));
    119         rect->setWidth(convertToLength(styleResolver, rectValue->width()));
    120         rect->setHeight(convertToLength(styleResolver, rectValue->height()));
     116        rect->setX(convertToLength(state, rectValue->x()));
     117        rect->setY(convertToLength(state, rectValue->y()));
     118        rect->setWidth(convertToLength(state, rectValue->width()));
     119        rect->setHeight(convertToLength(state, rectValue->height()));
    121120        if (rectValue->radiusX()) {
    122             rect->setCornerRadiusX(convertToLength(styleResolver, rectValue->radiusX()));
     121            rect->setCornerRadiusX(convertToLength(state, rectValue->radiusX()));
    123122            if (rectValue->radiusY())
    124                 rect->setCornerRadiusY(convertToLength(styleResolver, rectValue->radiusY()));
     123                rect->setCornerRadiusY(convertToLength(state, rectValue->radiusY()));
    125124        }
    126125        basicShape = rect.release();
     
    131130        RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create();
    132131
    133         circle->setCenterX(convertToLength(styleResolver, circleValue->centerX()));
    134         circle->setCenterY(convertToLength(styleResolver, circleValue->centerY()));
    135         circle->setRadius(convertToLength(styleResolver, circleValue->radius()));
     132        circle->setCenterX(convertToLength(state, circleValue->centerX()));
     133        circle->setCenterY(convertToLength(state, circleValue->centerY()));
     134        circle->setRadius(convertToLength(state, circleValue->radius()));
    136135
    137136        basicShape = circle.release();
     
    142141        RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create();
    143142
    144         ellipse->setCenterX(convertToLength(styleResolver, ellipseValue->centerX()));
    145         ellipse->setCenterY(convertToLength(styleResolver, ellipseValue->centerY()));
    146         ellipse->setRadiusX(convertToLength(styleResolver, ellipseValue->radiusX()));
    147         ellipse->setRadiusY(convertToLength(styleResolver, ellipseValue->radiusY()));
     143        ellipse->setCenterX(convertToLength(state, ellipseValue->centerX()));
     144        ellipse->setCenterY(convertToLength(state, ellipseValue->centerY()));
     145        ellipse->setRadiusX(convertToLength(state, ellipseValue->radiusX()));
     146        ellipse->setRadiusY(convertToLength(state, ellipseValue->radiusY()));
    148147
    149148        basicShape = ellipse.release();
     
    157156        const Vector<RefPtr<CSSPrimitiveValue> >& values = polygonValue->values();
    158157        for (unsigned i = 0; i < values.size(); i += 2)
    159             polygon->appendPoint(convertToLength(styleResolver, values.at(i).get()), convertToLength(styleResolver, values.at(i + 1).get()));
     158            polygon->appendPoint(convertToLength(state, values.at(i).get()), convertToLength(state, values.at(i + 1).get()));
    160159
    161160        basicShape = polygon.release();
  • trunk/Source/WebCore/css/BasicShapeFunctions.h

    r127155 r143556  
    3131#define BasicShapeFunctions_h
    3232
     33#include "StyleResolver.h"
    3334#include <wtf/PassRefPtr.h>
    3435
     
    3839class CSSBasicShape;
    3940class CSSValue;
    40 class StyleResolver;
    4141
    4242PassRefPtr<CSSValue> valueForBasicShape(const BasicShape*);
    43 PassRefPtr<BasicShape> basicShapeForValue(const StyleResolver*, const CSSBasicShape*);
     43PassRefPtr<BasicShape> basicShapeForValue(const StyleResolver::State&, const CSSBasicShape*);
    4444
    4545}
  • trunk/Source/WebCore/css/CSSGradientValue.cpp

    r142444 r143556  
    3636#include "NodeRenderStyle.h"
    3737#include "RenderObject.h"
    38 #include "StyleResolver.h"
    3938#include "WebCoreMemoryInstrumentation.h"
    4039#include <wtf/MemoryInstrumentationVector.h>
     
    116115};
    117116
    118 PassRefPtr<CSSGradientValue> CSSGradientValue::gradientWithStylesResolved(StyleResolver* styleResolver)
     117PassRefPtr<CSSGradientValue> CSSGradientValue::gradientWithStylesResolved(StyleResolver::State& state)
    119118{
    120119    bool derived = false;
    121120    for (unsigned i = 0; i < m_stops.size(); i++)
    122         if (styleResolver->colorFromPrimitiveValueIsDerivedFromElement(m_stops[i].m_color.get())) {
     121        if (StyleResolver::colorFromPrimitiveValueIsDerivedFromElement(m_stops[i].m_color.get())) {
    123122            m_stops[i].m_colorIsDerivedFromElement = true;
    124123            derived = true;
     
    139138
    140139    for (unsigned i = 0; i < result->m_stops.size(); i++)
    141         result->m_stops[i].m_resolvedColor = styleResolver->colorFromPrimitiveValue(result->m_stops[i].m_color.get());
     140        result->m_stops[i].m_resolvedColor = StyleResolver::colorFromPrimitiveValue(state, result->m_stops[i].m_color.get());
    142141
    143142    return result.release();
  • trunk/Source/WebCore/css/CSSGradientValue.h

    r142444 r143556  
    2929#include "CSSImageGeneratorValue.h"
    3030#include "CSSPrimitiveValue.h"
     31#include "StyleResolver.h"
    3132#include <wtf/RefPtr.h>
    3233#include <wtf/Vector.h>
     
    9091
    9192    void loadSubimages(CachedResourceLoader*) { }
    92     PassRefPtr<CSSGradientValue> gradientWithStylesResolved(StyleResolver*);
     93    PassRefPtr<CSSGradientValue> gradientWithStylesResolved(StyleResolver::State&);
    9394
    9495protected:
  • trunk/Source/WebCore/css/CSSToStyleMap.cpp

    r142168 r143556  
    4444RenderStyle* CSSToStyleMap::style() const
    4545{
    46     return m_resolver->style();
     46    return m_state.style();
    4747}
    4848   
    4949RenderStyle* CSSToStyleMap::rootElementStyle() const
    5050{
    51     return m_resolver->rootElementStyle();
     51    return m_state.rootElementStyle();
    5252}
    5353
    5454bool CSSToStyleMap::useSVGZoomRules() const
    5555{
    56     return m_resolver->useSVGZoomRules();
     56    return m_state.useSVGZoomRules();
    5757}
    5858   
    5959PassRefPtr<StyleImage> CSSToStyleMap::styleImage(CSSPropertyID propertyId, CSSValue* value)
    6060{
    61     return m_resolver->styleImage(propertyId, value);
     61    return StyleResolver::styleImage(m_state, propertyId, value);
    6262}
    6363
  • trunk/Source/WebCore/css/CSSToStyleMap.h

    r142168 r143556  
    2525#include "CSSPropertyNames.h"
    2626#include "LengthBox.h"
     27#include "StyleResolver.h"
    2728
    2829namespace WebCore {
     
    3334class RenderStyle;
    3435class StyleImage;
    35 class StyleResolver;
    3636class NinePieceImage;
    3737
     
    4141
    4242public:
    43     CSSToStyleMap(StyleResolver* resolver) : m_resolver(resolver) { }
     43    CSSToStyleMap(StyleResolver::State& state) : m_state(state) { }
    4444
    4545    void mapFillAttachment(CSSPropertyID, FillLayer*, CSSValue*);
     
    8383    PassRefPtr<StyleImage> styleImage(CSSPropertyID, CSSValue*);
    8484
    85     StyleResolver* m_resolver;
     85    StyleResolver::State& m_state;
    8686};
    8787
  • trunk/Source/WebCore/css/SVGCSSStyleSelector.cpp

    r142757 r143556  
    103103}
    104104
    105 void StyleResolver::applySVGProperty(CSSPropertyID id, CSSValue* value)
     105void StyleResolver::applySVGProperty(const State& state, CSSPropertyID id, CSSValue* value)
    106106{
    107107    ASSERT(value);
     
    110110        primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    111111
    112     const State& state = m_state;
    113112    SVGRenderStyle* svgstyle = state.style()->accessSVGStyle();
    114113
     
    232231            if (isInherit) {
    233232                const SVGRenderStyle* svgParentStyle = state.parentStyle()->svgStyle();
    234                 svgstyle->setFillPaint(svgParentStyle->fillPaintType(), svgParentStyle->fillPaintColor(), svgParentStyle->fillPaintUri(), applyPropertyToRegularStyle(), applyPropertyToVisitedLinkStyle());
     233                svgstyle->setFillPaint(svgParentStyle->fillPaintType(), svgParentStyle->fillPaintColor(), svgParentStyle->fillPaintUri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
    235234                return;
    236235            }
    237236            if (isInitial) {
    238                 svgstyle->setFillPaint(SVGRenderStyle::initialFillPaintType(), SVGRenderStyle::initialFillPaintColor(), SVGRenderStyle::initialFillPaintUri(), applyPropertyToRegularStyle(), applyPropertyToVisitedLinkStyle());
     237                svgstyle->setFillPaint(SVGRenderStyle::initialFillPaintType(), SVGRenderStyle::initialFillPaintColor(), SVGRenderStyle::initialFillPaintUri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
    239238                return;
    240239            }
    241240            if (value->isSVGPaint()) {
    242241                SVGPaint* svgPaint = static_cast<SVGPaint*>(value);
    243                 svgstyle->setFillPaint(svgPaint->paintType(), colorFromSVGColorCSSValue(svgPaint, state.style()->color()), svgPaint->uri(), applyPropertyToRegularStyle(), applyPropertyToVisitedLinkStyle());
     242                svgstyle->setFillPaint(svgPaint->paintType(), colorFromSVGColorCSSValue(svgPaint, state.style()->color()), svgPaint->uri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
    244243            }
    245244            break;
     
    249248            if (isInherit) {
    250249                const SVGRenderStyle* svgParentStyle = state.parentStyle()->svgStyle();
    251                 svgstyle->setStrokePaint(svgParentStyle->strokePaintType(), svgParentStyle->strokePaintColor(), svgParentStyle->strokePaintUri(), applyPropertyToRegularStyle(), applyPropertyToVisitedLinkStyle());
     250                svgstyle->setStrokePaint(svgParentStyle->strokePaintType(), svgParentStyle->strokePaintColor(), svgParentStyle->strokePaintUri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
    252251                return;
    253252            }
    254253            if (isInitial) {
    255                 svgstyle->setStrokePaint(SVGRenderStyle::initialStrokePaintType(), SVGRenderStyle::initialStrokePaintColor(), SVGRenderStyle::initialStrokePaintUri(), applyPropertyToRegularStyle(), applyPropertyToVisitedLinkStyle());
     254                svgstyle->setStrokePaint(SVGRenderStyle::initialStrokePaintType(), SVGRenderStyle::initialStrokePaintColor(), SVGRenderStyle::initialStrokePaintUri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
    256255                return;
    257256            }
    258257            if (value->isSVGPaint()) {
    259258                SVGPaint* svgPaint = static_cast<SVGPaint*>(value);
    260                 svgstyle->setStrokePaint(svgPaint->paintType(), colorFromSVGColorCSSValue(svgPaint, state.style()->color()), svgPaint->uri(), applyPropertyToRegularStyle(), applyPropertyToVisitedLinkStyle());
     259                svgstyle->setStrokePaint(svgPaint->paintType(), colorFromSVGColorCSSValue(svgPaint, state.style()->color()), svgPaint->uri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
    261260            }
    262261            break;
     
    571570            Color color;
    572571            if (item->color)
    573                 color = colorFromPrimitiveValue(item->color.get());
     572                color = StyleResolver::colorFromPrimitiveValue(state, item->color.get());
    574573
    575574            // -webkit-svg-shadow does should not have a spread or style
  • trunk/Source/WebCore/css/StyleBuilder.cpp

    r142168 r143556  
    4444#include "RenderView.h"
    4545#include "Settings.h"
    46 #include "StyleResolver.h"
    4746#include <wtf/StdLibExtras.h>
    4847#include <wtf/UnusedParam.h>
     
    6261
    6362    template <CSSPropertyID id>
    64     static inline void applyInheritValue(CSSPropertyID propertyID, StyleResolver* styleResolver)
     63    static inline void applyInheritValue(CSSPropertyID propertyID, StyleResolver::State& state)
    6564    {
    6665        if (id == CSSPropertyInvalid)
     
    7069        const PropertyHandler& handler = table.propertyHandler(id);
    7170        if (handler.isValid())
    72             handler.applyInheritValue(propertyID, styleResolver);
    73     }
    74 
    75     static void applyInheritValue(CSSPropertyID propertyID, StyleResolver* styleResolver)
    76     {
    77         applyInheritValue<one>(propertyID, styleResolver);
    78         applyInheritValue<two>(propertyID, styleResolver);
    79         applyInheritValue<three>(propertyID, styleResolver);
    80         applyInheritValue<four>(propertyID, styleResolver);
    81         applyInheritValue<five>(propertyID, styleResolver);
     71            handler.applyInheritValue(propertyID, state);
     72    }
     73
     74    static void applyInheritValue(CSSPropertyID propertyID, StyleResolver::State& state)
     75    {
     76        applyInheritValue<one>(propertyID, state);
     77        applyInheritValue<two>(propertyID, state);
     78        applyInheritValue<three>(propertyID, state);
     79        applyInheritValue<four>(propertyID, state);
     80        applyInheritValue<five>(propertyID, state);
    8281    }
    8382
    8483    template <CSSPropertyID id>
    85     static inline void applyInitialValue(CSSPropertyID propertyID, StyleResolver* styleResolver)
     84    static inline void applyInitialValue(CSSPropertyID propertyID, StyleResolver::State& state)
    8685    {
    8786        if (id == CSSPropertyInvalid)
     
    9190        const PropertyHandler& handler = table.propertyHandler(id);
    9291        if (handler.isValid())
    93             handler.applyInitialValue(propertyID, styleResolver);
    94     }
    95 
    96     static void applyInitialValue(CSSPropertyID propertyID, StyleResolver* styleResolver)
    97     {
    98         applyInitialValue<one>(propertyID, styleResolver);
    99         applyInitialValue<two>(propertyID, styleResolver);
    100         applyInitialValue<three>(propertyID, styleResolver);
    101         applyInitialValue<four>(propertyID, styleResolver);
    102         applyInitialValue<five>(propertyID, styleResolver);
     92            handler.applyInitialValue(propertyID, state);
     93    }
     94
     95    static void applyInitialValue(CSSPropertyID propertyID, StyleResolver::State& state)
     96    {
     97        applyInitialValue<one>(propertyID, state);
     98        applyInitialValue<two>(propertyID, state);
     99        applyInitialValue<three>(propertyID, state);
     100        applyInitialValue<four>(propertyID, state);
     101        applyInitialValue<five>(propertyID, state);
    103102    }
    104103
    105104    template <CSSPropertyID id>
    106     static inline void applyValue(CSSPropertyID propertyID, StyleResolver* styleResolver, CSSValue* value)
     105    static inline void applyValue(CSSPropertyID propertyID, StyleResolver::State& state, CSSValue* value)
    107106    {
    108107        if (id == CSSPropertyInvalid)
     
    112111        const PropertyHandler& handler = table.propertyHandler(id);
    113112        if (handler.isValid())
    114             handler.applyValue(propertyID, styleResolver, value);
    115     }
    116 
    117     static void applyValue(CSSPropertyID propertyID, StyleResolver* styleResolver, CSSValue* value)
     113            handler.applyValue(propertyID, state, value);
     114    }
     115
     116    static void applyValue(CSSPropertyID propertyID, StyleResolver::State& state, CSSValue* value)
    118117    {
    119118        if (!expandValue)
    120119            return;
    121120
    122         applyValue<one>(propertyID, styleResolver, value);
    123         applyValue<two>(propertyID, styleResolver, value);
    124         applyValue<three>(propertyID, styleResolver, value);
    125         applyValue<four>(propertyID, styleResolver, value);
    126         applyValue<five>(propertyID, styleResolver, value);
     121        applyValue<one>(propertyID, state, value);
     122        applyValue<two>(propertyID, state, value);
     123        applyValue<three>(propertyID, state, value);
     124        applyValue<four>(propertyID, state, value);
     125        applyValue<five>(propertyID, state, value);
    127126    }
    128127    static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
     
    135134    static GetterType value(RenderStyle* style) { return (style->*getterFunction)(); }
    136135    static InitialType initial() { return (*initialFunction)(); }
    137     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver) { setValue(styleResolver->style(), value(styleResolver->parentStyle())); }
    138     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver) { setValue(styleResolver->style(), initial()); }
    139     static void applyValue(CSSPropertyID, StyleResolver*, CSSValue*) { }
     136    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state) { setValue(state.style(), value(state.parentStyle())); }
     137    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state) { setValue(state.style(), initial()); }
     138    static void applyValue(CSSPropertyID, StyleResolver::State&, CSSValue*) { }
    140139    static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
    141140};
     
    145144public:
    146145    static void setValue(RenderStyle* style, SetterType value) { (style->*setterFunction)(value); }
    147     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     146    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    148147    {
    149148        if (value->isPrimitiveValue())
    150             setValue(styleResolver->style(), *static_cast<CSSPrimitiveValue*>(value));
     149            setValue(state.style(), *static_cast<CSSPrimitiveValue*>(value));
    151150    }
    152151    static PropertyHandler createHandler()
     
    161160public:
    162161    static void setValue(RenderStyle* style, NumberType value) { (style->*setterFunction)(value); }
    163     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     162    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    164163    {
    165164        if (!value->isPrimitiveValue())
     
    168167        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    169168        if (primitiveValue->getIdent() == idMapsToMinusOne)
    170             setValue(styleResolver->style(), -1);
     169            setValue(state.style(), -1);
    171170        else
    172             setValue(styleResolver->style(), primitiveValue->getValue<NumberType>(CSSPrimitiveValue::CSS_NUMBER));
     171            setValue(state.style(), primitiveValue->getValue<NumberType>(CSSPrimitiveValue::CSS_NUMBER));
    173172    }
    174173    static PropertyHandler createHandler()
     
    182181class ApplyPropertyStyleImage {
    183182public:
    184     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value) { (styleResolver->style()->*setterFunction)(styleResolver->styleImage(property, value)); }
     183    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value) { (state.style()->*setterFunction)(StyleResolver::styleImage(state, property, value)); }
    185184    static PropertyHandler createHandler()
    186185    {
     
    199198    static void setAuto(RenderStyle* style) { (style->*setAutoFunction)(); }
    200199
    201     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    202     {
    203         if (hasAuto(styleResolver->parentStyle()))
    204             setAuto(styleResolver->style());
     200    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     201    {
     202        if (hasAuto(state.parentStyle()))
     203            setAuto(state.style());
    205204        else
    206             setValue(styleResolver->style(), value(styleResolver->parentStyle()));
    207     }
    208 
    209     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver) { setAuto(styleResolver->style()); }
    210 
    211     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     205            setValue(state.style(), value(state.parentStyle()));
     206    }
     207
     208    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state) { setAuto(state.style()); }
     209
     210    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    212211    {
    213212        if (!value->isPrimitiveValue())
     
    216215        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    217216        if (primitiveValue->getIdent() == autoIdentity)
    218             setAuto(styleResolver->style());
     217            setAuto(state.style());
    219218        else if (valueType == Number)
    220             setValue(styleResolver->style(), *primitiveValue);
     219            setValue(state.style(), *primitiveValue);
    221220        else if (valueType == ComputeLength)
    222             setValue(styleResolver->style(), primitiveValue->computeLength<T>(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom()));
     221            setValue(state.style(), primitiveValue->computeLength<T>(state.style(), state.rootElementStyle(), state.style()->effectiveZoom()));
    223222    }
    224223
     
    228227class ApplyPropertyClip {
    229228private:
    230     static Length convertToLength(StyleResolver* styleResolver, CSSPrimitiveValue* value)
    231     {
    232         return value->convertToLength<FixedIntegerConversion | PercentConversion | FractionConversion | AutoConversion>(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom());
    233     }
    234 public:
    235     static void applyInheritValue(CSSPropertyID propertyID, StyleResolver* styleResolver)
    236     {
    237         RenderStyle* parentStyle = styleResolver->parentStyle();
     229    static Length convertToLength(StyleResolver::State& state, CSSPrimitiveValue* value)
     230    {
     231        return value->convertToLength<FixedIntegerConversion | PercentConversion | FractionConversion | AutoConversion>(state.style(), state.rootElementStyle(), state.style()->effectiveZoom());
     232    }
     233public:
     234    static void applyInheritValue(CSSPropertyID propertyID, StyleResolver::State& state)
     235    {
     236        RenderStyle* parentStyle = state.parentStyle();
    238237        if (!parentStyle->hasClip())
    239             return applyInitialValue(propertyID, styleResolver);
    240         styleResolver->style()->setClip(parentStyle->clipTop(), parentStyle->clipRight(), parentStyle->clipBottom(), parentStyle->clipLeft());
    241         styleResolver->style()->setHasClip(true);
    242     }
    243 
    244     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    245     {
    246         styleResolver->style()->setClip(Length(), Length(), Length(), Length());
    247         styleResolver->style()->setHasClip(false);
    248     }
    249 
    250     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     238            return applyInitialValue(propertyID, state);
     239        state.style()->setClip(parentStyle->clipTop(), parentStyle->clipRight(), parentStyle->clipBottom(), parentStyle->clipLeft());
     240        state.style()->setHasClip(true);
     241    }
     242
     243    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     244    {
     245        state.style()->setClip(Length(), Length(), Length(), Length());
     246        state.style()->setHasClip(false);
     247    }
     248
     249    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    251250    {
    252251        if (!value->isPrimitiveValue())
     
    256255
    257256        if (Rect* rect = primitiveValue->getRectValue()) {
    258             Length top = convertToLength(styleResolver, rect->top());
    259             Length right = convertToLength(styleResolver, rect->right());
    260             Length bottom = convertToLength(styleResolver, rect->bottom());
    261             Length left = convertToLength(styleResolver, rect->left());
    262             styleResolver->style()->setClip(top, right, bottom, left);
    263             styleResolver->style()->setHasClip(true);
     257            Length top = convertToLength(state, rect->top());
     258            Length right = convertToLength(state, rect->right());
     259            Length bottom = convertToLength(state, rect->bottom());
     260            Length left = convertToLength(state, rect->left());
     261            state.style()->setClip(top, right, bottom, left);
     262            state.style()->setHasClip(true);
    264263        } else if (primitiveValue->getIdent() == CSSValueAuto) {
    265             styleResolver->style()->setClip(Length(), Length(), Length(), Length());
    266             styleResolver->style()->setHasClip(false);
     264            state.style()->setClip(Length(), Length(), Length(), Length());
     265            state.style()->setHasClip(false);
    267266        }
    268267    }
     
    282281class ApplyPropertyColor {
    283282public:
    284     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
     283    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
    285284    {
    286285        // Visited link style can never explicitly inherit from parent visited link style so no separate getters are needed.
    287         Color color = (styleResolver->parentStyle()->*getterFunction)();
    288         applyColorValue(styleResolver, color.isValid() ? color : (styleResolver->parentStyle()->*defaultFunction)());
    289     }
    290 
    291     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    292     {
    293         applyColorValue(styleResolver, initialFunction());
    294     }
    295 
    296     static void applyValue(CSSPropertyID propertyID, StyleResolver* styleResolver, CSSValue* value)
     286        Color color = (state.parentStyle()->*getterFunction)();
     287        applyColorValue(state, color.isValid() ? color : (state.parentStyle()->*defaultFunction)());
     288    }
     289
     290    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     291    {
     292        applyColorValue(state, initialFunction());
     293    }
     294
     295    static void applyValue(CSSPropertyID propertyID, StyleResolver::State& state, CSSValue* value)
    297296    {
    298297        if (!value->isPrimitiveValue())
     
    301300        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    302301        if (inheritColorFromParent && primitiveValue->getIdent() == CSSValueCurrentcolor)
    303             applyInheritValue(propertyID, styleResolver);
     302            applyInheritValue(propertyID, state);
    304303        else {
    305             if (styleResolver->applyPropertyToRegularStyle())
    306                 (styleResolver->style()->*setterFunction)(styleResolver->colorFromPrimitiveValue(primitiveValue));
    307             if (styleResolver->applyPropertyToVisitedLinkStyle())
    308                 (styleResolver->style()->*visitedLinkSetterFunction)(styleResolver->colorFromPrimitiveValue(primitiveValue, /* forVisitedLink */ true));
    309         }
    310     }
    311 
    312     static void applyColorValue(StyleResolver* styleResolver, const Color& color)
    313     {
    314         if (styleResolver->applyPropertyToRegularStyle())
    315             (styleResolver->style()->*setterFunction)(color);
    316         if (styleResolver->applyPropertyToVisitedLinkStyle())
    317             (styleResolver->style()->*visitedLinkSetterFunction)(color);
     304            if (state.applyPropertyToRegularStyle())
     305                (state.style()->*setterFunction)(StyleResolver::colorFromPrimitiveValue(state, primitiveValue));
     306            if (state.applyPropertyToVisitedLinkStyle())
     307                (state.style()->*visitedLinkSetterFunction)(StyleResolver::colorFromPrimitiveValue(state, primitiveValue, /* forVisitedLink */ true));
     308        }
     309    }
     310
     311    static void applyColorValue(StyleResolver::State& state, const Color& color)
     312    {
     313        if (state.applyPropertyToRegularStyle())
     314            (state.style()->*setterFunction)(color);
     315        if (state.applyPropertyToVisitedLinkStyle())
     316            (state.style()->*visitedLinkSetterFunction)(color);
    318317    }
    319318
     
    324323class ApplyPropertyDirection {
    325324public:
    326     static void applyValue(CSSPropertyID propertyID, StyleResolver* styleResolver, CSSValue* value)
    327     {
    328         ApplyPropertyDefault<TextDirection, getterFunction, TextDirection, setterFunction, TextDirection, initialFunction>::applyValue(propertyID, styleResolver, value);
    329         Element* element = styleResolver->element();
    330         if (element && styleResolver->element() == element->document()->documentElement())
     325    static void applyValue(CSSPropertyID propertyID, StyleResolver::State& state, CSSValue* value)
     326    {
     327        ApplyPropertyDefault<TextDirection, getterFunction, TextDirection, setterFunction, TextDirection, initialFunction>::applyValue(propertyID, state, value);
     328        Element* element = state.element();
     329        if (element && state.element() == element->document()->documentElement())
    331330            element->document()->setDirectionSetOnDocumentElement(true);
    332331    }
     
    355354public:
    356355    static void setValue(RenderStyle* style, Length value) { (style->*setterFunction)(value); }
    357     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     356    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    358357    {
    359358        if (!value->isPrimitiveValue())
     
    363362        if (noneEnabled && primitiveValue->getIdent() == CSSValueNone) {
    364363            if (noneUndefined)
    365                 setValue(styleResolver->style(), Length(Undefined));
     364                setValue(state.style(), Length(Undefined));
    366365            else
    367                 setValue(styleResolver->style(), Length());
     366                setValue(state.style(), Length());
    368367        }
    369368        if (legacyIntrinsicEnabled) {
    370369            if (primitiveValue->getIdent() == CSSValueIntrinsic)
    371                 setValue(styleResolver->style(), Length(Intrinsic));
     370                setValue(state.style(), Length(Intrinsic));
    372371            else if (primitiveValue->getIdent() == CSSValueMinIntrinsic)
    373                 setValue(styleResolver->style(), Length(MinIntrinsic));
     372                setValue(state.style(), Length(MinIntrinsic));
    374373        }
    375374        if (intrinsicEnabled) {
    376375            if (primitiveValue->getIdent() == CSSValueWebkitMinContent)
    377                 setValue(styleResolver->style(), Length(MinContent));
     376                setValue(state.style(), Length(MinContent));
    378377            else if (primitiveValue->getIdent() == CSSValueWebkitMaxContent)
    379                 setValue(styleResolver->style(), Length(MaxContent));
     378                setValue(state.style(), Length(MaxContent));
    380379            else if (primitiveValue->getIdent() == CSSValueWebkitFillAvailable)
    381                 setValue(styleResolver->style(), Length(FillAvailable));
     380                setValue(state.style(), Length(FillAvailable));
    382381            else if (primitiveValue->getIdent() == CSSValueWebkitFitContent)
    383                 setValue(styleResolver->style(), Length(FitContent));
     382                setValue(state.style(), Length(FitContent));
    384383        }
    385384
    386385        if (autoEnabled && primitiveValue->getIdent() == CSSValueAuto)
    387             setValue(styleResolver->style(), Length());
     386            setValue(state.style(), Length());
    388387        else if (primitiveValue->isLength()) {
    389             Length length = primitiveValue->computeLength<Length>(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom());
     388            Length length = primitiveValue->computeLength<Length>(state.style(), state.rootElementStyle(), state.style()->effectiveZoom());
    390389            length.setQuirk(primitiveValue->isQuirkValue());
    391             setValue(styleResolver->style(), length);
     390            setValue(state.style(), length);
    392391        } else if (primitiveValue->isPercentage())
    393             setValue(styleResolver->style(), Length(primitiveValue->getDoubleValue(), Percent));
     392            setValue(state.style(), Length(primitiveValue->getDoubleValue(), Percent));
    394393        else if (primitiveValue->isCalculatedPercentageWithLength())
    395             setValue(styleResolver->style(), Length(primitiveValue->cssCalcValue()->toCalcValue(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom())));
     394            setValue(state.style(), Length(primitiveValue->cssCalcValue()->toCalcValue(state.style(), state.rootElementStyle(), state.style()->effectiveZoom())));
    396395        else if (primitiveValue->isViewportPercentageLength())
    397             setValue(styleResolver->style(), primitiveValue->viewportPercentageLength());
     396            setValue(state.style(), primitiveValue->viewportPercentageLength());
    398397    }
    399398
     
    410409public:
    411410    static void setValue(RenderStyle* style, const AtomicString& value) { (style->*setterFunction)(value); }
    412     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     411    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    413412    {
    414413        if (!value->isPrimitiveValue())
     
    417416        if ((identBehavior == MapNoneToNull && primitiveValue->getIdent() == CSSValueNone)
    418417            || (identBehavior == MapAutoToNull && primitiveValue->getIdent() == CSSValueAuto))
    419             setValue(styleResolver->style(), nullAtom);
     418            setValue(state.style(), nullAtom);
    420419        else
    421             setValue(styleResolver->style(), primitiveValue->getStringValue());
     420            setValue(state.style(), primitiveValue->getStringValue());
    422421    }
    423422    static PropertyHandler createHandler()
     
    432431public:
    433432    static void setValue(RenderStyle* style, LengthSize value) { (style->*setterFunction)(value); }
    434     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     433    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    435434    {
    436435        if (!value->isPrimitiveValue())
     
    449448            radiusWidth = pair->first()->viewportPercentageLength();
    450449        else if (pair->first()->isCalculatedPercentageWithLength())
    451             radiusWidth = Length((pair->first()->cssCalcValue()->toCalcValue(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom())));
     450            radiusWidth = Length((pair->first()->cssCalcValue()->toCalcValue(state.style(), state.rootElementStyle(), state.style()->effectiveZoom())));
    452451        else
    453             radiusWidth = pair->first()->computeLength<Length>(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom());
     452            radiusWidth = pair->first()->computeLength<Length>(state.style(), state.rootElementStyle(), state.style()->effectiveZoom());
    454453        if (pair->second()->isPercentage())
    455454            radiusHeight = Length(pair->second()->getDoubleValue(), Percent);
     
    457456            radiusHeight = pair->second()->viewportPercentageLength();
    458457        else if (pair->second()->isCalculatedPercentageWithLength())
    459             radiusHeight = Length((pair->second()->cssCalcValue()->toCalcValue(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom())));
     458            radiusHeight = Length((pair->second()->cssCalcValue()->toCalcValue(state.style(), state.rootElementStyle(), state.style()->effectiveZoom())));
    460459        else
    461             radiusHeight = pair->second()->computeLength<Length>(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom());
     460            radiusHeight = pair->second()->computeLength<Length>(state.style(), state.rootElementStyle(), state.style()->effectiveZoom());
    462461        int width = radiusWidth.value();
    463462        int height = radiusHeight.value();
     
    470469
    471470        LengthSize size(radiusWidth, radiusHeight);
    472         setValue(styleResolver->style(), size);
     471        setValue(state.style(), size);
    473472    }
    474473    static PropertyHandler createHandler()
     
    504503class ApplyPropertyFillLayer {
    505504public:
    506     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    507     {
    508         FillLayer* currChild = (styleResolver->style()->*accessLayersFunction)();
     505    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     506    {
     507        FillLayer* currChild = (state.style()->*accessLayersFunction)();
    509508        FillLayer* prevChild = 0;
    510         const FillLayer* currParent = (styleResolver->parentStyle()->*layersFunction)();
     509        const FillLayer* currParent = (state.parentStyle()->*layersFunction)();
    511510        while (currParent && (currParent->*testFunction)()) {
    512511            if (!currChild) {
     
    528527    }
    529528
    530     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    531     {
    532         FillLayer* currChild = (styleResolver->style()->*accessLayersFunction)();
     529    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     530    {
     531        FillLayer* currChild = (state.style()->*accessLayersFunction)();
    533532        (currChild->*setFunction)((*initialFunction)(fillLayerType));
    534533        for (currChild = currChild->next(); currChild; currChild = currChild->next())
     
    536535    }
    537536
    538     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
    539     {
    540         FillLayer* currChild = (styleResolver->style()->*accessLayersFunction)();
     537    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
     538    {
     539        FillLayer* currChild = (state.style()->*accessLayersFunction)();
    541540        FillLayer* prevChild = 0;
     541        CSSToStyleMap styleMap(state);
    542542        if (value->isValueList()
    543543#if ENABLE(CSS_IMAGE_SET)
     
    553553                    prevChild->setNext(currChild);
    554554                }
    555                 (styleResolver->styleMap()->*mapFillFunction)(propertyId, currChild, valueList->itemWithoutBoundsCheck(i));
     555                (styleMap.*mapFillFunction)(propertyId, currChild, valueList->itemWithoutBoundsCheck(i));
    556556                prevChild = currChild;
    557557                currChild = currChild->next();
    558558            }
    559559        } else {
    560             (styleResolver->styleMap()->*mapFillFunction)(propertyId, currChild, value);
     560            (styleMap.*mapFillFunction)(propertyId, currChild, value);
    561561            currChild = currChild->next();
    562562        }
     
    584584public:
    585585    static void setValue(RenderStyle* style, T value) { (style->*setterFunction)(value); }
    586     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     586    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    587587    {
    588588        // note: CSSPropertyLetter/WordSpacing right now sets to zero if it's not a primitive value for some reason...
     
    603603            length = 5;
    604604        } else if (ident == CSSValueInvalid) {
    605             float zoom = (svgZoomEnabled && styleResolver->useSVGZoomRules()) ? 1.0f : styleResolver->style()->effectiveZoom();
     605            float zoom = (svgZoomEnabled && state.useSVGZoomRules()) ? 1.0f : state.style()->effectiveZoom();
    606606
    607607            // Any original result that was >= 1 should not be allowed to fall below 1.
    608608            // This keeps border lines from vanishing.
    609             length = primitiveValue->computeLength<T>(styleResolver->style(), styleResolver->rootElementStyle(), zoom);
     609            length = primitiveValue->computeLength<T>(state.style(), state.rootElementStyle(), zoom);
    610610            if (zoom < 1.0f && length < 1.0) {
    611                 T originalLength = primitiveValue->computeLength<T>(styleResolver->style(), styleResolver->rootElementStyle(), 1.0);
     611                T originalLength = primitiveValue->computeLength<T>(state.style(), state.rootElementStyle(), 1.0);
    612612                if (originalLength >= 1.0)
    613613                    length = 1.0;
     
    619619        }
    620620
    621         setValue(styleResolver->style(), length);
     621        setValue(state.style(), length);
    622622    }
    623623    static PropertyHandler createHandler()
     
    631631class ApplyPropertyFont {
    632632public:
    633     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    634     {
    635         FontDescription fontDescription = styleResolver->fontDescription();
    636         (fontDescription.*setterFunction)((styleResolver->parentFontDescription().*getterFunction)());
    637         styleResolver->setFontDescription(fontDescription);
    638     }
    639 
    640     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    641     {
    642         FontDescription fontDescription = styleResolver->fontDescription();
     633    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     634    {
     635        FontDescription fontDescription = state.fontDescription();
     636        (fontDescription.*setterFunction)((state.parentFontDescription().*getterFunction)());
     637        state.setFontDescription(fontDescription);
     638    }
     639
     640    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     641    {
     642        FontDescription fontDescription = state.fontDescription();
    643643        (fontDescription.*setterFunction)(initialValue);
    644         styleResolver->setFontDescription(fontDescription);
    645     }
    646 
    647     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     644        state.setFontDescription(fontDescription);
     645    }
     646
     647    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    648648    {
    649649        if (!value->isPrimitiveValue())
    650650            return;
    651651        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    652         FontDescription fontDescription = styleResolver->fontDescription();
     652        FontDescription fontDescription = state.fontDescription();
    653653        (fontDescription.*setterFunction)(*primitiveValue);
    654         styleResolver->setFontDescription(fontDescription);
     654        state.setFontDescription(fontDescription);
    655655    }
    656656
     
    677677    }
    678678public:
    679     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    680     {
    681         float size = styleResolver->parentStyle()->fontDescription().specifiedSize();
     679    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     680    {
     681        float size = state.parentStyle()->fontDescription().specifiedSize();
    682682
    683683        if (size < 0)
    684684            return;
    685685
    686         FontDescription fontDescription = styleResolver->style()->fontDescription();
    687         fontDescription.setKeywordSize(styleResolver->parentStyle()->fontDescription().keywordSize());
    688         styleResolver->setFontSize(fontDescription, size);
    689         styleResolver->setFontDescription(fontDescription);
     686        FontDescription fontDescription = state.style()->fontDescription();
     687        fontDescription.setKeywordSize(state.parentStyle()->fontDescription().keywordSize());
     688        StyleResolver::setFontSize(state, fontDescription, size);
     689        state.setFontDescription(fontDescription);
    690690        return;
    691691    }
    692692
    693     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    694     {
    695         FontDescription fontDescription = styleResolver->style()->fontDescription();
    696         float size = styleResolver->fontSizeForKeyword(styleResolver->document(), CSSValueMedium, fontDescription.useFixedDefaultSize());
     693    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     694    {
     695        FontDescription fontDescription = state.style()->fontDescription();
     696        float size = StyleResolver::fontSizeForKeyword(state.document(), CSSValueMedium, fontDescription.useFixedDefaultSize());
    697697
    698698        if (size < 0)
     
    700700
    701701        fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
    702         styleResolver->setFontSize(fontDescription, size);
    703         styleResolver->setFontDescription(fontDescription);
     702        StyleResolver::setFontSize(state, fontDescription, size);
     703        state.setFontDescription(fontDescription);
    704704        return;
    705705    }
    706706
    707     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     707    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    708708    {
    709709        if (!value->isPrimitiveValue())
     
    712712        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    713713
    714         FontDescription fontDescription = styleResolver->style()->fontDescription();
     714        FontDescription fontDescription = state.style()->fontDescription();
    715715        fontDescription.setKeywordSize(0);
    716716        float parentSize = 0;
     
    718718        float size = 0;
    719719
    720         if (styleResolver->parentStyle()) {
    721             parentSize = styleResolver->parentStyle()->fontDescription().specifiedSize();
    722             parentIsAbsoluteSize = styleResolver->parentStyle()->fontDescription().isAbsoluteSize();
     720        if (state.parentStyle()) {
     721            parentSize = state.parentStyle()->fontDescription().specifiedSize();
     722            parentIsAbsoluteSize = state.parentStyle()->fontDescription().isAbsoluteSize();
    723723        }
    724724
     
    734734            case CSSValueXxLarge:
    735735            case CSSValueWebkitXxxLarge:
    736                 size = styleResolver->fontSizeForKeyword(styleResolver->document(), ident, fontDescription.useFixedDefaultSize());
     736                size = StyleResolver::fontSizeForKeyword(state.document(), ident, fontDescription.useFixedDefaultSize());
    737737                fontDescription.setKeywordSize(ident - CSSValueXxSmall + 1);
    738738                break;
     
    752752                                              || !(primitiveValue->isPercentage() || primitiveValue->isFontRelativeLength()));
    753753            if (primitiveValue->isLength())
    754                 size = primitiveValue->computeLength<float>(styleResolver->parentStyle(), styleResolver->rootElementStyle(), 1.0, true);
     754                size = primitiveValue->computeLength<float>(state.parentStyle(), state.rootElementStyle(), 1.0, true);
    755755            else if (primitiveValue->isPercentage())
    756756                size = (primitiveValue->getFloatValue() * parentSize) / 100.0f;
    757757            else if (primitiveValue->isCalculatedPercentageWithLength())
    758                 size = primitiveValue->cssCalcValue()->toCalcValue(styleResolver->parentStyle(), styleResolver->rootElementStyle())->evaluate(parentSize);
     758                size = primitiveValue->cssCalcValue()->toCalcValue(state.parentStyle(), state.rootElementStyle())->evaluate(parentSize);
    759759            else if (primitiveValue->isViewportPercentageLength())
    760                 size = valueForLength(primitiveValue->viewportPercentageLength(), 0, styleResolver->document()->renderView());
     760                size = valueForLength(primitiveValue->viewportPercentageLength(), 0, state.document()->renderView());
    761761            else
    762762                return;
     
    770770        size = min(maximumAllowedFontSize, size);
    771771
    772         styleResolver->setFontSize(fontDescription, size);
    773         styleResolver->setFontDescription(fontDescription);
     772        StyleResolver::setFontSize(state, fontDescription, size);
     773        state.setFontDescription(fontDescription);
    774774        return;
    775775    }
     
    780780class ApplyPropertyFontWeight {
    781781public:
    782     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     782    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    783783    {
    784784        if (!value->isPrimitiveValue())
    785785            return;
    786786        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    787         FontDescription fontDescription = styleResolver->fontDescription();
     787        FontDescription fontDescription = state.fontDescription();
    788788        switch (primitiveValue->getIdent()) {
    789789        case CSSValueInvalid:
     
    799799            fontDescription.setWeight(*primitiveValue);
    800800        }
    801         styleResolver->setFontDescription(fontDescription);
     801        state.setFontDescription(fontDescription);
    802802    }
    803803    static PropertyHandler createHandler()
     
    810810class ApplyPropertyFontVariantLigatures {
    811811public:
    812     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    813     {
    814         const FontDescription& parentFontDescription = styleResolver->parentFontDescription();
    815         FontDescription fontDescription = styleResolver->fontDescription();
     812    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     813    {
     814        const FontDescription& parentFontDescription = state.parentFontDescription();
     815        FontDescription fontDescription = state.fontDescription();
    816816
    817817        fontDescription.setCommonLigaturesState(parentFontDescription.commonLigaturesState());
     
    819819        fontDescription.setHistoricalLigaturesState(parentFontDescription.historicalLigaturesState());
    820820
    821         styleResolver->setFontDescription(fontDescription);
    822     }
    823 
    824     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    825     {
    826         FontDescription fontDescription = styleResolver->fontDescription();
     821        state.setFontDescription(fontDescription);
     822    }
     823
     824    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     825    {
     826        FontDescription fontDescription = state.fontDescription();
    827827
    828828        fontDescription.setCommonLigaturesState(FontDescription::NormalLigaturesState);
     
    830830        fontDescription.setHistoricalLigaturesState(FontDescription::NormalLigaturesState);
    831831
    832         styleResolver->setFontDescription(fontDescription);
    833     }
    834 
    835     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     832        state.setFontDescription(fontDescription);
     833    }
     834
     835    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    836836    {
    837837        FontDescription::LigaturesState commonLigaturesState = FontDescription::NormalLigaturesState;
     
    879879#endif
    880880
    881         FontDescription fontDescription = styleResolver->fontDescription();
     881        FontDescription fontDescription = state.fontDescription();
    882882        fontDescription.setCommonLigaturesState(commonLigaturesState);
    883883        fontDescription.setDiscretionaryLigaturesState(discretionaryLigaturesState);
    884884        fontDescription.setHistoricalLigaturesState(historicalLigaturesState);
    885         styleResolver->setFontDescription(fontDescription);
     885        state.setFontDescription(fontDescription);
    886886    }
    887887
     
    899899class ApplyPropertyBorderImage {
    900900public:
    901     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     901    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    902902    {
    903903        NinePieceImage image;
    904904        if (borderImageType == BorderMask)
    905905            image.setMaskDefaults();
    906         styleResolver->styleMap()->mapNinePieceImage(property, value, image);
    907         (styleResolver->style()->*setterFunction)(image);
     906        CSSToStyleMap styleMap(state);
     907        styleMap.mapNinePieceImage(property, value, image);
     908        (state.style()->*setterFunction)(image);
    908909    }
    909910
     
    922923    static inline void setValue(RenderStyle* style, const NinePieceImage& value) { return type == BorderImage ? style->setBorderImage(value) : style->setMaskBoxImage(value); }
    923924public:
    924     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    925     {
    926         NinePieceImage image(getValue(styleResolver->style()));
     925    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     926    {
     927        NinePieceImage image(getValue(state.style()));
    927928        switch (modifier) {
    928929        case Outset:
    929             image.copyOutsetFrom(getValue(styleResolver->parentStyle()));
     930            image.copyOutsetFrom(getValue(state.parentStyle()));
    930931            break;
    931932        case Repeat:
    932             image.copyRepeatFrom(getValue(styleResolver->parentStyle()));
     933            image.copyRepeatFrom(getValue(state.parentStyle()));
    933934            break;
    934935        case Slice:
    935             image.copyImageSlicesFrom(getValue(styleResolver->parentStyle()));
     936            image.copyImageSlicesFrom(getValue(state.parentStyle()));
    936937            break;
    937938        case Width:
    938             image.copyBorderSlicesFrom(getValue(styleResolver->parentStyle()));
    939             break;
    940         }
    941         setValue(styleResolver->style(), image);
    942     }
    943 
    944     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    945     {
    946         NinePieceImage image(getValue(styleResolver->style()));
     939            image.copyBorderSlicesFrom(getValue(state.parentStyle()));
     940            break;
     941        }
     942        setValue(state.style(), image);
     943    }
     944
     945    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     946    {
     947        NinePieceImage image(getValue(state.style()));
    947948        switch (modifier) {
    948949        case Outset:
     
    963964            break;
    964965        }
    965         setValue(styleResolver->style(), image);
    966     }
    967 
    968     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
    969     {
    970         NinePieceImage image(getValue(styleResolver->style()));
     966        setValue(state.style(), image);
     967    }
     968
     969    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
     970    {
     971        NinePieceImage image(getValue(state.style()));
     972        CSSToStyleMap styleMap(state);
    971973        switch (modifier) {
    972974        case Outset:
    973             image.setOutset(styleResolver->styleMap()->mapNinePieceImageQuad(value));
     975            image.setOutset(styleMap.mapNinePieceImageQuad(value));
    974976            break;
    975977        case Repeat:
    976             styleResolver->styleMap()->mapNinePieceImageRepeat(value, image);
     978            styleMap.mapNinePieceImageRepeat(value, image);
    977979            break;
    978980        case Slice:
    979             styleResolver->styleMap()->mapNinePieceImageSlice(value, image);
     981            styleMap.mapNinePieceImageSlice(value, image);
    980982            break;
    981983        case Width:
    982             image.setBorderSlices(styleResolver->styleMap()->mapNinePieceImageQuad(value));
    983             break;
    984         }
    985         setValue(styleResolver->style(), image);
     984            image.setBorderSlices(styleMap.mapNinePieceImageQuad(value));
     985            break;
     986        }
     987        setValue(state.style(), image);
    986988    }
    987989
     
    992994class ApplyPropertyBorderImageSource {
    993995public:
    994     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value) { (styleResolver->style()->*setterFunction)(styleResolver->styleImage(id, value)); }
     996    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value) { (state.style()->*setterFunction)(StyleResolver::styleImage(state, id, value)); }
    995997    static PropertyHandler createHandler()
    996998    {
     
    10041006class ApplyPropertyCounter {
    10051007public:
    1006     static void emptyFunction(CSSPropertyID, StyleResolver*) { }
    1007     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    1008     {
    1009         CounterDirectiveMap& map = styleResolver->style()->accessCounterDirectives();
    1010         CounterDirectiveMap& parentMap = styleResolver->parentStyle()->accessCounterDirectives();
     1008    static void emptyFunction(CSSPropertyID, StyleResolver::State&) { }
     1009    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     1010    {
     1011        CounterDirectiveMap& map = state.style()->accessCounterDirectives();
     1012        CounterDirectiveMap& parentMap = state.parentStyle()->accessCounterDirectives();
    10111013
    10121014        typedef CounterDirectiveMap::iterator Iterator;
     
    10211023        }
    10221024    }
    1023     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1025    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    10241026    {
    10251027        if (!value->isValueList())
     
    10281030        CSSValueList* list = static_cast<CSSValueList*>(value);
    10291031
    1030         CounterDirectiveMap& map = styleResolver->style()->accessCounterDirectives();
     1032        CounterDirectiveMap& map = state.style()->accessCounterDirectives();
    10311033        typedef CounterDirectiveMap::iterator Iterator;
    10321034
     
    10641066class ApplyPropertyCursor {
    10651067public:
    1066     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    1067     {
    1068         styleResolver->style()->setCursor(styleResolver->parentStyle()->cursor());
    1069         styleResolver->style()->setCursorList(styleResolver->parentStyle()->cursors());
    1070     }
    1071 
    1072     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    1073     {
    1074         styleResolver->style()->clearCursorList();
    1075         styleResolver->style()->setCursor(RenderStyle::initialCursor());
    1076     }
    1077 
    1078     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
    1079     {
    1080         styleResolver->style()->clearCursorList();
     1068    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     1069    {
     1070        state.style()->setCursor(state.parentStyle()->cursor());
     1071        state.style()->setCursorList(state.parentStyle()->cursors());
     1072    }
     1073
     1074    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     1075    {
     1076        state.style()->clearCursorList();
     1077        state.style()->setCursor(RenderStyle::initialCursor());
     1078    }
     1079
     1080    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
     1081    {
     1082        state.style()->clearCursorList();
    10811083        if (value->isValueList()) {
    10821084            CSSValueList* list = static_cast<CSSValueList*>(value);
    10831085            int len = list->length();
    1084             styleResolver->style()->setCursor(CURSOR_AUTO);
     1086            state.style()->setCursor(CURSOR_AUTO);
    10851087            for (int i = 0; i < len; i++) {
    10861088                CSSValue* item = list->itemWithoutBoundsCheck(i);
    10871089                if (item->isCursorImageValue()) {
    10881090                    CSSCursorImageValue* image = static_cast<CSSCursorImageValue*>(item);
    1089                     if (image->updateIfSVGCursorIsUsed(styleResolver->element())) // Elements with SVG cursors are not allowed to share style.
    1090                         styleResolver->style()->setUnique();
    1091                     styleResolver->style()->addCursor(styleResolver->styleImage(CSSPropertyCursor, image), image->hotSpot());
     1091                    if (image->updateIfSVGCursorIsUsed(state.element())) // Elements with SVG cursors are not allowed to share style.
     1092                        state.style()->setUnique();
     1093                    state.style()->addCursor(StyleResolver::styleImage(state, CSSPropertyCursor, image), image->hotSpot());
    10921094                } else if (item->isPrimitiveValue()) {
    10931095                    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(item);
    10941096                    if (primitiveValue->isIdent())
    1095                         styleResolver->style()->setCursor(*primitiveValue);
     1097                        state.style()->setCursor(*primitiveValue);
    10961098                }
    10971099            }
    10981100        } else if (value->isPrimitiveValue()) {
    10991101            CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    1100             if (primitiveValue->isIdent() && styleResolver->style()->cursor() != ECursor(*primitiveValue))
    1101                 styleResolver->style()->setCursor(*primitiveValue);
     1102            if (primitiveValue->isIdent() && state.style()->cursor() != ECursor(*primitiveValue))
     1103                state.style()->setCursor(*primitiveValue);
    11021104        }
    11031105    }
     
    11081110class ApplyPropertyTextAlign {
    11091111public:
    1110     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1112    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    11111113    {
    11121114        if (!value->isPrimitiveValue())
     
    11161118
    11171119        if (primitiveValue->getIdent() != CSSValueWebkitMatchParent)
    1118             styleResolver->style()->setTextAlign(*primitiveValue);
    1119         else if (styleResolver->parentStyle()->textAlign() == TASTART)
    1120             styleResolver->style()->setTextAlign(styleResolver->parentStyle()->isLeftToRightDirection() ? LEFT : RIGHT);
    1121         else if (styleResolver->parentStyle()->textAlign() == TAEND)
    1122             styleResolver->style()->setTextAlign(styleResolver->parentStyle()->isLeftToRightDirection() ? RIGHT : LEFT);
     1120            state.style()->setTextAlign(*primitiveValue);
     1121        else if (state.parentStyle()->textAlign() == TASTART)
     1122            state.style()->setTextAlign(state.parentStyle()->isLeftToRightDirection() ? LEFT : RIGHT);
     1123        else if (state.parentStyle()->textAlign() == TAEND)
     1124            state.style()->setTextAlign(state.parentStyle()->isLeftToRightDirection() ? RIGHT : LEFT);
    11231125        else
    1124             styleResolver->style()->setTextAlign(styleResolver->parentStyle()->textAlign());
     1126            state.style()->setTextAlign(state.parentStyle()->textAlign());
    11251127    }
    11261128    static PropertyHandler createHandler()
     
    11331135class ApplyPropertyTextDecoration {
    11341136public:
    1135     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1137    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    11361138    {
    11371139        ETextDecoration t = RenderStyle::initialTextDecoration();
     
    11411143            t |= *static_cast<CSSPrimitiveValue*>(item);
    11421144        }
    1143         styleResolver->style()->setTextDecoration(t);
     1145        state.style()->setTextDecoration(t);
    11441146    }
    11451147    static PropertyHandler createHandler()
     
    11521154class ApplyPropertyLineHeight {
    11531155public:
    1154     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1156    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    11551157    {
    11561158        if (!value->isPrimitiveValue())
     
    11631165            lineHeight = RenderStyle::initialLineHeight();
    11641166        else if (primitiveValue->isLength()) {
    1165             double multiplier = styleResolver->style()->effectiveZoom();
    1166             if (styleResolver->style()->textSizeAdjust()) {
    1167                 if (Frame* frame = styleResolver->document()->frame())
     1167            double multiplier = state.style()->effectiveZoom();
     1168            if (state.style()->textSizeAdjust()) {
     1169                if (Frame* frame = state.document()->frame())
    11681170                    multiplier *= frame->textZoomFactor();
    11691171            }
    1170             lineHeight = primitiveValue->computeLength<Length>(styleResolver->style(), styleResolver->rootElementStyle(), multiplier);
     1172            lineHeight = primitiveValue->computeLength<Length>(state.style(), state.rootElementStyle(), multiplier);
    11711173        } else if (primitiveValue->isPercentage()) {
    11721174            // FIXME: percentage should not be restricted to an integer here.
    1173             lineHeight = Length((styleResolver->style()->fontSize() * primitiveValue->getIntValue()) / 100, Fixed);
     1175            lineHeight = Length((state.style()->fontSize() * primitiveValue->getIntValue()) / 100, Fixed);
    11741176        } else if (primitiveValue->isNumber()) {
    11751177            // FIXME: number and percentage values should produce the same type of Length (ie. Fixed or Percent).
     
    11791181        else
    11801182            return;
    1181         styleResolver->style()->setLineHeight(lineHeight);
     1183        state.style()->setLineHeight(lineHeight);
    11821184    }
    11831185    static PropertyHandler createHandler()
     
    12661268    }
    12671269public:
    1268     static void applyInheritValue(CSSPropertyID, StyleResolver*) { }
    1269     static void applyInitialValue(CSSPropertyID, StyleResolver*) { }
    1270     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
    1271     {
    1272         styleResolver->style()->resetPageSizeType();
     1270    static void applyInheritValue(CSSPropertyID, StyleResolver::State&) { }
     1271    static void applyInitialValue(CSSPropertyID, StyleResolver::State&) { }
     1272    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
     1273    {
     1274        state.style()->resetPageSizeType();
    12731275        Length width;
    12741276        Length height;
     
    12861288                if (!second->isLength())
    12871289                    return;
    1288                 width = first->computeLength<Length>(styleResolver->style(), styleResolver->rootElementStyle());
    1289                 height = second->computeLength<Length>(styleResolver->style(), styleResolver->rootElementStyle());
     1290                width = first->computeLength<Length>(state.style(), state.rootElementStyle());
     1291                height = second->computeLength<Length>(state.style(), state.rootElementStyle());
    12901292            } else {
    12911293                // <page-size> <orientation>
     
    13051307                // <length>
    13061308                pageSizeType = PAGE_SIZE_RESOLVED;
    1307                 width = height = primitiveValue->computeLength<Length>(styleResolver->style(), styleResolver->rootElementStyle());
     1309                width = height = primitiveValue->computeLength<Length>(state.style(), state.rootElementStyle());
    13081310            } else {
    13091311                switch (primitiveValue->getIdent()) {
     
    13311333            return;
    13321334        }
    1333         styleResolver->style()->setPageSizeType(pageSizeType);
    1334         styleResolver->style()->setPageSize(LengthSize(width, height));
     1335        state.style()->setPageSizeType(pageSizeType);
     1336        state.style()->setPageSize(LengthSize(width, height));
    13351337    }
    13361338    static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
     
    13391341class ApplyPropertyTextEmphasisStyle {
    13401342public:
    1341     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    1342     {
    1343         styleResolver->style()->setTextEmphasisFill(styleResolver->parentStyle()->textEmphasisFill());
    1344         styleResolver->style()->setTextEmphasisMark(styleResolver->parentStyle()->textEmphasisMark());
    1345         styleResolver->style()->setTextEmphasisCustomMark(styleResolver->parentStyle()->textEmphasisCustomMark());
    1346     }
    1347 
    1348     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    1349     {
    1350         styleResolver->style()->setTextEmphasisFill(RenderStyle::initialTextEmphasisFill());
    1351         styleResolver->style()->setTextEmphasisMark(RenderStyle::initialTextEmphasisMark());
    1352         styleResolver->style()->setTextEmphasisCustomMark(RenderStyle::initialTextEmphasisCustomMark());
    1353     }
    1354 
    1355     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1343    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     1344    {
     1345        state.style()->setTextEmphasisFill(state.parentStyle()->textEmphasisFill());
     1346        state.style()->setTextEmphasisMark(state.parentStyle()->textEmphasisMark());
     1347        state.style()->setTextEmphasisCustomMark(state.parentStyle()->textEmphasisCustomMark());
     1348    }
     1349
     1350    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     1351    {
     1352        state.style()->setTextEmphasisFill(RenderStyle::initialTextEmphasisFill());
     1353        state.style()->setTextEmphasisMark(RenderStyle::initialTextEmphasisMark());
     1354        state.style()->setTextEmphasisCustomMark(RenderStyle::initialTextEmphasisCustomMark());
     1355    }
     1356
     1357    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    13561358    {
    13571359        if (value->isValueList()) {
     
    13671369                CSSPrimitiveValue* value = static_cast<CSSPrimitiveValue*>(item);
    13681370                if (value->getIdent() == CSSValueFilled || value->getIdent() == CSSValueOpen)
    1369                     styleResolver->style()->setTextEmphasisFill(*value);
     1371                    state.style()->setTextEmphasisFill(*value);
    13701372                else
    1371                     styleResolver->style()->setTextEmphasisMark(*value);
     1373                    state.style()->setTextEmphasisMark(*value);
    13721374            }
    1373             styleResolver->style()->setTextEmphasisCustomMark(nullAtom);
     1375            state.style()->setTextEmphasisCustomMark(nullAtom);
    13741376            return;
    13751377        }
     
    13801382
    13811383        if (primitiveValue->isString()) {
    1382             styleResolver->style()->setTextEmphasisFill(TextEmphasisFillFilled);
    1383             styleResolver->style()->setTextEmphasisMark(TextEmphasisMarkCustom);
    1384             styleResolver->style()->setTextEmphasisCustomMark(primitiveValue->getStringValue());
    1385             return;
    1386         }
    1387 
    1388         styleResolver->style()->setTextEmphasisCustomMark(nullAtom);
     1384            state.style()->setTextEmphasisFill(TextEmphasisFillFilled);
     1385            state.style()->setTextEmphasisMark(TextEmphasisMarkCustom);
     1386            state.style()->setTextEmphasisCustomMark(primitiveValue->getStringValue());
     1387            return;
     1388        }
     1389
     1390        state.style()->setTextEmphasisCustomMark(nullAtom);
    13891391
    13901392        if (primitiveValue->getIdent() == CSSValueFilled || primitiveValue->getIdent() == CSSValueOpen) {
    1391             styleResolver->style()->setTextEmphasisFill(*primitiveValue);
    1392             styleResolver->style()->setTextEmphasisMark(TextEmphasisMarkAuto);
     1393            state.style()->setTextEmphasisFill(*primitiveValue);
     1394            state.style()->setTextEmphasisMark(TextEmphasisMarkAuto);
    13931395        } else {
    1394             styleResolver->style()->setTextEmphasisFill(TextEmphasisFillFilled);
    1395             styleResolver->style()->setTextEmphasisMark(*primitiveValue);
     1396            state.style()->setTextEmphasisFill(TextEmphasisFillFilled);
     1397            state.style()->setTextEmphasisMark(*primitiveValue);
    13961398        }
    13971399    }
     
    14161418    static void clear(Animation* animation) { (animation->*clearFunction)(); }
    14171419    static T initial() { return (*initialFunction)(); }
    1418     static void map(StyleResolver* styleResolver, Animation* animation, CSSValue* value) { (styleResolver->styleMap()->*mapFunction)(animation, value); }
     1420    static void map(StyleResolver::State& state, Animation* animation, CSSValue* value)
     1421    {
     1422        CSSToStyleMap styleMap(state);
     1423        (styleMap.*mapFunction)(animation, value);
     1424    }
    14191425    static AnimationList* accessAnimations(RenderStyle* style) { return (style->*animationGetterFunction)(); }
    14201426    static const AnimationList* animations(RenderStyle* style) { return (style->*immutableAnimationGetterFunction)(); }
    14211427
    1422     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    1423     {
    1424         AnimationList* list = accessAnimations(styleResolver->style());
    1425         const AnimationList* parentList = animations(styleResolver->parentStyle());
     1428    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     1429    {
     1430        AnimationList* list = accessAnimations(state.style());
     1431        const AnimationList* parentList = animations(state.parentStyle());
    14261432        size_t i = 0, parentSize = parentList ? parentList->size() : 0;
    14271433        for ( ; i < parentSize && test(parentList->animation(i)); ++i) {
     
    14371443    }
    14381444
    1439     static void applyInitialValue(CSSPropertyID propertyID, StyleResolver* styleResolver)
    1440     {
    1441         AnimationList* list = accessAnimations(styleResolver->style());
     1445    static void applyInitialValue(CSSPropertyID propertyID, StyleResolver::State& state)
     1446    {
     1447        AnimationList* list = accessAnimations(state.style());
    14421448        if (list->isEmpty())
    14431449            list->append(Animation::create());
     
    14491455    }
    14501456
    1451     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
    1452     {
    1453         AnimationList* list = accessAnimations(styleResolver->style());
     1457    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
     1458    {
     1459        AnimationList* list = accessAnimations(state.style());
    14541460        size_t childIndex = 0;
    14551461        if (value->isValueList()) {
     
    14581464                if (childIndex <= list->size())
    14591465                    list->append(Animation::create());
    1460                 map(styleResolver, list->animation(childIndex), i.value());
     1466                map(state, list->animation(childIndex), i.value());
    14611467                ++childIndex;
    14621468            }
     
    14641470            if (list->isEmpty())
    14651471                list->append(Animation::create());
    1466             map(styleResolver, list->animation(childIndex), value);
     1472            map(state, list->animation(childIndex), value);
    14671473            childIndex = 1;
    14681474        }
     
    14781484class ApplyPropertyOutlineStyle {
    14791485public:
    1480     static void applyInheritValue(CSSPropertyID propertyID, StyleResolver* styleResolver)
    1481     {
    1482         ApplyPropertyDefaultBase<OutlineIsAuto, &RenderStyle::outlineStyleIsAuto, OutlineIsAuto, &RenderStyle::setOutlineStyleIsAuto, OutlineIsAuto, &RenderStyle::initialOutlineStyleIsAuto>::applyInheritValue(propertyID, styleResolver);
    1483         ApplyPropertyDefaultBase<EBorderStyle, &RenderStyle::outlineStyle, EBorderStyle, &RenderStyle::setOutlineStyle, EBorderStyle, &RenderStyle::initialBorderStyle>::applyInheritValue(propertyID, styleResolver);
    1484     }
    1485 
    1486     static void applyInitialValue(CSSPropertyID propertyID, StyleResolver* styleResolver)
    1487     {
    1488         ApplyPropertyDefaultBase<OutlineIsAuto, &RenderStyle::outlineStyleIsAuto, OutlineIsAuto, &RenderStyle::setOutlineStyleIsAuto, OutlineIsAuto, &RenderStyle::initialOutlineStyleIsAuto>::applyInitialValue(propertyID, styleResolver);
    1489         ApplyPropertyDefaultBase<EBorderStyle, &RenderStyle::outlineStyle, EBorderStyle, &RenderStyle::setOutlineStyle, EBorderStyle, &RenderStyle::initialBorderStyle>::applyInitialValue(propertyID, styleResolver);
    1490     }
    1491 
    1492     static void applyValue(CSSPropertyID propertyID, StyleResolver* styleResolver, CSSValue* value)
    1493     {
    1494         ApplyPropertyDefault<OutlineIsAuto, &RenderStyle::outlineStyleIsAuto, OutlineIsAuto, &RenderStyle::setOutlineStyleIsAuto, OutlineIsAuto, &RenderStyle::initialOutlineStyleIsAuto>::applyValue(propertyID, styleResolver, value);
    1495         ApplyPropertyDefault<EBorderStyle, &RenderStyle::outlineStyle, EBorderStyle, &RenderStyle::setOutlineStyle, EBorderStyle, &RenderStyle::initialBorderStyle>::applyValue(propertyID, styleResolver, value);
     1486    static void applyInheritValue(CSSPropertyID propertyID, StyleResolver::State& state)
     1487    {
     1488        ApplyPropertyDefaultBase<OutlineIsAuto, &RenderStyle::outlineStyleIsAuto, OutlineIsAuto, &RenderStyle::setOutlineStyleIsAuto, OutlineIsAuto, &RenderStyle::initialOutlineStyleIsAuto>::applyInheritValue(propertyID, state);
     1489        ApplyPropertyDefaultBase<EBorderStyle, &RenderStyle::outlineStyle, EBorderStyle, &RenderStyle::setOutlineStyle, EBorderStyle, &RenderStyle::initialBorderStyle>::applyInheritValue(propertyID, state);
     1490    }
     1491
     1492    static void applyInitialValue(CSSPropertyID propertyID, StyleResolver::State& state)
     1493    {
     1494        ApplyPropertyDefaultBase<OutlineIsAuto, &RenderStyle::outlineStyleIsAuto, OutlineIsAuto, &RenderStyle::setOutlineStyleIsAuto, OutlineIsAuto, &RenderStyle::initialOutlineStyleIsAuto>::applyInitialValue(propertyID, state);
     1495        ApplyPropertyDefaultBase<EBorderStyle, &RenderStyle::outlineStyle, EBorderStyle, &RenderStyle::setOutlineStyle, EBorderStyle, &RenderStyle::initialBorderStyle>::applyInitialValue(propertyID, state);
     1496    }
     1497
     1498    static void applyValue(CSSPropertyID propertyID, StyleResolver::State& state, CSSValue* value)
     1499    {
     1500        ApplyPropertyDefault<OutlineIsAuto, &RenderStyle::outlineStyleIsAuto, OutlineIsAuto, &RenderStyle::setOutlineStyleIsAuto, OutlineIsAuto, &RenderStyle::initialOutlineStyleIsAuto>::applyValue(propertyID, state, value);
     1501        ApplyPropertyDefault<EBorderStyle, &RenderStyle::outlineStyle, EBorderStyle, &RenderStyle::setOutlineStyle, EBorderStyle, &RenderStyle::initialBorderStyle>::applyValue(propertyID, state, value);
    14961502    }
    14971503
     
    15011507class ApplyPropertyResize {
    15021508public:
    1503     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1509    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    15041510    {
    15051511        if (!value->isPrimitiveValue())
     
    15131519            return;
    15141520        case CSSValueAuto:
    1515             if (Settings* settings = styleResolver->document()->settings())
     1521            if (Settings* settings = state.document()->settings())
    15161522                r = settings->textAreasAreResizable() ? RESIZE_BOTH : RESIZE_NONE;
    15171523            break;
     
    15191525            r = *primitiveValue;
    15201526        }
    1521         styleResolver->style()->setResize(r);
     1527        state.style()->setResize(r);
    15221528    }
    15231529
     
    15311537class ApplyPropertyVerticalAlign {
    15321538public:
    1533     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1539    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    15341540    {
    15351541        if (!value->isPrimitiveValue())
     
    15391545
    15401546        if (primitiveValue->getIdent())
    1541             return styleResolver->style()->setVerticalAlign(*primitiveValue);
    1542 
    1543         styleResolver->style()->setVerticalAlignLength(primitiveValue->convertToLength<FixedIntegerConversion | PercentConversion | CalculatedConversion | ViewportPercentageConversion>(styleResolver->style(), styleResolver->rootElementStyle(), styleResolver->style()->effectiveZoom()));
     1547            return state.style()->setVerticalAlign(*primitiveValue);
     1548
     1549        state.style()->setVerticalAlignLength(primitiveValue->convertToLength<FixedIntegerConversion | PercentConversion | CalculatedConversion | ViewportPercentageConversion>(state.style(), state.rootElementStyle(), state.style()->effectiveZoom()));
    15441550    }
    15451551
     
    15531559class ApplyPropertyAspectRatio {
    15541560public:
    1555     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    1556     {
    1557         if (!styleResolver->parentStyle()->hasAspectRatio())
    1558             return;
    1559         styleResolver->style()->setHasAspectRatio(true);
    1560         styleResolver->style()->setAspectRatioDenominator(styleResolver->parentStyle()->aspectRatioDenominator());
    1561         styleResolver->style()->setAspectRatioNumerator(styleResolver->parentStyle()->aspectRatioNumerator());
    1562     }
    1563 
    1564     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    1565     {
    1566         styleResolver->style()->setHasAspectRatio(RenderStyle::initialHasAspectRatio());
    1567         styleResolver->style()->setAspectRatioDenominator(RenderStyle::initialAspectRatioDenominator());
    1568         styleResolver->style()->setAspectRatioNumerator(RenderStyle::initialAspectRatioNumerator());
    1569     }
    1570 
    1571     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1561    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     1562    {
     1563        if (!state.parentStyle()->hasAspectRatio())
     1564            return;
     1565        state.style()->setHasAspectRatio(true);
     1566        state.style()->setAspectRatioDenominator(state.parentStyle()->aspectRatioDenominator());
     1567        state.style()->setAspectRatioNumerator(state.parentStyle()->aspectRatioNumerator());
     1568    }
     1569
     1570    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     1571    {
     1572        state.style()->setHasAspectRatio(RenderStyle::initialHasAspectRatio());
     1573        state.style()->setAspectRatioDenominator(RenderStyle::initialAspectRatioDenominator());
     1574        state.style()->setAspectRatioNumerator(RenderStyle::initialAspectRatioNumerator());
     1575    }
     1576
     1577    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    15721578    {
    15731579        if (!value->isAspectRatioValue()) {
    1574             styleResolver->style()->setHasAspectRatio(false);
     1580            state.style()->setHasAspectRatio(false);
    15751581            return;
    15761582        }
    15771583        CSSAspectRatioValue* aspectRatioValue = static_cast<CSSAspectRatioValue*>(value);
    1578         styleResolver->style()->setHasAspectRatio(true);
    1579         styleResolver->style()->setAspectRatioDenominator(aspectRatioValue->denominatorValue());
    1580         styleResolver->style()->setAspectRatioNumerator(aspectRatioValue->numeratorValue());
     1584        state.style()->setHasAspectRatio(true);
     1585        state.style()->setAspectRatioDenominator(aspectRatioValue->denominatorValue());
     1586        state.style()->setAspectRatioNumerator(aspectRatioValue->numeratorValue());
    15811587    }
    15821588
     
    15891595class ApplyPropertyZoom {
    15901596private:
    1591     static void resetEffectiveZoom(StyleResolver* styleResolver)
     1597    static void resetEffectiveZoom(StyleResolver::State& state)
    15921598    {
    15931599        // Reset the zoom in effect. This allows the setZoom method to accurately compute a new zoom in effect.
    1594         styleResolver->setEffectiveZoom(styleResolver->parentStyle() ? styleResolver->parentStyle()->effectiveZoom() : RenderStyle::initialZoom());
    1595     }
    1596 
    1597 public:
    1598     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    1599     {
    1600         resetEffectiveZoom(styleResolver);
    1601         styleResolver->setZoom(styleResolver->parentStyle()->zoom());
    1602     }
    1603 
    1604     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    1605     {
    1606         resetEffectiveZoom(styleResolver);
    1607         styleResolver->setZoom(RenderStyle::initialZoom());
    1608     }
    1609 
    1610     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1600        state.setEffectiveZoom(state.parentStyle() ? state.parentStyle()->effectiveZoom() : RenderStyle::initialZoom());
     1601    }
     1602
     1603public:
     1604    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     1605    {
     1606        resetEffectiveZoom(state);
     1607        state.setZoom(state.parentStyle()->zoom());
     1608    }
     1609
     1610    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     1611    {
     1612        resetEffectiveZoom(state);
     1613        state.setZoom(RenderStyle::initialZoom());
     1614    }
     1615
     1616    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    16111617    {
    16121618        ASSERT_WITH_SECURITY_IMPLICATION(value->isPrimitiveValue());
     
    16141620
    16151621        if (primitiveValue->getIdent() == CSSValueNormal) {
    1616             resetEffectiveZoom(styleResolver);
    1617             styleResolver->setZoom(RenderStyle::initialZoom());
     1622            resetEffectiveZoom(state);
     1623            state.setZoom(RenderStyle::initialZoom());
    16181624        } else if (primitiveValue->getIdent() == CSSValueReset) {
    1619             styleResolver->setEffectiveZoom(RenderStyle::initialZoom());
    1620             styleResolver->setZoom(RenderStyle::initialZoom());
     1625            state.setEffectiveZoom(RenderStyle::initialZoom());
     1626            state.setZoom(RenderStyle::initialZoom());
    16211627        } else if (primitiveValue->getIdent() == CSSValueDocument) {
    1622             float docZoom = styleResolver->rootElementStyle() ? styleResolver->rootElementStyle()->zoom() : RenderStyle::initialZoom();
    1623             styleResolver->setEffectiveZoom(docZoom);
    1624             styleResolver->setZoom(docZoom);
     1628            float docZoom = state.rootElementStyle() ? state.rootElementStyle()->zoom() : RenderStyle::initialZoom();
     1629            state.setEffectiveZoom(docZoom);
     1630            state.setZoom(docZoom);
    16251631        } else if (primitiveValue->isPercentage()) {
    1626             resetEffectiveZoom(styleResolver);
     1632            resetEffectiveZoom(state);
    16271633            if (float percent = primitiveValue->getFloatValue())
    1628                 styleResolver->setZoom(percent / 100.0f);
     1634                state.setZoom(percent / 100.0f);
    16291635        } else if (primitiveValue->isNumber()) {
    1630             resetEffectiveZoom(styleResolver);
     1636            resetEffectiveZoom(state);
    16311637            if (float number = primitiveValue->getFloatValue())
    1632                 styleResolver->setZoom(number);
     1638                state.setZoom(number);
    16331639        }
    16341640    }
     
    16421648class ApplyPropertyDisplay {
    16431649private:
    1644     static inline bool isValidDisplayValue(StyleResolver* styleResolver, EDisplay displayPropertyValue)
     1650    static inline bool isValidDisplayValue(StyleResolver::State& state, EDisplay displayPropertyValue)
    16451651    {
    16461652#if ENABLE(SVG)
    1647         if (styleResolver->element() && styleResolver->element()->isSVGElement() && styleResolver->style()->styleType() == NOPSEUDO)
     1653        if (state.element() && state.element()->isSVGElement() && state.style()->styleType() == NOPSEUDO)
    16481654            return (displayPropertyValue == INLINE || displayPropertyValue == BLOCK || displayPropertyValue == NONE);
    16491655#else
    1650         UNUSED_PARAM(styleResolver);
     1656        UNUSED_PARAM(state);
    16511657        UNUSED_PARAM(displayPropertyValue);
    16521658#endif
     
    16541660    }
    16551661public:
    1656     static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
    1657     {
    1658         EDisplay display = styleResolver->parentStyle()->display();
    1659         if (!isValidDisplayValue(styleResolver, display))
    1660             return;
    1661         styleResolver->style()->setDisplay(display);
    1662     }
    1663 
    1664     static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
    1665     {
    1666         styleResolver->style()->setDisplay(RenderStyle::initialDisplay());
    1667     }
    1668 
    1669     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1662    static void applyInheritValue(CSSPropertyID, StyleResolver::State& state)
     1663    {
     1664        EDisplay display = state.parentStyle()->display();
     1665        if (!isValidDisplayValue(state, display))
     1666            return;
     1667        state.style()->setDisplay(display);
     1668    }
     1669
     1670    static void applyInitialValue(CSSPropertyID, StyleResolver::State& state)
     1671    {
     1672        state.style()->setDisplay(RenderStyle::initialDisplay());
     1673    }
     1674
     1675    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    16701676    {
    16711677        if (!value->isPrimitiveValue())
     
    16741680        EDisplay display = *static_cast<CSSPrimitiveValue*>(value);
    16751681
    1676         if (!isValidDisplayValue(styleResolver, display))
    1677             return;
    1678 
    1679         styleResolver->style()->setDisplay(display);
     1682        if (!isValidDisplayValue(state, display))
     1683            return;
     1684
     1685        state.style()->setDisplay(display);
    16801686    }
    16811687
     
    16901696public:
    16911697    static void setValue(RenderStyle* style, PassRefPtr<ClipPathOperation> value) { (style->*setterFunction)(value); }
    1692     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1698    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    16931699    {
    16941700        if (value->isPrimitiveValue()) {
    16951701            CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    16961702            if (primitiveValue->getIdent() == CSSValueNone)
    1697                 setValue(styleResolver->style(), 0);
     1703                setValue(state.style(), 0);
    16981704            else if (primitiveValue->isShape()) {
    1699                 setValue(styleResolver->style(), ShapeClipPathOperation::create(basicShapeForValue(styleResolver, primitiveValue->getShapeValue())));
     1705                setValue(state.style(), ShapeClipPathOperation::create(basicShapeForValue(state, primitiveValue->getShapeValue())));
    17001706            }
    17011707#if ENABLE(SVG)
    17021708            else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_URI) {
    17031709                String cssURLValue = primitiveValue->getStringValue();
    1704                 KURL url = styleResolver->document()->completeURL(cssURLValue);
     1710                KURL url = state.document()->completeURL(cssURLValue);
    17051711                // FIXME: It doesn't work with forward or external SVG references (see https://bugs.webkit.org/show_bug.cgi?id=90405)
    1706                 setValue(styleResolver->style(), ReferenceClipPathOperation::create(cssURLValue, url.fragmentIdentifier()));
     1712                setValue(state.style(), ReferenceClipPathOperation::create(cssURLValue, url.fragmentIdentifier()));
    17071713            }
    17081714#endif
     
    17211727public:
    17221728    static void setValue(RenderStyle* style, PassRefPtr<ExclusionShapeValue> value) { (style->*setterFunction)(value); }
    1723     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1729    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    17241730    {
    17251731        if (value->isPrimitiveValue()) {
    17261732            CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    17271733            if (primitiveValue->getIdent() == CSSValueAuto)
    1728                 setValue(styleResolver->style(), 0);
     1734                setValue(state.style(), 0);
    17291735            // FIXME Bug 102571: Layout for the value 'outside-shape' is not yet implemented
    17301736            else if (primitiveValue->getIdent() == CSSValueOutsideShape)
    1731                 setValue(styleResolver->style(), ExclusionShapeValue::createOutsideValue());
     1737                setValue(state.style(), ExclusionShapeValue::createOutsideValue());
    17321738            else if (primitiveValue->isShape()) {
    1733                 RefPtr<ExclusionShapeValue> shape = ExclusionShapeValue::createShapeValue(basicShapeForValue(styleResolver, primitiveValue->getShapeValue()));
    1734                 setValue(styleResolver->style(), shape.release());
     1739                RefPtr<ExclusionShapeValue> shape = ExclusionShapeValue::createShapeValue(basicShapeForValue(state, primitiveValue->getShapeValue()));
     1740                setValue(state.style(), shape.release());
    17351741            }
    17361742        }
     
    17471753class ApplyPropertyImageResolution {
    17481754public:
    1749     static void applyInheritValue(CSSPropertyID propertyID, StyleResolver* styleResolver)
    1750     {
    1751         ApplyPropertyDefaultBase<ImageResolutionSource, &RenderStyle::imageResolutionSource, ImageResolutionSource, &RenderStyle::setImageResolutionSource, ImageResolutionSource, &RenderStyle::initialImageResolutionSource>::applyInheritValue(propertyID, styleResolver);
    1752         ApplyPropertyDefaultBase<ImageResolutionSnap, &RenderStyle::imageResolutionSnap, ImageResolutionSnap, &RenderStyle::setImageResolutionSnap, ImageResolutionSnap, &RenderStyle::initialImageResolutionSnap>::applyInheritValue(propertyID, styleResolver);
    1753         ApplyPropertyDefaultBase<float, &RenderStyle::imageResolution, float, &RenderStyle::setImageResolution, float, &RenderStyle::initialImageResolution>::applyInheritValue(propertyID, styleResolver);
    1754     }
    1755 
    1756     static void applyInitialValue(CSSPropertyID propertyID, StyleResolver* styleResolver)
    1757     {
    1758         ApplyPropertyDefaultBase<ImageResolutionSource, &RenderStyle::imageResolutionSource, ImageResolutionSource, &RenderStyle::setImageResolutionSource, ImageResolutionSource, &RenderStyle::initialImageResolutionSource>::applyInitialValue(propertyID, styleResolver);
    1759         ApplyPropertyDefaultBase<ImageResolutionSnap, &RenderStyle::imageResolutionSnap, ImageResolutionSnap, &RenderStyle::setImageResolutionSnap, ImageResolutionSnap, &RenderStyle::initialImageResolutionSnap>::applyInitialValue(propertyID, styleResolver);
    1760         ApplyPropertyDefaultBase<float, &RenderStyle::imageResolution, float, &RenderStyle::setImageResolution, float, &RenderStyle::initialImageResolution>::applyInitialValue(propertyID, styleResolver);
    1761     }
    1762 
    1763     static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
     1755    static void applyInheritValue(CSSPropertyID propertyID, StyleResolver::State& state)
     1756    {
     1757        ApplyPropertyDefaultBase<ImageResolutionSource, &RenderStyle::imageResolutionSource, ImageResolutionSource, &RenderStyle::setImageResolutionSource, ImageResolutionSource, &RenderStyle::initialImageResolutionSource>::applyInheritValue(propertyID, state);
     1758        ApplyPropertyDefaultBase<ImageResolutionSnap, &RenderStyle::imageResolutionSnap, ImageResolutionSnap, &RenderStyle::setImageResolutionSnap, ImageResolutionSnap, &RenderStyle::initialImageResolutionSnap>::applyInheritValue(propertyID, state);
     1759        ApplyPropertyDefaultBase<float, &RenderStyle::imageResolution, float, &RenderStyle::setImageResolution, float, &RenderStyle::initialImageResolution>::applyInheritValue(propertyID, state);
     1760    }
     1761
     1762    static void applyInitialValue(CSSPropertyID propertyID, StyleResolver::State& state)
     1763    {
     1764        ApplyPropertyDefaultBase<ImageResolutionSource, &RenderStyle::imageResolutionSource, ImageResolutionSource, &RenderStyle::setImageResolutionSource, ImageResolutionSource, &RenderStyle::initialImageResolutionSource>::applyInitialValue(propertyID, state);
     1765        ApplyPropertyDefaultBase<ImageResolutionSnap, &RenderStyle::imageResolutionSnap, ImageResolutionSnap, &RenderStyle::setImageResolutionSnap, ImageResolutionSnap, &RenderStyle::initialImageResolutionSnap>::applyInitialValue(propertyID, state);
     1766        ApplyPropertyDefaultBase<float, &RenderStyle::imageResolution, float, &RenderStyle::setImageResolution, float, &RenderStyle::initialImageResolution>::applyInitialValue(propertyID, state);
     1767    }
     1768
     1769    static void applyValue(CSSPropertyID, StyleResolver::State& state, CSSValue* value)
    17641770    {
    17651771        if (!value->isValueList())
     
    17811787                resolution = primitiveValue->getDoubleValue(CSSPrimitiveValue::CSS_DPPX);
    17821788        }
    1783         styleResolver->style()->setImageResolutionSource(source);
    1784         styleResolver->style()->setImageResolutionSnap(snap);
    1785         styleResolver->style()->setImageResolution(resolution);
     1789        state.style()->setImageResolutionSource(source);
     1790        state.style()->setImageResolutionSnap(snap);
     1791        state.style()->setImageResolution(resolution);
    17861792    }
    17871793
  • trunk/Source/WebCore/css/StyleBuilder.h

    r128656 r143556  
    2727
    2828#include "CSSPropertyNames.h"
     29#include "StyleResolver.h"
    2930#include <wtf/PassRefPtr.h>
    3031#include <wtf/RefCounted.h>
     
    3435class CSSValue;
    3536class StyleBuilder;
    36 class StyleResolver;
    3737
    3838class PropertyHandler {
    3939public:
    40     typedef void (*InheritFunction)(CSSPropertyID, StyleResolver*);
    41     typedef void (*InitialFunction)(CSSPropertyID, StyleResolver*);
    42     typedef void (*ApplyFunction)(CSSPropertyID, StyleResolver*, CSSValue*);
     40    typedef void (*InheritFunction)(CSSPropertyID, StyleResolver::State&);
     41    typedef void (*InitialFunction)(CSSPropertyID, StyleResolver::State&);
     42    typedef void (*ApplyFunction)(CSSPropertyID, StyleResolver::State&, CSSValue*);
    4343    PropertyHandler() : m_inherit(0), m_initial(0), m_apply(0) { }
    4444    PropertyHandler(InheritFunction inherit, InitialFunction initial, ApplyFunction apply) : m_inherit(inherit), m_initial(initial), m_apply(apply) { }
    45     void applyInheritValue(CSSPropertyID propertyID, StyleResolver* styleResolver) const { ASSERT(m_inherit); (*m_inherit)(propertyID, styleResolver); }
    46     void applyInitialValue(CSSPropertyID propertyID, StyleResolver* styleResolver) const { ASSERT(m_initial); (*m_initial)(propertyID, styleResolver); }
    47     void applyValue(CSSPropertyID propertyID, StyleResolver* styleResolver, CSSValue* value) const { ASSERT(m_apply); (*m_apply)(propertyID, styleResolver, value); }
     45    void applyInheritValue(CSSPropertyID propertyID, StyleResolver::State& state) const { ASSERT(m_inherit); (*m_inherit)(propertyID, state); }
     46    void applyInitialValue(CSSPropertyID propertyID, StyleResolver::State& state) const { ASSERT(m_initial); (*m_initial)(propertyID, state); }
     47    void applyValue(CSSPropertyID propertyID, StyleResolver::State& state, CSSValue* value) const { ASSERT(m_apply); (*m_apply)(propertyID, state, value); }
    4848    bool isValid() const { return m_inherit && m_initial && m_apply; }
    4949    InheritFunction inheritFunction() const { return m_inherit; }
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r143300 r143556  
    4848#include "CSSSupportsRule.h"
    4949#include "CSSTimingFunctionValue.h"
     50#include "CSSToStyleMap.h"
    5051#include "CSSValueList.h"
    5152#if ENABLE(CSS_VARIABLES)
     
    195196#define HANDLE_INHERIT(prop, Prop) \
    196197if (isInherit) { \
    197     m_state.style()->set##Prop(m_state.parentStyle()->prop()); \
     198    state.style()->set##Prop(state.parentStyle()->prop()); \
    198199    return; \
    199200}
     
    202203HANDLE_INHERIT(prop, Prop) \
    203204if (isInitial) { \
    204     m_state.style()->set##Prop(RenderStyle::initial##Prop()); \
     205    state.style()->set##Prop(RenderStyle::initial##Prop()); \
    205206    return; \
    206207}
     
    223224    return rightToLeftDecl.get();
    224225}
    225 
    226226
    227227inline StaticCSSRuleList* StyleResolver::State::ensureRuleList()
     
    270270#endif
    271271    , m_styleBuilder(StyleBuilder::sharedStyleBuilder())
    272     , m_styleMap(this)
    273272{
    274273    Element* root = document->documentElement();
     
    454453bool MatchingUARulesScope::m_matchingUARules = false;
    455454
    456 void StyleResolver::collectMatchingRules(const MatchRequest& matchRequest, RuleRange& ruleRange)
     455void StyleResolver::collectMatchingRules(State& state, const MatchRequest& matchRequest, RuleRange& ruleRange)
    457456{
    458457    ASSERT(matchRequest.ruleSet);
    459     ASSERT(m_state.element());
    460 
    461     State& state = m_state;
     458    ASSERT(state.element());
     459
    462460    Element* element = state.element();
    463461    const StyledElement* styledElement = state.styledElement();
     
    465463    if (!pseudoId.isEmpty()) {
    466464        ASSERT(styledElement);
    467         collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRules(pseudoId.impl()), matchRequest, ruleRange);
     465        collectMatchingRulesForList(state, matchRequest.ruleSet->shadowPseudoElementRules(pseudoId.impl()), matchRequest, ruleRange);
    468466    }
    469467
    470468#if ENABLE(VIDEO_TRACK)
    471469    if (element->isWebVTTElement())
    472         collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), matchRequest, ruleRange);
     470        collectMatchingRulesForList(state, matchRequest.ruleSet->cuePseudoRules(), matchRequest, ruleRange);
    473471#endif
    474472    // Check whether other types of rules are applicable in the current tree scope. Criteria for this:
     
    486484    // then sort the buffer.
    487485    if (element->hasID())
    488         collectMatchingRulesForList(matchRequest.ruleSet->idRules(element->idForStyleResolution().impl()), matchRequest, ruleRange);
     486        collectMatchingRulesForList(state, matchRequest.ruleSet->idRules(element->idForStyleResolution().impl()), matchRequest, ruleRange);
    489487    if (styledElement && styledElement->hasClass()) {
    490488        for (size_t i = 0; i < styledElement->classNames().size(); ++i)
    491             collectMatchingRulesForList(matchRequest.ruleSet->classRules(styledElement->classNames()[i].impl()), matchRequest, ruleRange);
     489            collectMatchingRulesForList(state, matchRequest.ruleSet->classRules(styledElement->classNames()[i].impl()), matchRequest, ruleRange);
    492490    }
    493491
    494492    if (element->isLink())
    495         collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules(), matchRequest, ruleRange);
     493        collectMatchingRulesForList(state, matchRequest.ruleSet->linkPseudoClassRules(), matchRequest, ruleRange);
    496494    if (SelectorChecker::matchesFocusPseudoClass(element))
    497         collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(), matchRequest, ruleRange);
    498     collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element->localName().impl()), matchRequest, ruleRange);
    499     collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), matchRequest, ruleRange);
    500 }
    501 
    502 void StyleResolver::collectMatchingRulesForRegion(const MatchRequest& matchRequest, RuleRange& ruleRange)
    503 {
    504     if (!m_state.regionForStyling())
     495        collectMatchingRulesForList(state, matchRequest.ruleSet->focusPseudoClassRules(), matchRequest, ruleRange);
     496    collectMatchingRulesForList(state, matchRequest.ruleSet->tagRules(element->localName().impl()), matchRequest, ruleRange);
     497    collectMatchingRulesForList(state, matchRequest.ruleSet->universalRules(), matchRequest, ruleRange);
     498}
     499
     500void StyleResolver::collectMatchingRulesForRegion(State& state, const MatchRequest& matchRequest, RuleRange& ruleRange)
     501{
     502    if (!state.regionForStyling())
    505503        return;
    506504
     
    508506    for (unsigned i = 0; i < size; ++i) {
    509507        const CSSSelector* regionSelector = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.at(i).selector;
    510         if (checkRegionSelector(regionSelector, static_cast<Element*>(m_state.regionForStyling()->node()))) {
     508        if (checkRegionSelector(regionSelector, static_cast<Element*>(state.regionForStyling()->node()))) {
    511509            RuleSet* regionRules = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.at(i).ruleSet.get();
    512510            ASSERT(regionRules);
    513             collectMatchingRules(MatchRequest(regionRules, matchRequest.includeEmptyRules, matchRequest.scope), ruleRange);
    514         }
    515     }
    516 }
    517 
    518 void StyleResolver::sortAndTransferMatchedRules(MatchResult& result)
    519 {
    520     State& state = m_state;
     511            collectMatchingRules(state, MatchRequest(regionRules, matchRequest.includeEmptyRules, matchRequest.scope), ruleRange);
     512        }
     513    }
     514}
     515
     516void StyleResolver::sortAndTransferMatchedRules(State& state, MatchResult& result)
     517{
    521518    Vector<const RuleData*, 32>& matchedRules = state.matchedRules();
    522519    if (matchedRules.isEmpty())
    523520        return;
    524521
    525     sortMatchedRules();
     522    sortMatchedRules(state);
    526523
    527524    if (state.mode() == SelectorChecker::CollectingRules) {
     
    539536}
    540537
    541 void StyleResolver::matchScopedAuthorRules(MatchResult& result, bool includeEmptyRules)
     538void StyleResolver::matchScopedAuthorRules(State& state, MatchResult& result, bool includeEmptyRules)
    542539{
    543540#if ENABLE(STYLE_SCOPED) || ENABLE(SHADOW_DOM)
     
    546543
    547544    // Match scoped author rules by traversing the scoped element stack (rebuild it if it got inconsistent).
    548     if (m_scopeResolver->hasScopedStyles() && m_scopeResolver->ensureStackConsistency(m_state.element())) {
    549         bool applyAuthorStyles = m_state.element()->treeScope()->applyAuthorStyles();
     545    if (m_scopeResolver->hasScopedStyles() && m_scopeResolver->ensureStackConsistency(state.element())) {
     546        bool applyAuthorStyles = state.element()->treeScope()->applyAuthorStyles();
    550547        bool documentScope = true;
    551548        unsigned scopeSize = m_scopeResolver->stackSize();
    552549        for (unsigned i = 0; i < scopeSize; ++i) {
    553             m_state.matchedRules().clear();
     550            state.matchedRules().clear();
    554551            result.ranges.lastAuthorRule = result.matchedProperties.size() - 1;
    555552
     
    566563            MatchRequest matchRequest(frame.m_ruleSet, includeEmptyRules, frame.m_scope);
    567564            RuleRange ruleRange = result.ranges.authorRuleRange();
    568             collectMatchingRules(matchRequest, ruleRange);
    569             collectMatchingRulesForRegion(matchRequest, ruleRange);
    570             sortAndTransferMatchedRules(result);
    571         }
    572     }
    573 
    574     matchHostRules(result, includeEmptyRules);
     565            collectMatchingRules(state, matchRequest, ruleRange);
     566            collectMatchingRulesForRegion(state, matchRequest, ruleRange);
     567            sortAndTransferMatchedRules(state, result);
     568        }
     569    }
     570
     571    matchHostRules(state, result, includeEmptyRules);
    575572#else
     573    UNUSED_PARAM(state);
    576574    UNUSED_PARAM(result);
    577575    UNUSED_PARAM(includeEmptyRules);
     
    579577}
    580578
    581 inline bool StyleResolver::styleSharingCandidateMatchesHostRules()
     579inline bool StyleResolver::styleSharingCandidateMatchesHostRules(State& state)
    582580{
    583581#if ENABLE(SHADOW_DOM)
    584     return m_scopeResolver && m_scopeResolver->styleSharingCandidateMatchesHostRules(m_state.element());
     582    return m_scopeResolver && m_scopeResolver->styleSharingCandidateMatchesHostRules(state.element());
    585583#else
    586584    return false;
    587 #endif
    588 }
    589 
    590 void StyleResolver::matchHostRules(MatchResult& result, bool includeEmptyRules)
     585    UNUSED_PARAM(state);
     586#endif
     587}
     588
     589void StyleResolver::matchHostRules(State& state, MatchResult& result, bool includeEmptyRules)
    591590{
    592591#if ENABLE(SHADOW_DOM)
    593592    ASSERT(m_scopeResolver);
    594593
    595     m_state.matchedRules().clear();
     594    state.matchedRules().clear();
    596595    result.ranges.lastAuthorRule = result.matchedProperties.size() - 1;
    597596
    598597    Vector<RuleSet*> matchedRules;
    599     m_scopeResolver->matchHostRules(m_state.element(), matchedRules);
     598    m_scopeResolver->matchHostRules(state.element(), matchedRules);
    600599    if (matchedRules.isEmpty())
    601600        return;
     
    603602    for (unsigned i = matchedRules.size(); i > 0; --i) {
    604603        RuleRange ruleRange = result.ranges.authorRuleRange();
    605         collectMatchingRules(MatchRequest(matchedRules.at(i-1), includeEmptyRules, m_state.element()), ruleRange);
    606     }
    607     sortAndTransferMatchedRules(result);
     604        collectMatchingRules(state, MatchRequest(matchedRules.at(i-1), includeEmptyRules, state.element()), ruleRange);
     605    }
     606    sortAndTransferMatchedRules(state, result);
    608607#else
     608    UNUSED_PARAM(state);
    609609    UNUSED_PARAM(result);
    610610    UNUSED_PARAM(includeEmptyRules);
     
    612612}
    613613
    614 void StyleResolver::matchAuthorRules(MatchResult& result, bool includeEmptyRules)
    615 {
    616     m_state.matchedRules().clear();
     614void StyleResolver::matchAuthorRules(State& state, MatchResult& result, bool includeEmptyRules)
     615{
     616    state.matchedRules().clear();
    617617    result.ranges.lastAuthorRule = result.matchedProperties.size() - 1;
    618618
    619     if (!m_state.element())
     619    if (!state.element())
    620620        return;
    621621
     
    623623    MatchRequest matchRequest(m_ruleSets.authorStyle(), includeEmptyRules);
    624624    RuleRange ruleRange = result.ranges.authorRuleRange();
    625     collectMatchingRules(matchRequest, ruleRange);
    626     collectMatchingRulesForRegion(matchRequest, ruleRange);
     625    collectMatchingRules(state, matchRequest, ruleRange);
     626    collectMatchingRulesForRegion(state, matchRequest, ruleRange);
    627627#if ENABLE(SHADOW_DOM)
    628628    Vector<MatchRequest> matchRequests;
    629629    m_ruleSets.shadowDistributedRules().collectMatchRequests(includeEmptyRules, matchRequests);
    630630    for (size_t i = 0; i < matchRequests.size(); ++i)
    631         collectMatchingRules(matchRequests[i], ruleRange);
    632 #endif
    633 
    634     sortAndTransferMatchedRules(result);
    635 
    636     matchScopedAuthorRules(result, includeEmptyRules);
    637 }
    638 
    639 void StyleResolver::matchUserRules(MatchResult& result, bool includeEmptyRules)
     631        collectMatchingRules(state, matchRequests[i], ruleRange);
     632#endif
     633
     634    sortAndTransferMatchedRules(state, result);
     635
     636    matchScopedAuthorRules(state, result, includeEmptyRules);
     637}
     638
     639void StyleResolver::matchUserRules(State& state, MatchResult& result, bool includeEmptyRules)
    640640{
    641641    if (!m_ruleSets.userStyle())
    642642        return;
    643643   
    644     m_state.matchedRules().clear();
     644    state.matchedRules().clear();
    645645
    646646    result.ranges.lastUserRule = result.matchedProperties.size() - 1;
    647647    MatchRequest matchRequest(m_ruleSets.userStyle(), includeEmptyRules);
    648648    RuleRange ruleRange = result.ranges.userRuleRange();
    649     collectMatchingRules(matchRequest, ruleRange);
    650     collectMatchingRulesForRegion(matchRequest, ruleRange);
    651 
    652     sortAndTransferMatchedRules(result);
    653 }
    654 
    655 void StyleResolver::matchUARules(MatchResult& result, RuleSet* rules)
    656 {
    657     m_state.matchedRules().clear();
     649    collectMatchingRules(state, matchRequest, ruleRange);
     650    collectMatchingRulesForRegion(state, matchRequest, ruleRange);
     651
     652    sortAndTransferMatchedRules(state, result);
     653}
     654
     655void StyleResolver::matchUARules(State& state, MatchResult& result, RuleSet* rules)
     656{
     657    state.matchedRules().clear();
    658658   
    659659    result.ranges.lastUARule = result.matchedProperties.size() - 1;
    660660    RuleRange ruleRange = result.ranges.UARuleRange();
    661     collectMatchingRules(MatchRequest(rules), ruleRange);
    662 
    663     sortAndTransferMatchedRules(result);
    664 }
    665 
    666 void StyleResolver::collectMatchingRulesForList(const Vector<RuleData>* rules, const MatchRequest& matchRequest, RuleRange& ruleRange)
     661    collectMatchingRules(state, MatchRequest(rules), ruleRange);
     662
     663    sortAndTransferMatchedRules(state, result);
     664}
     665
     666void StyleResolver::collectMatchingRulesForList(State& state, const Vector<RuleData>* rules, const MatchRequest& matchRequest, RuleRange& ruleRange)
    667667{
    668668    if (!rules)
    669669        return;
    670670
    671     State& state = m_state;
    672671    // In some cases we may end up looking up style for random elements in the middle of a recursive tree resolve.
    673672    // Ancestor identifier filter won't be up-to-date in that case and we can't use the fast path.
     
    683682        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willMatchRule(document(), rule, this);
    684683        PseudoId dynamicPseudo = NOPSEUDO;
    685         if (ruleMatches(ruleData, matchRequest.scope, dynamicPseudo, matchRequest.behaviorAtBoundary)) {
     684        if (ruleMatches(state, ruleData, matchRequest.scope, dynamicPseudo, matchRequest.behaviorAtBoundary)) {
    686685            // If the rule has no properties to apply, then ignore it in the non-debug mode.
    687686            const StylePropertySet* properties = rule->properties();
     
    711710
    712711                // Add this rule to our list of matched rules.
    713                 m_state.addMatchedRule(&ruleData);
     712                state.addMatchedRule(&ruleData);
    714713                InspectorInstrumentation::didMatchRule(cookie, true);
    715714                continue;
     
    727726}
    728727
    729 void StyleResolver::sortMatchedRules()
    730 {
    731     std::sort(m_state.matchedRules().begin(), m_state.matchedRules().end(), compareRules);
    732 }
    733 
    734 void StyleResolver::matchAllRules(MatchResult& result, bool includeSMILProperties)
    735 {
    736     matchUARules(result);
     728void StyleResolver::sortMatchedRules(State& state)
     729{
     730    std::sort(state.matchedRules().begin(), state.matchedRules().end(), compareRules);
     731}
     732
     733void StyleResolver::matchAllRules(State& state, MatchResult& result, bool includeSMILProperties)
     734{
     735    matchUARules(state, result);
    737736
    738737    // Now we check user sheet rules.
    739738    if (m_matchAuthorAndUserStyles)
    740         matchUserRules(result, false);
     739        matchUserRules(state, result, false);
    741740
    742741    // Now check author rules, beginning first with presentational attributes mapped from HTML.
    743     if (m_state.styledElement()) {
    744         addElementStyleProperties(result, m_state.styledElement()->presentationAttributeStyle());
     742    if (state.styledElement()) {
     743        addElementStyleProperties(result, state.styledElement()->presentationAttributeStyle());
    745744
    746745        // Now we check additional mapped declarations.
    747746        // Tables and table cells share an additional mapped rule that must be applied
    748747        // after all attributes, since their mapped style depends on the values of multiple attributes.
    749         addElementStyleProperties(result, m_state.styledElement()->additionalPresentationAttributeStyle());
    750 
    751         if (m_state.styledElement()->isHTMLElement()) {
     748        addElementStyleProperties(result, state.styledElement()->additionalPresentationAttributeStyle());
     749
     750        if (state.styledElement()->isHTMLElement()) {
    752751            bool isAuto;
    753             TextDirection textDirection = toHTMLElement(m_state.styledElement())->directionalityIfhasDirAutoAttribute(isAuto);
     752            TextDirection textDirection = toHTMLElement(state.styledElement())->directionalityIfhasDirAutoAttribute(isAuto);
    754753            if (isAuto)
    755754                addMatchedProperties(result, textDirection == LTR ? leftToRightDeclaration() : rightToLeftDeclaration());
     
    759758    // Check the rules in author sheets next.
    760759    if (m_matchAuthorAndUserStyles)
    761         matchAuthorRules(result, false);
     760        matchAuthorRules(state, result, false);
    762761
    763762    // Now check our inline style attribute.
    764     if (m_matchAuthorAndUserStyles && m_state.styledElement() && m_state.styledElement()->inlineStyle()) {
     763    if (m_matchAuthorAndUserStyles && state.styledElement() && state.styledElement()->inlineStyle()) {
    765764        // Inline style is immutable as long as there is no CSSOM wrapper.
    766765        // FIXME: Media control shadow trees seem to have problems with caching.
    767         bool isInlineStyleCacheable = !m_state.styledElement()->inlineStyle()->isMutable() && !m_state.styledElement()->isInShadowTree();
     766        bool isInlineStyleCacheable = !state.styledElement()->inlineStyle()->isMutable() && !state.styledElement()->isInShadowTree();
    768767        // FIXME: Constify.
    769         addElementStyleProperties(result, m_state.styledElement()->inlineStyle(), isInlineStyleCacheable);
     768        addElementStyleProperties(result, state.styledElement()->inlineStyle(), isInlineStyleCacheable);
    770769    }
    771770
    772771#if ENABLE(SVG)
    773772    // Now check SMIL animation override style.
    774     if (includeSMILProperties && m_matchAuthorAndUserStyles && m_state.styledElement() && m_state.styledElement()->isSVGElement())
    775         addElementStyleProperties(result, static_cast<SVGElement*>(m_state.styledElement())->animatedSMILStyleProperties(), false /* isCacheable */);
     773    if (includeSMILProperties && m_matchAuthorAndUserStyles && state.styledElement() && state.styledElement()->isSVGElement())
     774        addElementStyleProperties(result, static_cast<SVGElement*>(state.styledElement())->animatedSMILStyleProperties(), false /* isCacheable */);
    776775#else
    777776    UNUSED_PARAM(includeSMILProperties);
     
    795794}
    796795
    797 inline void StyleResolver::initElement(Element* e)
    798 {
    799     if (m_state.element() != e) {
    800         m_state.initElement(e);
    801         if (e && e == e->document()->documentElement()) {
    802             e->document()->setDirectionSetOnDocumentElement(false);
    803             e->document()->setWritingModeSetOnDocumentElement(false);
    804         }
     796inline void StyleResolver::initElement(State& state, Element* e)
     797{
     798    state.initElement(e);
     799    if (e && e == e->document()->documentElement()) {
     800        e->document()->setDirectionSetOnDocumentElement(false);
     801        e->document()->setWritingModeSetOnDocumentElement(false);
    805802    }
    806803}
     
    890887}
    891888
    892 bool StyleResolver::styleSharingCandidateMatchesRuleSet(RuleSet* ruleSet)
     889bool StyleResolver::styleSharingCandidateMatchesRuleSet(Element* e, RuleSet* ruleSet)
    893890{
    894891    if (!ruleSet)
    895892        return false;
    896     m_state.matchedRules().clear();
    897 
    898     m_state.setMode(SelectorChecker::SharingRules);
     893
     894    State state(document());
     895    state.initElement(e);
     896    state.setMode(SelectorChecker::SharingRules);
    899897    int firstRuleIndex = -1, lastRuleIndex = -1;
    900898    RuleRange ruleRange(firstRuleIndex, lastRuleIndex);
    901     collectMatchingRules(MatchRequest(ruleSet), ruleRange);
    902     m_state.setMode(SelectorChecker::ResolvingStyle);
    903     if (m_state.matchedRules().isEmpty())
    904         return false;
    905     m_state.matchedRules().clear();
    906     return true;
    907 }
    908 
    909 bool StyleResolver::canShareStyleWithControl(StyledElement* element) const
    910 {
    911     const State& state = m_state;
     899    collectMatchingRules(state, MatchRequest(ruleSet), ruleRange);
     900    return !state.matchedRules().isEmpty();
     901}
     902
     903bool StyleResolver::canShareStyleWithControl(const State& state, StyledElement* element) const
     904{
    912905    HTMLInputElement* thisInputElement = element->toInputElement();
    913906    HTMLInputElement* otherInputElement = state.element()->toInputElement();
     
    963956}
    964957
    965 bool StyleResolver::sharingCandidateHasIdenticalStyleAffectingAttributes(StyledElement* sharingCandidate) const
    966 {
    967     const State& state = m_state;
     958bool StyleResolver::sharingCandidateHasIdenticalStyleAffectingAttributes(const State& state, StyledElement* sharingCandidate) const
     959{
    968960    if (state.element()->elementData() == sharingCandidate->elementData())
    969961        return true;
     
    1005997}
    1006998
    1007 bool StyleResolver::canShareStyleWithElement(StyledElement* element) const
     999bool StyleResolver::canShareStyleWithElement(const State& state, StyledElement* element) const
    10081000{
    10091001    RenderStyle* style = element->renderStyle();
    1010     const State& state = m_state;
    10111002
    10121003    if (!style)
     
    10381029    if (element == element->document()->cssTarget())
    10391030        return false;
    1040     if (!sharingCandidateHasIdenticalStyleAffectingAttributes(element))
     1031    if (!sharingCandidateHasIdenticalStyleAffectingAttributes(state, element))
    10411032        return false;
    10421033    if (element->additionalPresentationAttributeStyle() != state.styledElement()->additionalPresentationAttributeStyle())
     
    10591050        return false;
    10601051
    1061     if (isControl && !canShareStyleWithControl(element))
     1052    if (isControl && !canShareStyleWithControl(state, element))
    10621053        return false;
    10631054
     
    10991090}
    11001091
    1101 inline StyledElement* StyleResolver::findSiblingForStyleSharing(Node* node, unsigned& count) const
     1092inline StyledElement* StyleResolver::findSiblingForStyleSharing(const State& state, Node* node, unsigned& count) const
    11021093{
    11031094    for (; node; node = node->previousSibling()) {
    11041095        if (!node->isStyledElement())
    11051096            continue;
    1106         if (canShareStyleWithElement(static_cast<StyledElement*>(node)))
     1097        if (canShareStyleWithElement(state, static_cast<StyledElement*>(node)))
    11071098            break;
    11081099        if (count++ == cStyleSearchThreshold)
     
    11121103}
    11131104
    1114 RenderStyle* StyleResolver::locateSharedStyle()
    1115 {
    1116     State& state = m_state;
     1105RenderStyle* StyleResolver::locateSharedStyle(State& state)
     1106{
    11171107    if (!state.styledElement() || !state.parentStyle())
    11181108        return 0;
     
    11471137    Node* cousinList = state.styledElement()->previousSibling();
    11481138    while (cousinList) {
    1149         shareElement = findSiblingForStyleSharing(cousinList, count);
     1139        shareElement = findSiblingForStyleSharing(state, cousinList, count);
    11501140        if (shareElement)
    11511141            break;
     
    11581148
    11591149    // Can't share if sibling rules apply. This is checked at the end as it should rarely fail.
    1160     if (styleSharingCandidateMatchesRuleSet(m_ruleSets.sibling()))
     1150    if (styleSharingCandidateMatchesRuleSet(state.element(), m_ruleSets.sibling()))
    11611151        return 0;
    11621152    // Can't share if attribute rules apply.
    1163     if (styleSharingCandidateMatchesRuleSet(m_ruleSets.uncommonAttribute()))
     1153    if (styleSharingCandidateMatchesRuleSet(state.element(), m_ruleSets.uncommonAttribute()))
    11641154        return 0;
    11651155    // Can't share if @host @-rules apply.
    1166     if (styleSharingCandidateMatchesHostRules())
     1156    if (styleSharingCandidateMatchesHostRules(state))
    11671157        return 0;
    11681158    // Tracking child index requires unique style for each node. This may get set by the sibling rule match above.
     
    11721162}
    11731163
    1174 void StyleResolver::matchUARules(MatchResult& result)
     1164void StyleResolver::matchUARules(State& state, MatchResult& result)
    11751165{
    11761166    MatchingUARulesScope scope;
     
    11811171    RuleSet* userAgentStyleSheet = m_medium->mediaTypeMatchSpecific("print")
    11821172        ? CSSDefaultStyleSheets::defaultPrintStyle : CSSDefaultStyleSheets::defaultStyle;
    1183     matchUARules(result, userAgentStyleSheet);
     1173    matchUARules(state, result, userAgentStyleSheet);
    11841174
    11851175    // In quirks mode, we match rules from the quirks user agent sheet.
    11861176    if (document()->inQuirksMode())
    1187         matchUARules(result, CSSDefaultStyleSheets::defaultQuirksStyle);
     1177        matchUARules(state, result, CSSDefaultStyleSheets::defaultQuirksStyle);
    11881178
    11891179    // If document uses view source styles (in view source mode or in xml viewer mode), then we match rules from the view source style sheet.
    11901180    if (document()->isViewSource())
    1191         matchUARules(result, CSSDefaultStyleSheets::viewSourceStyle());
     1181        matchUARules(state, result, CSSDefaultStyleSheets::viewSourceStyle());
    11921182}
    11931183
     
    13871377    }
    13881378
    1389     State& state = m_state;
    1390     initElement(element);
     1379    State state(document());
     1380    initElement(state, element);
    13911381    state.initForStyleResolve(document(), element, defaultParent, NOPSEUDO, regionForStyling);
    13921382    if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoint()) {
    1393         RenderStyle* sharedStyle = locateSharedStyle();
     1383        RenderStyle* sharedStyle = locateSharedStyle(state);
    13941384        if (sharedStyle)
    13951385            return sharedStyle;
     
    13971387
    13981388    RefPtr<RenderStyle> cloneForParent;
     1389    RefPtr<RenderStyle> style;
    13991390
    14001391    if (state.parentStyle()) {
    1401         state.setStyle(RenderStyle::create());
    1402         state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(element) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
     1392        style = RenderStyle::create();
     1393        style->inheritFrom(state.parentStyle(), isAtShadowBoundary(element) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
    14031394    } else {
    1404         state.setStyle(defaultStyleForElement());
    1405         cloneForParent = RenderStyle::clone(state.style());
     1395        style = defaultStyleForElement();
     1396        cloneForParent = RenderStyle::clone(style.get());
    14061397        state.setParentStyle(cloneForParent.get());
    14071398    }
     1399    state.setStyle(style);
     1400
    14081401    // contenteditable attribute (implemented by -webkit-user-modify) should
    14091402    // be propagated from shadow host to distributed node.
     
    14331426    MatchResult matchResult;
    14341427    if (matchingBehavior == MatchOnlyUserAgentRules)
    1435         matchUARules(matchResult);
     1428        matchUARules(state, matchResult);
    14361429    else
    1437         matchAllRules(matchResult, matchingBehavior != MatchAllRulesExcludingSMIL);
    1438 
    1439     applyMatchedProperties(matchResult, element);
     1430        matchAllRules(state, matchResult, matchingBehavior != MatchAllRulesExcludingSMIL);
     1431
     1432    applyMatchedProperties(state, matchResult, element);
    14401433
    14411434    // Clean up our style object's display and text decorations (among other fixups).
    1442     adjustRenderStyle(state.style(), state.parentStyle(), element);
    1443 
    1444     state.clear(); // Clear out for the next resolve.
     1435    adjustRenderStyle(state, style.get(), state.parentStyle(), element);
    14451436
    14461437    document()->didAccessStyleResolver();
     
    14501441}
    14511442
    1452 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(const RenderStyle* elementStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue)
     1443PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(State& state, const RenderStyle* elementStyle, const StyleKeyframe* keyframe, KeyframeValue& keyframeValue)
    14531444{
    14541445    MatchResult result;
     
    14561447        addMatchedProperties(result, keyframe->properties());
    14571448
    1458     ASSERT(!m_state.style());
    1459 
    1460     State& state = m_state;
    1461 
    14621449    // Create the style
    1463     state.setStyle(RenderStyle::clone(elementStyle));
     1450    RefPtr<RenderStyle> style = RenderStyle::clone(elementStyle);
     1451    state.setStyle(style);
    14641452    state.setLineHeightValue(0);
    14651453
     
    14681456    bool inheritedOnly = false;
    14691457    if (keyframe->properties())
    1470         applyMatchedProperties<HighPriorityProperties>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
     1458        applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
    14711459
    14721460    // If our font got dirtied, go ahead and update it now.
    1473     updateFont();
     1461    updateFont(state);
    14741462
    14751463    // Line-height is set when we are sure we decided on the font-size
    14761464    if (state.lineHeightValue())
    1477         applyProperty(CSSPropertyLineHeight, state.lineHeightValue());
     1465        applyProperty(state, CSSPropertyLineHeight, state.lineHeightValue());
    14781466
    14791467    // Now do rest of the properties.
    14801468    if (keyframe->properties())
    1481         applyMatchedProperties<LowPriorityProperties>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
     1469        applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
    14821470
    14831471    // If our font got dirtied by one of the non-essential font props,
    14841472    // go ahead and update it a second time.
    1485     updateFont();
     1473    updateFont(state);
    14861474
    14871475    // Start loading resources referenced by this style.
    1488     loadPendingResources();
     1476    loadPendingResources(state);
    14891477   
    14901478    // Add all the animating properties to the keyframe.
     
    15231511    // Construct and populate the style for each keyframe
    15241512    const Vector<RefPtr<StyleKeyframe> >& keyframes = keyframesRule->keyframes();
     1513    State state(document());
     1514    initElement(state, e);
     1515    state.initForStyleResolve(document(), e);
    15251516    for (unsigned i = 0; i < keyframes.size(); ++i) {
    15261517        // Apply the declaration to the style. This is a simplified version of the logic in styleForElement
    1527         initElement(e);
    1528         m_state.initForStyleResolve(document(), e);
    1529 
    15301518        const StyleKeyframe* keyframe = keyframes[i].get();
    15311519
    15321520        KeyframeValue keyframeValue(0, 0);
    1533         keyframeValue.setStyle(styleForKeyframe(elementStyle, keyframe, keyframeValue));
     1521        keyframeValue.setStyle(styleForKeyframe(state, elementStyle, keyframe, keyframeValue));
    15341522
    15351523        // Add this keyframe style to all the indicated key times
     
    15511539        }
    15521540        KeyframeValue keyframeValue(0, 0);
    1553         keyframeValue.setStyle(styleForKeyframe(elementStyle, zeroPercentKeyframe, keyframeValue));
     1541        keyframeValue.setStyle(styleForKeyframe(state, elementStyle, zeroPercentKeyframe, keyframeValue));
    15541542        list.insert(keyframeValue);
    15551543    }
     
    15631551        }
    15641552        KeyframeValue keyframeValue(1, 0);
    1565         keyframeValue.setStyle(styleForKeyframe(elementStyle, hundredPercentKeyframe, keyframeValue));
     1553        keyframeValue.setStyle(styleForKeyframe(state, elementStyle, hundredPercentKeyframe, keyframeValue));
    15661554        list.insert(keyframeValue);
    15671555    }
     
    15741562        return 0;
    15751563
    1576     State& state = m_state;
    1577 
    1578     initElement(e);
    1579 
     1564    State state(document());
     1565    initElement(state, e);
    15801566    state.initForStyleResolve(document(), e, parentStyle, pseudo);
    15811567    state.setStyle(RenderStyle::create());
    1582     state.style()->inheritFrom(m_state.parentStyle());
     1568    state.style()->inheritFrom(state.parentStyle());
    15831569
    15841570    // Since we don't use pseudo-elements in any of our quirk/print user agent rules, don't waste time walking
     
    15871573    // Check UA, user and author rules.
    15881574    MatchResult matchResult;
    1589     matchUARules(matchResult);
     1575    matchUARules(state, matchResult);
    15901576
    15911577    if (m_matchAuthorAndUserStyles) {
    1592         matchUserRules(matchResult, false);
    1593         matchAuthorRules(matchResult, false);
     1578        matchUserRules(state, matchResult, false);
     1579        matchAuthorRules(state, matchResult, false);
    15941580    }
    15951581
     
    15991585    state.style()->setStyleType(pseudo);
    16001586
    1601     applyMatchedProperties(matchResult, e);
     1587    applyMatchedProperties(state, matchResult, e);
    16021588
    16031589    // Clean up our style object's display and text decorations (among other fixups).
    1604     adjustRenderStyle(state.style(), m_state.parentStyle(), 0);
     1590    adjustRenderStyle(state, state.style(), state.parentStyle(), 0);
    16051591
    16061592    // Start loading resources referenced by this style.
    1607     loadPendingResources();
     1593    loadPendingResources(state);
    16081594
    16091595    document()->didAccessStyleResolver();
     
    16151601PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex)
    16161602{
    1617     m_state.initForStyleResolve(document(), document()->documentElement()); // m_rootElementStyle will be set to the document style.
    1618 
    1619     m_state.setStyle(RenderStyle::create());
    1620     m_state.style()->inheritFrom(m_state.rootElementStyle());
    1621 
    1622     const bool isLeft = isLeftPage(pageIndex);
     1603    State state(document());
     1604    state.initForStyleResolve(document(), document()->documentElement()); // m_rootElementStyle will be set to the document style.
     1605
     1606    state.setStyle(RenderStyle::create());
     1607    state.style()->inheritFrom(state.rootElementStyle());
     1608
     1609    const bool isLeft = isLeftPage(state, pageIndex);
    16231610    const bool isFirst = isFirstPage(pageIndex);
    16241611    const String page = pageName(pageIndex);
     
    16291616    // Only consider the global author RuleSet for @page rules, as per the HTML5 spec.
    16301617    matchPageRules(result, m_ruleSets.authorStyle(), isLeft, isFirst, page);
    1631     m_state.setLineHeightValue(0);
     1618    state.setLineHeightValue(0);
    16321619    bool inheritedOnly = false;
    16331620#if ENABLE(CSS_VARIABLES)
    1634     applyMatchedProperties<VariableDefinitions>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
    1635 #endif
    1636     applyMatchedProperties<HighPriorityProperties>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
     1621    applyMatchedProperties<VariableDefinitions>(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
     1622#endif
     1623    applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
    16371624
    16381625    // If our font got dirtied, go ahead and update it now.
    1639     updateFont();
     1626    updateFont(state);
    16401627
    16411628    // Line-height is set when we are sure we decided on the font-size.
    1642     if (m_state.lineHeightValue())
    1643         applyProperty(CSSPropertyLineHeight, m_state.lineHeightValue());
    1644 
    1645     applyMatchedProperties<LowPriorityProperties>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
     1629    if (state.lineHeightValue())
     1630        applyProperty(state, CSSPropertyLineHeight, state.lineHeightValue());
     1631
     1632    applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
    16461633
    16471634    // Start loading resources referenced by this style.
    1648     loadPendingResources();
     1635    loadPendingResources(state);
    16491636
    16501637    document()->didAccessStyleResolver();
    16511638
    16521639    // Now return the style.
    1653     return m_state.takeStyle();
     1640    return state.takeStyle();
    16541641}
    16551642
    16561643PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement()
    16571644{
    1658     m_state.setStyle(RenderStyle::create());
     1645    State state(document());
     1646    state.setStyle(RenderStyle::create());
    16591647    // Make sure our fonts are initialized if we don't inherit them from our parent style.
    16601648    if (Settings* settings = documentSettings()) {
    1661         initializeFontStyle(settings);
    1662         m_state.style()->font().update(fontSelector());
     1649        initializeFontStyle(state, settings);
     1650        state.style()->font().update(fontSelector());
    16631651    } else
    1664         m_state.style()->font().update(0);
    1665 
    1666     return m_state.takeStyle();
     1652        state.style()->font().update(0);
     1653
     1654    return state.takeStyle();
    16671655}
    16681656
     
    17591747}
    17601748
    1761 void StyleResolver::adjustRenderStyle(RenderStyle* style, RenderStyle* parentStyle, Element *e)
     1749void StyleResolver::adjustRenderStyle(State& state, RenderStyle* style, RenderStyle* parentStyle, Element *e)
    17621750{
    17631751    ASSERT(parentStyle);
     
    19521940    // Let the theme also have a crack at adjusting the style.
    19531941    if (style->hasAppearance())
    1954         RenderTheme::defaultTheme()->adjustStyle(this, style, e, m_state.hasUAAppearance(), m_state.borderData(), m_state.backgroundData(), m_state.backgroundColor());
     1942        RenderTheme::defaultTheme()->adjustStyle(this, style, e, state.hasUAAppearance(), state.borderData(), state.backgroundData(), state.backgroundColor());
    19551943
    19561944    // If we have first-letter pseudo style, do not share this style.
     
    20332021}
    20342022
    2035 void StyleResolver::updateFont()
    2036 {
    2037     if (!m_state.fontDirty())
    2038         return;
    2039 
    2040     checkForTextSizeAdjust();
    2041     RenderStyle* style = m_state.style();
    2042     checkForGenericFamilyChange(style, m_state.parentStyle());
    2043     checkForZoomChange(style, m_state.parentStyle());
     2023void StyleResolver::updateFont(State& state)
     2024{
     2025    if (!state.fontDirty())
     2026        return;
     2027
     2028    checkForTextSizeAdjust(state);
     2029    RenderStyle* style = state.style();
     2030    checkForGenericFamilyChange(state, style, state.parentStyle());
     2031    checkForZoomChange(state, style, state.parentStyle());
    20442032    checkForOrientationChange(style);
    20452033    style->font().update(m_fontSelector);
    2046     m_state.setFontDirty(false);
     2034    state.setFontDirty(false);
    20472035}
    20482036
     
    20572045        return 0;
    20582046
    2059     m_state.setMode(SelectorChecker::CollectingRules);
    2060 
    2061     initElement(e);
    2062     m_state.initForStyleResolve(document(), e, 0, pseudoId);
     2047    State state(document());
     2048    state.setMode(SelectorChecker::CollectingRules);
     2049
     2050    initElement(state, e);
     2051    state.initForStyleResolve(document(), e, 0, pseudoId);
    20632052
    20642053    MatchResult dummy;
    20652054    if (rulesToInclude & UAAndUserCSSRules) {
    20662055        // First we match rules from the user agent sheet.
    2067         matchUARules(dummy);
     2056        matchUARules(state, dummy);
    20682057
    20692058        // Now we check user sheet rules.
    20702059        if (m_matchAuthorAndUserStyles)
    2071             matchUserRules(dummy, rulesToInclude & EmptyCSSRules);
     2060            matchUserRules(state, dummy, rulesToInclude & EmptyCSSRules);
    20722061    }
    20732062
    20742063    if (m_matchAuthorAndUserStyles && (rulesToInclude & AuthorCSSRules)) {
    2075         m_state.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules));
     2064        state.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules));
    20762065
    20772066        // Check the rules in author sheets.
    2078         matchAuthorRules(dummy, rulesToInclude & EmptyCSSRules);
    2079 
    2080         m_state.setSameOriginOnly(false);
    2081     }
    2082 
    2083     m_state.setMode(SelectorChecker::ResolvingStyle);
    2084 
    2085     return m_state.takeRuleList();
    2086 }
    2087 
    2088 inline bool StyleResolver::ruleMatches(const RuleData& ruleData, const ContainerNode* scope, PseudoId& dynamicPseudo, SelectorChecker::BehaviorAtBoundary behaviorAtBoundary)
    2089 {
    2090     State& state = m_state;
    2091 
     2067        matchAuthorRules(state, dummy, rulesToInclude & EmptyCSSRules);
     2068    }
     2069
     2070    return state.takeRuleList();
     2071}
     2072
     2073inline bool StyleResolver::ruleMatches(State& state, const RuleData& ruleData, const ContainerNode* scope, PseudoId& dynamicPseudo, SelectorChecker::BehaviorAtBoundary behaviorAtBoundary)
     2074{
    20922075    if (ruleData.hasFastCheckableSelector()) {
    20932076        // We know this selector does not include any pseudo elements.
     
    21282111        return false;
    21292112
    2130     SelectorChecker selectorChecker(document(), m_state.mode());
     2113    SelectorChecker selectorChecker(document(), SelectorChecker::QueryingRules);
    21312114    for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s))
    21322115        if (selectorChecker.matches(s, regionElement))
     
    21502133
    21512134template <StyleResolver::StyleApplicationPass pass>
    2152 void StyleResolver::applyProperties(const StylePropertySet* properties, StyleRule* rule, bool isImportant, bool inheritedOnly, PropertyWhitelistType propertyWhitelistType)
    2153 {
    2154     ASSERT((propertyWhitelistType != PropertyWhitelistRegion) || m_state.regionForStyling());
     2135void StyleResolver::applyProperties(State& state, const StylePropertySet* properties, StyleRule* rule, bool isImportant, bool inheritedOnly, PropertyWhitelistType propertyWhitelistType)
     2136{
     2137    ASSERT((propertyWhitelistType != PropertyWhitelistRegion) || state.regionForStyling());
    21552138    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willProcessRule(document(), rule, this);
    21562139
     
    21802163            COMPILE_ASSERT(CSSPropertyVariable < firstCSSProperty, CSS_variable_is_before_first_property);
    21812164            if (property == CSSPropertyVariable)
    2182                 applyProperty(current.id(), current.value());
     2165                applyProperty(state, current.id(), current.value());
    21832166            break;
    21842167#endif
     
    21932176            // give special priority to font-xxx, color properties, etc
    21942177            if (property < CSSPropertyLineHeight)
    2195                 applyProperty(current.id(), current.value());
     2178                applyProperty(state, current.id(), current.value());
    21962179            // we apply line-height later
    21972180            else if (property == CSSPropertyLineHeight)
    2198                 m_state.setLineHeightValue(current.value());
     2181                state.setLineHeightValue(current.value());
    21992182            break;
    22002183        case LowPriorityProperties:
    22012184            if (property > CSSPropertyLineHeight)
    2202                 applyProperty(current.id(), current.value());
     2185                applyProperty(state, current.id(), current.value());
    22032186        }
    22042187    }
     
    22072190
    22082191template <StyleResolver::StyleApplicationPass pass>
    2209 void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, bool isImportant, int startIndex, int endIndex, bool inheritedOnly)
     2192void StyleResolver::applyMatchedProperties(State& state, const MatchResult& matchResult, bool isImportant, int startIndex, int endIndex, bool inheritedOnly)
    22102193{
    22112194    if (startIndex == -1)
    22122195        return;
    22132196
    2214     State& state = m_state;
    22152197    if (state.style()->insideLink() != NotInsideLink) {
    22162198        for (int i = startIndex; i <= endIndex; ++i) {
     
    22212203            state.setApplyPropertyToVisitedLinkStyle(linkMatchType & SelectorChecker::MatchVisited);
    22222204
    2223             applyProperties<pass>(matchedProperties.properties.get(), matchResult.matchedRules[i], isImportant, inheritedOnly, static_cast<PropertyWhitelistType>(matchedProperties.whitelistType));
     2205            applyProperties<pass>(state, matchedProperties.properties.get(), matchResult.matchedRules[i], isImportant, inheritedOnly, static_cast<PropertyWhitelistType>(matchedProperties.whitelistType));
    22242206        }
    22252207        state.setApplyPropertyToRegularStyle(true);
     
    22292211    for (int i = startIndex; i <= endIndex; ++i) {
    22302212        const MatchedProperties& matchedProperties = matchResult.matchedProperties[i];
    2231         applyProperties<pass>(matchedProperties.properties.get(), matchResult.matchedRules[i], isImportant, inheritedOnly, static_cast<PropertyWhitelistType>(matchedProperties.whitelistType));
     2213        applyProperties<pass>(state, matchedProperties.properties.get(), matchResult.matchedRules[i], isImportant, inheritedOnly, static_cast<PropertyWhitelistType>(matchedProperties.whitelistType));
    22322214    }
    22332215}
     
    23292311}
    23302312
    2331 void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const Element* element)
     2313void StyleResolver::applyMatchedProperties(State& state, const MatchResult& matchResult, const Element* element)
    23322314{
    23332315    ASSERT(element);
    2334     State& state = m_state;
    23352316    unsigned cacheHash = matchResult.isCacheable ? computeMatchedPropertiesHash(matchResult.matchedProperties.data(), matchResult.matchedProperties.size()) : 0;
    23362317    bool applyInheritedOnly = false;
     
    23562337#if ENABLE(CSS_VARIABLES)
    23572338    // First apply all variable definitions, as they may be used during application of later properties.
    2358     applyMatchedProperties<VariableDefinitions>(matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
    2359     applyMatchedProperties<VariableDefinitions>(matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
    2360     applyMatchedProperties<VariableDefinitions>(matchResult, true, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
    2361     applyMatchedProperties<VariableDefinitions>(matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
     2339    applyMatchedProperties<VariableDefinitions>(state, matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
     2340    applyMatchedProperties<VariableDefinitions>(state, matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
     2341    applyMatchedProperties<VariableDefinitions>(state, matchResult, true, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
     2342    applyMatchedProperties<VariableDefinitions>(state, matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
    23622343#endif
    23632344
     
    23672348    // and (4) normal important.
    23682349    state.setLineHeightValue(0);
    2369     applyMatchedProperties<HighPriorityProperties>(matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
    2370     applyMatchedProperties<HighPriorityProperties>(matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
    2371     applyMatchedProperties<HighPriorityProperties>(matchResult, true, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
    2372     applyMatchedProperties<HighPriorityProperties>(matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
     2350    applyMatchedProperties<HighPriorityProperties>(state, matchResult, false, 0, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
     2351    applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
     2352    applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
     2353    applyMatchedProperties<HighPriorityProperties>(state, matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
    23732354
    23742355    if (cacheItem && cacheItem->renderStyle->effectiveZoom() != state.style()->effectiveZoom()) {
     
    23782359
    23792360    // If our font got dirtied, go ahead and update it now.
    2380     updateFont();
     2361    updateFont(state);
    23812362
    23822363    // Line-height is set when we are sure we decided on the font-size.
    23832364    if (state.lineHeightValue())
    2384         applyProperty(CSSPropertyLineHeight, state.lineHeightValue());
     2365        applyProperty(state, CSSPropertyLineHeight, state.lineHeightValue());
    23852366
    23862367    // Many properties depend on the font. If it changes we just apply all properties.
     
    23892370
    23902371    // Now do the normal priority UA properties.
    2391     applyMatchedProperties<LowPriorityProperties>(matchResult, false, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
     2372    applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
    23922373   
    23932374    // Cache our border and background so that we can examine them later.
     
    23952376   
    23962377    // Now do the author and user normal priority properties and all the !important properties.
    2397     applyMatchedProperties<LowPriorityProperties>(matchResult, false, matchResult.ranges.lastUARule + 1, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
    2398     applyMatchedProperties<LowPriorityProperties>(matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
    2399     applyMatchedProperties<LowPriorityProperties>(matchResult, true, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
    2400     applyMatchedProperties<LowPriorityProperties>(matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
     2378    applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, matchResult.ranges.lastUARule + 1, matchResult.matchedProperties.size() - 1, applyInheritedOnly);
     2379    applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matchResult.ranges.firstAuthorRule, matchResult.ranges.lastAuthorRule, applyInheritedOnly);
     2380    applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matchResult.ranges.firstUserRule, matchResult.ranges.lastUserRule, applyInheritedOnly);
     2381    applyMatchedProperties<LowPriorityProperties>(state, matchResult, true, matchResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
    24012382   
    24022383    // Start loading resources referenced by this style.
    2403     loadPendingResources();
     2384    loadPendingResources(state);
    24042385   
    24052386    ASSERT(!state.fontDirty());
     
    24712452}
    24722453
    2473 bool StyleResolver::isLeftPage(int pageIndex) const
     2454bool StyleResolver::isLeftPage(State& state, int pageIndex) const
    24742455{
    24752456    bool isFirstPageLeft = false;
    2476     if (!m_state.rootElementStyle()->isLeftToRightDirection())
     2457    if (!state.rootElementStyle()->isLeftToRightDirection())
    24772458        isFirstPageLeft = true;
    24782459
     
    24922473}
    24932474
    2494 void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, RenderStyle* style)
    2495 {
    2496     initElement(0);
    2497     m_state.initForStyleResolve(document(), 0, style);
    2498     m_state.setStyle(style);
    2499     applyPropertyToCurrentStyle(id, value);
    2500 }
    2501 
    2502 void StyleResolver::applyPropertyToCurrentStyle(CSSPropertyID id, CSSValue* value)
    2503 {
    2504     if (value)
    2505         applyProperty(id, value);
     2475void StyleResolver::applyPropertyWithNullCheck(State& state, CSSPropertyID id, CSSValue* value)
     2476{
     2477    if (!value)
     2478        return;
     2479    applyProperty(state, id, value);
     2480}
     2481
     2482void StyleResolver::applyFontPropertyToStyle(RenderStyle* style, const StylePropertySet* parsedStyle)
     2483{
     2484    State state(document());
     2485    state.initForStyleResolve(document(), 0, style);
     2486    state.setStyle(style);
     2487
     2488    applyPropertyWithNullCheck(state, CSSPropertyFontFamily, parsedStyle->getPropertyCSSValue(CSSPropertyFontFamily).get());
     2489    applyPropertyWithNullCheck(state, CSSPropertyFontStyle, parsedStyle->getPropertyCSSValue(CSSPropertyFontStyle).get());
     2490    applyPropertyWithNullCheck(state, CSSPropertyFontVariant, parsedStyle->getPropertyCSSValue(CSSPropertyFontVariant).get());
     2491    applyPropertyWithNullCheck(state, CSSPropertyFontWeight, parsedStyle->getPropertyCSSValue(CSSPropertyFontWeight).get());
     2492
     2493    // As described in BUG66291, setting font-size and line-height on a font may entail a CSSPrimitiveValue::computeLengthDouble call,
     2494    // which assumes the fontMetrics are available for the affected font, otherwise a crash occurs (see http://trac.webkit.org/changeset/96122).
     2495    // The updateFont() calls below update the fontMetrics and ensure the proper setting of font-size and line-height.
     2496    updateFont(state);
     2497    applyPropertyWithNullCheck(state, CSSPropertyFontSize, parsedStyle->getPropertyCSSValue(CSSPropertyFontSize).get());
     2498    updateFont(state);
     2499    applyPropertyWithNullCheck(state, CSSPropertyLineHeight, parsedStyle->getPropertyCSSValue(CSSPropertyLineHeight).get());
    25062500}
    25072501
     
    26062600// if we'd pass a 1.0 zoom factor everyhwere. So we only pass a zoom factor of 1.0 for specific
    26072601// properties that are NOT allowed to scale within a zoomed SVG document (letter/word-spacing/font-size).
    2608 bool StyleResolver::useSVGZoomRules()
    2609 {
    2610     return m_state.element() && m_state.element()->isSVGElement();
    2611 }
    26122602
    26132603static bool createGridTrackBreadth(CSSPrimitiveValue* primitiveValue, const StyleResolver::State& state, Length& workingLength)
     
    27272717}
    27282718
    2729 void StyleResolver::resolveVariables(CSSPropertyID id, CSSValue* value, Vector<std::pair<CSSPropertyID, String> >& knownExpressions)
    2730 {
    2731     std::pair<CSSPropertyID, String> expression(id, value->serializeResolvingVariables(*m_state.style()->variables()));
     2719void StyleResolver::resolveVariables(State& state, CSSPropertyID id, CSSValue* value, Vector<std::pair<CSSPropertyID, String> >& knownExpressions)
     2720{
     2721    std::pair<CSSPropertyID, String> expression(id, value->serializeResolvingVariables(*state.style()->variables()));
    27322722
    27332723    if (knownExpressions.contains(expression))
     
    27442734        StylePropertySet::PropertyReference property = resultSet->propertyAt(i);
    27452735        if (property.id() != CSSPropertyVariable && hasVariableReference(property.value()))
    2746             resolveVariables(property.id(), property.value(), knownExpressions);
     2736            resolveVariables(state, property.id(), property.value(), knownExpressions);
    27472737        else
    2748             applyProperty(property.id(), property.value());
    2749     }
    2750 }
    2751 #endif
    2752 
    2753 void StyleResolver::applyProperty(CSSPropertyID id, CSSValue* value)
     2738            applyProperty(state, property.id(), property.value());
     2739    }
     2740}
     2741#endif
     2742
     2743void StyleResolver::applyProperty(State& state, CSSPropertyID id, CSSValue* value)
    27542744{
    27552745#if ENABLE(CSS_VARIABLES)
    27562746    if (id != CSSPropertyVariable && hasVariableReference(value)) {
    27572747        Vector<std::pair<CSSPropertyID, String> > knownExpressions;
    2758         resolveVariables(id, value, knownExpressions);
    2759         return;
    2760     }
    2761 #endif
    2762 
    2763     State& state = m_state;
     2748        resolveVariables(state, id, value, knownExpressions);
     2749        return;
     2750    }
     2751#endif
     2752
    27642753    bool isInherit = state.parentNode() && value->isInheritedValue();
    27652754    bool isInitial = value->isInitialValue() || (!state.parentNode() && value->isInheritedValue());
     
    27912780    if (handler.isValid()) {
    27922781        if (isInherit)
    2793             handler.applyInheritValue(id, this);
     2782            handler.applyInheritValue(id, state);
    27942783        else if (isInitial)
    2795             handler.applyInitialValue(id, this);
     2784            handler.applyInitialValue(id, state);
    27962785        else
    2797             handler.applyValue(id, this, value);
     2786            handler.applyValue(id, state, value);
    27982787        return;
    27992788    }
     
    28272816                if (item->isImageGeneratorValue()) {
    28282817                    if (item->isGradientValue())
    2829                         state.style()->setContent(StyleGeneratedImage::create(static_cast<CSSGradientValue*>(item)->gradientWithStylesResolved(this).get()), didSet);
     2818                        state.style()->setContent(StyleGeneratedImage::create(static_cast<CSSGradientValue*>(item)->gradientWithStylesResolved(state).get()), didSet);
    28302819                    else
    28312820                        state.style()->setContent(StyleGeneratedImage::create(static_cast<CSSImageGeneratorValue*>(item)), didSet);
     
    28332822#if ENABLE(CSS_IMAGE_SET)
    28342823                } else if (item->isImageSetValue()) {
    2835                     state.style()->setContent(setOrPendingFromValue(CSSPropertyContent, static_cast<CSSImageSetValue*>(item)), didSet);
     2824                    state.style()->setContent(setOrPendingFromValue(state, CSSPropertyContent, static_cast<CSSImageSetValue*>(item)), didSet);
    28362825                    didSet = true;
    28372826#endif
     
    28392828
    28402829                if (item->isImageValue()) {
    2841                     state.style()->setContent(cachedOrPendingFromValue(CSSPropertyContent, static_cast<CSSImageValue*>(item)), didSet);
     2830                    state.style()->setContent(cachedOrPendingFromValue(state, CSSPropertyContent, static_cast<CSSImageValue*>(item)), didSet);
    28422831                    didSet = true;
    28432832                    continue;
     
    29412930            fontDescription.setFamily(parentFontDescription.firstFamily());
    29422931            fontDescription.setIsSpecifiedFont(parentFontDescription.isSpecifiedFont());
    2943             setFontDescription(fontDescription);
     2932            state.setFontDescription(fontDescription);
    29442933            return;
    29452934        }
     
    29512940            // to non-monospace.
    29522941            if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize())
    2953                 setFontSize(fontDescription, fontSizeForKeyword(document(), CSSValueXxSmall + fontDescription.keywordSize() - 1, false));
     2942                setFontSize(state, fontDescription, fontSizeForKeyword(document(), CSSValueXxSmall + fontDescription.keywordSize() - 1, false));
    29542943            fontDescription.setGenericFamily(initialDesc.genericFamily());
    29552944            if (!initialDesc.firstFamily().familyIsEmpty())
    29562945                fontDescription.setFamily(initialDesc.firstFamily());
    2957             setFontDescription(fontDescription);
     2946            state.setFontDescription(fontDescription);
    29582947            return;
    29592948        }
     
    30303019        if (currFamily) {
    30313020            if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize() != oldFamilyUsedFixedDefaultSize)
    3032                 setFontSize(fontDescription, fontSizeForKeyword(document(), CSSValueXxSmall + fontDescription.keywordSize() - 1, !oldFamilyUsedFixedDefaultSize));
    3033 
    3034             setFontDescription(fontDescription);
     3021                setFontSize(state, fontDescription, fontSizeForKeyword(document(), CSSValueXxSmall + fontDescription.keywordSize() - 1, !oldFamilyUsedFixedDefaultSize));
     3022
     3023            state.setFontDescription(fontDescription);
    30353024        }
    30363025        return;
     
    30573046            state.style()->setLineHeight(state.parentStyle()->specifiedLineHeight());
    30583047            state.setLineHeightValue(0);
    3059             setFontDescription(fontDescription);
     3048            state.setFontDescription(fontDescription);
    30603049        } else if (isInitial) {
    30613050            Settings* settings = documentSettings();
     
    30633052            if (!settings)
    30643053                return;
    3065             initializeFontStyle(settings);
     3054            initializeFontStyle(state, settings);
    30663055        } else if (primitiveValue) {
    30673056            state.style()->setLineHeight(RenderStyle::initialLineHeight());
     
    30823071
    30833072                // Handle the zoom factor.
    3084                 fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(document(), state.style(), fontDescription.isAbsoluteSize(), fontDescription.specifiedSize(), useSVGZoomRules()));
    3085                 setFontDescription(fontDescription);
     3073                fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(document(), state.style(), fontDescription.isAbsoluteSize(), fontDescription.specifiedSize(), state.useSVGZoomRules()));
     3074                state.setFontDescription(fontDescription);
    30863075            }
    30873076        } else if (value->isFontValue()) {
     
    30903079                || !font->size || !font->lineHeight || !font->family)
    30913080                return;
    3092             applyProperty(CSSPropertyFontStyle, font->style.get());
    3093             applyProperty(CSSPropertyFontVariant, font->variant.get());
    3094             applyProperty(CSSPropertyFontWeight, font->weight.get());
     3081            applyProperty(state, CSSPropertyFontStyle, font->style.get());
     3082            applyProperty(state, CSSPropertyFontVariant, font->variant.get());
     3083            applyProperty(state, CSSPropertyFontWeight, font->weight.get());
    30953084            // The previous properties can dirty our font but they don't try to read the font's
    30963085            // properties back, which is safe. However if font-size is using the 'ex' unit, it will
    30973086            // need query the dirtied font's x-height to get the computed size. To be safe in this
    30983087            // case, let's just update the font now.
    3099             updateFont();
    3100             applyProperty(CSSPropertyFontSize, font->size.get());
     3088            updateFont(state);
     3089            applyProperty(state, CSSPropertyFontSize, font->size.get());
    31013090
    31023091            state.setLineHeightValue(font->lineHeight.get());
    31033092
    3104             applyProperty(CSSPropertyFontFamily, font->family.get());
     3093            applyProperty(state, CSSPropertyFontFamily, font->family.get());
    31053094        }
    31063095        return;
     
    31333122            Color color;
    31343123            if (item->color)
    3135                 color = colorFromPrimitiveValue(item->color.get());
     3124                color = colorFromPrimitiveValue(state, item->color.get());
    31363125            else if (state.style())
    31373126                color = state.style()->color();
     
    31623151        NinePieceImage mask;
    31633152        mask.setMaskDefaults();
    3164         m_styleMap.mapNinePieceImage(id, reflectValue->mask(), mask);
     3153        CSSToStyleMap styleMap(state);
     3154        styleMap.mapNinePieceImage(id, reflectValue->mask(), mask);
    31653155        reflection->setMask(mask);
    31663156
     
    32543244        FontDescription fontDescription = state.style()->fontDescription();
    32553245        fontDescription.setScript(localeToScriptCodeForFontSelection(state.style()->locale()));
    3256         setFontDescription(fontDescription);
     3246        state.setFontDescription(fontDescription);
    32573247        return;
    32583248    }
     
    32613251        if (!primitiveValue || !primitiveValue->getIdent())
    32623252            return;
    3263         setTextSizeAdjust(primitiveValue->getIdent() == CSSValueAuto);
     3253        state.setTextSizeAdjust(primitiveValue->getIdent() == CSSValueAuto);
    32643254        return;
    32653255    }
     
    33883378            break;
    33893379
    3390         Color col = colorFromPrimitiveValue(primitiveValue);
     3380        Color col = colorFromPrimitiveValue(state, primitiveValue);
    33913381        state.style()->setTapHighlightColor(col);
    33923382        return;
     
    34433433        CSSPropertyID newId = CSSProperty::resolveDirectionAwareProperty(id, state.style()->direction(), state.style()->writingMode());
    34443434        ASSERT(newId != id);
    3445         return applyProperty(newId, value);
     3435        return applyProperty(state, newId, value);
    34463436    }
    34473437    case CSSPropertyFontStretch:
     
    34733463       
    34743464        if (primitiveValue)
    3475             setWritingMode(*primitiveValue);
     3465            state.setWritingMode(*primitiveValue);
    34763466
    34773467        // FIXME: It is not ok to modify document state while applying style.
     
    34853475
    34863476        if (primitiveValue)
    3487             setTextOrientation(*primitiveValue);
     3477            state.setTextOrientation(*primitiveValue);
    34883478
    34893479        return;
     
    35083498    case CSSPropertyWebkitFontFeatureSettings: {
    35093499        if (primitiveValue && primitiveValue->getIdent() == CSSValueNormal) {
    3510             setFontDescription(state.style()->fontDescription().makeNormalFeatureSettings());
     3500            state.setFontDescription(state.style()->fontDescription().makeNormalFeatureSettings());
    35113501            return;
    35123502        }
     
    35273517        }
    35283518        fontDescription.setFeatureSettings(settings.release());
    3529         setFontDescription(fontDescription);
     3519        state.setFontDescription(fontDescription);
    35303520        return;
    35313521    }
     
    35353525        HANDLE_INHERIT_AND_INITIAL(filter, Filter);
    35363526        FilterOperations operations;
    3537         if (createFilterOperations(value, state.style(), state.rootElementStyle(), operations))
     3527        if (createFilterOperations(state, value, state.style(), state.rootElementStyle(), operations))
    35383528            state.style()->setFilter(operations);
    35393529        return;
     
    38563846#if ENABLE(SVG)
    38573847        // Try the SVG properties
    3858         applySVGProperty(id, value);
    3859 #endif
    3860         return;
    3861     }
    3862 }
    3863 
    3864 PassRefPtr<StyleImage> StyleResolver::styleImage(CSSPropertyID property, CSSValue* value)
     3848        applySVGProperty(state, id, value);
     3849#endif
     3850        return;
     3851    }
     3852}
     3853
     3854PassRefPtr<StyleImage> StyleResolver::styleImage(State& state, CSSPropertyID property, CSSValue* value)
    38653855{
    38663856    if (value->isImageValue())
    3867         return cachedOrPendingFromValue(property, static_cast<CSSImageValue*>(value));
     3857        return cachedOrPendingFromValue(state, property, static_cast<CSSImageValue*>(value));
    38683858
    38693859    if (value->isImageGeneratorValue()) {
    38703860        if (value->isGradientValue())
    3871             return generatedOrPendingFromValue(property, static_cast<CSSGradientValue*>(value)->gradientWithStylesResolved(this).get());
    3872         return generatedOrPendingFromValue(property, static_cast<CSSImageGeneratorValue*>(value));
     3861            return generatedOrPendingFromValue(state, property, static_cast<CSSGradientValue*>(value)->gradientWithStylesResolved(state).get());
     3862        return generatedOrPendingFromValue(state, property, static_cast<CSSImageGeneratorValue*>(value));
    38733863    }
    38743864
    38753865#if ENABLE(CSS_IMAGE_SET)
    38763866    if (value->isImageSetValue())
    3877         return setOrPendingFromValue(property, static_cast<CSSImageSetValue*>(value));
     3867        return setOrPendingFromValue(state, property, static_cast<CSSImageSetValue*>(value));
    38783868#endif
    38793869
    38803870    if (value->isCursorImageValue())
    3881         return cursorOrPendingFromValue(property, static_cast<CSSCursorImageValue*>(value));
     3871        return cursorOrPendingFromValue(state, property, static_cast<CSSCursorImageValue*>(value));
    38823872
    38833873    return 0;
    38843874}
    38853875
    3886 PassRefPtr<StyleImage> StyleResolver::cachedOrPendingFromValue(CSSPropertyID property, CSSImageValue* value)
     3876PassRefPtr<StyleImage> StyleResolver::cachedOrPendingFromValue(State& state, CSSPropertyID property, CSSImageValue* value)
    38873877{
    38883878    RefPtr<StyleImage> image = value->cachedOrPendingImage();
    38893879    if (image && image->isPendingImage())
    3890         m_state.pendingImageProperties().set(property, value);
     3880        state.pendingImageProperties().set(property, value);
    38913881    return image.release();
    38923882}
    38933883
    3894 PassRefPtr<StyleImage> StyleResolver::generatedOrPendingFromValue(CSSPropertyID property, CSSImageGeneratorValue* value)
     3884PassRefPtr<StyleImage> StyleResolver::generatedOrPendingFromValue(State& state, CSSPropertyID property, CSSImageGeneratorValue* value)
    38953885{
    38963886    if (value->isPending()) {
    3897         m_state.pendingImageProperties().set(property, value);
     3887        state.pendingImageProperties().set(property, value);
    38983888        return StylePendingImage::create(value);
    38993889    }
     
    39023892
    39033893#if ENABLE(CSS_IMAGE_SET)
    3904 PassRefPtr<StyleImage> StyleResolver::setOrPendingFromValue(CSSPropertyID property, CSSImageSetValue* value)
    3905 {
    3906     RefPtr<StyleImage> image = value->cachedOrPendingImageSet(document());
     3894PassRefPtr<StyleImage> StyleResolver::setOrPendingFromValue(State& state, CSSPropertyID property, CSSImageSetValue* value)
     3895{
     3896    RefPtr<StyleImage> image = value->cachedOrPendingImageSet(state.document());
    39073897    if (image && image->isPendingImage())
    3908         m_state.pendingImageProperties().set(property, value);
     3898        state.pendingImageProperties().set(property, value);
    39093899    return image.release();
    39103900}
    39113901#endif
    39123902
    3913 PassRefPtr<StyleImage> StyleResolver::cursorOrPendingFromValue(CSSPropertyID property, CSSCursorImageValue* value)
    3914 {
    3915     RefPtr<StyleImage> image = value->cachedOrPendingImage(document());
     3903PassRefPtr<StyleImage> StyleResolver::cursorOrPendingFromValue(State& state, CSSPropertyID property, CSSCursorImageValue* value)
     3904{
     3905    RefPtr<StyleImage> image = value->cachedOrPendingImage(state.document());
    39163906    if (image && image->isPendingImage())
    3917         m_state.pendingImageProperties().set(property, value);
     3907        state.pendingImageProperties().set(property, value);
    39183908    return image.release();
    39193909}
    39203910
    3921 void StyleResolver::checkForTextSizeAdjust()
    3922 {
    3923     RenderStyle* style = m_state.style();
     3911void StyleResolver::checkForTextSizeAdjust(State& state)
     3912{
     3913    RenderStyle* style = state.style();
    39243914
    39253915    if (style->textSizeAdjust())
     
    39313921}
    39323922
    3933 void StyleResolver::checkForZoomChange(RenderStyle* style, RenderStyle* parentStyle)
     3923void StyleResolver::checkForZoomChange(State& state, RenderStyle* style, RenderStyle* parentStyle)
    39343924{
    39353925    if (style->effectiveZoom() == parentStyle->effectiveZoom())
     
    39383928    const FontDescription& childFont = style->fontDescription();
    39393929    FontDescription newFontDescription(childFont);
    3940     setFontSize(newFontDescription, childFont.specifiedSize());
     3930    setFontSize(state, newFontDescription, childFont.specifiedSize());
    39413931    style->setFontDescription(newFontDescription);
    39423932}
    39433933
    3944 void StyleResolver::checkForGenericFamilyChange(RenderStyle* style, RenderStyle* parentStyle)
     3934void StyleResolver::checkForGenericFamilyChange(State& state, RenderStyle* style, RenderStyle* parentStyle)
    39453935{
    39463936    const FontDescription& childFont = style->fontDescription();
     
    39763966
    39773967    FontDescription newFontDescription(childFont);
    3978     setFontSize(newFontDescription, size);
     3968    setFontSize(state, newFontDescription, size);
    39793969    style->setFontDescription(newFontDescription);
    39803970}
    39813971
    3982 void StyleResolver::initializeFontStyle(Settings* settings)
     3972void StyleResolver::initializeFontStyle(State& state, Settings* settings)
    39833973{
    39843974    FontDescription fontDescription;
     
    39923982    }
    39933983    fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
    3994     setFontSize(fontDescription, fontSizeForKeyword(document(), CSSValueMedium, false));
    3995     m_state.style()->setLineHeight(RenderStyle::initialLineHeight());
    3996     m_state.setLineHeightValue(0);
    3997     setFontDescription(fontDescription);
    3998 }
    3999 
    4000 void StyleResolver::setFontSize(FontDescription& fontDescription, float size)
     3984    setFontSize(state, fontDescription, fontSizeForKeyword(document(), CSSValueMedium, false));
     3985    state.style()->setLineHeight(RenderStyle::initialLineHeight());
     3986    state.setLineHeightValue(0);
     3987    state.setFontDescription(fontDescription);
     3988}
     3989
     3990void StyleResolver::setFontSize(State& state, FontDescription& fontDescription, float size)
    40013991{
    40023992    fontDescription.setSpecifiedSize(size);
    4003     fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(document(), m_state.style(), fontDescription.isAbsoluteSize(), size, useSVGZoomRules()));
     3993    fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(state.document(), state.style(), fontDescription.isAbsoluteSize(), size, state.useSVGZoomRules()));
    40043994}
    40053995
     
    41994189}
    42004190
    4201 Color StyleResolver::colorFromPrimitiveValue(CSSPrimitiveValue* value, bool forVisitedLink) const
     4191Color StyleResolver::colorFromPrimitiveValue(const StyleResolver::State& state, CSSPrimitiveValue* value, bool forVisitedLink)
    42024192{
    42034193    if (value->isRGBColor())
    42044194        return Color(value->getRGBA32Value());
    42054195
    4206     const State& state = m_state;
    42074196    int ident = value->getIdent();
    42084197    switch (ident) {
     
    45504539
    45514540#if ENABLE(CSS_FILTERS) && ENABLE(SVG)
    4552 void StyleResolver::loadPendingSVGDocuments()
    4553 {
    4554     State& state = m_state;
     4541void StyleResolver::loadPendingSVGDocuments(State& state)
     4542{
    45554543    if (!state.style()->hasFilter() || state.pendingSVGDocuments().isEmpty())
    45564544        return;
     
    45794567
    45804568#if ENABLE(CSS_SHADERS)
    4581 StyleShader* StyleResolver::styleShader(CSSValue* value)
     4569StyleShader* StyleResolver::styleShader(State& state, CSSValue* value)
    45824570{
    45834571    if (value->isWebKitCSSShaderValue())
    4584         return cachedOrPendingStyleShaderFromValue(static_cast<WebKitCSSShaderValue*>(value));
     4572        return cachedOrPendingStyleShaderFromValue(state, static_cast<WebKitCSSShaderValue*>(value));
    45854573    return 0;
    45864574}
    45874575
    4588 StyleShader* StyleResolver::cachedOrPendingStyleShaderFromValue(WebKitCSSShaderValue* value)
     4576StyleShader* StyleResolver::cachedOrPendingStyleShaderFromValue(State& state, WebKitCSSShaderValue* value)
    45894577{
    45904578    StyleShader* shader = value->cachedOrPendingShader();
    45914579    if (shader && shader->isPendingShader())
    4592         m_state.setHasPendingShaders(true);
     4580        state.setHasPendingShaders(true);
    45934581    return shader;
    45944582}
    45954583
    4596 void StyleResolver::loadPendingShaders()
    4597 {
    4598     if (!m_state.style()->hasFilter() || !m_state.hasPendingShaders())
    4599         return;
    4600 
    4601     CachedResourceLoader* cachedResourceLoader = m_state.document()->cachedResourceLoader();
    4602 
    4603     Vector<RefPtr<FilterOperation> >& filterOperations = m_state.style()->mutableFilter().operations();
     4584void StyleResolver::loadPendingShaders(State& state)
     4585{
     4586    if (!state.style()->hasFilter() || !state.hasPendingShaders())
     4587        return;
     4588
     4589    CachedResourceLoader* cachedResourceLoader = state.document()->cachedResourceLoader();
     4590
     4591    Vector<RefPtr<FilterOperation> >& filterOperations = state.style()->mutableFilter().operations();
    46044592    for (unsigned i = 0; i < filterOperations.size(); ++i) {
    46054593        RefPtr<FilterOperation> filterOperation = filterOperations.at(i);
     
    46184606        }
    46194607    }
    4620     m_state.setHasPendingShaders(false);
     4608    state.setHasPendingShaders(false);
    46214609}
    46224610
     
    46564644}
    46574645
    4658 PassRefPtr<CustomFilterParameter> StyleResolver::parseCustomFilterTransformParameter(const String& name, CSSValueList* values)
     4646PassRefPtr<CustomFilterParameter> StyleResolver::parseCustomFilterTransformParameter(State& state, const String& name, CSSValueList* values)
    46594647{
    46604648    RefPtr<CustomFilterTransformParameter> transformParameter = CustomFilterTransformParameter::create(name);
    46614649    TransformOperations operations;
    4662     createTransformOperations(values, m_state.style(), m_state.rootElementStyle(), operations);
     4650    createTransformOperations(values, state.style(), state.rootElementStyle(), operations);
    46634651    transformParameter->setOperations(operations);
    46644652    return transformParameter.release();
    46654653}
    46664654
    4667 PassRefPtr<CustomFilterParameter> StyleResolver::parseCustomFilterParameter(const String& name, CSSValue* parameterValue)
     4655PassRefPtr<CustomFilterParameter> StyleResolver::parseCustomFilterParameter(State& state, const String& name, CSSValue* parameterValue)
    46684656{
    46694657    // FIXME: Implement other parameters types parsing.
     
    46884676    // return 0 if that assumption is incorrect.
    46894677    if (values->itemWithoutBoundsCheck(0)->isWebKitCSSTransformValue())
    4690         return parseCustomFilterTransformParameter(name, values);
     4678        return parseCustomFilterTransformParameter(state, name, values);
    46914679
    46924680    // We can have only arrays of booleans or numbers, so use the first value to choose between those two.
     
    47054693}
    47064694
    4707 bool StyleResolver::parseCustomFilterParameterList(CSSValue* parametersValue, CustomFilterParameterList& parameterList)
     4695bool StyleResolver::parseCustomFilterParameterList(State& state, CSSValue* parametersValue, CustomFilterParameterList& parameterList)
    47084696{
    47094697    HashSet<String> knownParameterNames;
     
    47304718            return false;
    47314719       
    4732         RefPtr<CustomFilterParameter> parameter = parseCustomFilterParameter(name, iterator.value());
     4720        RefPtr<CustomFilterParameter> parameter = parseCustomFilterParameter(state, name, iterator.value());
    47334721        if (!parameter)
    47344722            return false;
     
    47494737}
    47504738
    4751 PassRefPtr<CustomFilterOperation> StyleResolver::createCustomFilterOperationWithInlineSyntax(WebKitCSSFilterValue* filterValue)
     4739PassRefPtr<CustomFilterOperation> StyleResolver::createCustomFilterOperationWithInlineSyntax(State& state, WebKitCSSFilterValue* filterValue)
    47524740{
    47534741    CSSValue* shadersValue = filterValue->itemWithoutBoundsCheck(0);
     
    47584746    ASSERT(shadersListLength);
    47594747
    4760     RefPtr<StyleShader> vertexShader = styleShader(shadersList->itemWithoutBoundsCheck(0));
     4748    RefPtr<StyleShader> vertexShader = styleShader(state, shadersList->itemWithoutBoundsCheck(0));
    47614749    RefPtr<StyleShader> fragmentShader;
    47624750    CustomFilterProgramType programType = PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE;
     
    47714759
    47724760            ASSERT(mixFunction->length());
    4773             fragmentShader = styleShader(iterator.value());
     4761            fragmentShader = styleShader(state, iterator.value());
    47744762            iterator.advance();
    47754763
     
    47874775        } else {
    47884776            programType = PROGRAM_TYPE_NO_ELEMENT_TEXTURE;
    4789             fragmentShader = styleShader(fragmentShaderOrMixFunction);
     4777            fragmentShader = styleShader(state, fragmentShaderOrMixFunction);
    47904778        }
    47914779    }
     
    48434831   
    48444832    CustomFilterParameterList parameterList;
    4845     if (parametersValue && !parseCustomFilterParameterList(parametersValue, parameterList))
     4833    if (parametersValue && !parseCustomFilterParameterList(state, parametersValue, parameterList))
    48464834        return 0;
    48474835   
     
    48504838}
    48514839
    4852 PassRefPtr<CustomFilterOperation> StyleResolver::createCustomFilterOperation(WebKitCSSFilterValue* filterValue)
     4840PassRefPtr<CustomFilterOperation> StyleResolver::createCustomFilterOperation(State& state, WebKitCSSFilterValue* filterValue)
    48534841{
    48544842    ASSERT(filterValue->length());
    48554843    bool isAtRuleReferenceSyntax = filterValue->itemWithoutBoundsCheck(0)->isPrimitiveValue();
    4856     return isAtRuleReferenceSyntax ? createCustomFilterOperationWithAtRuleReferenceSyntax(filterValue) : createCustomFilterOperationWithInlineSyntax(filterValue);
    4857 }
    4858 
    4859 #endif
    4860 
    4861 bool StyleResolver::createFilterOperations(CSSValue* inValue, RenderStyle* style, RenderStyle* rootStyle, FilterOperations& outOperations)
     4844    return isAtRuleReferenceSyntax ? createCustomFilterOperationWithAtRuleReferenceSyntax(filterValue) : createCustomFilterOperationWithInlineSyntax(state, filterValue);
     4845}
     4846
     4847#endif
     4848
     4849bool StyleResolver::createFilterOperations(State& state, CSSValue* inValue, RenderStyle* style, RenderStyle* rootStyle, FilterOperations& outOperations)
    48624850{
    48634851    ASSERT(outOperations.isEmpty());
     
    48924880        }
    48934881        if (operationType == FilterOperation::CUSTOM) {
    4894             RefPtr<CustomFilterOperation> operation = createCustomFilterOperation(filterValue);
     4882            RefPtr<CustomFilterOperation> operation = createCustomFilterOperation(state, filterValue);
    48954883            if (!operation)
    48964884                return false;
     
    49104898
    49114899            WebKitCSSSVGDocumentValue* svgDocumentValue = static_cast<WebKitCSSSVGDocumentValue*>(argument);
    4912             KURL url = m_state.document()->completeURL(svgDocumentValue->url());
     4900            KURL url = state.document()->completeURL(svgDocumentValue->url());
    49134901
    49144902            RefPtr<ReferenceFilterOperation> operation = ReferenceFilterOperation::create(svgDocumentValue->url(), url.fragmentIdentifier(), operationType);
    4915             if (SVGURIReference::isExternalURIReference(svgDocumentValue->url(), m_state.document())) {
     4903            if (SVGURIReference::isExternalURIReference(svgDocumentValue->url(), state.document())) {
    49164904                if (!svgDocumentValue->loadRequested())
    4917                     m_state.pendingSVGDocuments().set(operation.get(), svgDocumentValue);
     4905                    state.pendingSVGDocuments().set(operation.get(), svgDocumentValue);
    49184906                else if (svgDocumentValue->cachedSVGDocument())
    49194907                    operation->setCachedSVGDocumentReference(adoptPtr(new CachedSVGDocumentReference(svgDocumentValue->cachedSVGDocument())));
     
    49994987            Color color;
    50004988            if (item->color)
    5001                 color = colorFromPrimitiveValue(item->color.get());
     4989                color = colorFromPrimitiveValue(state, item->color.get());
    50024990
    50034991            operations.operations().append(DropShadowFilterOperation::create(location, blur, color.isValid() ? color : Color::transparent, operationType));
     
    50175005#endif
    50185006
    5019 PassRefPtr<StyleImage> StyleResolver::loadPendingImage(StylePendingImage* pendingImage)
    5020 {
    5021     CachedResourceLoader* cachedResourceLoader = m_state.document()->cachedResourceLoader();
     5007PassRefPtr<StyleImage> StyleResolver::loadPendingImage(State& state, StylePendingImage* pendingImage)
     5008{
     5009    CachedResourceLoader* cachedResourceLoader = state.document()->cachedResourceLoader();
    50225010
    50235011    if (pendingImage->cssImageValue()) {
     
    50475035}
    50485036
    5049 void StyleResolver::loadPendingImages()
    5050 {
    5051     if (m_state.pendingImageProperties().isEmpty())
    5052         return;
    5053 
    5054     PendingImagePropertyMap::const_iterator::Keys end = m_state.pendingImageProperties().end().keys();
    5055     for (PendingImagePropertyMap::const_iterator::Keys it = m_state.pendingImageProperties().begin().keys(); it != end; ++it) {
     5037void StyleResolver::loadPendingImages(State& state)
     5038{
     5039    if (state.pendingImageProperties().isEmpty())
     5040        return;
     5041
     5042    PendingImagePropertyMap::const_iterator::Keys end = state.pendingImageProperties().end().keys();
     5043    for (PendingImagePropertyMap::const_iterator::Keys it = state.pendingImageProperties().begin().keys(); it != end; ++it) {
    50565044        CSSPropertyID currentProperty = *it;
    50575045
    50585046        switch (currentProperty) {
    50595047        case CSSPropertyBackgroundImage: {
    5060             for (FillLayer* backgroundLayer = m_state.style()->accessBackgroundLayers(); backgroundLayer; backgroundLayer = backgroundLayer->next()) {
     5048            for (FillLayer* backgroundLayer = state.style()->accessBackgroundLayers(); backgroundLayer; backgroundLayer = backgroundLayer->next()) {
    50615049                if (backgroundLayer->image() && backgroundLayer->image()->isPendingImage())
    5062                     backgroundLayer->setImage(loadPendingImage(static_cast<StylePendingImage*>(backgroundLayer->image())));
     5050                    backgroundLayer->setImage(loadPendingImage(state, static_cast<StylePendingImage*>(backgroundLayer->image())));
    50635051            }
    50645052            break;
    50655053        }
    50665054        case CSSPropertyContent: {
    5067             for (ContentData* contentData = const_cast<ContentData*>(m_state.style()->contentData()); contentData; contentData = contentData->next()) {
     5055            for (ContentData* contentData = const_cast<ContentData*>(state.style()->contentData()); contentData; contentData = contentData->next()) {
    50685056                if (contentData->isImage()) {
    50695057                    StyleImage* image = static_cast<ImageContentData*>(contentData)->image();
    50705058                    if (image->isPendingImage()) {
    5071                         RefPtr<StyleImage> loadedImage = loadPendingImage(static_cast<StylePendingImage*>(image));
     5059                        RefPtr<StyleImage> loadedImage = loadPendingImage(state, static_cast<StylePendingImage*>(image));
    50725060                        if (loadedImage)
    50735061                            static_cast<ImageContentData*>(contentData)->setImage(loadedImage.release());
     
    50785066        }
    50795067        case CSSPropertyCursor: {
    5080             if (CursorList* cursorList = m_state.style()->cursors()) {
     5068            if (CursorList* cursorList = state.style()->cursors()) {
    50815069                for (size_t i = 0; i < cursorList->size(); ++i) {
    50825070                    CursorData& currentCursor = cursorList->at(i);
    50835071                    if (StyleImage* image = currentCursor.image()) {
    50845072                        if (image->isPendingImage())
    5085                             currentCursor.setImage(loadPendingImage(static_cast<StylePendingImage*>(image)));
     5073                            currentCursor.setImage(loadPendingImage(state, static_cast<StylePendingImage*>(image)));
    50865074                    }
    50875075                }
     
    50905078        }
    50915079        case CSSPropertyListStyleImage: {
    5092             if (m_state.style()->listStyleImage() && m_state.style()->listStyleImage()->isPendingImage())
    5093                 m_state.style()->setListStyleImage(loadPendingImage(static_cast<StylePendingImage*>(m_state.style()->listStyleImage())));
     5080            if (state.style()->listStyleImage() && state.style()->listStyleImage()->isPendingImage())
     5081                state.style()->setListStyleImage(loadPendingImage(state, static_cast<StylePendingImage*>(state.style()->listStyleImage())));
    50945082            break;
    50955083        }
    50965084        case CSSPropertyBorderImageSource: {
    5097             if (m_state.style()->borderImageSource() && m_state.style()->borderImageSource()->isPendingImage())
    5098                 m_state.style()->setBorderImageSource(loadPendingImage(static_cast<StylePendingImage*>(m_state.style()->borderImageSource())));
     5085            if (state.style()->borderImageSource() && state.style()->borderImageSource()->isPendingImage())
     5086                state.style()->setBorderImageSource(loadPendingImage(state, static_cast<StylePendingImage*>(state.style()->borderImageSource())));
    50995087            break;
    51005088        }
    51015089        case CSSPropertyWebkitBoxReflect: {
    5102             if (StyleReflection* reflection = m_state.style()->boxReflect()) {
     5090            if (StyleReflection* reflection = state.style()->boxReflect()) {
    51035091                const NinePieceImage& maskImage = reflection->mask();
    51045092                if (maskImage.image() && maskImage.image()->isPendingImage()) {
    5105                     RefPtr<StyleImage> loadedImage = loadPendingImage(static_cast<StylePendingImage*>(maskImage.image()));
     5093                    RefPtr<StyleImage> loadedImage = loadPendingImage(state, static_cast<StylePendingImage*>(maskImage.image()));
    51065094                    reflection->setMask(NinePieceImage(loadedImage.release(), maskImage.imageSlices(), maskImage.fill(), maskImage.borderSlices(), maskImage.outset(), maskImage.horizontalRule(), maskImage.verticalRule()));
    51075095                }
     
    51105098        }
    51115099        case CSSPropertyWebkitMaskBoxImageSource: {
    5112             if (m_state.style()->maskBoxImageSource() && m_state.style()->maskBoxImageSource()->isPendingImage())
    5113                 m_state.style()->setMaskBoxImageSource(loadPendingImage(static_cast<StylePendingImage*>(m_state.style()->maskBoxImageSource())));
     5100            if (state.style()->maskBoxImageSource() && state.style()->maskBoxImageSource()->isPendingImage())
     5101                state.style()->setMaskBoxImageSource(loadPendingImage(state, static_cast<StylePendingImage*>(state.style()->maskBoxImageSource())));
    51145102            break;
    51155103        }
    51165104        case CSSPropertyWebkitMaskImage: {
    5117             for (FillLayer* maskLayer = m_state.style()->accessMaskLayers(); maskLayer; maskLayer = maskLayer->next()) {
     5105            for (FillLayer* maskLayer = state.style()->accessMaskLayers(); maskLayer; maskLayer = maskLayer->next()) {
    51185106                if (maskLayer->image() && maskLayer->image()->isPendingImage())
    5119                     maskLayer->setImage(loadPendingImage(static_cast<StylePendingImage*>(maskLayer->image())));
     5107                    maskLayer->setImage(loadPendingImage(state, static_cast<StylePendingImage*>(maskLayer->image())));
    51205108            }
    51215109            break;
     
    51265114    }
    51275115
    5128     m_state.pendingImageProperties().clear();
    5129 }
    5130 
    5131 void StyleResolver::loadPendingResources()
     5116    state.pendingImageProperties().clear();
     5117}
     5118
     5119void StyleResolver::loadPendingResources(State& state)
    51325120{
    51335121    // Start loading images referenced by this style.
    5134     loadPendingImages();
     5122    loadPendingImages(state);
    51355123
    51365124#if ENABLE(CSS_SHADERS)
    51375125    // Start loading the shaders referenced by this style.
    5138     loadPendingShaders();
     5126    loadPendingShaders(state);
    51395127#endif
    51405128   
    51415129#if ENABLE(CSS_FILTERS) && ENABLE(SVG)
    51425130    // Start loading the SVG Documents referenced by this style.
    5143     loadPendingSVGDocuments();
     5131    loadPendingSVGDocuments(state);
    51445132#endif
    51455133}
     
    51845172    info.addMember(m_scopeResolver, "scopeResolver");
    51855173
    5186     info.addMember(m_state, "state");
    5187 
    51885174    // FIXME: move this to a place where it would be called only once?
    51895175    info.addMember(CSSDefaultStyleSheets::defaultStyle, "defaultStyle");
  • trunk/Source/WebCore/css/StyleResolver.h

    r142855 r143556  
    2525#include "CSSRule.h"
    2626#include "CSSRuleList.h"
    27 #include "CSSToStyleMap.h"
    2827#include "CSSValueList.h"
    2928#include "DocumentRuleSets.h"
     
    179178    static PassRefPtr<RenderStyle> styleForDocument(Document*, CSSFontSelector* = 0);
    180179
    181     RenderStyle* style() const { return m_state.style(); }
    182     RenderStyle* parentStyle() const { return m_state.parentStyle(); }
    183     RenderStyle* rootElementStyle() const { return m_state.rootElementStyle(); }
    184     Element* element() { return m_state.element(); }
    185180    Document* document() { return m_document; }
    186181    StyleScopeResolver* scopeResolver() const { return m_scopeResolver.get(); }
    187     bool hasParentNode() const { return m_state.parentNode(); }
    188182
    189183    // FIXME: It could be better to call m_ruleSets.appendAuthorStyleSheets() directly after we factor StyleRsolver further.
     
    211205    }
    212206#endif
     207    class State;
    213208
    214209private:
    215     void initElement(Element*);
    216     RenderStyle* locateSharedStyle();
    217     bool styleSharingCandidateMatchesRuleSet(RuleSet*);
    218     bool styleSharingCandidateMatchesHostRules();
     210    void initElement(State&, Element*);
     211    RenderStyle* locateSharedStyle(State&);
     212    bool styleSharingCandidateMatchesRuleSet(Element*, RuleSet*);
     213    bool styleSharingCandidateMatchesHostRules(State&);
    219214    Node* locateCousinList(Element* parent, unsigned& visitedNodeCount) const;
    220     StyledElement* findSiblingForStyleSharing(Node*, unsigned& count) const;
    221     bool canShareStyleWithElement(StyledElement*) const;
    222 
    223     PassRefPtr<RenderStyle> styleForKeyframe(const RenderStyle*, const StyleKeyframe*, KeyframeValue&);
     215    StyledElement* findSiblingForStyleSharing(const State&, Node*, unsigned& count) const;
     216    bool canShareStyleWithElement(const State&, StyledElement*) const;
     217
     218    PassRefPtr<RenderStyle> styleForKeyframe(State&, const RenderStyle*, const StyleKeyframe*, KeyframeValue&);
    224219
    225220public:
     
    244239
    245240public:
    246     void applyPropertyToStyle(CSSPropertyID, CSSValue*, RenderStyle*);
    247 
    248     void applyPropertyToCurrentStyle(CSSPropertyID, CSSValue*);
    249 
    250     void updateFont();
    251     void initializeFontStyle(Settings*);
     241    void applyFontPropertyToStyle(RenderStyle*, const StylePropertySet*);
     242
     243    void updateFont(State&);
     244    void initializeFontStyle(State&, Settings*);
    252245
    253246    static float getComputedSizeFromSpecifiedSize(Document*, float zoomFactor, bool isAbsoluteSize, float specifiedSize, ESmartMinimumForFontSize = UseSmartMinimumForFontFize);
    254247
    255     void setFontSize(FontDescription&, float size);
     248    static void setFontSize(State&, FontDescription&, float size);
    256249
    257250private:
     
    259252
    260253public:
    261     bool useSVGZoomRules();
    262 
    263254    static bool colorFromPrimitiveValueIsDerivedFromElement(CSSPrimitiveValue*);
    264     Color colorFromPrimitiveValue(CSSPrimitiveValue*, bool forVisitedLink = false) const;
     255    static Color colorFromPrimitiveValue(const State&, CSSPrimitiveValue*, bool forVisitedLink = false);
    265256
    266257    bool hasSelectorForId(const AtomicString&) const;
     
    290281
    291282#if ENABLE(CSS_FILTERS)
    292     bool createFilterOperations(CSSValue* inValue, RenderStyle* inStyle, RenderStyle* rootStyle, FilterOperations& outOperations);
     283    bool createFilterOperations(State&, CSSValue* inValue, RenderStyle* inStyle, RenderStyle* rootStyle, FilterOperations& outOperations);
    293284#if ENABLE(CSS_SHADERS)
    294     StyleShader* styleShader(CSSValue*);
    295     StyleShader* cachedOrPendingStyleShaderFromValue(WebKitCSSShaderValue*);
    296     bool parseCustomFilterParameterList(CSSValue*, CustomFilterParameterList&);
    297     PassRefPtr<CustomFilterParameter> parseCustomFilterParameter(const String& name, CSSValue*);
     285    StyleShader* styleShader(State&, CSSValue*);
     286    StyleShader* cachedOrPendingStyleShaderFromValue(State&, WebKitCSSShaderValue*);
     287    bool parseCustomFilterParameterList(State&, CSSValue*, CustomFilterParameterList&);
     288    PassRefPtr<CustomFilterParameter> parseCustomFilterParameter(State&, const String& name, CSSValue*);
    298289    PassRefPtr<CustomFilterParameter> parseCustomFilterArrayParameter(const String& name, CSSValueList*);
    299290    PassRefPtr<CustomFilterParameter> parseCustomFilterNumberParameter(const String& name, CSSValueList*);
    300     PassRefPtr<CustomFilterParameter> parseCustomFilterTransformParameter(const String& name, CSSValueList*);
     291    PassRefPtr<CustomFilterParameter> parseCustomFilterTransformParameter(State&, const String& name, CSSValueList*);
    301292    PassRefPtr<CustomFilterOperation> createCustomFilterOperationWithAtRuleReferenceSyntax(WebKitCSSFilterValue*);
    302     PassRefPtr<CustomFilterOperation> createCustomFilterOperationWithInlineSyntax(WebKitCSSFilterValue*);
    303     PassRefPtr<CustomFilterOperation> createCustomFilterOperation(WebKitCSSFilterValue*);
    304     void loadPendingShaders();
     293    PassRefPtr<CustomFilterOperation> createCustomFilterOperationWithInlineSyntax(State&, WebKitCSSFilterValue*);
     294    PassRefPtr<CustomFilterOperation> createCustomFilterOperation(State&, WebKitCSSFilterValue*);
     295    void loadPendingShaders(State&);
    305296#endif
    306297#if ENABLE(SVG)
    307     void loadPendingSVGDocuments();
     298    void loadPendingSVGDocuments(State&);
    308299#endif
    309300#endif // ENABLE(CSS_FILTERS)
    310301
    311     void loadPendingResources();
     302    void loadPendingResources(State&);
    312303
    313304private:
    314305    // This function fixes up the default font size if it detects that the current generic font family has changed. -dwh
    315     void checkForGenericFamilyChange(RenderStyle*, RenderStyle* parentStyle);
    316     void checkForZoomChange(RenderStyle*, RenderStyle* parentStyle);
    317     void checkForTextSizeAdjust();
    318 
    319     void adjustRenderStyle(RenderStyle* styleToAdjust, RenderStyle* parentStyle, Element*);
     306    void checkForGenericFamilyChange(State&, RenderStyle*, RenderStyle* parentStyle);
     307    void checkForZoomChange(State&, RenderStyle*, RenderStyle* parentStyle);
     308    void checkForTextSizeAdjust(State&);
     309
     310    void adjustRenderStyle(State&, RenderStyle* styleToAdjust, RenderStyle* parentStyle, Element*);
    320311
    321312    struct RuleRange {
     
    364355    void addElementStyleProperties(MatchResult&, const StylePropertySet*, bool isCacheable = true);
    365356
    366     void matchAllRules(MatchResult&, bool includeSMILProperties);
    367     void matchUARules(MatchResult&);
    368     void matchUARules(MatchResult&, RuleSet*);
    369     void matchAuthorRules(MatchResult&, bool includeEmptyRules);
    370     void matchUserRules(MatchResult&, bool includeEmptyRules);
    371     void matchScopedAuthorRules(MatchResult&, bool includeEmptyRules);
    372     void matchHostRules(MatchResult&, bool includeEmptyRules);
    373 
    374     void collectMatchingRules(const MatchRequest&, RuleRange&);
    375     void collectMatchingRulesForRegion(const MatchRequest&, RuleRange&);
    376     void collectMatchingRulesForList(const Vector<RuleData>*, const MatchRequest&, RuleRange&);
     357    void matchAllRules(State&, MatchResult&, bool includeSMILProperties);
     358    void matchUARules(State&, MatchResult&);
     359    void matchUARules(State&, MatchResult&, RuleSet*);
     360    void matchAuthorRules(State&, MatchResult&, bool includeEmptyRules);
     361    void matchUserRules(State&, MatchResult&, bool includeEmptyRules);
     362    void matchScopedAuthorRules(State&, MatchResult&, bool includeEmptyRules);
     363    void matchHostRules(State&, MatchResult&, bool includeEmptyRules);
     364
     365    void collectMatchingRules(State&, const MatchRequest&, RuleRange&);
     366    void collectMatchingRulesForRegion(State&, const MatchRequest&, RuleRange&);
     367    void collectMatchingRulesForList(State&, const Vector<RuleData>*, const MatchRequest&, RuleRange&);
    377368
    378369    bool fastRejectSelector(const RuleData&) const;
    379     void sortMatchedRules();
    380     void sortAndTransferMatchedRules(MatchResult&);
    381 
    382     bool ruleMatches(const RuleData&, const ContainerNode* scope, PseudoId&, SelectorChecker::BehaviorAtBoundary = SelectorChecker::DoesNotCrossBoundary);
     370    void sortMatchedRules(State&);
     371    void sortAndTransferMatchedRules(State&, MatchResult&);
     372
     373    bool ruleMatches(State&, const RuleData&, const ContainerNode* scope, PseudoId&, SelectorChecker::BehaviorAtBoundary = SelectorChecker::DoesNotCrossBoundary);
    383374    bool checkRegionSelector(const CSSSelector* regionSelector, Element* regionElement);
    384     void applyMatchedProperties(const MatchResult&, const Element*);
     375    void applyMatchedProperties(State&, const MatchResult&, const Element*);
    385376    enum StyleApplicationPass {
    386377#if ENABLE(CSS_VARIABLES)
     
    391382    };
    392383    template <StyleApplicationPass pass>
    393     void applyMatchedProperties(const MatchResult&, bool important, int startIndex, int endIndex, bool inheritedOnly);
     384    void applyMatchedProperties(State&, const MatchResult&, bool important, int startIndex, int endIndex, bool inheritedOnly);
    394385    template <StyleApplicationPass pass>
    395     void applyProperties(const StylePropertySet* properties, StyleRule*, bool isImportant, bool inheritedOnly, PropertyWhitelistType = PropertyWhitelistNone);
     386    void applyProperties(State&, const StylePropertySet* properties, StyleRule*, bool isImportant, bool inheritedOnly, PropertyWhitelistType = PropertyWhitelistNone);
    396387#if ENABLE(CSS_VARIABLES)
    397     void resolveVariables(CSSPropertyID, CSSValue*, Vector<std::pair<CSSPropertyID, String> >& knownExpressions);
     388    void resolveVariables(State&, CSSPropertyID, CSSValue*, Vector<std::pair<CSSPropertyID, String> >& knownExpressions);
    398389#endif
    399390    static bool isValidRegionStyleProperty(CSSPropertyID);
     
    405396    Settings* documentSettings() { return m_document->settings(); }
    406397
    407     bool isLeftPage(int pageIndex) const;
    408     bool isRightPage(int pageIndex) const { return !isLeftPage(pageIndex); }
     398    bool isLeftPage(State&, int pageIndex) const;
     399    bool isRightPage(State& state, int pageIndex) const { return !isLeftPage(state, pageIndex); }
    409400    bool isFirstPage(int pageIndex) const;
    410401    String pageName(int pageIndex) const;
     
    416407
    417408public:
     409
    418410    typedef HashMap<CSSPropertyID, RefPtr<CSSValue> > PendingImagePropertyMap;
    419411#if ENABLE(CSS_FILTERS) && ENABLE(SVG)
    420412    typedef HashMap<FilterOperation*, RefPtr<WebKitCSSSVGDocumentValue> > PendingSVGDocumentMap;
    421413#endif
    422 
    423414    class State {
    424415        WTF_MAKE_NONCOPYABLE(State);
    425416    public:
    426         State()
    427         : m_element(0)
     417        State(Document* document)
     418        : m_document(document)
     419        , m_element(0)
    428420        , m_styledElement(0)
    429421        , m_parentNode(0)
     
    452444        void clear();
    453445
    454         Document* document() const { return m_element->document(); }
     446        Document* document() const { return m_document; }
    455447        Element* element() const { return m_element; }
    456448        StyledElement* styledElement() const { return m_styledElement; }
     
    513505        Vector<const RuleData*, 32>& matchedRules() { return m_matchedRules; }
    514506        void addMatchedRule(const RuleData* rule) { m_matchedRules.append(rule); }
     507        bool useSVGZoomRules() const { return m_element && m_element->isSVGElement(); }
    515508       
    516509    private:
    517         // FIXME(bug 108563): to make it easier to review, these member
    518         // variables are public. However we should add methods to access
    519         // these variables.
     510        Document* m_document;
    520511        Element* m_element;
    521512        RefPtr<RenderStyle> m_style;
     
    563554    static RenderStyle* styleNotYetAvailable() { return s_styleNotYetAvailable; }
    564555
    565     PassRefPtr<StyleImage> styleImage(CSSPropertyID, CSSValue*);
    566     PassRefPtr<StyleImage> cachedOrPendingFromValue(CSSPropertyID, CSSImageValue*);
    567     PassRefPtr<StyleImage> generatedOrPendingFromValue(CSSPropertyID, CSSImageGeneratorValue*);
     556    static PassRefPtr<StyleImage> styleImage(State&, CSSPropertyID, CSSValue*);
     557    static PassRefPtr<StyleImage> cachedOrPendingFromValue(State&, CSSPropertyID, CSSImageValue*);
     558    static PassRefPtr<StyleImage> generatedOrPendingFromValue(State&, CSSPropertyID, CSSImageGeneratorValue*);
    568559#if ENABLE(CSS_IMAGE_SET)
    569     PassRefPtr<StyleImage> setOrPendingFromValue(CSSPropertyID, CSSImageSetValue*);
    570 #endif
    571     PassRefPtr<StyleImage> cursorOrPendingFromValue(CSSPropertyID, CSSCursorImageValue*);
    572 
    573     bool applyPropertyToRegularStyle() const { return m_state.applyPropertyToRegularStyle(); }
    574     bool applyPropertyToVisitedLinkStyle() const { return m_state.applyPropertyToVisitedLinkStyle(); }
     560    static PassRefPtr<StyleImage> setOrPendingFromValue(State&, CSSPropertyID, CSSImageSetValue*);
     561#endif
     562    static PassRefPtr<StyleImage> cursorOrPendingFromValue(State&, CSSPropertyID, CSSCursorImageValue*);
    575563
    576564    static Length convertToIntLength(CSSPrimitiveValue*, RenderStyle*, RenderStyle* rootStyle, double multiplier = 1);
    577565    static Length convertToFloatLength(CSSPrimitiveValue*, RenderStyle*, RenderStyle* rootStyle, double multiplier = 1);
    578566
    579     CSSToStyleMap* styleMap() { return &m_styleMap; }
    580567    InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWrappers; }
    581     const FontDescription& fontDescription() { return m_state.fontDescription(); }
    582     const FontDescription& parentFontDescription() { return m_state.parentFontDescription(); }
    583     void setFontDescription(const FontDescription& fontDescription) { m_state.setFontDescription(fontDescription); }
    584     void setZoom(float f) { m_state.setZoom(f); }
    585     void setEffectiveZoom(float f) { m_state.setEffectiveZoom(f); }
    586     void setTextSizeAdjust(bool b) { m_state.setTextSizeAdjust(b); }
    587     void setWritingMode(WritingMode writingMode) { m_state.setWritingMode(writingMode); }
    588     void setTextOrientation(TextOrientation textOrientation) { m_state.setTextOrientation(textOrientation); }
    589568   
    590569    void reportMemoryUsage(MemoryObjectInfo*) const;
     
    596575
    597576private:
    598     bool canShareStyleWithControl(StyledElement*) const;
    599 
    600     void applyProperty(CSSPropertyID, CSSValue*);
     577    bool canShareStyleWithControl(const State&, StyledElement*) const;
     578
     579    void applyPropertyWithNullCheck(State&, CSSPropertyID, CSSValue*);
     580    void applyProperty(State&, CSSPropertyID, CSSValue*);
    601581
    602582#if ENABLE(SVG)
    603     void applySVGProperty(CSSPropertyID, CSSValue*);
    604 #endif
    605 
    606     PassRefPtr<StyleImage> loadPendingImage(StylePendingImage*);
    607     void loadPendingImages();
     583    void applySVGProperty(const State&, CSSPropertyID, CSSValue*);
     584#endif
     585
     586    PassRefPtr<StyleImage> loadPendingImage(State&, StylePendingImage*);
     587    void loadPendingImages(State&);
    608588
    609589    static unsigned computeMatchedPropertiesHash(const MatchedProperties*, unsigned size);
     
    623603
    624604    bool classNamesAffectedByRules(const SpaceSplitString&) const;
    625     bool sharingCandidateHasIdenticalStyleAffectingAttributes(StyledElement*) const;
     605    bool sharingCandidateHasIdenticalStyleAffectingAttributes(const State&, StyledElement*) const;
    626606
    627607    unsigned m_matchedPropertiesCacheAdditionsSinceLastSweep;
     
    650630
    651631    OwnPtr<StyleScopeResolver> m_scopeResolver;
    652     CSSToStyleMap m_styleMap;
    653632    InspectorCSSOMWrappers m_inspectorCSSOMWrappers;
    654 
    655     State m_state;
    656633
    657634    friend class StyleBuilder;
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r143232 r143556  
    20652065    // Now map the font property longhands into the style.
    20662066    StyleResolver* styleResolver = canvas()->styleResolver();
    2067     styleResolver->applyPropertyToStyle(CSSPropertyFontFamily, parsedStyle->getPropertyCSSValue(CSSPropertyFontFamily).get(), newStyle.get());
    2068     styleResolver->applyPropertyToCurrentStyle(CSSPropertyFontStyle, parsedStyle->getPropertyCSSValue(CSSPropertyFontStyle).get());
    2069     styleResolver->applyPropertyToCurrentStyle(CSSPropertyFontVariant, parsedStyle->getPropertyCSSValue(CSSPropertyFontVariant).get());
    2070     styleResolver->applyPropertyToCurrentStyle(CSSPropertyFontWeight, parsedStyle->getPropertyCSSValue(CSSPropertyFontWeight).get());
    2071 
    2072     // As described in BUG66291, setting font-size and line-height on a font may entail a CSSPrimitiveValue::computeLengthDouble call,
    2073     // which assumes the fontMetrics are available for the affected font, otherwise a crash occurs (see http://trac.webkit.org/changeset/96122).
    2074     // The updateFont() calls below update the fontMetrics and ensure the proper setting of font-size and line-height.
    2075     styleResolver->updateFont();
    2076     styleResolver->applyPropertyToCurrentStyle(CSSPropertyFontSize, parsedStyle->getPropertyCSSValue(CSSPropertyFontSize).get());
    2077     styleResolver->updateFont();
    2078     styleResolver->applyPropertyToCurrentStyle(CSSPropertyLineHeight, parsedStyle->getPropertyCSSValue(CSSPropertyLineHeight).get());
     2067    styleResolver->applyFontPropertyToStyle(newStyle.get(), parsedStyle.get());
    20792068
    20802069    modifiableState().m_font = newStyle->font();
Note: See TracChangeset for help on using the changeset viewer.