Title: [287987] trunk/Source/WebCore
Revision
287987
Author
grao...@webkit.org
Date
2022-01-13 12:34:29 -0800 (Thu, 13 Jan 2022)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (287986 => 287987)


--- trunk/Source/WebCore/ChangeLog	2022-01-13 20:22:50 UTC (rev 287986)
+++ trunk/Source/WebCore/ChangeLog	2022-01-13 20:34:29 UTC (rev 287987)
@@ -1,3 +1,37 @@
+2022-01-13  Antoine Quint  <grao...@webkit.org>
+
+        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):
+
 2022-01-13  Tim Horton  <timothy_hor...@apple.com>
 
         Fix a few Objective-C object leaks due to early returns in `init`

Modified: trunk/Source/WebCore/animation/KeyframeEffect.cpp (287986 => 287987)


--- trunk/Source/WebCore/animation/KeyframeEffect.cpp	2022-01-13 20:22:50 UTC (rev 287986)
+++ trunk/Source/WebCore/animation/KeyframeEffect.cpp	2022-01-13 20:34:29 UTC (rev 287987)
@@ -86,8 +86,8 @@
 
 static inline void invalidateElement(const std::optional<const Styleable>& styleable)
 {
-    if (auto* elementOrPseudoElement = elementOrPseudoElementForStyleable(styleable))
-        elementOrPseudoElement->invalidateStyleInternal();
+    if (styleable)
+        styleable->element.invalidateStyleInternal();
 }
 
 static inline String CSSPropertyIDToIDLAttributeName(CSSPropertyID cssPropertyId)

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (287986 => 287987)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2022-01-13 20:22:50 UTC (rev 287986)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2022-01-13 20:34:29 UTC (rev 287987)
@@ -75,6 +75,7 @@
 #include "StyleResolver.h"
 #include "StyleScope.h"
 #include "StyleScrollSnapPoints.h"
+#include "Styleable.h"
 #include "TouchAction.h"
 #include "WebKitFontFamilyNames.h"
 #include "WillChangeData.h"
@@ -2374,28 +2375,15 @@
     }
 }
 
-Element* ComputedStyleExtractor::styledElement() const
+RenderElement* ComputedStyleExtractor::styledRenderer() const
 {
     if (!m_element)
         return nullptr;
-    PseudoElement* pseudoElement;
-    if (m_pseudoElementSpecifier == PseudoId::Before && (pseudoElement = m_element->beforePseudoElement()))
-        return pseudoElement;
-    if (m_pseudoElementSpecifier == PseudoId::After && (pseudoElement = m_element->afterPseudoElement()))
-        return pseudoElement;
-    return m_element.get();
-}
-
-RenderElement* ComputedStyleExtractor::styledRenderer() const
-{
-    auto* element = styledElement();
-    if (!element)
+    if (m_pseudoElementSpecifier != PseudoId::None)
+        return Styleable(*m_element, m_pseudoElementSpecifier).renderer();
+    if (m_element->hasDisplayContents())
         return nullptr;
-    if (m_pseudoElementSpecifier != PseudoId::None && element == m_element.get())
-        return nullptr;
-    if (element->hasDisplayContents())
-        return nullptr;
-    return element->renderer();
+    return m_element->renderer();
 }
 
 static bool isImplicitlyInheritedGridOrFlexProperty(CSSPropertyID propertyID)
@@ -2450,12 +2438,6 @@
 {
     if (element.styleValidity() != Style::Validity::Valid)
         return false;
-    if (element.isPseudoElement()) {
-        if (auto* host = downcast<PseudoElement>(element).hostElement()) {
-            if (host->styleValidity() != Style::Validity::Valid)
-                return false;
-        }
-    }
     if (element.document().hasPendingFullStyleRebuild())
         return false;
     if (!element.document().childNeedsStyleRecalc())
@@ -2515,13 +2497,14 @@
     return true;
 }
 
-static inline const RenderStyle* computeRenderStyleForProperty(Element& element, PseudoId pseudoElementSpecifier, CSSPropertyID propertyID, std::unique_ptr<RenderStyle>& ownedStyle)
+static inline const RenderStyle* computeRenderStyleForProperty(Element& element, PseudoId pseudoElementSpecifier, CSSPropertyID propertyID, std::unique_ptr<RenderStyle>& ownedStyle, RenderElement* renderer)
 {
-    auto* renderer = element.renderer();
+    if (!renderer)
+        renderer = element.renderer();
 
     if (renderer && renderer->isComposited() && CSSPropertyAnimation::animationOfPropertyIsAccelerated(propertyID)) {
         ownedStyle = renderer->animatedStyle();
-        if (pseudoElementSpecifier != PseudoId::None && !element.isPseudoElement()) {
+        if (pseudoElementSpecifier != PseudoId::None) {
             // FIXME: This cached pseudo style will only exist if the animation has been run at least once.
             return ownedStyle->getCachedPseudoStyle(pseudoElementSpecifier);
         }
@@ -2528,7 +2511,7 @@
         return ownedStyle.get();
     }
 
-    return element.computedStyle(element.isPseudoElement() ? PseudoId::None : pseudoElementSpecifier);
+    return element.computedStyle(pseudoElementSpecifier);
 }
 
 static Ref<CSSValue> shapePropertyValue(const RenderStyle& style, const ShapeValue* shapeValue)
@@ -2666,17 +2649,14 @@
 
 RefPtr<CSSValue> ComputedStyleExtractor::customPropertyValue(const String& propertyName)
 {
-    Element* styledElement = this->styledElement();
+    Element* styledElement = m_element.get();
     if (!styledElement)
         return nullptr;
     
-    if (updateStyleIfNeededForProperty(*styledElement, CSSPropertyCustom)) {
-        // Style update may change styledElement() to PseudoElement or back.
-        styledElement = this->styledElement();
-    }
+    updateStyleIfNeededForProperty(*styledElement, CSSPropertyCustom);
 
     std::unique_ptr<RenderStyle> ownedStyle;
-    auto* style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, CSSPropertyCustom, ownedStyle);
+    auto* style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, CSSPropertyCustom, ownedStyle, nullptr);
     if (!style)
         return nullptr;
 
