diff options
Diffstat (limited to 'WebCore/html/NumberInputType.cpp')
-rw-r--r-- | WebCore/html/NumberInputType.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/WebCore/html/NumberInputType.cpp b/WebCore/html/NumberInputType.cpp index 28f510c..e290e50 100644 --- a/WebCore/html/NumberInputType.cpp +++ b/WebCore/html/NumberInputType.cpp @@ -131,8 +131,8 @@ bool NumberInputType::stepMismatch(const String& value, double step) const double remainder = fabs(doubleValue - step * round(doubleValue / step)); // Accepts erros in lower fractional part which IEEE 754 single-precision // can't represent. - double acceptableError = step / pow(2.0, FLT_MANT_DIG); - return acceptableError < remainder && remainder < (step - acceptableError); + double computedAcceptableError = acceptableError(step); + return computedAcceptableError < remainder && remainder < (step - computedAcceptableError); } double NumberInputType::stepBase() const @@ -140,6 +140,11 @@ double NumberInputType::stepBase() const return parseToDouble(element()->fastGetAttribute(minAttr), defaultStepBase()); } +double NumberInputType::stepBaseWithDecimalPlaces(unsigned* decimalPlaces) const +{ + return parseToDoubleWithDecimalPlaces(element()->fastGetAttribute(minAttr), defaultStepBase(), decimalPlaces); +} + double NumberInputType::defaultStep() const { return numberDefaultStep; @@ -150,6 +155,11 @@ double NumberInputType::stepScaleFactor() const return numberStepScaleFactor; } +bool NumberInputType::handleKeydownEvent(KeyboardEvent* event) +{ + return handleKeydownEventForSpinButton(event) || TextFieldInputType::handleKeydownEventForSpinButton(event); +} + double NumberInputType::parseToDouble(const String& src, double defaultValue) const { double numberValue; @@ -159,6 +169,15 @@ double NumberInputType::parseToDouble(const String& src, double defaultValue) co return numberValue; } +double NumberInputType::parseToDoubleWithDecimalPlaces(const String& src, double defaultValue, unsigned *decimalPlaces) const +{ + double numberValue; + if (!parseToDoubleForNumberTypeWithDecimalPlaces(src, &numberValue, decimalPlaces)) + return defaultValue; + ASSERT(isfinite(numberValue)); + return numberValue; +} + String NumberInputType::serialize(double value) const { if (!isfinite(value)) @@ -166,4 +185,10 @@ String NumberInputType::serialize(double value) const return serializeForNumberType(value); } +double NumberInputType::acceptableError(double step) const +{ + return step / pow(2.0, FLT_MANT_DIG); +} + + } // namespace WebCore |