[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

eric at webkit.org eric at webkit.org
Wed Apr 7 23:48:17 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit 8b47b6c78c503b8a46de9531d63f3f5759f62f3b
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Nov 19 01:48:52 2009 +0000

    2009-11-18  Kent Tamura  <tkent at chromium.org>
    
            Reviewed by Darin Adler.
    
            Add tests for ValidityState.stepMismatch.
            https://bugs.webkit.org/show_bug.cgi?id=31331
    
            * fast/forms/ValidityState-stepMismatch-number-expected.txt: Added.
            * fast/forms/ValidityState-stepMismatch-number.html: Added.
            * fast/forms/ValidityState-stepMismatch-range-expected.txt: Added.
            * fast/forms/ValidityState-stepMismatch-range.html: Added.
            * fast/forms/ValidityState-stepMismatch-unsupported-expected.txt: Added.
            * fast/forms/ValidityState-stepMismatch-unsupported.html: Added.
            * fast/forms/input-step-expected.txt: Added.
            * fast/forms/input-step.html: Added.
            * fast/forms/script-tests/ValidityState-stepMismatch-number.js: Added.
            * fast/forms/script-tests/ValidityState-stepMismatch-range.js: Added.
            * fast/forms/script-tests/ValidityState-stepMismatch-unsupported.js: Added.
            * fast/forms/script-tests/input-step.js: Added.
    2009-11-18  Kent Tamura  <tkent at chromium.org>
    
            Reviewed by Darin Adler.
    
            Support for step attribute and ValidityStae.stepMismatch for
            type=number and range.  stepMismatch will be false if the
            difference between the current value and a multiple of the step
            value is very small.
    
            Change the behavior of RenderSlider so that it always has a value
            rounded to the step attribute value.
    
            https://bugs.webkit.org/show_bug.cgi?id=31331
    
            Tests: fast/forms/ValidityState-stepMismatch-number.html
                   fast/forms/ValidityState-stepMismatch-range.html
                   fast/forms/ValidityState-stepMismatch-unsupported.html
                   fast/forms/input-step.html
    
            * html/HTMLAttributeNames.in: Add "step".
            * html/HTMLInputElement.cpp:
            (WebCore::HTMLInputElement::stepMismatch):
            (WebCore::HTMLInputElement::getStepParameters):
            (WebCore::HTMLInputElement::getAllowedValueStep):
            * html/HTMLInputElement.h:
            * html/HTMLInputElement.idl: Add "step".
            * html/ValidityState.cpp:
            (WebCore::ValidityState::stepMismatch): Forward to HTMLInputElement::stepMismatch().
            * html/ValidityState.h:
            * rendering/RenderSlider.cpp:
            (WebCore::SliderRange::SliderRange):
            (WebCore::SliderRange::clampValue):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51159 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 5aea16e..731d96c 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,23 @@
+2009-11-18  Kent Tamura  <tkent at chromium.org>
+
+        Reviewed by Darin Adler.
+
+        Add tests for ValidityState.stepMismatch.
+        https://bugs.webkit.org/show_bug.cgi?id=31331
+
+        * fast/forms/ValidityState-stepMismatch-number-expected.txt: Added.
+        * fast/forms/ValidityState-stepMismatch-number.html: Added.
+        * fast/forms/ValidityState-stepMismatch-range-expected.txt: Added.
+        * fast/forms/ValidityState-stepMismatch-range.html: Added.
+        * fast/forms/ValidityState-stepMismatch-unsupported-expected.txt: Added.
+        * fast/forms/ValidityState-stepMismatch-unsupported.html: Added.
+        * fast/forms/input-step-expected.txt: Added.
+        * fast/forms/input-step.html: Added.
+        * fast/forms/script-tests/ValidityState-stepMismatch-number.js: Added.
+        * fast/forms/script-tests/ValidityState-stepMismatch-range.js: Added.
+        * fast/forms/script-tests/ValidityState-stepMismatch-unsupported.js: Added.
+        * fast/forms/script-tests/input-step.js: Added.
+
 2009-11-18  Shu Chang  <Chang.Shu at nokia.com>
 
         Reviewed by Eric Seidel.
diff --git a/LayoutTests/fast/forms/ValidityState-stepMismatch-number-expected.txt b/LayoutTests/fast/forms/ValidityState-stepMismatch-number-expected.txt
new file mode 100644
index 0000000..c6903c2
--- /dev/null
+++ b/LayoutTests/fast/forms/ValidityState-stepMismatch-number-expected.txt
@@ -0,0 +1,27 @@
+Check stepMismatch results for type=number.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is true
+PASS input.validity.stepMismatch is true
+PASS input.validity.stepMismatch is true
+PASS input.value is "5"
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is true
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is true
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/ValidityState-stepMismatch-number.html b/LayoutTests/fast/forms/ValidityState-stepMismatch-number.html
new file mode 100644
index 0000000..73967bf
--- /dev/null
+++ b/LayoutTests/fast/forms/ValidityState-stepMismatch-number.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/ValidityState-stepMismatch-number.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/ValidityState-stepMismatch-range-expected.txt b/LayoutTests/fast/forms/ValidityState-stepMismatch-range-expected.txt
new file mode 100644
index 0000000..641e5a7
--- /dev/null
+++ b/LayoutTests/fast/forms/ValidityState-stepMismatch-range-expected.txt
@@ -0,0 +1,27 @@
+Check stepMismatch results for type=range.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.value is "3"
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/ValidityState-stepMismatch-range.html b/LayoutTests/fast/forms/ValidityState-stepMismatch-range.html
new file mode 100644
index 0000000..4f8f785
--- /dev/null
+++ b/LayoutTests/fast/forms/ValidityState-stepMismatch-range.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/ValidityState-stepMismatch-range.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/ValidityState-stepMismatch-unsupported-expected.txt b/LayoutTests/fast/forms/ValidityState-stepMismatch-unsupported-expected.txt
new file mode 100644
index 0000000..63d50f4
--- /dev/null
+++ b/LayoutTests/fast/forms/ValidityState-stepMismatch-unsupported-expected.txt
@@ -0,0 +1,25 @@
+Check stepMismatch results for types which does not support for step.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS input.validity.stepMismatch is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/ValidityState-stepMismatch-unsupported.html b/LayoutTests/fast/forms/ValidityState-stepMismatch-unsupported.html
new file mode 100644
index 0000000..3f9c4e1
--- /dev/null
+++ b/LayoutTests/fast/forms/ValidityState-stepMismatch-unsupported.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/ValidityState-stepMismatch-unsupported.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/input-step-expected.txt b/LayoutTests/fast/forms/input-step-expected.txt
new file mode 100644
index 0000000..fa1b6ca
--- /dev/null
+++ b/LayoutTests/fast/forms/input-step-expected.txt
@@ -0,0 +1,21 @@
+Test the behavior of step attribute and step DOM property.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.step is ""
+PASS input.getAttribute("step") is "foo"
+PASS input.step is "bar"
+PASS input.step is "null"
+PASS input.getAttribute("step") is "null"
+PASS input.step is "null"
+PASS input.step is "undefined"
+PASS input.getAttribute("step") is "undefined"
+PASS input.step is "undefined"
+PASS input.step is "256"
+PASS input.getAttribute("step") is "256"
+PASS input.step is "256"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/input-step.html b/LayoutTests/fast/forms/input-step.html
new file mode 100644
index 0000000..37e3d49
--- /dev/null
+++ b/LayoutTests/fast/forms/input-step.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/input-step.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch-number.js b/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch-number.js
new file mode 100644
index 0000000..6f74448
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch-number.js
@@ -0,0 +1,69 @@
+description('Check stepMismatch results for type=number.');
+
+var input = document.createElement('input');
+input.type = 'number';
+
+// If the value is empty, it never mismatches.
+input.value = '';
+shouldBe('input.validity.stepMismatch', 'false');
+input.min = '0.1';
+input.step = '1.0';
+shouldBe('input.validity.stepMismatch', 'false');
+
+// Integers
+input.value = '1';
+input.min = '0';
+input.step = '2';
+shouldBe('input.validity.stepMismatch', 'true');
+input.value = '-3';
+input.min = '-4';
+input.step = '2';
+shouldBe('input.validity.stepMismatch', 'true');
+input.min = '0';
+input.max = '5';
+input.step = '3';
+input.value = '5';
+shouldBe('input.validity.stepMismatch', 'true');
+shouldBe('input.value', '"5"');
+// Invalid step attribute is ignored.
+input.value = '-3';
+input.min = '-4';
+input.max = '';
+input.step = '-2';
+shouldBe('input.validity.stepMismatch', 'false');
+input.step = null;
+shouldBe('input.validity.stepMismatch', 'false');
+input.step = undefined;
+shouldBe('input.validity.stepMismatch', 'false');
+// Huge numbers and small step; uncomparable
+input.value = '1.7976931348623157e+308';
+input.min = '';
+input.step = '3';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '1.7976931348623156e+308';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '1.7976931348623155e+308';
+shouldBe('input.validity.stepMismatch', 'false');
+// Huge numbers and huge step
+input.value = '1.60e+308';
+input.step = '0.20e+308';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '1.60e+308';
+input.step = '0.22e+308';
+shouldBe('input.validity.stepMismatch', 'true');
+
+// Fractional numbers
+input.value = '0.9';
+input.step = '0.1';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '0.9';
+input.step = '0.1000001';
+shouldBe('input.validity.stepMismatch', 'true');
+input.value = '0.9';
+input.step = '0.1000000000000001';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '1.0';
+input.step = '0.3333333333333333';
+shouldBe('input.validity.stepMismatch', 'false');
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch-range.js b/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch-range.js
new file mode 100644
index 0000000..3e59459
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch-range.js
@@ -0,0 +1,74 @@
+description('Check stepMismatch results for type=range.');
+
+var input = document.createElement('input');
+// Needs a renderer.
+document.body.appendChild(input);
+input.type = 'range';
+
+// The following test inputs are the same as ValidityState-stepMismatch-number.js,
+// but all expected results should be 'false'.
+
+// If the value is empty, it never mismatches.
+input.value = '';
+shouldBe('input.validity.stepMismatch', 'false');
+input.min = '0.1';
+input.step = '1.0';
+shouldBe('input.validity.stepMismatch', 'false');
+
+// Integers
+input.value = '1';
+input.min = '0';
+input.step = '2';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '-3';
+input.min = '-4';
+input.step = '2';
+shouldBe('input.validity.stepMismatch', 'false');
+input.min = '0';
+input.max = '5';
+input.step = '3';
+input.value = '5';
+shouldBe('input.validity.stepMismatch', 'false');
+shouldBe('input.value', '"3"');
+// Invalid step attribute is ignored.
+input.value = '-3';
+input.min = '-4';
+input.max = '';
+input.step = '-2';
+shouldBe('input.validity.stepMismatch', 'false');
+input.step = null;
+shouldBe('input.validity.stepMismatch', 'false');
+input.step = undefined;
+shouldBe('input.validity.stepMismatch', 'false');
+// Huge numbers and small step; uncomparable
+input.value = '1.7976931348623157e+308';
+input.min = '';
+input.step = '3';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '1.7976931348623156e+308';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '1.7976931348623155e+308';
+shouldBe('input.validity.stepMismatch', 'false');
+// Huge numbers and huge step
+input.value = '1.60e+308';
+input.step = '0.20e+308';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '1.60e+308';
+input.step = '0.22e+308';
+shouldBe('input.validity.stepMismatch', 'false');
+
+// Fractional numbers
+input.value = '0.9';
+input.step = '0.1';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '0.9';
+input.step = '0.1000001';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '0.9';
+input.step = '0.1000000000000001';
+shouldBe('input.validity.stepMismatch', 'false');
+input.value = '1.0';
+input.step = '0.3333333333333333';
+shouldBe('input.validity.stepMismatch', 'false');
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch-unsupported.js b/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch-unsupported.js
new file mode 100644
index 0000000..2439ec6
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch-unsupported.js
@@ -0,0 +1,41 @@
+description('Check stepMismatch results for types which does not support for step.');
+
+var input = document.createElement('input');
+
+input.type = 'text';
+input.step = '3';
+input.value = '2';
+shouldBe('input.validity.stepMismatch', 'false');
+
+input.type = 'button';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'checkbox';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'color';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'email';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'hidden';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'image';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'khtml_isindex';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'passwd';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'radio';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'reset';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'search';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'submit';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'tel';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'url';
+shouldBe('input.validity.stepMismatch', 'false');
+input.type = 'file';
+shouldBe('input.validity.stepMismatch', 'false');
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/forms/script-tests/input-step.js b/LayoutTests/fast/forms/script-tests/input-step.js
new file mode 100644
index 0000000..216a009
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/input-step.js
@@ -0,0 +1,36 @@
+description('Test the behavior of step attribute and step DOM property.');
+
+var input = document.createElement('input');
+input.type = 'number';
+
+// No step attribute.
+shouldBe('input.step', '""');
+
+// Set an invalid step value.
+input.step = 'foo';
+shouldBe('input.getAttribute("step")', '"foo"');
+input.setAttribute('step', 'bar');
+shouldBe('input.step', '"bar"');
+
+// Null.
+input.step = null;
+shouldBe('input.step', '"null"');
+shouldBe('input.getAttribute("step")', '"null"');
+input.setAttribute('step', null);
+shouldBe('input.step', '"null"');
+
+// Undefined.
+input.step = undefined;
+shouldBe('input.step', '"undefined"');
+shouldBe('input.getAttribute("step")', '"undefined"');
+input.setAttribute('step', undefined);
+shouldBe('input.step', '"undefined"');
+
+// Non-string.
+input.step = 256;
+shouldBe('input.step', '"256"');
+shouldBe('input.getAttribute("step")', '"256"');
+input.setAttribute('step', 256);
+shouldBe('input.step', '"256"');
+
+var successfullyParsed = true;
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 992ad35..84b6200 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,36 @@
+2009-11-18  Kent Tamura  <tkent at chromium.org>
+
+        Reviewed by Darin Adler.
+
+        Support for step attribute and ValidityStae.stepMismatch for
+        type=number and range.  stepMismatch will be false if the
+        difference between the current value and a multiple of the step
+        value is very small.
+
+        Change the behavior of RenderSlider so that it always has a value
+        rounded to the step attribute value.
+
+        https://bugs.webkit.org/show_bug.cgi?id=31331
+
+        Tests: fast/forms/ValidityState-stepMismatch-number.html
+               fast/forms/ValidityState-stepMismatch-range.html
+               fast/forms/ValidityState-stepMismatch-unsupported.html
+               fast/forms/input-step.html
+
+        * html/HTMLAttributeNames.in: Add "step".
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::stepMismatch):
+        (WebCore::HTMLInputElement::getStepParameters):
+        (WebCore::HTMLInputElement::getAllowedValueStep):
+        * html/HTMLInputElement.h:
+        * html/HTMLInputElement.idl: Add "step".
+        * html/ValidityState.cpp:
+        (WebCore::ValidityState::stepMismatch): Forward to HTMLInputElement::stepMismatch().
+        * html/ValidityState.h:
+        * rendering/RenderSlider.cpp:
+        (WebCore::SliderRange::SliderRange):
+        (WebCore::SliderRange::clampValue):
+
 2009-11-18  Dmitry Titov  <dimich at chromium.org>
 
         Reviewed by Darin Adler.
