[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 13:16:37 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 15e8a00367047a152fda9584448bd64fad44b222
Author: tkent at chromium.org <tkent at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Sep 10 04:49:09 2010 +0000

    2010-09-09  Kent Tamura  <tkent at chromium.org>
    
            Reviewed by Dimitri Glazkov.
    
            <input type=number> should not have an invalid number as its value
            https://bugs.webkit.org/show_bug.cgi?id=43973
    
            * fast/forms/ValidityState-rangeOverflow-expected.txt:
            * fast/forms/ValidityState-rangeUnderflow-expected.txt:
            * fast/forms/ValidityState-typeMismatch-number-expected.txt:
            * fast/forms/input-number-commit-valid-only-expected.txt: Added.
            * fast/forms/input-number-commit-valid-only.html: Added.
            * fast/forms/script-tests/ValidityState-typeMismatch-number.js:
            * fast/forms/script-tests/input-number-commit-valid-only.js: Added.
    2010-09-09  Kent Tamura  <tkent at chromium.org>
    
            Reviewed by Dimitri Glazkov.
    
            <input type=number> should not have an invalid number as its value
            https://bugs.webkit.org/show_bug.cgi?id=43973
    
            This change implements the value sanitization algorithm for
            type=number, and remove validity.typeMismatch support for
            type=number in order to improve HTML5 conformance.
    
            HTMLInputElement::value for type=number always has a valid number
            string or an empty string. However, the input field for it, a
            RenderTextControlSingleLine, can have a non-number string. For
            example, '-' is a non-number string, but a user needs to type
            '-'. So, the string in the input field has never been committed to
            HTMLInputElement until the string becomes a valid number string.
    
            This change is also a preparation of supporting localized
            numbers. A localized string in the input field would not be
            matched with HTMLInputElement::value.
    
            Test: fast/forms/input-number-commit-valid-only.html
    
            * dom/InputElement.h: Add isCommittableValue()
            * html/HTMLInputElement.cpp:
            (WebCore::HTMLInputElement::handleBlurEvent):
             Set formControlValueMatchesRenderer false to clean an invalid value in the renderer.
            (WebCore::HTMLInputElement::isCommittableValue):
            (WebCore::HTMLInputElement::sanitizeValue):
            * html/HTMLInputElement.h:
            * html/ValidityState.cpp:
            (WebCore::ValidityState::typeMismatch): Always returns false for type=number.
            * rendering/RenderTextControlSingleLine.cpp:
            (WebCore::RenderTextControlSingleLine::subtreeHasChanged):
            * wml/WMLInputElement.h:
            (WebCore::WMLInputElement::isCommittableValue):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@67164 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 02af316..1e71be0 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,18 @@
+2010-09-09  Kent Tamura  <tkent at chromium.org>
+
+        Reviewed by Dimitri Glazkov.
+
+        <input type=number> should not have an invalid number as its value
+        https://bugs.webkit.org/show_bug.cgi?id=43973
+
+        * fast/forms/ValidityState-rangeOverflow-expected.txt:
+        * fast/forms/ValidityState-rangeUnderflow-expected.txt:
+        * fast/forms/ValidityState-typeMismatch-number-expected.txt:
+        * fast/forms/input-number-commit-valid-only-expected.txt: Added.
+        * fast/forms/input-number-commit-valid-only.html: Added.
+        * fast/forms/script-tests/ValidityState-typeMismatch-number.js:
+        * fast/forms/script-tests/input-number-commit-valid-only.js: Added.
+
 2010-09-09  Tony Gentilcore  <tonyg at chromium.org>
 
         Reviewed by Adam Barth.
diff --git a/LayoutTests/fast/forms/ValidityState-rangeOverflow-expected.txt b/LayoutTests/fast/forms/ValidityState-rangeOverflow-expected.txt
index b77aa59..57fc3c2 100644
--- a/LayoutTests/fast/forms/ValidityState-rangeOverflow-expected.txt
+++ b/LayoutTests/fast/forms/ValidityState-rangeOverflow-expected.txt
@@ -63,7 +63,7 @@ PASS The value "99" doesn't overflow the maximum value "100".
 PASS The value "-101" doesn't overflow the maximum value "-100".
 PASS The value "99" doesn't overflow the maximum value "1E+2".
 PASS The value "0.99" doesn't overflow the maximum value "1.00".
-PASS The value "abc" doesn't overflow the maximum value "100".
+PASS The value "" doesn't overflow the maximum value "100".
 PASS The value "" doesn't overflow the maximum value "-1".
 PASS The value "101" doesn't overflow the maximum value "".
 PASS The value "101" doesn't overflow the maximum value "xxx".
diff --git a/LayoutTests/fast/forms/ValidityState-rangeUnderflow-expected.txt b/LayoutTests/fast/forms/ValidityState-rangeUnderflow-expected.txt
index 983275f..64d9d8c 100644
--- a/LayoutTests/fast/forms/ValidityState-rangeUnderflow-expected.txt
+++ b/LayoutTests/fast/forms/ValidityState-rangeUnderflow-expected.txt
@@ -63,7 +63,7 @@ PASS The value "101" doesn't underflow the minimum value "100".
 PASS The value "-99" doesn't underflow the minimum value "-100".
 PASS The value "101" doesn't underflow the minimum value "1E+2".
 PASS The value "1.01" doesn't underflow the minimum value "1.00".
-PASS The value "abc" doesn't underflow the minimum value "100".
+PASS The value "" doesn't underflow the minimum value "100".
 PASS The value "" doesn't underflow the minimum value "1".
 PASS The value "-1" doesn't underflow the minimum value "".
 PASS The value "-1" doesn't underflow the minimum value "xxx".
diff --git a/LayoutTests/fast/forms/ValidityState-typeMismatch-number-expected.txt b/LayoutTests/fast/forms/ValidityState-typeMismatch-number-expected.txt
index d6fac6f..af3cf5e 100644
--- a/LayoutTests/fast/forms/ValidityState-typeMismatch-number-expected.txt
+++ b/LayoutTests/fast/forms/ValidityState-typeMismatch-number-expected.txt
@@ -3,34 +3,34 @@ This test aims to check for typeMismatch flag with type=number input fields
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS 0 is a correct valid number.
-PASS 10 is a correct valid number.
-PASS 01 is a correct valid number.
-PASS -0 is a correct valid number.
-PASS -1.2 is a correct valid number.
-PASS 1.2E10 is a correct valid number.
-PASS 1.2E-10 is a correct valid number.
-PASS 1.2E+10 is a correct valid number.
-PASS 12345678901234567890123456789012345678901234567890 is a correct valid number.
-PASS 0.12345678901234567890123456789012345678901234567890 is a correct valid number.
-PASS abc is a correct invalid number.
-PASS 0xff is a correct invalid number.
-PASS +1 is a correct invalid number.
-PASS  10 is a correct invalid number.
-PASS 10  is a correct invalid number.
-PASS 1,2 is a correct invalid number.
-PASS .2 is a correct invalid number.
-PASS 1E is a correct invalid number.
-PASS NaN is a correct invalid number.
-PASS nan is a correct invalid number.
-PASS Inf is a correct invalid number.
-PASS inf is a correct invalid number.
-PASS Infinity is a correct invalid number.
-PASS infinity is a correct invalid number.
-PASS  is a correct valid number.
-PASS 1.2E65535 is a correct invalid number.
-PASS 1. is a correct valid number.
-PASS 1.2e10 is a correct valid number.
+PASS "0" is a valid number.
+PASS "10" is a valid number.
+PASS "01" is a valid number.
+PASS "-0" is a valid number.
+PASS "-1.2" is a valid number.
+PASS "1.2E10" is a valid number.
+PASS "1.2E-10" is a valid number.
+PASS "1.2E+10" is a valid number.
+PASS "12345678901234567890123456789012345678901234567890" is a valid number.
+PASS "0.12345678901234567890123456789012345678901234567890" is a valid number.
+PASS "abc" was sanitized to "".
+PASS "0xff" was sanitized to "".
+PASS "+1" was sanitized to "".
+PASS " 10" was sanitized to "".
+PASS "10 " was sanitized to "".
+PASS "1,2" was sanitized to "".
+PASS ".2" was sanitized to "".
+PASS "1E" was sanitized to "".
+PASS "NaN" was sanitized to "".
+PASS "nan" was sanitized to "".
+PASS "Inf" was sanitized to "".
+PASS "inf" was sanitized to "".
+PASS "Infinity" was sanitized to "".
+PASS "infinity" was sanitized to "".
+PASS "" is a valid number.
+PASS "1.2E65535" was sanitized to "".
+PASS "1." is a valid number.
+PASS "1.2e10" is a valid number.
 PASS successfullyParsed is true
 
 TEST COMPLETE
diff --git a/LayoutTests/fast/forms/input-number-commit-valid-only-expected.txt b/LayoutTests/fast/forms/input-number-commit-valid-only-expected.txt
new file mode 100644
index 0000000..9395441
--- /dev/null
+++ b/LayoutTests/fast/forms/input-number-commit-valid-only-expected.txt
@@ -0,0 +1,12 @@
+Type=number field should not accept invalid numbers though a user can type such strings
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.value is "512"
+PASS input.value is "512"
+PASS input.value is "512"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/input-number-commit-valid-only.html b/LayoutTests/fast/forms/input-number-commit-valid-only.html
new file mode 100644
index 0000000..c1e09fc
--- /dev/null
+++ b/LayoutTests/fast/forms/input-number-commit-valid-only.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-number-commit-valid-only.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/script-tests/ValidityState-typeMismatch-number.js b/LayoutTests/fast/forms/script-tests/ValidityState-typeMismatch-number.js
index 2e8a086..8b80c0c 100644
--- a/LayoutTests/fast/forms/script-tests/ValidityState-typeMismatch-number.js
+++ b/LayoutTests/fast/forms/script-tests/ValidityState-typeMismatch-number.js
@@ -3,56 +3,66 @@ description('This test aims to check for typeMismatch flag with type=number inpu
 var i = document.createElement('input');
 i.type = 'number';
 
-function check(value, mismatchExpected)
+function check(value)
 {
     i.value = value;
-    var actual = i.validity.typeMismatch;
-    var didPass = actual == mismatchExpected;
-    var resultText = value + ' is ' + (didPass ? 'a correct ' : 'an incorrect ') + (actual ? 'invalid' : 'valid') + ' number.';
-    if (didPass)
+    var mismatch = i.validity.typeMismatch;
+    var resultText = '"' + value + '" is ' + (mismatch ? 'an invalid' : 'a valid') + ' number.';
+    if (!mismatch)
         testPassed(resultText);
     else
         testFailed(resultText);
 }
 
+function checkSanitization(value, expectedValue)
+{
+    i.value = value;
+    if (i.validity.typeMismatch) {
+        testFailed('"' + value + '" made typeMismatch true.');
+    } else if (i.value != expectedValue) {
+        testFailed('"' + value + '" was sanitized to "' + i.value + '". It should be ' + expectedValue);
+    } else {
+        testPassed('"' + value + '" was sanitized to "' + i.value + '".');
+    }
+}
+
 // Valid values
-check('0', false);
-check('10', false);
-check('01', false);
-check('-0', false);
-check('-1.2', false);
-check('1.2E10', false);
-check('1.2E-10', false);
-check('1.2E+10', false);
-check('12345678901234567890123456789012345678901234567890', false);
-check('0.12345678901234567890123456789012345678901234567890', false);
+check('0');
+check('10');
+check('01');
+check('-0');
+check('-1.2');
+check('1.2E10');
+check('1.2E-10');
+check('1.2E+10');
+check('12345678901234567890123456789012345678901234567890');
+check('0.12345678901234567890123456789012345678901234567890');
 
 // Invalid values
-check('abc', true);
-check('0xff', true);
-
-check('+1', true);
-check(' 10', true);
-check('10 ', true);
-check('1,2', true);
-check('.2', true);
-check('1E', true);
-check('NaN', true);
-check('nan', true);
-check('Inf', true);
-check('inf', true);
-check('Infinity', true);
-check('infinity', true);
+checkSanitization('abc', '');
+checkSanitization('0xff', '');
+
+checkSanitization('+1', '');
+checkSanitization(' 10', '');
+checkSanitization('10 ', '');
+checkSanitization('1,2', '');
+checkSanitization('.2', '');
+checkSanitization('1E', '');
+checkSanitization('NaN', '');
+checkSanitization('nan', '');
+checkSanitization('Inf', '');
+checkSanitization('inf', '');
+checkSanitization('Infinity', '');
+checkSanitization('infinity', '');
 
 // Assume empty string as valid.
-check('', false);
+check('');
 
-// The spec allows, but our implementation doesn't
 // Huge exponent.
-check('1.2E65535', true);
+checkSanitization('1.2E65535', '');
 
 // The spec doesn't allow, but our implementation does.
-check('1.', false);
-check('1.2e10', false);
+check('1.');
+check('1.2e10');
 
 var successfullyParsed = true;
diff --git a/LayoutTests/fast/forms/script-tests/input-number-commit-valid-only.js b/LayoutTests/fast/forms/script-tests/input-number-commit-valid-only.js
new file mode 100644
index 0000000..df460aa
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/input-number-commit-valid-only.js
@@ -0,0 +1,24 @@
+description('Type=number field should not accept invalid numbers though a user can type such strings');
+
+var parent = document.createElement('div');
+document.body.appendChild(parent);
+parent.innerHTML = '<input type=number id=number value=256>';
+
+var input = document.getElementById('number');
+input.focus();
+document.execCommand('SelectAll', false, null);
+document.execCommand('InsertText', false, '512');
+shouldBe('input.value', '"512"');
+
+document.execCommand('SelectAll', false, null);
+document.execCommand('InsertText', false, '+++');
+input.blur();
+shouldBe('input.value', '"512"');
+
+input.focus();
+document.execCommand('SelectAll', false, null);
+document.execCommand('InsertText', false, '');
+input.blur();
+shouldBe('input.value', '"512"');
+
+var successfullyParsed = true;
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 6b605d7..8e4b42c 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,41 @@
+2010-09-09  Kent Tamura  <tkent at chromium.org>
+
+        Reviewed by Dimitri Glazkov.
+
+        <input type=number> should not have an invalid number as its value
+        https://bugs.webkit.org/show_bug.cgi?id=43973
+
+        This change implements the value sanitization algorithm for
+        type=number, and remove validity.typeMismatch support for
+        type=number in order to improve HTML5 conformance.
+
+        HTMLInputElement::value for type=number always has a valid number
+        string or an empty string. However, the input field for it, a
+        RenderTextControlSingleLine, can have a non-number string. For
+        example, '-' is a non-number string, but a user needs to type
+        '-'. So, the string in the input field has never been committed to
+        HTMLInputElement until the string becomes a valid number string.
+
+        This change is also a preparation of supporting localized
+        numbers. A localized string in the input field would not be
+        matched with HTMLInputElement::value.
+
+        Test: fast/forms/input-number-commit-valid-only.html
+
+        * dom/InputElement.h: Add isCommittableValue()
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::handleBlurEvent):
+         Set formControlValueMatchesRenderer false to clean an invalid value in the renderer.
+        (WebCore::HTMLInputElement::isCommittableValue):
+        (WebCore::HTMLInputElement::sanitizeValue):
+        * html/HTMLInputElement.h:
+        * html/ValidityState.cpp:
+        (WebCore::ValidityState::typeMismatch): Always returns false for type=number.
+        * rendering/RenderTextControlSingleLine.cpp:
+        (WebCore::RenderTextControlSingleLine::subtreeHasChanged):
+        * wml/WMLInputElement.h:
+        (WebCore::WMLInputElement::isCommittableValue):
+
 2010-09-09  Tony Gentilcore  <tonyg at chromium.org>
 
         Reviewed by Adam Barth.
diff --git a/WebCore/dom/InputElement.h b/WebCore/dom/InputElement.h
index 56fc99d..d5ce212 100644
--- a/WebCore/dom/InputElement.h
+++ b/WebCore/dom/InputElement.h
@@ -60,6 +60,8 @@ public:
     virtual void setValue(const String&, bool sendChangeEvent = false) = 0;
     virtual void setValueForUser(const String&) = 0;
 
+    // Returns true if the specified string can be set as the value of InputElement.
+    virtual bool isAcceptableValue(const String&) const = 0;
     virtual String sanitizeValue(const String&) const = 0;
     virtual void setValueFromRenderer(const String&) = 0;
 
diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp
index 4ae68cc..f9cf522 100644
--- a/WebCore/html/HTMLInputElement.cpp
+++ b/WebCore/html/HTMLInputElement.cpp
@@ -260,7 +260,8 @@ bool HTMLInputElement::typeMismatch(const String& value) const
     case COLOR:
         return !isValidColorString(value);
     case NUMBER:
-        return !parseToDoubleForNumberType(value, 0);
+        ASSERT(parseToDoubleForNumberType(value, 0));
+        return false;
     case URL:
         return !KURL(KURL(), value).isValid();
     case EMAIL: {
@@ -827,6 +828,8 @@ void HTMLInputElement::handleFocusEvent()
 
 void HTMLInputElement::handleBlurEvent()
 {
+    // Reset the renderer value, which might be unmatched with the element value.
+    setFormControlValueMatchesRenderer(false);
     InputElement::dispatchBlurEvent(this, this);
 }
 
@@ -2664,8 +2667,18 @@ FileList* HTMLInputElement::files()
     return m_fileList.get();
 }
 
+bool HTMLInputElement::isAcceptableValue(const String& proposedValue) const
+{
+    if (inputType() != NUMBER)
+        return true;
+    return proposedValue.isEmpty() || parseToDoubleForNumberType(proposedValue, 0);
+}
+
 String HTMLInputElement::sanitizeValue(const String& proposedValue) const
 {
+    if (inputType() == NUMBER)
+        return parseToDoubleForNumberType(proposedValue, 0) ? proposedValue : String();
+
     if (isTextField())
         return InputElement::sanitizeValueForTextField(this, proposedValue);
 
diff --git a/WebCore/html/HTMLInputElement.h b/WebCore/html/HTMLInputElement.h
index 657b468..4de121d 100644
--- a/WebCore/html/HTMLInputElement.h
+++ b/WebCore/html/HTMLInputElement.h
@@ -281,6 +281,7 @@ private:
 
     virtual void cacheSelection(int start, int end);
 
+    virtual bool isAcceptableValue(const String&) const;
     virtual String sanitizeValue(const String&) const;
 
     virtual void documentDidBecomeActive();
diff --git a/WebCore/rendering/RenderTextControlSingleLine.cpp b/WebCore/rendering/RenderTextControlSingleLine.cpp
index b22a799..c9d6d43 100644
--- a/WebCore/rendering/RenderTextControlSingleLine.cpp
+++ b/WebCore/rendering/RenderTextControlSingleLine.cpp
@@ -170,7 +170,9 @@ void RenderTextControlSingleLine::subtreeHasChanged()
     // InputElement::handleBeforeTextInsertedEvent() has already called
     // sanitizeUserInputValue().
     // sanitizeValue() is needed because IME input doesn't dispatch BeforeTextInsertedEvent.
-    input->setValueFromRenderer(input->sanitizeValue(text()));
+    String value = text();
+    if (input->isAcceptableValue(value))
+        input->setValueFromRenderer(input->sanitizeValue(value));
 
     if (m_cancelButton)
         updateCancelButtonVisibility();
diff --git a/WebCore/wml/WMLInputElement.h b/WebCore/wml/WMLInputElement.h
index 70d85e9..df7f497 100644
--- a/WebCore/wml/WMLInputElement.h
+++ b/WebCore/wml/WMLInputElement.h
@@ -82,6 +82,7 @@ public:
     virtual void defaultEventHandler(Event*);
     virtual void cacheSelection(int start, int end);
 
+    virtual bool isAcceptableValue(const String&) const { return true; }
     virtual String sanitizeValue(const String& proposedValue) const { return constrainValue(proposedValue); }
 
     virtual void documentDidBecomeActive();

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list