зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1556373 - Implement labels attribute of ElementInternals; r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D126130
This commit is contained in:
Родитель
18fb16c542
Коммит
4485bbef82
|
@ -56,6 +56,17 @@ HTMLFormElement* ElementInternals::GetForm(ErrorResult& aRv) const {
|
|||
return GetForm();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#dom-elementinternals-labels
|
||||
already_AddRefed<nsINodeList> ElementInternals::GetLabels(
|
||||
ErrorResult& aRv) const {
|
||||
if (!mTarget || !mTarget->IsFormAssociatedElement()) {
|
||||
aRv.ThrowNotSupportedError(
|
||||
"Target element is not a form-associated custom element");
|
||||
return nullptr;
|
||||
}
|
||||
return mTarget->Labels();
|
||||
}
|
||||
|
||||
void ElementInternals::SetForm(HTMLFormElement* aForm) { mForm = aForm; }
|
||||
|
||||
void ElementInternals::ClearForm(bool aRemoveFromForm, bool aUnbindOrDelete) {
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
#include "nsIFormControl.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
class nsINodeList;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class ErrorResult;
|
||||
|
@ -38,6 +40,7 @@ class ElementInternals final : public nsIFormControl, public nsWrapperCache {
|
|||
// WebIDL
|
||||
ShadowRoot* GetShadowRoot() const;
|
||||
mozilla::dom::HTMLFormElement* GetForm(ErrorResult& aRv) const;
|
||||
already_AddRefed<nsINodeList> GetLabels(ErrorResult& aRv) const;
|
||||
|
||||
// nsIFormControl
|
||||
mozilla::dom::HTMLFieldSetElement* GetFieldSet() override {
|
||||
|
|
|
@ -26,6 +26,7 @@ class HTMLElement final : public nsGenericHTMLFormElement {
|
|||
// Element
|
||||
void SetCustomElementDefinition(
|
||||
CustomElementDefinition* aDefinition) override;
|
||||
bool IsLabelable() const override { return IsFormAssociatedElement(); }
|
||||
|
||||
// nsGenericHTMLElement
|
||||
// https://html.spec.whatwg.org/multipage/custom-elements.html#dom-attachinternals
|
||||
|
|
|
@ -15,4 +15,7 @@ interface ElementInternals {
|
|||
// Form-associated custom elements
|
||||
[Pref="dom.webcomponents.formAssociatedCustomElement.enabled", Throws]
|
||||
readonly attribute HTMLFormElement? form;
|
||||
|
||||
[Pref="dom.webcomponents.formAssociatedCustomElement.enabled", Throws]
|
||||
readonly attribute NodeList labels;
|
||||
};
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
[ElementInternals-labels.html]
|
||||
[LABEL click]
|
||||
expected: FAIL
|
||||
|
||||
[LABEL association]
|
||||
expected: FAIL
|
||||
|
|
@ -295,7 +295,8 @@ prefs: [dom.security.featurePolicy.experimental.enabled:true, dom.security.featu
|
|||
expected: FAIL
|
||||
|
||||
[ElementInternals interface: attribute labels]
|
||||
expected: FAIL
|
||||
expected:
|
||||
if release_or_beta: FAIL
|
||||
|
||||
[AudioTrack interface: attribute id]
|
||||
expected: FAIL
|
||||
|
|
|
@ -36,6 +36,10 @@ test(() => {
|
|||
const labels = container.querySelectorAll('label');
|
||||
control = container.querySelector('my-control');
|
||||
assert_array_equals(control.i.labels, labels);
|
||||
|
||||
container.innerHTML = '<my-control></my-control>';
|
||||
control = container.querySelector('my-control');
|
||||
assert_array_equals(control.i.labels, []);
|
||||
}, 'LABEL association');
|
||||
|
||||
test(() => {
|
||||
|
@ -46,5 +50,14 @@ test(() => {
|
|||
container.querySelector('label').click();
|
||||
assert_equals(clickCount, 1);
|
||||
}, 'LABEL click');
|
||||
|
||||
test(() => {
|
||||
class NotFormAssociatedElement extends HTMLElement {}
|
||||
customElements.define('not-form-associated-element', NotFormAssociatedElement);
|
||||
const element = new NotFormAssociatedElement();
|
||||
const i = element.attachInternals();
|
||||
assert_throws_dom('NotSupportedError', () => i.labels);
|
||||
}, "ElementInternals.labels should throw NotSupportedError if the target element is not a form-associated custom element");
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
|
Загрузка…
Ссылка в новой задаче