+static const int defaultTrackLength = 129;
+
+// FIXME: The SliderRange class and functions are entirely based on the DOM,
+// and could be put with HTMLInputElement (possibly with a new name) instead of here.
+struct SliderRange {
+ bool isIntegral;
+ double minimum;
+ double maximum;
+
+ explicit SliderRange(HTMLInputElement*);
+ double clampValue(double value);
+ double valueFromElement(HTMLInputElement*, bool* wasClamped = 0);
+};
+
+SliderRange::SliderRange(HTMLInputElement* element)
+{
+ // FIXME: What's the right way to handle an integral range with non-integral minimum and maximum?
+ // Currently values are guaranteed to be integral but could be outside the range in that case.
+
+ isIntegral = !equalIgnoringCase(element->getAttribute(precisionAttr), "float");
+
+ // FIXME: This treats maximum strings that can't be parsed as 0, but perhaps 100 would be more appropriate.
+ const AtomicString& maxString = element->getAttribute(maxAttr);
+ maximum = maxString.isNull() ? 100.0 : maxString.toDouble();
+
+ // If the maximum is smaller, use it as the minimum.
+ minimum = min(element->getAttribute(minAttr).toDouble(), maximum);
+}
+
+double SliderRange::clampValue(double value)
+{
+ double clampedValue = max(minimum, min(value, maximum));
+ return isIntegral ? round(clampedValue) : clampedValue;
+}