Ignore:
Timestamp:
Jan 13, 2022, 12:34:29 PM (3 years ago)
Author:
[email protected]
Message:

Remove use of PseudoElement in ComputedStyleExtractor
https://bugs.webkit.org/show_bug.cgi?id=235158

Reviewed by Darin Adler.

When we fixed bug 234987, the easiest thing was to add some code that uses PseudoElement,
which was already used in several places in ComputedStyleExtractor. However, we want to
remove code using PseudoElement, not add more.

This patch does that throughout ComputedStyleExtractor and also removes some use in
KeyframeEffect by always invalidating the host instead of going through PseudoElement,
which wasn't necessary anymore.

We also had to modify Styleable::renderer() to return nullptr for the "::marker" case
in case there is no content set for the marker, because essentially there is nothing
being rendered for the marker and it would cause ComputedStyleExtractor::propertyValue()
to return computed value instead of "auto" for width and height for instance.

  • animation/KeyframeEffect.cpp:

(WebCore::invalidateElement):

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::ComputedStyleExtractor::styledRenderer const):
(WebCore::hasValidStyleForProperty):
(WebCore::computeRenderStyleForProperty):
(WebCore::ComputedStyleExtractor::customPropertyValue):
(WebCore::ComputedStyleExtractor::propertyValue):
(WebCore::ComputedStyleExtractor::getLayerCount):
(WebCore::ComputedStyleExtractor::styledElement const): Deleted.

  • css/CSSComputedStyleDeclaration.h:
  • style/Styleable.cpp:

