Bug 1694741 - Part 1: Support width and height attributes in HTMLSourceElement's webidl. r=emilio

This also introduce a pref which protect these two attributes:
dom.picture_source_dimension_attributes.enabled.

These two dimension attributes will be mapped to the style of <img> elements
if the <source> element's parent is <picture>. This will be implemented
in the later patch. For now, we just implement the DOM interface.

Differential Revision: https://phabricator.services.mozilla.com/D152585
This commit is contained in:
Boris Chiou 2022-08-22 20:18:37 +00:00
Родитель 59c20a4b1a
Коммит b0e1f7a8ac
5 изменённых файлов: 49 добавлений и 21 удалений

Просмотреть файл

@ -68,6 +68,20 @@ void HTMLSourceElement::UpdateMediaList(const nsAttrValue* aValue) {
mMediaList = MediaList::Create(mediaStr);
}
bool HTMLSourceElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
const nsAString& aValue,
nsIPrincipal* aMaybeScriptedPrincipal,
nsAttrValue& aResult) {
if (StaticPrefs::dom_picture_source_dimension_attributes_enabled() &&
aNamespaceID == kNameSpaceID_None &&
(aAttribute == nsGkAtoms::width || aAttribute == nsGkAtoms::height)) {
return aResult.ParseHTMLDimension(aValue);
}
return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
aMaybeScriptedPrincipal, aResult);
}
nsresult HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,

Просмотреть файл

@ -87,18 +87,31 @@ class HTMLSourceElement final : public nsGenericHTMLElement {
SetHTMLAttr(nsGkAtoms::media, aMedia, rv);
}
uint32_t Width() const { return GetUnsignedIntAttr(nsGkAtoms::width, 0); }
void SetWidth(uint32_t aWidth, ErrorResult& aRv) {
SetUnsignedIntAttr(nsGkAtoms::width, aWidth, 0, aRv);
}
uint32_t Height() const { return GetUnsignedIntAttr(nsGkAtoms::height, 0); }
void SetHeight(uint32_t aHeight, ErrorResult& aRv) {
SetUnsignedIntAttr(nsGkAtoms::height, aHeight, 0, aRv);
}
protected:
virtual ~HTMLSourceElement();
virtual JSObject* WrapNode(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
JSObject* WrapNode(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
protected:
virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) override;
bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
const nsAString& aValue,
nsIPrincipal* aMaybeScriptedPrincipal,
nsAttrValue& aResult) override;
nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
const nsAttrValue* aValue, const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) override;
private:
RefPtr<MediaList> mMediaList;

Просмотреть файл

@ -28,4 +28,10 @@ partial interface HTMLSourceElement {
attribute DOMString sizes;
[CEReactions, SetterThrows]
attribute DOMString media;
[CEReactions, SetterThrows,
Pref="dom.picture_source_dimension_attributes.enabled"]
attribute unsigned long width;
[CEReactions, SetterThrows,
Pref="dom.picture_source_dimension_attributes.enabled"]
attribute unsigned long height;
};

Просмотреть файл

@ -3132,6 +3132,13 @@
value: false
mirror: always
# This enables width and height attributes and map these attributes to img
# element's style.
- name: dom.picture_source_dimension_attributes.enabled
type: bool
value: false
mirror: always
# Is support for Element.requestPointerLock enabled?
# This is added for accessibility purpose. When user has no way to exit
# pointer lock (e.g. no keyboard available), they can use this pref to

Просмотреть файл

@ -1,4 +1,4 @@
prefs: [dom.security.featurePolicy.experimental.enabled:true, dom.security.featurePolicy.header.enabled:true, dom.security.featurePolicy.webidl.enabled:true, dom.forms.inputmode:true, dom.forms.enterkeyhint:true, dom.forms.autocapitalize:true, html5.inert.enabled:true]
prefs: [dom.security.featurePolicy.experimental.enabled:true, dom.security.featurePolicy.header.enabled:true, dom.security.featurePolicy.webidl.enabled:true, dom.forms.inputmode:true, dom.forms.enterkeyhint:true, dom.forms.autocapitalize:true, html5.inert.enabled:true, dom.picture_source_dimension_attributes.enabled:true]
[idlharness.https.html?exclude=(Document|Window|HTML.*)]
[AudioTrack interface: existence and properties of interface prototype object]
expected: FAIL
@ -677,18 +677,6 @@ prefs: [dom.security.featurePolicy.experimental.enabled:true, dom.security.featu
[HTMLIFrameElement interface: attribute loading]
expected: FAIL
[HTMLSourceElement interface: attribute width]
expected: FAIL
[HTMLSourceElement interface: attribute height]
expected: FAIL
[HTMLSourceElement interface: document.createElement("source") must inherit property "width" with the proper type]
expected: FAIL
[HTMLSourceElement interface: document.createElement("source") must inherit property "height" with the proper type]
expected: FAIL
[HTMLIFrameElement interface: document.createElement("iframe") must inherit property "loading" with the proper type]
expected: FAIL