Skip to content

Commit

Permalink
Fix <output>.defaultValue for descendant mutations
Browse files Browse the repository at this point in the history
The ChildrenChanged listener which updates defaultValue doesn't account
for mutations deeper than the first layer of children. This patch
accounts for it by computing textContent more often instead of relying
on ChildrenChanged.

This was brought up in this whatwg/html discussion [1]. Based on
domenic's suggestion [2], I heavily based this on the jsdom
implementation [3].

[1] whatwg/html#6516
[2] whatwg/html#6516 (comment)
[3] https://github.com/jsdom/jsdom/blob/04f6c13f4a4d387c7fc979b8f62c6f68d8a0c639/lib/jsdom/living/nodes/HTMLOutputElement-impl.js

Change-Id: I2f491f3c2759f1d3ca4fce1025f5677e34479d6f
Fixed: 1206416
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2878397
Reviewed-by: Mason Freed <masonf@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#881932}
  • Loading branch information
josepharhar authored and Chromium LUCI CQ committed May 12, 2021
1 parent e2542fe commit 922348f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
26 changes: 12 additions & 14 deletions third_party/blink/renderer/core/html/forms/html_output_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,35 @@ DOMTokenList* HTMLOutputElement::htmlFor() const {
return tokens_.Get();
}

void HTMLOutputElement::ChildrenChanged(const ChildrenChange& change) {
HTMLFormControlElement::ChildrenChanged(change);

if (is_default_value_mode_)
default_value_ = textContent();
}

void HTMLOutputElement::ResetImpl() {
// The reset algorithm for output elements is to set the element's
// value mode flag to "default" and then to set the element's textContent
// attribute to the default value.
if (default_value_ == value())
if (defaultValue() == value())
return;
setTextContent(default_value_);
setTextContent(defaultValue());
is_default_value_mode_ = true;
}

String HTMLOutputElement::value() const {
return textContent();
}

void HTMLOutputElement::setValue(const String& value) {
void HTMLOutputElement::setValue(const String& newValue) {
String oldValue = value();

if (is_default_value_mode_)
default_value_ = oldValue;

// The value mode flag set to "value" when the value attribute is set.
is_default_value_mode_ = false;
if (value == this->value())
return;
setTextContent(value);

if (newValue != oldValue)
setTextContent(newValue);
}

String HTMLOutputElement::defaultValue() const {
return default_value_;
return is_default_value_mode_ ? textContent() : default_value_;
}

void HTMLOutputElement::setDefaultValue(const String& value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class CORE_EXPORT HTMLOutputElement final : public HTMLFormControlElement {
bool IsEnumeratable() const override { return true; }
bool IsLabelable() const override { return true; }
bool SupportsFocus() const override;
void ChildrenChanged(const ChildrenChange&) override;
void ResetImpl() override;

bool is_default_value_mode_;
Expand Down

This file was deleted.

0 comments on commit 922348f

Please sign in to comment.