Skip to content

Commit 819e12e

Browse files
committed
Bug 1919718 - Part 3: Update color on AfterSetAttr and add tests r=emilio
I realized that this should not be specific to IDL setter. Differential Revision: https://phabricator.services.mozilla.com/D278959
1 parent 43f88cf commit 819e12e

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

dom/html/HTMLInputElement.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,8 @@ void HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
15531553
}
15541554
UpdatePlaceholderShownState();
15551555
needValidityUpdate = true;
1556+
} else if (aName == nsGkAtoms::colorspace || aName == nsGkAtoms::alpha) {
1557+
UpdateColor();
15561558
}
15571559

15581560
if (CreatesDateTimeWidget()) {
@@ -1629,11 +1631,6 @@ bool HTMLInputElement::Alpha() const {
16291631
return HasAttr(nsGkAtoms::alpha);
16301632
}
16311633

1632-
void HTMLInputElement::SetAlpha(bool aValue, ErrorResult& aRv) {
1633-
SetHTMLBoolAttr(nsGkAtoms::alpha, aValue, aRv);
1634-
UpdateColor();
1635-
}
1636-
16371634
void HTMLInputElement::GetAutocomplete(nsAString& aValue) {
16381635
if (!DoesAutocompleteApply()) {
16391636
return;
@@ -1680,12 +1677,6 @@ StyleColorSpace HTMLInputElement::GetColorSpaceEnum() const {
16801677
return StyleColorSpace::Srgb;
16811678
}
16821679

1683-
void HTMLInputElement::SetColorSpace(const nsAString& aValue,
1684-
ErrorResult& aRv) {
1685-
SetHTMLAttr(nsGkAtoms::colorspace, aValue, aRv);
1686-
UpdateColor();
1687-
}
1688-
16891680
void HTMLInputElement::GetFormEnctype(nsAString& aValue) {
16901681
GetEnumAttr(nsGkAtoms::formenctype, "", kFormDefaultEnctype->tag, aValue);
16911682
}
@@ -2187,6 +2178,10 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY void HTMLInputElement::UpdateColor() {
21872178
// agent must run update a color well control color given the element.
21882179
// (But it involves setting value, which will run sanitization, which will
21892180
// call the same function. So we just call Get/SetValue here.)
2181+
if (mType != FormControlType::InputColor) {
2182+
// This is only needed for color, basically no-op for others.
2183+
return;
2184+
}
21902185
if (!mValueChanged) {
21912186
SetDefaultValueAsValue();
21922187
return;

dom/html/HTMLInputElement.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ class HTMLInputElement final : public TextControlElement,
453453
}
454454

455455
bool Alpha() const;
456-
void SetAlpha(bool aValue, ErrorResult& aRv);
456+
void SetAlpha(bool aValue, ErrorResult& aRv) {
457+
SetHTMLBoolAttr(nsGkAtoms::alpha, aValue, aRv);
458+
}
457459

458460
void GetAlt(nsAString& aValue) { GetHTMLAttr(nsGkAtoms::alt, aValue); }
459461
void SetAlt(const nsAString& aValue, ErrorResult& aRv) {
@@ -483,7 +485,9 @@ class HTMLInputElement final : public TextControlElement,
483485

484486
void GetColorSpace(nsAString& aValue) const;
485487
StyleColorSpace GetColorSpaceEnum() const;
486-
void SetColorSpace(const nsAString& aValue, ErrorResult& aRv);
488+
void SetColorSpace(const nsAString& aValue, ErrorResult& aRv) {
489+
SetHTMLAttr(nsGkAtoms::colorspace, aValue, aRv);
490+
}
487491

488492
bool IsRadioOrCheckbox() const {
489493
return mType == FormControlType::InputCheckbox ||

testing/web-platform/tests/html/semantics/forms/the-input-element/color.window.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,19 @@ test(() => {
244244
input.value = "color(display-p3 3 none .2 / .6)";
245245
assert_equals(input.value, "color(display-p3 3 0 0.2 / 0.6)");
246246
}, "Display P3 colors can be out-of-bounds");
247+
248+
test(() => {
249+
const input = document.createElement("input");
250+
input.type = "color";
251+
input.value = "white";
252+
input.setAttribute("colorspace", "display-p3");
253+
assert_equals(input.value, "color(display-p3 1 1 1)");
254+
}, "Setting colorspace by setAttribute should update the value");
255+
256+
test(() => {
257+
const input = document.createElement("input");
258+
input.type = "color";
259+
input.value = "blue";
260+
input.setAttribute("alpha", "");
261+
assert_equals(input.value, "color(srgb 0 0 1)");
262+
}, "Setting alpha by setAttribute should update the value");

0 commit comments

Comments
 (0)