(WebCore::Styleable::renderer const):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r287926 r287987  
    7676#include "StyleScope.h"
    7777#include "StyleScrollSnapPoints.h"
     78#include "Styleable.h"
    7879#include "TouchAction.h"
    7980#include "WebKitFontFamilyNames.h"
     
    23752376}
    23762377
    2377 Element* ComputedStyleExtractor::styledElement() const
     2378RenderElement* ComputedStyleExtractor::styledRenderer() const
    23782379{
    23792380    if (!m_element)
    23802381        return nullptr;
    2381     PseudoElement* pseudoElement;
    2382     if (m_pseudoElementSpecifier == PseudoId::Before && (pseudoElement = m_element->beforePseudoElement()))
    2383         return pseudoElement;
    2384     if (m_pseudoElementSpecifier == PseudoId::After && (pseudoElement = m_element->afterPseudoElement()))
    2385         return pseudoElement;
    2386     return m_element.get();
    2387 }
    2388 
    2389 RenderElement* ComputedStyleExtractor::styledRenderer() const
    2390 {
    2391     auto* element = styledElement();
    2392     if (!element)
     2382    if (m_pseudoElementSpecifier != PseudoId::None)
     2383        return Styleable(*m_element, m_pseudoElementSpecifier).renderer();
     2384    if (m_element->hasDisplayContents())
    23932385        return nullptr;
    2394     if (m_pseudoElementSpecifier != PseudoId::None && element == m_element.get())
    2395         return nullptr;
    2396     if (element->hasDisplayContents())
    2397         return nullptr;
    2398     return element->renderer();
     2386    return m_element->renderer();
    23992387}
    24002388
     
    24512439    if (element.styleValidity() != Style::Validity::Valid)
    24522440        return false;
    2453     if (element.isPseudoElement()) {
    2454         if (auto* host = downcast<PseudoElement>(element).hostElement()) {
    2455             if (host->styleValidity() != Style::Validity::Valid)
    2456                 return false;
    2457         }
    2458     }
    24592441    if (element.document().hasPendingFullStyleRebuild())
    24602442        return false;
     
    25162498}
    25172499
    2518 static inline const RenderStyle* computeRenderStyleForProperty(Element& element, PseudoId pseudoElementSpecifier, CSSPropertyID propertyID, std::unique_ptr<RenderStyle>& ownedStyle)
    2519 {
    2520     auto* renderer = element.renderer();
     2500static inline const RenderStyle* computeRenderStyleForProperty(Element& element, PseudoId pseudoElementSpecifier, CSSPropertyID propertyID, std::unique_ptr<RenderStyle>& ownedStyle, RenderElement* renderer)
     2501{
     2502    if (!renderer)
     2503        renderer = element.renderer();
    25212504
    25222505    if (renderer && renderer->isComposited() && CSSPropertyAnimation::animationOfPropertyIsAccelerated(propertyID)) {
    25232506        ownedStyle = renderer->animatedStyle();
    2524         if (pseudoElementSpecifier != PseudoId::None && !element.isPseudoElement()) {
     2507        if (pseudoElementSpecifier != PseudoId::None) {
    25252508            // FIXME: This cached pseudo style will only exist if the animation has been run at least once.
    25262509            return ownedStyle->getCachedPseudoStyle(pseudoElementSpecifier);
     
    25292512    }
    25302513
    2531     return element.computedStyle(element.isPseudoElement() ? PseudoId::None : pseudoElementSpecifier);
     2514    return element.computedStyle(pseudoElementSpecifier);
    25322515}
    25332516
     
    26672650RefPtr<CSSValue> ComputedStyleExtractor::customPropertyValue(const String& propertyName)
    26682651{
    2669     Element* styledElement = this->styledElement();
     2652    Element* styledElement = m_element.get();
    26702653    if (!styledElement)
    26712654        return nullptr;
    26722655   
    2673     if (updateStyleIfNeededForProperty(*styledElement, CSSPropertyCustom)) {
    2674         // Style update may change styledElement() to PseudoElement or back.
    2675         styledElement = this->styledElement();
    2676     }
     2656    updateStyleIfNeededForProperty(*styledElement, CSSPropertyCustom);
    26772657
    26782658    std::unique_ptr<RenderStyle> ownedStyle;
    2679     auto* style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, CSSPropertyCustom, ownedStyle);
     2659    auto* style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, CSSPropertyCustom, ownedStyle, nullptr);
    26802660    if (!style)
    26812661        return nullptr;
     
    27352715RefPtr<CSSValue> ComputedStyleExtractor::propertyValue(CSSPropertyID propertyID, EUpdateLayout updateLayout)
    27362716{
    2737     auto* styledElement = this->styledElement();
     2717    auto* styledElement = m_element.get();
    27382718    if (!styledElement)
    27392719        return nullptr;
     
    27462726        Document& document = m_element->document();
    27472727
    2748         if (updateStyleIfNeededForProperty(*styledElement, propertyID)) {
    2749             // Style update may change styledElement() to PseudoElement or back.
    2750             styledElement = this->styledElement();
    2751         }
     2728        updateStyleIfNeededForProperty(*styledElement, propertyID);
    27522729        renderer = styledRenderer();
    27532730
     
    27552732            return nullptr;
    27562733
    2757         style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, propertyID, ownedStyle);
     2734        style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, propertyID, ownedStyle, renderer);
    27582735
    27592736        // FIXME: Some of these cases could be narrowed down or optimized better.
     
    27622739            || (document.styleScope().resolverIfExists() && document.styleScope().resolverIfExists()->hasViewportDependentMediaQueries() && document.ownerElement());
    27632740
    2764         if (forceFullLayout) {
     2741        if (forceFullLayout)
    27652742            document.updateLayoutIgnorePendingStylesheets();
    2766             styledElement = this->styledElement();
    2767         }
    27682743    }
    27692744
    27702745    if (!updateLayout || forceFullLayout) {
    2771         style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, propertyID, ownedStyle);
     2746        style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, propertyID, ownedStyle, renderer);
    27722747        renderer = styledRenderer();
    27732748    }
     
    44114386{
    44124387    ASSERT(property == CSSPropertyBackground || property == CSSPropertyMask);
    4413     if (!styledElement())
     4388    if (!m_element)
    44144389        return 0;
    44154390
    44164391    std::unique_ptr<RenderStyle> ownedStyle;
    4417     const RenderStyle* style = computeRenderStyleForProperty(*styledElement(), m_pseudoElementSpecifier, property, ownedStyle);
     4392    const RenderStyle* style = computeRenderStyleForProperty(*m_element, m_pseudoElementSpecifier, property, ownedStyle, nullptr);
    44184393    if (!style)
    44194394        return 0;
Note: See TracChangeset for help on using the changeset viewer.