Skip to content

Commit

Permalink
Rename Cloneable to Clonable to align with Web Specification wording
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=267634
rdar://problem/121516711

Reviewed by Ryosuke Niwa.

This patch is just rename of `cloneable` to `clonable` as per web-specification [1]:

[1] https://dom.spec.whatwg.org/#shadowroot-clonable

* Source/WebCore/dom/ShadowRoot.cpp:
(ShadowRoot::ShadowRoot):
(ShadowRoot::cloneNodeInternal):
* Source/WebCore/dom/ShadowRoot.h:
* Source/WebCore/dom/ShadowRoot.idl:
* Source/WebCore/dom/ShadowRootInit.h:
* LayoutTests/fast/shadow-dom/clonable-shadow-root.html: Renamed from
LayoutTests/fast/shadow-dom/cloneable-shadow-root.html and rebaselined
* LayoutTests/fast/shadow-dom/clonable-shadow-root-expected.txt: Renamed from
LayoutTests/fast/shadow-dom/cloneable-shadow-root-expected.txt and rebaselined

Canonical link: https://commits.webkit.org/274063@main
  • Loading branch information
Ahmad-S792 authored and rniwa committed Feb 4, 2024
1 parent 817b933 commit 55c8a56
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

PASS ShadowRoot in "open" mode is not cloneable by default
PASS ShadowRoot in "closed" mode is not cloneable by default
PASS ShadowRoot in "open" mode is cloneable if cloneable flag is set
PASS ShadowRoot in "closed" mode is cloneable if cloneable flag is set
PASS ShadowRoot in "open" mode is not clonable by default
PASS ShadowRoot in "closed" mode is not clonable by default
PASS ShadowRoot in "open" mode is clonable if clonable flag is set
PASS ShadowRoot in "closed" mode is clonable if clonable flag is set
PASS Cloning ShadowRoot in "open" mode clones shadow root mode
PASS Cloning ShadowRoot in "closed" mode clones shadow root mode
PASS Cloning ShadowRoot in "open" mode clones delegatesFocus flag set to true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
test(() => {
const host = document.createElement('div');
const shadowRoot = host.attachShadow({mode});
assert_false(shadowRoot.cloneable);
assert_false(shadowRoot.clonable);

const clonedHost = host.cloneNode(true);
assert_true(!!clonedHost.attachShadow({mode}));
assert_throws_dom('NotSupportedError', () => {
shadowRoot.cloneNode(true);
});
}, `ShadowRoot in "${mode}" mode is not cloneable by default`);
}, `ShadowRoot in "${mode}" mode is not clonable by default`);
}

testShadowRootIsNotCloneableByDefault('open');
Expand All @@ -28,15 +28,15 @@
function testShadowRootIsCloneable(mode) {
test(() => {
const host = document.createElement('div');
const shadowRoot = host.attachShadow({mode, cloneable: true});
assert_true(shadowRoot.cloneable);
const shadowRoot = host.attachShadow({mode, clonable: true});
assert_true(shadowRoot.clonable);

const clonedHost = host.cloneNode(true);
assert_throws_dom('NotSupportedError', () => {
clonedHost.attachShadow({mode});
});
assert_equals(!!clonedHost.shadowRoot, mode == 'open');
}, `ShadowRoot in "${mode}" mode is cloneable if cloneable flag is set`);
}, `ShadowRoot in "${mode}" mode is clonable if clonable flag is set`);
}

