Title: [134510] trunk
Revision
134510
Author
[email protected]
Date
2012-11-13 17:08:46 -0800 (Tue, 13 Nov 2012)

Log Message

Make HTMLLegendElement.form behave according to specification
https://bugs.webkit.org/show_bug.cgi?id=101044

Patch by Christophe Dumez <[email protected]> on 2012-11-13
Reviewed by Kent Tamura.

Source/WebCore:

According to the HTML5 specification (http://dev.w3.org/html5/spec/single-page.html#dom-legend-form),
The form IDL attribute's behavior depends on whether the legend element is in a fieldset element or
not. If the legend has a fieldset element as its parent, then the form IDL attribute must return the
same value as the form IDL attribute on that fieldset element. Otherwise, it must return null.

This patch makes WebKit behaves according to specification (and Firefox). Previously, legend.form was
not returning null if the element was not inside a fieldset. Also, legend.form did not necessarily
return the same value as the parent fieldset's form attribute.

Test: fast/forms/legend/legend-form.html

* html/HTMLLegendElement.cpp:
(WebCore):
(WebCore::HTMLLegendElement::virtualForm):
* html/HTMLLegendElement.h:
(HTMLLegendElement):

LayoutTests:

A new fast/forms/legend/legend-form.html test to check that
the legend element's form attribute behaves according to
specification.

* fast/forms/legend/legend-form-expected.txt: Added.
* fast/forms/legend/legend-form.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (134509 => 134510)


--- trunk/LayoutTests/ChangeLog	2012-11-14 01:06:41 UTC (rev 134509)
+++ trunk/LayoutTests/ChangeLog	2012-11-14 01:08:46 UTC (rev 134510)
@@ -1,3 +1,17 @@
+2012-11-13  Christophe Dumez  <[email protected]>
+
+        Make HTMLLegendElement.form behave according to specification
+        https://bugs.webkit.org/show_bug.cgi?id=101044
+
+        Reviewed by Kent Tamura.
+
+        A new fast/forms/legend/legend-form.html test to check that
+        the legend element's form attribute behaves according to
+        specification.
+
+        * fast/forms/legend/legend-form-expected.txt: Added.
+        * fast/forms/legend/legend-form.html: Added.
+
 2012-11-13  Dimitri Glazkov  <[email protected]>
 
         Unreviewed, rolling out r134377.

Added: trunk/LayoutTests/fast/forms/legend/legend-form-expected.txt (0 => 134510)


--- trunk/LayoutTests/fast/forms/legend/legend-form-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/legend/legend-form-expected.txt	2012-11-14 01:08:46 UTC (rev 134510)
@@ -0,0 +1,21 @@
+This test checks the form attribute of the legend element.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+- Ensures that the form attribute of legend element depends on whether its parent is a fieldset element or not.
+PASS legendElement1.form is owner
+PASS legendElement2.form is null
+PASS legendElement3.form is null
+
+- Ensures that the legend's form attribute points its parent fieldset's form owner even if the element is within another form element.
+PASS fieldsetElement.form is owner
+PASS legendElement.form is owner
+
+- Ensures whether the form owner is set correctly for the legend when the value of form attribute of its parent fieldset changed.
+PASS fieldsetElement.form is form1
+PASS legendElement.form is form1
+PASS fieldsetElement.form is form2
+PASS legendElement.form is form2
+

Added: trunk/LayoutTests/fast/forms/legend/legend-form.html (0 => 134510)


--- trunk/LayoutTests/fast/forms/legend/legend-form.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/legend/legend-form.html	2012-11-14 01:08:46 UTC (rev 134510)
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+description("This test checks the form attribute of the legend element.");
+
+var container = document.createElement('div');
+document.body.appendChild(container);
+
+debug('');
+debug('- Ensures that the form attribute of legend element depends on whether its parent is a fieldset element or not.');
+container.innerHTML = '<form id=owner>' +
+    '    <fieldset><legend id=legendElement1 name=victim /></fieldset>' +
+    '    <legend id=legendElement2 name=victim />' +
+    '    <fieldset><div><legend id=legendElement3 name=victim /></div></fieldset>' +
+    '</form>';
+owner = document.getElementById('owner');
+var legendElement1 = document.getElementById('legendElement1');
+var legendElement2 = document.getElementById('legendElement2');
+shouldBe('legendElement1.form', 'owner');
+shouldBe('legendElement2.form', 'null');
+shouldBe('legendElement3.form', 'null');
+
+debug('');
+debug('- Ensures that the legend\'s form attribute points its parent fieldset\'s form owner even if the element is within another form element.');
+container.innerHTML = '<form id=owner></form>' +
+    '<form id=shouldNotBeOwner>' +
+    '    <fieldset id=fieldsetElement name=victim form=owner>' +
+    '        <legend id=legendElement name=victim />' +
+    '    </fieldset>' +
+    '</form>';
+owner = document.getElementById('owner');
+var inputElement = document.getElementById('fieldsetElement');
+var labelElement = document.getElementById('legendElement');
+shouldBe('fieldsetElement.form', 'owner');
+shouldBe('legendElement.form', 'owner');
+
+debug('');
+debug('- Ensures whether the form owner is set correctly for the legend when the value of form attribute of its parent fieldset changed.');
+container.innerHTML = '<form id=form1></form>' +
+    '<form id=form2></form>' +
+    '<fieldset id=fieldsetElement name=victim form=form1>' +
+    '    <legend id=legendElement />' +
+    '</fieldset>';
+var form1 = document.getElementById('form1');
+var form2 = document.getElementById('form2');
+fieldsetElement = document.getElementById('fieldsetElement');
+legendElement = document.getElementById('legendElement');
+shouldBe('fieldsetElement.form', 'form1');
+shouldBe('legendElement.form', 'form1');
+fieldsetElement.attributes['form'].value = 'form2';
+shouldBe('fieldsetElement.form', 'form2');
+shouldBe('legendElement.form', 'form2');
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (134509 => 134510)


--- trunk/Source/WebCore/ChangeLog	2012-11-14 01:06:41 UTC (rev 134509)
+++ trunk/Source/WebCore/ChangeLog	2012-11-14 01:08:46 UTC (rev 134510)
@@ -1,3 +1,27 @@
+2012-11-13  Christophe Dumez  <[email protected]>
+
+        Make HTMLLegendElement.form behave according to specification
+        https://bugs.webkit.org/show_bug.cgi?id=101044
+
+        Reviewed by Kent Tamura.
+
+        According to the HTML5 specification (http://dev.w3.org/html5/spec/single-page.html#dom-legend-form),
+        The form IDL attribute's behavior depends on whether the legend element is in a fieldset element or
+        not. If the legend has a fieldset element as its parent, then the form IDL attribute must return the
+        same value as the form IDL attribute on that fieldset element. Otherwise, it must return null.
+
+        This patch makes WebKit behaves according to specification (and Firefox). Previously, legend.form was
+        not returning null if the element was not inside a fieldset. Also, legend.form did not necessarily
+        return the same value as the parent fieldset's form attribute.
+
+        Test: fast/forms/legend/legend-form.html
+
+        * html/HTMLLegendElement.cpp:
+        (WebCore):
+        (WebCore::HTMLLegendElement::virtualForm):
+        * html/HTMLLegendElement.h:
+        (HTMLLegendElement):
+
 2012-11-13  Mark Lam  <[email protected]>
 
         Make an assertion in JSEventListener::jsFunction() more useful.

Modified: trunk/Source/WebCore/html/HTMLLegendElement.cpp (134509 => 134510)


--- trunk/Source/WebCore/html/HTMLLegendElement.cpp	2012-11-14 01:06:41 UTC (rev 134509)
+++ trunk/Source/WebCore/html/HTMLLegendElement.cpp	2012-11-14 01:08:46 UTC (rev 134510)
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "HTMLLegendElement.h"
 
+#include "HTMLFieldSetElement.h"
 #include "HTMLFormControlElement.h"
 #include "HTMLNames.h"
 #include <wtf/StdLibExtras.h>
@@ -83,5 +84,17 @@
     if (HTMLFormControlElement* control = associatedControl())
         control->accessKeyAction(sendMouseEvents);
 }
+
+HTMLFormElement* HTMLLegendElement::virtualForm() const
+{
+    // According to the specification, If the legend has a fieldset element as
+    // its parent, then the form attribute must return the same value as the
+    // form attribute on that fieldset element. Otherwise, it must return null.
+    ContainerNode* fieldset = parentNode();
+    if (!fieldset || !fieldset->hasTagName(fieldsetTag))
+        return 0;
+
+    return static_cast<HTMLFieldSetElement*>(fieldset)->form();
+}
     
 } // namespace

Modified: trunk/Source/WebCore/html/HTMLLegendElement.h (134509 => 134510)


--- trunk/Source/WebCore/html/HTMLLegendElement.h	2012-11-14 01:06:41 UTC (rev 134509)
+++ trunk/Source/WebCore/html/HTMLLegendElement.h	2012-11-14 01:08:46 UTC (rev 134510)
@@ -42,6 +42,7 @@
 
     virtual void accessKeyAction(bool sendMouseEvents);
     virtual void focus(bool restorePreviousSelection = true);
+    virtual HTMLFormElement* virtualForm() const OVERRIDE;
 };
 
 } //namespace
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to