Bug 612730 (2/3) - :-moz-ui-invalid and :-moz-ui-valid apply for <select> if the user tried to submit the form in an invalid state. r=bz a=jst
authorMounir Lamouri <mounir.lamouri@gmail.com>
Wed, 24 Nov 2010 11:09:17 +0100
changeset 58157 8fd7b019a2e6e78a53f17ac2143a8707c8fef4a2
parent 58156 e077f4fddd25c02be9cc08fc6222cf0f1b6cbcd7
child 58158 f4a67c552e73c72659d76baaac730e8ae071d856
push id17175
push usermlamouri@mozilla.com
push dateWed, 24 Nov 2010 10:15:50 +0000
treeherdermozilla-central@7f5cd850578e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, jst
bugs612730
milestone2.0b8pre
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 612730 (2/3) - :-moz-ui-invalid and :-moz-ui-valid apply for <select> if the user tried to submit the form in an invalid state. r=bz a=jst
content/html/content/src/nsHTMLSelectElement.cpp
content/html/content/test/test_bug605124-1.html
content/html/content/test/test_bug605125-1.html
--- a/content/html/content/src/nsHTMLSelectElement.cpp
+++ b/content/html/content/src/nsHTMLSelectElement.cpp
@@ -67,16 +67,17 @@
 #include "nsIFrame.h"
 
 #include "nsDOMError.h"
 #include "nsServiceManagerUtils.h"
 #include "nsRuleData.h"
 #include "nsEventDispatcher.h"
 #include "mozilla/dom/Element.h"
 #include "mozAutoDocUpdate.h"
+#include "nsHTMLFormElement.h"
 
 using namespace mozilla::dom;
 
 NS_IMPL_ISUPPORTS1(nsSelectState, nsSelectState)
 NS_DEFINE_STATIC_IID_ACCESSOR(nsSelectState, NS_SELECT_STATE_IID)
 
 //----------------------------------------------------------------------
 //
