Skip to content
Permalink
Browse files
Add SlotAssignmentMode to ShadowRootInit and ShadowRoot
https://bugs.webkit.org/show_bug.cgi?id=243635

Reviewed by Cameron McCormack.

Added slotAssignment to ShadowRootInit and ShadowRoot.

* LayoutTests/imported/w3c/web-platform-tests/dom/idlharness.window-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/shadow-dom/imperative-slot-api-expected.txt:
* 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:
* Source/WebCore/dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::ShadowRoot):
* Source/WebCore/dom/ShadowRoot.h:
(WebCore::ShadowRoot::slotAssignmentMode): Added.
* Source/WebCore/dom/ShadowRoot.idl:
* Source/WebCore/dom/ShadowRootInit.h:
* Source/WebCore/dom/ShadowRootInit.idl:
* Source/WebCore/dom/SlotAssignmentMode.h: Added.
* Source/WebCore/dom/SlotAssignmentMode.idl: Added.

Canonical link: https://commits.webkit.org/253198@main
  • Loading branch information
rniwa committed Aug 8, 2022
1 parent 43e4f7c commit d94de81283e2f99b9a8bce3f6d605a4095e19a35
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 7 deletions.
@@ -876,7 +876,7 @@ PASS ShadowRoot interface: existence and properties of interface prototype objec
PASS ShadowRoot interface: existence and properties of interface prototype object's @@unscopables property
PASS ShadowRoot interface: attribute mode
PASS ShadowRoot interface: attribute delegatesFocus
FAIL ShadowRoot interface: attribute slotAssignment assert_true: The prototype object must have a property "slotAssignment" expected true got false
PASS ShadowRoot interface: attribute slotAssignment
PASS ShadowRoot interface: attribute host
PASS ShadowRoot interface: attribute onslotchange
PASS Element interface: existence and properties of interface object
@@ -1,5 +1,5 @@

