[webkit-changes] [WebKit/WebKit] 2539a9: Expose importNode on ShadowRoot and maintain scope...
Ryosuke Niwa
noreply at github.com
Tue Dec 10 14:33:02 PST 2024
Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 2539a900b51185feffb61785523868aa20ca1482
https://github.com/WebKit/WebKit/commit/2539a900b51185feffb61785523868aa20ca1482
Author: Ryosuke Niwa <rniwa at webkit.org>
Date: 2024-12-10 (Tue, 10 Dec 2024)
Changed paths:
A LayoutTests/imported/w3c/web-platform-tests/custom-elements/scoped-registry/ShadowRoot-importNode.tentative-expected.txt
A LayoutTests/imported/w3c/web-platform-tests/custom-elements/scoped-registry/ShadowRoot-importNode.tentative.html
M LayoutTests/imported/w3c/web-platform-tests/custom-elements/scoped-registry/ShadowRoot-innerHTML-upgrade.tentative-expected.txt
A LayoutTests/imported/w3c/web-platform-tests/custom-elements/scoped-registry/ShadowRoot-innerHTML.tentative-expected.txt
A LayoutTests/imported/w3c/web-platform-tests/custom-elements/scoped-registry/ShadowRoot-innerHTML.tentative.html
M Source/WebCore/bindings/js/JSCustomElementInterface.cpp
M Source/WebCore/bindings/js/JSHTMLElementCustom.cpp
M Source/WebCore/dom/Attr.cpp
M Source/WebCore/dom/Attr.h
M Source/WebCore/dom/CDATASection.cpp
M Source/WebCore/dom/CDATASection.h
M Source/WebCore/dom/Comment.cpp
M Source/WebCore/dom/Comment.h
M Source/WebCore/dom/ContainerNode.cpp
M Source/WebCore/dom/ContainerNode.h
M Source/WebCore/dom/CustomElementRegistry.cpp
M Source/WebCore/dom/CustomElementRegistry.h
M Source/WebCore/dom/Document.cpp
M Source/WebCore/dom/Document.h
M Source/WebCore/dom/DocumentFragment.cpp
M Source/WebCore/dom/DocumentFragment.h
M Source/WebCore/dom/DocumentType.cpp
M Source/WebCore/dom/DocumentType.h
M Source/WebCore/dom/Element.cpp
M Source/WebCore/dom/Element.h
M Source/WebCore/dom/Node.h
M Source/WebCore/dom/ProcessingInstruction.cpp
M Source/WebCore/dom/ProcessingInstruction.h
M Source/WebCore/dom/ShadowRoot.cpp
M Source/WebCore/dom/ShadowRoot.h
M Source/WebCore/dom/ShadowRoot.idl
M Source/WebCore/dom/Text.cpp
M Source/WebCore/dom/Text.h
M Source/WebCore/dom/TreeScope.cpp
M Source/WebCore/dom/TreeScope.h
M Source/WebCore/editing/markup.cpp
M Source/WebCore/editing/markup.h
M Source/WebCore/html/AttachmentAssociatedElement.h
M Source/WebCore/html/HTMLImageElement.cpp
M Source/WebCore/html/HTMLImageElement.h
M Source/WebCore/html/HTMLInputElement.cpp
M Source/WebCore/html/HTMLInputElement.h
M Source/WebCore/html/HTMLScriptElement.cpp
M Source/WebCore/html/HTMLScriptElement.h
M Source/WebCore/html/HTMLSourceElement.cpp
M Source/WebCore/html/HTMLSourceElement.h
M Source/WebCore/html/HTMLTemplateElement.cpp
M Source/WebCore/html/HTMLTemplateElement.h
M Source/WebCore/html/parser/HTMLConstructionSite.cpp
M Source/WebCore/html/parser/HTMLConstructionSite.h
M Source/WebCore/html/parser/HTMLDocumentParser.cpp
M Source/WebCore/html/parser/HTMLDocumentParser.h
M Source/WebCore/html/parser/HTMLTreeBuilder.cpp
M Source/WebCore/html/parser/HTMLTreeBuilder.h
M Source/WebCore/html/shadow/SliderThumbElement.cpp
M Source/WebCore/html/shadow/SliderThumbElement.h
M Source/WebCore/html/track/TextTrackCue.cpp
M Source/WebCore/html/track/VTTCue.cpp
M Source/WebCore/html/track/WebVTTElement.cpp
M Source/WebCore/html/track/WebVTTElement.h
M Source/WebCore/svg/SVGScriptElement.cpp
M Source/WebCore/svg/SVGScriptElement.h
M Source/WebCore/svg/SVGUseElement.cpp
Log Message:
-----------
Expose importNode on ShadowRoot and maintain scoped registry association with disconnected nodes
https://bugs.webkit.org/show_bug.cgi?id=283431
Reviewed by Chris Dumez.
This PR adds ShadowRoot.prototype.importNode and association of scoped custom element registry with disconnected nodes.
Specifically, when disconnected nodes maintain association with the registry of the last shadow tree to which it belonged.
To maintain the association of an element with a scoped custom element registry, this PR introduces the scoped custom element map.
An element is added to this map whenever it's synchronously created with a scoped custom element registry or removed from a shadow
tree which uses a scoped custom element registry, and an element is removed from the map when it's inserted into a shadow tree or
a document tree. An element has ElementStateFlag::UsesScopedCustomElementRegistryMap set when it's present in this this hash map
so that we can avoid hash map look up in common cases when the element is in a document tree or a shadow tree, or otherwise not
associated with a scoped custom element registry.
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/scoped-registry/ShadowRoot-importNode.tentative-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/scoped-registry/ShadowRoot-importNode.tentative.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/scoped-registry/ShadowRoot-innerHTML.tentative-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/custom-elements/scoped-registry/ShadowRoot-innerHTML.tentative.html: Added.
* Source/WebCore/bindings/js/JSCustomElementInterface.cpp:
(WebCore::JSCustomElementInterface::tryToConstructCustomElement): Fixed a bug that we were not resetting the active custom
element registry when the global scope / previous scope wasn't set.
(WebCore::JSCustomElementInterface::upgradeElement): Ditto.
* Source/WebCore/bindings/js/JSHTMLElementCustom.cpp:
(WebCore::constructJSHTMLElement):
* Source/WebCore/dom/Attr.cpp:
(WebCore::Attr::cloneNodeInternal):
* Source/WebCore/dom/Attr.h:
* Source/WebCore/dom/CDATASection.cpp:
(WebCore::CDATASection::cloneNodeInternal):
* Source/WebCore/dom/CDATASection.h:
* Source/WebCore/dom/Comment.cpp:
(WebCore::Comment::cloneNodeInternal):
* Source/WebCore/dom/Comment.h:
* Source/WebCore/dom/ContainerNode.cpp:
(WebCore::ContainerNode::cloneChildNodes): Now takes TreeScope to clone nodes to.
* Source/WebCore/dom/ContainerNode.h:
* Source/WebCore/dom/CustomElementRegistry.cpp:
(WebCore::CustomElementRegistry::addToScopedCustomElementRegistryMap): Added.
(WebCore::CustomElementRegistry::removeFromScopedCustomElementRegistryMap): Added.
(WebCore::CustomElementRegistry::scopedCustomElementRegistryMap): Added.
* Source/WebCore/dom/CustomElementRegistry.h:
(WebCore::CustomElementRegistry::isScoped const): Added.
(WebCore::CustomElementRegistry::registryForElement): Added.
(WebCore::CustomElementRegistry::registryForNodeOrTreeScope): Added.
* Source/WebCore/dom/Document.cpp:
(WebCore::createUpgradeCandidateElement): Now takes a TreeScope instead of a Document.
(WebCore::createHTMLElementWithNameValidation):
(WebCore::Document::importNode): Moved to TreeScope.cpp
(WebCore::createFallbackHTMLElement): Now takes a TreeScope instead of a Document.
(WebCore::TreeScope::createElement):
(WebCore::Document::setActiveCustomElementRegistry): Now takes a pointer instead of a reference since we want to able to reset the
value to nullptr when we're done creating or upgrading an element.
(WebCore::Document::cloneNodeInternal): Now takes a TreeScope instead of a Document.
* Source/WebCore/dom/Document.h:
* Source/WebCore/dom/DocumentFragment.cpp:
(WebCore::DocumentFragment::cloneNodeInternal): Ditto.
(WebCore::DocumentFragment::parseHTML): Now takes CustomElementRegistry as an optional argument.
* Source/WebCore/dom/DocumentFragment.h:
(WebCore::DocumentFragment::parseHTML):
* Source/WebCore/dom/DocumentType.cpp:
(WebCore::DocumentType::cloneNodeInternal):
* Source/WebCore/dom/DocumentType.h:
* Source/WebCore/dom/Element.cpp:
(WebCore::Element::cloneNodeInternal): Now takes a TreeScope instead of a Document.
(WebCore::Element::cloneShadowTreeIfPossible):
(WebCore::Element::cloneElementWithChildren): Ditto.
(WebCore::Element::cloneElementWithoutChildren): Ditto.
(WebCore::Element::cloneElementWithoutAttributesAndChildren): Ditto.
(WebCore::Element::insertedIntoAncestor): Removes the element from the scoped custom element registry map if it's inserted into
a TreeScope.
(WebCore::Element::removedFromAncestor): Adds the element to the scoped custom element registry map if the registry of the tree
to which this element belonged before the removal is scoped.
(WebCore::Element::replaceChildrenWithMarkup): Calls createFragmentForInnerOuterHTML with an appropriate registry.
(WebCore::Element::setOuterHTML): Ditto.
(WebCore::Element::insertAdjacentHTML): Ditto.
* Source/WebCore/dom/Element.h:
* Source/WebCore/dom/Node.h:
(WebCore::Node::cloneNode):
(WebCore::Node::usesScopedCustomElementRegistryMap const): Added.
(WebCore::Node::setUsesScopedCustomElementRegistryMap): Added.
(WebCore::Node::clearUsesScopedCustomElementRegistryMap): Added.
(WebCore::Node::ElementStateFlag): Added UsesScopedCustomElementRegistryMap as a new enum value.
* Source/WebCore/dom/ProcessingInstruction.cpp:
(WebCore::ProcessingInstruction::cloneNodeInternal):
* Source/WebCore/dom/ProcessingInstruction.h:
* Source/WebCore/dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::replaceChildrenWithMarkup): Calls createFragmentForInnerOuterHTML with the custom element registry
associated with this shadow tree.
(WebCore::ShadowRoot::cloneNodeInternal):
* Source/WebCore/dom/ShadowRoot.h:
* Source/WebCore/dom/ShadowRoot.idl:
* Source/WebCore/dom/Text.cpp:
(WebCore::Text::cloneNodeInternal):
* Source/WebCore/dom/Text.h:
* Source/WebCore/dom/TreeScope.cpp:
(WebCore::TreeScope::importNode): Moved from Document.
* Source/WebCore/dom/TreeScope.h:
* Source/WebCore/editing/markup.cpp:
(WebCore::createFragmentForMarkup): Now optionally takes a custom element registry as an argument.
(WebCore::createFragmentForInnerOuterHTML): Ditto.
* Source/WebCore/editing/markup.h:
* Source/WebCore/html/AttachmentAssociatedElement.h:
* Source/WebCore/html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::cloneElementWithoutAttributesAndChildren):
* Source/WebCore/html/HTMLImageElement.h:
* Source/WebCore/html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::cloneElementWithoutAttributesAndChildren):
* Source/WebCore/html/HTMLInputElement.h:
* Source/WebCore/html/HTMLScriptElement.cpp:
(WebCore::HTMLScriptElement::cloneElementWithoutAttributesAndChildren):
* Source/WebCore/html/HTMLScriptElement.h:
* Source/WebCore/html/HTMLSourceElement.cpp:
(WebCore::HTMLSourceElement::cloneElementWithoutAttributesAndChildren):
* Source/WebCore/html/HTMLSourceElement.h:
* Source/WebCore/html/HTMLTemplateElement.cpp:
(WebCore::HTMLTemplateElement::cloneNodeInternal):
* Source/WebCore/html/HTMLTemplateElement.h:
* Source/WebCore/html/parser/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::HTMLConstructionSite): Now takes a custom element registry as an argument.
(WebCore::HTMLConstructionSite::createHTMLElementOrFindCustomElementInterface): Add the newly created element to the scoped custom
element map if the registry we used is a scoped custom element registry.
* Source/WebCore/html/parser/HTMLConstructionSite.h:
* Source/WebCore/html/parser/HTMLDocumentParser.cpp:
(WebCore::HTMLDocumentParser::HTMLDocumentParser): Now takes CustomElementRegistry as an argument.
(WebCore::HTMLDocumentParser::create): Ditto.
(WebCore::HTMLDocumentParser::parseDocumentFragment): Ditto.
* Source/WebCore/html/parser/HTMLDocumentParser.h:
(WebCore::HTMLDocumentParser::parseDocumentFragment): Ditto.
* Source/WebCore/html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::HTMLTreeBuilder): Ditto.
* Source/WebCore/html/parser/HTMLTreeBuilder.h:
* Source/WebCore/html/shadow/SliderThumbElement.cpp:
(WebCore::SliderThumbElement::cloneElementWithoutAttributesAndChildren):
* Source/WebCore/html/shadow/SliderThumbElement.h:
* Source/WebCore/html/track/TextTrackCue.cpp:
(WebCore::TextTrackCue::create):
(WebCore::TextTrackCue::getCueAsHTML):
(WebCore::TextTrackCue::rebuildDisplayTree):
* Source/WebCore/html/track/VTTCue.cpp:
(WebCore::VTTCue::createCueRenderingTree):
* Source/WebCore/html/track/WebVTTElement.cpp:
(WebCore::WebVTTElement::cloneElementWithoutAttributesAndChildren):
* Source/WebCore/html/track/WebVTTElement.h:
* Source/WebCore/svg/SVGScriptElement.cpp:
(WebCore::SVGScriptElement::cloneElementWithoutAttributesAndChildren):
* Source/WebCore/svg/SVGScriptElement.h:
* Source/WebCore/svg/SVGUseElement.cpp:
(WebCore::cloneDataAndChildren):
Canonical link: https://commits.webkit.org/287633@main
To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications
More information about the webkit-changes
mailing list