Title: [292334] branches/safari-613-branch
Revision
292334
Author
[email protected]
Date
2022-04-04 14:56:00 -0700 (Mon, 04 Apr 2022)

Log Message

Cherry pick r290574 r290639 r291028 r291961.

Patches needed for Cameron's "Make input element UA shadow tree creation lazy" change.

Modified Paths

Added Paths

Diff

Added: branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-crash-expected.html (0 => 292334)


--- branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-crash-expected.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-crash-expected.html	2022-04-04 21:56:00 UTC (rev 292334)
@@ -0,0 +1 @@
+PASS if no crash.

Added: branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-crash.html (0 => 292334)


--- branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-crash.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-crash.html	2022-04-04 21:56:00 UTC (rev 292334)
@@ -0,0 +1,10 @@
+PASS if no crash.
+<div id=x></div>
+<script>
+let audio0 = document.createElement('audio');
+x.append(audio0);
+audio0.controls = true;
+x.append(document.createElement('input'));
+x.outerHTML += '';
+x.remove();
+</script>

Added: branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-expected.html (0 => 292334)


--- branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-expected.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-expected.html	2022-04-04 21:56:00 UTC (rev 292334)
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<body>
+<script src=""
+<script>
+run({ useParser: true });
+</script>

Added: branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-move-document-crash-expected.txt (0 => 292334)


--- branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-move-document-crash-expected.txt	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-move-document-crash-expected.txt	2022-04-04 21:56:00 UTC (rev 292334)
@@ -0,0 +1 @@
+PASS if no crash.

Added: branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-move-document-crash.html (0 => 292334)


--- branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-move-document-crash.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation-move-document-crash.html	2022-04-04 21:56:00 UTC (rev 292334)
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+PASS if no crash.
+<script>
+function run() {
+    if (window.testRunner)
+        testRunner.dumpAsText();
+
+    let e = document.createElement("input");
+    frames[0].document.body.offsetTop;
+    document.body.append(e);
+    frames[0].document.body.append(e);
+}
+</script>
+<iframe _onload_="run()"></iframe>

Added: branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation.html (0 => 292334)


--- branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation.html	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation.html	2022-04-04 21:56:00 UTC (rev 292334)
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<body>
+<script src=""
+<script>
+run({ useParser: false });
+</script>

Added: branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation.js (0 => 292334)


--- branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation.js	                        (rev 0)
+++ branches/safari-613-branch/LayoutTests/fast/forms/lazy-shadow-tree-creation.js	2022-04-04 21:56:00 UTC (rev 292334)
@@ -0,0 +1,57 @@
+const types = {
+    "color": { value: "#008000" },
+    "date": { value: "2022-01-01" },
+    "datetime-local": { value: "2022-01-01" },
+    "email": { value: "[email protected]" },
+    "file": { },
+    "month": { value: "2022-01" },
+    "number": { value: "123" },
+    "password": { },
+    "range": { value: "75" },
+    "search": { value: "abc" },
+    "telephone": { value: "+61300000000" },
+    "text": { value: "abc" },
+    "time": { value: "10:00" },
+    "url": { value: "https://example.com/" },
+    "week": { value: "2022-W1" },
+};
+
+function supportsType(typeName) {
+    let e = document.createElement("input");
+    e.type = typeName;
+    return e.type == typeName;
+}
+
+function makeAndAppendInput(options, typeName, attributes = { }) {
+    let span = document.createElement("span");
+    document.body.append(span);
+
+    if (options.useParser) {
+        let tag = `<input type="${typeName}"`;
+        for (let name in attributes)
+            tag += ` ${name}="${attributes[name]}"`;
+        tag += ">";
+        span.innerHTML = tag;
+    } else {
+        let input = document.createElement("input");
+        input.type = typeName;
+        for (let name in attributes)
+            input.setAttribute(name, attributes[name]);
+        span.append(input);
+    }
+}
+
+function run(options) {
+    for (let typeName in types) {
+        if (!supportsType(typeName))
+            continue;
+
+        let type = types[typeName];
+        makeAndAppendInput(options, typeName);
+
+        if (type.value)
+            makeAndAppendInput(options, typeName, { value: type.value });
+
+        makeAndAppendInput(options, typeName, { value: type.value, disabled: "disabled" });
+    }
+}

Modified: branches/safari-613-branch/LayoutTests/fast/shadow-dom/style-resolver-sharing-expected.txt (292333 => 292334)


--- branches/safari-613-branch/LayoutTests/fast/shadow-dom/style-resolver-sharing-expected.txt	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/LayoutTests/fast/shadow-dom/style-resolver-sharing-expected.txt	2022-04-04 21:56:00 UTC (rev 292334)
@@ -1,7 +1,6 @@
 Verify that shadow roots with identical styles share style resolvers (have equal identifier below).
 (document resolver (identifier=0) (author rule count=0))
 (shadow root resolver (user agent) (identifier=1) (author rule count=0))