@@ -1568,23 +1569,25 @@ nsEventStates
 nsHTMLSelectElement::IntrinsicState() const
 {
   nsEventStates state = nsGenericHTMLFormElement::IntrinsicState();
 
   if (IsCandidateForConstraintValidation()) {
     if (IsValid()) {
       state |= NS_EVENT_STATE_VALID;
 
-      if (mSelectionHasChanged) {
+      if ((mForm && mForm->HasEverTriedInvalidSubmit()) ||
+          mSelectionHasChanged) {
         state |= NS_EVENT_STATE_MOZ_UI_VALID;
       }
     } else {
       state |= NS_EVENT_STATE_INVALID;
 
-      if (mSelectionHasChanged || GetValidityState(VALIDITY_STATE_CUSTOM_ERROR)) {
+      if ((mForm && mForm->HasEverTriedInvalidSubmit()) ||
+          mSelectionHasChanged || GetValidityState(VALIDITY_STATE_CUSTOM_ERROR)) {
         state |= NS_EVENT_STATE_MOZ_UI_INVALID;
       }
     }
   }
 
   if (HasAttr(kNameSpaceID_None, nsGkAtoms::required)) {
     state |= NS_EVENT_STATE_REQUIRED;
   } else {
--- a/content/html/content/test/test_bug605124-1.html
+++ b/content/html/content/test/test_bug605124-1.html
@@ -11,24 +11,26 @@ https://bugzilla.mozilla.org/show_bug.cg
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=605124">Mozilla Bug 605124</a>
 <p id="display"></p>
 <div id="content">
   <form>
     <textarea required></textarea>
     <input required>
+    <select required></select>
     <button type='submit'></button>
   </form>
 
   <table>
     <form>
     <tr>
       <textarea required></textarea>
       <input required>
+      <select required></select>
       <button type='submit'></button>
     </tr>
     </form>
   </table>
 </div>
 <pre id="test">
 <script type="application/javascript">
 
@@ -44,52 +46,62 @@ netscape.security.PrivilegeManager.enabl
 var os = Components.classes['@mozilla.org/observer-service;1']
                    .getService(Components.interfaces.nsIObserverService);
 var observers = os.enumerateObservers("invalidformsubmit");
 
 if (observers.hasMoreElements()) {
   var content = document.getElementById('content');
   var textarea = document.getElementsByTagName('textarea')[0];
   var input = document.getElementsByTagName('input')[0];
+  var select = document.getElementsByTagName('select')[0];
   var button = document.getElementsByTagName('button')[0];
   var form = document.forms[0];
 
   checkPseudoClass(textarea, false);
   checkPseudoClass(input, false);
+  checkPseudoClass(select, false);
 
   // Try to submit.
   button.click();
   checkPseudoClass(textarea, true);
   checkPseudoClass(input, true);
+  checkPseudoClass(select, true);
 
   // No longer in the form.
   content.appendChild(textarea);
   content.appendChild(input);
+  content.appendChild(select);
   checkPseudoClass(textarea, false);
   checkPseudoClass(input, false);
+  checkPseudoClass(select, false);
 
   // Back in the form.
   form.appendChild(textarea);
   form.appendChild(input);
+  form.appendChild(select);
   checkPseudoClass(textarea, true);
   checkPseudoClass(input, true);
+  checkPseudoClass(select, true);
 
   /* Case when elements get orphaned. */
   var textarea = document.getElementsByTagName('textarea')[1];
   var input = document.getElementsByTagName('input')[1];
+  var select = document.getElementsByTagName('select')[1];
   var button = document.getElementsByTagName('button')[1];
   var form = document.forms[1];
 
   // Try to submit.
   button.click();
   checkPseudoClass(textarea, true);
   checkPseudoClass(input, true);
+  checkPseudoClass(select, true);
 
   // Remove the form.
   document.getElementsByTagName('table')[0].removeChild(form);
   checkPseudoClass(textarea, false);
   checkPseudoClass(input, false);
+  checkPseudoClass(select, false);
 }
 
 </script>
 </pre>
 </body>
 </html>
--- a/content/html/content/test/test_bug605125-1.html
+++ b/content/html/content/test/test_bug605125-1.html
@@ -8,33 +8,35 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="application/javascript" src="/MochiKit/packed.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.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=605125">Mozilla Bug 605125</a>
 <p id="display"></p>
 <div id="content">
-  <form>
+  <form id='f1'>
     <textarea></textarea>
     <input>
     <button type='submit'></button>
     <select></select>
   </form>
 
   <table>
-    <form>
+    <form id='f2'>
     <tr>
       <textarea></textarea>
       <input>
       <button type='submit'></button>
       <select></select>
     </tr>
     </form>
   </table>
+  <input form='f1' required>
+  <input form='f2' required>
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 605125 **/
 
 /**
  * NOTE: this test is very similar to 605124-1.html.
@@ -47,59 +49,65 @@ function checkPseudoClass(aElement, aExp
 }
 
 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 var os = Components.classes['@mozilla.org/observer-service;1']
                    .getService(Components.interfaces.nsIObserverService);
 var observers = os.enumerateObservers("invalidformsubmit");
 
 if (observers.hasMoreElements()) {
-  // Make both <select> invalid so the forms will be invalid.
-  document.getElementsByTagName('select')[0].setCustomValidity("foo");
-  document.getElementsByTagName('select')[1].setCustomValidity("foo");
-
   var content = document.getElementById('content');
   var textarea = document.getElementsByTagName('textarea')[0];
   var input = document.getElementsByTagName('input')[0];
   var button = document.getElementsByTagName('button')[0];
+  var select = document.getElementsByTagName('select')[0];
   var form = document.forms[0];
 
   checkPseudoClass(textarea, false);
   checkPseudoClass(input, false);
+  checkPseudoClass(select, false);
 
   // Try to submit.
   button.click();
   checkPseudoClass(textarea, true);
   checkPseudoClass(input, true);
+  checkPseudoClass(select, true);
 
   // No longer in the form.
   content.appendChild(textarea);
   content.appendChild(input);
+  content.appendChild(select);
   checkPseudoClass(textarea, false);
   checkPseudoClass(input, false);
+  checkPseudoClass(select, false);
 
   // Back in the form.
   form.appendChild(textarea);
   form.appendChild(input);
+  form.appendChild(select);
   checkPseudoClass(textarea, true);
   checkPseudoClass(input, true);
+  checkPseudoClass(select, true);
 
   /* Case when elements get orphaned. */
   var textarea = document.getElementsByTagName('textarea')[1];
   var input = document.getElementsByTagName('input')[1];
   var button = document.getElementsByTagName('button')[1];
+  var select = document.getElementsByTagName('select')[1];
   var form = document.forms[1];
 
   // Try to submit.
   button.click();
   checkPseudoClass(textarea, true);
   checkPseudoClass(input, true);
+  checkPseudoClass(select, true);
 
   // Remove the form.
   document.getElementsByTagName('table')[0].removeChild(form);
   checkPseudoClass(textarea, false);
   checkPseudoClass(input, false);
+  checkPseudoClass(select, false);
 }
 
 </script>
 </pre>
 </body>
 </html>