@@ -499,6 +499,29 @@ int32_t Element::TabIndex() {
499499 return TabIndexDefault ();
500500}
501501
502+ /* static */
503+ void Element::TraverseCustomElementRegistry (
504+ Element* aElement, nsCycleCollectionTraversalCallback& aCb) {
505+ if (aElement->GetCustomElementRegistryState () ==
506+ CustomElementRegistryState::Scoped) {
507+ RefPtr<CustomElementRegistry> registry =
508+ CustomElementRegistry::GetScopedRegistry (*aElement);
509+ if (registry) {
510+ NS_CYCLE_COLLECTION_NOTE_EDGE_NAME (aCb, " scoped CustomElementRegistry" );
511+ aCb.NoteXPCOMChild (registry.get ());
512+ }
513+ }
514+ }
515+
516+ /* static */
517+ void Element::UnlinkCustomElementRegistry (Element* aElement) {
518+ if (aElement->GetCustomElementRegistryState () ==
519+ CustomElementRegistryState::Scoped) {
520+ CustomElementRegistry::RemoveScopedRegistry (*aElement);
521+ aElement->SetCustomElementRegistryState (CustomElementRegistryState::Global);
522+ }
523+ }
524+
502525void Element::Focus (const FocusOptions& aOptions, CallerType aCallerType,
503526 ErrorResult& aError) {
504527 const RefPtr<nsFocusManager> fm = nsFocusManager::GetFocusManager ();
@@ -538,6 +561,41 @@ void Element::SetShadowRoot(ShadowRoot* aShadowRoot) {
538561 slots->mShadowRoot = aShadowRoot;
539562}
540563
564+ void Element::SetCustomElementRegistry (
565+ CustomElementRegistry* aCustomElementRegistry) {
566+ MOZ_ASSERT (StaticPrefs::dom_scoped_custom_element_registries_enabled ());
567+ MOZ_ASSERT (!!aCustomElementRegistry,
568+ " We shouldn't be setting a null custom element registry" );
569+ MOZ_ASSERT (
570+ GetCustomElementRegistryState () != CustomElementRegistryState::Scoped,
571+ " We shouldn't override an already assigned scoped registry" );
572+
573+ if (aCustomElementRegistry->IsScoped ()) {
574+ SetCustomElementRegistryState (CustomElementRegistryState::Scoped);
575+ CustomElementRegistry::SetScopedRegistry (*this , *aCustomElementRegistry);
576+ } else {
577+ SetCustomElementRegistryState (CustomElementRegistryState::Global);
578+ }
579+ }
580+
581+ /* https://dom.spec.whatwg.org/#element-custom-element-registry */
582+ CustomElementRegistry* Element::GetCustomElementRegistry () {
583+ switch (GetCustomElementRegistryState ()) {
584+ case CustomElementRegistryState::Global:
585+ return OwnerDoc ()->GetEffectiveGlobalCustomElementRegistry ();
586+ case CustomElementRegistryState::Null:
587+ return nullptr ;
588+ case CustomElementRegistryState::Scoped: {
589+ RefPtr<CustomElementRegistry> registry =
590+ CustomElementRegistry::GetScopedRegistry (*this );
591+ MOZ_ASSERT (registry);
592+ return registry;
593+ }
594+ }
595+ MOZ_ASSERT_UNREACHABLE (" Invalid CustomElementRegistryState" );
596+ return nullptr ;
597+ }
598+
541599void Element::SetLastRememberedBSize (float aBSize) {
542600 ExtendedDOMSlots ()->mLastRememberedBSize = Some (aBSize);
543601}
@@ -4515,6 +4573,25 @@ nsresult Element::CopyInnerTo(Element* aDst, ReparseAttributes aReparse) {
45154573 }
45164574 }
45174575
4576+ // https://dom.spec.whatwg.org/#clone-a-single-node
4577+ // Step 2.1. Let registry be node's custom element registry.
4578+ // Step 2.2. If registry is null, then set registry to fallbackRegistry.
4579+ // Step 2.3. If registry is a global custom element registry, then set
4580+ // registry to document's effective global custom element registry.
4581+ // XXX Steps 2.1-2.3 are partially handled here by propagating registry
4582+ // state; the full registry resolution happens in "create an element".
4583+ CustomElementRegistryState state = GetCustomElementRegistryState ();
4584+ if (state == CustomElementRegistryState::Scoped) {
4585+ MOZ_ASSERT (StaticPrefs::dom_scoped_custom_element_registries_enabled ());
4586+ RefPtr<CustomElementRegistry> scopedRegistry =
4587+ CustomElementRegistry::GetScopedRegistry (*this );
4588+ aDst->SetCustomElementRegistry (scopedRegistry);
4589+ } else {
4590+ MOZ_ASSERT (state == CustomElementRegistryState::Global ||
4591+ StaticPrefs::dom_scoped_custom_element_registries_enabled ());
4592+ aDst->SetCustomElementRegistryState (state);
4593+ }
4594+
45184595 // https://html.spec.whatwg.org/#enqueue-a-custom-element-upgrade-reaction
45194596 dom::NodeInfo* dstNodeInfo = aDst->NodeInfo ();
45204597 if (CustomElementData* data = GetCustomElementData ()) {
0 commit comments