- Revision
- 91058
- Author
- [email protected]
- Date
- 2011-07-15 01:10:54 -0700 (Fri, 15 Jul 2011)
Log Message
Clear the content of a search input form when 'Escape' is pressed.
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 <[email protected]> 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 <[email protected]> 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.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (91057 => 91058)
--- trunk/LayoutTests/ChangeLog 2011-07-15 07:23:01 UTC (rev 91057)
+++ trunk/LayoutTests/ChangeLog 2011-07-15 08:10:54 UTC (rev 91058)
@@ -1,3 +1,16 @@
+2011-07-15 Kentaro Hara <[email protected]>
+
+ 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 <[email protected]>
[chromium] updated test expectations.
Added: trunk/LayoutTests/fast/forms/input-search-press-escape-key-expected.txt (0 => 91058)
--- trunk/LayoutTests/fast/forms/input-search-press-escape-key-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/forms/input-search-press-escape-key-expected.txt 2011-07-15 08:10:54 UTC (rev 91058)
@@ -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
+
Added: trunk/LayoutTests/fast/forms/input-search-press-escape-key.html (0 => 91058)
--- trunk/LayoutTests/fast/forms/input-search-press-escape-key.html (rev 0)
+++ trunk/LayoutTests/fast/forms/input-search-press-escape-key.html 2011-07-15 08:10:54 UTC (rev 91058)
@@ -0,0 +1,82 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</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=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (91057 => 91058)
--- trunk/Source/WebCore/ChangeLog 2011-07-15 07:23:01 UTC (rev 91057)
+++ trunk/Source/WebCore/ChangeLog 2011-07-15 08:10:54 UTC (rev 91058)
@@ -1,3 +1,19 @@
+2011-07-15 Kentaro Hara <[email protected]>
+
+ 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 <[email protected]>
Move useRepaintBounds from RenderBlock::layoutRunsAndFloats to LineLayoutState
Modified: trunk/Source/WebCore/html/SearchInputType.cpp (91057 => 91058)
--- trunk/Source/WebCore/html/SearchInputType.cpp 2011-07-15 07:23:01 UTC (rev 91057)
+++ trunk/Source/WebCore/html/SearchInputType.cpp 2011-07-15 08:10:54 UTC (rev 91058)
@@ -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 @@
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();
Modified: trunk/Source/WebCore/html/SearchInputType.h (91057 => 91058)
--- trunk/Source/WebCore/html/SearchInputType.h 2011-07-15 07:23:01 UTC (rev 91057)
+++ trunk/Source/WebCore/html/SearchInputType.h 2011-07-15 08:10:54 UTC (rev 91058)
@@ -56,6 +56,7 @@
virtual void destroyShadowSubtree();
virtual HTMLElement* resultsButtonElement() const;
virtual HTMLElement* cancelButtonElement() const;
+ virtual void handleKeydownEvent(KeyboardEvent*);
void searchEventTimerFired(Timer<SearchInputType>*);