[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.21-584-g1e41756
tkent at chromium.org
tkent at chromium.org
Fri Feb 26 22:19:29 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit 57258085e6d758b060e2953104ca0894ae277ff1
Author: tkent at chromium.org <tkent at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Sat Feb 13 19:52:37 2010 +0000
2010-02-13 Kent Tamura <tkent at chromium.org>
Reviewed by Darin Adler.
Refactor parsing/serialization functions in HTMLInputElement.
https://bugs.webkit.org/show_bug.cgi?id=34852
- Rename formStringToDouble() to parseToDoubleForNumberType()
- Rename formStringToDateComponents() to parseToDateComponents()
- Rename formStringFromDouble() to serializeForNumberType()
- Add serializeForDateTimeTypes()
The code is moved from setValueAsDate() and setDateValue().
- Add serialize()
parseToDouble() is the top-level function to parse a
type-dependent string and return a double
value. parseToDoubleForNumber() and parseToDateComponents()
functions are helper functions for it. serialize() is the
top-level function to serialize a double value to a type-dependent
string, and serializeForNumberType() and
serializeForDateTimeTypes() are helper functions for it.
No tests because of no functional changes.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::stepMismatch):
(WebCore::HTMLInputElement::getAllowedValueStep):
(WebCore::HTMLInputElement::parseToDouble):
(WebCore::HTMLInputElement::valueAsDate):
(WebCore::HTMLInputElement::setValueAsDate):
(WebCore::HTMLInputElement::setValueAsNumber):
(WebCore::HTMLInputElement::serializeForDateTimeTypes):
(WebCore::HTMLInputElement::serialize):
(WebCore::HTMLInputElement::serializeForNumberType):
(WebCore::HTMLInputElement::parseToDoubleForNumberType):
(WebCore::HTMLInputElement::parseToDateComponents):
* html/HTMLInputElement.h:
* html/ValidityState.cpp:
(WebCore::ValidityState::typeMismatch):
* rendering/RenderSlider.cpp:
(WebCore::SliderRange::valueFromElement):
(WebCore::RenderSlider::updateFromElement):
(WebCore::RenderSlider::setValueForPosition):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@54754 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 75ef1c1..d961cf0 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,47 @@
+2010-02-13 Kent Tamura <tkent at chromium.org>
+
+ Reviewed by Darin Adler.
+
+ Refactor parsing/serialization functions in HTMLInputElement.
+ https://bugs.webkit.org/show_bug.cgi?id=34852
+
+ - Rename formStringToDouble() to parseToDoubleForNumberType()
+ - Rename formStringToDateComponents() to parseToDateComponents()
+ - Rename formStringFromDouble() to serializeForNumberType()
+ - Add serializeForDateTimeTypes()
+ The code is moved from setValueAsDate() and setDateValue().
+ - Add serialize()
+
+ parseToDouble() is the top-level function to parse a
+ type-dependent string and return a double
+ value. parseToDoubleForNumber() and parseToDateComponents()
+ functions are helper functions for it. serialize() is the
+ top-level function to serialize a double value to a type-dependent
+ string, and serializeForNumberType() and
+ serializeForDateTimeTypes() are helper functions for it.
+
+ No tests because of no functional changes.
+
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::stepMismatch):
+ (WebCore::HTMLInputElement::getAllowedValueStep):
+ (WebCore::HTMLInputElement::parseToDouble):
+ (WebCore::HTMLInputElement::valueAsDate):
+ (WebCore::HTMLInputElement::setValueAsDate):
+ (WebCore::HTMLInputElement::setValueAsNumber):
+ (WebCore::HTMLInputElement::serializeForDateTimeTypes):
+ (WebCore::HTMLInputElement::serialize):
+ (WebCore::HTMLInputElement::serializeForNumberType):
+ (WebCore::HTMLInputElement::parseToDoubleForNumberType):
+ (WebCore::HTMLInputElement::parseToDateComponents):
+ * html/HTMLInputElement.h:
+ * html/ValidityState.cpp:
+ (WebCore::ValidityState::typeMismatch):
+ * rendering/RenderSlider.cpp:
+ (WebCore::SliderRange::valueFromElement):
+ (WebCore::RenderSlider::updateFromElement):
+ (WebCore::RenderSlider::setValueForPosition):
+
2010-01-05 Ojan Vafai <ojan at chromium.org>
Reviewed by Dan Bernstein.
diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp
index 43f71ab..0831363 100644
--- a/WebCore/html/HTMLInputElement.cpp
+++ b/WebCore/html/HTMLInputElement.cpp
@@ -500,7 +500,7 @@ bool HTMLInputElement::stepMismatch() const
return false;
case NUMBER: {
double doubleValue;
- if (!formStringToDouble(value(), &doubleValue))
+ if (!parseToDoubleForNumberType(value(), &doubleValue))
return false;
doubleValue = fabs(doubleValue - stepBase());
if (isinf(doubleValue))
@@ -621,7 +621,7 @@ bool HTMLInputElement::getAllowedValueStep(double* step) const
if (equalIgnoringCase(stepString, "any"))
return false;
double parsed;
- if (!formStringToDouble(stepString, &parsed) || parsed <= 0.0) {
+ if (!parseToDoubleForNumberType(stepString, &parsed) || parsed <= 0.0) {
*step = defaultStep * stepScaleFactor;
return true;
}
@@ -1607,7 +1607,7 @@ double HTMLInputElement::parseToDouble(const String& src, double defaultValue) c
case TIME:
case WEEK: {
DateComponents date;
- if (!formStringToDateComponents(inputType(), src, &date))
+ if (!parseToDateComponents(inputType(), src, &date))
return defaultValue;
double msec = date.millisecondsSinceEpoch();
ASSERT(isfinite(msec));
@@ -1615,7 +1615,7 @@ double HTMLInputElement::parseToDouble(const String& src, double defaultValue) c
}
case MONTH: {
DateComponents date;
- if (!formStringToDateComponents(inputType(), src, &date))
+ if (!parseToDateComponents(inputType(), src, &date))
return defaultValue;
double months = date.monthsSinceEpoch();
ASSERT(isfinite(months));
@@ -1624,7 +1624,7 @@ double HTMLInputElement::parseToDouble(const String& src, double defaultValue) c
case NUMBER:
case RANGE: {
double numberValue;
- if (!formStringToDouble(src, &numberValue))
+ if (!parseToDoubleForNumberType(src, &numberValue))
return defaultValue;
ASSERT(isfinite(numberValue));
return numberValue;
@@ -1662,7 +1662,7 @@ double HTMLInputElement::valueAsDate() const
return parseToDouble(value(), DateComponents::invalidMilliseconds());
case MONTH: {
DateComponents date;
- if (!formStringToDateComponents(inputType(), value(), &date))
+ if (!parseToDateComponents(inputType(), value(), &date))
return DateComponents::invalidMilliseconds();
double msec = date.millisecondsSinceEpoch();
ASSERT(isfinite(msec));
@@ -1696,24 +1696,22 @@ double HTMLInputElement::valueAsDate() const
void HTMLInputElement::setValueAsDate(double value, ExceptionCode& ec)
{
- DateComponents date;
- bool success;
switch (inputType()) {
case DATE:
- success = date.setMillisecondsSinceEpochForDate(value);
- break;
case DATETIME:
- success = date.setMillisecondsSinceEpochForDateTime(value);
- break;
- case MONTH:
- success = date.setMillisecondsSinceEpochForMonth(value);
- break;
case TIME:
- success = date.setMillisecondsSinceMidnight(value);
- break;
case WEEK:
- success = date.setMillisecondsSinceEpochForWeek(value);
- break;
+ setValue(serializeForDateTimeTypes(value));
+ return;
+ case MONTH: {
+ DateComponents date;
+ if (!date.setMillisecondsSinceEpochForMonth(value)) {
+ setValue(String());
+ return;
+ }
+ setValue(date.toString());
+ return;
+ }
case BUTTON:
case CHECKBOX:
case COLOR:
@@ -1735,33 +1733,8 @@ void HTMLInputElement::setValueAsDate(double value, ExceptionCode& ec)
case URL:
ec = INVALID_STATE_ERR;
return;
- default:
- ASSERT_NOT_REACHED();
- success = false;
- }
- if (!success) {
- setValue(String());
- return;
- }
- setDateValue(date);
-}
-
-void HTMLInputElement::setDateValue(const DateComponents& date)
-{
- double step;
- if (!getAllowedValueStep(&step)) {
- setValue(date.toString());
- return;
}
- if (!fmod(step, msecPerMinute)) {
- setValue(date.toString(DateComponents::None));
- return;
- }
- if (!fmod(step, msecPerSecond)) {
- setValue(date.toString(DateComponents::Second));
- return;
- }
- setValue(date.toString(DateComponents::Millisecond));
+ ASSERT_NOT_REACHED();
}
double HTMLInputElement::valueAsNumber() const
@@ -1809,32 +1782,109 @@ void HTMLInputElement::setValueAsNumber(double newValue, ExceptionCode& ec)
switch (inputType()) {
case DATE:
case DATETIME:
+ case DATETIMELOCAL:
+ case MONTH:
+ case NUMBER:
+ case RANGE:
case TIME:
case WEEK:
- setValueAsDate(newValue, ec);
+ setValue(serialize(newValue));
return;
- case MONTH: {
- DateComponents date;
- if (!date.setMonthsSinceEpoch(newValue)) {
- setValue(String());
- return;
- }
- setValue(date.toString());
+
+ 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:
+ ec = INVALID_STATE_ERR;
return;
}
- case DATETIMELOCAL: {
- DateComponents date;
- if (!date.setMillisecondsSinceEpochForDateTimeLocal(newValue)) {
- setValue(String());
- return;
- }
- setDateValue(date);
- return;
+ ASSERT_NOT_REACHED();
+}
+
+String HTMLInputElement::serializeForDateTimeTypes(double value) const
+{
+ bool success;
+ DateComponents date;
+ switch (inputType()) {
+ case DATE:
+ success = date.setMillisecondsSinceEpochForDate(value);
+ break;
+ case DATETIME:
+ success = date.setMillisecondsSinceEpochForDateTime(value);
+ break;
+ case DATETIMELOCAL:
+ success = date.setMillisecondsSinceEpochForDateTimeLocal(value);
+ break;
+ case MONTH:
+ success = date.setMonthsSinceEpoch(value);
+ break;
+ case TIME:
+ success = date.setMillisecondsSinceMidnight(value);
+ break;
+ case WEEK:
+ success = date.setMillisecondsSinceEpochForWeek(value);
+ break;
+ case NUMBER:
+ case RANGE:
+ 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:
+ ASSERT_NOT_REACHED();
+ return String();
}
+ if (!success)
+ return String();
+
+ double step;
+ if (!getAllowedValueStep(&step))
+ return date.toString();
+ if (!fmod(step, msecPerMinute))
+ return date.toString(DateComponents::None);
+ if (!fmod(step, msecPerSecond))
+ return date.toString(DateComponents::Second);
+ return date.toString(DateComponents::Millisecond);
+}
+
+String HTMLInputElement::serialize(double value) const
+{
+ if (!isfinite(value))
+ return String();
+ switch (inputType()) {
+ case DATE:
+ case DATETIME:
+ case DATETIMELOCAL:
+ case MONTH:
+ case TIME:
+ case WEEK:
+ return serializeForDateTimeTypes(value);
case NUMBER:
case RANGE:
- setValue(formStringFromDouble(newValue));
- return;
+ return serializeForNumberType(value);
case BUTTON:
case CHECKBOX:
@@ -1852,11 +1902,10 @@ void HTMLInputElement::setValueAsNumber(double newValue, ExceptionCode& ec)
case TELEPHONE:
case TEXT:
case URL:
- ec = INVALID_STATE_ERR;
- return;
+ break;
}
ASSERT_NOT_REACHED();
- return;
+ return String();
}
String HTMLInputElement::placeholder() const
@@ -2561,7 +2610,7 @@ bool HTMLInputElement::willValidate() const
inputType() != BUTTON && inputType() != RESET;
}
-String HTMLInputElement::formStringFromDouble(double number)
+String HTMLInputElement::serializeForNumberType(double number)
{
// According to HTML5, "the best representation of the number n as a floating
// point number" is a string produced by applying ToString() to n.
@@ -2571,7 +2620,7 @@ String HTMLInputElement::formStringFromDouble(double number)
return String(buffer, length);
}
-bool HTMLInputElement::formStringToDouble(const String& src, double* out)
+bool HTMLInputElement::parseToDoubleForNumberType(const String& src, double* out)
{
// See HTML5 2.4.4.3 `Real numbers.'
@@ -2597,7 +2646,7 @@ bool HTMLInputElement::formStringToDouble(const String& src, double* out)
return true;
}
-bool HTMLInputElement::formStringToDateComponents(InputType type, const String& formString, DateComponents* out)
+bool HTMLInputElement::parseToDateComponents(InputType type, const String& formString, DateComponents* out)
{
if (formString.isEmpty())
return false;
diff --git a/WebCore/html/HTMLInputElement.h b/WebCore/html/HTMLInputElement.h
index 4665437..40930ac 100644
--- a/WebCore/html/HTMLInputElement.h
+++ b/WebCore/html/HTMLInputElement.h
@@ -262,14 +262,14 @@ public:
// Converts the specified string to a floating number.
// If the conversion fails, the return value is false. Take care that leading or trailing unnecessary characters make failures. This returns false for an empty string input.
// The double* parameter may be 0.
- static bool formStringToDouble(const String&, double*);
+ static bool parseToDoubleForNumberType(const String&, double*);
// Converts the specified number to a string. This is an implementation of
// HTML5's "algorithm to convert a number to a string" for NUMBER/RANGE types.
- static String formStringFromDouble(double);
+ static String serializeForNumberType(double);
// Parses the specified string as the InputType, and returns true if it is successfully parsed.
// An instance pointed by the DateComponents* parameter will have parsed values and be
// modified even if the parsing fails. The DateComponents* parameter may be 0.
- static bool formStringToDateComponents(InputType, const String&, DateComponents*);
+ static bool parseToDateComponents(InputType, const String&, DateComponents*);
protected:
virtual void willMoveToNewOwnerDocument();
@@ -305,11 +305,14 @@ private:
// succeeds; Returns defaultValue otherwise. This function can
// return NaN or Infinity only if defaultValue is NaN or Infinity.
double parseToDouble(const String&, double defaultValue) const;
-
- // Generates a suitable string for the specified DateComponents and the
- // step value, and calls setValue() with it.
- void setDateValue(const DateComponents&);
-
+ // Create a string representation of the specified double value for the
+ // current input type. If NaN or Infinity is specified, this returns an
+ // emtpy string. This should not be called for types without valueAsNumber.
+ String serialize(double) const;
+ // Create a string representation of the specified double value for the
+ // current input type. The type must be one of DATE, DATETIME,
+ // DATETIMELOCAL, MONTH, TIME, and WEEK.
+ String serializeForDateTimeTypes(double) const;
#if ENABLE(DATALIST)
HTMLDataListElement* dataList() const;
diff --git a/WebCore/html/ValidityState.cpp b/WebCore/html/ValidityState.cpp
index 1e0a07b..c6c58a5 100644
--- a/WebCore/html/ValidityState.cpp
+++ b/WebCore/html/ValidityState.cpp
@@ -80,7 +80,7 @@ bool ValidityState::typeMismatch() const
case HTMLInputElement::COLOR:
return !isValidColorString(value);
case HTMLInputElement::NUMBER:
- return !HTMLInputElement::formStringToDouble(value, 0);
+ return !HTMLInputElement::parseToDoubleForNumberType(value, 0);
case HTMLInputElement::URL:
return !KURL(KURL(), value).isValid();
case HTMLInputElement::EMAIL: {
@@ -100,7 +100,7 @@ bool ValidityState::typeMismatch() const
case HTMLInputElement::MONTH:
case HTMLInputElement::TIME:
case HTMLInputElement::WEEK:
- return !HTMLInputElement::formStringToDateComponents(input->inputType(), value, 0);
+ return !HTMLInputElement::parseToDateComponents(input->inputType(), value, 0);
case HTMLInputElement::BUTTON:
case HTMLInputElement::CHECKBOX:
case HTMLInputElement::FILE:
diff --git a/WebCore/rendering/RenderSlider.cpp b/WebCore/rendering/RenderSlider.cpp
index b2f5cef..5bbe9af 100644
--- a/WebCore/rendering/RenderSlider.cpp
+++ b/WebCore/rendering/RenderSlider.cpp
@@ -103,7 +103,7 @@ double SliderRange::clampValue(double value)
double SliderRange::valueFromElement(HTMLInputElement* element, bool* wasClamped)
{
double oldValue;
- bool parseSuccess = HTMLInputElement::formStringToDouble(element->value(), &oldValue);
+ bool parseSuccess = HTMLInputElement::parseToDoubleForNumberType(element->value(), &oldValue);
if (!parseSuccess)
oldValue = (minimum + maximum) / 2;
double newValue = clampValue(oldValue);
@@ -379,7 +379,7 @@ void RenderSlider::updateFromElement()
bool clamped;
double value = range.valueFromElement(element, &clamped);
if (clamped)
- element->setValueFromRenderer(HTMLInputElement::formStringFromDouble(value));
+ element->setValueFromRenderer(HTMLInputElement::serializeForNumberType(value));
// Layout will take care of the thumb's size and position.
if (!m_thumb) {
@@ -435,7 +435,7 @@ void RenderSlider::setValueForPosition(int position)
if (style()->appearance() == SliderVerticalPart || style()->appearance() == MediaVolumeSliderPart)
fraction = 1 - fraction;
double value = range.clampValue(range.valueFromProportion(fraction));
- element->setValueFromRenderer(HTMLInputElement::formStringFromDouble(value));
+ element->setValueFromRenderer(HTMLInputElement::serializeForNumberType(value));
// Also update the position if appropriate.
if (position != currentPosition()) {
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list