FAIL attachShadow can take slotAssignment parameter. assert_equals: slotAssignment should return "manual" expected (string) "manual" but got (undefined) undefined
PASS attachShadow can take slotAssignment parameter.
FAIL slot.attach() should take variadic not sequence. tTree.s1.assign is not a function. (In 'tTree.s1.assign(c1,c2)', 'tTree.s1.assign' is undefined)
FAIL Imperative slot API can assign nodes in manual slot assignment. assert_equals: expected null but got Element node <slot id="s1"></slot>
FAIL Order of slottables is preserved in manual slot assignment. tTree.s1.assign is not a function. (In 'tTree.s1.assign(tTree.c2, tTree.c3, tTree.c1)', 'tTree.s1.assign' is undefined)
@@ -981,6 +981,7 @@ set(WebCore_NON_SVG_IDL_FILES
dom/ShadowRoot.idl
dom/ShadowRootInit.idl
dom/ShadowRootMode.idl
dom/SlotAssignmentMode.idl
dom/Slotable.idl
dom/StaticRange.idl
dom/StringCallback.idl
@@ -1127,6 +1127,7 @@ $(PROJECT_DIR)/dom/SecurityPolicyViolationEvent.idl
$(PROJECT_DIR)/dom/ShadowRoot.idl
$(PROJECT_DIR)/dom/ShadowRootInit.idl
$(PROJECT_DIR)/dom/ShadowRootMode.idl
$(PROJECT_DIR)/dom/SlotAssignmentMode.idl
$(PROJECT_DIR)/dom/Slotable.idl
$(PROJECT_DIR)/dom/StaticRange.idl
$(PROJECT_DIR)/dom/StringCallback.idl
@@ -2552,6 +2552,8 @@ $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSSharedWorker.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSSharedWorker.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSSharedWorkerGlobalScope.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSSharedWorkerGlobalScope.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSSlotAssignmentMode.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSSlotAssignmentMode.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSSlotable.cpp
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSSlotable.h
$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSSourceBuffer.cpp
@@ -983,6 +983,7 @@ JS_BINDING_IDLS := \
$(WebCore)/dom/ShadowRoot.idl \
$(WebCore)/dom/ShadowRootInit.idl \
$(WebCore)/dom/ShadowRootMode.idl \
$(WebCore)/dom/SlotAssignmentMode.idl \
$(WebCore)/dom/Slotable.idl \
$(WebCore)/dom/StaticRange.idl \
$(WebCore)/dom/StringCallback.idl \
@@ -736,6 +736,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
dom/ShadowRootMode.h
dom/SimpleRange.h
dom/SimulatedClickOptions.h
dom/SlotAssignmentMode.h
dom/SpaceSplitString.h
dom/StaticRange.h
dom/StyledElement.h
@@ -3940,6 +3940,7 @@ JSShadowRootMode.cpp
JSShareData.cpp
JSSharedWorker.cpp
JSSharedWorkerGlobalScope.cpp
JSSlotAssignmentMode.cpp
JSSlotable.cpp
JSSourceBuffer.cpp
JSSourceBufferList.cpp
@@ -3329,6 +3329,7 @@
9B2D8A7914997CCF00ECEF3E /* UndoStep.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B2D8A7814997CCF00ECEF3E /* UndoStep.h */; settings = {ATTRIBUTES = (Private, ); }; };
9B32CDA913DF7FA900F34D13 /* RenderedPosition.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B32CDA713DF7FA900F34D13 /* RenderedPosition.h */; };
9B417064125662B3006B28FC /* ApplyBlockElementCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B417062125662B3006B28FC /* ApplyBlockElementCommand.h */; };
9B4F0636289F3882007831DB /* SlotAssignmentMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B4F0630289F2F08007831DB /* SlotAssignmentMode.h */; settings = {ATTRIBUTES = (Private, ); }; };
9B50B1DE17CD4C0F0087F63C /* FormNamedItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B50B1DC17CD4C0F0087F63C /* FormNamedItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
9B532EA41BA928570038A827 /* SlotAssignment.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B532EA21BA928570038A827 /* SlotAssignment.h */; };
9B69D3B51B98FFE900E3512B /* HTMLSlotElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B69D3B31B98FFE900E3512B /* HTMLSlotElement.h */; };
@@ -13649,6 +13650,8 @@
9B417062125662B3006B28FC /* ApplyBlockElementCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplyBlockElementCommand.h; sourceTree = "<group>"; };
9B417063125662B3006B28FC /* ApplyBlockElementCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ApplyBlockElementCommand.cpp; sourceTree = "<group>"; };
9B4376EF2117E872009D03A0 /* ThrowOnDynamicMarkupInsertionCountIncrementer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ThrowOnDynamicMarkupInsertionCountIncrementer.h; sourceTree = "<group>"; };
9B4F0630289F2F08007831DB /* SlotAssignmentMode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SlotAssignmentMode.h; sourceTree = "<group>"; };
9B4F0632289F2F08007831DB /* SlotAssignmentMode.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = SlotAssignmentMode.idl; sourceTree = "<group>"; };
9B50B1DC17CD4C0F0087F63C /* FormNamedItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FormNamedItem.h; sourceTree = "<group>"; };
9B532EA11BA928570038A827 /* SlotAssignment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SlotAssignment.cpp; sourceTree = "<group>"; };
9B532EA21BA928570038A827 /* SlotAssignment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SlotAssignment.h; sourceTree = "<group>"; };
@@ -33275,6 +33278,8 @@
835F8B261D2D90BA00E408EC /* Slotable.idl */,
9B532EA11BA928570038A827 /* SlotAssignment.cpp */,
9B532EA21BA928570038A827 /* SlotAssignment.h */,
9B4F0630289F2F08007831DB /* SlotAssignmentMode.h */,
9B4F0632289F2F08007831DB /* SlotAssignmentMode.idl */,
D01A27AB10C9BFD800026A42 /* SpaceSplitString.cpp */,
D01A27AC10C9BFD800026A42 /* SpaceSplitString.h */,
BC7FA62C0D1F0EFF00DB22A9 /* StaticNodeList.cpp */,
@@ -37906,6 +37911,7 @@
C149D567242EB84A003EBB12 /* SleepDisablerIdentifier.h in Headers */,
4150F9F112B6E0E70008C860 /* SliderThumbElement.h in Headers */,
9B532EA41BA928570038A827 /* SlotAssignment.h in Headers */,
9B4F0636289F3882007831DB /* SlotAssignmentMode.h in Headers */,
4B6FA6F40C39E48C00087011 /* SmartReplace.h in Headers */,
E4AFD00C0DAF335400F5F55C /* SMILTime.h in Headers */,
E4AFD00E0DAF335500F5F55C /* SMILTimeContainer.h in Headers */,
@@ -2670,7 +2670,7 @@ ExceptionOr<ShadowRoot&> Element::attachShadow(const ShadowRootInit& init)
return Exception { NotSupportedError };
if (init.mode == ShadowRootMode::UserAgent)
return Exception { TypeError };
auto shadow = ShadowRoot::create(document(), init.mode, init.delegatesFocus ? ShadowRoot::DelegatesFocus::Yes : ShadowRoot::DelegatesFocus::No);
auto shadow = ShadowRoot::create(document(), init.mode, init.slotAssignment, init.delegatesFocus ? ShadowRoot::DelegatesFocus::Yes : ShadowRoot::DelegatesFocus::No);
auto& result = shadow.get();
addShadowRoot(WTFMove(shadow));
return result;
@@ -65,11 +65,12 @@ static_assert(sizeof(ShadowRoot) == sizeof(SameSizeAsShadowRoot), "shadowroot sh
static_assert(sizeof(WeakPtr<Element>) == sizeof(void*), "WeakPtr should be same size as raw pointer");
#endif

ShadowRoot::ShadowRoot(Document& document, ShadowRootMode type, DelegatesFocus delegatesFocus)
ShadowRoot::ShadowRoot(Document& document, ShadowRootMode type, SlotAssignmentMode assignmentMode, DelegatesFocus delegatesFocus)
: DocumentFragment(document, CreateShadowRoot)
, TreeScope(*this, document)
, m_delegatesFocus(delegatesFocus == DelegatesFocus::Yes)
, m_type(type)
, m_slotAssignmentMode(assignmentMode)
, m_styleScope(makeUnique<Style::Scope>(*this))
{
if (type == ShadowRootMode::UserAgent)
@@ -34,6 +34,7 @@
#include "HTMLVideoElement.h"
#endif
#include "ShadowRootMode.h"
#include "SlotAssignmentMode.h"
#include <wtf/HashMap.h>

namespace WebCore {
@@ -49,9 +50,10 @@ class ShadowRoot final : public DocumentFragment, public TreeScope {

enum class DelegatesFocus : uint8_t { Yes, No };

static Ref<ShadowRoot> create(Document& document, ShadowRootMode type, DelegatesFocus delegatesFocus = DelegatesFocus::No)
static Ref<ShadowRoot> create(Document& document, ShadowRootMode type,
SlotAssignmentMode assignmentMode = SlotAssignmentMode::Named, DelegatesFocus delegatesFocus = DelegatesFocus::No)
{
return adoptRef(*new ShadowRoot(document, type, delegatesFocus));
return adoptRef(*new ShadowRoot(document, type, assignmentMode, delegatesFocus));
}

static Ref<ShadowRoot> create(Document& document, std::unique_ptr<SlotAssignment>&& assignment)
@@ -87,6 +89,7 @@ class ShadowRoot final : public DocumentFragment, public TreeScope {

void removeAllEventListeners() override;

SlotAssignmentMode slotAssignmentMode() const { return m_slotAssignmentMode; }
HTMLSlotElement* findAssignedSlot(const Node&);

void renameSlotElement(HTMLSlotElement&, const AtomString& oldName, const AtomString& newName);
@@ -118,7 +121,7 @@ class ShadowRoot final : public DocumentFragment, public TreeScope {
Vector<RefPtr<WebAnimation>> getAnimations();

private:
ShadowRoot(Document&, ShadowRootMode, DelegatesFocus);
ShadowRoot(Document&, ShadowRootMode, SlotAssignmentMode, DelegatesFocus);
ShadowRoot(Document&, std::unique_ptr<SlotAssignment>&&);

bool childTypeAllowed(NodeType) const override;
@@ -135,6 +138,7 @@ class ShadowRoot final : public DocumentFragment, public TreeScope {
bool m_delegatesFocus { false };
bool m_containsFocusedElement { false };
ShadowRootMode m_type { ShadowRootMode::UserAgent };
SlotAssignmentMode m_slotAssignmentMode { SlotAssignmentMode::Named };

WeakPtr<Element> m_host;
RefPtr<StyleSheetList> m_styleSheetList;
@@ -29,6 +29,7 @@
] interface ShadowRoot : DocumentFragment {
readonly attribute ShadowRootMode mode;
readonly attribute boolean delegatesFocus;
[ImplementedAs=slotAssignmentMode, EnabledBySetting=ImperativeSlotAPIEnabled] readonly attribute SlotAssignmentMode slotAssignment;
readonly attribute Element host;
attribute EventHandler onslotchange;
};
@@ -26,12 +26,14 @@
#pragma once

#include "ShadowRootMode.h"
#include "SlotAssignmentMode.h"

namespace WebCore {

struct ShadowRootInit {
ShadowRootMode mode;
bool delegatesFocus { false };
SlotAssignmentMode slotAssignment { SlotAssignmentMode::Named };
};

}
@@ -26,4 +26,5 @@
dictionary ShadowRootInit {
required ShadowRootMode mode;
boolean delegatesFocus = false;
SlotAssignmentMode slotAssignment = "named";
};
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

namespace WebCore {

enum class SlotAssignmentMode : uint8_t {
Manual,
Named,
};

}

@@ -0,0 +1,29 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

enum SlotAssignmentMode {
"manual",
"named"
};

0 comments on commit d94de81

Please sign in to comment.