Bug 73821

Summary: keyboard event doesn't fire while moving mouse with button pressed
Product: WebKit Reporter: Rakesh <rakeshchaitan>
Component: WebCore Misc.Assignee: Rakesh <rakeshchaitan>
Status: RESOLVED FIXED    
Severity: Normal CC: adele, ap, bweinstein, rniwa, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Windows XP   
URL: http://jsfiddle.net/VFAnx/
Attachments:
Description Flags
Proposed patch
none
Updated patch none

Description Rakesh 2011-12-05 04:26:05 PST
1. Register an eventListener for keydown. Add an alert in the callback function
2. Click and hold the left mouse button. Move the mouse around (as if you want to select something)
3. While moving the mouse press any key.

Key Down event listener is not called.

This happens only on Windows. Works fine on mac and linux.

Chromium issue: http://code.google.com/p/chromium/issues/detail?id=83518
Comment 1 Rakesh 2011-12-05 04:28:01 PST
This issue looks like hapening due to PAN scrolling.
After debugging I found it is returning from this code in EventHandler::keyEvent:

#if ENABLE(PAN_SCROLLING)
    if (Page* page = m_frame->page()) {
        if (page->mainFrame()->eventHandler()->m_panScrollInProgress || m_autoscrollInProgress) {
            // If a key is pressed while the autoscroll/panScroll is in progress then we want to stop
            if (initialKeyEvent.type() == PlatformKeyboardEvent::KeyDown || initialKeyEvent.type() == PlatformKeyboardEvent::RawKeyDown)
                stopAutoscrollTimer();

            // If we were in autoscroll/panscroll mode, we swallow the key event
            return true;
        }
    }
#endif

This check should only be for pan scrolling?

This I think some inputs can be taken from https://bugs.webkit.org/show_bug.cgi?id=28005
Comment 2 Rakesh 2011-12-06 01:50:58 PST
Created attachment 118007 [details]
Proposed patch

Removed the check the autoscroll in keyEvent so that autoscroll does not stop on key press. This behaviour is consistent with IE and Firefox.
Comment 3 Alexey Proskuryakov 2011-12-06 08:42:03 PST
Comment on attachment 118007 [details]
Proposed patch

View in context: https://bugs.webkit.org/attachment.cgi?id=118007&action=review

> Source/WebCore/page/EventHandler.cpp:2526
> -        if (page->mainFrame()->eventHandler()->m_panScrollInProgress || m_autoscrollInProgress) {
> +        if (page->mainFrame()->eventHandler()->m_panScrollInProgress) {
>              // If a key is pressed while the autoscroll/panScroll is in progress then we want to stop

Please fix the comment. It is no longer correct after the change.

When was this code introduced, and why?

> LayoutTests/fast/events/autoscroll-should-not-stop-on-keypress.html:11
> +        var y = document.body.scrollHeight + 100;

Please give "y" a meaningful name.

> LayoutTests/fast/events/autoscroll-should-not-stop-on-keypress.html:19
> +        debug("Test manually that scrolling deos not stop if we press a key while autoscroll is happening.");

Typo: does.

> LayoutTests/fast/events/autoscroll-should-not-stop-on-keypress.html:24
> +function testAutoScroll() {
> +    shouldBe('document.body.scrollTop + window.innerHeight', 'document.body.scrollHeight');

What guarantees that scrolling will be done by the time this function is called?
Comment 4 Rakesh 2011-12-06 09:05:02 PST
(In reply to comment #3)
> >              // If a key is pressed while the autoscroll/panScroll is in progress then we want to stop
> 
> Please fix the comment. It is no longer correct after the change.

Yes, the comment is no longer valid.
 
> When was this code introduced, and why?
> 

This change was introduced by http://trac.webkit.org/changeset/35758(Brian pointed me to this). This in my view was meant for pan scrolling only.

> > LayoutTests/fast/events/autoscroll-should-not-stop-on-keypress.html:11
> > +        var y = document.body.scrollHeight + 100;
> 
> Please give "y" a meaningful name.
> 
> > LayoutTests/fast/events/autoscroll-should-not-stop-on-keypress.html:19
> > +        debug("Test manually that scrolling deos not stop if we press a key while autoscroll is happening.");
> 
> Typo: does.
> 

Will do the suggested changes.

> > LayoutTests/fast/events/autoscroll-should-not-stop-on-keypress.html:24
> > +function testAutoScroll() {
> > +    shouldBe('document.body.scrollTop + window.innerHeight', 'document.body.scrollHeight');
> 
> What guarantees that scrolling will be done by the time this function is called?

Its an approx. time by which it should happen. Please suggest if any better way to know for sure.
Comment 5 Rakesh 2011-12-06 23:06:37 PST
Created attachment 118175 [details]
Updated patch

Modified comments and fixed typo and variable in test case.
Comment 6 Alexey Proskuryakov 2011-12-08 17:20:21 PST
Comment on attachment 118175 [details]
Updated patch

Talked on IRC, and I had some confusion about this patch. Posting the explanation here for posterity.

The fix does more than the original description asked for - in addition to making the event fire (which could be achieved by avoiding an early return), it fixes a user visible issue where autoscrolling stopped if a key was pressed.

Both new behaviors seem to match IE9 in my testing.
Comment 7 WebKit Review Bot 2011-12-08 17:47:08 PST
Comment on attachment 118175 [details]
Updated patch

Clearing flags on attachment: 118175

Committed r102408: <http://trac.webkit.org/changeset/102408>
Comment 8 WebKit Review Bot 2011-12-08 17:47:13 PST
All reviewed patches have been landed.  Closing bug.
Comment 10 Alexey Proskuryakov 2011-12-14 13:41:58 PST
Looks like this way of starting autoscroll doesn't work on Mac. But we have other autoscroll tests in fast/events, which work fine. Looks like the trick is to use an iframe instead of moving mouse pointer out of the window.

Rakesh, would you be willing to adjust the test to be more like existing autoscroll ones, so that it would work on Mac? In the meantime, Ryosuke is going to skip it.
Comment 11 Rakesh 2011-12-14 18:05:59 PST
(In reply to comment #10)
> Looks like this way of starting autoscroll doesn't work on Mac. But we have other autoscroll tests in fast/events, which work fine. Looks like the trick is to use an iframe instead of moving mouse pointer out of the window.
> 
> Rakesh, would you be willing to adjust the test to be more like existing autoscroll ones, so that it would work on Mac? In the meantime, Ryosuke is going to skip it.

Yes, will make that change. Sorry, I saw the failing tests but could not get hold of a mac so could not check the failures. 

https://bugs.webkit.org/show_bug.cgi?id=74538 is logged for this by rniwa.