Title: [290574] trunk/Source/WebCore
Revision
290574
Author
[email protected]
Date
2022-02-27 17:16:00 -0800 (Sun, 27 Feb 2022)

Log Message

Add a mechanism to request a UA shadow tree update before style
https://bugs.webkit.org/show_bug.cgi?id=237224

Reviewed by Antti Koivisto.

SVG <use> elements register themselves with the document when their
shadow tree contents need updating, and this updating is done in
Document::resolveStyle. For lazy HTML <input> element UA shadow trees
(in bug 236747) we need something similar.

* dom/Document.cpp:
(WebCore::Document::resolveStyle):
(WebCore::Document::addElementWithPendingUserAgentShadowTreeUpdate):
(WebCore::Document::removeElementWithPendingUserAgentShadowTreeUpdate):
* dom/Document.h:
* dom/Element.h:
(WebCore::Element::updateUserAgentShadowTree):
* svg/SVGDocumentExtensions.cpp:
(WebCore::SVGDocumentExtensions::~SVGDocumentExtensions): Deleted.
(WebCore::SVGDocumentExtensions::addUseElementWithPendingShadowTreeUpdate): Deleted.
(WebCore::SVGDocumentExtensions::removeUseElementWithPendingShadowTreeUpdate): Deleted.
* svg/SVGDocumentExtensions.h:
(WebCore::SVGDocumentExtensions::useElementsWithPendingShadowTreeUpdate const): Deleted.
* svg/SVGUseElement.cpp:
(WebCore::SVGUseElement::insertedIntoAncestor):
(WebCore::SVGUseElement::removedFromAncestor):
(WebCore::SVGUseElement::updateUserAgentShadowTree):
(WebCore::SVGUseElement::invalidateShadowTree):
(WebCore::SVGUseElement::updateShadowTree): Deleted.
* svg/SVGUseElement.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (290573 => 290574)


--- trunk/Source/WebCore/ChangeLog	2022-02-27 23:52:38 UTC (rev 290573)
+++ trunk/Source/WebCore/ChangeLog	2022-02-28 01:16:00 UTC (rev 290574)
@@ -1,3 +1,36 @@
+2022-02-27  Cameron McCormack  <[email protected]>
+
+        Add a mechanism to request a UA shadow tree update before style
+        https://bugs.webkit.org/show_bug.cgi?id=237224
+
+        Reviewed by Antti Koivisto.
+
+        SVG <use> elements register themselves with the document when their
+        shadow tree contents need updating, and this updating is done in
+        Document::resolveStyle. For lazy HTML <input> element UA shadow trees
+        (in bug 236747) we need something similar.
+
+        * dom/Document.cpp:
+        (WebCore::Document::resolveStyle):
+        (WebCore::Document::addElementWithPendingUserAgentShadowTreeUpdate):
+        (WebCore::Document::removeElementWithPendingUserAgentShadowTreeUpdate):
+        * dom/Document.h:
+        * dom/Element.h:
+        (WebCore::Element::updateUserAgentShadowTree):
+        * svg/SVGDocumentExtensions.cpp:
+        (WebCore::SVGDocumentExtensions::~SVGDocumentExtensions): Deleted.
+        (WebCore::SVGDocumentExtensions::addUseElementWithPendingShadowTreeUpdate): Deleted.
+        (WebCore::SVGDocumentExtensions::removeUseElementWithPendingShadowTreeUpdate): Deleted.
+        * svg/SVGDocumentExtensions.h:
+        (WebCore::SVGDocumentExtensions::useElementsWithPendingShadowTreeUpdate const): Deleted.
+        * svg/SVGUseElement.cpp:
+        (WebCore::SVGUseElement::insertedIntoAncestor):
+        (WebCore::SVGUseElement::removedFromAncestor):
+        (WebCore::SVGUseElement::updateUserAgentShadowTree):
+        (WebCore::SVGUseElement::invalidateShadowTree):
+        (WebCore::SVGUseElement::updateShadowTree): Deleted.
+        * svg/SVGUseElement.h:
+
 2022-02-27  Antoine Quint  <[email protected]>
 
         [web-animations] web-animations/timing-model/animations/setting-the-timeline-of-an-animation.html is a unique failure

Modified: trunk/Source/WebCore/dom/Document.cpp (290573 => 290574)


--- trunk/Source/WebCore/dom/Document.cpp	2022-02-27 23:52:38 UTC (rev 290573)
+++ trunk/Source/WebCore/dom/Document.cpp	2022-02-28 01:16:00 UTC (rev 290574)
@@ -2005,15 +2005,18 @@
 
     RenderView::RepaintRegionAccumulator repaintRegionAccumulator(renderView());
 
-    // FIXME: Do this update per tree scope.
-    if (auto* extensions = m_svgExtensions.get()) {
-        auto elements = copyToVectorOf<Ref<SVGUseElement>>(extensions->useElementsWithPendingShadowTreeUpdate());
-        // We can't clear m_svgUseElements here because updateShadowTree may end up executing arbitrary scripts
-        // which may insert new SVG use elements or remove existing ones inside sync IPC via ImageLoader::updateFromElement.
-        for (auto& element : elements)
-            element->updateShadowTree();
-    }
+    // FIXME: Do this user agent shadow tree update per tree scope.
 
