forked from mirrors/gecko-dev
Bug 1878045 - Progress element's max property should ignore non-positive values on setting. r=dom-core,edgar
Tests will be in WPT (https://github.com/web-platform-tests/wpt/pull/44355) Differential Revision: https://phabricator.services.mozilla.com/D200619
This commit is contained in:
parent
2205f758d4
commit
cfb5119fc0
2 changed files with 21 additions and 1 deletions
|
|
@ -37,7 +37,10 @@ class HTMLProgressElement final : public nsGenericHTMLElement {
|
|||
}
|
||||
double Max() const;
|
||||
void SetMax(double aValue, ErrorResult& aRv) {
|
||||
SetDoubleAttr(nsGkAtoms::max, aValue, aRv);
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-progress-max
|
||||
// The max IDL attribute must reflect the content attribute of the same
|
||||
// name, limited to only positive numbers.
|
||||
SetDoubleAttr<Reflection::OnlyPositive>(nsGkAtoms::max, aValue, aRv);
|
||||
}
|
||||
double Position() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -858,14 +858,31 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase {
|
|||
uint32_t GetDimensionAttrAsUnsignedInt(nsAtom* aAttr,
|
||||
uint32_t aDefault) const;
|
||||
|
||||
enum class Reflection {
|
||||
Unlimited,
|
||||
OnlyPositive,
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets value of attribute to specified double. Only works for attributes
|
||||
* in null namespace.
|
||||
*
|
||||
* Implements
|
||||
* https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:idl-double
|
||||
*
|
||||
* @param aAttr name of attribute.
|
||||
* @param aValue Double value of attribute.
|
||||
*/
|
||||
template <Reflection Limited = Reflection::Unlimited>
|
||||
void SetDoubleAttr(nsAtom* aAttr, double aValue, mozilla::ErrorResult& aRv) {
|
||||
// 1. If the reflected IDL attribute is limited to only positive numbers and
|
||||
// the given value is not greater than 0, then return.
|
||||
if (Limited == Reflection::OnlyPositive && aValue <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Run this's set the content attribute with the given value, converted
|
||||
// to the best representation of the number as a floating-point number.
|
||||
nsAutoString value;
|
||||
value.AppendFloat(aValue);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue