Decimal InputType::findStepBase(const Decimal& defaultValue) const { Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr), Decimal::nan()); if (!stepBase.isFinite()) stepBase = parseToNumber(element().fastGetAttribute(valueAttr), defaultValue); return stepBase; }
StepRange InputType::createStepRange(AnyStepHandling anyStepHandling, const Decimal& stepBaseDefault, const Decimal& minimumDefault, const Decimal& maximumDefault, const StepRange::StepDescription& stepDescription) const { const Decimal stepBase = findStepBase(stepBaseDefault); const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), minimumDefault); const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), maximumDefault); const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr)); return StepRange(stepBase, minimum, maximum, step, stepDescription); }
StepRange DateTimeLocalInputType::createStepRange(AnyStepHandling anyStepHandling) const { DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (dateTimeLocalDefaultStep, dateTimeLocalDefaultStepBase, dateTimeLocalStepScaleFactor, StepRange::ScaledStepValueShouldBeInteger)); const Decimal stepBase = parseToNumber(element()->fastGetAttribute(minAttr), 0); const Decimal minimum = parseToNumber(element()->fastGetAttribute(minAttr), Decimal::fromDouble(DateComponents::minimumDateTime())); const Decimal maximum = parseToNumber(element()->fastGetAttribute(maxAttr), Decimal::fromDouble(DateComponents::maximumDateTime())); const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element()->fastGetAttribute(stepAttr)); return StepRange(stepBase, minimum, maximum, step, stepDescription); }
StepRange WeekInputType::createStepRange(AnyStepHandling anyStepHandling) const { DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (weekDefaultStep, weekDefaultStepBase, weekStepScaleFactor, StepRange::ParsedStepValueShouldBeInteger)); const Decimal stepBase = findStepBase(weekDefaultStepBase); const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), Decimal::fromDouble(DateComponents::minimumWeek())); const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), Decimal::fromDouble(DateComponents::maximumWeek())); const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr)); return StepRange(stepBase, minimum, maximum, step, stepDescription); }
StepRange NumberInputType::createStepRange(AnyStepHandling anyStepHandling) const { DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (numberDefaultStep, numberDefaultStepBase, numberStepScaleFactor)); const Decimal stepBase = parseToDecimalForNumberType(element()->fastGetAttribute(minAttr), numberDefaultStepBase); // FIXME: We should use numeric_limits<double>::max for number input type. const Decimal floatMax = Decimal::fromDouble(numeric_limits<float>::max()); const Decimal minimum = parseToNumber(element()->fastGetAttribute(minAttr), -floatMax); const Decimal maximum = parseToNumber(element()->fastGetAttribute(maxAttr), floatMax); const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element()->fastGetAttribute(stepAttr)); return StepRange(stepBase, minimum, maximum, step, stepDescription); }
StepRange NumberInputType::createStepRange(AnyStepHandling anyStepHandling) const { DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (numberDefaultStep, numberDefaultStepBase, numberStepScaleFactor)); unsigned stepBaseDecimalPlaces; double stepBaseValue = parseToNumberWithDecimalPlaces(element()->fastGetAttribute(minAttr), numberDefaultStepBase, &stepBaseDecimalPlaces); StepRange::NumberWithDecimalPlaces stepBase(stepBaseValue, min(stepBaseDecimalPlaces, 16u)); double minimum = parseToNumber(element()->fastGetAttribute(minAttr), -numeric_limits<float>::max()); double maximum = parseToNumber(element()->fastGetAttribute(maxAttr), numeric_limits<float>::max()); StepRange::NumberWithDecimalPlacesOrMissing step = StepRange::parseStep(anyStepHandling, stepDescription, element()->fastGetAttribute(stepAttr)); return StepRange(stepBase, minimum, maximum, step, stepDescription); }
StepRange RangeInputType::createStepRange(AnyStepHandling anyStepHandling) const { DEPRECATED_DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (rangeDefaultStep, rangeDefaultStepBase, rangeStepScaleFactor)); const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), rangeDefaultMinimum); const Decimal maximum = ensureMaximum(parseToNumber(element().fastGetAttribute(maxAttr), rangeDefaultMaximum), minimum, rangeDefaultMaximum); const AtomicString& precisionValue = element().fastGetAttribute(precisionAttr); if (!precisionValue.isNull()) { const Decimal step = equalIgnoringCase(precisionValue, "float") ? Decimal::nan() : 1; return StepRange(minimum, minimum, maximum, step, stepDescription); } const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr)); return StepRange(minimum, minimum, maximum, step, stepDescription); }
void InputType::stepUp(int n, ExceptionState& exceptionState) { if (!isSteppable()) { exceptionState.throwDOMException(InvalidStateError, "This form element is not steppable."); return; } const Decimal current = parseToNumber(element().value(), 0); applyStep(current, n, RejectAny, DispatchNoEvent, exceptionState); }
StepRange RangeInputType::createStepRange( AnyStepHandling anyStepHandling) const { DEFINE_STATIC_LOCAL( const StepRange::StepDescription, stepDescription, (rangeDefaultStep, rangeDefaultStepBase, rangeStepScaleFactor)); const Decimal stepBase = findStepBase(rangeDefaultStepBase); const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), rangeDefaultMinimum); const Decimal maximum = ensureMaximum( parseToNumber(element().fastGetAttribute(maxAttr), rangeDefaultMaximum), minimum, rangeDefaultMaximum); const Decimal step = StepRange::parseStep( anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr)); // Range type always has range limitations because it has default // minimum/maximum. // https://html.spec.whatwg.org/multipage/forms.html#range-state-(type=range):concept-input-min-default const bool hasRangeLimitations = true; return StepRange(stepBase, minimum, maximum, hasRangeLimitations, step, stepDescription); }
void RangeInputType::updateTickMarkValues() { if (!m_tickMarkValuesDirty) return; m_tickMarkValues.clear(); m_tickMarkValuesDirty = false; HTMLDataListElement* dataList = element().dataList(); if (!dataList) return; HTMLDataListOptionsCollection* options = dataList->options(); m_tickMarkValues.reserveCapacity(options->length()); for (unsigned i = 0; i < options->length(); ++i) { HTMLOptionElement* optionElement = options->item(i); String optionValue = optionElement->value(); if (!this->element().isValidValue(optionValue)) continue; m_tickMarkValues.append(parseToNumber(optionValue, Decimal::nan())); } m_tickMarkValues.shrinkToFit(); nonCopyingSort(m_tickMarkValues.begin(), m_tickMarkValues.end(), decimalCompare); }
void RangeInputType::updateTickMarkValues() { if (!m_tickMarkValuesDirty) return; m_tickMarkValues.clear(); m_tickMarkValuesDirty = false; HTMLDataListElement* dataList = element().dataList(); if (!dataList) return; Ref<HTMLCollection> options = dataList->options(); m_tickMarkValues.reserveCapacity(options->length()); for (unsigned i = 0; i < options->length(); ++i) { Node* node = options->item(i); HTMLOptionElement& optionElement = downcast<HTMLOptionElement>(*node); String optionValue = optionElement.value(); if (!element().isValidValue(optionValue)) continue; m_tickMarkValues.append(parseToNumber(optionValue, Decimal::nan())); } m_tickMarkValues.shrinkToFit(); std::sort(m_tickMarkValues.begin(), m_tickMarkValues.end()); }
Decimal InputType::parseToNumberOrNaN(const String& string) const { return parseToNumber(string, Decimal::nan()); }
String RangeInputType::sanitizeValue(const String& proposedValue) const { StepRange stepRange(createStepRange(RejectAny)); const Decimal proposedNumericValue = parseToNumber(proposedValue, stepRange.defaultValue()); return serializeForNumberType(stepRange.clampValue(proposedNumericValue)); }
double NumberInputType::valueAsNumber() const { return parseToNumber(element()->value(), numeric_limits<double>::quiet_NaN()); }