LayoutTests:
authoradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Dec 2006 01:53:48 +0000 (01:53 +0000)
committeradele <adele@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Dec 2006 01:53:48 +0000 (01:53 +0000)
        Reviewed by Geoff.

        Test for <rdar://problem/4895716> REGRESSION: Pressing return key in search field doesn't begin search

        * fast/events/onsearch-enter-expected.txt: Added.
        * fast/events/onsearch-enter.html: Added.

WebCore:

        Reviewed by Geoff.

        - Fix for <rdar://problem/4895716> REGRESSION: Pressing return key in search field doesn't begin search

        Test: fast/events/onsearch-enter.html

        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::defaultEventHandler): Calls onSearch when handling "Enter".  Also removed
         special case for AppKit search fields, so now the enter event is considered handled here.
        (WebCore::HTMLInputElement::onSearch): Added. Dispatches search event.
        * html/HTMLInputElement.h: Added onSearch.
        * rendering/RenderTextControl.cpp: (WebCore::RenderTextControl::onSearch): Calls onSearch on the node.

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

LayoutTests/ChangeLog
LayoutTests/fast/events/onsearch-enter-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/onsearch-enter.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLInputElement.cpp
WebCore/html/HTMLInputElement.h
WebCore/rendering/RenderTextControl.cpp

index 7ffe7888b9b233cddd9bf25c18001289a8e6e9c7..fbc4c26ec60498d0fd4894277fd51c318b00f5e7 100644 (file)
@@ -1,3 +1,12 @@
+l2006-12-21  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Geoff.
+
+        Test for <rdar://problem/4895716> REGRESSION: Pressing return key in search field doesn't begin search
+
+        * fast/events/onsearch-enter-expected.txt: Added.
+        * fast/events/onsearch-enter.html: Added.
+
 2006-12-21  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Brady Eidson.
diff --git a/LayoutTests/fast/events/onsearch-enter-expected.txt b/LayoutTests/fast/events/onsearch-enter-expected.txt
new file mode 100644 (file)
index 0000000..641bbbb
--- /dev/null
@@ -0,0 +1,4 @@
+This tests that onSearch fires correctly.
+
+Test Passed
+
diff --git a/LayoutTests/fast/events/onsearch-enter.html b/LayoutTests/fast/events/onsearch-enter.html
new file mode 100644 (file)
index 0000000..bc76385
--- /dev/null
@@ -0,0 +1,26 @@
+<html>
+    <head>
+        <script>
+        function test()
+        {
+            var sf = document.getElementById('sf');
+            sf.focus();
+            var enterEvent = document.createEvent("KeyboardEvents");
+            enterEvent.initKeyboardEvent("keypress", true, false, window, "Enter", 0, false, false, false, false, false);
+            sf.dispatchEvent(enterEvent);
+            if (window.layoutTestController)
+                layoutTestController.dumpAsText();
+        }
+        function log(msg)
+        {
+            var res = document.getElementById('res');
+            res.innerHTML = res.innerHTML + msg + "<br>";
+        }
+        </script>
+    </head>
+    <body onload="test()">
+        This tests that onSearch fires correctly.<br>
+        <input type="search" id="sf" onSearch="log('Test Passed');"></input>
+        <div id="res"></div>
+    </body>
+</html>
index 2c2004e2999e7b54137e64cb5d73b8bde05fad3b..c54420c80f2e2f5cc5e7bb47e385aee6a4d9b33d 100644 (file)
@@ -1,3 +1,18 @@
+2006-12-21  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Geoff.
+
+        - Fix for <rdar://problem/4895716> REGRESSION: Pressing return key in search field doesn't begin search
+
+        Test: fast/events/onsearch-enter.html
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::defaultEventHandler): Calls onSearch when handling "Enter".  Also removed
+         special case for AppKit search fields, so now the enter event is considered handled here.
+        (WebCore::HTMLInputElement::onSearch): Added. Dispatches search event.
+        * html/HTMLInputElement.h: Added onSearch.
+        * rendering/RenderTextControl.cpp: (WebCore::RenderTextControl::onSearch): Calls onSearch on the node.
+
 2006-12-21  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Brady Eidson.
index 2f1c9646d28010d49e5b8780ba8c51e1d7a06970..371ffc44c2c4d424808acc78055b89cc4f37bed3 100644 (file)
@@ -1345,16 +1345,15 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
             dispatchSimulatedClick(evt);
             evt->setDefaultHandled();
         } else if (clickDefaultFormButton) {
-            if (isSearchField())
+            if (isSearchField()) {
                 addSearchResult();
+                onSearch();
+            }
             blur();
             // Form may never have been present, or may have been destroyed by the blur event.
-            if (form()) {
+            if (form())
                 form()->submitClick(evt);
-                evt->setDefaultHandled();
-            } else if (inputType() != SEARCH) {
-                evt->setDefaultHandled();
-            }
+            evt->setDefaultHandled();
         }
     }
 
@@ -1520,5 +1519,11 @@ void HTMLInputElement::addSearchResult()
     if (renderer())
         static_cast<RenderTextControl*>(renderer())->addSearchResult();
 }
+
+void HTMLInputElement::onSearch()
+{
+    ASSERT(isSearchField());
+    dispatchHTMLEvent(searchEvent, true, false);
+}
     
 } // namespace
index 2a16afceb67a5df3782ddf9ba575d8bb75666c8c..118feaf3178ad8f4ab8d8ae3b4d2fe98e8642581 100644 (file)
@@ -175,6 +175,7 @@ public:
     
     void cacheSelection(int s, int e) { cachedSelStart = s; cachedSelEnd = e; };
     void addSearchResult();
+    void onSearch();
 
 protected:
     AtomicString m_name;
index 333f208fdf6c6e366a85cb072e3b921233067ac6..0e4886dab853e6e902cfdd56615fd6a6f3222134 100644 (file)
@@ -807,7 +807,7 @@ void RenderTextControl::addSearchResult()
 
 void RenderTextControl::onSearch() const
 {
-    static_cast<EventTargetNode*>(node())->dispatchHTMLEvent(searchEvent, true, false);
+    static_cast<HTMLInputElement*>(node())->onSearch();
 }
 
 void RenderTextControl::showPopup()