Changeset 252313 in webkit


Ignore:
Timestamp:
Nov 10, 2019 12:01:51 AM (4 years ago)
Author:
Antti Koivisto
Message:

Stack allocate StyleResolver state
https://bugs.webkit.org/show_bug.cgi?id=204053

Reviewed by Zalan Bujtas.

State is currently awkwardly a member that gets cleared. It should be stack allocated and
passed around where needed.

  • animation/KeyframeEffect.cpp:

(WebCore::KeyframeEffect::updateBlendingKeyframes):

  • css/DOMCSSRegisterCustomProperty.cpp:

(WebCore::DOMCSSRegisterCustomProperty::registerProperty):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::builderContext):

Helper for initializing Style::Builder from resolver state.

(WebCore::StyleResolver::styleForElement):
(WebCore::StyleResolver::styleForKeyframe):
(WebCore::StyleResolver::keyframeStylesForAnimation):
(WebCore::StyleResolver::pseudoStyleForElement):
(WebCore::StyleResolver::styleForPage):
(WebCore::StyleResolver::defaultStyleForElement):
(WebCore::StyleResolver::pseudoStyleRulesForElement):
(WebCore::StyleResolver::applyMatchedProperties):
(WebCore::StyleResolver::State::clear): Deleted.

Nothing to clear, state is transient.

(WebCore::StyleResolver::setNewStateWithElement): Deleted.
(WebCore::StyleResolver::applyPropertyToStyle): Deleted.
(WebCore::StyleResolver::applyPropertyToCurrentStyle): Deleted.

Style::Builder can be used directly to apply properties instead of via these functions that require state setup.

(WebCore::StyleResolver::initializeFontStyle): Deleted.

  • css/StyleResolver.h:

(WebCore::StyleResolver::inspectorCSSOMWrappers):
(WebCore::StyleResolver::style const): Deleted.
(WebCore::StyleResolver::parentStyle const): Deleted.
(WebCore::StyleResolver::rootElementStyle const): Deleted.
(WebCore::StyleResolver::element const): Deleted.
(WebCore::StyleResolver::state): Deleted.
(WebCore::StyleResolver::state const): Deleted.

  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::setFont):

Use Style::Builder directly to apply properties.

  • style/StyleBuilder.cpp:

(WebCore::Style::Builder::Builder):

Encapsulte immutable arguments into BuilderContext type.

(WebCore::Style::Builder::applyPropertyValue):

  • style/StyleBuilder.h:
  • style/StyleBuilderState.cpp:

(WebCore::Style::BuilderState::BuilderState):
(WebCore::Style::BuilderState::updateFontForZoomChange):
(WebCore::Style::BuilderState::updateFontForGenericFamilyChange):

  • style/StyleBuilderState.h:

(WebCore::Style::BuilderState::parentStyle const):
(WebCore::Style::BuilderState::rootElementStyle const):
(WebCore::Style::BuilderState::document const):
(WebCore::Style::BuilderState::element const):
(WebCore::Style::BuilderState::parentFontDescription):

Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252308 r252313  
     12019-11-10  Antti Koivisto  <antti@apple.com>
     2
     3        Stack allocate StyleResolver state
     4        https://bugs.webkit.org/show_bug.cgi?id=204053
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        State is currently awkwardly a member that gets cleared. It should be stack allocated and
     9        passed around where needed.
     10
     11        * animation/KeyframeEffect.cpp:
     12        (WebCore::KeyframeEffect::updateBlendingKeyframes):
     13        * css/DOMCSSRegisterCustomProperty.cpp:
     14        (WebCore::DOMCSSRegisterCustomProperty::registerProperty):
     15        * css/StyleResolver.cpp:
     16        (WebCore::StyleResolver::builderContext):
     17
     18        Helper for initializing Style::Builder from resolver state.
     19
     20        (WebCore::StyleResolver::styleForElement):
     21        (WebCore::StyleResolver::styleForKeyframe):
     22        (WebCore::StyleResolver::keyframeStylesForAnimation):
     23        (WebCore::StyleResolver::pseudoStyleForElement):
     24        (WebCore::StyleResolver::styleForPage):
     25        (WebCore::StyleResolver::defaultStyleForElement):
     26        (WebCore::StyleResolver::pseudoStyleRulesForElement):
     27        (WebCore::StyleResolver::applyMatchedProperties):
     28        (WebCore::StyleResolver::State::clear): Deleted.
     29
     30        Nothing to clear, state is transient.
     31
     32        (WebCore::StyleResolver::setNewStateWithElement): Deleted.
     33        (WebCore::StyleResolver::applyPropertyToStyle): Deleted.
     34        (WebCore::StyleResolver::applyPropertyToCurrentStyle): Deleted.
     35
     36        Style::Builder can be used directly to apply properties instead of via these functions that require state setup.
     37
     38        (WebCore::StyleResolver::initializeFontStyle): Deleted.
     39        * css/StyleResolver.h:
     40        (WebCore::StyleResolver::inspectorCSSOMWrappers):
     41        (WebCore::StyleResolver::style const): Deleted.
     42        (WebCore::StyleResolver::parentStyle const): Deleted.
     43        (WebCore::StyleResolver::rootElementStyle const): Deleted.
     44        (WebCore::StyleResolver::element const): Deleted.
     45        (WebCore::StyleResolver::state): Deleted.
     46        (WebCore::StyleResolver::state const): Deleted.
     47        * html/canvas/CanvasRenderingContext2D.cpp:
     48        (WebCore::CanvasRenderingContext2D::setFont):
     49
     50        Use Style::Builder directly to apply properties.
     51
     52        * style/StyleBuilder.cpp:
     53        (WebCore::Style::Builder::Builder):
     54
     55        Encapsulte immutable arguments into BuilderContext type.
     56
     57        (WebCore::Style::Builder::applyPropertyValue):
     58        * style/StyleBuilder.h:
     59        * style/StyleBuilderState.cpp:
     60        (WebCore::Style::BuilderState::BuilderState):
     61        (WebCore::Style::BuilderState::updateFontForZoomChange):
     62        (WebCore::Style::BuilderState::updateFontForGenericFamilyChange):
     63        * style/StyleBuilderState.h:
     64        (WebCore::Style::BuilderState::parentStyle const):
     65        (WebCore::Style::BuilderState::rootElementStyle const):
     66        (WebCore::Style::BuilderState::document const):
     67        (WebCore::Style::BuilderState::element const):
     68        (WebCore::Style::BuilderState::parentFontDescription):
     69
    1702019-11-09  Antti Koivisto  <antti@apple.com>
    271
  • trunk/Source/WebCore/animation/KeyframeEffect.cpp

    r252253 r252313  
    745745
    746746    for (auto& keyframe : m_parsedKeyframes) {
    747         styleResolver.setNewStateWithElement(*m_target);
    748747        KeyframeValue keyframeValue(keyframe.computedOffset, nullptr);
    749748
     
    753752
    754753        auto keyframeRule = StyleRuleKeyframe::create(WTFMove(styleProperties));
    755         keyframeValue.setStyle(styleResolver.styleForKeyframe(&elementStyle, keyframeRule.ptr(), keyframeValue));
     754        keyframeValue.setStyle(styleResolver.styleForKeyframe(*m_target, &elementStyle, keyframeRule.ptr(), keyframeValue));
    756755        keyframeList.insert(WTFMove(keyframeValue));
    757756    }
  • trunk/Source/WebCore/css/DOMCSSRegisterCustomProperty.cpp

    r252030 r252313  
    5353        // We need to initialize this so that we can successfully parse computationally dependent values (like em units).
    5454        // We don't actually need the values to be accurate, since they will be rejected later anyway
    55         styleResolver.applyPropertyToStyle(CSSPropertyInvalid, nullptr, styleResolver.defaultStyleForElement());
     55        auto style = styleResolver.defaultStyleForElement(nullptr);
    5656
    5757        HashSet<CSSPropertyID> dependencies;
     
    6161            return Exception { SyntaxError, "The given initial value must be computationally independent." };
    6262
     63
    6364        MatchResult matchResult;
    64         Style::Builder dummyBuilder(styleResolver, matchResult, { });
     65
     66        auto parentStyle = RenderStyle::clone(*style);
     67        Style::Builder dummyBuilder(*style, { document, parentStyle }, matchResult, { });
     68
    6569        initialValue = CSSPropertyParser::parseTypedCustomPropertyValue(descriptor.name, descriptor.syntax, tokenizer.tokenRange(), dummyBuilder.state(), strictCSSParserContext());
    6670
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r252308 r252313  
    8585using namespace HTMLNames;
    8686
    87 inline void StyleResolver::State::clear()
    88 {
    89     m_element = nullptr;
    90     m_parentStyle = nullptr;
    91     m_ownedParentStyle = nullptr;
    92     m_userAgentAppearanceStyle = nullptr;
    93 }
    94 
    9587StyleResolver::StyleResolver(Document& document)
    9688    : m_ruleSets(*this)
     
    174166}
    175167
    176 StyleResolver::State::State(const Element& element, const RenderStyle* parentStyle, const RenderStyle* documentElementStyle, const SelectorFilter* selectorFilter)
     168StyleResolver::State::State(const Element& element, const RenderStyle* parentStyle, const RenderStyle* documentElementStyle)
    177169    : m_element(&element)
    178170    , m_parentStyle(parentStyle)
    179     , m_selectorFilter(selectorFilter)
    180171{
    181172    bool resetStyleInheritance = hasShadowRootParent(element) && downcast<ShadowRoot>(element.parentNode())->resetStyleInheritance();
     
    208199}
    209200
    210 void StyleResolver::setNewStateWithElement(const Element& element)
    211 {
    212     // Apply the declaration to the style. This is a simplified version of the logic in styleForElement.
    213     m_state = State(element, nullptr);
     201Style::BuilderContext StyleResolver::builderContext(const State& state)
     202{
     203    return {
     204        m_document,
     205        *state.parentStyle(),
     206        state.rootElementStyle(),
     207        state.element()
     208    };
    214209}
    215210
     
    218213    RELEASE_ASSERT(!m_isDeleted);
    219214
    220     m_state = State(element, parentStyle, m_overrideDocumentElementStyle, selectorFilter);
    221     State& state = m_state;
     215    auto state = State(element, parentStyle, m_overrideDocumentElementStyle);
    222216
    223217    if (state.parentStyle()) {
     
    225219        state.style()->inheritFrom(*state.parentStyle());
    226220    } else {
    227         state.setStyle(defaultStyleForElement());
     221        state.setStyle(defaultStyleForElement(&element));
    228222        state.setParentStyle(RenderStyle::clonePtr(*state.style()));
    229223    }
     
    244238    CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(element);
    245239
    246     ElementRuleCollector collector(element, m_ruleSets, m_state.selectorFilter());
     240    ElementRuleCollector collector(element, m_ruleSets, selectorFilter);
    247241    collector.setMedium(&m_mediaQueryEvaluator);
    248242
     
    261255    auto elementStyleRelations = Style::commitRelationsToRenderStyle(style, element, collector.styleRelations());
    262256
    263     applyMatchedProperties(collector.matchResult(), element);
     257    applyMatchedProperties(state, collector.matchResult());
    264258
    265259    Style::Adjuster adjuster(document(), *state.parentStyle(), parentBoxStyle, &element);
     
    269263        document().setHasStyleWithViewportUnits();
    270264
    271     state.clear(); // Clear out for the next resolve.
    272 
    273265    return { state.takeStyle(), WTFMove(elementStyleRelations) };
    274266}
    275267
    276 std::unique_ptr<RenderStyle> StyleResolver::styleForKeyframe(const RenderStyle* elementStyle, const StyleRuleKeyframe* keyframe, KeyframeValue& keyframeValue)
     268std::unique_ptr<RenderStyle> StyleResolver::styleForKeyframe(const Element& element, const RenderStyle* elementStyle, const StyleRuleKeyframe* keyframe, KeyframeValue& keyframeValue)
    277269{
    278270    RELEASE_ASSERT(!m_isDeleted);
     
    281273    result.authorDeclarations.append({ &keyframe->properties() });
    282274
    283     ASSERT(!m_state.style());
    284 
    285     State& state = m_state;
    286 
    287     // Create the style
     275    auto state = State(element, nullptr);
     276
    288277    state.setStyle(RenderStyle::clonePtr(*elementStyle));
    289278    state.setParentStyle(RenderStyle::clonePtr(*elementStyle));
    290279
    291     Style::Builder builder(*this, result, { Style::CascadeLevel::Author });
     280    Style::Builder builder(*state.style(), builderContext(state), result, { Style::CascadeLevel::Author });
    292281    builder.applyAllProperties();
    293282
     
    372361    // Construct and populate the style for each keyframe.
    373362    for (auto& keyframe : *keyframes) {
    374         setNewStateWithElement(element);
    375 
    376363        // Add this keyframe style to all the indicated key times
    377364        for (auto key : keyframe->keys()) {
    378365            KeyframeValue keyframeValue(0, nullptr);
    379             keyframeValue.setStyle(styleForKeyframe(elementStyle, keyframe.ptr(), keyframeValue));
     366            keyframeValue.setStyle(styleForKeyframe(element, elementStyle, keyframe.ptr(), keyframeValue));
    380367            keyframeValue.setKey(key);
    381368            if (auto timingFunctionCSSValue = keyframe->properties().getPropertyCSSValue(CSSPropertyAnimationTimingFunction))
     
    394381        }
    395382        KeyframeValue keyframeValue(0, nullptr);
    396         keyframeValue.setStyle(styleForKeyframe(elementStyle, zeroPercentKeyframe, keyframeValue));
     383        keyframeValue.setStyle(styleForKeyframe(element, elementStyle, zeroPercentKeyframe, keyframeValue));
    397384        list.insert(WTFMove(keyframeValue));
    398385    }
     
    406393        }
    407394        KeyframeValue keyframeValue(1, nullptr);
    408         keyframeValue.setStyle(styleForKeyframe(elementStyle, hundredPercentKeyframe, keyframeValue));
     395        keyframeValue.setStyle(styleForKeyframe(element, elementStyle, hundredPercentKeyframe, keyframeValue));
    409396        list.insert(WTFMove(keyframeValue));
    410397    }
     
    413400std::unique_ptr<RenderStyle> StyleResolver::pseudoStyleForElement(const Element& element, const PseudoStyleRequest& pseudoStyleRequest, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const SelectorFilter* selectorFilter)
    414401{
    415     m_state = State(element, &parentStyle, m_overrideDocumentElementStyle, selectorFilter);
    416 
    417     State& state = m_state;
    418 
    419     if (m_state.parentStyle()) {
     402    auto state = State(element, &parentStyle, m_overrideDocumentElementStyle);
     403
     404    if (state.parentStyle()) {
    420405        state.setStyle(RenderStyle::createPtr());
    421         state.style()->inheritFrom(*m_state.parentStyle());
     406        state.style()->inheritFrom(*state.parentStyle());
    422407    } else {
    423         state.setStyle(defaultStyleForElement());
     408        state.setStyle(defaultStyleForElement(&element));
    424409        state.setParentStyle(RenderStyle::clonePtr(*state.style()));
    425410    }
    426411
    427     // Since we don't use pseudo-elements in any of our quirk/print user agent rules, don't waste time walking
    428     // those rules.
    429 
    430     // Check UA, user and author rules.
    431     ElementRuleCollector collector(element, m_ruleSets, m_state.selectorFilter());
     412    ElementRuleCollector collector(element, m_ruleSets, selectorFilter);
    432413    collector.setPseudoStyleRequest(pseudoStyleRequest);
    433414    collector.setMedium(&m_mediaQueryEvaluator);
     
    446427    state.style()->setStyleType(pseudoStyleRequest.pseudoId);
    447428
    448     applyMatchedProperties(collector.matchResult(), element);
     429    applyMatchedProperties(state, collector.matchResult());
    449430
    450431    Style::Adjuster adjuster(document(), *state.parentStyle(), parentBoxStyle, nullptr);
     
    454435        document().setHasStyleWithViewportUnits();
    455436
    456     // Now return the style.
    457437    return state.takeStyle();
    458438}
     
    466446        return RenderStyle::createPtr();
    467447
    468     m_state = State(*documentElement, m_document.renderStyle());
    469 
    470     m_state.setStyle(RenderStyle::createPtr());
    471     m_state.style()->inheritFrom(*m_state.rootElementStyle());
    472 
    473     PageRuleCollector collector(m_state, m_ruleSets);
     448    auto state = State(*documentElement, m_document.renderStyle());
     449
     450    state.setStyle(RenderStyle::createPtr());
     451    state.style()->inheritFrom(*state.rootElementStyle());
     452
     453    PageRuleCollector collector(state, m_ruleSets);
    474454    collector.matchAllPageRules(pageIndex);
    475455
    476456    auto& result = collector.matchResult();
    477457
    478     Style::Builder builder(*this, result, { Style::CascadeLevel::Author });
     458    Style::Builder builder(*state.style(), builderContext(state), result, { Style::CascadeLevel::Author });
    479459    builder.applyAllProperties();
    480460
    481461    // Now return the style.
    482     return m_state.takeStyle();
    483 }
    484 
    485 std::unique_ptr<RenderStyle> StyleResolver::defaultStyleForElement()
    486 {
    487     m_state.setStyle(RenderStyle::createPtr());
    488     // Make sure our fonts are initialized if we don't inherit them from our parent style.
    489     initializeFontStyle();
    490     m_state.style()->fontCascade().update(&document().fontSelector());
    491     return m_state.takeStyle();
     462    return state.takeStyle();
     463}
     464
     465std::unique_ptr<RenderStyle> StyleResolver::defaultStyleForElement(const Element* element)
     466{
     467    auto style = RenderStyle::createPtr();
     468
     469    FontCascadeDescription fontDescription;
     470    fontDescription.setRenderingMode(settings().fontRenderingMode());
     471    fontDescription.setOneFamily(standardFamily);
     472    fontDescription.setKeywordSizeFromIdentifier(CSSValueMedium);
     473
     474    auto size = Style::fontSizeForKeyword(CSSValueMedium, false, document());
     475    fontDescription.setSpecifiedSize(size);
     476    fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), is<SVGElement>(element), style.get(), document()));
     477
     478    fontDescription.setShouldAllowUserInstalledFonts(settings().shouldAllowUserInstalledFonts() ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No);
     479    style->setFontDescription(WTFMove(fontDescription));
     480
     481    style->fontCascade().update(&document().fontSelector());
     482
     483    return style;
    492484}
    493485
     
    502494        return { };
    503495
    504     m_state = State(*element, nullptr);
    505 
    506     ElementRuleCollector collector(*element, m_ruleSets, m_state.selectorFilter());
     496    auto state = State(*element, nullptr);
     497
     498    ElementRuleCollector collector(*element, m_ruleSets, nullptr);
    507499    collector.setMode(SelectorChecker::Mode::CollectingRules);
    508500    collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId));
     
    547539}
    548540
    549 void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const Element& element, UseMatchedDeclarationsCache useMatchedDeclarationsCache)
    550 {
    551     State& state = m_state;
     541void StyleResolver::applyMatchedProperties(State& state, const MatchResult& matchResult, UseMatchedDeclarationsCache useMatchedDeclarationsCache)
     542{
    552543    unsigned cacheHash = useMatchedDeclarationsCache == UseMatchedDeclarationsCache::Yes ? Style::MatchedDeclarationsCache::computeHash(matchResult) : 0;
    553544    auto includedProperties = Style::PropertyCascade::IncludedProperties::All;
     
    555546    auto& style = *state.style();
    556547    auto& parentStyle = *state.parentStyle();
     548    auto& element = *state.element();
    557549
    558550    auto* cacheEntry = m_matchedDeclarationsCache.find(cacheHash, matchResult);
     
    580572        // can look at them later to figure out if this is a styled form control or not.
    581573        auto userAgentStyle = RenderStyle::clonePtr(style);
    582         Style::Builder builder(*userAgentStyle, *this, matchResult, { Style::CascadeLevel::UserAgent });
     574        Style::Builder builder(*userAgentStyle, builderContext(state), matchResult, { Style::CascadeLevel::UserAgent });
    583575        builder.applyAllProperties();
    584576
     
    586578    }
    587579
    588     Style::Builder builder(*this, matchResult, Style::allCascadeLevels(), includedProperties);
     580    Style::Builder builder(*state.style(), builderContext(state), matchResult, Style::allCascadeLevels(), includedProperties);
    589581
    590582    // High priority properties may affect resolution of other properties (they are mostly font related).
     
    593585    // If the effective zoom value changes, we can't use the matched properties cache. Start over.
    594586    if (cacheEntry && cacheEntry->renderStyle->effectiveZoom() != style.effectiveZoom())
    595         return applyMatchedProperties(matchResult, element, UseMatchedDeclarationsCache::No);
     587        return applyMatchedProperties(state, matchResult, UseMatchedDeclarationsCache::No);
    596588
    597589    // If the font changed, we can't use the matched properties cache. Start over.
    598590    if (cacheEntry && cacheEntry->renderStyle->fontDescription() != style.fontDescription())
    599         return applyMatchedProperties(matchResult, element, UseMatchedDeclarationsCache::No);
     591        return applyMatchedProperties(state, matchResult, UseMatchedDeclarationsCache::No);
    600592
    601593    builder.applyLowPriorityProperties();
     
    609601    if (Style::MatchedDeclarationsCache::isCacheable(element, style, parentStyle))
    610602        m_matchedDeclarationsCache.add(style, parentStyle, cacheHash, matchResult);
    611 }
    612 
    613 void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, std::unique_ptr<RenderStyle> style)
    614 {
    615     m_state = State();
    616     m_state.setParentStyle(RenderStyle::clonePtr(*style));
    617     m_state.setStyle(WTFMove(style));
    618     applyPropertyToCurrentStyle(id, value);
    619 }
    620 
    621 void StyleResolver::applyPropertyToCurrentStyle(CSSPropertyID id, CSSValue* value)
    622 {
    623     if (!value)
    624         return;
    625 
    626     MatchResult matchResult;
    627     Style::Builder builder(*this, matchResult, { });
    628     builder.applyPropertyValue(id, *value);
    629 }
    630 
    631 void StyleResolver::initializeFontStyle()
    632 {
    633     FontCascadeDescription fontDescription;
    634     fontDescription.setRenderingMode(settings().fontRenderingMode());
    635     fontDescription.setOneFamily(standardFamily);
    636     fontDescription.setKeywordSizeFromIdentifier(CSSValueMedium);
    637 
    638     auto size = Style::fontSizeForKeyword(CSSValueMedium, false, document());
    639     fontDescription.setSpecifiedSize(size);
    640     fontDescription.setComputedSize(Style::computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), is<SVGElement>(m_state.element()), m_state.style(), document()));
    641 
    642     fontDescription.setShouldAllowUserInstalledFonts(settings().shouldAllowUserInstalledFonts() ? AllowUserInstalledFonts::Yes : AllowUserInstalledFonts::No);
    643     style()->setFontDescription(WTFMove(fontDescription));
    644603}
    645604
  • trunk/Source/WebCore/css/StyleResolver.h

    r252308 r252313  
    3030#include "RenderStyle.h"
    3131#include "RuleSet.h"
     32#include "StyleBuilderState.h"
    3233#include <memory>
    3334#include <wtf/HashMap.h>
     
    113114
    114115    std::unique_ptr<RenderStyle> styleForPage(int pageIndex);
    115     std::unique_ptr<RenderStyle> defaultStyleForElement();
    116 
    117     RenderStyle* style() const { return m_state.style(); }
    118     const RenderStyle* parentStyle() const { return m_state.parentStyle(); }
    119     const RenderStyle* rootElementStyle() const { return m_state.rootElementStyle(); }
    120     const Element* element() const { return m_state.element(); }
     116    std::unique_ptr<RenderStyle> defaultStyleForElement(const Element*);
     117
    121118    Document& document() { return m_document; }
    122119    const Document& document() const { return m_document; }
     
    135132    void addCurrentSVGFontFaceRules();
    136133
    137     void setNewStateWithElement(const Element&);
    138     std::unique_ptr<RenderStyle> styleForKeyframe(const RenderStyle*, const StyleRuleKeyframe*, KeyframeValue&);
     134    std::unique_ptr<RenderStyle> styleForKeyframe(const Element&, const RenderStyle*, const StyleRuleKeyframe*, KeyframeValue&);
    139135    bool isAnimationNameValid(const String&);
    140136
     
    150146    Vector<RefPtr<StyleRule>> pseudoStyleRulesForElement(const Element*, PseudoId, unsigned rulesToInclude = AllButEmptyCSSRules);
    151147
    152     void applyPropertyToStyle(CSSPropertyID, CSSValue*, std::unique_ptr<RenderStyle>);
    153     void applyPropertyToCurrentStyle(CSSPropertyID, CSSValue*);
    154 
    155     void initializeFontStyle();
    156 
    157148    bool hasSelectorForId(const AtomString&) const;
    158149    bool hasSelectorForAttribute(const Element&, const AtomString&) const;
     
    182173    void clearCachedDeclarationsAffectedByViewportUnits();
    183174
     175    InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWrappers; }
     176
    184177private:
    185     enum class UseMatchedDeclarationsCache { Yes, No };
    186     void applyMatchedProperties(const MatchResult&, const Element&, UseMatchedDeclarationsCache = UseMatchedDeclarationsCache::Yes);
    187 
    188     DocumentRuleSets m_ruleSets;
    189 
    190     typedef HashMap<AtomStringImpl*, RefPtr<StyleRuleKeyframes>> KeyframesRuleMap;
    191     KeyframesRuleMap m_keyframesRuleMap;
    192 
    193 public:
     178    friend class PageRuleCollector;
     179
    194180    class State {
    195181    public:
    196182        State() { }
    197         State(const Element&, const RenderStyle* parentStyle, const RenderStyle* documentElementStyle = nullptr, const SelectorFilter* = nullptr);
     183        State(const Element&, const RenderStyle* parentStyle, const RenderStyle* documentElementStyle = nullptr);
    198184
    199185    public:
    200         void clear();
    201 
    202186        const Element* element() const { return m_element; }
    203187
     
    213197        void setUserAgentAppearanceStyle(std::unique_ptr<RenderStyle> style) { m_userAgentAppearanceStyle = WTFMove(style); }
    214198
    215         const SelectorFilter* selectorFilter() const { return m_selectorFilter; }
    216        
    217199    private:
    218200        const Element* m_element { nullptr };
    219201        std::unique_ptr<RenderStyle> m_style;
    220202        const RenderStyle* m_parentStyle { nullptr };
    221         std::unique_ptr<RenderStyle> m_ownedParentStyle;
     203        std::unique_ptr<const RenderStyle> m_ownedParentStyle;
    222204        const RenderStyle* m_rootElementStyle { nullptr };
    223 
    224         const SelectorFilter* m_selectorFilter { nullptr };
    225205
    226206        std::unique_ptr<RenderStyle> m_userAgentAppearanceStyle;
    227207    };
    228208
    229     State& state() { return m_state; }
    230     const State& state() const { return m_state; }
    231 
    232     InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWrappers; }
    233 
    234 private:
    235     void cacheBorderAndBackground();
     209    Style::BuilderContext builderContext(const State&);
     210
     211    enum class UseMatchedDeclarationsCache { Yes, No };
     212    void applyMatchedProperties(State&, const MatchResult&, UseMatchedDeclarationsCache = UseMatchedDeclarationsCache::Yes);
     213
     214    DocumentRuleSets m_ruleSets;
     215
     216    typedef HashMap<AtomStringImpl*, RefPtr<StyleRuleKeyframes>> KeyframesRuleMap;
     217    KeyframesRuleMap m_keyframesRuleMap;
    236218
    237219    MediaQueryEvaluator m_mediaQueryEvaluator;
     
    251233
    252234    InspectorCSSOMWrappers m_inspectorCSSOMWrappers;
    253 
    254     State m_state;
    255235
    256236    Style::MatchedDeclarationsCache m_matchedDeclarationsCache;
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r251796 r252313  
    4444#include "ResourceLoadObserver.h"
    4545#include "RuntimeEnabledFeatures.h"
     46#include "StyleBuilder.h"
    4647#include "StyleProperties.h"
    47 #include "StyleResolver.h"
    4848#include "TextMetrics.h"
    4949#include "TextRun.h"
     
    172172
    173173    // Now map the font property longhands into the style.
    174     StyleResolver& styleResolver = canvas().styleResolver();
    175     styleResolver.applyPropertyToStyle(CSSPropertyFontFamily, parsedStyle->getPropertyCSSValue(CSSPropertyFontFamily).get(), WTFMove(newStyle));
    176     styleResolver.applyPropertyToCurrentStyle(CSSPropertyFontStyle, parsedStyle->getPropertyCSSValue(CSSPropertyFontStyle).get());
    177     styleResolver.applyPropertyToCurrentStyle(CSSPropertyFontVariantCaps, parsedStyle->getPropertyCSSValue(CSSPropertyFontVariantCaps).get());
    178     styleResolver.applyPropertyToCurrentStyle(CSSPropertyFontWeight, parsedStyle->getPropertyCSSValue(CSSPropertyFontWeight).get());
    179     styleResolver.applyPropertyToCurrentStyle(CSSPropertyFontSize, parsedStyle->getPropertyCSSValue(CSSPropertyFontSize).get());
    180     styleResolver.applyPropertyToCurrentStyle(CSSPropertyLineHeight, parsedStyle->getPropertyCSSValue(CSSPropertyLineHeight).get());
    181 
    182     modifiableState().font.initialize(document.fontSelector(), *styleResolver.style());
     174
     175    MatchResult matchResult;
     176    auto parentStyle = RenderStyle::clone(*newStyle);
     177    WebCore::Style::Builder styleBuilder(*newStyle, { document, parentStyle }, matchResult, { });
     178
     179    styleBuilder.applyPropertyValue(CSSPropertyFontFamily, parsedStyle->getPropertyCSSValue(CSSPropertyFontFamily).get());
     180    styleBuilder.applyPropertyValue(CSSPropertyFontStyle, parsedStyle->getPropertyCSSValue(CSSPropertyFontStyle).get());
     181    styleBuilder.applyPropertyValue(CSSPropertyFontVariantCaps, parsedStyle->getPropertyCSSValue(CSSPropertyFontVariantCaps).get());
     182    styleBuilder.applyPropertyValue(CSSPropertyFontWeight, parsedStyle->getPropertyCSSValue(CSSPropertyFontWeight).get());
     183    styleBuilder.applyPropertyValue(CSSPropertyFontSize, parsedStyle->getPropertyCSSValue(CSSPropertyFontSize).get());
     184    styleBuilder.applyPropertyValue(CSSPropertyLineHeight, parsedStyle->getPropertyCSSValue(CSSPropertyLineHeight).get());
     185
     186    modifiableState().font.initialize(document.fontSelector(), *newStyle);
    183187}
    184188
  • trunk/Source/WebCore/style/PropertyCascade.h

    r252030 r252313  
    3636
    3737namespace Style {
    38 
    39 inline bool isValidVisitedLinkProperty(CSSPropertyID id)
    40 {
    41     switch (id) {
    42     case CSSPropertyBackgroundColor:
    43     case CSSPropertyBorderLeftColor:
    44     case CSSPropertyBorderRightColor:
    45     case CSSPropertyBorderTopColor:
    46     case CSSPropertyBorderBottomColor:
    47     case CSSPropertyCaretColor:
    48     case CSSPropertyColor:
    49     case CSSPropertyOutlineColor:
    50     case CSSPropertyColumnRuleColor:
    51     case CSSPropertyTextDecorationColor:
    52     case CSSPropertyWebkitTextEmphasisColor:
    53     case CSSPropertyWebkitTextFillColor:
    54     case CSSPropertyWebkitTextStrokeColor:
    55     case CSSPropertyFill:
    56     case CSSPropertyStroke:
    57     case CSSPropertyStrokeColor:
    58         return true;
    59     default:
    60         break;
    61     }
    62 
    63     return false;
    64 }
    6538
    6639class PropertyCascade {
  • trunk/Source/WebCore/style/StyleBuilder.cpp

    r252255 r252313  
    3838#include "StyleBuilderGenerated.h"
    3939#include "StyleFontSizeFunctions.h"
    40 #include "StyleResolver.h"
    4140
    4241namespace WebCore {
     
    4544static const CSSPropertyID firstLowPriorityProperty = static_cast<CSSPropertyID>(lastHighPriorityProperty + 1);
    4645
    47 static PropertyCascade::Direction directionFromStyle(const RenderStyle& style)
     46inline PropertyCascade::Direction directionFromStyle(const RenderStyle& style)
    4847{
    4948    return { style.direction(), style.writingMode() };
    5049}
    5150
    52 Builder::Builder(RenderStyle& style, const StyleResolver& resolver, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, PropertyCascade::IncludedProperties includedProperties)
     51inline bool isValidVisitedLinkProperty(CSSPropertyID id)
     52{
     53    switch (id) {
     54    case CSSPropertyBackgroundColor:
     55    case CSSPropertyBorderLeftColor:
     56    case CSSPropertyBorderRightColor:
     57    case CSSPropertyBorderTopColor:
     58    case CSSPropertyBorderBottomColor:
     59    case CSSPropertyCaretColor:
     60    case CSSPropertyColor:
     61    case CSSPropertyOutlineColor:
     62    case CSSPropertyColumnRuleColor:
     63    case CSSPropertyTextDecorationColor:
     64    case CSSPropertyWebkitTextEmphasisColor:
     65    case CSSPropertyWebkitTextFillColor:
     66    case CSSPropertyWebkitTextStrokeColor:
     67    case CSSPropertyFill:
     68    case CSSPropertyStroke:
     69    case CSSPropertyStrokeColor:
     70        return true;
     71    default:
     72        break;
     73    }
     74
     75    return false;
     76}
     77
     78Builder::Builder(RenderStyle& style, BuilderContext&& context, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, PropertyCascade::IncludedProperties includedProperties)
    5379    : m_cascade(matchResult, cascadeLevels, includedProperties, directionFromStyle(style))
    54     , m_state(*this, style, *resolver.parentStyle(), resolver.rootElementStyle(), resolver.document(), resolver.element())
    55 {
    56     ASSERT(resolver.parentStyle());
    57 }
    58 
    59 Builder::Builder(StyleResolver& resolver, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, PropertyCascade::IncludedProperties includedProperties)
    60     : Builder(*resolver.style(), resolver, matchResult, cascadeLevels, includedProperties)
    61 {
    62     ASSERT(resolver.style());
     80    , m_state(*this, style, WTFMove(context))
     81{
    6382}
    6483
     
    98117}
    99118
    100 void Builder::applyPropertyValue(CSSPropertyID propertyID, CSSValue& value)
    101 {
    102     applyProperty(propertyID, value, SelectorChecker::MatchDefault);
     119void Builder::applyPropertyValue(CSSPropertyID propertyID, CSSValue* value)
     120{
     121    if (!value)
     122        return;
     123
     124    applyProperty(propertyID, *value, SelectorChecker::MatchDefault);
    103125
    104126    m_state.updateFont();
  • trunk/Source/WebCore/style/StyleBuilder.h

    r252255 r252313  
    3636    WTF_MAKE_FAST_ALLOCATED;
    3737public:
    38     Builder(RenderStyle&, const StyleResolver&, const MatchResult&, OptionSet<CascadeLevel>, PropertyCascade::IncludedProperties = PropertyCascade::IncludedProperties::All);
    39     Builder(StyleResolver&, const MatchResult&, OptionSet<CascadeLevel>, PropertyCascade::IncludedProperties = PropertyCascade::IncludedProperties::All);
     38    Builder(RenderStyle&, BuilderContext&&, const MatchResult&, OptionSet<CascadeLevel>, PropertyCascade::IncludedProperties = PropertyCascade::IncludedProperties::All);
    4039    ~Builder();
    4140
     
    4746    void applyCustomProperty(const String& name);
    4847
    49     void applyPropertyValue(CSSPropertyID, CSSValue&);
     48    void applyPropertyValue(CSSPropertyID, CSSValue*);
    5049
    5150    BuilderState& state() { return m_state; }
  • trunk/Source/WebCore/style/StyleBuilderState.cpp

    r252030 r252313  
    5252namespace Style {
    5353
    54 BuilderState::BuilderState(Builder& builder, RenderStyle& style, const RenderStyle& parentStyle, const RenderStyle* rootElementStyle, const Document& document, const Element* element)
     54BuilderState::BuilderState(Builder& builder, RenderStyle& style, BuilderContext&& context)
    5555    : m_builder(builder)
    5656    , m_styleMap(*this)
    5757    , m_style(style)
    58     , m_parentStyle(parentStyle)
    59     , m_rootElementStyle(rootElementStyle)
    60     , m_cssToLengthConversionData(&style, rootElementStyle, document.renderView())
    61     , m_document(document)
    62     , m_element(element)
     58    , m_context(WTFMove(context))
     59    , m_cssToLengthConversionData(&style, rootElementStyle(), document().renderView())
    6360{
    6461}
     
    360357void BuilderState::updateFontForZoomChange()
    361358{
    362     if (m_style.effectiveZoom() == m_parentStyle.effectiveZoom() && m_style.textZoom() == m_parentStyle.textZoom())
     359    if (m_style.effectiveZoom() == parentStyle().effectiveZoom() && m_style.textZoom() == parentStyle().textZoom())
    363360        return;
    364361
     
    377374        return;
    378375
    379     const auto& parentFont = m_parentStyle.fontDescription();
     376    const auto& parentFont = parentStyle().fontDescription();
    380377    if (childFont.useFixedDefaultSize() == parentFont.useFixedDefaultSize())
    381378        return;
  • trunk/Source/WebCore/style/StyleBuilderState.h

    r251916 r252313  
    4242class Builder;
    4343
     44struct BuilderContext {
     45    Ref<const Document> document;
     46    const RenderStyle& parentStyle;
     47    const RenderStyle* rootElementStyle = nullptr;
     48    RefPtr<const Element> element = nullptr;
     49};
     50
    4451class BuilderState {
    4552public:
    46     BuilderState(Builder&, RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* rootElementStyle, const Document&, const Element*);
     53    BuilderState(Builder&, RenderStyle&, BuilderContext&&);
    4754
    4855    Builder& builder() { return m_builder; }
    4956
    5057    RenderStyle& style() { return m_style; }
    51     const RenderStyle& parentStyle() const { return m_parentStyle; }
    52     const RenderStyle* rootElementStyle() const { return m_rootElementStyle; }
     58    const RenderStyle& parentStyle() const { return m_context.parentStyle; }
     59    const RenderStyle* rootElementStyle() const { return m_context.rootElementStyle; }
    5360
    54     const Document& document() const { return m_document.get(); }
    55     const Element* element() const { return m_element.get(); }
     61    const Document& document() const { return m_context.document.get(); }
     62    const Element* element() const { return m_context.element.get(); }
    5663
    5764    void setFontDescription(FontCascadeDescription&& fontDescription) { m_fontDirty |= m_style.setFontDescription(WTFMove(fontDescription)); }
     
    6673
    6774    const FontCascadeDescription& fontDescription() { return m_style.fontDescription(); }
    68     const FontCascadeDescription& parentFontDescription() { return m_parentStyle.fontDescription(); }
     75    const FontCascadeDescription& parentFontDescription() { return parentStyle().fontDescription(); }
    6976
    7077    // FIXME: These are mutually exclusive, clean up the code to take that into account.
     
    106113
    107114    RenderStyle& m_style;
    108     const RenderStyle& m_parentStyle;
    109     const RenderStyle* m_rootElementStyle;
     115    const BuilderContext m_context;
    110116
    111117    const CSSToLengthConversionData m_cssToLengthConversionData;
    112 
    113     Ref<const Document> m_document;
    114     RefPtr<const Element> m_element;
    115118
    116119    Bitmap<numCSSProperties> m_appliedProperties;
Note: See TracChangeset for help on using the changeset viewer.