Bug 633913 - Add a pseudo-class to access indeterminate <progress> elements. r=bz
authorMounir Lamouri <mounir.lamouri@gmail.com>
Wed, 04 May 2011 16:53:17 +0200
changeset 69387 89d4c7fd4d0d30d65f48acfee1e2f8e52a3c8970
parent 69386 2139b047dbb7f2820da0b5eacc31220aaa245688
child 69388 78ea30b54e01663116cc7a6df5816df0af66a10d
push id76
push userbzbarsky@mozilla.com
push dateTue, 05 Jul 2011 17:00:57 +0000
treeherdermozilla-beta@d3a2732c35f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs633913
milestone6.0a1
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 633913 - Add a pseudo-class to access indeterminate <progress> elements. r=bz
content/html/content/src/nsHTMLProgressElement.cpp
content/html/content/test/test_bug514437.html
--- a/content/html/content/src/nsHTMLProgressElement.cpp
+++ b/content/html/content/src/nsHTMLProgressElement.cpp
@@ -33,16 +33,17 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsIDOMHTMLProgressElement.h"
 #include "nsGenericHTMLElement.h"
 #include "nsAttrValue.h"
+#include "nsEventStateManager.h"
 
 
 class nsHTMLProgressElement : public nsGenericHTMLFormElement,
                               public nsIDOMHTMLProgressElement
 {
 public:
   nsHTMLProgressElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsHTMLProgressElement();
@@ -62,16 +63,18 @@ public:
   // nsIDOMHTMLProgressElement
   NS_DECL_NSIDOMHTMLPROGRESSELEMENT
 
   // nsIFormControl
   NS_IMETHOD_(PRUint32) GetType() const { return NS_FORM_PROGRESS; }
   NS_IMETHOD Reset();
   NS_IMETHOD SubmitNamesValues(nsFormSubmission* aFormSubmission);
 
+  nsEventStates IntrinsicState() const;
+
   nsresult Clone(nsINodeInfo* aNodeInfo, nsINode** aResult) const;
 
   PRBool ParseAttribute(PRInt32 aNamespaceID, nsIAtom* aAttribute,
                         const nsAString& aValue, nsAttrValue& aResult);
 
   virtual nsXPCClassInfo* GetClassInfo();
 
 protected:
@@ -129,16 +132,28 @@ nsHTMLProgressElement::Reset()
 
 NS_IMETHODIMP
 nsHTMLProgressElement::SubmitNamesValues(nsFormSubmission* aFormSubmission)
 {
   // The progress element is not submittable.
   return NS_OK;
 }
 
+nsEventStates
+nsHTMLProgressElement::IntrinsicState() const
+{
+  nsEventStates state = nsGenericHTMLFormElement::IntrinsicState();
+
+  if (IsIndeterminate()) {
+    state |= NS_EVENT_STATE_INDETERMINATE;
+  }
+
+  return state;
+}
+
 PRBool
 nsHTMLProgressElement::ParseAttribute(PRInt32 aNamespaceID, nsIAtom* aAttribute,
                                       const nsAString& aValue, nsAttrValue& aResult)
 {
   if (aNamespaceID == kNameSpaceID_None) {
     if (aAttribute == nsGkAtoms::value || aAttribute == nsGkAtoms::max) {
       return aResult.ParseDoubleValue(aValue);
     }
--- a/content/html/content/test/test_bug514437.html
+++ b/content/html/content/test/test_bug514437.html
@@ -1,32 +1,35 @@
 <!DOCTYPE HTML>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=514437
+https://bugzilla.mozilla.org/show_bug.cgi?id=633913
 -->
 <head>
-  <title>Test for Bug 514437</title>
+  <title>Test for Bug 514437 and Bug 633913</title>
   <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=514437">Mozilla Bug 514437</a>
+and
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633913">Mozilla Bug 633913</a>
 <p id="display"></p>
 <iframe name="submit_frame" onload="onFormSubmission();" style="visibility: hidden;"></iframe>
 <div id="content" style="visibility: hidden;">
   <form id='f' method='get' target='submit_frame' action='foo'>
     <progress id='p'></progress>
   </form>
 </div>
 <pre id="test">
 <script type="application/javascript">
 
-/** Test for Bug 514437 **/
+/** Test for Bug 514437 and Bug 633913 **/
 
 function checkFormIDLAttribute(aElement)
 {
   var form = document.forms[0];
   var content = document.getElementById('content');
   is(aElement.form, form, "The form IDL attribute should be the parent form");
 
   content.removeChild(form);
@@ -173,16 +176,57 @@ function checkPositionAttribute()
 
   var element = document.createElement('progress');
 
   for each(var test in tests) {
     checkPositionValue(element, test[0], test[1], test[2], test[3]);
   }
 }
 
+function checkIndeterminatePseudoClass()
+{
+  function checkIndeterminate(aElement, aValue, aMax, aIndeterminate) {
+    if (aValue != null) {
+      aElement.setAttribute('value', aValue);
+    } else {
+      aElement.removeAttribute('value');
+    }
+
+    if (aMax != null) {
+      aElement.setAttribute('max', aMax);
+    } else {
+      aElement.removeAttribute('max');
+    }
+
+    is(aElement.mozMatchesSelector("progress:indeterminate"), aIndeterminate,
+       "<progress> indeterminate state should be " + aIndeterminate);
+  }
+
+  var tests = [
+    // Indeterminate state: (value is undefined, or not a float)
+    // value has to be defined (indeterminate state).
+    [ null, null, true ],
+    [ null,  1.0, true ],
+    [ 'foo', 1.0, true ],
+    // Determined state:
+    [ -1.0,  1.0, false ],
+    [  2.0,  1.0, false ],
+    [ 1.0,  null, false ],
+    [ 1.0, 'foo', false ],
+    [ 1.0,  -1.0, false ],
+    [ 0.0,   1.0, false ],
+  ];
+
+  var element = document.createElement('progress');
+
+  for each(var test in tests) {
+    checkIndeterminate(element, test[0], test[1], test[2]);
+  }
+}
+
 function checkFormListedElement(aElement)
 {
   is(document.forms[0].elements.length, 0, "the form should have no element");
 }
 
 function checkLabelable(aElement)
 {
   var content = document.getElementById('content');
@@ -260,16 +304,18 @@ is(p.constructor, HTMLProgressElement,
 checkFormIDLAttribute(p);
 
 checkValueAttribute();
 
 checkMaxAttribute();
 
 checkPositionAttribute();
 
+checkIndeterminatePseudoClass();
+
 checkFormListedElement(p);
 
 checkLabelable(p);
 
 checkNotResetableAndFormSubmission(p);
 
 </script>
 </pre>