Diff
Modified: trunk/LayoutTests/ChangeLog (91548 => 91549)
--- trunk/LayoutTests/ChangeLog 2011-07-22 03:12:43 UTC (rev 91548)
+++ trunk/LayoutTests/ChangeLog 2011-07-22 03:27:30 UTC (rev 91549)
@@ -1,3 +1,17 @@
+2011-07-21 Shinya Kawanaka <[email protected]>
+
+ The input[type="number"] with step="any" should not suffer from step mismatch.
+ https://bugs.webkit.org/show_bug.cgi?id=64858
+
+ Reviewed by Kent Tamura.
+
+ Added test cases of input[type="number"] with step="any"
+
+ * fast/forms/input-stepup-stepdown-expected.txt: added the test cases.
+ * fast/forms/input-stepup-stepdown-from-renderer-expected.txt: ditto.
+ * fast/forms/script-tests/input-stepup-stepdown-from-renderer.js: ditto.
+ * fast/forms/script-tests/input-stepup-stepdown.js: ditto.
+
2011-07-21 Robin Qiu <[email protected]>
https://bugs.webkit.org/show_bug.cgi?id=60737
Modified: trunk/LayoutTests/fast/forms/input-stepup-stepdown-expected.txt (91548 => 91549)
--- trunk/LayoutTests/fast/forms/input-stepup-stepdown-expected.txt 2011-07-22 03:12:43 UTC (rev 91548)
+++ trunk/LayoutTests/fast/forms/input-stepup-stepdown-expected.txt 2011-07-22 03:27:30 UTC (rev 91549)
@@ -139,6 +139,9 @@
Step=any
PASS stepUp("0", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepDown("0", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+Step=any corner case
+PASS stepUpExplicitBounds("0", "100", "any", "1.5", "1") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDownExplicitBounds("0", "100", "any", "1.5", "1") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
Overflow/underflow
PASS stepDown("1", "1", "0") is "0"
PASS stepDown("0", "1", "0") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
Modified: trunk/LayoutTests/fast/forms/input-stepup-stepdown-from-renderer-expected.txt (91548 => 91549)
--- trunk/LayoutTests/fast/forms/input-stepup-stepdown-from-renderer-expected.txt 2011-07-22 03:12:43 UTC (rev 91548)
+++ trunk/LayoutTests/fast/forms/input-stepup-stepdown-from-renderer-expected.txt 2011-07-22 03:27:30 UTC (rev 91549)
@@ -116,6 +116,9 @@
Step=any
PASS stepUp("0", "any", null) is "1"
PASS stepDown("0", "any", null) is "-1"
+Step=any corner case
+PASS stepUpExplicitBounds("0", "100", "any", "1.5", "1") is "2.5"
+PASS stepDownExplicitBounds("0", "100", "any", "1.5", "1") is "0.5"
Overflow/underflow
PASS stepDown("1", "1", "0") is "0"
PASS stepDown("0", "1", "0") is "0"
Modified: trunk/LayoutTests/fast/forms/script-tests/input-stepup-stepdown-from-renderer.js (91548 => 91549)
--- trunk/LayoutTests/fast/forms/script-tests/input-stepup-stepdown-from-renderer.js 2011-07-22 03:12:43 UTC (rev 91548)
+++ trunk/LayoutTests/fast/forms/script-tests/input-stepup-stepdown-from-renderer.js 2011-07-22 03:27:30 UTC (rev 91549)
@@ -199,6 +199,9 @@
debug('Step=any');
shouldBe('stepUp("0", "any", null)', '"1"');
shouldBe('stepDown("0", "any", null)', '"-1"');
+debug('Step=any corner case');
+shouldBe('stepUpExplicitBounds("0", "100", "any", "1.5", "1")', '"2.5"');
+shouldBe('stepDownExplicitBounds("0", "100", "any", "1.5", "1")', '"0.5"');
debug('Overflow/underflow');
shouldBe('stepDown("1", "1", "0")', '"0"');
shouldBe('stepDown("0", "1", "0")', '"0"');
Modified: trunk/LayoutTests/fast/forms/script-tests/input-stepup-stepdown.js (91548 => 91549)
--- trunk/LayoutTests/fast/forms/script-tests/input-stepup-stepdown.js 2011-07-22 03:12:43 UTC (rev 91548)
+++ trunk/LayoutTests/fast/forms/script-tests/input-stepup-stepdown.js 2011-07-22 03:27:30 UTC (rev 91549)
@@ -194,6 +194,9 @@
debug('Step=any');
shouldThrow('stepUp("0", "any", null)', invalidStateErr);
shouldThrow('stepDown("0", "any", null)', invalidStateErr);
+debug('Step=any corner case');
+shouldThrow('stepUpExplicitBounds("0", "100", "any", "1.5", "1")', invalidStateErr);
+shouldThrow('stepDownExplicitBounds("0", "100", "any", "1.5", "1")', invalidStateErr);
debug('Overflow/underflow');
shouldBe('stepDown("1", "1", "0")', '"0"');
shouldThrow('stepDown("0", "1", "0")', invalidStateErr);
Modified: trunk/Source/WebCore/ChangeLog (91548 => 91549)
--- trunk/Source/WebCore/ChangeLog 2011-07-22 03:12:43 UTC (rev 91548)
+++ trunk/Source/WebCore/ChangeLog 2011-07-22 03:27:30 UTC (rev 91549)
@@ -1,3 +1,16 @@
+2011-07-21 Shinya Kawanaka <[email protected]>
+
+ The input[type="number"] with step="any" should not suffer from step mismatch.
+ https://bugs.webkit.org/show_bug.cgi?id=64858
+
+ Reviewed by Kent Tamura.
+
+ Added check step="any" not to suffer from step mismatch.
+
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::applyStep): Added check step="any".
+ (WebCore::HTMLInputElement::alignValueForStep): Added.
+
2011-07-21 MORITA Hajime <[email protected]>
[Refactoring] ShadowContentSelector should be ShadowInclusionSelector
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (91548 => 91549)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2011-07-22 03:12:43 UTC (rev 91548)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2011-07-22 03:27:30 UTC (rev 91549)
@@ -415,6 +415,7 @@
ec = INVALID_STATE_ERR;
return;
}
+
double acceptableError = m_inputType->acceptableError(step);
if (newValue - m_inputType->minimum() < -acceptableError) {
ec = INVALID_STATE_ERR;
@@ -422,30 +423,43 @@
}
if (newValue < m_inputType->minimum())
newValue = m_inputType->minimum();
- unsigned baseDecimalPlaces;
- double base = m_inputType->stepBaseWithDecimalPlaces(&baseDecimalPlaces);
- baseDecimalPlaces = min(baseDecimalPlaces, 16u);
- if (newValue < pow(10.0, 21.0)) {
- if (stepMismatch(value())) {
- double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, currentDecimalPlaces)));
- newValue = round(newValue * scale) / scale;
- } else {
- double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, baseDecimalPlaces)));
- newValue = round((base + round((newValue - base) / step) * step) * scale) / scale;
- }
- }
+
+ const AtomicString& stepString = fastGetAttribute(stepAttr);
+ if (!equalIgnoringCase(stepString, "any"))
+ newValue = alignValueForStep(newValue, step, currentDecimalPlaces, stepDecimalPlaces);
+
if (newValue - m_inputType->maximum() > acceptableError) {
ec = INVALID_STATE_ERR;
return;
}
if (newValue > m_inputType->maximum())
newValue = m_inputType->maximum();
+
setValueAsNumber(newValue, ec);
if (AXObjectCache::accessibilityEnabled())
document()->axObjectCache()->postNotification(renderer(), AXObjectCache::AXValueChanged, true);
}
+double HTMLInputElement::alignValueForStep(double newValue, double step, unsigned currentDecimalPlaces, unsigned stepDecimalPlaces)
+{
+ if (newValue >= pow(10.0, 21.0))
+ return newValue;
+
+ unsigned baseDecimalPlaces;
+ double base = m_inputType->stepBaseWithDecimalPlaces(&baseDecimalPlaces);
+ baseDecimalPlaces = min(baseDecimalPlaces, 16u);
+ if (stepMismatch(value())) {
+ double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, currentDecimalPlaces)));
+ newValue = round(newValue * scale) / scale;
+ } else {
+ double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, baseDecimalPlaces)));
+ newValue = round((base + round((newValue - base) / step) * step) * scale) / scale;
+ }
+
+ return newValue;
+}
+
void HTMLInputElement::stepUp(int n, ExceptionCode& ec)
{
applyStep(n, RejectAny, ec);
Modified: trunk/Source/WebCore/html/HTMLInputElement.h (91548 => 91549)
--- trunk/Source/WebCore/html/HTMLInputElement.h 2011-07-22 03:12:43 UTC (rev 91548)
+++ trunk/Source/WebCore/html/HTMLInputElement.h 2011-07-22 03:27:30 UTC (rev 91549)
@@ -321,6 +321,7 @@
// Helper for stepUp()/stepDown(). Adds step value * count to the current value.
void applyStep(double count, AnyStepHandling, ExceptionCode&);
+ double alignValueForStep(double value, double step, unsigned currentDecimalPlaces, unsigned stepDecimalPlaces);
#if ENABLE(DATALIST)
HTMLDataListElement* dataList() const;