@@ -2734,7 +2714,7 @@
 
 RefPtr<CSSValue> ComputedStyleExtractor::propertyValue(CSSPropertyID propertyID, EUpdateLayout updateLayout)
 {
-    auto* styledElement = this->styledElement();
+    auto* styledElement = m_element.get();
     if (!styledElement)
         return nullptr;
 
@@ -2745,16 +2725,13 @@
     if (updateLayout) {
         Document& document = m_element->document();
 
-        if (updateStyleIfNeededForProperty(*styledElement, propertyID)) {
-            // Style update may change styledElement() to PseudoElement or back.
-            styledElement = this->styledElement();
-        }
+        updateStyleIfNeededForProperty(*styledElement, propertyID);
         renderer = styledRenderer();
 
         if (propertyID == CSSPropertyDisplay && !renderer && is<SVGElement>(*styledElement) && !downcast<SVGElement>(*styledElement).isValid())
             return nullptr;
 
-        style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, propertyID, ownedStyle);
+        style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, propertyID, ownedStyle, renderer);
 
         // FIXME: Some of these cases could be narrowed down or optimized better.
         forceFullLayout = isLayoutDependent(propertyID, style, renderer)
@@ -2761,14 +2738,12 @@
             || styledElement->isInShadowTree()
             || (document.styleScope().resolverIfExists() && document.styleScope().resolverIfExists()->hasViewportDependentMediaQueries() && document.ownerElement());
 
-        if (forceFullLayout) {
+        if (forceFullLayout)
             document.updateLayoutIgnorePendingStylesheets();
-            styledElement = this->styledElement();
-        }
     }
 
     if (!updateLayout || forceFullLayout) {
-        style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, propertyID, ownedStyle);
+        style = computeRenderStyleForProperty(*styledElement, m_pseudoElementSpecifier, propertyID, ownedStyle, renderer);
         renderer = styledRenderer();
     }
 
@@ -4410,11 +4385,11 @@
 size_t ComputedStyleExtractor::getLayerCount(CSSPropertyID property)
 {
     ASSERT(property == CSSPropertyBackground || property == CSSPropertyMask);
-    if (!styledElement())
+    if (!m_element)
         return 0;
 
     std::unique_ptr<RenderStyle> ownedStyle;
-    const RenderStyle* style = computeRenderStyleForProperty(*styledElement(), m_pseudoElementSpecifier, property, ownedStyle);
+    const RenderStyle* style = computeRenderStyleForProperty(*m_element, m_pseudoElementSpecifier, property, ownedStyle, nullptr);
     if (!style)
         return 0;
 

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h (287986 => 287987)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h	2022-01-13 20:22:50 UTC (rev 287986)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h	2022-01-13 20:34:29 UTC (rev 287987)
@@ -81,14 +81,7 @@
     static void addValueForAnimationPropertyToList(CSSValueList&, CSSPropertyID, const Animation*);
 
 private:
-    // The styled element is either the element passed into
-    // computedPropertyValue, or the PseudoElement for :before and :after if
-    // they exist.
-    Element* styledElement() const;
-
     // The renderer we should use for resolving layout-dependent properties.
-    // Note that it differs from styledElement()->renderer() in the case we have
-    // no pseudo-element.
     RenderElement* styledRenderer() const;
 
     RefPtr<CSSValue> svgPropertyValue(CSSPropertyID);

Modified: trunk/Source/WebCore/style/Styleable.cpp (287986 => 287987)


--- trunk/Source/WebCore/style/Styleable.cpp	2022-01-13 20:22:50 UTC (rev 287986)
+++ trunk/Source/WebCore/style/Styleable.cpp	2022-01-13 20:34:29 UTC (rev 287987)
@@ -98,13 +98,16 @@
             return beforePseudoElement->renderer();
         break;
     case PseudoId::Marker:
-        if (is<RenderListItem>(element.renderer()))
-            return downcast<RenderListItem>(*element.renderer()).markerRenderer();
+        if (is<RenderListItem>(element.renderer())) {
+            auto* markerRenderer = downcast<RenderListItem>(*element.renderer()).markerRenderer();
+            if (markerRenderer && markerRenderer->style().hasContent())
+                return markerRenderer;
+        }
         break;
     case PseudoId::None:
         return element.renderer();
     default:
-        ASSERT_NOT_REACHED();
+        return nullptr;
     }
 
     return nullptr;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to