summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/html/NumberInputType.cpp
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-05-18 13:36:51 +0100
committerSteve Block <steveblock@google.com>2011-05-24 15:38:28 +0100
commit2fc2651226baac27029e38c9d6ef883fa32084db (patch)
treee396d4bf89dcce6ed02071be66212495b1df1dec /Source/WebCore/html/NumberInputType.cpp
parentb3725cedeb43722b3b175aaeff70552e562d2c94 (diff)
downloadexternal_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.zip
external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.tar.gz
external_webkit-2fc2651226baac27029e38c9d6ef883fa32084db.tar.bz2
Merge WebKit at r78450: Initial merge by git.
Change-Id: I6d3e5f1f868ec266a0aafdef66182ddc3f265dc1
Diffstat (limited to 'Source/WebCore/html/NumberInputType.cpp')
-rw-r--r--Source/WebCore/html/NumberInputType.cpp39
1 files changed, 30 insertions, 9 deletions
diff --git a/Source/WebCore/html/NumberInputType.cpp b/Source/WebCore/html/NumberInputType.cpp
index 3916527..0011115 100644
--- a/Source/WebCore/html/NumberInputType.cpp
+++ b/Source/WebCore/html/NumberInputType.cpp
@@ -38,6 +38,7 @@
#include "HTMLNames.h"
#include "HTMLParserIdioms.h"
#include "KeyboardEvent.h"
+#include "LocalizedNumber.h"
#include "RenderTextControl.h"
#include <limits>
#include <wtf/ASCIICType.h>
@@ -49,17 +50,21 @@ namespace WebCore {
using namespace HTMLNames;
using namespace std;
-static const double numberDefaultMinimum = -FLT_MAX;
-static const double numberDefaultMaximum = FLT_MAX;
-
static const double numberDefaultStep = 1.0;
static const double numberStepScaleFactor = 1.0;
-static bool isNumberCharacter(UChar ch)
+// Returns true if the specified character can be a part of 'valid floating
+// point number' of HTML5.
+static bool isHTMLNumberCharacter(UChar ch)
{
return ch == '+' || ch == '-' || ch == '.' || ch == 'e' || ch == 'E' || isASCIIDigit(ch);
}
+static bool isNumberCharacter(UChar ch)
+{
+ return isLocalizedNumberCharacter(ch) || isHTMLNumberCharacter(ch);
+}
+
PassOwnPtr<InputType> NumberInputType::create(HTMLInputElement* element)
{
return adoptPtr(new NumberInputType(element));
@@ -77,11 +82,11 @@ double NumberInputType::valueAsNumber() const
void NumberInputType::setValueAsNumber(double newValue, ExceptionCode& ec) const
{
- if (newValue < numberDefaultMinimum) {
+ if (newValue < -numeric_limits<float>::max()) {
ec = INVALID_STATE_ERR;
return;
}
- if (newValue > numberDefaultMaximum) {
+ if (newValue > numeric_limits<float>::max()) {
ec = INVALID_STATE_ERR;
return;
}
@@ -120,12 +125,12 @@ bool NumberInputType::supportsRangeLimitation() const
double NumberInputType::minimum() const
{
- return parseToDouble(element()->fastGetAttribute(minAttr), numberDefaultMinimum);
+ return parseToDouble(element()->fastGetAttribute(minAttr), -numeric_limits<float>::max());
}
double NumberInputType::maximum() const
{
- return parseToDouble(element()->fastGetAttribute(maxAttr), numberDefaultMaximum);
+ return parseToDouble(element()->fastGetAttribute(maxAttr), numeric_limits<float>::max());
}
bool NumberInputType::stepMismatch(const String& value, double step) const
@@ -248,13 +253,29 @@ void NumberInputType::handleBlurEvent()
element()->renderer()->updateFromElement();
}
+String NumberInputType::visibleValue() const
+{
+ String currentValue = element()->value();
+ if (currentValue.isEmpty())
+ return currentValue;
+ double doubleValue = numeric_limits<double>::quiet_NaN();
+ parseToDoubleForNumberType(currentValue, &doubleValue);
+ String localized = formatLocalizedNumber(doubleValue);
+ return localized.isEmpty() ? currentValue : localized;
+}
+
bool NumberInputType::isAcceptableValue(const String& proposedValue)
{
- return proposedValue.isEmpty() || parseToDoubleForNumberType(proposedValue, 0);
+ return proposedValue.isEmpty() || isfinite(parseLocalizedNumber(proposedValue)) || parseToDoubleForNumberType(proposedValue, 0);
}
String NumberInputType::sanitizeValue(const String& proposedValue)
{
+ // Try to parse the value as a localized number, then try to parse it as
+ // the standard format.
+ double parsedValue = parseLocalizedNumber(proposedValue);
+ if (isfinite(parsedValue))
+ return serializeForNumberType(parsedValue);
return parseToDoubleForNumberType(proposedValue, 0) ? proposedValue : String();
}