зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1723521 - Part 2: Add available-to-element-internals flag in ShadowRoot; r=smaug
See https://github.com/whatwg/dom/pull/893. Differential Revision: https://phabricator.services.mozilla.com/D121565
This commit is contained in:
Родитель
8a6f168f50
Коммит
a599b69db0
|
@ -1160,14 +1160,11 @@ bool Element::CanAttachShadowDOM() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-attachshadow
|
||||
// https://dom.spec.whatwg.org/commit-snapshots/1eadf0a4a271acc92013d1c0de8c730ac96204f9/#dom-element-attachshadow
|
||||
already_AddRefed<ShadowRoot> Element::AttachShadow(const ShadowRootInit& aInit,
|
||||
ErrorResult& aError) {
|
||||
/**
|
||||
* 1. If context object's namespace is not the HTML namespace,
|
||||
* then throw a "NotSupportedError" DOMException.
|
||||
* 2. If context object's local name is not valid to attach shadow DOM to,
|
||||
* then throw a "NotSupportedError" DOMException.
|
||||
* Step 1, 2, and 3.
|
||||
*/
|
||||
if (!CanAttachShadowDOM()) {
|
||||
aError.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||
|
@ -1175,8 +1172,7 @@ already_AddRefed<ShadowRoot> Element::AttachShadow(const ShadowRootInit& aInit,
|
|||
}
|
||||
|
||||
/**
|
||||
* 4. If context object is a shadow host, then throw
|
||||
* an "NotSupportedError" DOMException.
|
||||
* 4. If this is a shadow host, then throw a "NotSupportedError" DOMException.
|
||||
*/
|
||||
if (GetShadowRoot()) {
|
||||
aError.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
||||
|
@ -1214,7 +1210,7 @@ already_AddRefed<ShadowRoot> Element::AttachShadowWithoutNameChecks(
|
|||
}
|
||||
|
||||
/**
|
||||
* 4. Let shadow be a new shadow root whose node document is
|
||||
* 5. Let shadow be a new shadow root whose node document is
|
||||
* context object's node document, host is context object,
|
||||
* and mode is init's mode.
|
||||
*/
|
||||
|
@ -1227,7 +1223,17 @@ already_AddRefed<ShadowRoot> Element::AttachShadowWithoutNameChecks(
|
|||
}
|
||||
|
||||
/**
|
||||
* 5. Set context object's shadow root to shadow.
|
||||
* 7. If this’s custom element state is "precustomized" or "custom", then set
|
||||
* shadow’s available to element internals to true.
|
||||
*/
|
||||
CustomElementData* ceData = GetCustomElementData();
|
||||
if (ceData && (ceData->mState == CustomElementData::State::ePrecustomized ||
|
||||
ceData->mState == CustomElementData::State::eCustom)) {
|
||||
shadowRoot->SetAvailableToElementInternals();
|
||||
}
|
||||
|
||||
/**
|
||||
* 9. Set context object's shadow root to shadow.
|
||||
*/
|
||||
SetShadowRoot(shadowRoot);
|
||||
|
||||
|
@ -1240,7 +1246,7 @@ already_AddRefed<ShadowRoot> Element::AttachShadowWithoutNameChecks(
|
|||
}
|
||||
|
||||
/**
|
||||
* 6. Return shadow.
|
||||
* 10. Return shadow.
|
||||
*/
|
||||
return shadowRoot.forget();
|
||||
}
|
||||
|
|
|
@ -54,7 +54,8 @@ ShadowRoot::ShadowRoot(Element* aElement, ShadowRootMode aMode,
|
|||
DocumentOrShadowRoot(this),
|
||||
mMode(aMode),
|
||||
mSlotAssignment(aSlotAssignment),
|
||||
mIsUAWidget(false) {
|
||||
mIsUAWidget(false),
|
||||
mIsAvailableToElementInternals(false) {
|
||||
SetHost(aElement);
|
||||
|
||||
// Nodes in a shadow tree should never store a value
|
||||
|
|
|
@ -208,6 +208,14 @@ class ShadowRoot final : public DocumentFragment,
|
|||
mIsUAWidget = true;
|
||||
}
|
||||
|
||||
bool IsAvailableToElementInternals() const {
|
||||
return mIsAvailableToElementInternals;
|
||||
}
|
||||
|
||||
void SetAvailableToElementInternals() {
|
||||
mIsAvailableToElementInternals = true;
|
||||
}
|
||||
|
||||
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
||||
|
||||
// nsIRadioGroupContainer
|
||||
|
@ -280,6 +288,9 @@ class ShadowRoot final : public DocumentFragment,
|
|||
|
||||
bool mIsUAWidget : 1;
|
||||
|
||||
// https://dom.spec.whatwg.org/#shadowroot-available-to-element-internals
|
||||
bool mIsAvailableToElementInternals : 1;
|
||||
|
||||
nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче