Bug 660238 (1/3) - Add const getters to nsHTMLMeterElement. f=mounir r=smaug
authorLaurent Dulary <dularylaurent@gmail.com>
Wed, 16 May 2012 13:21:53 +0200
changeset 95943 ca2a01618e4377fafc4db1b3f536780af7fb2233
parent 95942 30a518ac406f61200ed4468202947ebf940dd2e4
child 95944 3ffbdbac1f7f72aeadf57e6809e2cfea00213938
push id22860
push usermlamouri@mozilla.com
push dateWed, 06 Jun 2012 13:16:50 +0000
treeherdermozilla-central@3df1de4c9592 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs660238
milestone16.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 660238 (1/3) - Add const getters to nsHTMLMeterElement. f=mounir r=smaug
content/html/content/src/nsHTMLMeterElement.cpp
--- a/content/html/content/src/nsHTMLMeterElement.cpp
+++ b/content/html/content/src/nsHTMLMeterElement.cpp
@@ -76,21 +76,39 @@ public:
 
   bool ParseAttribute(PRInt32 aNamespaceID, nsIAtom* aAttribute,
                       const nsAString& aValue, nsAttrValue& aResult);
 
   virtual nsXPCClassInfo* GetClassInfo();
 
   virtual nsIDOMNode* AsDOMNode() { return this; }
 
-protected:
+private:
 
   static const double kDefaultValue;
   static const double kDefaultMin;
   static const double kDefaultMax;
+
+  /* @return the minimum value */
+  double GetMin() const;
+
+  /* @return the maximum value */
+  double GetMax() const;
+
+  /* @return the actual value */
+  double GetValue() const;
+
+  /* @return the low value */
+  double GetLow() const;
+
+  /* @return the high value */
+  double GetHigh() const;
+
+  /* @return the optimum value */
+  double GetOptimum() const;
 };
 
 const double nsHTMLMeterElement::kDefaultValue =  0.0;
 const double nsHTMLMeterElement::kDefaultMin   =  0.0;
 const double nsHTMLMeterElement::kDefaultMax   =  1.0;
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Meter)
 
@@ -150,229 +168,247 @@ nsHTMLMeterElement::ParseAttribute(PRInt
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::GetForm(nsIDOMHTMLFormElement** aForm)
 {
   return nsGenericHTMLFormElement::GetForm(aForm);
 }
 
-NS_IMETHODIMP
-nsHTMLMeterElement::GetMin(double* aValue)
+/*
+ * Value getters :
+ * const getters used by XPCOM methods and by IntrinsicState
+ */
+
+double
+nsHTMLMeterElement::GetMin() const
 {
   /**
    * If the attribute min is defined, the minimum is this value.
    * Otherwise, the minimum is the default value.
    */
   const nsAttrValue* attrMin = mAttrsAndChildren.GetAttr(nsGkAtoms::min);
   if (attrMin && attrMin->Type() == nsAttrValue::eDoubleValue) {
-    *aValue = attrMin->GetDoubleValue();
-    return NS_OK;
+    return attrMin->GetDoubleValue();
+  }
+  return kDefaultMin;
+}
+
+double
+nsHTMLMeterElement::GetMax() const
+{
+  /**
+   * If the attribute max is defined, the maximum is this value.
+   * Otherwise, the maximum is the default value.
+   * If the maximum value is less than the minimum value,
+   * the maximum value is the same as the minimum value.
+   */
+  double max;
+
+  const nsAttrValue* attrMax = mAttrsAndChildren.GetAttr(nsGkAtoms::max);
+  if (attrMax && attrMax->Type() == nsAttrValue::eDoubleValue) {
+    max = attrMax->GetDoubleValue();
+  } else {
+    max = kDefaultMax;
+  }
+
+  return NS_MAX(max, GetMin());
+}
+
+double
+nsHTMLMeterElement::GetValue() const
+{
+  /**
+   * If the attribute value is defined, the actual value is this value.
+   * Otherwise, the actual value is the default value.
+   * If the actual value is less than the minimum value,
+   * the actual value is the same as the minimum value.
+   * If the actual value is greater than the maximum value,
+   * the actual value is the same as the maximum value.
+   */
+  double value;
+
+  const nsAttrValue* attrValue = mAttrsAndChildren.GetAttr(nsGkAtoms::value);
+  if (attrValue && attrValue->Type() == nsAttrValue::eDoubleValue) {
+    value = attrValue->GetDoubleValue();
+  } else {
+    value = kDefaultValue;
+  }
+
+  double min = GetMin();
+
+  if (value <= min) {
+    return min;
+  }
+
+  return NS_MIN(value, GetMax());
+}
+
+double
+nsHTMLMeterElement::GetLow() const
+{
+  /**
+   * If the low value is defined, the low value is this value.
+   * Otherwise, the low value is the minimum value.
+   * If the low value is less than the minimum value,
+   * the low value is the same as the minimum value.
+   * If the low value is greater than the maximum value,
+   * the low value is the same as the maximum value.
+   */
+
+  double min = GetMin();
+
+  const nsAttrValue* attrLow = mAttrsAndChildren.GetAttr(nsGkAtoms::low);
+  if (!attrLow || attrLow->Type() != nsAttrValue::eDoubleValue) {
+    return min;
   }
 
-  *aValue = kDefaultMin;
+  double low = attrLow->GetDoubleValue();
+
+  if (low <= min) {
+    return min;
+  }
+
+  return NS_MIN(low, GetMax());
+}
+
+double
+nsHTMLMeterElement::GetHigh() const
+{
+  /**
+   * If the high value is defined, the high value is this value.
+   * Otherwise, the high value is the maximum value.
+   * If the high value is less than the low value,
+   * the high value is the same as the low value.
+   * If the high value is greater than the maximum value,
+   * the high value is the same as the maximum value.
+   */
+
+  double max = GetMax();
+
+  const nsAttrValue* attrHigh = mAttrsAndChildren.GetAttr(nsGkAtoms::high);
+  if (!attrHigh || attrHigh->Type() != nsAttrValue::eDoubleValue) {
+    return max;
+  }
+
+  double high = attrHigh->GetDoubleValue();
+
+  if (high >= max) {
+    return max;
+  }
+
+  return NS_MAX(high, GetLow());
+}
+
+double
+nsHTMLMeterElement::GetOptimum() const
+{
+  /**
+   * If the optimum value is defined, the optimum value is this value.
+   * Otherwise, the optimum value is the midpoint between
+   * the minimum value and the maximum value :
+   * min + (max - min)/2 = (min + max)/2
+   * If the optimum value is less than the minimum value,
+   * the optimum value is the same as the minimum value.
+   * If the optimum value is greater than the maximum value,
+   * the optimum value is the same as the maximum value.
+   */
+
+  double max = GetMax();
+
+  double min = GetMin();
+
+  const nsAttrValue* attrOptimum =
+              mAttrsAndChildren.GetAttr(nsGkAtoms::optimum);
+  if (!attrOptimum || attrOptimum->Type() != nsAttrValue::eDoubleValue) {
+    return (min + max) / 2.0;
+  }
+
+  double optimum = attrOptimum->GetDoubleValue();
+
+  if (optimum <= min) {
+    return min;
+  }
+
+  return NS_MIN(optimum, max);
+}
+
+/*
+ * XPCOM methods
+ */
+
+NS_IMETHODIMP
+nsHTMLMeterElement::GetMin(double* aValue)
+{
+  *aValue = GetMin();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::SetMin(double aValue)
 {
   return SetDoubleAttr(nsGkAtoms::min, aValue);
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::GetMax(double* aValue)
 {
-  /**
-   * If the attribute max is defined, the maximum is this value.
-   * Otherwise, the maximum is the default value.
-   * If the maximum value is less than the minimum value,
-   * the maximum value is the same as the minimum value.
-   */
-  const nsAttrValue* attrMax = mAttrsAndChildren.GetAttr(nsGkAtoms::max);
-  if (attrMax && attrMax->Type() == nsAttrValue::eDoubleValue) {
-    *aValue = attrMax->GetDoubleValue();
-  } else {
-    *aValue = kDefaultMax;
-  }
-
-  double min;
-  GetMin(&min);
-
-  *aValue = NS_MAX(*aValue, min);
-
+  *aValue = GetMax();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::SetMax(double aValue)
 {
   return SetDoubleAttr(nsGkAtoms::max, aValue);
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::GetValue(double* aValue)
 {
-  /**
-   * If the attribute value is defined, the actual value is this value.
-   * Otherwise, the actual value is the default value.
-   * If the actual value is less than the minimum value,
-   * the actual value is the same as the minimum value.
-   * If the actual value is greater than the maximum value,
-   * the actual value is the same as the maximum value.
-   */
-  const nsAttrValue* attrValue = mAttrsAndChildren.GetAttr(nsGkAtoms::value);
-  if (attrValue && attrValue->Type() == nsAttrValue::eDoubleValue) {
-    *aValue = attrValue->GetDoubleValue();
-  } else {
-    *aValue = kDefaultValue;
-  }
-
-  double min;
-  GetMin(&min);
-
-  if (*aValue <= min) {
-    *aValue = min;
-    return NS_OK;
-  }
-
-  double max;
-  GetMax(&max);
-
-  *aValue = NS_MIN(*aValue, max);
-
+  *aValue = GetValue();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::SetValue(double aValue)
 {
   return SetDoubleAttr(nsGkAtoms::value, aValue);
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::GetLow(double* aValue)
 {
-  /**
-   * If the low value is defined, the low value is this value.
-   * Otherwise, the low value is the minimum value.
-   * If the low value is less than the minimum value,
-   * the low value is the same as the minimum value.
-   * If the low value is greater than the maximum value,
-   * the low value is the same as the maximum value.
-   */
-
-  double min;
-  GetMin(&min);
-
-  const nsAttrValue* attrLow = mAttrsAndChildren.GetAttr(nsGkAtoms::low);
-  if (!attrLow || attrLow->Type() != nsAttrValue::eDoubleValue) {
-    *aValue = min;
-    return NS_OK;
-  }
-
-  *aValue = attrLow->GetDoubleValue();
-
-  if (*aValue <= min) {
-    *aValue = min;
-    return NS_OK;
-  }
-
-  double max;
-  GetMax(&max);
-
-  *aValue = NS_MIN(*aValue, max);
-
+  *aValue = GetLow();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::SetLow(double aValue)
 {
   return SetDoubleAttr(nsGkAtoms::low, aValue);
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::GetHigh(double* aValue)
 {
-  /**
-   * If the high value is defined, the high value is this value.
-   * Otherwise, the high value is the maximum value.
-   * If the high value is less than the low value,
-   * the high value is the same as the low value.
-   * If the high value is greater than the maximum value,
-   * the high value is the same as the maximum value.
-   */
-
-  double max;
-  GetMax(&max);
-
-  const nsAttrValue* attrHigh = mAttrsAndChildren.GetAttr(nsGkAtoms::high);
-  if (!attrHigh || attrHigh->Type() != nsAttrValue::eDoubleValue) {
-    *aValue = max;
-    return NS_OK;
-  }
-
-  *aValue = attrHigh->GetDoubleValue();
-
-  if (*aValue >= max) {
-    *aValue = max;
-    return NS_OK;
-  }
-
-  double low;
-  GetLow(&low);
-
-  *aValue = NS_MAX(*aValue, low);
-
+  *aValue = GetHigh();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::SetHigh(double aValue)
 {
   return SetDoubleAttr(nsGkAtoms::high, aValue);
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::GetOptimum(double* aValue)
 {
-  /**
-   * If the optimum value is defined, the optimum value is this value.
-   * Otherwise, the optimum value is the midpoint between
-   * the minimum value and the maximum value :
-   * min + (max - min)/2 = (min + max)/2
-   * If the optimum value is less than the minimum value,
-   * the optimum value is the same as the minimum value.
-   * If the optimum value is greater than the maximum value,
-   * the optimum value is the same as the maximum value.
-   */
-
-  double max;
-  GetMax(&max);
-
-  double min;
-  GetMin(&min);
-
-  const nsAttrValue* attrOptimum =
-              mAttrsAndChildren.GetAttr(nsGkAtoms::optimum);
-  if (!attrOptimum || attrOptimum->Type() != nsAttrValue::eDoubleValue) {
-    *aValue = (min + max) / 2.0;
-    return NS_OK;
-  }
-
-  *aValue = attrOptimum->GetDoubleValue();
-
-  if (*aValue <= min) {
-    *aValue = min;
-    return NS_OK;
-  }
-
-  *aValue = NS_MIN(*aValue, max);
-
+  *aValue = GetOptimum();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHTMLMeterElement::SetOptimum(double aValue)
 {
   return SetDoubleAttr(nsGkAtoms::optimum, aValue);
 }