Bug 557087 (1/6) - Fieldset elements can be disabled. r+a=sicking
authorMounir Lamouri <mounir.lamouri@gmail.com>
Sat, 18 Sep 2010 23:24:58 +0200
changeset 54341 61050f17467d
parent 54340 c6e08993db4c
child 54342 b15d9c989201
push id15858
push usermlamouri@mozilla.com
push dateMon, 20 Sep 2010 03:35:23 +0000
treeherdermozilla-central@8b47f3cabf9f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs557087
milestone2.0b7pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 557087 (1/6) - Fieldset elements can be disabled. r+a=sicking
content/html/content/src/nsGenericHTMLElement.cpp
content/html/content/src/nsHTMLFieldSetElement.cpp
content/html/content/test/Makefile.in
content/html/content/test/test_bug557087-1.html
dom/interfaces/html/nsIDOMHTMLFieldSetElement.idl
layout/reftests/bugs/84400-2-ref.html
layout/reftests/bugs/84400-2.html
layout/reftests/css-disabled/fieldset/fieldset-disabled.html
layout/reftests/css-disabled/fieldset/fieldset-enabled.html
layout/reftests/css-disabled/fieldset/fieldset-ref.html
layout/reftests/css-disabled/fieldset/reftest.list
layout/reftests/css-disabled/fieldset/style.css
layout/reftests/css-disabled/reftest.list
layout/reftests/css-enabled/fieldset/fieldset-disabled.html
layout/reftests/css-enabled/fieldset/fieldset-enabled.html
layout/reftests/css-enabled/fieldset/fieldset-ref.html
layout/reftests/css-enabled/fieldset/reftest.list
layout/reftests/css-enabled/fieldset/style.css
layout/reftests/css-enabled/reftest.list
layout/reftests/reftest.list
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -2682,17 +2682,16 @@ nsGenericHTMLFormElement::PreHandleEvent
 
 PRBool
 nsGenericHTMLFormElement::CanBeDisabled() const
 {
   PRInt32 type = GetType();
   // It's easier to test the types that _cannot_ be disabled
   return
     type != NS_FORM_LABEL &&
-    type != NS_FORM_FIELDSET &&
     type != NS_FORM_OBJECT &&
     type != NS_FORM_OUTPUT;
 }
 
 PRBool
 nsGenericHTMLFormElement::IsSubmitControl() const
 {
   PRInt32 type = GetType();
--- a/content/html/content/src/nsHTMLFieldSetElement.cpp
+++ b/content/html/content/src/nsHTMLFieldSetElement.cpp
@@ -37,16 +37,17 @@
 #include "nsIDOMHTMLFieldSetElement.h"
 #include "nsIDOMHTMLFormElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsStyleConsts.h"
 #include "nsIForm.h"
 #include "nsIFormControl.h"
 #include "nsIConstraintValidation.h"
+#include "nsEventDispatcher.h"
 
 
 class nsHTMLFieldSetElement : public nsGenericHTMLFormElement,
                               public nsIDOMHTMLFieldSetElement,
                               public nsIConstraintValidation
 {
 public:
   using nsIConstraintValidation::GetValidationMessage;
@@ -64,16 +65,19 @@ public:
   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::)
 
   // nsIDOMHTMLFieldSetElement
   NS_DECL_NSIDOMHTMLFIELDSETELEMENT
 
+  // nsIContent
+  virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
+
   // nsIFormControl
   NS_IMETHOD_(PRUint32) GetType() const { return NS_FORM_FIELDSET; }
   NS_IMETHOD Reset();
   NS_IMETHOD SubmitNamesValues(nsFormSubmission* aFormSubmission);
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
   virtual nsXPCClassInfo* GetClassInfo();
 
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLFieldSetElement,
@@ -129,21 +133,35 @@ NS_INTERFACE_TABLE_HEAD(nsHTMLFieldSetEl
                                    nsIConstraintValidation)
   NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLFieldSetElement,
                                                nsGenericHTMLFormElement)
 NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLFieldSetElement)
 
 NS_IMPL_ELEMENT_CLONE(nsHTMLFieldSetElement)
 
 
