Skip to content
Permalink
Browse files
LayoutTests:
        Reviewed by Maciej.

        - test for <rdar://problem/4887428> REGRESSION: Implement slight delay for firing incremental onSearch event

        * fast/forms/search-event-delay-expected.txt: Added.
        * fast/forms/search-event-delay.html: Added.

WebCore:

        Reviewed by Maciej.

        - fix <rdar://problem/4887428> REGRESSION: Implement slight delay for firing incremental onSearch event

        * rendering/RenderTextControl.h:
        * rendering/RenderTextControl.cpp:
        (WebCore::RenderTextControl::RenderTextControl): Set up timer.
        (WebCore::RenderTextControl::subtreeHasChanged): Start timer here instead of immediately sending event.
        (WebCore::RenderTextControl::searchEventTimerFired): Added. Sends search event.
        (WebCore::RenderTextControl::stopSearchEventTimer): Added.
        (WebCore::RenderTextControl::startSearchEventTimer): Added. Sends search event right away if there is
        no text. If there is some text, sets the timer using the same delay rule as NSSearchField. If you keep
        typing, then the timer keeps getting reset 0.2 seconds into the future until you pause.

        * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::onSearch): Tell the renderer to
        stop the timer, since we're sending a search event. This helps when a caller other than
        the timer decides to send an explicit search event.



Canonical link: https://commits.webkit.org/16261@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@19336 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
darinadler committed Feb 1, 2007
1 parent 1b8ae1a commit 804d66624577c54bf31c9678838b207c5c980ec4
Showing 7 changed files with 140 additions and 1 deletion.
@@ -1,3 +1,12 @@
2007-02-01 Darin Adler <darin@apple.com>

Reviewed by Maciej.

- test for <rdar://problem/4887428> REGRESSION: Implement slight delay for firing incremental onSearch event

* fast/forms/search-event-delay-expected.txt: Added.
* fast/forms/search-event-delay.html: Added.

2007-01-31 Darin Adler <darin@apple.com>

Reviewed by Adam and Geoff.
@@ -0,0 +1,10 @@
This tests the delay between when you type and the search event fires.

As of this writing we can't use DOM events to type into a search field, so the test uses the event sender and only runs under DumpRenderTree.



The two rows below should match.
0.5 0.4 0.3 0.2 0.2 0
0.5 0.4 0.3 0.2 0.2 0

@@ -0,0 +1,64 @@
<script>

var count = 0;
var keyEventTime;

function sendKeyEvent()
{
if (window.eventSender)
eventSender.keyDown("x");
}

function sendDeleteKeyEvent()
{
if (window.eventSender)
eventSender.keyDown("\x7F");
}

function keyEvent(event)
{
keyEventTime = event.timeStamp;
}

function searchEvent(event)
{
document.getElementById("times").innerHTML += " " + (Math.round((event.timeStamp - keyEventTime) / 100) / 10);
count += 1;
if (count != 6) {
if (count != 5)
sendKeyEvent();
else {
document.getElementById("search").select();
sendDeleteKeyEvent();
}
} else {
if (window.layoutTestController)
layoutTestController.notifyDone();
}
}

function startTest()
{
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
document.getElementById("search").focus();
sendKeyEvent();
}

</script>

<body onload="startTest()">

<p>This tests the delay between when you type and the search event fires.</p>

<p>As of this writing we can't use DOM events to type into a search field, so the test uses the event sender and only runs under DumpRenderTree.</p>

<p><input id="search" type="search" incremental onkeypress="keyEvent(event)" onsearch="searchEvent(event)"></p>

<div>The two rows below should match.</div>
<div>0.5 0.4 0.3 0.2 0.2 0</p>
<div id="times"></div>

</body>
@@ -1,3 +1,23 @@
2007-02-01 Darin Adler <darin@apple.com>

Reviewed by Maciej.

- fix <rdar://problem/4887428> REGRESSION: Implement slight delay for firing incremental onSearch event

