fieldset:disabled > legend:first-child legend input should not be disabled
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Feb 2014 01:06:52 +0000 (01:06 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Feb 2014 01:06:52 +0000 (01:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=129068

Reviewed by Andreas Kling.

Source/WebCore:

An input element inside a disabled fieldset element is ordinarily disabled unless it's inside
a legend element that is the first of its kind to appear in the fieldset's child node list.

Prior to this patch, an input element inside such a legend element was erroneously disabled if
we had another legend element between the two as in <fieldset disabled><legend><legend><input>.

Fixed the bug by correcting the algorithm in updateAncestorDisabledState.

Test: fast/forms/fieldset/fieldset-disabled-2.html

* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::updateAncestorDisabledState):

LayoutTests:

Added a new regression test.

* fast/forms/fieldset/fieldset-disabled-2-expected.txt: Added.
* fast/forms/fieldset/fieldset-disabled-2.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@164403 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/fieldset/fieldset-disabled-2-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/fieldset/fieldset-disabled-2.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLFormControlElement.cpp

index 6e3bb6cbb27fc3367d149d79aff7c85e32986ff2..25a5e82fa178c2f61f0c4553aa94d3bdf478f648 100644 (file)
@@ -1,3 +1,15 @@
+2014-02-19  Ryosuke Niwa  <rniwa@webkit.org>
+
+        fieldset:disabled > legend:first-child legend input should not be disabled
+        https://bugs.webkit.org/show_bug.cgi?id=129068
+
+        Reviewed by Andreas Kling.
+
+        Added a new regression test.
+
+        * fast/forms/fieldset/fieldset-disabled-2-expected.txt: Added.
+        * fast/forms/fieldset/fieldset-disabled-2.html: Added.
+
 2014-02-18  Ryosuke Niwa  <rniwa@webkit.org>
 
         Changing selection shouldn't synchronously update editor UI components
diff --git a/LayoutTests/fast/forms/fieldset/fieldset-disabled-2-expected.txt b/LayoutTests/fast/forms/fieldset/fieldset-disabled-2-expected.txt
new file mode 100644 (file)
index 0000000..8a89129
--- /dev/null
@@ -0,0 +1,19 @@
+Additional tests for fieldset element disabling descendent input elements
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS isInputDisabledById("inputOutsideLegend") is true
+PASS isInputDisabledById("inputInsideFirstLegend") is false
+PASS isInputDisabledById("inputInsideSecondLegend") is true
+PASS isInputDisabledById("inputInsideNestedFirstLegend") is false
+
+setDisabledOnAllFieldsets(false)
+PASS isInputDisabledById("inputOutsideLegend") is false
+PASS isInputDisabledById("inputInsideFirstLegend") is false
+PASS isInputDisabledById("inputInsideSecondLegend") is false
+PASS isInputDisabledById("inputInsideNestedFirstLegend") is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/fieldset/fieldset-disabled-2.html b/LayoutTests/fast/forms/fieldset/fieldset-disabled-2.html
new file mode 100644 (file)
index 0000000..a3a7712
--- /dev/null
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../../../resources/js-test-pre.js"></script>
+<style type="text/css">
+input:enabled { color: #000; }
+input:disabled { color: #666; }
+</style>
+<div id="container">
+<input id="randomInput">
+<fieldset disabled><input id="inputOutsideLegend"></fieldset>
+<fieldset disabled><legend><input id="inputInsideFirstLegend"></legend></fieldset>
+<fieldset disabled><legend></legend><legend><input id="inputInsideSecondLegend"></legend></fieldset>
+<fieldset disabled><legend><legend><input id="inputInsideNestedFirstLegend"></legend></legend></fieldset>
+</div>
+<script>
+
+description("Additional tests for fieldset element disabling descendent input elements");
+
+function isInputDisabledById(id) {
+    var input = document.getElementById(id);
+    return getComputedStyle(input).color == 'rgb(102, 102, 102)';
+}
+
+shouldBeTrue('isInputDisabledById("inputOutsideLegend")');
+shouldBeFalse('isInputDisabledById("inputInsideFirstLegend")');
+shouldBeTrue('isInputDisabledById("inputInsideSecondLegend")');
+shouldBeFalse('isInputDisabledById("inputInsideNestedFirstLegend")');
+
+function setDisabledOnAllFieldsets(value) {
+    var fieldsets = document.querySelectorAll('fieldset');
+    for (var i = 0; i < fieldsets.length; i++)
+        fieldsets[i].disabled = value;
+}
+
+debug('');
+evalAndLog('setDisabledOnAllFieldsets(false)');
+shouldBeFalse('isInputDisabledById("inputOutsideLegend")');
+shouldBeFalse('isInputDisabledById("inputInsideFirstLegend")');
+shouldBeFalse('isInputDisabledById("inputInsideSecondLegend")');
+shouldBeFalse('isInputDisabledById("inputInsideNestedFirstLegend")');
+
+document.getElementById('container').style.display = 'none';
+
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
index ffb5c2a251fb3c41b21a84ccbd00f3e562cd8a04..af4d9ccd17cf275df8500cd958552930b61c35b4 100644 (file)
@@ -1,3 +1,23 @@
+2014-02-19  Ryosuke Niwa  <rniwa@webkit.org>
+
+        fieldset:disabled > legend:first-child legend input should not be disabled
+        https://bugs.webkit.org/show_bug.cgi?id=129068
+
+        Reviewed by Andreas Kling.
+
+        An input element inside a disabled fieldset element is ordinarily disabled unless it's inside
+        a legend element that is the first of its kind to appear in the fieldset's child node list.
+
+        Prior to this patch, an input element inside such a legend element was erroneously disabled if
+        we had another legend element between the two as in <fieldset disabled><legend><legend><input>.
+
+        Fixed the bug by correcting the algorithm in updateAncestorDisabledState.
+
+        Test: fast/forms/fieldset/fieldset-disabled-2.html
+
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::updateAncestorDisabledState):
+
 2014-02-18  Ryosuke Niwa  <rniwa@webkit.org>
 
         Changing selection shouldn't synchronously update editor UI components
index 8f7bd97293bbb8a2a940d2e465abe2317497353d..9eb604f916f9f370a613e7fcf2b08759f398bfc6 100644 (file)
@@ -101,17 +101,17 @@ bool HTMLFormControlElement::formNoValidate() const
 
 void HTMLFormControlElement::updateAncestorDisabledState() const
 {
-    HTMLFieldSetElement* fieldSetAncestor = 0;
-    ContainerNode* legendAncestor = 0;
-    for (ContainerNode* ancestor = parentNode(); ancestor; ancestor = ancestor->parentNode()) {
-        if (!legendAncestor && ancestor->hasTagName(legendTag))
-            legendAncestor = ancestor;
-        if (ancestor->hasTagName(fieldsetTag)) {
-            fieldSetAncestor = toHTMLFieldSetElement(ancestor);
-            break;
+    Element* previousAncestor = nullptr;
+    for (Element* ancestor = parentElement(); ancestor; ancestor = ancestor->parentElement()) {
+        if (isHTMLFieldSetElement(ancestor)) {
+            HTMLFieldSetElement& fieldSetAncestor = toHTMLFieldSetElement(*ancestor);
+            bool isInFirstLegend = previousAncestor && isHTMLLegendElement(previousAncestor) && previousAncestor == fieldSetAncestor.legend();
+            m_ancestorDisabledState = !fieldSetAncestor.isDisabledFormControl() || isInFirstLegend ? AncestorDisabledStateEnabled : AncestorDisabledStateDisabled;
+            return;
         }
+        previousAncestor = ancestor;
     }
-    m_ancestorDisabledState = (fieldSetAncestor && fieldSetAncestor->isDisabledFormControl() && !(legendAncestor && legendAncestor == fieldSetAncestor->legend())) ? AncestorDisabledStateDisabled : AncestorDisabledStateEnabled;
+    m_ancestorDisabledState = AncestorDisabledStateEnabled;
 }
 
 void HTMLFormControlElement::ancestorDisabledStateWasChanged()