mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-28 03:17:31 +09:00
Bug 1411878 - Support Element.shadowRoot and Element.assignedSlot / TextNode.assignedSlot on closed shadow root
Tag #1375
This commit is contained in:
parent
67c4d022dc
commit
31b26a24e3
8 changed files with 67 additions and 11 deletions
|
|
@ -1104,6 +1104,25 @@ Element::GetSlot(nsAString& aName)
|
|||
GetAttr(kNameSpaceID_None, nsGkAtoms::slot, aName);
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-shadowroot
|
||||
ShadowRoot*
|
||||
Element::GetShadowRootByMode() const
|
||||
{
|
||||
/**
|
||||
* 1. Let shadow be context object’s shadow root.
|
||||
* 2. If shadow is null or its mode is "closed", then return null.
|
||||
*/
|
||||
ShadowRoot* shadowRoot = GetShadowRoot();
|
||||
if (!shadowRoot || shadowRoot->IsClosed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. Return shadow.
|
||||
*/
|
||||
return shadowRoot;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-attachshadow
|
||||
already_AddRefed<ShadowRoot>
|
||||
Element::AttachShadow(const ShadowRootInit& aInit, ErrorResult& aError)
|
||||
|
|
|
|||
|
|
@ -927,6 +927,7 @@ public:
|
|||
// Shadow DOM v1
|
||||
already_AddRefed<ShadowRoot> AttachShadow(const ShadowRootInit& aInit,
|
||||
ErrorResult& aError);
|
||||
ShadowRoot* GetShadowRootByMode() const;
|
||||
void SetSlot(const nsAString& aName, ErrorResult& aError);
|
||||
void GetSlot(nsAString& aName);
|
||||
|
||||
|
|
|
|||
|
|
@ -152,6 +152,36 @@ nsIContent::FindFirstNonChromeOnlyAccessContent() const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-slotable-assignedslot
|
||||
HTMLSlotElement*
|
||||
nsIContent::GetAssignedSlotByMode() const
|
||||
{
|
||||
/**
|
||||
* Get slotable's assigned slot for the result of
|
||||
* find a slot with open flag UNSET [1].
|
||||
*
|
||||
* [1] https://dom.spec.whatwg.org/#assign-a-slot
|
||||
*/
|
||||
HTMLSlotElement* slot = GetAssignedSlot();
|
||||
if (!slot) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(GetParent());
|
||||
MOZ_ASSERT(GetParent()->GetShadowRoot());
|
||||
|
||||
/**
|
||||
* Additional check for open flag SET:
|
||||
* If slotable’s parent’s shadow root's mode is not "open",
|
||||
* then return null.
|
||||
*/
|
||||
if (GetParent()->GetShadowRoot()->IsClosed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
nsINode*
|
||||
nsIContent::GetFlattenedTreeParentNodeInternal(FlattenedParentType aType) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,6 +51,11 @@ public:
|
|||
{
|
||||
return mMode;
|
||||
}
|
||||
bool IsClosed()
|
||||
{
|
||||
return mMode == ShadowRootMode::Closed;
|
||||
}
|
||||
|
||||
|
||||
// [deprecated] Shadow DOM v0
|
||||
void AddToIdTable(Element* aElement, nsIAtom* aId);
|
||||
|
|
|
|||
|
|
@ -724,6 +724,15 @@ public:
|
|||
*/
|
||||
virtual void SetAssignedSlot(mozilla::dom::HTMLSlotElement* aSlot) = 0;
|
||||
|
||||
/**
|
||||
* Gets the assigned slot associated with this content based on parent's
|
||||
* shadow root mode. Returns null if parent's shadow root is "closed".
|
||||
* https://dom.spec.whatwg.org/#dom-slotable-assignedslot
|
||||
*
|
||||
* @return The assigned slot element or null.
|
||||
*/
|
||||
mozilla::dom::HTMLSlotElement* GetAssignedSlotByMode() const;
|
||||
|
||||
/**
|
||||
* Gets the insertion parent element of the XBL binding.
|
||||
* The insertion parent is our one true parent in the transformed DOM.
|
||||
|
|
|
|||
|
|
@ -238,9 +238,9 @@ partial interface Element {
|
|||
// Shadow DOM v1
|
||||
[Throws, Pref="nsDocument::IsWebComponentsEnabled"]
|
||||
ShadowRoot attachShadow(ShadowRootInit shadowRootInitDict);
|
||||
[Func="nsDocument::IsWebComponentsEnabled"]
|
||||
[BinaryName="shadowRootByMode", Func="nsDocument::IsWebComponentsEnabled"]
|
||||
readonly attribute ShadowRoot? shadowRoot;
|
||||
[Pref="nsDocument::IsWebComponentsEnabled"]
|
||||
[BinaryName="assignedSlotByMode", Pref="nsDocument::IsWebComponentsEnabled"]
|
||||
readonly attribute HTMLSlotElement? assignedSlot;
|
||||
[CEReactions, Unscopable, SetterThrows, Pref="nsDocument::IsWebComponentsEnabled"]
|
||||
attribute DOMString slot;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ interface Text : CharacterData {
|
|||
};
|
||||
|
||||
partial interface Text {
|
||||
[Pref="dom.webcomponents.enabled"]
|
||||
[BinaryName="assignedSlotByMode", Pref="dom.webcomponents.enabled"]
|
||||
readonly attribute HTMLSlotElement? assignedSlot;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
[Element-interface-shadowRoot-attribute.html]
|
||||
type: testharness
|
||||
[shadowRoot attribute must return the open shadow root associated with the element]
|
||||
expected: FAIL
|
||||
|
||||
[shadowRoot attribute must return null if the shadow root attached to the element is closed]
|
||||
expected: FAIL
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue