[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 11:17:35 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 83230bf9b1683c8426c244482eb47b921a7e33a0
Author: tkent at chromium.org <tkent at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Jul 16 21:40:34 2010 +0000

    Keyboard operations for <input type=number>
    https://bugs.webkit.org/show_bug.cgi?id=42076
    
    Reviewed by Darin Fisher.
    
    WebCore:
    
    - The up arrow key works as stepUp().
    - The down arrow key works as stepDown().
    - Reject characters other than + - 0-9 . e E
    
    Test: fast/forms/input-number-keyoperation.html
    
    * html/HTMLInputElement.cpp:
    (WebCore::HTMLInputElement::defaultEventHandler):
     Add up/down arrow keys support, and call handleBeforeTextInsertedEvent().
    (WebCore::isNumberCharacter):
    (WebCore::HTMLInputElement::handleBeforeTextInsertedEvent):
     For type=number, remove unacceptable characters.
    * html/HTMLInputElement.h:
    
    LayoutTests:
    
    * fast/forms/input-number-keyoperation-expected.txt: Added.
    * fast/forms/input-number-keyoperation.html: Added.
    * fast/forms/script-tests/input-number-keyoperation.js: Added.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63586 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 6074b4d..4c5e1ed 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,14 @@
+2010-07-16  Kent Tamura  <tkent at chromium.org>
+
+        Reviewed by Darin Fisher.
+
+        Keyboard operations for <input type=number>
+        https://bugs.webkit.org/show_bug.cgi?id=42076
+
+        * fast/forms/input-number-keyoperation-expected.txt: Added.
+        * fast/forms/input-number-keyoperation.html: Added.
+        * fast/forms/script-tests/input-number-keyoperation.js: Added.
+
 2010-07-16  Brian Weinstein  <bweinstein at apple.com>
 
         Land updated expected results for fast/dom/prototype-inheritance-2-expected.txt on Windows.
diff --git a/LayoutTests/fast/forms/input-number-keyoperation-expected.txt b/LayoutTests/fast/forms/input-number-keyoperation-expected.txt
new file mode 100644
index 0000000..fca556b
--- /dev/null
+++ b/LayoutTests/fast/forms/input-number-keyoperation-expected.txt
@@ -0,0 +1,15 @@
+Test for keyboard operations for <input type=number>
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Inserting "ab123cd":
+PASS input.value is "123"
+Press the up arrow key:
+PASS input.value is "124"
+Press the down arrow key:
+PASS input.value is "123"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/input-number-keyoperation.html b/LayoutTests/fast/forms/input-number-keyoperation.html
new file mode 100644
index 0000000..0a9e1a1
--- /dev/null
+++ b/LayoutTests/fast/forms/input-number-keyoperation.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-keyoperation.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/script-tests/input-number-keyoperation.js b/LayoutTests/fast/forms/script-tests/input-number-keyoperation.js
new file mode 100644
index 0000000..c4ed7a0
--- /dev/null
+++ b/LayoutTests/fast/forms/script-tests/input-number-keyoperation.js
@@ -0,0 +1,20 @@
+description('Test for keyboard operations for &lt;input type=number>');
+var parent = document.createElement('div');
+document.body.appendChild(parent);
+parent.innerHTML = '<input type=number id=number>';
+
+var input = document.getElementById('number');
+input.focus();
+debug('Inserting "ab123cd":');
+document.execCommand('InsertText', false, 'ab123cd');
+shouldBe('input.value', '"123"');
+
+debug('Press the up arrow key:');
+eventSender.keyDown('upArrow');
+shouldBe('input.value', '"124"');
+
+debug('Press the down arrow key:');
+eventSender.keyDown('downArrow');
+shouldBe('input.value', '"123"');
+
+var successfullyParsed = true;
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 7d4bee2..df6491f 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -2,6 +2,27 @@
 
         Reviewed by Darin Fisher.
 
+        Keyboard operations for <input type=number>
+        https://bugs.webkit.org/show_bug.cgi?id=42076
+
+        - The up arrow key works as stepUp().
+        - The down arrow key works as stepDown().
+        - Reject characters other than + - 0-9 . e E
+
+        Test: fast/forms/input-number-keyoperation.html
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::defaultEventHandler):
+         Add up/down arrow keys support, and call handleBeforeTextInsertedEvent().
+        (WebCore::isNumberCharacter):
+        (WebCore::HTMLInputElement::handleBeforeTextInsertedEvent):
+         For type=number, remove unacceptable characters.
+        * html/HTMLInputElement.h:
+
+2010-07-16  Kent Tamura  <tkent at chromium.org>
+
+        Reviewed by Darin Fisher.
+
         Improve hover state handling for spin buttons
         https://bugs.webkit.org/show_bug.cgi?id=42260
 
diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp
index 2d1cee1..d1023ed 100644
--- a/WebCore/html/HTMLInputElement.cpp
+++ b/WebCore/html/HTMLInputElement.cpp
@@ -29,6 +29,7 @@
 
 #include "AXObjectCache.h"
 #include "Attribute.h"
+#include "BeforeTextInsertedEvent.h"
 #include "CSSPropertyNames.h"
 #include "ChromeClient.h"
 #include "DateComponents.h"
@@ -106,6 +107,12 @@ static const double weekDefaultStepBase = -259200000.0; // The first day of 1970
 static const double msecPerMinute = 60 * 1000;
 static const double msecPerSecond = 1000;
 
+static bool isNumberCharacter(UChar ch)
+{
+    return ch == '+' || ch == '-' || ch == '.' || ch == 'e' || ch == 'E'
+        || ch >= '0' && ch <= '9';
+}
+
 HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
     : HTMLTextFormControlElement(tagName, document, form)
     , m_xPos(0)
@@ -2138,7 +2145,21 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
         }
     }
 
-    if (isTextField()
+    if (hasSpinButton() && evt->type() == eventNames().keydownEvent && evt->isKeyboardEvent()) {
+        String key = static_cast<KeyboardEvent*>(evt)->keyIdentifier();
+        int step = 0;
+        if (key == "Up")
+            step = 1;
+        else if (key == "Down")
+            step = -1;
+        if (step) {
+            stepUpFromRenderer(step);
+            evt->setDefaultHandled();
+            return;
+        }
+    }
+ 
+   if (isTextField()
             && evt->type() == eventNames().keydownEvent
             && evt->isKeyboardEvent()
             && focused()
@@ -2393,7 +2414,7 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
     }
 
     if (evt->isBeforeTextInsertedEvent())
-        InputElement::handleBeforeTextInsertedEvent(m_data, this, this, evt);
+        handleBeforeTextInsertedEvent(evt);
 
     if (isTextField() && renderer() && (evt->isMouseEvent() || evt->isDragEvent() || evt->isWheelEvent() || evt->type() == eventNames().blurEvent || evt->type() == eventNames().focusEvent))
         toRenderTextControlSingleLine(renderer())->forwardEvent(evt);
@@ -2405,6 +2426,33 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
         HTMLFormControlElementWithState::defaultEventHandler(evt);
 }
 
+void HTMLInputElement::handleBeforeTextInsertedEvent(Event* event)
+{
+    if (inputType() == NUMBER) {
+        BeforeTextInsertedEvent* textEvent = static_cast<BeforeTextInsertedEvent*>(event);
+        unsigned length = textEvent->text().length();
+        bool hasInvalidChar = false;
+        for (unsigned i = 0; i < length; ++i) {
+            if (!isNumberCharacter(textEvent->text()[i])) {
+                hasInvalidChar = true;
+                break;
+            }
+        }
+        if (hasInvalidChar) {
+            Vector<UChar> stripped;
+            stripped.reserveCapacity(length);
+            for (unsigned i = 0; i < length; ++i) {
+                UChar ch = textEvent->text()[i];
+                if (!isNumberCharacter(ch))
+                    continue;
+                stripped.append(ch);
+            }
+            textEvent->setText(String::adopt(stripped));
+        }
+    }
+    InputElement::handleBeforeTextInsertedEvent(m_data, this, this, event);
+}
+
 PassRefPtr<HTMLFormElement> HTMLInputElement::createTemporaryFormForIsIndex()
 {
     RefPtr<HTMLFormElement> form = HTMLFormElement::create(document());
diff --git a/WebCore/html/HTMLInputElement.h b/WebCore/html/HTMLInputElement.h
index 49cf3c9..3b9ba88 100644
--- a/WebCore/html/HTMLInputElement.h
+++ b/WebCore/html/HTMLInputElement.h
@@ -303,6 +303,7 @@ private:
 
     void updateCheckedRadioButtons();
     
+    void handleBeforeTextInsertedEvent(Event*);
     PassRefPtr<HTMLFormElement> createTemporaryFormForIsIndex();
     // Helper for getAllowedValueStep();
     bool getStepParameters(double* defaultStep, double* stepScaleFactor) const;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list