Clear the content of a search input form when 'Escape' is pressed.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jul 2011 08:10:54 +0000 (08:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jul 2011 08:10:54 +0000 (08:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=51897

Source/WebCore:

This change added handleKeydownEvent() to a search input form,
which clears the form and triggers a 'search' event when 'Escape' is pressed.

Patch by Kentaro Hara <haraken@google.com> on 2011-07-15
Reviewed by Kent Tamura.

Test: fast/forms/input-search-press-escape-key.html

* html/SearchInputType.cpp:
(WebCore::SearchInputType::handleKeydownEvent):
* html/SearchInputType.h:

LayoutTests:

The added test checks if the value in a search input form is cleared
and a 'search' event is triggered, when we press 'Escape' key.

Patch by Kentaro Hara <haraken@google.com> on 2011-07-15
Reviewed by Kent Tamura.

* fast/forms/input-search-press-escape-key-expected.txt: Added.
* fast/forms/input-search-press-escape-key.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@91058 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/forms/input-search-press-escape-key-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/input-search-press-escape-key.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/SearchInputType.cpp
Source/WebCore/html/SearchInputType.h

index 29e6806..849b1c4 100644 (file)
@@ -1,3 +1,16 @@
+2011-07-15  Kentaro Hara  <haraken@google.com>
+
+        Clear the content of a search input form when 'Escape' is pressed.
+        https://bugs.webkit.org/show_bug.cgi?id=51897
+
+        The added test checks if the value in a search input form is cleared
+        and a 'search' event is triggered, when we press 'Escape' key.
+
+        Reviewed by Kent Tamura.
+
+        * fast/forms/input-search-press-escape-key-expected.txt: Added.
+        * fast/forms/input-search-press-escape-key.html: Added.
+
 2011-07-14  Hayato Ito  <hayato@chromium.org>
 
         [chromium] updated test expectations.
diff --git a/LayoutTests/fast/forms/input-search-press-escape-key-expected.txt b/LayoutTests/fast/forms/input-search-press-escape-key-expected.txt
new file mode 100644 (file)
index 0000000..b34aacf
--- /dev/null
@@ -0,0 +1,17 @@
+
+This tests if the value in a search input form is cleared and a 'search' event is triggered, when we press the Escape key. To run (a part of) this test manually, type some text in the search form and then press the Escape key. If the text is cleared, then the test passes.
+
+PASS input.value is ""
+PASS searchEventObserved is true
+PASS input.value is ""
+PASS searchEventObserved is true
+PASS input.value is "foo"
+PASS searchEventObserved is false
+PASS input.value is "foo"
+PASS searchEventObserved is false
+PASS input.value is "foo"
+PASS searchEventObserved is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/input-search-press-escape-key.html b/LayoutTests/fast/forms/input-search-press-escape-key.html
new file mode 100644 (file)
index 0000000..2db8bac
--- /dev/null
@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../js/resources/js-test-pre.js"></script>
+<script src="resources/common.js"></script>
+</head>
+<body>
+<input id="search" type="search" onsearch="searchEventDispatched()" />
+<div id="console">
+<p>
+This tests if the value in a search input form is cleared
+and a 'search' event is triggered, when we press the Escape key.
+To run (a part of) this test manually,
+type some text in the search form and then press the Escape key.
+If the text is cleared, then the test passes.
+</p>
+</div>
+<script>
+var searchEventObserved;
+
+if (window.layoutTestController && window.eventSender) {
+    var input = $("search");
+    var enabled = false;
+    var disabled = true;
+    var readonly = true;
+
+    searchEventObserved = false;
+    input.focus();
+    setInputAttributes(input, "foo", enabled);
+    eventSender.keyDown("\x1B");
+    shouldBeEqualToString('input.value', "");
+    shouldBe('searchEventObserved', 'true');
+    input.blur();
+
+    searchEventObserved = false;
+    input.focus();
+    setInputAttributes(input, "", enabled);
+    eventSender.keyDown("\x1B");
+    shouldBeEqualToString('input.value', "");
+    shouldBe('searchEventObserved', 'true');
+    input.blur();
+
+    searchEventObserved = false;
+    input.focus();
+    setInputAttributes(input, "foo", enabled, readonly);
+    eventSender.keyDown("\x1B");
+    shouldBeEqualToString('input.value', "foo");
+    shouldBe('searchEventObserved', 'false');
+    input.blur();
+
+    searchEventObserved = false;
+    input.focus();
+    setInputAttributes(input, "foo", disabled);
+    eventSender.keyDown("\x1B");
+    shouldBeEqualToString('input.value', "foo");
+    shouldBe('searchEventObserved', 'false');
+    input.blur();
+
+    searchEventObserved = false;
+    input.focus();
+    setInputAttributes(input, "foo", disabled, readonly);
+    eventSender.keyDown("\x1B");
+    shouldBeEqualToString('input.value', "foo");
+    shouldBe('searchEventObserved', 'false');
+    input.blur();
+}
+
+function setInputAttributes(input, text, disabled, readonly) {
+    input.value = text;
+    input.disabled = disabled;
+    input.readOnly = !!readonly;
+}
+
+function searchEventDispatched() {
+    searchEventObserved = true;
+}
+
+var successfullyParsed = true;
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
index 7e26ab1..6e6ad8a 100644 (file)
@@ -1,3 +1,19 @@
+2011-07-15  Kentaro Hara  <haraken@google.com>
+
+        Clear the content of a search input form when 'Escape' is pressed.
+        https://bugs.webkit.org/show_bug.cgi?id=51897
+
+        This change added handleKeydownEvent() to a search input form,
+        which clears the form and triggers a 'search' event when 'Escape' is pressed.
+
+        Reviewed by Kent Tamura.
+
+        Test: fast/forms/input-search-press-escape-key.html
+
+        * html/SearchInputType.cpp:
+        (WebCore::SearchInputType::handleKeydownEvent):
+        * html/SearchInputType.h:
+
 2011-07-15  Alexandru Chiculita  <achicu@adobe.com>
 
         Move useRepaintBounds from RenderBlock::layoutRunsAndFloats to LineLayoutState
index abddb01..7cd9ca1 100644 (file)
@@ -32,6 +32,7 @@
 #include "SearchInputType.h"
 
 #include "HTMLInputElement.h"
+#include "KeyboardEvent.h"
 #include "RenderTextControlSingleLine.h"
 #include "ShadowRoot.h"
 #include "TextControlInnerElements.h"
@@ -99,6 +100,24 @@ HTMLElement* SearchInputType::cancelButtonElement() const
     return m_cancelButton.get();
 }
 
+void SearchInputType::handleKeydownEvent(KeyboardEvent* event)
+{
+    if (element()->disabled() || element()->readOnly()) {
+        TextFieldInputType::handleKeydownEvent(event);
+        return;
+    }
+
+    const String& key = event->keyIdentifier();
+    if (key == "U+001B") {
+        RefPtr<HTMLInputElement> input = element();
+        input->setValueForUser("");
+        input->onSearch();
+        event->setDefaultHandled();
+        return;
+    }
+    TextFieldInputType::handleKeydownEvent(event);
+}
+
 void SearchInputType::destroyShadowSubtree()
 {
     TextFieldInputType::destroyShadowSubtree();
index d19d071..a9fefb1 100644 (file)
@@ -56,6 +56,7 @@ private:
     virtual void destroyShadowSubtree();
     virtual HTMLElement* resultsButtonElement() const;
     virtual HTMLElement* cancelButtonElement() const;
+    virtual void handleKeydownEvent(KeyboardEvent*);
 
     void searchEventTimerFired(Timer<SearchInputType>*);