+NS_IMPL_BOOL_ATTR(nsHTMLFieldSetElement, Disabled, disabled)
 NS_IMPL_STRING_ATTR(nsHTMLFieldSetElement, Name, name)
 
 // nsIConstraintValidation
 NS_IMPL_NSICONSTRAINTVALIDATION(nsHTMLFieldSetElement)
 
+// nsIContent
+nsresult
+nsHTMLFieldSetElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
+{
+  // Do not process any DOM events if the element is disabled.
+  aVisitor.mCanHandle = PR_FALSE;
+  if (HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) {
+    return NS_OK;
+  }
+
+  return nsGenericHTMLFormElement::PreHandleEvent(aVisitor);
+}
+
 // nsIDOMHTMLFieldSetElement
 
 NS_IMETHODIMP
 nsHTMLFieldSetElement::GetForm(nsIDOMHTMLFormElement** aForm)
 {
   return nsGenericHTMLFormElement::GetForm(aForm);
 }
 
--- a/content/html/content/test/Makefile.in
+++ b/content/html/content/test/Makefile.in
@@ -224,12 +224,13 @@ include $(topsrcdir)/config/rules.mk
 		test_bug557628-1.html \
 		test_bug557628-2.html \
 		test_bug592802.html \
 		test_bug589696.html \
 		test_bug595429.html \
 		test_bug595447.html \
 		test_bug595449.html \
 		test_bug595457.html \
+		test_bug557087-1.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/test_bug557087-1.html
@@ -0,0 +1,127 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=557087
+-->
+<head>
+  <title>Test for Bug 557087</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=557087">Mozilla Bug 557087</a>
+<p id="display"></p>
+<div id="content">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 557087 **/
+
+function checkDisabledAttribute(aFieldset)
+{
+  ok('disabled' in aFieldset,
+     "fieldset elements should have the disabled attribute");
+
+  ok(!aFieldset.disabled,
+     "fieldset elements disabled attribute should be disabled");
+  is(aFieldset.getAttribute('disabled'), null,
+    "fieldset elements disabled attribute should be disabled");
+
+  aFieldset.disabled = true;
+  ok(aFieldset.disabled,
+     "fieldset elements disabled attribute should be enabled");
+  isnot(aFieldset.getAttribute('disabled'), null,
+    "fieldset elements disabled attribute should be enabled");
+
+  aFieldset.removeAttribute('disabled');
+  aFieldset.setAttribute('disabled', '');
+  ok(aFieldset.disabled,
+     "fieldset elements disabled attribute should be enabled");
+  isnot(aFieldset.getAttribute('disabled'), null,
+    "fieldset elements disabled attribute should be enabled");
+
+  aFieldset.removeAttribute('disabled');
+  ok(!aFieldset.disabled,
+     "fieldset elements disabled attribute should be disabled");
+  is(aFieldset.getAttribute('disabled'), null,
+    "fieldset elements disabled attribute should be disabled");
+}
+
+function checkDisabledPseudoClass(aFieldset)
+{
+  is(document.querySelector(":disabled"), null,
+     "no elements should have :disabled applied to them");
+
+  aFieldset.disabled = true;
+  is(document.querySelector(":disabled"), aFieldset,
+     ":disabled should apply to fieldset elements");
+
+  aFieldset.disabled = false;
+  is(document.querySelector(":disabled"), null,
+     "no elements should have :disabled applied to them");
+}
+
+function checkEnabledPseudoClass(aFieldset)
+{
+  is(document.querySelector(":enabled"), aFieldset,
+     ":enabled should apply to fieldset elements");
+
+  aFieldset.disabled = true;
+  is(document.querySelector(":enabled"), null,
+     "no elements should have :enabled applied to them");
+
+  aFieldset.disabled = false;
+  is(document.querySelector(":enabled"), aFieldset,
+     ":enabled should apply to fieldset elements");
+}
+
+function checkFocus(aFieldset)
+{
+  aFieldset.disabled = true;
+  aFieldset.setAttribute('tabindex', 1);
+
+  aFieldset.focus();
+
+  isnot(document.activeElement, aFieldset,
+        "fieldset can't be focused when disabled");
+  aFieldset.removeAttribute('tabindex');
+  aFieldset.disabled = false;
+}
+
+function checkClickEvent(aFieldset)
+{
+  var clickHandled = false;
+
+  aFieldset.disabled = true;
+
+  aFieldset.addEventListener("click", function(aEvent) {
+    aEvent.target.removeEventListener("click", arguments.callee, false);
+    clickHandled = true;
+  }, false);
+
+  sendMouseEvent({type:'click'}, aFieldset);
+  SimpleTest.executeSoon(function() {
+    ok(!clickHandled, "When disabled, fieldset should prevent click events");
+    SimpleTest.finish();
+  });
+}
+
+SimpleTest.waitForExplicitFinish();
+
+var fieldset = document.createElement("fieldset");
+var content  = document.getElementById('content');
+content.appendChild(fieldset);
+
+checkDisabledAttribute(fieldset);
+checkDisabledPseudoClass(fieldset);
+checkEnabledPseudoClass(fieldset);
+checkFocus(fieldset);
+checkClickEvent(fieldset);
+
+</script>
+</pre>
+</body>
+</html>
--- a/dom/interfaces/html/nsIDOMHTMLFieldSetElement.idl
+++ b/dom/interfaces/html/nsIDOMHTMLFieldSetElement.idl
@@ -44,19 +44,20 @@
  * [X]HTML fieldset element.
  *
  * For more information on this interface please see
  * http://www.w3.org/TR/DOM-Level-2-HTML/
  */
 
 interface nsIDOMValidityState;
 
-[scriptable, uuid(b38efb33-ec68-487a-bf9b-2920425fa408)]
+[scriptable, uuid(58db2166-36fc-482c-a9f8-84ad262537b2)]
 interface nsIDOMHTMLFieldSetElement : nsIDOMHTMLElement
 {
+           attribute boolean                disabled;
   readonly attribute nsIDOMHTMLFormElement  form;
            attribute DOMString              name;
 
   readonly attribute DOMString              type;
 
   readonly attribute nsIDOMHTMLCollection   elements;
 
   // The following lines are parte of the constraint validation API, see:
--- a/layout/reftests/bugs/84400-2-ref.html
+++ b/layout/reftests/bugs/84400-2-ref.html
@@ -26,23 +26,16 @@
 
       <div>
 	label:
 	<label>bogus</label> <span>FAIL</span>
 	<label disabled="disabled">bogus</label> <span>FAIL</span>
       </div>      
 
       <div>
-	fieldset:
-	<fieldset class="hideme"><legend>bogus</legend></fieldset> <span>FAIL</span>
-	<fieldset class="hideme" disabled="disabled"><legend>bogus</legend></fieldset> <span>FAIL</span>
-	<fieldset class="hideme"><legend disabled="disabled">bogus</legend></fieldset> <span>FAIL</span>
-      </div>
-
-      <div>
 	legend:
 	<fieldset><legend>FAIL</legend></fieldset>
 	<fieldset><legend disabled="disabled">FAIL</legend></fieldset>
 	<fieldset disabled="disabled"><legend>FAIL</legend></fieldset>
       </div>
 
       <div>
 	div (inside form):
--- a/layout/reftests/bugs/84400-2.html
+++ b/layout/reftests/bugs/84400-2.html
@@ -29,23 +29,16 @@
 
       <div>
 	label:
 	<label>bogus</label> <span>FAIL</span>
 	<label disabled="disabled">bogus</label> <span>FAIL</span>
       </div>      
 
       <div>
-	fieldset:
-	<fieldset class="hideme"><legend>bogus</legend></fieldset> <span>FAIL</span>
-	<fieldset class="hideme" disabled="disabled"><legend>bogus</legend></fieldset> <span>FAIL</span>
-	<fieldset class="hideme"><legend disabled="disabled">bogus</legend></fieldset> <span>FAIL</span>
-      </div>
-
-      <div>
 	legend:
 	<fieldset><legend>FAIL</legend></fieldset>
 	<fieldset><legend disabled="disabled">FAIL</legend></fieldset>
 	<fieldset disabled="disabled"><legend>FAIL</legend></fieldset>
       </div>
 
       <div>
 	div (inside form):
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-disabled/fieldset/fieldset-disabled.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+  <link rel='stylesheet' type='text/css' href='style.css'>
+  <body>
+    <fieldset class="disabled" disabled></fieldset>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-disabled/fieldset/fieldset-enabled.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+  <link rel='stylesheet' type='text/css' href='style.css'>
+  <body>
+    <fieldset class="enabled"></fieldset>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-disabled/fieldset/fieldset-ref.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+  <link rel='stylesheet' type='text/css' href='style.css'>
+  <body>
+    <fieldset class='ref'></fieldset>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-disabled/fieldset/reftest.list
@@ -0,0 +1,2 @@
+== fieldset-enabled.html fieldset-ref.html
+== fieldset-disabled.html fieldset-ref.html
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-disabled/fieldset/style.css
@@ -0,0 +1,16 @@
+fieldset.disabled {
+  background-color: red;
+}
+
+fieldset:disabled.disabled,
+fieldset.ref {
+  background-color: green;
+}
+
+fieldset.enabled {
+  background-color: green;
+}
+
+fieldset:disabled.enabled {
+  background-color: red;
+}
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-disabled/reftest.list
@@ -0,0 +1,1 @@
+include fieldset/reftest.list
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-enabled/fieldset/fieldset-disabled.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+  <link rel='stylesheet' type='text/css' href='style.css'>
+  <body>
+    <fieldset class="disabled" disabled></fieldset>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-enabled/fieldset/fieldset-enabled.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+  <link rel='stylesheet' type='text/css' href='style.css'>
+  <body>
+    <fieldset class="enabled"></fieldset>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-enabled/fieldset/fieldset-ref.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+  <link rel='stylesheet' type='text/css' href='style.css'>
+  <body>
+    <fieldset class='ref'></fieldset>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-enabled/fieldset/reftest.list
@@ -0,0 +1,2 @@
+== fieldset-enabled.html fieldset-ref.html
+== fieldset-disabled.html fieldset-ref.html
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-enabled/fieldset/style.css
@@ -0,0 +1,16 @@
+fieldset.enabled {
+  background-color: red;
+}
+
+fieldset:enabled.enabled,
+fieldset.ref {
+  background-color: green;
+}
+
+fieldset.disabled {
+  background-color: green;
+}
+
+fieldset:enabled.disabled {
+  background-color: red;
+}
new file mode 100644
--- /dev/null
+++ b/layout/reftests/css-enabled/reftest.list
@@ -0,0 +1,1 @@
+include fieldset/reftest.list
--- a/layout/reftests/reftest.list
+++ b/layout/reftests/reftest.list
@@ -45,16 +45,22 @@ include canvas/reftest.list
 include css-calc/reftest.list
 
 # css character encoding tests
 include css-charset/reftest.list
 
 # css default pseudo class tests
 include css-default/reftest.list
 
+# css :disable tests
+include css-disabled/reftest.list
+
+# css :enable tests
+include css-enabled/reftest.list
+
 # css @import tests
 include css-import/reftest.list
 
 # css gradients
 include css-gradients/reftest.list
 
 # css media queries (tests for print mode)
 include css-mediaqueries/reftest.list