+    // We can't clear m_elementsWithPendingUserAgentShadowTreeUpdates here
+    // because SVGUseElement::updateUserAgentShadowTree may end up executing
+    // arbitrary scripts which may insert new SVG use elements or remove
+    // existing ones inside sync IPC via ImageLoader::updateFromElement.
+    //
+    // Instead, it is the responsibility of updateUserAgentShadowTree to
+    // remove the element.
+    for (auto& element : copyToVectorOf<Ref<Element>>(m_elementsWithPendingUserAgentShadowTreeUpdates))
+        element->updateUserAgentShadowTree();
+
     // FIXME: We should update style on our ancestor chain before proceeding, however doing so at
     // the time this comment was originally written caused several tests to crash.
 
@@ -9086,6 +9089,20 @@
     return std::nullopt;
 }
 
+void Document::addElementWithPendingUserAgentShadowTreeUpdate(Element& element)
+{
+    ASSERT(&element.document() == this);
+    auto result = m_elementsWithPendingUserAgentShadowTreeUpdates.add(element);
+    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.isNewEntry);
+}
+
+void Document::removeElementWithPendingUserAgentShadowTreeUpdate(Element& element)
+{
+    ASSERT(&element.document() == this);
+    m_elementsWithPendingUserAgentShadowTreeUpdates.remove(element);
+    // FIXME: Assert that element was in m_elementsWithPendingUserAgentShadowTreeUpdates once re-entrancy to update style and layout have been removed.
+}
+
 } // namespace WebCore
 
 #undef DOCUMENT_RELEASE_LOG

Modified: trunk/Source/WebCore/dom/Document.h (290573 => 290574)


--- trunk/Source/WebCore/dom/Document.h	2022-02-27 23:52:38 UTC (rev 290573)
+++ trunk/Source/WebCore/dom/Document.h	2022-02-28 01:16:00 UTC (rev 290574)
@@ -1673,6 +1673,9 @@
 
     void createNewIdentifier();
 
+    void addElementWithPendingUserAgentShadowTreeUpdate(Element&);
+    void removeElementWithPendingUserAgentShadowTreeUpdate(Element&);
+
 protected:
     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     WEBCORE_EXPORT Document(Frame*, const Settings&, const URL&, DocumentClasses = { }, unsigned constructionFlags = 0, ScriptExecutionContextIdentifier = { });
@@ -2264,6 +2267,8 @@
     std::unique_ptr<ModalContainerObserver> m_modalContainerObserver;
 
     Vector<Function<void()>> m_whenIsVisibleHandlers;
+
+    WeakHashSet<Element> m_elementsWithPendingUserAgentShadowTreeUpdates;
 };
 
 Element* eventTargetElementForDocument(Document*);

Modified: trunk/Source/WebCore/dom/Element.h (290573 => 290574)


--- trunk/Source/WebCore/dom/Element.h	2022-02-27 23:52:38 UTC (rev 290573)
+++ trunk/Source/WebCore/dom/Element.h	2022-02-28 01:16:00 UTC (rev 290574)
@@ -664,6 +664,8 @@
     bool hasDuplicateAttribute() const { return m_hasDuplicateAttribute; };
     void setHasDuplicateAttribute(bool hasDuplicateAttribute) { m_hasDuplicateAttribute = hasDuplicateAttribute; };
 
+    virtual void updateUserAgentShadowTree() { }
+
 protected:
     Element(const QualifiedName&, Document&, ConstructionType);
 

Modified: trunk/Source/WebCore/svg/SVGDocumentExtensions.cpp (290573 => 290574)


--- trunk/Source/WebCore/svg/SVGDocumentExtensions.cpp	2022-02-27 23:52:38 UTC (rev 290573)
+++ trunk/Source/WebCore/svg/SVGDocumentExtensions.cpp	2022-02-28 01:16:00 UTC (rev 290574)
@@ -48,10 +48,7 @@
 {
 }
 
-SVGDocumentExtensions::~SVGDocumentExtensions()
-{
-    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_useElementsWithPendingShadowTreeUpdate.computesEmpty());
-}
+SVGDocumentExtensions::~SVGDocumentExtensions() = default;
 
 void SVGDocumentExtensions::addTimeContainer(SVGSVGElement& element)
 {
@@ -90,20 +87,6 @@
     return m_resources.get(id);
 }
 