-(shadow root resolver (user agent) (identifier=1) (author rule count=0))
 (shadow root resolver (author) (identifier=2) (author rule count=0))
 (shadow root resolver (author) (identifier=2) (author rule count=0))
 (shadow root resolver (author) (identifier=2) (author rule count=0))
@@ -11,11 +10,11 @@
 (shadow root resolver (author) (identifier=3) (author rule count=1))
 (shadow root resolver (author) (identifier=3) (author rule count=1))
 (shadow root resolver (author) (identifier=3) (author rule count=1))
+(shadow root resolver (user agent) (identifier=1) (author rule count=0))
 
 After style mutation
 (document resolver (identifier=0) (author rule count=0))
 (shadow root resolver (user agent) (identifier=1) (author rule count=0))
-(shadow root resolver (user agent) (identifier=1) (author rule count=0))
 (shadow root resolver (author) (identifier=2) (author rule count=0))
 (shadow root resolver (author) (identifier=2) (author rule count=0))
 (shadow root resolver (author) (identifier=3) (author rule count=1))
@@ -25,4 +24,5 @@
 (shadow root resolver (author) (identifier=2) (author rule count=0))
 (shadow root resolver (author) (identifier=2) (author rule count=0))
 (shadow root resolver (author) (identifier=3) (author rule count=1))
+(shadow root resolver (user agent) (identifier=1) (author rule count=0))
 

Modified: branches/safari-613-branch/Source/WebCore/dom/Document.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/dom/Document.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/dom/Document.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -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.
 
@@ -9060,6 +9063,25 @@
     return ts;
 }
 
+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.
+}
+
+bool Document::hasElementWithPendingUserAgentShadowTreeUpdate(Element& element) const
+{
+    return m_elementsWithPendingUserAgentShadowTreeUpdates.contains(element);
+}
+
 } // namespace WebCore
 
 #undef DOCUMENT_RELEASE_LOG

Modified: branches/safari-613-branch/Source/WebCore/dom/Document.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/dom/Document.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/dom/Document.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -1673,6 +1673,10 @@
     WEBCORE_EXPORT ModalContainerObserver* modalContainerObserver();
     ModalContainerObserver* modalContainerObserverIfExists() const;
 
+    WEBCORE_EXPORT bool hasElementWithPendingUserAgentShadowTreeUpdate(Element&) const;
+    void addElementWithPendingUserAgentShadowTreeUpdate(Element&);
+    WEBCORE_EXPORT void removeElementWithPendingUserAgentShadowTreeUpdate(Element&);
+
 protected:
     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     WEBCORE_EXPORT Document(Frame*, const Settings&, const URL&, DocumentClasses = { }, unsigned constructionFlags = 0);
@@ -2260,6 +2264,8 @@
 #endif
 
     std::unique_ptr<ModalContainerObserver> m_modalContainerObserver;
+
+    WeakHashSet<Element> m_elementsWithPendingUserAgentShadowTreeUpdates;
 };
 
 Element* eventTargetElementForDocument(Document*);

Modified: branches/safari-613-branch/Source/WebCore/dom/Element.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/dom/Element.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/dom/Element.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -662,6 +662,8 @@
     bool hasDuplicateAttribute() const { return m_hasDuplicateAttribute; };
     void setHasDuplicateAttribute(bool hasDuplicateAttribute) { m_hasDuplicateAttribute = hasDuplicateAttribute; };
 
+    virtual void updateUserAgentShadowTree() { }
+
 protected:
     Element(const QualifiedName&, Document&, ConstructionType);
 

Modified: branches/safari-613-branch/Source/WebCore/html/BaseDateAndTimeInputType.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/BaseDateAndTimeInputType.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/BaseDateAndTimeInputType.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -306,7 +306,7 @@
     }
 }
 
