Title: [115407] trunk
Revision
115407
Author
[email protected]
Date
2012-04-26 21:04:29 -0700 (Thu, 26 Apr 2012)

Log Message

datalist: Form control in a <datalist> should be barred from constraint validation
https://bugs.webkit.org/show_bug.cgi?id=84359

Source/WebCore:

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#the-datalist-element
According to this, if an element has a datalist element ancestor, it is barred from constraint validation.

Reviewed by Kent Tamura.

Test: fast/forms/datalist/datalist-child-validation.html

* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::HTMLFormControlElement):
(WebCore::HTMLFormControlElement::updateAncestors): Updates the ancestor information.
(WebCore::HTMLFormControlElement::insertedInto): Invalidates the ancestor information and calls setNeedsWillValidateCheck
(WebCore::HTMLFormControlElement::removedFrom): Invalidates the ancestor information and calls setNeedsWillValidateCheck
(WebCore::HTMLFormControlElement::disabled):
(WebCore::HTMLFormControlElement::recalcWillValidate): Returns false if element has a datalist ancestor.
(WebCore::HTMLFormControlElement::setNeedsWillValidateCheck): Check if ancestor information is valid too.
* html/HTMLFormControlElement.h:
(HTMLFormControlElement):

LayoutTests:

Reviewed by Kent Tamura.

* fast/forms/datalist/datalist-child-validation-expected.txt: Added.
* fast/forms/datalist/datalist-child-validation.html: Added. Tests that willValidate changes from false to true when we move the element out of the datalist.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (115406 => 115407)


--- trunk/LayoutTests/ChangeLog	2012-04-27 03:51:37 UTC (rev 115406)
+++ trunk/LayoutTests/ChangeLog	2012-04-27 04:04:29 UTC (rev 115407)
@@ -1,3 +1,13 @@
+2012-04-26  Keishi Hattori  <[email protected]>
+
+        datalist: Form control in a <datalist> should be barred from constraint validation
+        https://bugs.webkit.org/show_bug.cgi?id=84359
+
+        Reviewed by Kent Tamura.
+
+        * fast/forms/datalist/datalist-child-validation-expected.txt: Added.
+        * fast/forms/datalist/datalist-child-validation.html: Added. Tests that willValidate changes from false to true when we move the element out of the datalist.
+
 2012-04-26  Jeffrey Pfau  <[email protected]>
 
         Invalid cast in WebCore::HTMLCollection::isAcceptableElement

Added: trunk/LayoutTests/fast/forms/datalist/datalist-child-validation-expected.txt (0 => 115407)


--- trunk/LayoutTests/fast/forms/datalist/datalist-child-validation-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/datalist/datalist-child-validation-expected.txt	2012-04-27 04:04:29 UTC (rev 115407)
@@ -0,0 +1,12 @@
+Test for child elements of a datalist element.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS e.willValidate is false
+PASS e.willValidate is true
+PASS document.querySelector(":invalid") is e
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/datalist/datalist-child-validation.html (0 => 115407)


--- trunk/LayoutTests/fast/forms/datalist/datalist-child-validation.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/datalist/datalist-child-validation.html	2012-04-27 04:04:29 UTC (rev 115407)
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<datalist id="list">
+  <input type=text id=e required>
+</datalist>
+
+<script>
+description('Test for child elements of a datalist element.');
+
+var e = document.getElementById('e');
+shouldBeFalse('e.willValidate');
+document.body.appendChild(e);
+shouldBeTrue('e.willValidate');
+shouldBe('document.querySelector(":invalid")', 'e');
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (115406 => 115407)


--- trunk/Source/WebCore/ChangeLog	2012-04-27 03:51:37 UTC (rev 115406)
+++ trunk/Source/WebCore/ChangeLog	2012-04-27 04:04:29 UTC (rev 115407)
@@ -1,3 +1,26 @@
+2012-04-26  Keishi Hattori  <[email protected]>
+
+        datalist: Form control in a <datalist> should be barred from constraint validation
+        https://bugs.webkit.org/show_bug.cgi?id=84359
+
+        http://www.whatwg.org/specs/web-apps/current-work/multipage/the-button-element.html#the-datalist-element
+        According to this, if an element has a datalist element ancestor, it is barred from constraint validation.
+
+        Reviewed by Kent Tamura.
+
+        Test: fast/forms/datalist/datalist-child-validation.html
+
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::HTMLFormControlElement):
+        (WebCore::HTMLFormControlElement::updateAncestors): Updates the ancestor information.
+        (WebCore::HTMLFormControlElement::insertedInto): Invalidates the ancestor information and calls setNeedsWillValidateCheck
+        (WebCore::HTMLFormControlElement::removedFrom): Invalidates the ancestor information and calls setNeedsWillValidateCheck
+        (WebCore::HTMLFormControlElement::disabled):
+        (WebCore::HTMLFormControlElement::recalcWillValidate): Returns false if element has a datalist ancestor.
+        (WebCore::HTMLFormControlElement::setNeedsWillValidateCheck): Check if ancestor information is valid too.
+        * html/HTMLFormControlElement.h:
+        (HTMLFormControlElement):
+
 2012-04-26  Adrienne Walker  <[email protected]>
 
         [chromium] Remove unused CCLayerImpl::debugID()

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (115406 => 115407)


