Match newly-clarified spec on textarea defaultValue/value/child text content
https://bugs.webkit.org/show_bug.cgi?id=173878
Reviewed by Darin Adler.
LayoutTests/imported/w3c:
Re-sync WPT test from upstream and rebaseline to improve test coverage.
* web-platform-tests/html/semantics/forms/the-textarea-element/value-defaultValue-textContent-expected.txt:
* web-platform-tests/html/semantics/forms/the-textarea-element/value-defaultValue-textContent.html:
Source/WebCore:
Update HTMLTextArea.defaultValue to match align with other browsers and match the
latest HTML specification:
- https://html.spec.whatwg.org/#dom-textarea-defaultvalue
The defaultValue getter should return the child text content:
- https://dom.spec.whatwg.org/#concept-child-text-content
Our code was traversing all Text descendants, not just the children.
The defaultValue setter should act as the setter of the Element's textContent
IDL attribute. Previously, we had a custom logic that was only removing the
text children.
Test: imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/value-defaultValue-textContent.html
* dom/ScriptElement.cpp:
(WebCore::ScriptElement::scriptContent const):
* dom/TextNodeTraversal.cpp:
(WebCore::TextNodeTraversal::childTextContent):
* dom/TextNodeTraversal.h:
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::defaultValue const):
(WebCore::HTMLTextAreaElement::setDefaultValue):
* html/HTMLTitleElement.cpp:
(WebCore::HTMLTitleElement::text const):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@220290 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/dom/TextNodeTraversal.cpp b/Source/WebCore/dom/TextNodeTraversal.cpp
index 112a284..b78ca79 100644
--- a/Source/WebCore/dom/TextNodeTraversal.cpp
+++ b/Source/WebCore/dom/TextNodeTraversal.cpp
@@ -54,5 +54,13 @@
return String();
}
+String childTextContent(const ContainerNode& root)
+{
+ StringBuilder result;
+ for (Text* text = TextNodeTraversal::firstChild(root); text; text = TextNodeTraversal::nextSibling(*text))
+ result.append(text->data());
+ return result.toString();
+}
+
}
}