-void BaseDateAndTimeInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(bool)
+void BaseDateAndTimeInputType::createShadowSubtree()
 {
     ASSERT(needsShadowSubtree());
     ASSERT(element());
@@ -334,6 +334,9 @@
 void BaseDateAndTimeInputType::updateInnerTextValue()
 {
     ASSERT(element());
+
+    createShadowSubtreeIfNeeded();
+
     if (!m_dateTimeEditElement) {
         auto node = element()->userAgentShadowRoot()->firstChild();
         if (!is<HTMLElement>(node))

Modified: branches/safari-613-branch/Source/WebCore/html/BaseDateAndTimeInputType.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/BaseDateAndTimeInputType.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/BaseDateAndTimeInputType.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -114,7 +114,7 @@
     bool isMouseFocusable() const final;
 
     void handleDOMActivateEvent(Event&) override;
-    void createShadowSubtreeAndUpdateInnerTextElementEditability(bool) final;
+    void createShadowSubtree() final;
     void destroyShadowSubtree() final;
     void updateInnerTextValue() final;
     bool hasCustomFocusLogic() const final;

Modified: branches/safari-613-branch/Source/WebCore/html/ColorInputType.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/ColorInputType.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/ColorInputType.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -135,7 +135,7 @@
     return parseSimpleColorValue(element()->value()).value();
 }
 
-void ColorInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(bool)
+void ColorInputType::createShadowSubtree()
 {
     ASSERT(needsShadowSubtree());
     ASSERT(element());

Modified: branches/safari-613-branch/Source/WebCore/html/ColorInputType.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/ColorInputType.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/ColorInputType.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -62,7 +62,7 @@
     bool supportsRequired() const final;
     String fallbackValue() const final;
     String sanitizeValue(const String&) const final;
-    void createShadowSubtreeAndUpdateInnerTextElementEditability(bool) final;
+    void createShadowSubtree() final;
     void setValue(const String&, bool valueChanged, TextFieldEventBehavior) final;
     void attributeChanged(const QualifiedName&) final;
     void handleDOMActivateEvent(Event&) final;

Modified: branches/safari-613-branch/Source/WebCore/html/FileInputType.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/FileInputType.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/FileInputType.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -262,18 +262,20 @@
     element()->invalidateStyleForSubtree();
 }
 
-void FileInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(bool)
+void FileInputType::createShadowSubtree()
 {
     ASSERT(needsShadowSubtree());
     ASSERT(element());
     ASSERT(element()->shadowRoot());
-    element()->userAgentShadowRoot()->appendChild(ContainerNode::ChildChange::Source::Parser, element()->multiple() ? UploadButtonElement::createForMultiple(element()->document()): UploadButtonElement::create(element()->document()));
+
+    auto button = element()->multiple() ? UploadButtonElement::createForMultiple(element()->document()) : UploadButtonElement::create(element()->document());
+    element()->userAgentShadowRoot()->appendChild(ContainerNode::ChildChange::Source::Parser, button);
+    disabledStateChanged();
 }
 
 void FileInputType::disabledStateChanged()
 {
     ASSERT(element());
-    ASSERT(element()->shadowRoot());
 
     auto root = element()->userAgentShadowRoot();
     if (!root)
@@ -287,7 +289,6 @@
 {
     if (name == multipleAttr) {
         if (auto* element = this->element()) {
-            ASSERT(element->shadowRoot());
             if (auto root = element->userAgentShadowRoot()) {
                 if (RefPtr button = childrenOfType<UploadButtonElement>(*root).first())
                     button->setValue(element->multiple() ? fileButtonChooseMultipleFilesLabel() : fileButtonChooseFileLabel());

Modified: branches/safari-613-branch/Source/WebCore/html/FileInputType.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/FileInputType.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/FileInputType.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -77,7 +77,7 @@
 #endif
 
     Icon* icon() const final;
-    void createShadowSubtreeAndUpdateInnerTextElementEditability(bool) final;
+    void createShadowSubtree() final;
     void disabledStateChanged() final;
     void attributeChanged(const QualifiedName&) final;
     String defaultToolTip() const final;

Modified: branches/safari-613-branch/Source/WebCore/html/HTMLInputElement.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/HTMLInputElement.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/HTMLInputElement.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -134,9 +134,10 @@
     , m_hasTouchEventHandler(false)
 #endif
     , m_isSpellcheckDisabledExceptTextReplacement(false)
+    , m_hasPendingUserAgentShadowTreeUpdate(false)
 {
-    // m_inputType is lazily created when constructed by the parser to avoid constructing unnecessarily a text inputType and
-    // its shadow subtree, just to destroy them when the |type| attribute gets set by the parser to something else than 'text'.
+    // m_inputType is lazily created when constructed by the parser to avoid constructing unnecessarily a text inputType,
+    // just to destroy them when the |type| attribute gets set by the parser to something else than 'text'.
     if (!createdByParser)
         m_inputType = InputType::createText(*this);
 
@@ -146,14 +147,7 @@
 
 Ref<HTMLInputElement> HTMLInputElement::create(const QualifiedName& tagName, Document& document, HTMLFormElement* form, bool createdByParser)
 {
-    bool shouldCreateShadowRootLazily = createdByParser;
-    Ref<HTMLInputElement> inputElement = adoptRef(*new HTMLInputElement(tagName, document, form, createdByParser));
-    if (!shouldCreateShadowRootLazily) {
-        ASSERT(inputElement->m_inputType->needsShadowSubtree());
-        inputElement->createUserAgentShadowRoot();
-        inputElement->createShadowSubtreeAndUpdateInnerTextElementEditability();
-    }
-    return inputElement;
+    return adoptRef(*new HTMLInputElement(tagName, document, form, createdByParser));
 }
 
 HTMLImageLoader& HTMLInputElement::ensureImageLoader()
@@ -163,12 +157,6 @@
     return *m_imageLoader;
 }
 
-void HTMLInputElement::createShadowSubtreeAndUpdateInnerTextElementEditability()
-{
-    Ref<InputType> protectedInputType(*m_inputType);
-    protectedInputType->createShadowSubtreeAndUpdateInnerTextElementEditability(isInnerTextElementEditable());
-}
-
 HTMLInputElement::~HTMLInputElement()
 {
     if (needsSuspensionCallback())
@@ -211,6 +199,11 @@
     return m_inputType->innerTextElement();
 }
 
+RefPtr<TextControlInnerTextElement> HTMLInputElement::innerTextElementCreatingShadowSubtreeIfNeeded()
+{
+    return m_inputType->innerTextElementCreatingShadowSubtreeIfNeeded();
+}
+
 HTMLElement* HTMLInputElement::innerBlockElement() const
 {
     return m_inputType->innerBlockElement();
@@ -579,10 +572,7 @@
     m_inputType->detachFromElement();
 
     m_inputType = WTFMove(newType);
-    if (m_inputType->needsShadowSubtree()) {
-        ensureUserAgentShadowRoot();
-        createShadowSubtreeAndUpdateInnerTextElementEditability();
-    }
+    m_inputType->createShadowSubtreeIfNeeded();
 
     updateWillValidateAndValidity();
 
@@ -735,9 +725,6 @@
     const AtomString& type = attributeWithoutSynchronization(typeAttr);
     if (type.isNull()) {
         m_inputType = InputType::createText(*this);
-        ASSERT(m_inputType->needsShadowSubtree());
-        createUserAgentShadowRoot();
-        createShadowSubtreeAndUpdateInnerTextElementEditability();
         updateWillValidateAndValidity();
         return;
     }
@@ -744,10 +731,6 @@
 
     m_hasType = true;
     m_inputType = InputType::create(*this, type);
-    if (m_inputType->needsShadowSubtree()) {
-        createUserAgentShadowRoot();
-        createShadowSubtreeAndUpdateInnerTextElementEditability();
-    }
     updateWillValidateAndValidity();
     registerForSuspensionCallbackIfNeeded();
     runPostTypeUpdateTasks();
@@ -1586,18 +1569,27 @@
 #if ENABLE(DATALIST_ELEMENT)
     resetListAttributeTargetObserver();
 #endif
+    if (insertionType.connectedToDocument && m_inputType->needsShadowSubtree() && !m_inputType->hasCreatedShadowSubtree() && !m_hasPendingUserAgentShadowTreeUpdate) {
+        document().addElementWithPendingUserAgentShadowTreeUpdate(*this);
+        m_hasPendingUserAgentShadowTreeUpdate = true;
+    }
+    
     return InsertedIntoAncestorResult::NeedsPostInsertionCallback;
 }
 
+void HTMLInputElement::updateUserAgentShadowTree()
+{
+    ASSERT(m_hasPendingUserAgentShadowTreeUpdate);
+    document().removeElementWithPendingUserAgentShadowTreeUpdate(*this);
+    m_hasPendingUserAgentShadowTreeUpdate = false;
+    m_inputType->createShadowSubtreeIfNeeded();
+}
+
 void HTMLInputElement::didFinishInsertingNode()
 {
     HTMLTextFormControlElement::didFinishInsertingNode();
     if (isInTreeScope() && !form())
         addToRadioButtonGroup();
-#if ENABLE(DATALIST_ELEMENT)
-    if (isConnected() && m_hasNonEmptyList)
-        dataListMayHaveChanged();
-#endif
 }
 
 void HTMLInputElement::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree)
@@ -1606,6 +1598,10 @@
         oldParentOfRemovedTree.treeScope().radioButtonGroups().removeButton(*this);
     if (removalType.disconnectedFromDocument && !form())
         removeFromRadioButtonGroup();
+    if (removalType.disconnectedFromDocument && m_hasPendingUserAgentShadowTreeUpdate) {
+        document().removeElementWithPendingUserAgentShadowTreeUpdate(*this);
+        m_hasPendingUserAgentShadowTreeUpdate = false;
+    }
     HTMLTextFormControlElement::removedFromAncestor(removalType, oldParentOfRemovedTree);
     ASSERT(!isConnected());
 #if ENABLE(DATALIST_ELEMENT)

Modified: branches/safari-613-branch/Source/WebCore/html/HTMLInputElement.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/HTMLInputElement.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/HTMLInputElement.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -137,6 +137,7 @@
     HTMLElement* containerElement() const;
     
     RefPtr<TextControlInnerTextElement> innerTextElement() const final;
+    RefPtr<TextControlInnerTextElement> innerTextElementCreatingShadowSubtreeIfNeeded() final;
     RenderStyle createInnerTextStyle(const RenderStyle&) final;
 
     HTMLElement* innerBlockElement() const;
@@ -354,6 +355,10 @@
 
     String resultForDialogSubmit() const final;
 
+    bool isInnerTextElementEditable() const final { return !hasAutoFillStrongPasswordButton() && HTMLTextFormControlElement::isInnerTextElementEditable(); }
+
+    void updateUserAgentShadowTree() final;
+
 protected:
     HTMLInputElement(const QualifiedName&, Document&, HTMLFormElement*, bool createdByParser);
 
@@ -369,8 +374,6 @@
     void removedFromAncestor(RemovalType, ContainerNode&) final;
     void didMoveToNewDocument(Document& oldDocument, Document& newDocument) final;
 
-    void createShadowSubtreeAndUpdateInnerTextElementEditability();
-
     int defaultTabIndex() const final;
     bool hasCustomFocusLogic() const final;
     bool isKeyboardFocusable(KeyboardEvent*) const final;
@@ -382,8 +385,6 @@
 
     bool isInteractiveContent() const final;
 
-    bool isInnerTextElementEditable() const final { return !hasAutoFillStrongPasswordButton() && HTMLTextFormControlElement::isInnerTextElementEditable(); }
-
     bool canTriggerImplicitSubmission() const final { return isTextField(); }
 
     const AtomString& formControlType() const final;
@@ -493,6 +494,7 @@
     bool m_hasTouchEventHandler : 1;
 #endif
     bool m_isSpellcheckDisabledExceptTextReplacement : 1;
+    bool m_hasPendingUserAgentShadowTreeUpdate : 1;
     RefPtr<InputType> m_inputType;
     // The ImageLoader must be owned by this element because the loader code assumes
     // that it lives as long as its owning element lives. If we move the loader into

Modified: branches/safari-613-branch/Source/WebCore/html/HTMLTextAreaElement.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/HTMLTextAreaElement.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/HTMLTextAreaElement.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -345,6 +345,11 @@
     return childrenOfType<TextControlInnerTextElement>(*root).first();
 }
 
+RefPtr<TextControlInnerTextElement> HTMLTextAreaElement::innerTextElementCreatingShadowSubtreeIfNeeded()
+{
+    return innerTextElement();
+}
+
 void HTMLTextAreaElement::rendererWillBeDestroyed()
 {
     updateValue();

Modified: branches/safari-613-branch/Source/WebCore/html/HTMLTextAreaElement.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/HTMLTextAreaElement.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/HTMLTextAreaElement.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -57,6 +57,7 @@
     bool isValidValue(const String&) const;
     
     WEBCORE_EXPORT RefPtr<TextControlInnerTextElement> innerTextElement() const final;
+    WEBCORE_EXPORT RefPtr<TextControlInnerTextElement> innerTextElementCreatingShadowSubtreeIfNeeded() final;
     RenderStyle createInnerTextStyle(const RenderStyle&) final;
     void copyNonAttributePropertiesFromElement(const Element&) final;
 

Modified: branches/safari-613-branch/Source/WebCore/html/HTMLTextFormControlElement.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/HTMLTextFormControlElement.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/HTMLTextFormControlElement.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -128,7 +128,9 @@
 {
     if (event.type() == eventNames().blurEvent || event.type() == eventNames().focusEvent)
         return;
-    innerTextElement()->defaultEventHandler(event);
+
+    if (auto innerText = innerTextElement())
+        innerText->defaultEventHandler(event);
 }
 
 String HTMLTextFormControlElement::strippedPlaceholder() const
@@ -300,7 +302,7 @@
     end = std::max(end, 0);
     start = std::min(std::max(start, 0), end);
 
-    auto innerText = innerTextElement();
+    auto innerText = innerTextElementCreatingShadowSubtreeIfNeeded();
     bool hasFocus = document().focusedElement() == this;
     if (!hasFocus && innerText) {
         if (!isConnected()) {
@@ -360,6 +362,7 @@
 
 VisiblePosition HTMLTextFormControlElement::visiblePositionForIndex(int index) const
 {
+    ASSERT(innerTextElement());
     VisiblePosition position = positionForIndex(innerTextElement().get(), index);
     ASSERT(indexForVisiblePosition(position) == index);
     return position;
@@ -578,7 +581,7 @@
 void HTMLTextFormControlElement::setInnerTextValue(const String& value)
 {
     LayoutDisallowedScope layoutDisallowedScope(LayoutDisallowedScope::Reason::PerformanceOptimization);
-    auto innerText = innerTextElement();
+    auto innerText = innerTextElementCreatingShadowSubtreeIfNeeded();
     if (!innerText)
         return;
 

Modified: branches/safari-613-branch/Source/WebCore/html/HTMLTextFormControlElement.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/HTMLTextFormControlElement.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/HTMLTextFormControlElement.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -89,6 +89,7 @@
     virtual String value() const = 0;
 
     virtual RefPtr<TextControlInnerTextElement> innerTextElement() const = 0;
+    virtual RefPtr<TextControlInnerTextElement> innerTextElementCreatingShadowSubtreeIfNeeded() = 0;
     virtual RenderStyle createInnerTextStyle(const RenderStyle&) = 0;
 
     void selectionChanged(bool shouldFireSelectEvent);

Modified: branches/safari-613-branch/Source/WebCore/html/InputType.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/InputType.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/InputType.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -561,7 +561,7 @@
     element()->defaultBlur();
 }
 
-void InputType::createShadowSubtreeAndUpdateInnerTextElementEditability(bool)
+void InputType::createShadowSubtree()
 {
 }
 
@@ -1100,6 +1100,12 @@
     return nullptr;
 }
 
+RefPtr<TextControlInnerTextElement> InputType::innerTextElementCreatingShadowSubtreeIfNeeded()
+{
+    createShadowSubtreeIfNeeded();
+    return innerTextElement();
+}
+
 String InputType::resultForDialogSubmit() const
 {
     ASSERT(element());
@@ -1106,4 +1112,14 @@
     return element()->value();
 }
 
+void InputType::createShadowSubtreeIfNeeded()
+{
+    if (m_hasCreatedShadowSubtree || !needsShadowSubtree())
+        return;
+    Ref protectedThis { *this };
+    element()->ensureUserAgentShadowRoot();
+    m_hasCreatedShadowSubtree = true;
+    createShadowSubtree();
+}
+
 } // namespace WebCore

Modified: branches/safari-613-branch/Source/WebCore/html/InputType.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/InputType.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/InputType.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -206,6 +206,7 @@
     bool supportLabels() const;
     bool isEnumeratable() const;
     bool needsShadowSubtree() const { return !nonShadowRootTypes.contains(m_type); }
+    bool hasCreatedShadowSubtree() const { return m_hasCreatedShadowSubtree; }
 
     // Form value functions.
 
@@ -306,7 +307,8 @@
 
     // Shadow tree handling.
 
-    virtual void createShadowSubtreeAndUpdateInnerTextElementEditability(bool);
+    void createShadowSubtreeIfNeeded();
+    virtual void createShadowSubtree();
     virtual void destroyShadowSubtree();
 
     virtual HTMLElement* containerElement() const { return nullptr; }
@@ -323,6 +325,7 @@
 #if ENABLE(DATALIST_ELEMENT)
     virtual HTMLElement* dataListButtonElement() const { return nullptr; }
 #endif
+    RefPtr<TextControlInnerTextElement> innerTextElementCreatingShadowSubtreeIfNeeded();
 
     // Miscellaneous functions.
 
@@ -412,6 +415,7 @@
     ExceptionOr<void> applyStep(int count, AnyStepHandling, TextFieldEventBehavior);
 
     const Type m_type;
+    bool m_hasCreatedShadowSubtree { false };
     // m_element is null if this InputType is no longer associated with an element (either the element died or changed input type).
     WeakPtr<HTMLInputElement> m_element;
 };

Modified: branches/safari-613-branch/Source/WebCore/html/RangeInputType.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/RangeInputType.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/RangeInputType.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -133,6 +133,10 @@
 void RangeInputType::handleMouseDownEvent(MouseEvent& event)
 {
     ASSERT(element());
+
+    if (!hasCreatedShadowSubtree())
+        return;
+
     if (element()->isDisabledFormControl())
         return;
 
@@ -151,10 +155,15 @@
 #if ENABLE(TOUCH_EVENTS)
 void RangeInputType::handleTouchEvent(TouchEvent& event)
 {
+    ASSERT(element());
+
+    if (!hasCreatedShadowSubtree())
+        return;
+
 #if PLATFORM(IOS_FAMILY)
     typedSliderThumbElement().handleTouchEvent(event);
 #elif ENABLE(TOUCH_SLIDER)
-    ASSERT(element());
+
     if (element()->isDisabledFormControl())
         return;
 
@@ -183,6 +192,8 @@
 
 void RangeInputType::disabledStateChanged()
 {
+    if (!hasCreatedShadowSubtree())
+        return;
     typedSliderThumbElement().hostDisabledStateChanged();
 }
 
@@ -189,6 +200,7 @@
 auto RangeInputType::handleKeydownEvent(KeyboardEvent& event) -> ShouldCallBaseEventHandler
 {
     ASSERT(element());
+
     if (element()->isDisabledFormControl())
         return ShouldCallBaseEventHandler::Yes;
 
@@ -241,7 +253,7 @@
     return ShouldCallBaseEventHandler::Yes;
 }
 
-void RangeInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(bool)
+void RangeInputType::createShadowSubtree()
 {
     ASSERT(needsShadowSubtree());
     ASSERT(element());
@@ -259,6 +271,10 @@
 HTMLElement* RangeInputType::sliderTrackElement() const
 {
     ASSERT(element());
+
+    if (!hasCreatedShadowSubtree())
+        return nullptr;
+
     ASSERT(element()->userAgentShadowRoot());
     ASSERT(element()->userAgentShadowRoot()->firstChild()); // container
     ASSERT(element()->userAgentShadowRoot()->firstChild()->isHTMLElement());
@@ -277,6 +293,7 @@
 
 SliderThumbElement& RangeInputType::typedSliderThumbElement() const
 {
+    ASSERT(hasCreatedShadowSubtree());
     ASSERT(sliderTrackElement()->firstChild()); // thumb
     ASSERT(sliderTrackElement()->firstChild()->isHTMLElement());
 
@@ -322,7 +339,8 @@
             if (element->hasDirtyValue())
                 element->setValue(element->value());
         }
-        typedSliderThumbElement().setPositionFromValue();
+        if (hasCreatedShadowSubtree())
+            typedSliderThumbElement().setPositionFromValue();
     }
     InputType::attributeChanged(name);
 }
@@ -339,7 +357,8 @@
         element()->setTextAsOfLastFormControlChangeEvent(value);
     }
 
-    typedSliderThumbElement().setPositionFromValue();
+    if (hasCreatedShadowSubtree())
+        typedSliderThumbElement().setPositionFromValue();
 }
 
 String RangeInputType::fallbackValue() const
@@ -368,7 +387,7 @@
 {
     m_tickMarkValuesDirty = true;
     RefPtr<HTMLElement> sliderTrackElement = this->sliderTrackElement();
-    if (sliderTrackElement->renderer())
+    if (sliderTrackElement && sliderTrackElement->renderer())
         sliderTrackElement->renderer()->setNeedsLayout();
 }
 

Modified: branches/safari-613-branch/Source/WebCore/html/RangeInputType.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/RangeInputType.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/RangeInputType.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -52,7 +52,7 @@
     void handleMouseDownEvent(MouseEvent&) final;
     ShouldCallBaseEventHandler handleKeydownEvent(KeyboardEvent&) final;
     RenderPtr<RenderElement> createInputRenderer(RenderStyle&&) final;
-    void createShadowSubtreeAndUpdateInnerTextElementEditability(bool) final;
+    void createShadowSubtree() final;
     Decimal parseToNumber(const String&, const Decimal&) const final;
     String serialize(const Decimal&) const final;
     bool accessKeyAction(bool sendMouseEvents) final;

Modified: branches/safari-613-branch/Source/WebCore/html/SearchInputType.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/SearchInputType.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/SearchInputType.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -102,13 +102,13 @@
     return true;
 }
 
-void SearchInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(bool isInnerTextElementEditable)
+void SearchInputType::createShadowSubtree()
 {
     ASSERT(needsShadowSubtree());
     ASSERT(!m_resultsButton);
     ASSERT(!m_cancelButton);
 
-    TextFieldInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(isInnerTextElementEditable);
+    TextFieldInputType::createShadowSubtree();
     RefPtr<HTMLElement> container = containerElement();
     RefPtr<HTMLElement> textWrapper = innerBlockElement();
     ASSERT(container);

Modified: branches/safari-613-branch/Source/WebCore/html/SearchInputType.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/SearchInputType.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/SearchInputType.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -51,7 +51,7 @@
     RenderPtr<RenderElement> createInputRenderer(RenderStyle&&) final;
     const AtomString& formControlType() const final;
     bool needsContainer() const final;
-    void createShadowSubtreeAndUpdateInnerTextElementEditability(bool) final;
+    void createShadowSubtree() final;
     void destroyShadowSubtree() final;
     HTMLElement* resultsButtonElement() const final;
     HTMLElement* cancelButtonElement() const final;

Modified: branches/safari-613-branch/Source/WebCore/html/TextFieldInputType.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/TextFieldInputType.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/TextFieldInputType.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -108,7 +108,11 @@
 bool TextFieldInputType::isEmptyValue() const
 {
     auto innerText = innerTextElement();
-    ASSERT(innerText);
+    if (!innerText) {
+        // Since we always create the shadow subtree if a value is set, we know
+        // that the value is empty.
+        return true;
+    }
 
     for (Text* text = TextNodeTraversal::firstWithin(*innerText); text; text = TextNodeTraversal::next(*text, innerText.get())) {
         if (text->length())
@@ -221,6 +225,8 @@
 
 void TextFieldInputType::forwardEvent(Event& event)
 {
+    ASSERT(element());
+
     if (m_innerSpinButton) {
         m_innerSpinButton->forwardEvent(event);
         if (event.defaultHandled())
@@ -231,10 +237,8 @@
     bool isBlurEvent = event.type() == eventNames().blurEvent;
     if (isFocusEvent || isBlurEvent)
         capsLockStateMayHaveChanged();
-    if (event.isMouseEvent() || isFocusEvent || isBlurEvent) {
-        ASSERT(element());
+    if (event.isMouseEvent() || isFocusEvent || isBlurEvent)
         element()->forwardEvent(event);
-    }
 }
 
 void TextFieldInputType::elementDidBlur()
@@ -316,11 +320,12 @@
     return RenderTheme::singleton().shouldHaveCapsLockIndicator(*element());
 }
 
-void TextFieldInputType::createShadowSubtreeAndUpdateInnerTextElementEditability(bool isInnerTextElementEditable)
+void TextFieldInputType::createShadowSubtree()
 {
     ASSERT(needsShadowSubtree());
     ASSERT(element());
     ASSERT(element()->shadowRoot());
+    ASSERT(!element()->shadowRoot()->hasChildNodes());
 
     ASSERT(!m_innerText);
     ASSERT(!m_innerBlock);
@@ -331,9 +336,17 @@
     Document& document = element()->document();
     bool shouldHaveSpinButton = this->shouldHaveSpinButton();
     bool shouldHaveCapsLockIndicator = this->shouldHaveCapsLockIndicator();
-    bool createsContainer = shouldHaveSpinButton || shouldHaveCapsLockIndicator || needsContainer();
+    bool shouldDrawAutoFillButton = this->shouldDrawAutoFillButton();
+#if ENABLE(DATALIST_ELEMENT)
+    bool hasDataList = element()->list();
+#endif
+    bool createsContainer = shouldHaveSpinButton || shouldHaveCapsLockIndicator || shouldDrawAutoFillButton
+#if ENABLE(DATALIST_ELEMENT)
+        || hasDataList
+#endif
+        || needsContainer();
 
-    m_innerText = TextControlInnerTextElement::create(document, isInnerTextElementEditable);
+    m_innerText = TextControlInnerTextElement::create(document, element()->isInnerTextElementEditable());
 
     if (!createsContainer) {
         element()->userAgentShadowRoot()->appendChild(ContainerNode::ChildChange::Source::Parser, *m_innerText);
@@ -358,7 +371,12 @@
 
         m_container->appendChild(ContainerNode::ChildChange::Source::Parser, *m_capsLockIndicator);
     }
+
     updateAutoFillButton();
+
+#if ENABLE(DATALIST_ELEMENT)
+    dataListMayHaveChanged();
+#endif
 }
 
 HTMLElement* TextFieldInputType::containerElement() const
@@ -373,7 +391,6 @@
 
 RefPtr<TextControlInnerTextElement> TextFieldInputType::innerTextElement() const
 {
-    ASSERT(m_innerText);
     return m_innerText;
 }
 
@@ -425,6 +442,9 @@
 
 void TextFieldInputType::disabledStateChanged()
 {
+    if (!hasCreatedShadowSubtree())
+        return;
+
     if (m_innerSpinButton)
         m_innerSpinButton->releaseCapture();
     capsLockStateMayHaveChanged();
@@ -433,6 +453,9 @@
 
 void TextFieldInputType::readOnlyStateChanged()
 {
+    if (!hasCreatedShadowSubtree())
+        return;
+
     if (m_innerSpinButton)
         m_innerSpinButton->releaseCapture();
     capsLockStateMayHaveChanged();
@@ -616,9 +639,14 @@
 
 void TextFieldInputType::updatePlaceholderText()
 {
+     ASSERT(element());
+ 
+     if (!hasCreatedShadowSubtree())
+         return;
+
     if (!supportsPlaceholder())
         return;
-    ASSERT(element());
+
     String placeholderText = element()->strippedPlaceholder();
     if (placeholderText.isEmpty()) {
         if (m_placeholder) {
@@ -816,6 +844,11 @@
 
 void TextFieldInputType::updateAutoFillButton()
 {
+    ASSERT(element());
+
+    if (!hasCreatedShadowSubtree())
+        return;
+
     capsLockStateMayHaveChanged();
 
     if (shouldDrawAutoFillButton()) {
@@ -822,7 +855,6 @@
         if (!m_container)
             createContainer();
 
-        ASSERT(element());
         AutoFillButtonType autoFillButtonType = element()->autoFillButtonType();
         if (!m_autoFillButton)
             createAutoFillButton(autoFillButtonType);
@@ -846,6 +878,9 @@
 
 void TextFieldInputType::dataListMayHaveChanged()
 {
+    if (!hasCreatedShadowSubtree())
+        return;
+
     m_cachedSuggestions = { };
 
     if (!m_dataListDropdownIndicator)

Modified: branches/safari-613-branch/Source/WebCore/html/TextFieldInputType.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/html/TextFieldInputType.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/html/TextFieldInputType.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -70,7 +70,7 @@
 #endif
 
     virtual bool needsContainer() const;
-    void createShadowSubtreeAndUpdateInnerTextElementEditability(bool) override;
+    void createShadowSubtree() override;
     void destroyShadowSubtree() override;
     void attributeChanged(const QualifiedName&) override;
     void disabledStateChanged() final;

Modified: branches/safari-613-branch/Source/WebCore/svg/SVGDocumentExtensions.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/svg/SVGDocumentExtensions.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/svg/SVGDocumentExtensions.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -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: branches/safari-613-branch/Source/WebCore/svg/SVGDocumentExtensions.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/svg/SVGDocumentExtensions.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/svg/SVGDocumentExtensions.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -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: branches/safari-613-branch/Source/WebCore/svg/SVGUseElement.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/svg/SVGUseElement.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/svg/SVGUseElement.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -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: branches/safari-613-branch/Source/WebCore/svg/SVGUseElement.h (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/svg/SVGUseElement.h	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/svg/SVGUseElement.h	2022-04-04 21:56:00 UTC (rev 292334)
@@ -38,8 +38,7 @@
     virtual ~SVGUseElement();
 
     void invalidateShadowTree();
-    bool shadowTreeNeedsUpdate() const { return m_shadowTreeNeedsUpdate; }
-    void updateShadowTree();
+    void updateUserAgentShadowTree() final;
 
     RenderElement* rendererClipChild() const;
 

Modified: branches/safari-613-branch/Source/WebCore/testing/Internals.cpp (292333 => 292334)


--- branches/safari-613-branch/Source/WebCore/testing/Internals.cpp	2022-04-04 21:55:52 UTC (rev 292333)
+++ branches/safari-613-branch/Source/WebCore/testing/Internals.cpp	2022-04-04 21:56:00 UTC (rev 292334)
@@ -1249,6 +1249,10 @@
 
 Node* Internals::shadowRoot(Element& host)
 {
+    if (host.document().hasElementWithPendingUserAgentShadowTreeUpdate(host)) {
+        host.updateUserAgentShadowTree();
+        host.document().removeElementWithPendingUserAgentShadowTreeUpdate(host);
+    }
     return host.shadowRoot();
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to