--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2012-04-27 03:51:37 UTC (rev 115406)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2012-04-27 04:04:29 UTC (rev 115407)
@@ -50,7 +50,7 @@
     : LabelableElement(tagName, document)
     , m_fieldSetAncestor(0)
     , m_legendAncestor(0)
-    , m_fieldSetAncestorValid(false)
+    , m_ancestorsValid(false)
     , m_disabled(false)
     , m_readOnly(false)
     , m_required(false)
@@ -60,6 +60,7 @@
     , m_isValid(true)
     , m_wasChangedSinceLastFormControlChangeEvent(false)
     , m_hasAutofocused(false)
+    , m_hasDataListAncestor(false)
 {
     setForm(form ? form : findFormAncestor());
     setHasCustomWillOrDidRecalcStyle();
@@ -100,19 +101,22 @@
     return fastHasAttribute(formnovalidateAttr);
 }
 
-void HTMLFormControlElement::updateFieldSetAndLegendAncestor() const
+void HTMLFormControlElement::updateAncestors() const
 {
+    m_hasDataListAncestor = false;
     m_fieldSetAncestor = 0;
     m_legendAncestor = 0;
     for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancestor->parentNode()) {
+        if (!m_hasDataListAncestor && ancestor->hasTagName(datalistTag))
+            m_hasDataListAncestor = true;
         if (!m_legendAncestor && ancestor->hasTagName(legendTag))
             m_legendAncestor = static_cast<HTMLLegendElement*>(ancestor);
-        if (ancestor->hasTagName(fieldsetTag)) {
+        if (!m_fieldSetAncestor && ancestor->hasTagName(fieldsetTag))
             m_fieldSetAncestor = static_cast<HTMLFieldSetElement*>(ancestor);
+        if (m_hasDataListAncestor && m_fieldSetAncestor)
             break;
-        }
     }
-    m_fieldSetAncestorValid = true;
+    m_ancestorsValid = true;
 }
 
 void HTMLFormControlElement::parseAttribute(Attribute* attr)
@@ -223,6 +227,8 @@
 
 Node::InsertionNotificationRequest HTMLFormControlElement::insertedInto(Node* insertionPoint)
 {
+    m_ancestorsValid = false;
+    setNeedsWillValidateCheck();
     HTMLElement::insertedInto(insertionPoint);
     FormAssociatedElement::insertedInto(insertionPoint);
     return InsertionDone;
@@ -230,7 +236,8 @@
 
 void HTMLFormControlElement::removedFrom(Node* insertionPoint)
 {
-    m_fieldSetAncestorValid = false;
+    m_ancestorsValid = false;
+    setNeedsWillValidateCheck();
     HTMLElement::removedFrom(insertionPoint);
     FormAssociatedElement::removedFrom(insertionPoint);
 }
@@ -273,8 +280,8 @@
     if (m_disabled)
         return true;
 
-    if (!m_fieldSetAncestorValid)
-        updateFieldSetAndLegendAncestor();
+    if (!m_ancestorsValid)
+        updateAncestors();
 
     // Form controls in the first legend element inside a fieldset are not affected by fieldset.disabled.
     if (m_fieldSetAncestor && m_fieldSetAncestor->disabled())
@@ -355,7 +362,7 @@
 {
     // FIXME: Should return false if this element has a datalist element as an
     // ancestor. See HTML5 4.10.10 'The datalist element.'
-    return !m_disabled && !m_readOnly;
+    return !m_hasDataListAncestor && !m_disabled && !m_readOnly;
 }
 
 bool HTMLFormControlElement::willValidate() const
@@ -374,6 +381,9 @@
 
 void HTMLFormControlElement::setNeedsWillValidateCheck()
 {
+    if (!m_ancestorsValid)
+        updateAncestors();
+
     // We need to recalculate willValidate immediately because willValidate change can causes style change.
     bool newWillValidate = recalcWillValidate();
     if (m_willValidateInitialized && m_willValidate == newWillValidate)

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (115406 => 115407)


--- trunk/Source/WebCore/html/HTMLFormControlElement.h	2012-04-27 03:51:37 UTC (rev 115406)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h	2012-04-27 04:04:29 UTC (rev 115407)
@@ -51,7 +51,7 @@
     void setFormMethod(const String&);
     bool formNoValidate() const;
 
-    void updateFieldSetAndLegendAncestor() const;
+    void updateAncestors() const;
 
     virtual void reset() { }
 
@@ -153,7 +153,7 @@
     mutable HTMLFieldSetElement* m_fieldSetAncestor;
     mutable HTMLLegendElement* m_legendAncestor;
     OwnPtr<ValidationMessage> m_validationMessage;
-    mutable bool m_fieldSetAncestorValid : 1;
+    mutable bool m_ancestorsValid : 1;
     bool m_disabled : 1;
     bool m_readOnly : 1;
     bool m_required : 1;
@@ -172,6 +172,7 @@
     bool m_wasChangedSinceLastFormControlChangeEvent : 1;
 
     bool m_hasAutofocused : 1;
+    mutable bool m_hasDataListAncestor : 1;
 };
 
 } // namespace
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to