testShadowRootIsCloneable('open');
Expand All @@ -45,8 +45,8 @@
function testShadowRootClonesShadowRootMode(mode) {
test(() => {
const host = document.createElement('div');
const shadowRoot = host.attachShadow({mode, cloneable: true});
assert_true(shadowRoot.cloneable);
const shadowRoot = host.attachShadow({mode, clonable: true});
assert_true(shadowRoot.clonable);
const clonedHost = host.cloneNode(true);
assert_equals(!!clonedHost.shadowRoot, mode == 'open');
}, `Cloning ShadowRoot in "${mode}" mode clones shadow root mode`);
Expand All @@ -58,8 +58,8 @@
function testShadowRootClonesDelegatesFocus(mode, delegatesFocus) {
test(() => {
const host = document.createElement('div');
const shadowRoot = host.attachShadow({mode, cloneable: true, delegatesFocus});
assert_true(shadowRoot.cloneable);
const shadowRoot = host.attachShadow({mode, clonable: true, delegatesFocus});
assert_true(shadowRoot.clonable);
shadowRoot.innerHTML = '<input onfocus="window.didFocusInputElement = true">';

const clonedHost = host.cloneNode(true);
Expand All @@ -82,8 +82,8 @@
test(() => {
const host = document.createElement('span');
host.innerHTML = '<div style="width: 100px; height: 100px; display: inline-block;"></div>';
const shadowRoot = host.attachShadow({mode, cloneable: true, slotAssignment: 'manual'});
assert_true(shadowRoot.cloneable);
const shadowRoot = host.attachShadow({mode, clonable: true, slotAssignment: 'manual'});
assert_true(shadowRoot.clonable);
shadowRoot.innerHTML = '<slot></slot>';
const clonedHost = host.cloneNode(true);
if (mode == 'open')
Expand All @@ -96,8 +96,8 @@
test(() => {
const host = document.createElement('span');
host.innerHTML = '<div style="width: 100px; height: 100px; display: inline-block;"></div>';
const shadowRoot = host.attachShadow({mode, cloneable: true, slotAssignment: 'named'});
assert_true(shadowRoot.cloneable);
const shadowRoot = host.attachShadow({mode, clonable: true, slotAssignment: 'named'});
assert_true(shadowRoot.clonable);
shadowRoot.innerHTML = '<slot></slot>';
const clonedHost = host.cloneNode(true);
if (mode == 'open')
Expand All @@ -114,8 +114,8 @@
function testShadowRootClonesShadowDescendants(mode) {
test(() => {
const host = document.createElement('span');
const shadowRoot = host.attachShadow({mode, cloneable: true});
assert_true(shadowRoot.cloneable);
const shadowRoot = host.attachShadow({mode, clonable: true});
assert_true(shadowRoot.clonable);
shadowRoot.innerHTML = '<div style="width: 100px; height: 100px; display: inline-block;"><div></div></div>';
const clonedHost = host.cloneNode(true);
if (mode == 'open')
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/dom/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ Ref<Node> Element::cloneNodeInternal(Document& targetDocument, CloningOperation
void Element::cloneShadowTreeIfPossible(Element& newHost)
{
RefPtr oldShadowRoot = this->shadowRoot();
if (!oldShadowRoot || !oldShadowRoot->isCloneable())
if (!oldShadowRoot || !oldShadowRoot->isClonable())
return;

Ref clonedShadowRoot = [&] {
Expand Down Expand Up @@ -2961,15 +2961,15 @@ ExceptionOr<ShadowRoot&> Element::attachShadow(const ShadowRootInit& init)
return Exception { ExceptionCode::TypeError };
Ref shadow = ShadowRoot::create(document(), init.mode, init.slotAssignment,
init.delegatesFocus ? ShadowRoot::DelegatesFocus::Yes : ShadowRoot::DelegatesFocus::No,
init.cloneable ? ShadowRoot::Cloneable::Yes : ShadowRoot::Cloneable::No,
init.clonable ? ShadowRoot::Clonable::Yes : ShadowRoot::Clonable::No,
isPrecustomizedOrDefinedCustomElement() ? ShadowRoot::AvailableToElementInternals::Yes : ShadowRoot::AvailableToElementInternals::No);
addShadowRoot(shadow.copyRef());
return shadow.get();
}

ExceptionOr<ShadowRoot&> Element::attachDeclarativeShadow(ShadowRootMode mode, bool delegatesFocus)
{
auto exceptionOrShadowRoot = attachShadow({ mode, delegatesFocus, /* cloneable */ true });
auto exceptionOrShadowRoot = attachShadow({ mode, delegatesFocus, /* clonable */ true });
if (exceptionOrShadowRoot.hasException())
return exceptionOrShadowRoot.releaseException();
Ref shadowRoot = exceptionOrShadowRoot.releaseReturnValue();
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/Range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ ExceptionOr<RefPtr<Node>> processAncestorsAndTheirSiblings(Range::ActionType act
for (auto& ancestor : ancestors) {
if (action == Range::Extract || action == Range::Clone) {
if (auto shadowRoot = dynamicDowncast<ShadowRoot>(ancestor.get())) {
if (!shadowRoot->isCloneable())
if (!shadowRoot->isClonable())
continue;
}
Ref clonedAncestor = ancestor->cloneNode(false); // Might have been removed already during mutation event.
Expand Down
6 changes: 3 additions & 3 deletions Source/WebCore/dom/ShadowRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ static_assert(sizeof(ShadowRoot) == sizeof(SameSizeAsShadowRoot), "shadowroot sh
static_assert(sizeof(WeakPtr<Element, WeakPtrImplWithEventTargetData>) == sizeof(void*), "WeakPtr should be same size as raw pointer");
#endif

ShadowRoot::ShadowRoot(Document& document, ShadowRootMode mode, SlotAssignmentMode assignmentMode, DelegatesFocus delegatesFocus, Cloneable cloneable, AvailableToElementInternals availableToElementInternals)
ShadowRoot::ShadowRoot(Document& document, ShadowRootMode mode, SlotAssignmentMode assignmentMode, DelegatesFocus delegatesFocus, Clonable clonable, AvailableToElementInternals availableToElementInternals)
: DocumentFragment(document, TypeFlag::IsShadowRoot)
, TreeScope(*this, document)
, m_delegatesFocus(delegatesFocus == DelegatesFocus::Yes)
, m_isCloneable(cloneable == Cloneable::Yes)
, m_isClonable(clonable == Clonable::Yes)
, m_availableToElementInternals(availableToElementInternals == AvailableToElementInternals::Yes)
, m_mode(mode)
, m_slotAssignmentMode(assignmentMode)
Expand Down Expand Up @@ -241,7 +241,7 @@ Ref<Node> ShadowRoot::cloneNodeInternal(Document& targetDocument, CloningOperati
switch (type) {
case CloningOperation::SelfWithTemplateContent:
return create(targetDocument, m_mode, m_slotAssignmentMode, m_delegatesFocus ? DelegatesFocus::Yes : DelegatesFocus::No,
m_isCloneable ? Cloneable::Yes : Cloneable::No, m_availableToElementInternals ? AvailableToElementInternals::Yes : AvailableToElementInternals::No);
m_isClonable ? Clonable::Yes : Clonable::No, m_availableToElementInternals ? AvailableToElementInternals::Yes : AvailableToElementInternals::No);
case CloningOperation::OnlySelf:
case CloningOperation::Everything:
break;
Expand Down
12 changes: 6 additions & 6 deletions Source/WebCore/dom/ShadowRoot.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class ShadowRoot final : public CanMakeCheckedPtr, public DocumentFragment, publ
public:

enum class DelegatesFocus : bool { No, Yes };
enum class Cloneable : bool { No, Yes };
enum class Clonable : bool { No, Yes };
enum class AvailableToElementInternals : bool { No, Yes };

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

static Ref<ShadowRoot> create(Document& document, std::unique_ptr<SlotAssignment>&& assignment)
Expand Down Expand Up @@ -88,7 +88,7 @@ class ShadowRoot final : public CanMakeCheckedPtr, public DocumentFragment, publ
bool containsFocusedElement() const { return m_containsFocusedElement; }
void setContainsFocusedElement(bool flag) { m_containsFocusedElement = flag; }

bool isCloneable() const { return m_isCloneable; }
bool isClonable() const { return m_isClonable; }

bool isAvailableToElementInternals() const { return m_availableToElementInternals; }
void setIsAvailableToElementInternals(bool flag) { m_availableToElementInternals = flag; }
Expand Down Expand Up @@ -147,7 +147,7 @@ class ShadowRoot final : public CanMakeCheckedPtr, public DocumentFragment, publ
Vector<RefPtr<WebAnimation>> getAnimations();

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

bool childTypeAllowed(NodeType) const override;
Expand All @@ -161,7 +161,7 @@ class ShadowRoot final : public CanMakeCheckedPtr, public DocumentFragment, publ

bool m_hasBegunDeletingDetachedChildren : 1 { false };
bool m_delegatesFocus : 1 { false };
bool m_isCloneable : 1 { false };
bool m_isClonable : 1 { false };
bool m_containsFocusedElement : 1 { false };
bool m_availableToElementInternals : 1 { false };
bool m_isDeclarativeShadowRoot : 1 { false };
Expand Down
4 changes: 3 additions & 1 deletion Source/WebCore/dom/ShadowRoot.idl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// https://dom.spec.whatwg.org/#interface-shadowroot

[
JSGenerateToJSObject,
JSGenerateToNativeObject,
Expand All @@ -31,7 +33,7 @@
readonly attribute ShadowRootMode mode;
readonly attribute boolean delegatesFocus;
[ImplementedAs=slotAssignmentMode, EnabledBySetting=ImperativeSlotAPIEnabled] readonly attribute SlotAssignmentMode slotAssignment;
[ImplementedAs=isCloneable, EnabledBySetting=DeclarativeShadowRootsEnabled] readonly attribute boolean cloneable;
[ImplementedAs=isClonable, EnabledBySetting=DeclarativeShadowRootsEnabled] readonly attribute boolean clonable;
readonly attribute Element host;
attribute EventHandler onslotchange;
};
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/dom/ShadowRootInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace WebCore {
struct ShadowRootInit {
ShadowRootMode mode;
bool delegatesFocus { false };
bool cloneable { false };
bool clonable { false };
SlotAssignmentMode slotAssignment { SlotAssignmentMode::Named };
};

Expand Down
4 changes: 3 additions & 1 deletion Source/WebCore/dom/ShadowRootInit.idl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

// https://dom.spec.whatwg.org/#dictdef-shadowrootinit

dictionary ShadowRootInit {
required ShadowRootMode mode;
boolean delegatesFocus = false;
[EnabledBySetting=DeclarativeShadowRootsEnabled] boolean cloneable = false;
[EnabledBySetting=DeclarativeShadowRootsEnabled] boolean clonable = false;
[EnabledBySetting=ImperativeSlotAPIEnabled] SlotAssignmentMode slotAssignment = "named";
};

0 comments on commit 55c8a56

Please sign in to comment.