⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 284693 in webkit


Ignore:
Timestamp:
Oct 22, 2021, 9:56:35 AM (5 years ago)
Author:
Antti Koivisto
Message:

Factor style resolver context arguments into a struct
https://bugs.webkit.org/show_bug.cgi?id=232137

Reviewed by Antoine Quint.

Add Style::ResolutionContext struct and use it to consistently pass around all context argument needed
for resolving style instead of just passing around individual arguments as separate function parameter.

An immediately benefit is that we can remove the stateful setOverrideDocumentElementStyle hack.
This also makes the style system more flexible and extensible for future work.

Most of the patch is mechanically replacing a parent style argument in various places with a context
struct argument.

  • animation/AnimationEffect.h:
  • animation/CSSAnimation.cpp:

(WebCore::CSSAnimation::create):

  • animation/CSSAnimation.h:
  • animation/CSSTransition.cpp:

(WebCore::CSSTransition::create):
(WebCore::CSSTransition::resolve):

  • animation/CSSTransition.h:
  • animation/DeclarativeAnimation.cpp:

(WebCore::DeclarativeAnimation::initialize):

  • animation/DeclarativeAnimation.h:
  • animation/KeyframeEffect.cpp:

(WebCore::KeyframeEffect::updateBlendingKeyframes):
(WebCore::KeyframeEffect::computeDeclarativeAnimationBlendingKeyframes):
(WebCore::KeyframeEffect::computeCSSAnimationBlendingKeyframes):
(WebCore::KeyframeEffect::apply):
(WebCore::KeyframeEffect::setAnimatedPropertiesInStyle):

  • animation/KeyframeEffect.h:
  • animation/KeyframeEffectStack.cpp:

(WebCore::KeyframeEffectStack::applyKeyframeEffects):

  • animation/KeyframeEffectStack.h:
  • animation/WebAnimation.cpp:

(WebCore::WebAnimation::resolve):
(WebCore::WebAnimation::commitStyles):

  • animation/WebAnimation.h:
  • css/MediaQueryMatcher.cpp:

(WebCore::MediaQueryMatcher::documentElementUserAgentStyle const):

  • css/StyleMedia.cpp:

(WebCore::StyleMedia::matchMedium const):

  • dom/Document.cpp:

(WebCore::Document::styleForElementIgnoringPendingStylesheets):

  • dom/Element.cpp:

(WebCore::Element::resolveStyle):
(WebCore::Element::resolveCustomStyle):

  • dom/Element.h:
  • html/HTMLTitleElement.cpp:

(WebCore::HTMLTitleElement::computedTextWithDirection):

  • html/shadow/DateTimeFieldElement.cpp:

(WebCore::DateTimeFieldElement::resolveCustomStyle):

  • html/shadow/DateTimeFieldElement.h:
  • html/shadow/SliderThumbElement.cpp:

(WebCore::SliderThumbElement::resolveCustomStyle):
(WebCore::SliderContainerElement::resolveCustomStyle):

  • html/shadow/SliderThumbElement.h:
  • html/shadow/TextControlInnerElements.cpp:

(WebCore::TextControlInnerContainer::resolveCustomStyle):
(WebCore::TextControlInnerElement::resolveCustomStyle):
(WebCore::TextControlInnerTextElement::resolveCustomStyle):
(WebCore::TextControlPlaceholderElement::resolveCustomStyle):
(WebCore::SearchFieldResultsButtonElement::resolveCustomStyle):
(WebCore::SearchFieldCancelButtonElement::resolveCustomStyle):

  • html/shadow/TextControlInnerElements.h:
  • rendering/RenderElement.cpp:

(WebCore::RenderElement::computeFirstLineStyle const):
(WebCore::RenderElement::getUncachedPseudoStyle const):

  • rendering/style/KeyframeList.cpp:

(WebCore::KeyframeList::fillImplicitKeyframes):

  • style/StyleResolver.cpp:

(WebCore::Style::Resolver::Resolver):
(WebCore::Style::Resolver::styleForElement):
(WebCore::Style::Resolver::styleForKeyframe):
(WebCore::Style::Resolver::keyframeStylesForAnimation):
(WebCore::Style::Resolver::pseudoStyleForElement):

  • style/StyleResolver.h:

(WebCore::Style::Resolver::overrideDocumentElementStyle const): Deleted.
(WebCore::Style::Resolver::setOverrideDocumentElementStyle): Deleted.

  • style/StyleTreeResolver.cpp:

(WebCore::Style::TreeResolver::Scope::Scope):
(WebCore::Style::TreeResolver::Scope::~Scope):
(WebCore::Style::TreeResolver::styleForStyleable):
(WebCore::Style::TreeResolver::resolveElement):
(WebCore::Style::TreeResolver::resolvePseudoStyle):
(WebCore::Style::TreeResolver::makeResolveContext):
(WebCore::Style::TreeResolver::makeResolveContextForPseudoElement):
(WebCore::Style::TreeResolver::parentBoxStyleForPseudoElement const):
(WebCore::Style::TreeResolver::createAnimatedElementUpdate):
(WebCore::Style::TreeResolver::parentBoxStyleForPseudo const): Deleted.

  • style/StyleTreeResolver.h:
  • style/Styleable.cpp:

(WebCore::Styleable::updateCSSAnimations const):
(WebCore::updateCSSTransitionsForStyleableAndProperty):

  • style/Styleable.h:

(WebCore::Styleable::applyKeyframeEffects const):

  • svg/SVGElement.cpp:

(WebCore::SVGElement::resolveCustomStyle):

  • svg/SVGElement.h:
  • svg/SVGElementRareData.h:

(WebCore::SVGElementRareData::overrideComputedStyle):

  • testing/Internals.cpp:

(WebCore::Internals::highlightPseudoElementColor):

Location:
trunk/Source/WebCore
Files:
38 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r284692 r284693  
     12021-10-22  Antti Koivisto  <antti@apple.com>
     2
     3        Factor style resolver context arguments into a struct
     4        https://bugs.webkit.org/show_bug.cgi?id=232137
     5
     6        Reviewed by Antoine Quint.
     7
     8        Add Style::ResolutionContext struct and use it to consistently pass around all context argument needed
     9        for resolving style instead of just passing around individual arguments as separate function parameter.
     10
     11        An immediately benefit is that we can remove the stateful setOverrideDocumentElementStyle hack.
     12        This also makes the style system more flexible and extensible for future work.
     13
     14        Most of the patch is mechanically replacing a parent style argument in various places with a context
     15        struct argument.
     16
     17        * animation/AnimationEffect.h:
     18        * animation/CSSAnimation.cpp:
     19        (WebCore::CSSAnimation::create):
     20        * animation/CSSAnimation.h:
     21        * animation/CSSTransition.cpp:
     22        (WebCore::CSSTransition::create):
     23        (WebCore::CSSTransition::resolve):
     24        * animation/CSSTransition.h:
     25        * animation/DeclarativeAnimation.cpp:
     26        (WebCore::DeclarativeAnimation::initialize):
     27        * animation/DeclarativeAnimation.h:
     28        * animation/KeyframeEffect.cpp:
     29        (WebCore::KeyframeEffect::updateBlendingKeyframes):
     30        (WebCore::KeyframeEffect::computeDeclarativeAnimationBlendingKeyframes):
     31        (WebCore::KeyframeEffect::computeCSSAnimationBlendingKeyframes):
     32        (WebCore::KeyframeEffect::apply):
     33        (WebCore::KeyframeEffect::setAnimatedPropertiesInStyle):
     34        * animation/KeyframeEffect.h:
     35        * animation/KeyframeEffectStack.cpp:
     36        (WebCore::KeyframeEffectStack::applyKeyframeEffects):
     37        * animation/KeyframeEffectStack.h:
     38        * animation/WebAnimation.cpp:
     39        (WebCore::WebAnimation::resolve):
     40        (WebCore::WebAnimation::commitStyles):
     41        * animation/WebAnimation.h:
     42        * css/MediaQueryMatcher.cpp:
     43        (WebCore::MediaQueryMatcher::documentElementUserAgentStyle const):
     44        * css/StyleMedia.cpp:
     45        (WebCore::StyleMedia::matchMedium const):
     46        * dom/Document.cpp:
     47        (WebCore::Document::styleForElementIgnoringPendingStylesheets):
     48        * dom/Element.cpp:
     49        (WebCore::Element::resolveStyle):
     50        (WebCore::Element::resolveCustomStyle):
     51        * dom/Element.h:
     52        * html/HTMLTitleElement.cpp:
     53        (WebCore::HTMLTitleElement::computedTextWithDirection):
     54        * html/shadow/DateTimeFieldElement.cpp:
     55        (WebCore::DateTimeFieldElement::resolveCustomStyle):
     56        * html/shadow/DateTimeFieldElement.h:
     57        * html/shadow/SliderThumbElement.cpp:
     58        (WebCore::SliderThumbElement::resolveCustomStyle):
     59        (WebCore::SliderContainerElement::resolveCustomStyle):
     60        * html/shadow/SliderThumbElement.h:
     61        * html/shadow/TextControlInnerElements.cpp:
     62        (WebCore::TextControlInnerContainer::resolveCustomStyle):
     63        (WebCore::TextControlInnerElement::resolveCustomStyle):
     64        (WebCore::TextControlInnerTextElement::resolveCustomStyle):
     65        (WebCore::TextControlPlaceholderElement::resolveCustomStyle):
     66        (WebCore::SearchFieldResultsButtonElement::resolveCustomStyle):
     67        (WebCore::SearchFieldCancelButtonElement::resolveCustomStyle):
     68        * html/shadow/TextControlInnerElements.h:
     69        * rendering/RenderElement.cpp:
     70        (WebCore::RenderElement::computeFirstLineStyle const):
     71        (WebCore::RenderElement::getUncachedPseudoStyle const):
     72        * rendering/style/KeyframeList.cpp:
     73        (WebCore::KeyframeList::fillImplicitKeyframes):
     74        * style/StyleResolver.cpp:
     75        (WebCore::Style::Resolver::Resolver):
     76        (WebCore::Style::Resolver::styleForElement):
     77        (WebCore::Style::Resolver::styleForKeyframe):
     78        (WebCore::Style::Resolver::keyframeStylesForAnimation):
     79        (WebCore::Style::Resolver::pseudoStyleForElement):
     80        * style/StyleResolver.h:
     81        (WebCore::Style::Resolver::overrideDocumentElementStyle const): Deleted.
     82        (WebCore::Style::Resolver::setOverrideDocumentElementStyle): Deleted.
     83        * style/StyleTreeResolver.cpp:
     84        (WebCore::Style::TreeResolver::Scope::Scope):
     85        (WebCore::Style::TreeResolver::Scope::~Scope):
     86        (WebCore::Style::TreeResolver::styleForStyleable):
     87        (WebCore::Style::TreeResolver::resolveElement):
     88        (WebCore::Style::TreeResolver::resolvePseudoStyle):
     89        (WebCore::Style::TreeResolver::makeResolveContext):
     90        (WebCore::Style::TreeResolver::makeResolveContextForPseudoElement):
     91        (WebCore::Style::TreeResolver::parentBoxStyleForPseudoElement const):
     92        (WebCore::Style::TreeResolver::createAnimatedElementUpdate):
     93        (WebCore::Style::TreeResolver::parentBoxStyleForPseudo const): Deleted.
     94        * style/StyleTreeResolver.h:
     95        * style/Styleable.cpp:
     96        (WebCore::Styleable::updateCSSAnimations const):
     97        (WebCore::updateCSSTransitionsForStyleableAndProperty):
     98        * style/Styleable.h:
     99        (WebCore::Styleable::applyKeyframeEffects const):
     100        * svg/SVGElement.cpp:
     101        (WebCore::SVGElement::resolveCustomStyle):
     102        * svg/SVGElement.h:
     103        * svg/SVGElementRareData.h:
     104        (WebCore::SVGElementRareData::overrideComputedStyle):
     105        * testing/Internals.cpp:
     106        (WebCore::Internals::highlightPseudoElementColor):
     107
    11082021-10-22  Sihui Liu  <sihui_liu@apple.com>
    2109
  • trunk/Source/WebCore/animation/AnimationEffect.h

    r284213 r284693  
    4848namespace WebCore {
    4949
     50namespace Style {
     51struct ResolutionContext;
     52}
     53
    5054class AnimationEffect : public RefCounted<AnimationEffect>, public CanMakeWeakPtr<AnimationEffect> {
    5155public:
     
    6266    ExceptionOr<void> updateTiming(std::optional<OptionalEffectTiming>);
    6367
    64     virtual void apply(RenderStyle& targetStyle, const RenderStyle* parentElementStyle, std::optional<Seconds> = std::nullopt) = 0;
     68    virtual void apply(RenderStyle& targetStyle, const Style::ResolutionContext&, std::optional<Seconds> = std::nullopt) = 0;
    6569    virtual void invalidate() = 0;
    6670    virtual void animationDidTick() = 0;
  • trunk/Source/WebCore/animation/CSSAnimation.cpp

    r278540 r284693  
    3737WTF_MAKE_ISO_ALLOCATED_IMPL(CSSAnimation);
    3838
    39 Ref<CSSAnimation> CSSAnimation::create(const Styleable& owningElement, const Animation& backingAnimation, const RenderStyle* oldStyle, const RenderStyle& newStyle, const RenderStyle* parentElementStyle)
     39Ref<CSSAnimation> CSSAnimation::create(const Styleable& owningElement, const Animation& backingAnimation, const RenderStyle* oldStyle, const RenderStyle& newStyle, const Style::ResolutionContext& resolutionContext)
    4040{
    4141    auto result = adoptRef(*new CSSAnimation(owningElement, backingAnimation));
    42     result->initialize(oldStyle, newStyle, parentElementStyle);
     42    result->initialize(oldStyle, newStyle, resolutionContext);
    4343
    4444    InspectorInstrumentation::didCreateWebAnimation(result.get());
  • trunk/Source/WebCore/animation/CSSAnimation.h

    r278253 r284693  
    3939    WTF_MAKE_ISO_ALLOCATED(CSSAnimation);
    4040public:
    41     static Ref<CSSAnimation> create(const Styleable&, const Animation&, const RenderStyle* oldStyle, const RenderStyle& newStyle, const RenderStyle* parentElementStyle);
     41    static Ref<CSSAnimation> create(const Styleable&, const Animation&, const RenderStyle* oldStyle, const RenderStyle& newStyle, const Style::ResolutionContext&);
    4242    ~CSSAnimation() = default;
    4343
  • trunk/Source/WebCore/animation/CSSTransition.cpp

    r278253 r284693  
    4242    ASSERT(oldStyle);
    4343    auto result = adoptRef(*new CSSTransition(owningElement, property, generationTime, backingAnimation, *oldStyle, newStyle, reversingAdjustedStartStyle, reversingShorteningFactor));
    44     result->initialize(oldStyle, newStyle, nullptr);
     44    result->initialize(oldStyle, newStyle, { nullptr });
    4545    result->setTimingProperties(delay, duration);
    4646
     
    6262}
    6363
    64 void CSSTransition::resolve(RenderStyle& targetStyle, const RenderStyle* parentElementStyle, std::optional<Seconds> startTime)
     64void CSSTransition::resolve(RenderStyle& targetStyle, const Style::ResolutionContext& resolutionContext, std::optional<Seconds> startTime)
    6565{
    66     DeclarativeAnimation::resolve(targetStyle, parentElementStyle, startTime);
     66    DeclarativeAnimation::resolve(targetStyle, resolutionContext, startTime);
    6767    m_currentStyle = RenderStyle::clonePtr(targetStyle);
    6868}
  • trunk/Source/WebCore/animation/CSSTransition.h

    r278340 r284693  
    5959    void setTimingProperties(Seconds delay, Seconds duration);
    6060    Ref<AnimationEventBase> createEvent(const AtomString& eventType, double elapsedTime, const String& pseudoId, std::optional<Seconds> timelineTime) final;
    61     void resolve(RenderStyle& targetStyle, const RenderStyle* parentElementStyle, std::optional<Seconds>) final;
     61    void resolve(RenderStyle& targetStyle, const Style::ResolutionContext&, std::optional<Seconds>) final;
    6262
    6363    CSSPropertyID m_property;
  • trunk/Source/WebCore/animation/DeclarativeAnimation.cpp

    r284057 r284693  
    106106}
    107107
    108 void DeclarativeAnimation::initialize(const RenderStyle* oldStyle, const RenderStyle& newStyle, const RenderStyle* parentElementStyle)
     108void DeclarativeAnimation::initialize(const RenderStyle* oldStyle, const RenderStyle& newStyle, const Style::ResolutionContext& resolutionContext)
    109109{
    110110    // We need to suspend invalidation of the animation's keyframe effect during its creation
     
    117117    setEffect(KeyframeEffect::create(*m_owningElement, m_owningPseudoId));
    118118    setTimeline(&m_owningElement->document().timeline());
    119     downcast<KeyframeEffect>(effect())->computeDeclarativeAnimationBlendingKeyframes(oldStyle, newStyle, parentElementStyle);
     119    downcast<KeyframeEffect>(effect())->computeDeclarativeAnimationBlendingKeyframes(oldStyle, newStyle, resolutionContext);
    120120    syncPropertiesWithBackingAnimation();
    121121    if (backingAnimation().playState() == AnimationPlayState::Playing)
  • trunk/Source/WebCore/animation/DeclarativeAnimation.h

    r278253 r284693  
    7676    DeclarativeAnimation(const Styleable&, const Animation&);
    7777
    78     virtual void initialize(const RenderStyle* oldStyle, const RenderStyle& newStyle, const RenderStyle* parentElementStyle);
     78    virtual void initialize(const RenderStyle* oldStyle, const RenderStyle& newStyle, const Style::ResolutionContext&);
    7979    virtual void syncPropertiesWithBackingAnimation();
    8080    // elapsedTime is the animation's current time at the time the event is added and is exposed through the DOM API, timelineTime is the animations'
  • trunk/Source/WebCore/animation/KeyframeEffect.cpp

    r284600 r284693  
    813813}
    814814
    815 void KeyframeEffect::updateBlendingKeyframes(RenderStyle& elementStyle, const RenderStyle* parentElementStyle)
     815void KeyframeEffect::updateBlendingKeyframes(RenderStyle& elementStyle, const Style::ResolutionContext& resolutionContext)
    816816{
    817817    if (!m_blendingKeyframes.isEmpty() || !m_target)
     
    830830
    831831        auto keyframeRule = StyleRuleKeyframe::create(WTFMove(styleProperties));
    832         keyframeValue.setStyle(styleResolver.styleForKeyframe(*m_target, &elementStyle, parentElementStyle, keyframeRule.ptr(), keyframeValue));
     832        keyframeValue.setStyle(styleResolver.styleForKeyframe(*m_target, &elementStyle, resolutionContext, keyframeRule.ptr(), keyframeValue));
    833833        keyframeList.insert(WTFMove(keyframeValue));
    834834    }
     
    10041004}
    10051005
    1006 void KeyframeEffect::computeDeclarativeAnimationBlendingKeyframes(const RenderStyle* oldStyle, const RenderStyle& newStyle, const RenderStyle* parentElementStyle)
     1006void KeyframeEffect::computeDeclarativeAnimationBlendingKeyframes(const RenderStyle* oldStyle, const RenderStyle& newStyle, const Style::ResolutionContext& resolutionContext)
    10071007{
    10081008    ASSERT(is<DeclarativeAnimation>(animation()));
    10091009    if (is<CSSAnimation>(animation()))
    1010         computeCSSAnimationBlendingKeyframes(newStyle, parentElementStyle);
     1010        computeCSSAnimationBlendingKeyframes(newStyle, resolutionContext);
    10111011    else if (is<CSSTransition>(animation()))
    10121012        computeCSSTransitionBlendingKeyframes(oldStyle, newStyle);
    10131013}
    10141014
    1015 void KeyframeEffect::computeCSSAnimationBlendingKeyframes(const RenderStyle& unanimatedStyle, const RenderStyle* parentElementStyle)
     1015void KeyframeEffect::computeCSSAnimationBlendingKeyframes(const RenderStyle& unanimatedStyle, const Style::ResolutionContext& resolutionContext)
    10161016{
    10171017    ASSERT(is<CSSAnimation>(animation()));
     
    10231023    KeyframeList keyframeList(backingAnimation.name().string);
    10241024    if (auto* styleScope = Style::Scope::forOrdinal(*m_target, backingAnimation.nameStyleScopeOrdinal()))
    1025         styleScope->resolver().keyframeStylesForAnimation(*m_target, &unanimatedStyle, parentElementStyle, keyframeList);
     1025        styleScope->resolver().keyframeStylesForAnimation(*m_target, &unanimatedStyle, resolutionContext, keyframeList);
    10261026
    10271027    // Ensure resource loads for all the frames.
     
    12671267}
    12681268
    1269 void KeyframeEffect::apply(RenderStyle& targetStyle, const RenderStyle* parentElementStyle, std::optional<Seconds> startTime)
     1269void KeyframeEffect::apply(RenderStyle& targetStyle, const Style::ResolutionContext& resolutionContext, std::optional<Seconds> startTime)
    12701270{
    12711271    if (!m_target)
    12721272        return;
    12731273
    1274     updateBlendingKeyframes(targetStyle, parentElementStyle);
     1274    updateBlendingKeyframes(targetStyle, resolutionContext);
    12751275
    12761276    auto computedTiming = getComputedTiming(startTime);
     
    14341434    // for a given iteration progress, current iteration and underlying value is calculated as follows.
    14351435
    1436     updateBlendingKeyframes(targetStyle, nullptr);
     1436    updateBlendingKeyframes(targetStyle, { nullptr });
    14371437    if (m_blendingKeyframes.isEmpty())
    14381438        return;
  • trunk/Source/WebCore/animation/KeyframeEffect.h

    r284075 r284693  
    124124
    125125    void getAnimatedStyle(std::unique_ptr<RenderStyle>& animatedStyle);
    126     void apply(RenderStyle& targetStyle, const RenderStyle* parentElementStyle, std::optional<Seconds> = std::nullopt) override;
     126    void apply(RenderStyle& targetStyle, const Style::ResolutionContext&, std::optional<Seconds> = std::nullopt) override;
    127127    void invalidate() override;
    128128    void animationDidTick() final;
     
    155155    bool colorFilterFunctionListsMatch() const override { return m_colorFilterFunctionListsMatch; }
    156156
    157     void computeDeclarativeAnimationBlendingKeyframes(const RenderStyle* oldStyle, const RenderStyle& newStyle, const RenderStyle* parentElementStyle);
     157    void computeDeclarativeAnimationBlendingKeyframes(const RenderStyle* oldStyle, const RenderStyle& newStyle, const Style::ResolutionContext&);
    158158    const KeyframeList& blendingKeyframes() const { return m_blendingKeyframes; }
    159159    const HashSet<CSSPropertyID>& animatedProperties();
     
    199199    void computeSomeKeyframesUseStepsTimingFunction();
    200200    void clearBlendingKeyframes();
    201     void updateBlendingKeyframes(RenderStyle& elementStyle, const RenderStyle* parentElementStyle);
    202     void computeCSSAnimationBlendingKeyframes(const RenderStyle& unanimatedStyle, const RenderStyle* parentElementStyle);
     201    void updateBlendingKeyframes(RenderStyle& elementStyle, const Style::ResolutionContext&);
     202    void computeCSSAnimationBlendingKeyframes(const RenderStyle& unanimatedStyle, const Style::ResolutionContext&);
    203203    void computeCSSTransitionBlendingKeyframes(const RenderStyle* oldStyle, const RenderStyle& newStyle);
    204204    void computeAcceleratedPropertiesState();
  • trunk/Source/WebCore/animation/KeyframeEffectStack.cpp

    r284516 r284693  
    122122}
    123123
    124 OptionSet<AnimationImpact> KeyframeEffectStack::applyKeyframeEffects(RenderStyle& targetStyle, const RenderStyle& previousLastStyleChangeEventStyle, const RenderStyle* parentElementStyle)
     124OptionSet<AnimationImpact> KeyframeEffectStack::applyKeyframeEffects(RenderStyle& targetStyle, const RenderStyle& previousLastStyleChangeEventStyle, const Style::ResolutionContext& resolutionContext)
    125125{
    126126    OptionSet<AnimationImpact> impact;
     
    135135    for (const auto& effect : sortedEffects()) {
    136136        ASSERT(effect->animation());
    137         effect->animation()->resolve(targetStyle, parentElementStyle);
     137        effect->animation()->resolve(targetStyle, resolutionContext);
    138138
    139139        if (effect->isRunningAccelerated() || effect->isAboutToRunAccelerated())
  • trunk/Source/WebCore/animation/KeyframeEffectStack.h

    r272904 r284693  
    3737class RenderStyle;
    3838
     39namespace Style {
     40struct ResolutionContext;
     41}
     42
    3943class KeyframeEffectStack {
    4044    WTF_MAKE_FAST_ALLOCATED;
     
    5155    bool isCurrentlyAffectingProperty(CSSPropertyID) const;
    5256    bool requiresPseudoElement() const;
    53     OptionSet<AnimationImpact> applyKeyframeEffects(RenderStyle& targetStyle, const RenderStyle& previousLastStyleChangeEventStyle, const RenderStyle* parentElementStyle);
     57    OptionSet<AnimationImpact> applyKeyframeEffects(RenderStyle& targetStyle, const RenderStyle& previousLastStyleChangeEventStyle, const Style::ResolutionContext&);
    5458    bool hasEffectWithImplicitKeyframes() const;
    5559
  • trunk/Source/WebCore/animation/WebAnimation.cpp

    r282784 r284693  
    12281228}
    12291229
    1230 void WebAnimation::resolve(RenderStyle& targetStyle, const RenderStyle* parentElementStyle, std::optional<Seconds> startTime)
     1230void WebAnimation::resolve(RenderStyle& targetStyle, const Style::ResolutionContext& resolutionContext, std::optional<Seconds> startTime)
    12311231{
    12321232    if (!m_shouldSkipUpdatingFinishedStateWhenResolving)
     
    12351235
    12361236    if (m_effect)
    1237         m_effect->apply(targetStyle, parentElementStyle, startTime);
     1237        m_effect->apply(targetStyle, resolutionContext, startTime);
    12381238}
    12391239
     
    14271427                break;
    14281428            if (effectInStack->animatedProperties().contains(property))
    1429                 effectInStack->animation()->resolve(*animatedStyle, nullptr);
     1429                effectInStack->animation()->resolve(*animatedStyle, { nullptr });
    14301430            if (effectInStack->animation() == this)
    14311431                break;
    14321432        }
    14331433        if (m_replaceState == ReplaceState::Removed)
    1434             effect->animation()->resolve(*animatedStyle, nullptr);
     1434            effect->animation()->resolve(*animatedStyle, { nullptr });
    14351435        if (auto cssValue = computedStyleExtractor.valueForPropertyInStyle(*animatedStyle, property, renderer))
    14361436            inlineStyle->setPropertyInternal(property, cssValue->cssText(), false);
  • trunk/Source/WebCore/animation/WebAnimation.h

    r278340 r284693  
    4949template<typename IDLType> class DOMPromiseProxyWithResolveCallback;
    5050
     51namespace Style {
     52struct ResolutionContext;
     53}
     54
    5155class WebAnimation : public RefCounted<WebAnimation>, public EventTargetWithInlineData, public ActiveDOMObject {
    5256    WTF_MAKE_ISO_ALLOCATED(WebAnimation);
     
    120124    virtual void tick();
    121125    WEBCORE_EXPORT Seconds timeToNextTick() const;
    122     virtual void resolve(RenderStyle& targetStyle, const RenderStyle* parentElementStyle, std::optional<Seconds> = std::nullopt);
     126    virtual void resolve(RenderStyle& targetStyle, const Style::ResolutionContext&, std::optional<Seconds> = std::nullopt);
    123127    void effectTargetDidChange(const std::optional<const Styleable>& previousTarget, const std::optional<const Styleable>& newTarget);
    124128    void acceleratedStateDidChange();
  • trunk/Source/WebCore/css/MediaQueryMatcher.cpp

    r284057 r284693  
    7373        return nullptr;
    7474
    75     return m_document->styleScope().resolver().styleForElement(*documentElement, m_document->renderStyle(), nullptr, RuleMatchingBehavior::MatchOnlyUserAgentRules).renderStyle;
     75    return m_document->styleScope().resolver().styleForElement(*documentElement, { m_document->renderStyle() }, RuleMatchingBehavior::MatchOnlyUserAgentRules).renderStyle;
    7676}
    7777
  • trunk/Source/WebCore/css/StyleMedia.cpp

    r236917 r284693  
    6767        return false;
    6868
    69     auto rootStyle = document->styleScope().resolver().styleForElement(*documentElement, document->renderStyle(), nullptr, RuleMatchingBehavior::MatchOnlyUserAgentRules).renderStyle;
     69    auto rootStyle = document->styleScope().resolver().styleForElement(*documentElement, { document->renderStyle() }, RuleMatchingBehavior::MatchOnlyUserAgentRules).renderStyle;
    7070
    7171    auto media = MediaQuerySet::create(query, MediaQueryParserContext(*document));
  • trunk/Source/WebCore/dom/Document.cpp

    r284528 r284693  
    22632263
    22642264    if (pseudoElementSpecifier != PseudoId::None)
    2265         return resolver.pseudoStyleForElement(element, { pseudoElementSpecifier }, *parentStyle);
    2266 
    2267     auto elementStyle = resolver.styleForElement(element, parentStyle);
     2265        return resolver.pseudoStyleForElement(element, { pseudoElementSpecifier }, { parentStyle });
     2266
     2267    auto elementStyle = resolver.styleForElement(element, { parentStyle });
    22682268    if (elementStyle.relations) {
    22692269        Style::Update emptyUpdate(*this);
  • trunk/Source/WebCore/dom/Element.cpp

    r284142 r284693  
    19751975}
    19761976
    1977 Style::ElementStyle Element::resolveStyle(const RenderStyle* parentStyle)
    1978 {
    1979     return styleResolver().styleForElement(*this, parentStyle);
     1977Style::ElementStyle Element::resolveStyle(const Style::ResolutionContext& resolutionContext)
     1978{
     1979    return styleResolver().styleForElement(*this, resolutionContext);
    19801980}
    19811981
     
    44104410}
    44114411
    4412 std::optional<Style::ElementStyle> Element::resolveCustomStyle(const RenderStyle&, const RenderStyle*)
     4412std::optional<Style::ElementStyle> Element::resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle*)
    44134413{
    44144414    ASSERT(hasCustomStyleResolveCallbacks());
  • trunk/Source/WebCore/dom/Element.h

    r284075 r284693  
    9595enum class Change : uint8_t;
    9696struct ElementStyle;
     97struct ResolutionContext;
    9798}
    9899
     
    572573    virtual void willDetachRenderers();
    573574    virtual void didDetachRenderers();
    574     virtual std::optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle);
     575    virtual std::optional<Style::ElementStyle> resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* shadowHostStyle);
    575576
    576577    LayoutRect absoluteEventHandlerBounds(bool& includesFixedPositionElements) override;
     
    594595
    595596    Style::Resolver& styleResolver();
    596     Style::ElementStyle resolveStyle(const RenderStyle* parentStyle);
     597    Style::ElementStyle resolveStyle(const Style::ResolutionContext&);
    597598
    598599    // Invalidates the style of a single element. Style is resolved lazily.
  • trunk/Source/WebCore/html/HTMLTitleElement.cpp

    r234808 r284693  
    8585        direction = computedStyle->direction();
    8686    else
    87         direction = styleResolver().styleForElement(*this, parentElement() ? parentElement()->renderStyle() : nullptr).renderStyle->direction();
     87        direction = styleResolver().styleForElement(*this, { parentElement() ? parentElement()->renderStyle() : nullptr }).renderStyle->direction();
    8888    return { text(), direction };
    8989}
  • trunk/Source/WebCore/html/shadow/DateTimeFieldElement.cpp

    r284093 r284693  
    6464}
    6565
    66 std::optional<Style::ElementStyle> DateTimeFieldElement::resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle)
    67 {
    68     auto elementStyle = resolveStyle(&parentStyle);
     66std::optional<Style::ElementStyle> DateTimeFieldElement::resolveCustomStyle(const Style::ResolutionContext& resolutionContext, const RenderStyle* shadowHostStyle)
     67{
     68    auto elementStyle = resolveStyle(resolutionContext);
    6969    if (!elementStyle.renderStyle)
    7070        return std::nullopt;
  • trunk/Source/WebCore/html/shadow/DateTimeFieldElement.h

    r278253 r284693  
    8686
    8787private:
    88     std::optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle&, const RenderStyle*) final;
     88    std::optional<Style::ElementStyle> resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle*) final;
    8989
    9090    bool supportsFocus() const override;
  • trunk/Source/WebCore/html/shadow/SliderThumbElement.cpp

    r283757 r284693  
    587587}
    588588
    589 std::optional<Style::ElementStyle> SliderThumbElement::resolveCustomStyle(const RenderStyle&, const RenderStyle* hostStyle)
     589std::optional<Style::ElementStyle> SliderThumbElement::resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* hostStyle)
    590590{
    591591    // This doesn't actually compute style. This is just a hack to pick shadow pseudo id when host style is known.
     
    638638}
    639639
    640 std::optional<Style::ElementStyle> SliderContainerElement::resolveCustomStyle(const RenderStyle&, const RenderStyle* hostStyle)
     640std::optional<Style::ElementStyle> SliderContainerElement::resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* hostStyle)
    641641{
    642642    // This doesn't actually compute style. This is just a hack to pick shadow pseudo id when host style is known.
  • trunk/Source/WebCore/html/shadow/SliderThumbElement.h

    r278253 r284693  
    7676    void willDetachRenderers() final;
    7777
    78     std::optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle&, const RenderStyle*) final;
     78    std::optional<Style::ElementStyle> resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle*) final;
    7979    const AtomString& shadowPseudoId() const final;
    8080
     
    135135    SliderContainerElement(Document&);
    136136    RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
    137     std::optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle&, const RenderStyle*) final;
     137    std::optional<Style::ElementStyle> resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle*) final;
    138138    const AtomString& shadowPseudoId() const final;
    139139    bool isSliderContainerElement() const final { return true; }
  • trunk/Source/WebCore/html/shadow/TextControlInnerElements.cpp

    r283757 r284693  
    8383}
    8484
    85 std::optional<Style::ElementStyle> TextControlInnerContainer::resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle*)
    86 {
    87     auto elementStyle = resolveStyle(&parentStyle);
     85std::optional<Style::ElementStyle> TextControlInnerContainer::resolveCustomStyle(const Style::ResolutionContext& resolutionContext, const RenderStyle*)
     86{
     87    auto elementStyle = resolveStyle(resolutionContext);
    8888    if (isStrongPasswordTextField(shadowHost())) {
    8989        elementStyle.renderStyle->setFlexWrap(FlexWrap::Wrap);
     
    105105}
    106106
    107 std::optional<Style::ElementStyle> TextControlInnerElement::resolveCustomStyle(const RenderStyle&, const RenderStyle* shadowHostStyle)
     107std::optional<Style::ElementStyle> TextControlInnerElement::resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* shadowHostStyle)
    108108{
    109109    auto newStyle = RenderStyle::createPtr();
     
    189189}
    190190
    191 std::optional<Style::ElementStyle> TextControlInnerTextElement::resolveCustomStyle(const RenderStyle&, const RenderStyle* shadowHostStyle)
     191std::optional<Style::ElementStyle> TextControlInnerTextElement::resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* shadowHostStyle)
    192192{
    193193    auto style = downcast<HTMLTextFormControlElement>(*shadowHost()).createInnerTextStyle(*shadowHostStyle);
     
    210210}
    211211
    212 std::optional<Style::ElementStyle> TextControlPlaceholderElement::resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle)
    213 {
    214     auto style = resolveStyle(&parentStyle);
     212std::optional<Style::ElementStyle> TextControlPlaceholderElement::resolveCustomStyle(const Style::ResolutionContext& resolutionContext, const RenderStyle* shadowHostStyle)
     213{
     214    auto style = resolveStyle(resolutionContext);
    215215
    216216    auto& controlElement = downcast<HTMLTextFormControlElement>(*containingShadowRoot()->host());
     
    240240}
    241241
    242 std::optional<Style::ElementStyle> SearchFieldResultsButtonElement::resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle)
     242std::optional<Style::ElementStyle> SearchFieldResultsButtonElement::resolveCustomStyle(const Style::ResolutionContext& resolutionContext, const RenderStyle* shadowHostStyle)
    243243{
    244244    RefPtr input = downcast<HTMLInputElement>(shadowHost());
     
    248248    if (shadowHostStyle && shadowHostStyle->effectiveAppearance() != SearchFieldPart) {
    249249        SetForScope<bool> canAdjustStyleForAppearance(m_canAdjustStyleForAppearance, false);
    250         return resolveStyle(&parentStyle);
     250        return resolveStyle(resolutionContext);
    251251    }
    252252
     
    307307}
    308308
    309 std::optional<Style::ElementStyle> SearchFieldCancelButtonElement::resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle*)
    310 {
    311     auto elementStyle = resolveStyle(&parentStyle);
     309std::optional<Style::ElementStyle> SearchFieldCancelButtonElement::resolveCustomStyle(const Style::ResolutionContext& resolutionContext, const RenderStyle*)
     310{
     311    auto elementStyle = resolveStyle(resolutionContext);
    312312    auto& inputElement = downcast<HTMLInputElement>(*shadowHost());
    313313    elementStyle.renderStyle->setVisibility(elementStyle.renderStyle->visibility() == Visibility::Hidden || inputElement.value().isEmpty() ? Visibility::Hidden : Visibility::Visible);
  • trunk/Source/WebCore/html/shadow/TextControlInnerElements.h

    r278253 r284693  
    4141    TextControlInnerContainer(Document&);
    4242    RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
    43     std::optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle) override;
     43    std::optional<Style::ElementStyle> resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* shadowHostStyle) override;
    4444};
    4545
     
    5151private:
    5252    TextControlInnerElement(Document&);
    53     std::optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle) override;
     53    std::optional<Style::ElementStyle> resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* shadowHostStyle) override;
    5454
    5555    bool isMouseFocusable() const override { return false; }
     
    7676    TextControlInnerTextElement(Document&);
    7777    RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
    78     std::optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle) override;
     78    std::optional<Style::ElementStyle> resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* shadowHostStyle) override;
    7979    bool isMouseFocusable() const override { return false; }
    8080    bool isTextControlInnerTextElement() const override { return true; }
     
    8989    TextControlPlaceholderElement(Document&);
    9090   
    91     std::optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle) override;
     91    std::optional<Style::ElementStyle> resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* shadowHostStyle) override;
    9292};
    9393
     
    107107    SearchFieldResultsButtonElement(Document&);
    108108    bool isMouseFocusable() const override { return false; }
    109     std::optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle) override;
     109    std::optional<Style::ElementStyle> resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* shadowHostStyle) override;
    110110    bool isSearchFieldResultsButtonElement() const override { return true; }
    111111
     
    126126    SearchFieldCancelButtonElement(Document&);
    127127    bool isMouseFocusable() const override { return false; }
    128     std::optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle) override;
     128    std::optional<Style::ElementStyle> resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* shadowHostStyle) override;
    129129};
    130130
  • trunk/Source/WebCore/rendering/RenderElement.cpp

    r284366 r284693  
    256256            return nullptr;
    257257
    258         auto style = composedTreeParentElement->styleResolver().styleForElement(*composedTreeParentElement, &parentStyle).renderStyle;
     258        auto style = composedTreeParentElement->styleResolver().styleForElement(*composedTreeParentElement, { &parentStyle }).renderStyle;
    259259        ASSERT(style->display() == DisplayType::Contents);
    260260
     
    265265    }
    266266
    267     return rendererForFirstLineStyle.element()->styleResolver().styleForElement(*element(), &parentStyle).renderStyle;
     267    return rendererForFirstLineStyle.element()->styleResolver().styleForElement(*element(), { &parentStyle }).renderStyle;
    268268}
    269269
     
    15321532    auto& styleResolver = element()->styleResolver();
    15331533
    1534     std::unique_ptr<RenderStyle> style = styleResolver.pseudoStyleForElement(*element(), pseudoElementRequest, *parentStyle);
     1534    std::unique_ptr<RenderStyle> style = styleResolver.pseudoStyleForElement(*element(), pseudoElementRequest, { parentStyle });
    15351535
    15361536    if (style)
  • trunk/Source/WebCore/rendering/style/KeyframeList.cpp

    r272898 r284693  
    120120    if (initialSize > 0 && m_keyframes[0].key()) {
    121121        KeyframeValue keyframeValue(0, nullptr);
    122         keyframeValue.setStyle(styleResolver.styleForKeyframe(element, elementStyle, parentElementStyle, &zeroPercentKeyframe(), keyframeValue));
     122        keyframeValue.setStyle(styleResolver.styleForKeyframe(element, elementStyle, { parentElementStyle }, &zeroPercentKeyframe(), keyframeValue));
    123123        insert(WTFMove(keyframeValue));
    124124    }
     
    127127    if (initialSize > 0 && (m_keyframes[size() - 1].key() != 1)) {
    128128        KeyframeValue keyframeValue(1, nullptr);
    129         keyframeValue.setStyle(styleResolver.styleForKeyframe(element, elementStyle, parentElementStyle, &hundredPercentKeyframe(), keyframeValue));
     129        keyframeValue.setStyle(styleResolver.styleForKeyframe(element, elementStyle, { parentElementStyle }, &hundredPercentKeyframe(), keyframeValue));
    130130        insert(WTFMove(keyframeValue));
    131131    }
  • trunk/Source/WebCore/style/StyleResolver.cpp

    r284672 r284693  
    160160
    161161    if (auto* documentElement = m_document.documentElement()) {
    162         m_rootDefaultStyle = styleForElement(*documentElement, m_document.renderStyle(), nullptr, RuleMatchingBehavior::MatchOnlyUserAgentRules).renderStyle;
     162        m_rootDefaultStyle = styleForElement(*documentElement, { m_document.renderStyle() }, RuleMatchingBehavior::MatchOnlyUserAgentRules).renderStyle;
    163163        // Turn off assertion against font lookups during style resolver initialization. We may need root style font for media queries.
    164164        m_document.fontSelector().incrementIsComputingRootStyleFont();
     
    219219}
    220220
    221 ElementStyle Resolver::styleForElement(const Element& element, const RenderStyle* parentStyle, const RenderStyle* parentBoxStyle, RuleMatchingBehavior matchingBehavior, const SelectorFilter* selectorFilter)
    222 {
    223     auto state = State(element, parentStyle, m_overrideDocumentElementStyle);
     221ElementStyle Resolver::styleForElement(const Element& element, const ResolutionContext& context, RuleMatchingBehavior matchingBehavior)
     222{
     223    auto state = State(element, context.parentStyle, context.documentElementStyle);
    224224
    225225    if (state.parentStyle()) {
     
    246246    UserAgentStyle::ensureDefaultStyleSheetsForElement(element);
    247247
    248     ElementRuleCollector collector(element, m_ruleSets, selectorFilter);
     248    ElementRuleCollector collector(element, m_ruleSets, context.selectorFilter);
    249249    collector.setMedium(&m_mediaQueryEvaluator);
    250250
     
    265265    applyMatchedProperties(state, collector.matchResult());
    266266
    267     Adjuster adjuster(document(), *state.parentStyle(), parentBoxStyle, &element);
     267    Adjuster adjuster(document(), *state.parentStyle(), context.parentBoxStyle, &element);
    268268    adjuster.adjust(*state.style(), state.userAgentAppearanceStyle());
    269269
     
    274274}
    275275
    276 std::unique_ptr<RenderStyle> Resolver::styleForKeyframe(const Element& element, const RenderStyle* elementStyle, const RenderStyle* parentElementStyle, const StyleRuleKeyframe* keyframe, KeyframeValue& keyframeValue)
     276std::unique_ptr<RenderStyle> Resolver::styleForKeyframe(const Element& element, const RenderStyle* elementStyle, const ResolutionContext& context, const StyleRuleKeyframe* keyframe, KeyframeValue& keyframeValue)
    277277{
    278278    MatchResult result;
    279279    result.authorDeclarations.append({ &keyframe->properties(), SelectorChecker::MatchAll, propertyAllowlistForPseudoId(elementStyle->styleType()) });
    280280
    281     auto state = State(element, nullptr, m_overrideDocumentElementStyle);
     281    auto state = State(element, nullptr, context.documentElementStyle);
    282282
    283283    state.setStyle(RenderStyle::clonePtr(*elementStyle));
    284     state.setParentStyle(RenderStyle::clonePtr(parentElementStyle ? *parentElementStyle : *elementStyle));
     284    state.setParentStyle(RenderStyle::clonePtr(context.parentStyle ? *context.parentStyle : *elementStyle));
    285285
    286286    Builder builder(*state.style(), builderContext(state), result, { CascadeLevel::Author });
     
    308308}
    309309
    310 void Resolver::keyframeStylesForAnimation(const Element& element, const RenderStyle* elementStyle, const RenderStyle* parentElementStyle, KeyframeList& list)
     310void Resolver::keyframeStylesForAnimation(const Element& element, const RenderStyle* elementStyle, const ResolutionContext& context, KeyframeList& list)
    311311{
    312312    list.clear();
     
    370370        for (auto key : keyframe->keys()) {
    371371            KeyframeValue keyframeValue(0, nullptr);
    372             keyframeValue.setStyle(styleForKeyframe(element, elementStyle, parentElementStyle, keyframe.ptr(), keyframeValue));
     372            keyframeValue.setStyle(styleForKeyframe(element, elementStyle, context, keyframe.ptr(), keyframeValue));
    373373            keyframeValue.setKey(key);
    374374            if (auto timingFunctionCSSValue = keyframe->properties().getPropertyCSSValue(CSSPropertyAnimationTimingFunction))
     
    378378    }
    379379
    380     list.fillImplicitKeyframes(element, *this, elementStyle, parentElementStyle);
    381 }
    382 
    383 std::unique_ptr<RenderStyle> Resolver::pseudoStyleForElement(const Element& element, const PseudoElementRequest& pseudoElementRequest, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const SelectorFilter* selectorFilter)
    384 {
    385     auto state = State(element, &parentStyle, m_overrideDocumentElementStyle);
     380    list.fillImplicitKeyframes(element, *this, elementStyle, context.parentStyle);
     381}
     382
     383std::unique_ptr<RenderStyle> Resolver::pseudoStyleForElement(const Element& element, const PseudoElementRequest& pseudoElementRequest, const ResolutionContext& context)
     384{
     385    auto state = State(element, context.parentStyle, context.documentElementStyle);
    386386
    387387    if (state.parentStyle()) {
     
    393393    }
    394394
    395     ElementRuleCollector collector(element, m_ruleSets, selectorFilter);
     395    ElementRuleCollector collector(element, m_ruleSets, context.selectorFilter);
    396396    collector.setPseudoElementRequest(pseudoElementRequest);
    397397    collector.setMedium(&m_mediaQueryEvaluator);
     
    412412    applyMatchedProperties(state, collector.matchResult());
    413413
    414     Adjuster adjuster(document(), *state.parentStyle(), parentBoxStyle, nullptr);
     414    Adjuster adjuster(document(), *state.parentStyle(), context.parentBoxStyle, nullptr);
    415415    adjuster.adjust(*state.style(), state.userAgentAppearanceStyle());
    416416
  • trunk/Source/WebCore/style/StyleResolver.h

    r284672 r284693  
    8181};
    8282
     83struct ResolutionContext {
     84    const RenderStyle* parentStyle;
     85    const RenderStyle* parentBoxStyle { nullptr };
     86    // This needs to be provided during style resolution when up-to-date document element style is not available via DOM.
     87    const RenderStyle* documentElementStyle { nullptr };
     88    const SelectorFilter* selectorFilter { nullptr };
     89};
     90
    8391class Resolver : public RefCounted<Resolver> {
    8492    WTF_MAKE_ISO_ALLOCATED(Resolver);
     
    8795    ~Resolver();
    8896
    89     ElementStyle styleForElement(const Element&, const RenderStyle* parentStyle, const RenderStyle* parentBoxStyle = nullptr, RuleMatchingBehavior = RuleMatchingBehavior::MatchAllRules, const SelectorFilter* = nullptr);
     97    ElementStyle styleForElement(const Element&, const ResolutionContext&, RuleMatchingBehavior = RuleMatchingBehavior::MatchAllRules);
    9098
    91     void keyframeStylesForAnimation(const Element&, const RenderStyle* elementStyle, const RenderStyle* parentElementStyle, KeyframeList&);
     99    void keyframeStylesForAnimation(const Element&, const RenderStyle* elementStyle, const ResolutionContext&, KeyframeList&);
    92100
    93     WEBCORE_EXPORT std::unique_ptr<RenderStyle> pseudoStyleForElement(const Element&, const PseudoElementRequest&, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle = nullptr, const SelectorFilter* = nullptr);
     101    WEBCORE_EXPORT std::unique_ptr<RenderStyle> pseudoStyleForElement(const Element&, const PseudoElementRequest&, const ResolutionContext&);
    94102
    95103    std::unique_ptr<RenderStyle> styleForPage(int pageIndex);
     
    107115    const MediaQueryEvaluator& mediaQueryEvaluator() const { return m_mediaQueryEvaluator; }
    108116
    109     const RenderStyle* overrideDocumentElementStyle() const { return m_overrideDocumentElementStyle; }
    110     void setOverrideDocumentElementStyle(const RenderStyle* style) { m_overrideDocumentElementStyle = style; }
    111 
    112117    void addCurrentSVGFontFaceRules();
    113118
    114     std::unique_ptr<RenderStyle> styleForKeyframe(const Element&, const RenderStyle* elementStyle, const RenderStyle* parentElementStyle, const StyleRuleKeyframe*, KeyframeValue&);
     119    std::unique_ptr<RenderStyle> styleForKeyframe(const Element&, const RenderStyle* elementStyle, const ResolutionContext&, const StyleRuleKeyframe*, KeyframeValue&);
    115120    bool isAnimationNameValid(const String&);
    116121
     
    165170    Document& m_document;
    166171
    167     const RenderStyle* m_overrideDocumentElementStyle { nullptr };
    168 
    169172    InspectorCSSOMWrappers m_inspectorCSSOMWrappers;
    170173
  • trunk/Source/WebCore/style/StyleTreeResolver.cpp

    r283269 r284693  
    8989    , enclosingScope(&enclosingScope)
    9090{
    91     resolver->setOverrideDocumentElementStyle(enclosingScope.resolver->overrideDocumentElementStyle());
    9291}
    9392
     
    9695    if (!shadowRoot)
    9796        resolver->document().setIsResolvingTreeStyle(false);
    98 
    99     resolver->setOverrideDocumentElementStyle(nullptr);
    10097}
    10198
     
    130127}
    131128
    132 std::unique_ptr<RenderStyle> TreeResolver::styleForStyleable(const Styleable& styleable, const RenderStyle& inheritedStyle)
     129std::unique_ptr<RenderStyle> TreeResolver::styleForStyleable(const Styleable& styleable, const ResolutionContext& resolutionContext)
    133130{
    134131    auto& element = styleable.element;
     
    136133    if (element.hasCustomStyleResolveCallbacks()) {
    137134        RenderStyle* shadowHostStyle = scope().shadowRoot ? m_update->elementStyle(*scope().shadowRoot->host()) : nullptr;
    138         if (auto customStyle = element.resolveCustomStyle(inheritedStyle, shadowHostStyle)) {
     135        if (auto customStyle = element.resolveCustomStyle(resolutionContext, shadowHostStyle)) {
    139136            if (customStyle->relations)
    140137                commitRelations(WTFMove(customStyle->relations), *m_update);
     
    147144        return style;
    148145
    149     auto elementStyle = scope().resolver->styleForElement(element, &inheritedStyle, parentBoxStyle(), RuleMatchingBehavior::MatchAllRules, &scope().selectorFilter);
     146    auto elementStyle = scope().resolver->styleForElement(element, resolutionContext);
    150147
    151148    if (elementStyle.relations)
     
    211208        return { };
    212209
     210    auto resolutionContext = makeResolutionContext();
     211
    213212    Styleable styleable { element, PseudoId::None };
    214     auto newStyle = styleForStyleable(styleable, parent().style);
     213    auto newStyle = styleForStyleable(styleable, resolutionContext);
    215214
    216215    if (!affectsRenderedSubtree(element, *newStyle))
     
    224223    }
    225224
    226     auto update = createAnimatedElementUpdate(WTFMove(newStyle), styleable, parent().change, parent().style, parentBoxStyle());
     225    auto update = createAnimatedElementUpdate(WTFMove(newStyle), styleable, parent().change, resolutionContext);
    227226    auto descendantsToResolve = computeDescendantsToResolve(update.change, element.styleValidity(), parent().descendantsToResolve);
    228227
    229228    if (&element == m_document.documentElement()) {
    230229        m_documentElementStyle = RenderStyle::clonePtr(*update.style);
    231         scope().resolver->setOverrideDocumentElementStyle(m_documentElementStyle.get());
    232230
    233231        if (!existingStyle || existingStyle->computedFontPixelSize() != update.style->computedFontPixelSize()) {
     
    287285        return { };
    288286
    289     auto& parentStyle = *elementUpdate.style;
    290     auto* parentBoxStyle = parentBoxStyleForPseudo(elementUpdate);
    291 
    292     auto pseudoStyle = scope().resolver->pseudoStyleForElement(element, { pseudoId }, parentStyle, parentBoxStyle, &scope().selectorFilter);
     287    auto resolutionContext = makeResolutionContextForPseudoElement(elementUpdate);
     288
     289    auto pseudoStyle = scope().resolver->pseudoStyleForElement(element, { pseudoId }, resolutionContext);
    293290    if (!pseudoStyle)
    294291        return { };
     
    298295        return { };
    299296
    300     return createAnimatedElementUpdate(WTFMove(pseudoStyle), { element, pseudoId }, elementUpdate.change, parentStyle, parentBoxStyle);
     297    return createAnimatedElementUpdate(WTFMove(pseudoStyle), { element, pseudoId }, elementUpdate.change, resolutionContext);
     298}
     299
     300ResolutionContext TreeResolver::makeResolutionContext()
     301{
     302    return {
     303        &parent().style,
     304        parentBoxStyle(),
     305        m_documentElementStyle.get(),
     306        &scope().selectorFilter
     307    };
     308}
     309
     310ResolutionContext TreeResolver::makeResolutionContextForPseudoElement(const ElementUpdate& elementUpdate)
     311{
     312    return {
     313        elementUpdate.style.get(),
     314        parentBoxStyleForPseudoElement(elementUpdate),
     315        m_documentElementStyle.get(),
     316        &scope().selectorFilter
     317    };
    301318}
    302319
     
    315332}
    316333
    317 const RenderStyle* TreeResolver::parentBoxStyleForPseudo(const ElementUpdate& elementUpdate) const
     334const RenderStyle* TreeResolver::parentBoxStyleForPseudoElement(const ElementUpdate& elementUpdate) const
    318335{
    319336    switch (elementUpdate.style->display()) {
     
    327344}
    328345
    329 ElementUpdate TreeResolver::createAnimatedElementUpdate(std::unique_ptr<RenderStyle> newStyle, const Styleable& styleable, Change parentChange, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle)
     346ElementUpdate TreeResolver::createAnimatedElementUpdate(std::unique_ptr<RenderStyle> newStyle, const Styleable& styleable, Change parentChange, const ResolutionContext& resolutionContext)
    330347{
    331348    auto& element = styleable.element;
     
    346363        // such that when CSS Transitions are updated the CSS Animations data is the same as during the previous style change event.
    347364        if ((oldStyle && oldStyle->hasAnimations()) || newStyle->hasAnimations())
    348             styleable.updateCSSAnimations(oldStyle, *newStyle, &parentStyle);
     365            styleable.updateCSSAnimations(oldStyle, *newStyle, resolutionContext);
    349366    }
    350367
     
    357374        // Apply all keyframe effects to the new style.
    358375        auto animatedStyle = RenderStyle::clonePtr(*newStyle);
    359         animationImpact = styleable.applyKeyframeEffects(*animatedStyle, *previousLastStyleChangeEventStyle, &parentStyle);
     376        animationImpact = styleable.applyKeyframeEffects(*animatedStyle, *previousLastStyleChangeEventStyle, resolutionContext);
    360377        newStyle = WTFMove(animatedStyle);
    361378
    362         Adjuster adjuster(document, parentStyle, parentBoxStyle, styleable.pseudoId == PseudoId::None ? &element : nullptr);
     379        Adjuster adjuster(document, *resolutionContext.parentStyle, resolutionContext.parentBoxStyle, styleable.pseudoId == PseudoId::None ? &element : nullptr);
    363380        adjuster.adjustAnimatedStyle(*newStyle, animationImpact);
    364381    } else
  • trunk/Source/WebCore/style/StyleTreeResolver.h

    r283134 r284693  
    4646
    4747class Resolver;
     48struct ResolutionContext;
    4849
    4950DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(TreeResolverScope);
     
    5657
    5758private:
    58     std::unique_ptr<RenderStyle> styleForStyleable(const Styleable&, const RenderStyle& inheritedStyle);
     59    std::unique_ptr<RenderStyle> styleForStyleable(const Styleable&, const ResolutionContext&);
    5960
    6061    void resolveComposedTree();
     
    6263    ElementUpdates resolveElement(Element&);
    6364
    64     static ElementUpdate createAnimatedElementUpdate(std::unique_ptr<RenderStyle>, const Styleable&, Change, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle);
     65    static ElementUpdate createAnimatedElementUpdate(std::unique_ptr<RenderStyle>, const Styleable&, Change, const ResolutionContext&);
    6566    std::optional<ElementUpdate> resolvePseudoStyle(Element&, const ElementUpdate&, PseudoId);
    6667
     
    100101    void popParentsToDepth(unsigned depth);
    101102
     103    ResolutionContext makeResolutionContext();
     104    ResolutionContext makeResolutionContextForPseudoElement(const ElementUpdate&);
    102105    const RenderStyle* parentBoxStyle() const;
    103     const RenderStyle* parentBoxStyleForPseudo(const ElementUpdate&) const;
     106    const RenderStyle* parentBoxStyleForPseudoElement(const ElementUpdate&) const;
    104107
    105108    Document& m_document;
  • trunk/Source/WebCore/style/Styleable.cpp

    r284313 r284693  
    212212}
    213213
    214 void Styleable::updateCSSAnimations(const RenderStyle* currentStyle, const RenderStyle& newStyle, const RenderStyle* parentElementStyle) const
     214void Styleable::updateCSSAnimations(const RenderStyle* currentStyle, const RenderStyle& newStyle, const Style::ResolutionContext& resolutionContext) const
    215215{
    216216    auto& keyframeEffectStack = ensureKeyframeEffectStack();
     
    262262
    263263            if (!foundMatchingAnimation)
    264                 newAnimations.add(CSSAnimation::create(*this, currentAnimation, currentStyle, newStyle, parentElementStyle));
     264                newAnimations.add(CSSAnimation::create(*this, currentAnimation, currentStyle, newStyle, resolutionContext));
    265265        }
    266266    }
     
    389389            // as its start time to ensure that it will produce a style with progress > 0.
    390390            bool shouldUseTimelineTimeAtCreation = is<CSSTransition>(animation) && (!animation->startTime() || *animation->startTime() == styleable.element.document().timeline().currentTime());
    391             animation->resolve(animatedStyle, nullptr, shouldUseTimelineTimeAtCreation ? downcast<CSSTransition>(*animation).timelineTimeAtCreation() : std::nullopt);
     391            animation->resolve(animatedStyle, { nullptr }, shouldUseTimelineTimeAtCreation ? downcast<CSSTransition>(*animation).timelineTimeAtCreation() : std::nullopt);
    392392            return animatedStyle;
    393393        }
     
    409409        if (is<CSSAnimation>(animation) && animation->isRelevant()) {
    410410            auto animatedStyle = RenderStyle::clone(newStyle);
    411             animation->resolve(animatedStyle, nullptr);
     411            animation->resolve(animatedStyle, { nullptr });
    412412            return animatedStyle;
    413413        }
  • trunk/Source/WebCore/style/Styleable.h

    r284313 r284693  
    8686    }
    8787
    88     OptionSet<AnimationImpact> applyKeyframeEffects(RenderStyle& targetStyle, const RenderStyle& previousLastStyleChangeEventStyle, const RenderStyle* parentElementStyle) const
     88    OptionSet<AnimationImpact> applyKeyframeEffects(RenderStyle& targetStyle, const RenderStyle& previousLastStyleChangeEventStyle, const Style::ResolutionContext& resolutionContext) const
    8989    {
    90         return element.ensureKeyframeEffectStack(pseudoId).applyKeyframeEffects(targetStyle, previousLastStyleChangeEventStyle, parentElementStyle);
     90        return element.ensureKeyframeEffectStack(pseudoId).applyKeyframeEffects(targetStyle, previousLastStyleChangeEventStyle, resolutionContext);
    9191    }
    9292
     
    156156    void removeDeclarativeAnimationFromListsForOwningElement(WebAnimation&) const;
    157157
    158     void updateCSSAnimations(const RenderStyle* currentStyle, const RenderStyle& afterChangeStyle, const RenderStyle* parentElementStyle) const;
     158    void updateCSSAnimations(const RenderStyle* currentStyle, const RenderStyle& afterChangeStyle, const Style::ResolutionContext&) const;
    159159    void updateCSSTransitions(const RenderStyle& currentStyle, const RenderStyle& newStyle) const;
    160160};
  • trunk/Source/WebCore/svg/SVGElement.cpp

    r284447 r284693  
    639639}
    640640
    641 std::optional<Style::ElementStyle> SVGElement::resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle*)
     641std::optional<Style::ElementStyle> SVGElement::resolveCustomStyle(const Style::ResolutionContext& resolutionContext, const RenderStyle*)
    642642{
    643643    // If the element is in a <use> tree we get the style from the definition tree.
    644644    if (RefPtr styleElement = this->correspondingElement()) {
    645         auto style = styleElement->resolveStyle(&parentStyle);
     645        auto styleElementResolutionContext = resolutionContext;
     646        // Can't use the selector filter since we are going to another part of the tree.
     647        styleElementResolutionContext.selectorFilter = nullptr;
     648        auto style = styleElement->resolveStyle(styleElementResolutionContext);
    646649        Style::Adjuster::adjustSVGElementStyle(*style.renderStyle, *this);
    647650        return style;
    648651    }
    649652
    650     return resolveStyle(&parentStyle);
     653    return resolveStyle(resolutionContext);
    651654}
    652655
  • trunk/Source/WebCore/svg/SVGElement.h

    r283851 r284693  
    106106    void setCorrespondingElement(SVGElement*);
    107107
    108     std::optional<Style::ElementStyle> resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle) override;
     108    std::optional<Style::ElementStyle> resolveCustomStyle(const Style::ResolutionContext&, const RenderStyle* shadowHostStyle) override;
    109109
    110110    static QualifiedName animatableAttributeForName(const AtomString&);
  • trunk/Source/WebCore/svg/SVGElementRareData.h

    r284093 r284693  
    7878        if (!m_overrideComputedStyle || m_needsOverrideComputedStyleUpdate) {
    7979            // The style computed here contains no CSS Animations/Transitions or SMIL induced rules - this is needed to compute the "base value" for the SMIL animation sandwhich model.
    80             m_overrideComputedStyle = element.styleResolver().styleForElement(element, parentStyle, nullptr, RuleMatchingBehavior::MatchAllRulesExcludingSMIL).renderStyle;
     80            m_overrideComputedStyle = element.styleResolver().styleForElement(element, { parentStyle }, RuleMatchingBehavior::MatchAllRulesExcludingSMIL).renderStyle;
    8181            m_needsOverrideComputedStyleUpdate = false;
    8282        }
  • trunk/Source/WebCore/testing/Internals.cpp

    r284523 r284693  
    60196019        return { };
    60206020
    6021     auto style = styleResolver.pseudoStyleForElement(element, { PseudoId::Highlight, highlightName }, *parentStyle);
     6021    auto style = styleResolver.pseudoStyleForElement(element, { PseudoId::Highlight, highlightName }, { parentStyle });
    60226022    if (!style)
    60236023        return { };
Note: See TracChangeset for help on using the changeset viewer.