[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
tkent at chromium.org
tkent at chromium.org
Wed Dec 22 14:21:33 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit 47c89857c14be0c7fc46fc91496592b46fb9c601
Author: tkent at chromium.org <tkent at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Oct 7 04:49:32 2010 +0000
2010-10-06 Kent Tamura <tkent at chromium.org>
Reviewed by Dimitri Glazkov.
Refactor HTMLInputElement: Move range/step related functions
https://bugs.webkit.org/show_bug.cgi?id=47251
Move the content of the following functions:
- rangeUnderflow()
- rangeOverflow()
- minimum()
- maximum()
- stepMismatch()
- stepBase()
getStepParameters() was split into InputType::defaultStep() and
stepScaleFactor().
* html/BaseDateAndTimeInputType.cpp:
(WebCore::BaseDateAndTimeInputType::rangeUnderflow):
(WebCore::BaseDateAndTimeInputType::rangeOverflow):
(WebCore::BaseDateAndTimeInputType::stepMismatch):
(WebCore::BaseDateAndTimeInputType::stepBase):
* html/BaseDateAndTimeInputType.h:
* html/DateInputType.cpp:
(WebCore::DateInputType::minimum):
(WebCore::DateInputType::maximum):
(WebCore::DateInputType::defaultStep):
(WebCore::DateInputType::stepScaleFactor):
(WebCore::DateInputType::parsedStepValueShouldBeInteger):
* html/DateInputType.h:
* html/DateTimeInputType.cpp:
(WebCore::DateTimeInputType::minimum):
(WebCore::DateTimeInputType::maximum):
(WebCore::DateTimeInputType::defaultStep):
(WebCore::DateTimeInputType::stepScaleFactor):
(WebCore::DateTimeInputType::scaledStepValeuShouldBeInteger):
* html/DateTimeInputType.h:
* html/DateTimeLocalInputType.cpp:
(WebCore::DateTimeLocalInputType::minimum):
(WebCore::DateTimeLocalInputType::maximum):
(WebCore::DateTimeLocalInputType::defaultStep):
(WebCore::DateTimeLocalInputType::stepScaleFactor):
(WebCore::DateTimeLocalInputType::scaledStepValeuShouldBeInteger):
* html/DateTimeLocalInputType.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::rangeUnderflow):
(WebCore::HTMLInputElement::rangeOverflow):
(WebCore::HTMLInputElement::minimum):
(WebCore::HTMLInputElement::maximum):
(WebCore::HTMLInputElement::stepMismatch):
(WebCore::HTMLInputElement::getAllowedValueStep):
(WebCore::HTMLInputElement::applyStep):
(WebCore::HTMLInputElement::handleKeyEventForRange):
(WebCore::HTMLInputElement::stepUpFromRenderer):
* html/HTMLInputElement.h:
* html/InputType.cpp:
(WebCore::InputType::patternMismatch):
(WebCore::InputType::rangeUnderflow):
(WebCore::InputType::rangeOverflow):
(WebCore::InputType::minimum):
(WebCore::InputType::maximum):
(WebCore::InputType::stepMismatch):
(WebCore::InputType::stepBase):
(WebCore::InputType::defaultStep):
(WebCore::InputType::stepScaleFactor):
(WebCore::InputType::parsedStepValueShouldBeInteger):
(WebCore::InputType::scaledStepValeuShouldBeInteger):
* html/InputType.h:
* html/MonthInputType.cpp:
(WebCore::MonthInputType::minimum):
(WebCore::MonthInputType::maximum):
(WebCore::MonthInputType::defaultStep):
(WebCore::MonthInputType::stepScaleFactor):
(WebCore::MonthInputType::parsedStepValueShouldBeInteger):
* html/MonthInputType.h:
* html/NumberInputType.cpp:
(WebCore::NumberInputType::rangeUnderflow):
(WebCore::NumberInputType::rangeOverflow):
(WebCore::NumberInputType::minimum):
(WebCore::NumberInputType::maximum):
(WebCore::NumberInputType::stepMismatch):
(WebCore::NumberInputType::stepBase):
(WebCore::NumberInputType::defaultStep):
(WebCore::NumberInputType::stepScaleFactor):
* html/NumberInputType.h:
* html/RangeInputType.cpp:
(WebCore::RangeInputType::rangeUnderflow):
(WebCore::RangeInputType::rangeOverflow):
(WebCore::RangeInputType::minimum):
(WebCore::RangeInputType::maximum):
(WebCore::RangeInputType::stepMismatch):
(WebCore::RangeInputType::stepBase):
(WebCore::RangeInputType::defaultStep):
(WebCore::RangeInputType::stepScaleFactor):
* html/RangeInputType.h:
* html/TimeInputType.cpp:
(WebCore::TimeInputType::minimum):
(WebCore::TimeInputType::maximum):
(WebCore::TimeInputType::defaultStep):
(WebCore::TimeInputType::stepScaleFactor):
(WebCore::TimeInputType::scaledStepValeuShouldBeInteger):
* html/TimeInputType.h:
* html/WeekInputType.cpp:
(WebCore::WeekInputType::minimum):
(WebCore::WeekInputType::maximum):
(WebCore::WeekInputType::stepBase):
(WebCore::WeekInputType::defaultStep):
(WebCore::WeekInputType::stepScaleFactor):
(WebCore::WeekInputType::parsedStepValueShouldBeInteger):
* html/WeekInputType.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@69272 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 0595f79..6bffd52 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,115 @@
+2010-10-06 Kent Tamura <tkent at chromium.org>
+
+ Reviewed by Dimitri Glazkov.
+
+ Refactor HTMLInputElement: Move range/step related functions
+ https://bugs.webkit.org/show_bug.cgi?id=47251
+
+ Move the content of the following functions:
+ - rangeUnderflow()
+ - rangeOverflow()
+ - minimum()
+ - maximum()
+ - stepMismatch()
+ - stepBase()
+
+ getStepParameters() was split into InputType::defaultStep() and
+ stepScaleFactor().
+
+ * html/BaseDateAndTimeInputType.cpp:
+ (WebCore::BaseDateAndTimeInputType::rangeUnderflow):
+ (WebCore::BaseDateAndTimeInputType::rangeOverflow):
+ (WebCore::BaseDateAndTimeInputType::stepMismatch):
+ (WebCore::BaseDateAndTimeInputType::stepBase):
+ * html/BaseDateAndTimeInputType.h:
+ * html/DateInputType.cpp:
+ (WebCore::DateInputType::minimum):
+ (WebCore::DateInputType::maximum):
+ (WebCore::DateInputType::defaultStep):
+ (WebCore::DateInputType::stepScaleFactor):
+ (WebCore::DateInputType::parsedStepValueShouldBeInteger):
+ * html/DateInputType.h:
+ * html/DateTimeInputType.cpp:
+ (WebCore::DateTimeInputType::minimum):
+ (WebCore::DateTimeInputType::maximum):
+ (WebCore::DateTimeInputType::defaultStep):
+ (WebCore::DateTimeInputType::stepScaleFactor):
+ (WebCore::DateTimeInputType::scaledStepValeuShouldBeInteger):
+ * html/DateTimeInputType.h:
+ * html/DateTimeLocalInputType.cpp:
+ (WebCore::DateTimeLocalInputType::minimum):
+ (WebCore::DateTimeLocalInputType::maximum):
+ (WebCore::DateTimeLocalInputType::defaultStep):
+ (WebCore::DateTimeLocalInputType::stepScaleFactor):
+ (WebCore::DateTimeLocalInputType::scaledStepValeuShouldBeInteger):
+ * html/DateTimeLocalInputType.h:
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::rangeUnderflow):
+ (WebCore::HTMLInputElement::rangeOverflow):
+ (WebCore::HTMLInputElement::minimum):
+ (WebCore::HTMLInputElement::maximum):
+ (WebCore::HTMLInputElement::stepMismatch):
+ (WebCore::HTMLInputElement::getAllowedValueStep):
+ (WebCore::HTMLInputElement::applyStep):
+ (WebCore::HTMLInputElement::handleKeyEventForRange):
+ (WebCore::HTMLInputElement::stepUpFromRenderer):
+ * html/HTMLInputElement.h:
+ * html/InputType.cpp:
+ (WebCore::InputType::patternMismatch):
+ (WebCore::InputType::rangeUnderflow):
+ (WebCore::InputType::rangeOverflow):
+ (WebCore::InputType::minimum):
+ (WebCore::InputType::maximum):
+ (WebCore::InputType::stepMismatch):
+ (WebCore::InputType::stepBase):
+ (WebCore::InputType::defaultStep):
+ (WebCore::InputType::stepScaleFactor):
+ (WebCore::InputType::parsedStepValueShouldBeInteger):
+ (WebCore::InputType::scaledStepValeuShouldBeInteger):
+ * html/InputType.h:
+ * html/MonthInputType.cpp:
+ (WebCore::MonthInputType::minimum):
+ (WebCore::MonthInputType::maximum):
+ (WebCore::MonthInputType::defaultStep):
+ (WebCore::MonthInputType::stepScaleFactor):
+ (WebCore::MonthInputType::parsedStepValueShouldBeInteger):
+ * html/MonthInputType.h:
+ * html/NumberInputType.cpp:
+ (WebCore::NumberInputType::rangeUnderflow):
+ (WebCore::NumberInputType::rangeOverflow):
+ (WebCore::NumberInputType::minimum):
+ (WebCore::NumberInputType::maximum):
+ (WebCore::NumberInputType::stepMismatch):
+ (WebCore::NumberInputType::stepBase):
+ (WebCore::NumberInputType::defaultStep):
+ (WebCore::NumberInputType::stepScaleFactor):
+ * html/NumberInputType.h:
+ * html/RangeInputType.cpp:
+ (WebCore::RangeInputType::rangeUnderflow):
+ (WebCore::RangeInputType::rangeOverflow):
+ (WebCore::RangeInputType::minimum):
+ (WebCore::RangeInputType::maximum):
+ (WebCore::RangeInputType::stepMismatch):
+ (WebCore::RangeInputType::stepBase):
+ (WebCore::RangeInputType::defaultStep):
+ (WebCore::RangeInputType::stepScaleFactor):
+ * html/RangeInputType.h:
+ * html/TimeInputType.cpp:
+ (WebCore::TimeInputType::minimum):
+ (WebCore::TimeInputType::maximum):
+ (WebCore::TimeInputType::defaultStep):
+ (WebCore::TimeInputType::stepScaleFactor):
+ (WebCore::TimeInputType::scaledStepValeuShouldBeInteger):
+ * html/TimeInputType.h:
+ * html/WeekInputType.cpp:
+ (WebCore::WeekInputType::minimum):
+ (WebCore::WeekInputType::maximum):
+ (WebCore::WeekInputType::stepBase):
+ (WebCore::WeekInputType::defaultStep):
+ (WebCore::WeekInputType::stepScaleFactor):
+ (WebCore::WeekInputType::parsedStepValueShouldBeInteger):
+ * html/WeekInputType.h:
+
2010-10-06 Simon Fraser <simon.fraser at apple.com>
Reviewed by Dan Bernstein, Darin Adler.
diff --git a/WebCore/html/BaseDateAndTimeInputType.cpp b/WebCore/html/BaseDateAndTimeInputType.cpp
index 1c22354..74ae1b9 100644
--- a/WebCore/html/BaseDateAndTimeInputType.cpp
+++ b/WebCore/html/BaseDateAndTimeInputType.cpp
@@ -32,12 +32,49 @@
#include "BaseDateAndTimeInputType.h"
#include "DateComponents.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
+#include <limits>
#include <wtf/MathExtras.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
+using namespace HTMLNames;
+using namespace std;
+
+bool BaseDateAndTimeInputType::rangeUnderflow(const String& value) const
+{
+ const double nan = numeric_limits<double>::quiet_NaN();
+ double doubleValue = parseToDouble(value, nan);
+ return isfinite(doubleValue) && doubleValue < minimum();
+}
+
+bool BaseDateAndTimeInputType::rangeOverflow(const String& value) const
+{
+ const double nan = numeric_limits<double>::quiet_NaN();
+ double doubleValue = parseToDouble(value, nan);
+ return isfinite(doubleValue) && doubleValue > maximum();
+}
+
+bool BaseDateAndTimeInputType::stepMismatch(const String& value, double step) const
+{
+ const double nan = numeric_limits<double>::quiet_NaN();
+ double doubleValue = parseToDouble(value, nan);
+ doubleValue = fabs(doubleValue - stepBase());
+ if (!isfinite(doubleValue))
+ return false;
+ ASSERT(round(doubleValue) == doubleValue);
+ ASSERT(round(step) == step);
+ return fmod(doubleValue, step);
+}
+
+double BaseDateAndTimeInputType::stepBase() const
+{
+ return parseToDouble(element()->fastGetAttribute(minAttr), defaultStepBase);
+}
+
double BaseDateAndTimeInputType::parseToDouble(const String& src, double defaultValue) const
{
DateComponents date;
diff --git a/WebCore/html/BaseDateAndTimeInputType.h b/WebCore/html/BaseDateAndTimeInputType.h
index 336cd83..45b1edf 100644
--- a/WebCore/html/BaseDateAndTimeInputType.h
+++ b/WebCore/html/BaseDateAndTimeInputType.h
@@ -40,11 +40,16 @@ namespace WebCore {
class BaseDateAndTimeInputType : public TextFieldInputType {
protected:
BaseDateAndTimeInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
+ virtual double parseToDouble(const String&, double) const;
virtual bool parseToDateComponents(const String&, DateComponents*) const;
// A helper for parseToDateComponents().
virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const = 0;
+
private:
- virtual double parseToDouble(const String&, double) const;
+ virtual bool rangeUnderflow(const String&) const;
+ virtual bool rangeOverflow(const String&) const;
+ virtual bool stepMismatch(const String&, double) const;
+ virtual double stepBase() const;
};
} // namespace WebCore
diff --git a/WebCore/html/DateInputType.cpp b/WebCore/html/DateInputType.cpp
index 3cb959d..022b2e8 100644
--- a/WebCore/html/DateInputType.cpp
+++ b/WebCore/html/DateInputType.cpp
@@ -32,10 +32,17 @@
#include "DateInputType.h"
#include "DateComponents.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
+using namespace HTMLNames;
+
+static const double dateDefaultStep = 1.0;
+static const double dateStepScaleFactor = 86400000.0;
+
PassOwnPtr<InputType> DateInputType::create(HTMLInputElement* element)
{
return adoptPtr(new DateInputType(element));
@@ -46,6 +53,31 @@ const AtomicString& DateInputType::formControlType() const
return InputTypeNames::date();
}
+double DateInputType::minimum() const
+{
+ return parseToDouble(element()->fastGetAttribute(minAttr), DateComponents::minimumDate());
+}
+
+double DateInputType::maximum() const
+{
+ return parseToDouble(element()->fastGetAttribute(maxAttr), DateComponents::maximumDate());
+}
+
+double DateInputType::defaultStep() const
+{
+ return dateDefaultStep;
+}
+
+double DateInputType::stepScaleFactor() const
+{
+ return dateStepScaleFactor;
+}
+
+bool DateInputType::parsedStepValueShouldBeInteger() const
+{
+ return true;
+}
+
bool DateInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const
{
ASSERT(out);
diff --git a/WebCore/html/DateInputType.h b/WebCore/html/DateInputType.h
index e37682e..58a078f 100644
--- a/WebCore/html/DateInputType.h
+++ b/WebCore/html/DateInputType.h
@@ -42,6 +42,11 @@ public:
private:
DateInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual double minimum() const;
+ virtual double maximum() const;
+ virtual double defaultStep() const;
+ virtual double stepScaleFactor() const;
+ virtual bool parsedStepValueShouldBeInteger() const;
virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
};
diff --git a/WebCore/html/DateTimeInputType.cpp b/WebCore/html/DateTimeInputType.cpp
index 75bf1da..8b19076 100644
--- a/WebCore/html/DateTimeInputType.cpp
+++ b/WebCore/html/DateTimeInputType.cpp
@@ -32,10 +32,17 @@
#include "DateTimeInputType.h"
#include "DateComponents.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
+using namespace HTMLNames;
+
+static const double dateTimeDefaultStep = 60.0;
+static const double dateTimeStepScaleFactor = 1000.0;
+
PassOwnPtr<InputType> DateTimeInputType::create(HTMLInputElement* element)
{
return adoptPtr(new DateTimeInputType(element));
@@ -46,6 +53,31 @@ const AtomicString& DateTimeInputType::formControlType() const
return InputTypeNames::datetime();
}
+double DateTimeInputType::minimum() const
+{
+ return parseToDouble(element()->fastGetAttribute(minAttr), DateComponents::minimumDateTime());
+}
+
+double DateTimeInputType::maximum() const
+{
+ return parseToDouble(element()->fastGetAttribute(maxAttr), DateComponents::maximumDateTime());
+}
+
+double DateTimeInputType::defaultStep() const
+{
+ return dateTimeDefaultStep;
+}
+
+double DateTimeInputType::stepScaleFactor() const
+{
+ return dateTimeStepScaleFactor;
+}
+
+bool DateTimeInputType::scaledStepValeuShouldBeInteger() const
+{
+ return true;
+}
+
bool DateTimeInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const
{
ASSERT(out);
diff --git a/WebCore/html/DateTimeInputType.h b/WebCore/html/DateTimeInputType.h
index 92ebc41..ef71f56 100644
--- a/WebCore/html/DateTimeInputType.h
+++ b/WebCore/html/DateTimeInputType.h
@@ -42,6 +42,11 @@ public:
private:
DateTimeInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual double minimum() const;
+ virtual double maximum() const;
+ virtual double defaultStep() const;
+ virtual double stepScaleFactor() const;
+ virtual bool scaledStepValeuShouldBeInteger() const;
virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
};
diff --git a/WebCore/html/DateTimeLocalInputType.cpp b/WebCore/html/DateTimeLocalInputType.cpp
index 916a386..bf8f840 100644
--- a/WebCore/html/DateTimeLocalInputType.cpp
+++ b/WebCore/html/DateTimeLocalInputType.cpp
@@ -32,10 +32,17 @@
#include "DateTimeLocalInputType.h"
#include "DateComponents.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
+using namespace HTMLNames;
+
+static const double dateTimeLocalDefaultStep = 60.0;
+static const double dateTimeLocalStepScaleFactor = 1000.0;
+
PassOwnPtr<InputType> DateTimeLocalInputType::create(HTMLInputElement* element)
{
return adoptPtr(new DateTimeLocalInputType(element));
@@ -46,6 +53,31 @@ const AtomicString& DateTimeLocalInputType::formControlType() const
return InputTypeNames::datetimelocal();
}
+double DateTimeLocalInputType::minimum() const
+{
+ return parseToDouble(element()->fastGetAttribute(minAttr), DateComponents::minimumDateTime());
+}
+
+double DateTimeLocalInputType::maximum() const
+{
+ return parseToDouble(element()->fastGetAttribute(maxAttr), DateComponents::maximumDateTime());
+}
+
+double DateTimeLocalInputType::defaultStep() const
+{
+ return dateTimeLocalDefaultStep;
+}
+
+double DateTimeLocalInputType::stepScaleFactor() const
+{
+ return dateTimeLocalStepScaleFactor;
+}
+
+bool DateTimeLocalInputType::scaledStepValeuShouldBeInteger() const
+{
+ return true;
+}
+
bool DateTimeLocalInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const
{
ASSERT(out);
diff --git a/WebCore/html/DateTimeLocalInputType.h b/WebCore/html/DateTimeLocalInputType.h
index 3ec841d..40d2e04 100644
--- a/WebCore/html/DateTimeLocalInputType.h
+++ b/WebCore/html/DateTimeLocalInputType.h
@@ -42,6 +42,11 @@ public:
private:
DateTimeLocalInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual double minimum() const;
+ virtual double maximum() const;
+ virtual double defaultStep() const;
+ virtual double stepScaleFactor() const;
+ virtual bool scaledStepValeuShouldBeInteger() const;
virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
};
diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp
index 0524fc8..0d41821 100644
--- a/WebCore/html/HTMLInputElement.cpp
+++ b/WebCore/html/HTMLInputElement.cpp
@@ -82,31 +82,6 @@ using namespace HTMLNames;
const int maxSavedResults = 256;
-// Constant values for getAllowedValueStep().
-static const double dateDefaultStep = 1.0;
-static const double dateStepScaleFactor = 86400000.0;
-static const double dateTimeDefaultStep = 60.0;
-static const double dateTimeStepScaleFactor = 1000.0;
-static const double monthDefaultStep = 1.0;
-static const double monthStepScaleFactor = 1.0;
-static const double numberDefaultStep = 1.0;
-static const double numberStepScaleFactor = 1.0;
-static const double timeDefaultStep = 60.0;
-static const double timeStepScaleFactor = 1000.0;
-static const double weekDefaultStep = 1.0;
-static const double weekStepScaleFactor = 604800000.0;
-
-// Constant values for minimum().
-static const double numberDefaultMinimum = -DBL_MAX;
-static const double rangeDefaultMinimum = 0.0;
-
-// Constant values for maximum().
-static const double numberDefaultMaximum = DBL_MAX;
-static const double rangeDefaultMaximum = 100.0;
-
-static const double defaultStepBase = 0.0;
-static const double weekDefaultStepBase = -259200000.0; // The first day of 1970-W01.
-
static const double msecPerMinute = 60 * 1000;
static const double msecPerSecond = 1000;
@@ -371,199 +346,22 @@ bool HTMLInputElement::tooLong(const String& value, NeedsToCheckDirtyFlag check)
bool HTMLInputElement::rangeUnderflow(const String& value) const
{
- const double nan = numeric_limits<double>::quiet_NaN();
- switch (deprecatedInputType()) {
- case DATE:
- case DATETIME:
- case DATETIMELOCAL:
- case MONTH:
- case NUMBER:
- case TIME:
- case WEEK: {
- double doubleValue = m_inputType->parseToDouble(value, nan);
- return isfinite(doubleValue) && doubleValue < minimum();
- }
- case RANGE: // Guaranteed by sanitization.
- ASSERT(m_inputType->parseToDouble(value, nan) >= minimum());
- case BUTTON:
- case CHECKBOX:
- case COLOR:
- case EMAIL:
- case FILE:
- case HIDDEN:
- case IMAGE:
- case ISINDEX:
- case PASSWORD:
- case RADIO:
- case RESET:
- case SEARCH:
- case SUBMIT:
- case TELEPHONE:
- case TEXT:
- case URL:
- break;
- }
- return false;
+ return m_inputType->rangeUnderflow(value);
}
bool HTMLInputElement::rangeOverflow(const String& value) const
{
- const double nan = numeric_limits<double>::quiet_NaN();
- switch (deprecatedInputType()) {
- case DATE:
- case DATETIME:
- case DATETIMELOCAL:
- case MONTH:
- case NUMBER:
- case TIME:
- case WEEK: {
- double doubleValue = m_inputType->parseToDouble(value, nan);
- return isfinite(doubleValue) && doubleValue > maximum();
- }
- case RANGE: // Guaranteed by sanitization.
- ASSERT(m_inputType->parseToDouble(value, nan) <= maximum());
- case BUTTON:
- case CHECKBOX:
- case COLOR:
- case EMAIL:
- case FILE:
- case HIDDEN:
- case IMAGE:
- case ISINDEX:
- case PASSWORD:
- case RADIO:
- case RESET:
- case SEARCH:
- case SUBMIT:
- case TELEPHONE:
- case TEXT:
- case URL:
- break;
- }
- return false;
+ return m_inputType->rangeOverflow(value);
}
double HTMLInputElement::minimum() const
{
- switch (deprecatedInputType()) {
- case DATE:
- return m_inputType->parseToDouble(getAttribute(minAttr), DateComponents::minimumDate());
- case DATETIME:
- case DATETIMELOCAL:
- return m_inputType->parseToDouble(getAttribute(minAttr), DateComponents::minimumDateTime());
- case MONTH:
- return m_inputType->parseToDouble(getAttribute(minAttr), DateComponents::minimumMonth());
- case NUMBER:
- return m_inputType->parseToDouble(getAttribute(minAttr), numberDefaultMinimum);
- case RANGE:
- return m_inputType->parseToDouble(getAttribute(minAttr), rangeDefaultMinimum);
- case TIME:
- return m_inputType->parseToDouble(getAttribute(minAttr), DateComponents::minimumTime());
- case WEEK:
- return m_inputType->parseToDouble(getAttribute(minAttr), DateComponents::minimumWeek());
- case BUTTON:
- case CHECKBOX:
- case COLOR:
- case EMAIL:
- case FILE:
- case HIDDEN:
- case IMAGE:
- case ISINDEX:
- case PASSWORD:
- case RADIO:
- case RESET:
- case SEARCH:
- case SUBMIT:
- case TELEPHONE:
- case TEXT:
- case URL:
- break;
- }
- ASSERT_NOT_REACHED();
- return 0;
+ return m_inputType->minimum();
}
double HTMLInputElement::maximum() const
{
- switch (deprecatedInputType()) {
- case DATE:
- return m_inputType->parseToDouble(getAttribute(maxAttr), DateComponents::maximumDate());
- case DATETIME:
- case DATETIMELOCAL:
- return m_inputType->parseToDouble(getAttribute(maxAttr), DateComponents::maximumDateTime());
- case MONTH:
- return m_inputType->parseToDouble(getAttribute(maxAttr), DateComponents::maximumMonth());
- case NUMBER:
- return m_inputType->parseToDouble(getAttribute(maxAttr), numberDefaultMaximum);
- case RANGE: {
- double max = m_inputType->parseToDouble(getAttribute(maxAttr), rangeDefaultMaximum);
- // A remedy for the inconsistent min/max values for RANGE.
- // Sets the maximum to the default or the minimum value.
- double min = minimum();
- if (max < min)
- max = std::max(min, rangeDefaultMaximum);
- return max;
- }
- case TIME:
- return m_inputType->parseToDouble(getAttribute(maxAttr), DateComponents::maximumTime());
- case WEEK:
- return m_inputType->parseToDouble(getAttribute(maxAttr), DateComponents::maximumWeek());
- case BUTTON:
- case CHECKBOX:
- case COLOR:
- case EMAIL:
- case FILE:
- case HIDDEN:
- case IMAGE:
- case ISINDEX:
- case PASSWORD:
- case RADIO:
- case RESET:
- case SEARCH:
- case SUBMIT:
- case TELEPHONE:
- case TEXT:
- case URL:
- break;
- }
- ASSERT_NOT_REACHED();
- return 0;
-}
-
-double HTMLInputElement::stepBase() const
-{
- switch (deprecatedInputType()) {
- case RANGE:
- return minimum();
- case DATE:
- case DATETIME:
- case DATETIMELOCAL:
- case MONTH:
- case NUMBER:
- case TIME:
- return m_inputType->parseToDouble(getAttribute(minAttr), defaultStepBase);
- case WEEK:
- return m_inputType->parseToDouble(getAttribute(minAttr), weekDefaultStepBase);
- case BUTTON:
- case CHECKBOX:
- case COLOR:
- case EMAIL:
- case FILE:
- case HIDDEN:
- case IMAGE:
- case ISINDEX:
- case PASSWORD:
- case RADIO:
- case RESET:
- case SEARCH:
- case SUBMIT:
- case TELEPHONE:
- case TEXT:
- case URL:
- break;
- }
- ASSERT_NOT_REACHED();
- return 0.0;
+ return m_inputType->maximum();
}
bool HTMLInputElement::stepMismatch(const String& value) const
@@ -571,126 +369,15 @@ bool HTMLInputElement::stepMismatch(const String& value) const
double step;
if (!getAllowedValueStep(&step))
return false;
- switch (deprecatedInputType()) {
- case RANGE:
- // stepMismatch doesn't occur for RANGE. RenderSlider guarantees the
- // value matches to step on user input, and sanitation takes care
- // of the general case.
- return false;
- case NUMBER: {
- double doubleValue;
- if (!parseToDoubleForNumberType(value, &doubleValue))
- return false;
- doubleValue = fabs(doubleValue - stepBase());
- if (isinf(doubleValue))
- return false;
- // double's fractional part size is DBL_MAN_DIG-bit. If the current
- // value is greater than step*2^DBL_MANT_DIG, the following fmod() makes
- // no sense.
- if (doubleValue / pow(2.0, DBL_MANT_DIG) > step)
- return false;
- double remainder = fmod(doubleValue, step);
- // Accepts errors in lower 7-bit.
- double acceptableError = step / pow(2.0, DBL_MANT_DIG - 7);
- return acceptableError < remainder && remainder < (step - acceptableError);
- }
- case DATE:
- case DATETIME:
- case DATETIMELOCAL:
- case MONTH:
- case TIME:
- case WEEK: {
- const double nan = numeric_limits<double>::quiet_NaN();
- double doubleValue = m_inputType->parseToDouble(value, nan);
- doubleValue = fabs(doubleValue - stepBase());
- if (!isfinite(doubleValue))
- return false;
- ASSERT(round(doubleValue) == doubleValue);
- ASSERT(round(step) == step);
- return fmod(doubleValue, step);
- }
- case BUTTON:
- case CHECKBOX:
- case COLOR:
- case EMAIL:
- case FILE:
- case HIDDEN:
- case IMAGE:
- case ISINDEX:
- case PASSWORD:
- case RADIO:
- case RESET:
- case SEARCH:
- case SUBMIT:
- case TELEPHONE:
- case TEXT:
- case URL:
- break;
- }
- // Non-supported types should be rejected by getAllowedValueStep().
- ASSERT_NOT_REACHED();
- return false;
-}
-
-bool HTMLInputElement::getStepParameters(double* defaultStep, double* stepScaleFactor) const
-{
- ASSERT(defaultStep);
- ASSERT(stepScaleFactor);
- switch (deprecatedInputType()) {
- case NUMBER:
- case RANGE:
- *defaultStep = numberDefaultStep;
- *stepScaleFactor = numberStepScaleFactor;
- return true;
- case DATE:
- *defaultStep = dateDefaultStep;
- *stepScaleFactor = dateStepScaleFactor;
- return true;
- case DATETIME:
- case DATETIMELOCAL:
- *defaultStep = dateTimeDefaultStep;
- *stepScaleFactor = dateTimeStepScaleFactor;
- return true;
- case MONTH:
- *defaultStep = monthDefaultStep;
- *stepScaleFactor = monthStepScaleFactor;
- return true;
- case TIME:
- *defaultStep = timeDefaultStep;
- *stepScaleFactor = timeStepScaleFactor;
- return true;
- case WEEK:
- *defaultStep = weekDefaultStep;
- *stepScaleFactor = weekStepScaleFactor;
- return true;
- case BUTTON:
- case CHECKBOX:
- case COLOR:
- case EMAIL:
- case FILE:
- case HIDDEN:
- case IMAGE:
- case ISINDEX:
- case PASSWORD:
- case RADIO:
- case RESET:
- case SEARCH:
- case SUBMIT:
- case TELEPHONE:
- case TEXT:
- case URL:
- return false;
- }
- ASSERT_NOT_REACHED();
- return false;
+ return m_inputType->stepMismatch(value, step);
}
bool HTMLInputElement::getAllowedValueStep(double* step) const
{
ASSERT(step);
- double defaultStep;
- double stepScaleFactor;
- if (!getStepParameters(&defaultStep, &stepScaleFactor))
+ double defaultStep = m_inputType->defaultStep();
+ double stepScaleFactor = m_inputType->stepScaleFactor();
+ if (!isfinite(defaultStep) || !isfinite(stepScaleFactor))
return false;
const AtomicString& stepString = getAttribute(stepAttr);
if (stepString.isEmpty()) {
@@ -704,12 +391,12 @@ bool HTMLInputElement::getAllowedValueStep(double* step) const
*step = defaultStep * stepScaleFactor;
return true;
}
- // For DATE, MONTH, WEEK, the parsed value should be an integer.
- if (deprecatedInputType() == DATE || deprecatedInputType() == MONTH || deprecatedInputType() == WEEK)
+ // For date, month, week, the parsed value should be an integer for some types.
+ if (m_inputType->parsedStepValueShouldBeInteger())
parsed = max(round(parsed), 1.0);
double result = parsed * stepScaleFactor;
- // For DATETIME, DATETIMELOCAL, TIME, the result should be an integer.
- if (deprecatedInputType() == DATETIME || deprecatedInputType() == DATETIMELOCAL || deprecatedInputType() == TIME)
+ // For datetime, datetime-local, time, the result should be an integer.
+ if (m_inputType->scaledStepValeuShouldBeInteger())
result = max(round(result), 1.0);
ASSERT(result > 0);
*step = result;
@@ -734,13 +421,13 @@ void HTMLInputElement::applyStep(double count, ExceptionCode& ec)
ec = INVALID_STATE_ERR;
return;
}
- if (newValue < minimum()) {
+ if (newValue < m_inputType->minimum()) {
ec = INVALID_STATE_ERR;
return;
}
- double base = stepBase();
+ double base = m_inputType->stepBase();
newValue = base + round((newValue - base) / step) * step;
- if (newValue > maximum()) {
+ if (newValue > m_inputType->maximum()) {
ec = INVALID_STATE_ERR;
return;
}
@@ -2442,8 +2129,8 @@ void HTMLInputElement::handleKeyEventForRange(KeyboardEvent* event)
ExceptionCode ec;
if (equalIgnoringCase(getAttribute(stepAttr), "any")) {
- double min = minimum();
- double max = maximum();
+ double min = m_inputType->minimum();
+ double max = m_inputType->maximum();
// FIXME: Is 1/100 reasonable?
double step = (max - min) / 100;
double current = m_inputType->parseToDouble(value(), numeric_limits<double>::quiet_NaN());
@@ -2837,8 +2524,8 @@ void HTMLInputElement::stepUpFromRenderer(int n)
const double nan = numeric_limits<double>::quiet_NaN();
String currentStringValue = value();
double current = m_inputType->parseToDouble(currentStringValue, nan);
- if (!isfinite(current) || (n > 0 && current < minimum()) || (n < 0 && current > maximum()))
- setValue(serialize(n > 0 ? minimum() : maximum()));
+ if (!isfinite(current) || (n > 0 && current < m_inputType->minimum()) || (n < 0 && current > m_inputType->maximum()))
+ setValue(serialize(n > 0 ? m_inputType->minimum() : m_inputType->maximum()));
else {
ExceptionCode ec;
stepUp(n, ec);
diff --git a/WebCore/html/HTMLInputElement.h b/WebCore/html/HTMLInputElement.h
index fb2e0ad..21f4f0a 100644
--- a/WebCore/html/HTMLInputElement.h
+++ b/WebCore/html/HTMLInputElement.h
@@ -326,12 +326,8 @@ private:
void handleBeforeTextInsertedEvent(Event*);
void handleKeyEventForRange(KeyboardEvent*);
PassRefPtr<HTMLFormElement> createTemporaryFormForIsIndex();
- // Helper for getAllowedValueStep();
- bool getStepParameters(double* defaultStep, double* stepScaleFactor) const;
// Helper for stepUp()/stepDown(). Adds step value * count to the current value.
void applyStep(double count, ExceptionCode&);
- // Helper for applyStepForNumberOrRange().
- double stepBase() const;
// Create a string representation of the specified double value for the
// current input type. If NaN or Infinity is specified, this returns an
diff --git a/WebCore/html/InputType.cpp b/WebCore/html/InputType.cpp
index 7b83ca4..ca58736 100644
--- a/WebCore/html/InputType.cpp
+++ b/WebCore/html/InputType.cpp
@@ -53,11 +53,15 @@
#include "TimeInputType.h"
#include "URLInputType.h"
#include "WeekInputType.h"
+#include <limits>
+#include <wtf/Assertions.h>
#include <wtf/HashMap.h>
#include <wtf/text/StringHash.h>
namespace WebCore {
+using namespace std;
+
typedef HashMap<String, PassOwnPtr<InputType> (*)(HTMLInputElement*), CaseFoldingHash> InputTypeFactoryMap;
static PassOwnPtr<InputTypeFactoryMap> createInputTypeFactoryMap()
{
@@ -122,6 +126,61 @@ bool InputType::patternMismatch(const String&) const
return false;
}
+bool InputType::rangeUnderflow(const String&) const
+{
+ return false;
+}
+
+bool InputType::rangeOverflow(const String&) const
+{
+ return false;
+}
+
+double InputType::minimum() const
+{
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
+double InputType::maximum() const
+{
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
+bool InputType::stepMismatch(const String&, double) const
+{
+ // Non-supported types should be rejected by HTMLInputElement::getAllowedValueStep().
+ ASSERT_NOT_REACHED();
+ return false;
+}
+
+double InputType::stepBase() const
+{
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
+double InputType::defaultStep() const
+{
+ return numeric_limits<double>::quiet_NaN();
+}
+
+double InputType::stepScaleFactor() const
+{
+ return numeric_limits<double>::quiet_NaN();
+}
+
+bool InputType::parsedStepValueShouldBeInteger() const
+{
+ return false;
+}
+
+bool InputType::scaledStepValeuShouldBeInteger() const
+{
+ return false;
+}
+
double InputType::parseToDouble(const String&, double defaultValue) const
{
return defaultValue;
diff --git a/WebCore/html/InputType.h b/WebCore/html/InputType.h
index 9ce7648..c40ed85 100644
--- a/WebCore/html/InputType.h
+++ b/WebCore/html/InputType.h
@@ -41,6 +41,8 @@ class HTMLInputElement;
class InputType : public Noncopyable {
public:
+ static const double defaultStepBase = 0.0;
+
static PassOwnPtr<InputType> create(HTMLInputElement*, const AtomicString&);
static PassOwnPtr<InputType> createText(HTMLInputElement*);
virtual ~InputType();
@@ -49,7 +51,19 @@ public:
virtual bool isTextType() const;
virtual const AtomicString& formControlType() const = 0;
+ // Validation-related functions
+
virtual bool patternMismatch(const String&) const;
+ virtual bool rangeUnderflow(const String&) const;
+ virtual bool rangeOverflow(const String&) const;
+ virtual double minimum() const;
+ virtual double maximum() const;
+ virtual bool stepMismatch(const String&, double) const;
+ virtual double stepBase() const;
+ virtual double defaultStep() const;
+ virtual double stepScaleFactor() const;
+ virtual bool parsedStepValueShouldBeInteger() const;
+ virtual bool scaledStepValeuShouldBeInteger() const;
// Parses the specified string for the type, and return
// the double value for the parsing result if the parsing
diff --git a/WebCore/html/MonthInputType.cpp b/WebCore/html/MonthInputType.cpp
index 80e2856..e4970e0 100644
--- a/WebCore/html/MonthInputType.cpp
+++ b/WebCore/html/MonthInputType.cpp
@@ -32,11 +32,18 @@
#include "MonthInputType.h"
#include "DateComponents.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
#include <wtf/MathExtras.h>
#include <wtf/PassOwnPtr.h>
namespace WebCore {
+using namespace HTMLNames;
+
+static const double monthDefaultStep = 1.0;
+static const double monthStepScaleFactor = 1.0;
+
PassOwnPtr<InputType> MonthInputType::create(HTMLInputElement* element)
{
return adoptPtr(new MonthInputType(element));
@@ -47,6 +54,31 @@ const AtomicString& MonthInputType::formControlType() const
return InputTypeNames::month();
}
+double MonthInputType::minimum() const
+{
+ return parseToDouble(element()->fastGetAttribute(minAttr), DateComponents::minimumMonth());
+}
+
+double MonthInputType::maximum() const
+{
+ return parseToDouble(element()->fastGetAttribute(maxAttr), DateComponents::maximumMonth());
+}
+
+double MonthInputType::defaultStep() const
+{
+ return monthDefaultStep;
+}
+
+double MonthInputType::stepScaleFactor() const
+{
+ return monthStepScaleFactor;
+}
+
+bool MonthInputType::parsedStepValueShouldBeInteger() const
+{
+ return true;
+}
+
double MonthInputType::parseToDouble(const String& src, double defaultValue) const
{
DateComponents date;
diff --git a/WebCore/html/MonthInputType.h b/WebCore/html/MonthInputType.h
index a7ea550..d3e2ba1 100644
--- a/WebCore/html/MonthInputType.h
+++ b/WebCore/html/MonthInputType.h
@@ -43,6 +43,11 @@ private:
MonthInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
virtual const AtomicString& formControlType() const;
virtual double parseToDouble(const String&, double) const;
+ virtual double minimum() const;
+ virtual double maximum() const;
+ virtual double defaultStep() const;
+ virtual double stepScaleFactor() const;
+ virtual bool parsedStepValueShouldBeInteger() const;
virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
};
diff --git a/WebCore/html/NumberInputType.cpp b/WebCore/html/NumberInputType.cpp
index 991b1fa..e1cd869 100644
--- a/WebCore/html/NumberInputType.cpp
+++ b/WebCore/html/NumberInputType.cpp
@@ -31,12 +31,27 @@
#include "config.h"
#include "NumberInputType.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
#include "HTMLParserIdioms.h"
+#include <limits>
#include <wtf/MathExtras.h>
#include <wtf/PassOwnPtr.h>
namespace WebCore {
+using namespace HTMLNames;
+using namespace std;
+
+// FIXME: Number values should be in the range of IEEE 754 single-precision
+// floating point number.
+// http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#real-numbers
+static const double numberDefaultMinimum = -DBL_MAX;
+static const double numberDefaultMaximum = DBL_MAX;
+
+static const double numberDefaultStep = 1.0;
+static const double numberStepScaleFactor = 1.0;
+
PassOwnPtr<InputType> NumberInputType::create(HTMLInputElement* element)
{
return adoptPtr(new NumberInputType(element));
@@ -47,6 +62,63 @@ const AtomicString& NumberInputType::formControlType() const
return InputTypeNames::number();
}
+bool NumberInputType::rangeUnderflow(const String& value) const
+{
+ const double nan = numeric_limits<double>::quiet_NaN();
+ double doubleValue = parseToDouble(value, nan);
+ return isfinite(doubleValue) && doubleValue < minimum();
+}
+
+bool NumberInputType::rangeOverflow(const String& value) const
+{
+ const double nan = numeric_limits<double>::quiet_NaN();
+ double doubleValue = parseToDouble(value, nan);
+ return isfinite(doubleValue) && doubleValue > maximum();
+}
+
+double NumberInputType::minimum() const
+{
+ return parseToDouble(element()->fastGetAttribute(minAttr), numberDefaultMinimum);
+}
+
+double NumberInputType::maximum() const
+{
+ return parseToDouble(element()->fastGetAttribute(maxAttr), numberDefaultMaximum);
+}
+
+bool NumberInputType::stepMismatch(const String& value, double step) const
+{
+ double doubleValue;
+ if (!parseToDoubleForNumberType(value, &doubleValue))
+ return false;
+ doubleValue = fabs(doubleValue - stepBase());
+ if (isinf(doubleValue))
+ return false;
+ // double's fractional part size is DBL_MAN_DIG-bit. If the current value
+ // is greater than step*2^DBL_MANT_DIG, the following fmod() makes no sense.
+ if (doubleValue / pow(2.0, DBL_MANT_DIG) > step)
+ return false;
+ double remainder = fmod(doubleValue, step);
+ // Accepts errors in lower 7-bit.
+ double acceptableError = step / pow(2.0, DBL_MANT_DIG - 7);
+ return acceptableError < remainder && remainder < (step - acceptableError);
+}
+
+double NumberInputType::stepBase() const
+{
+ return parseToDouble(element()->fastGetAttribute(minAttr), defaultStepBase);
+}
+
+double NumberInputType::defaultStep() const
+{
+ return numberDefaultStep;
+}
+
+double NumberInputType::stepScaleFactor() const
+{
+ return numberStepScaleFactor;
+}
+
double NumberInputType::parseToDouble(const String& src, double defaultValue) const
{
double numberValue;
diff --git a/WebCore/html/NumberInputType.h b/WebCore/html/NumberInputType.h
index 9a2e9cd..0e82937 100644
--- a/WebCore/html/NumberInputType.h
+++ b/WebCore/html/NumberInputType.h
@@ -42,6 +42,14 @@ public:
private:
NumberInputType(HTMLInputElement* element) : TextFieldInputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool rangeUnderflow(const String&) const;
+ virtual bool rangeOverflow(const String&) const;
+ virtual double minimum() const;
+ virtual double maximum() const;
+ virtual bool stepMismatch(const String&, double) const;
+ virtual double stepBase() const;
+ virtual double defaultStep() const;
+ virtual double stepScaleFactor() const;
virtual double parseToDouble(const String&, double) const;
};
diff --git a/WebCore/html/RangeInputType.cpp b/WebCore/html/RangeInputType.cpp
index 340d669..a73ca30 100644
--- a/WebCore/html/RangeInputType.cpp
+++ b/WebCore/html/RangeInputType.cpp
@@ -31,12 +31,23 @@
#include "config.h"
#include "RangeInputType.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
#include "HTMLParserIdioms.h"
+#include <limits>
#include <wtf/MathExtras.h>
#include <wtf/PassOwnPtr.h>
namespace WebCore {
+using namespace HTMLNames;
+using namespace std;
+
+static const double rangeDefaultMinimum = 0.0;
+static const double rangeDefaultMaximum = 100.0;
+static const double rangeDefaultStep = 1.0;
+static const double rangeStepScaleFactor = 1.0;
+
PassOwnPtr<InputType> RangeInputType::create(HTMLInputElement* element)
{
return adoptPtr(new RangeInputType(element));
@@ -47,6 +58,59 @@ const AtomicString& RangeInputType::formControlType() const
return InputTypeNames::range();
}
+bool RangeInputType::rangeUnderflow(const String& value) const
+{
+ // Guaranteed by sanitization.
+ ASSERT_UNUSED(value, parseToDouble(value, numeric_limits<double>::quiet_NaN()) >= minimum());
+ return false;
+}
+
+bool RangeInputType::rangeOverflow(const String& value) const
+{
+ // Guaranteed by sanitization.
+ ASSERT_UNUSED(value, parseToDouble(value, numeric_limits<double>::quiet_NaN()) <= maximum());
+ return false;
+}
+
+double RangeInputType::minimum() const
+{
+ return parseToDouble(element()->fastGetAttribute(minAttr), rangeDefaultMinimum);
+}
+
+double RangeInputType::maximum() const
+{
+ double max = parseToDouble(element()->fastGetAttribute(maxAttr), rangeDefaultMaximum);
+ // A remedy for the inconsistent min/max values.
+ // Sets the maximum to the default or the minimum value.
+ double min = minimum();
+ if (max < min)
+ max = std::max(min, rangeDefaultMaximum);
+ return max;
+}
+
+bool RangeInputType::stepMismatch(const String&, double) const
+{
+ // stepMismatch doesn't occur for type=range. RenderSlider guarantees the
+ // value matches to step on user input, and sanitization takes care
+ // of the general case.
+ return false;
+}
+
+double RangeInputType::stepBase() const
+{
+ return minimum();
+}
+
+double RangeInputType::defaultStep() const
+{
+ return rangeDefaultStep;
+}
+
+double RangeInputType::stepScaleFactor() const
+{
+ return rangeStepScaleFactor;
+}
+
double RangeInputType::parseToDouble(const String& src, double defaultValue) const
{
double numberValue;
diff --git a/WebCore/html/RangeInputType.h b/WebCore/html/RangeInputType.h
index e681e5a..17d6334 100644
--- a/WebCore/html/RangeInputType.h
+++ b/WebCore/html/RangeInputType.h
@@ -42,6 +42,14 @@ public:
private:
RangeInputType(HTMLInputElement* element) : InputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual bool rangeUnderflow(const String&) const;
+ virtual bool rangeOverflow(const String&) const;
+ virtual double minimum() const;
+ virtual double maximum() const;
+ virtual bool stepMismatch(const String&, double) const;
+ virtual double stepBase() const;
+ virtual double defaultStep() const;
+ virtual double stepScaleFactor() const;
virtual double parseToDouble(const String&, double) const;
};
diff --git a/WebCore/html/TimeInputType.cpp b/WebCore/html/TimeInputType.cpp
index 535ab04..74b13cc 100644
--- a/WebCore/html/TimeInputType.cpp
+++ b/WebCore/html/TimeInputType.cpp
@@ -32,10 +32,17 @@
#include "TimeInputType.h"
#include "DateComponents.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
+using namespace HTMLNames;
+
+static const double timeDefaultStep = 60.0;
+static const double timeStepScaleFactor = 1000.0;
+
PassOwnPtr<InputType> TimeInputType::create(HTMLInputElement* element)
{
return adoptPtr(new TimeInputType(element));
@@ -46,6 +53,31 @@ const AtomicString& TimeInputType::formControlType() const
return InputTypeNames::time();
}
+double TimeInputType::minimum() const
+{
+ return parseToDouble(element()->fastGetAttribute(minAttr), DateComponents::minimumTime());
+}
+
+double TimeInputType::maximum() const
+{
+ return parseToDouble(element()->fastGetAttribute(maxAttr), DateComponents::maximumTime());
+}
+
+double TimeInputType::defaultStep() const
+{
+ return timeDefaultStep;
+}
+
+double TimeInputType::stepScaleFactor() const
+{
+ return timeStepScaleFactor;
+}
+
+bool TimeInputType::scaledStepValeuShouldBeInteger() const
+{
+ return true;
+}
+
bool TimeInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const
{
ASSERT(out);
diff --git a/WebCore/html/TimeInputType.h b/WebCore/html/TimeInputType.h
index 5f1256d..9e751ab 100644
--- a/WebCore/html/TimeInputType.h
+++ b/WebCore/html/TimeInputType.h
@@ -42,6 +42,11 @@ public:
private:
TimeInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual double minimum() const;
+ virtual double maximum() const;
+ virtual double defaultStep() const;
+ virtual double stepScaleFactor() const;
+ virtual bool scaledStepValeuShouldBeInteger() const;
virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
};
diff --git a/WebCore/html/WeekInputType.cpp b/WebCore/html/WeekInputType.cpp
index 1bdabe0..947e631 100644
--- a/WebCore/html/WeekInputType.cpp
+++ b/WebCore/html/WeekInputType.cpp
@@ -32,10 +32,18 @@
#include "WeekInputType.h"
#include "DateComponents.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
#include <wtf/PassOwnPtr.h>
namespace WebCore {
+using namespace HTMLNames;
+
+static const double weekDefaultStepBase = -259200000.0; // The first day of 1970-W01.
+static const double weekDefaultStep = 1.0;
+static const double weekStepScaleFactor = 604800000.0;
+
PassOwnPtr<InputType> WeekInputType::create(HTMLInputElement* element)
{
return adoptPtr(new WeekInputType(element));
@@ -46,6 +54,36 @@ const AtomicString& WeekInputType::formControlType() const
return InputTypeNames::week();
}
+double WeekInputType::minimum() const
+{
+ return parseToDouble(element()->fastGetAttribute(minAttr), DateComponents::minimumWeek());
+}
+
+double WeekInputType::maximum() const
+{
+ return parseToDouble(element()->fastGetAttribute(maxAttr), DateComponents::maximumWeek());
+}
+
+double WeekInputType::stepBase() const
+{
+ return parseToDouble(element()->fastGetAttribute(minAttr), weekDefaultStepBase);
+}
+
+double WeekInputType::defaultStep() const
+{
+ return weekDefaultStep;
+}
+
+double WeekInputType::stepScaleFactor() const
+{
+ return weekStepScaleFactor;
+}
+
+bool WeekInputType::parsedStepValueShouldBeInteger() const
+{
+ return true;
+}
+
bool WeekInputType::parseToDateComponentsInternal(const UChar* characters, unsigned length, DateComponents* out) const
{
ASSERT(out);
diff --git a/WebCore/html/WeekInputType.h b/WebCore/html/WeekInputType.h
index a190ca8..4aed6dd 100644
--- a/WebCore/html/WeekInputType.h
+++ b/WebCore/html/WeekInputType.h
@@ -42,6 +42,12 @@ public:
private:
WeekInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
virtual const AtomicString& formControlType() const;
+ virtual double minimum() const;
+ virtual double maximum() const;
+ virtual double stepBase() const;
+ virtual double defaultStep() const;
+ virtual double stepScaleFactor() const;
+ virtual bool parsedStepValueShouldBeInteger() const;
virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const;
};
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list