* rendering/RenderTextControl.h:
* rendering/RenderTextControl.cpp:
(WebCore::RenderTextControl::RenderTextControl): Set up timer.
(WebCore::RenderTextControl::subtreeHasChanged): Start timer here instead of immediately sending event.
(WebCore::RenderTextControl::searchEventTimerFired): Added. Sends search event.
(WebCore::RenderTextControl::stopSearchEventTimer): Added.
(WebCore::RenderTextControl::startSearchEventTimer): Added. Sends search event right away if there is
no text. If there is some text, sets the timer using the same delay rule as NSSearchField. If you keep
typing, then the timer keeps getting reset 0.2 seconds into the future until you pause.

* html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::onSearch): Tell the renderer to
stop the timer, since we're sending a search event. This helps when a caller other than
the timer decides to send an explicit search event.

2007-02-01 Maciej Stachowiak <mjs@apple.com>

Fix by Darin, reviewed by Maciej.
@@ -1537,6 +1537,8 @@ void HTMLInputElement::addSearchResult()
void HTMLInputElement::onSearch()
{
ASSERT(isSearchField());
if (renderer())
static_cast<RenderTextControl*>(renderer())->stopSearchEventTimer();
dispatchHTMLEvent(searchEvent, true, false);
}

@@ -58,6 +58,7 @@ RenderTextControl::RenderTextControl(Node* node, bool multiLine)
, m_placeholderVisible(false)
, m_searchPopup(0)
, m_searchPopupIsVisible(false)
, m_searchEventTimer(this, &RenderTextControl::searchEventTimerFired)
{
}

@@ -479,7 +480,7 @@ void RenderTextControl::subtreeHasChanged()

// If the incremental attribute is set, then dispatch the search event
if (!input->getAttribute(incrementalAttr).isNull())
input->onSearch();
startSearchEventTimer();

if (!wasDirty) {
if (Frame* frame = document()->frame())
@@ -996,4 +997,30 @@ bool RenderTextControl::scroll(ScrollDirection direction, ScrollGranularity gran
return RenderObject::scroll(direction, granularity, multiplier);
}

void RenderTextControl::searchEventTimerFired(Timer<RenderTextControl>*)
{
static_cast<HTMLInputElement*>(node())->onSearch();
}

void RenderTextControl::stopSearchEventTimer()
{
m_searchEventTimer.stop();
}

void RenderTextControl::startSearchEventTimer()
{
unsigned length = text().length();

// If there's no text, fire the event right away.
if (!length) {
m_searchEventTimer.stop();
static_cast<HTMLInputElement*>(node())->onSearch();
return;
}

// After typing the first key, we wait 0.5 seconds.
// After the second key, 0.4 seconds, then 0.3, then 0.2 from then on.
m_searchEventTimer.startOneShot(max(0.2, 0.6 - 0.1 * length));
}

} // namespace WebCore
@@ -23,6 +23,7 @@

#include "PopupMenuClient.h"
#include "RenderBlock.h"
#include "Timer.h"

namespace WebCore {

@@ -88,6 +89,8 @@ class RenderTextControl : public RenderBlock, private PopupMenuClient {
void showPopup();
void hidePopup();

void stopSearchEventTimer();

private:
// PopupMenuClient methods
virtual void valueChanged(unsigned listIndex, bool fireEvents = true);
@@ -116,6 +119,8 @@ class RenderTextControl : public RenderBlock, private PopupMenuClient {
void createSubtreeIfNeeded();
void updateCancelButtonVisibility(RenderStyle*);
const AtomicString& autosaveName() const;
void startSearchEventTimer();
void searchEventTimerFired(Timer<RenderTextControl>*);

RefPtr<HTMLTextFieldInnerElement> m_innerBlock;
RefPtr<HTMLTextFieldInnerTextElement> m_innerText;
@@ -129,6 +134,8 @@ class RenderTextControl : public RenderBlock, private PopupMenuClient {
RefPtr<SearchPopupMenu> m_searchPopup;
bool m_searchPopupIsVisible;
mutable Vector<String> m_recentSearches;

Timer<RenderTextControl> m_searchEventTimer;
};

} // namespace WebCore

0 comments on commit 804d666

Please sign in to comment.