-
-void SVGDocumentExtensions::addUseElementWithPendingShadowTreeUpdate(SVGUseElement& element)
-{
-    auto result = m_useElementsWithPendingShadowTreeUpdate.add(element);
-    RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.isNewEntry);
-}
-
-void SVGDocumentExtensions::removeUseElementWithPendingShadowTreeUpdate(SVGUseElement& element)
-{
-    m_useElementsWithPendingShadowTreeUpdate.remove(element);
-    // FIXME: Assert that element was in m_svgUseElements once re-entrancy to update style and layout have been removed.
-}
-
-
 void SVGDocumentExtensions::startAnimations()
 {
     // FIXME: Eventually every "Time Container" will need a way to latch on to some global timer

Modified: trunk/Source/WebCore/svg/SVGDocumentExtensions.h (290573 => 290574)


--- trunk/Source/WebCore/svg/SVGDocumentExtensions.h	2022-02-27 23:52:38 UTC (rev 290573)
+++ trunk/Source/WebCore/svg/SVGDocumentExtensions.h	2022-02-28 01:16:00 UTC (rev 290574)
@@ -43,7 +43,7 @@
 public:
     explicit SVGDocumentExtensions(Document&);
     ~SVGDocumentExtensions();
-    
+
     void addTimeContainer(SVGSVGElement&);
     void removeTimeContainer(SVGSVGElement&);
 
@@ -51,10 +51,6 @@
     void removeResource(const AtomString& id);
     RenderSVGResourceContainer* resourceById(const AtomString& id) const;
 
-    void addUseElementWithPendingShadowTreeUpdate(SVGUseElement&);
-    void removeUseElementWithPendingShadowTreeUpdate(SVGUseElement&);
-    const WeakHashSet<SVGUseElement>& useElementsWithPendingShadowTreeUpdate() const { return m_useElementsWithPendingShadowTreeUpdate; }
-
     void startAnimations();
     void pauseAnimations();
     void unpauseAnimations();
@@ -86,7 +82,6 @@
     std::unique_ptr<SVGResourcesCache> m_resourcesCache;
 
     Vector<Ref<SVGElement>> m_rebuildElements;
-    WeakHashSet<SVGUseElement> m_useElementsWithPendingShadowTreeUpdate;
     bool m_areAnimationsPaused;
 
 public:

Modified: trunk/Source/WebCore/svg/SVGUseElement.cpp (290573 => 290574)


--- trunk/Source/WebCore/svg/SVGUseElement.cpp	2022-02-27 23:52:38 UTC (rev 290573)
+++ trunk/Source/WebCore/svg/SVGUseElement.cpp	2022-02-28 01:16:00 UTC (rev 290574)
@@ -100,7 +100,7 @@
     SVGGraphicsElement::insertedIntoAncestor(insertionType, parentOfInsertedTree);
     if (insertionType.connectedToDocument) {
         if (m_shadowTreeNeedsUpdate)
-            document().accessSVGExtensions().addUseElementWithPendingShadowTreeUpdate(*this);
+            document().addElementWithPendingUserAgentShadowTreeUpdate(*this);
         invalidateShadowTree();
         // FIXME: Move back the call to updateExternalDocument() here once notifyFinished is made always async.
         return InsertedIntoAncestorResult::NeedsPostInsertionCallback;
@@ -119,7 +119,7 @@
     // and SVGUseElement::updateExternalDocument which calls invalidateShadowTree().
     if (removalType.disconnectedFromDocument) {
         if (m_shadowTreeNeedsUpdate)
-            document().accessSVGExtensions().removeUseElementWithPendingShadowTreeUpdate(*this);
+            document().removeElementWithPendingUserAgentShadowTreeUpdate(*this);
     }
     SVGGraphicsElement::removedFromAncestor(removalType, oldParentOfRemovedTree);
     if (removalType.disconnectedFromDocument) {
@@ -217,7 +217,7 @@
     invalidateShadowTree();
 }
 
-void SVGUseElement::updateShadowTree()
+void SVGUseElement::updateUserAgentShadowTree()
 {
     m_shadowTreeNeedsUpdate = false;
 
@@ -226,7 +226,7 @@
 
     if (!isConnected())
         return;
-    document().accessSVGExtensions().removeUseElementWithPendingShadowTreeUpdate(*this);
+    document().removeElementWithPendingUserAgentShadowTreeUpdate(*this);
 
     String targetID;
     auto* target = findTarget(&targetID);
@@ -530,7 +530,7 @@
     invalidateStyleAndRenderersForSubtree();
     invalidateDependentShadowTrees();
     if (isConnected())
-        document().accessSVGExtensions().addUseElementWithPendingShadowTreeUpdate(*this);
+        document().addElementWithPendingUserAgentShadowTreeUpdate(*this);
 }
 
 void SVGUseElement::invalidateDependentShadowTrees()

Modified: trunk/Source/WebCore/svg/SVGUseElement.h (290573 => 290574)


--- trunk/Source/WebCore/svg/SVGUseElement.h	2022-02-27 23:52:38 UTC (rev 290573)
+++ trunk/Source/WebCore/svg/SVGUseElement.h	2022-02-28 01:16:00 UTC (rev 290574)
@@ -38,8 +38,7 @@
     virtual ~SVGUseElement();
 
     void invalidateShadowTree();
-    bool shadowTreeNeedsUpdate() const { return m_shadowTreeNeedsUpdate; }
-    void updateShadowTree();
+    void updateUserAgentShadowTree() final;
 
     RenderElement* rendererClipChild() const;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to