From de64e62a2a5041b0d59b985feba7e080993c36b8 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 11 Apr 2024 03:32:30 -0700 Subject: [PATCH] Add serializable shadow roots and getHTML() https://bugs.webkit.org/show_bug.cgi?id=271343 rdar://125513986 Reviewed by Ryosuke Niwa. This implements https://github.com/whatwg/html/pull/10139 as amended by https://github.com/whatwg/html/pull/10260. This also changes the way a shadow root is serialized to avoid creating a template element. The API is guarded by DeclarativeShadowRootsSerializerAPIsEnabled just in case there is a need to disable it without removing the code. Thanks to Chris Dumez for his help with Vector>. WPT tests are synchronized up to and including this commit: https://github.com/web-platform-tests/wpt/commit/dd2e51de9985a1c9d381607c2b314b6562545d37 This also adjusts the copyright lines to match the commit log for the relevant files. * LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/declarative-shadow-dom-repeats-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/declarative-shadow-dom-repeats.html: * LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml-ordering-expected.txt: Added. * LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml-ordering.html: Added. * LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml.html: Added. * LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml.tentative-expected.txt: Removed. * LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml.tentative.html: Removed. * LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/w3c-import.log: * LayoutTests/tests-options.json: * Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: * Source/WebCore/CMakeLists.txt: * Source/WebCore/DerivedSources-input.xcfilelist: * Source/WebCore/DerivedSources-output.xcfilelist: * Source/WebCore/DerivedSources.make: * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/Element.cpp: (WebCore::Element::getHTML const): * Source/WebCore/dom/Element.h: * Source/WebCore/dom/GetHTMLOptions.h: Added. * Source/WebCore/dom/GetHTMLOptions.idl: Added. * Source/WebCore/dom/InnerHTML.idl: * Source/WebCore/dom/ShadowRoot.cpp: (WebCore::ShadowRoot::ShadowRoot): (WebCore::ShadowRoot::getHTML const): (WebCore::ShadowRoot::cloneNodeInternal): * Source/WebCore/dom/ShadowRoot.h: * Source/WebCore/dom/ShadowRoot.idl: * Source/WebCore/dom/ShadowRootInit.h: * Source/WebCore/dom/ShadowRootInit.idl: * Source/WebCore/editing/MarkupAccumulator.cpp: (WebCore::MarkupAccumulator::MarkupAccumulator): (WebCore::MarkupAccumulator::shouldIncludeShadowRoots const): (WebCore::MarkupAccumulator::includeShadowRoot const): (WebCore::MarkupAccumulator::serializeNodesWithNamespaces): (WebCore::MarkupAccumulator::replacementElement): * Source/WebCore/editing/MarkupAccumulator.h: (WebCore::MarkupAccumulator::MarkupAccumulator): * Source/WebCore/editing/markup.cpp: (WebCore::serializeFragment): * Source/WebCore/editing/markup.h: (WebCore::serializeFragment): * Source/WebCore/html/HTMLAttributeNames.in: * Source/WebCore/html/HTMLTemplateElement.cpp: (WebCore::HTMLTemplateElement::attachAsDeclarativeShadowRootIfNeeded): * Source/WebCore/html/HTMLTemplateElement.idl: * Source/WebCore/html/parser/HTMLConstructionSite.cpp: (WebCore::HTMLConstructionSite::insertHTMLTemplateElement): * Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp: (WebCore::LegacyWebArchive::create): Canonical link: https://commits.webkit.org/277374@main --- ...eclarative-shadow-dom-repeats-expected.txt | 2 +- .../declarative-shadow-dom-repeats.html | 33 +- .../declarative/gethtml-expected.txt | 3642 +++++++++++++++++ .../declarative/gethtml-ordering-expected.txt | 5 + .../declarative/gethtml-ordering.html | 69 + .../shadow-dom/declarative/gethtml.html | 142 + .../gethtml.tentative-expected.txt | 1822 --------- .../declarative/gethtml.tentative.html | 126 - .../shadow-dom/declarative/w3c-import.log | 3 +- LayoutTests/tests-options.json | 3 + .../Preferences/UnifiedWebPreferences.yaml | 14 + Source/WebCore/CMakeLists.txt | 1 + .../WebCore/DerivedSources-input.xcfilelist | 1 + .../WebCore/DerivedSources-output.xcfilelist | 2 + Source/WebCore/DerivedSources.make | 1 + Source/WebCore/Headers.cmake | 1 + Source/WebCore/Sources.txt | 1 + .../WebCore/WebCore.xcodeproj/project.pbxproj | 6 + Source/WebCore/dom/Element.cpp | 18 +- Source/WebCore/dom/Element.h | 9 +- Source/WebCore/dom/GetHTMLOptions.h | 37 + Source/WebCore/dom/GetHTMLOptions.idl | 31 + Source/WebCore/dom/InnerHTML.idl | 5 +- Source/WebCore/dom/ShadowRoot.cpp | 18 +- Source/WebCore/dom/ShadowRoot.h | 13 +- Source/WebCore/dom/ShadowRoot.idl | 3 +- Source/WebCore/dom/ShadowRootInit.h | 3 +- Source/WebCore/dom/ShadowRootInit.idl | 3 +- Source/WebCore/editing/MarkupAccumulator.cpp | 103 +- Source/WebCore/editing/MarkupAccumulator.h | 16 +- Source/WebCore/editing/markup.cpp | 6 +- Source/WebCore/editing/markup.h | 7 +- Source/WebCore/html/HTMLAttributeNames.in | 1 + Source/WebCore/html/HTMLTemplateElement.cpp | 21 +- Source/WebCore/html/HTMLTemplateElement.idl | 1 + .../html/parser/HTMLConstructionSite.cpp | 15 +- .../loader/archive/cf/LegacyWebArchive.cpp | 6 +- 37 files changed, 4152 insertions(+), 2038 deletions(-) create mode 100644 LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml-expected.txt create mode 100644 LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml-ordering-expected.txt create mode 100644 LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml-ordering.html create mode 100644 LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml.html delete mode 100644 LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml.tentative-expected.txt delete mode 100644 LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/gethtml.tentative.html create mode 100644 Source/WebCore/dom/GetHTMLOptions.h create mode 100644 Source/WebCore/dom/GetHTMLOptions.idl diff --git a/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/declarative-shadow-dom-repeats-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/declarative-shadow-dom-repeats-expected.txt index 466284d00624c..cc1d815373631 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/declarative-shadow-dom-repeats-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/declarative-shadow-dom-repeats-expected.txt @@ -1,5 +1,5 @@ PASS Repeated declarative shadow roots keep only the first -PASS Calling attachShadow() on declarative shadow root must match type +PASS Calling attachShadow() on declarative shadow root must match mode PASS Calling attachShadow() on declarative shadow root must match all parameters diff --git a/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/declarative-shadow-dom-repeats.html b/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/declarative-shadow-dom-repeats.html index 4f1b4c748e8b7..a2bfa488fb76f 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/declarative-shadow-dom-repeats.html +++ b/LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/declarative-shadow-dom-repeats.html @@ -46,35 +46,48 @@ test((t) => { assert_throws_dom("NotSupportedError",() => { open1.attachShadow({mode: "closed"}); - },'Mismatched shadow root type should throw'); + },'Mismatched shadow root mode should throw'); const initialShadow = open1.shadowRoot; const shadow = open1.attachShadow({mode: "open"}); // Shouldn't throw assert_equals(shadow,initialShadow,'Same shadow should be returned'); assert_equals(shadow.textContent,'','Shadow should be empty'); -},'Calling attachShadow() on declarative shadow root must match type'); +},'Calling attachShadow() on declarative shadow root must match mode');
-