diff --git a/WebCore/html/HTMLAttributeNames.in b/WebCore/html/HTMLAttributeNames.in
index 7fef3c2..a4aaabc 100644
--- a/WebCore/html/HTMLAttributeNames.in
+++ b/WebCore/html/HTMLAttributeNames.in
@@ -235,6 +235,7 @@ spellcheck
 src
 standby
 start
+step
 style
 summary
 tabindex
diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp
index 7e03ddd..81a3d72 100644
--- a/WebCore/html/HTMLInputElement.cpp
+++ b/WebCore/html/HTMLInputElement.cpp
@@ -73,6 +73,10 @@ using namespace HTMLNames;
 
 const int maxSavedResults = 256;
 
+// Constant values for getAllowedValueStep().
+static const double numberDefaultStep = 1.0;
+static const double numberStepScaleFactor = 1.0;
+
 HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f)
     : HTMLTextFormControlElement(tagName, doc, f)
     , m_xPos(0)
@@ -308,6 +312,100 @@ double HTMLInputElement::rangeMaximum() const
     return max;
 }
 
+bool HTMLInputElement::stepMismatch() const
+{
+    double step;
+    if (!getAllowedValueStep(&step))
+        return false;
+    if (inputType() == NUMBER) {
+        double doubleValue;
+        if (!formStringToDouble(value(), &doubleValue))
+            return false;
+        double stepBase = 0.0;
+        formStringToDouble(getAttribute(minAttr), &stepBase);
+        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, DBL_MANT_DIG) > step)
+            return false;
+        double remainder = fmod(doubleValue, step);
+        // Accepts errors in lower 7-bit.
+        double acceptableError = step / pow(2, DBL_MANT_DIG - 7);
+        return acceptableError < remainder && remainder < (step - acceptableError);
+    }
+    // Non-RANGE types should be rejected by getAllowedValueStep().
+    ASSERT(inputType() == RANGE);
+    // stepMismatch doesn't occur for RANGE. RenderSlider guarantees the
+    // value matches to step.
+    return false;
+}
+
+bool HTMLInputElement::getStepParameters(double* defaultStep, double* stepScaleFactor) const
+{
+    ASSERT(defaultStep);
+    ASSERT(stepScaleFactor);
+    switch (inputType()) {
+    case NUMBER:
+    case RANGE:
+        *defaultStep = numberDefaultStep;
+        *stepScaleFactor = numberStepScaleFactor;
+        return true;
+    case DATE:
+    case DATETIME:
+    case DATETIMELOCAL:
+    case MONTH:
+    case TIME:
+    case WEEK:
+        // FIXME: Implement for these types.
+        return false;
+    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;
+}
+
+bool HTMLInputElement::getAllowedValueStep(double* step) const
+{
+    ASSERT(step);
+    double defaultStep;
+    double stepScaleFactor;
+    if (!getStepParameters(&defaultStep, &stepScaleFactor))
+        return false;
+    const AtomicString& stepString = getAttribute(stepAttr);
+    if (stepString.isEmpty()) {
+        *step = defaultStep * stepScaleFactor;
+        return true;
+    }
+    if (equalIgnoringCase(stepString, "any"))
+        return false;
+    double parsed;
+    if (!formStringToDouble(stepString, &parsed) || parsed <= 0.0) {
+        *step = defaultStep * stepScaleFactor;
+        return true;
+    }
+    *step = parsed * stepScaleFactor;
+    return true;
+}
+
 static inline CheckedRadioButtons& checkedRadioButtons(const HTMLInputElement *element)
 {
     if (HTMLFormElement* form = element->form())
diff --git a/WebCore/html/HTMLInputElement.h b/WebCore/html/HTMLInputElement.h
index 71d21d6..ff06f15 100644
--- a/WebCore/html/HTMLInputElement.h
+++ b/WebCore/html/HTMLInputElement.h
@@ -110,6 +110,11 @@ public:
     // Returns the maximum value for type=range.  Don't call this for other types.
     // This always returns a value which is <= rangeMinimum().
     double rangeMaximum() const;
+    // Sets the "allowed value step" defined in the HTML spec to the specified double pointer.
+    // Returns false if there is no "allowed value step."
+    bool getAllowedValueStep(double*) const;
+    // For ValidityState.
+    bool stepMismatch() const;
 
     bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; }
     virtual bool isRadioButton() const { return m_type == RADIO; }
@@ -265,7 +270,8 @@ private:
     virtual bool isRequiredFormControl() const;
 
     PassRefPtr<HTMLFormElement> createTemporaryFormForIsIndex();
-
+    // Helper for getAllowedValueStep();
+    bool getStepParameters(double* defaultStep, double* stepScaleFactor) const;
 #if ENABLE(DATALIST)
     HTMLDataListElement* dataList() const;
 #endif
diff --git a/WebCore/html/HTMLInputElement.idl b/WebCore/html/HTMLInputElement.idl
index 59248f4..b45d190 100644
--- a/WebCore/html/HTMLInputElement.idl
+++ b/WebCore/html/HTMLInputElement.idl
@@ -63,12 +63,14 @@ module html {
                  attribute unsigned long   size; // Changed string -> long as part of DOM level 2
 #endif
                  attribute [ConvertNullToNullString] DOMString src;
+                 attribute [Reflect] DOMString step;
                  attribute [ConvertNullToNullString, JSCCustomGetter] DOMString type; // readonly dropped as part of DOM level 2
                  attribute [ConvertNullToNullString] DOMString useMap;
                  attribute [ConvertNullToNullString] DOMString value;
 #if defined(ENABLE_DATALIST) && ENABLE_DATALIST
         readonly attribute HTMLOptionElement selectedOption;
 #endif
+
         readonly attribute boolean         willValidate;
         boolean            checkValidity();
         void               setCustomValidity(in [ConvertUndefinedOrNullToNullString] DOMString error);
diff --git a/WebCore/html/ValidityState.cpp b/WebCore/html/ValidityState.cpp
index 6b0a0b4..2c6e7a5 100644
--- a/WebCore/html/ValidityState.cpp
+++ b/WebCore/html/ValidityState.cpp
@@ -93,6 +93,13 @@ bool ValidityState::rangeOverflow()
     return static_cast<HTMLInputElement*>(control())->rangeOverflow();
 }
 
+bool ValidityState::stepMismatch()
+{
+    if (!control()->hasTagName(inputTag))
+        return false;
+    return static_cast<HTMLInputElement*>(control())->stepMismatch();
+}
+
 bool ValidityState::valid()
 {
     bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() ||
diff --git a/WebCore/html/ValidityState.h b/WebCore/html/ValidityState.h
index 1dee306..4e240ed 100644
--- a/WebCore/html/ValidityState.h
+++ b/WebCore/html/ValidityState.h
@@ -46,7 +46,7 @@ namespace WebCore {
         bool tooLong() { return control()->tooLong(); }
         bool rangeUnderflow();
         bool rangeOverflow();
-        bool stepMismatch() { return false; }
+        bool stepMismatch();
         bool customError() { return !m_customErrorMessage.isEmpty(); }
         bool valid();
 
diff --git a/WebCore/rendering/RenderSlider.cpp b/WebCore/rendering/RenderSlider.cpp
index 6448fb9..e18b433 100644
--- a/WebCore/rendering/RenderSlider.cpp
+++ b/WebCore/rendering/RenderSlider.cpp
@@ -48,7 +48,8 @@ static const int defaultTrackLength = 129;
 // FIXME: The SliderRange class and functions are entirely based on the DOM,
 // and could be put with HTMLInputElement (possibly with a new name) instead of here.
 struct SliderRange {
-    bool isIntegral;
+    bool hasStep;
+    double step;
     double minimum;
     double maximum;  // maximum must be >= minimum.
 
@@ -75,10 +76,11 @@ struct SliderRange {
 
 SliderRange::SliderRange(HTMLInputElement* element)
 {
-    // FIXME: What's the right way to handle an integral range with non-integral minimum and maximum?
-    // Currently values are guaranteed to be integral but could be outside the range in that case.
-
-    isIntegral = !equalIgnoringCase(element->getAttribute(precisionAttr), "float");
+    if (element->hasAttribute(precisionAttr)) {
+        step = 1.0;
+        hasStep = !equalIgnoringCase(element->getAttribute(precisionAttr), "float");
+    } else
+        hasStep = element->getAllowedValueStep(&step);
 
     maximum = element->rangeMaximum();
     minimum = element->rangeMinimum();
@@ -87,7 +89,15 @@ SliderRange::SliderRange(HTMLInputElement* element)
 double SliderRange::clampValue(double value)
 {
     double clampedValue = max(minimum, min(value, maximum));
-    return isIntegral ? round(clampedValue) : clampedValue;
+    if (!hasStep)
+        return clampedValue;
+    // Rounds clampedValue to minimum + N * step.
+    clampedValue = minimum + round((clampedValue - minimum) / step) * step;
+    if (clampedValue > maximum)
+       clampedValue -= step;
+    ASSERT(clampedValue >= minimum);
+    ASSERT(clampedValue <= maximum);
+    return clampedValue;
 }
 
 double SliderRange::valueFromElement(HTMLInputElement* element, bool* wasClamped)

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list