Skip to content

Commit edf2167

Browse files
keithamuskcirkel@mozilla.com
authored andcommitted
Bug 2023824 - Implement shadowrootslotassignment r=webidl,emilio
Differential Revision: https://phabricator.services.mozilla.com/D288343
1 parent 510a83c commit edf2167

19 files changed

Lines changed: 98 additions & 45 deletions

dom/base/nsContentUtils.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10978,6 +10978,10 @@ static bool StartSerializingShadowDOM(
1097810978
if (shadow->Clonable()) {
1097910979
aBuilder.Append(u" shadowrootclonable=\"\"");
1098010980
}
10981+
if (StaticPrefs::dom_shadowdom_shadowRootSlotAssignment_enabled() &&
10982+
shadow->SlotAssignment() == SlotAssignmentMode::Manual) {
10983+
aBuilder.Append(u" shadowrootslotassignment=\"manual\"");
10984+
}
1098110985

1098210986
aBuilder.Append(u">");
1098310987

@@ -13099,7 +13103,7 @@ int32_t nsContentUtils::CompareTreePosition(const nsINode* aNode1,
1309913103
nsIContent* nsContentUtils::AttachDeclarativeShadowRoot(
1310013104
nsIContent* aHost, ShadowRootMode aMode, bool aIsClonable,
1310113105
bool aIsSerializable, bool aDelegatesFocus, bool aCustomElementRegistry,
13102-
const nsAString& aReferenceTarget) {
13106+
SlotAssignmentMode aSlotAssignment, const nsAString& aReferenceTarget) {
1310313107
RefPtr<Element> host = mozilla::dom::Element::FromNodeOrNull(aHost);
1310413108
if (!host || host->GetShadowRoot()) {
1310513109
// https://html.spec.whatwg.org/#parsing-main-inhead:shadow-host
@@ -13109,7 +13113,7 @@ nsIContent* nsContentUtils::AttachDeclarativeShadowRoot(
1310913113
ShadowRootInit init;
1311013114
init.mMode = aMode;
1311113115
init.mDelegatesFocus = aDelegatesFocus;
13112-
init.mSlotAssignment = SlotAssignmentMode::Named;
13116+
init.mSlotAssignment = aSlotAssignment;
1311313117
init.mClonable = aIsClonable;
1311413118
init.mSerializable = aIsSerializable;
1311513119

dom/base/nsContentUtils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ struct SetHTMLOptions;
194194
struct SetHTMLUnsafeOptions;
195195
enum class ShadowRootMode : uint8_t;
196196
class ShadowRoot;
197+
enum class SlotAssignmentMode : uint8_t;
197198
struct StructuredSerializeOptions;
198199
struct SynthesizeMouseEventData;
199200
struct SynthesizeMouseEventOptions;
@@ -3644,7 +3645,8 @@ class nsContentUtils {
36443645
static nsIContent* AttachDeclarativeShadowRoot(
36453646
nsIContent* aHost, mozilla::dom::ShadowRootMode aMode, bool aIsClonable,
36463647
bool aIsSerializable, bool aDelegatesFocus, bool aCustomElementRegistry,
3647-
const nsAString&);
3648+
mozilla::dom::SlotAssignmentMode aSlotAssignment,
3649+
const nsAString& aReferenceTarget);
36483650

36493651
static bool NavigationMustBeAReplace(nsIURI& aURI, const Document& aDocument);
36503652

dom/html/HTMLTemplateElement.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "mozilla/dom/HTMLTemplateElement.h"
66

7+
#include "mozilla/StaticPrefs_dom.h"
78
#include "mozilla/dom/Document.h"
89
#include "mozilla/dom/HTMLTemplateElementBinding.h"
910
#include "mozilla/dom/NameSpaceConstants.h"
@@ -22,6 +23,14 @@ static constexpr nsAttrValue::EnumTableEntry kShadowRootModeTable[] = {
2223
{"closed", ShadowRootMode::Closed},
2324
};
2425

26+
static constexpr nsAttrValue::EnumTableEntry kSlotAssignmentTable[] = {
27+
{"named", SlotAssignmentMode::Named},
28+
{"manual", SlotAssignmentMode::Manual},
29+
};
30+
31+
static constexpr const nsAttrValue::EnumTableEntry* kSlotAssignmentDefault =
32+
&kSlotAssignmentTable[0];
33+
2534
HTMLTemplateElement::HTMLTemplateElement(
2635
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
2736
: nsGenericHTMLElement(std::move(aNodeInfo)) {
@@ -69,6 +78,12 @@ JSObject* HTMLTemplateElement::WrapNode(JSContext* aCx,
6978
return HTMLTemplateElement_Binding::Wrap(aCx, this, aGivenProto);
7079
}
7180

81+
void HTMLTemplateElement::GetShadowRootSlotAssignment(
82+
nsAString& aResult) const {
83+
GetEnumAttr(nsGkAtoms::shadowrootslotassignment, kSlotAssignmentDefault->tag,
84+
aResult);
85+
}
86+
7287
void HTMLTemplateElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
7388
const nsAttrValue* aValue,
7489
const nsAttrValue* aOldValue,
@@ -90,9 +105,16 @@ bool HTMLTemplateElement::ParseAttribute(int32_t aNamespaceID,
90105
const nsAString& aValue,
91106
nsIPrincipal* aMaybeScriptedPrincipal,
92107
nsAttrValue& aResult) {
93-
if (aNamespaceID == kNameSpaceID_None &&
94-
aAttribute == nsGkAtoms::shadowrootmode) {
95-
return aResult.ParseEnumValue(aValue, kShadowRootModeTable, false, nullptr);
108+
if (aNamespaceID == kNameSpaceID_None) {
109+
if (aAttribute == nsGkAtoms::shadowrootmode) {
110+
return aResult.ParseEnumValue(aValue, kShadowRootModeTable, false,
111+
nullptr);
112+
}
113+
if (aAttribute == nsGkAtoms::shadowrootslotassignment &&
114+
StaticPrefs::dom_shadowdom_shadowRootSlotAssignment_enabled()) {
115+
return aResult.ParseEnumValue(aValue, kSlotAssignmentTable, false,
116+
kSlotAssignmentDefault);
117+
}
96118
}
97119
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
98120
aMaybeScriptedPrincipal, aResult);

dom/html/HTMLTemplateElement.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class HTMLTemplateElement final : public nsGenericHTMLElement {
7777
SetHTMLAttr(nsGkAtoms::shadowrootreferencetarget, aValue);
7878
}
7979

80+
void GetShadowRootSlotAssignment(nsAString& aResult) const;
81+
void SetShadowRootSlotAssignment(const nsAString& aValue) {
82+
SetHTMLAttr(nsGkAtoms::shadowrootslotassignment, aValue);
83+
}
84+
8085
void SetHTML(const nsAString& aInnerHTML, const SetHTMLOptions& aOptions,
8186
ErrorResult& aError) final;
8287

dom/webidl/HTMLTemplateElement.webidl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ interface HTMLTemplateElement : HTMLElement {
2424
attribute boolean shadowRootSerializable;
2525
[CEReactions, SetterThrows, Pref="dom.shadowdom.referenceTarget.enabled"]
2626
attribute DOMString? shadowRootReferenceTarget;
27+
[CEReactions, Pref="dom.shadowdom.shadowRootSlotAssignment.enabled"]
28+
attribute DOMString shadowRootSlotAssignment;
2729
};

modules/libpref/init/StaticPrefList.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5733,6 +5733,11 @@
57335733
value: false
57345734
mirror: always
57355735

5736+
- name: dom.shadowdom.shadowRootSlotAssignment.enabled
5737+
type: RelaxedAtomicBool
5738+
value: false
5739+
mirror: always
5740+
57365741
# NOTE: This preference is used in unit tests. If it is removed or its default
57375742
# value changes, please update test_sharedMap_static_prefs.js accordingly.
57385743
- name: dom.webcomponents.shadowdom.report_usage

parser/html/javasrc/AttributeName.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ boolean equalsAnother(AttributeName another) {
808808
public static final AttributeName SANDBOX = new AttributeName(ALL_NO_NS, "sandbox", "sandbox", "sandbox", "sandbox", ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
809809
public static final AttributeName SHADOWROOTCUSTOMELEMENTREGISTRY = new AttributeName(ALL_NO_NS, "shadowrootcustomelementregistry", "shadowrootcustomelementregistry", "shadowrootcustomelementregistry", "shadowrootcustomelementregistry", ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
810810
public static final AttributeName SHADOWROOTDELEGATESFOCUS = new AttributeName(ALL_NO_NS, "shadowrootdelegatesfocus", "shadowrootdelegatesfocus", "shadowrootdelegatesfocus", "shadowrootdelegatesfocus", ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
811+
public static final AttributeName SHADOWROOTSLOTASSIGNMENT = new AttributeName(ALL_NO_NS, "shadowrootslotassignment", "shadowrootslotassignment", "shadowrootslotassignment", "shadowrootslotassignment", ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
811812
public static final AttributeName WORD_SPACING = new AttributeName(ALL_NO_NS, "word-spacing", "word-spacing", "word-spacing", "word-spacing", ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
812813
public static final AttributeName ACCENTUNDER = new AttributeName(ALL_NO_NS, "accentunder", "accentunder", "accentunder", "accentunder", ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
813814
public static final AttributeName ACCEPT_CHARSET = new AttributeName(ALL_NO_NS, "accept-charset", "accept-charset", "accept-charset", "accept-charset", ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
@@ -1709,6 +1710,7 @@ boolean equalsAnother(AttributeName another) {
17091710
REFX,
17101711
CY,
17111712
FY,
1713+
SHADOWROOTSLOTASSIGNMENT,
17121714
};
17131715
private final static int[] ATTRIBUTE_HASHES = {
17141716
1854497001,

parser/html/javasrc/TreeBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,8 +3087,9 @@ private T getDeclarativeShadowRoot(T currentNode, T templateNode, HtmlAttributes
30873087
boolean shadowRootDelegatesFocus = attributes.contains(AttributeName.SHADOWROOTDELEGATESFOCUS);
30883088
boolean shadowRootCustomElementRegistry = attributes.contains(AttributeName.SHADOWROOTCUSTOMELEMENTREGISTRY);
30893089
String shadowRootReferenceTarget = attributes.getValue(AttributeName.SHADOWROOTREFERENCETARGET);
3090+
String shadowRootSlotAssignment = attributes.getValue(AttributeName.SHADOWROOTSLOTASSIGNMENT);
30903091

3091-
return getShadowRootFromHost(currentNode, templateNode, shadowRootMode, shadowRootIsClonable, shadowRootIsSerializable, shadowRootDelegatesFocus, shadowRootCustomElementRegistry, shadowRootReferenceTarget);
3092+
return getShadowRootFromHost(currentNode, templateNode, shadowRootMode, shadowRootIsClonable, shadowRootIsSerializable, shadowRootDelegatesFocus, shadowRootCustomElementRegistry, shadowRootSlotAssignment, shadowRootReferenceTarget);
30923093
}
30933094

30943095
/**
@@ -5563,7 +5564,8 @@ void setDocumentFragmentForTemplate(T template, T fragment) {
55635564

55645565
T getShadowRootFromHost(T host, T template, String shadowRootMode,
55655566
boolean shadowRootIsClonable, boolean shadowRootIsSerializable, boolean shadowRootDelegatesFocus,
5566-
boolean shadowRootCustomElementRegistry, String shadowRootReferenceTarget) {
5567+
boolean shadowRootCustomElementRegistry, String shadowRootSlotAssignment,
5568+
String shadowRootReferenceTarget) {
55675569
return null;
55685570
}
55695571

parser/html/nsHtml5AttributeName.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ nsHtml5AttributeName*
208208
nsHtml5AttributeName::ATTR_SHADOWROOTCUSTOMELEMENTREGISTRY = nullptr;
209209
nsHtml5AttributeName* nsHtml5AttributeName::ATTR_SHADOWROOTDELEGATESFOCUS =
210210
nullptr;
211+
nsHtml5AttributeName* nsHtml5AttributeName::ATTR_SHADOWROOTSLOTASSIGNMENT =
212+
nullptr;
211213
nsHtml5AttributeName* nsHtml5AttributeName::ATTR_WORD_SPACING = nullptr;
212214
nsHtml5AttributeName* nsHtml5AttributeName::ATTR_ACCENTUNDER = nullptr;
213215
nsHtml5AttributeName* nsHtml5AttributeName::ATTR_ACCEPT_CHARSET = nullptr;
@@ -1059,6 +1061,10 @@ void nsHtml5AttributeName::initializeStatics() {
10591061
ALL_NO_NS, nsGkAtoms::shadowrootdelegatesfocus,
10601062
nsGkAtoms::shadowrootdelegatesfocus, nsGkAtoms::shadowrootdelegatesfocus,
10611063
ALL_NO_PREFIX);
1064+
ATTR_SHADOWROOTSLOTASSIGNMENT = new nsHtml5AttributeName(
1065+
ALL_NO_NS, nsGkAtoms::shadowrootslotassignment,
1066+
nsGkAtoms::shadowrootslotassignment, nsGkAtoms::shadowrootslotassignment,
1067+
ALL_NO_PREFIX);
10621068
ATTR_WORD_SPACING = new nsHtml5AttributeName(
10631069
ALL_NO_NS, nsGkAtoms::word_spacing, nsGkAtoms::word_spacing,
10641070
nsGkAtoms::word_spacing, ALL_NO_PREFIX);
@@ -2222,7 +2228,7 @@ void nsHtml5AttributeName::initializeStatics() {
22222228
ATTR_REFY =
22232229
new nsHtml5AttributeName(ALL_NO_NS, nsGkAtoms::refy, nsGkAtoms::refy,
22242230
nsGkAtoms::refY, ALL_NO_PREFIX);
2225-
ATTRIBUTE_NAMES = new nsHtml5AttributeName*[509];
2231+
ATTRIBUTE_NAMES = new nsHtml5AttributeName*[510];
22262232
ATTRIBUTE_NAMES[0] = ATTR_MASKUNITS;
22272233
ATTRIBUTE_NAMES[1] = ATTR_BASEPROFILE;
22282234
ATTRIBUTE_NAMES[2] = ATTR_SLOPE;
@@ -2732,6 +2738,7 @@ void nsHtml5AttributeName::initializeStatics() {
27322738
ATTRIBUTE_NAMES[506] = ATTR_REFX;
27332739
ATTRIBUTE_NAMES[507] = ATTR_CY;
27342740
ATTRIBUTE_NAMES[508] = ATTR_FY;
2741+
ATTRIBUTE_NAMES[509] = ATTR_SHADOWROOTSLOTASSIGNMENT;
27352742
}
27362743

27372744
void nsHtml5AttributeName::releaseStatics() {
@@ -2861,6 +2868,7 @@ void nsHtml5AttributeName::releaseStatics() {
28612868
delete ATTR_SANDBOX;
28622869
delete ATTR_SHADOWROOTCUSTOMELEMENTREGISTRY;
28632870
delete ATTR_SHADOWROOTDELEGATESFOCUS;
2871+
delete ATTR_SHADOWROOTSLOTASSIGNMENT;
28642872
delete ATTR_WORD_SPACING;
28652873
delete ATTR_ACCENTUNDER;
28662874
delete ATTR_ACCEPT_CHARSET;

parser/html/nsHtml5AttributeName.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ class nsHtml5AttributeName {
290290
static nsHtml5AttributeName* ATTR_SANDBOX;
291291
static nsHtml5AttributeName* ATTR_SHADOWROOTCUSTOMELEMENTREGISTRY;
292292
static nsHtml5AttributeName* ATTR_SHADOWROOTDELEGATESFOCUS;
293+
static nsHtml5AttributeName* ATTR_SHADOWROOTSLOTASSIGNMENT;
293294
static nsHtml5AttributeName* ATTR_WORD_SPACING;
294295
static nsHtml5AttributeName* ATTR_ACCENTUNDER;
295296
static nsHtml5AttributeName* ATTR_ACCEPT_CHARSET;

0 commit comments

Comments
 (0)