Bug 200558 - [Win][WebKit2] Can't prevent input events by canceling keydown events
Summary: [Win][WebKit2] Can't prevent input events by canceling keydown events
Status: RESOLVED DUPLICATE of bug 204694
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Fujii Hironori
URL:
Keywords:
Depends on: 204694
Blocks:
  Show dependency treegraph
 
Reported: 2019-08-08 19:11 PDT by Fujii Hironori
Modified: 2019-12-01 19:21 PST (History)
5 users (show)

See Also:


Attachments
WIP patch (907 bytes, patch)
2019-10-03 21:50 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (2.59 KB, patch)
2019-10-03 22:07 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff
Patch (2.59 KB, patch)
2019-10-03 22:08 PDT, Fujii Hironori
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fujii Hironori 2019-08-08 19:11:19 PDT
[Win][WebKit2] Can't prevent input events by canceling keydown events

You can test it by using
https://javascript.info/keyboard-events

In old Windows WK2, this issue was fixed in

Bug 56020 – WebKit2: Pressing Tab in Web Inspector's console does not cycle through completion options
r83633

In Windows WK1, WM_CHAR event is removed if WM_DOWN is consumed.

WebView::keyDown
::PeekMessage(&msg, m_viewWindow, WM_CHAR, WM_CHAR, PM_REMOVE);
https://trac.webkit.org/browser/webkit/trunk/Source/WebKitLegacy/win/WebView.cpp?rev=248454#L2393

r23462
r25377
r28620 (Bug 13916)
Comment 1 Fujii Hironori 2019-10-03 21:33:11 PDT
Test cases testing preventing a keydown event.

fast/events/inputText-never-fired-on-keydown-cancel.html
fast/events/keydown-keypress-preventDefault.html
Comment 2 Fujii Hironori 2019-10-03 21:44:54 PDT
In old WebKit2 approach, TranslateMessage was called if a keydown
event isn't comsumed.

This has two problems:
1. This method can't be used in applications which is using TranslateMessage normally.
   For example and particularly, MiniBrowser can't use it because it supports WK1 and WK2 windows.
2. keypress event could be dispatched after keyup event unexpectedly.
   For example, if I type VK_A and VK_B quickly. Following native key events are queued:

     WM_KEYDOWN (VK_A)
     WM_KEYUP (VK_A)
     WM_KEYDOWN (VK_B)
     WM_KEYUP (VK_B)

   The first WM_KEYDOWN is sent to web process, and remaining events are queued in m_keyEventQueue.
   In didNotHandleKeyEvent of the first event, WM_CHAR (a) is posted by TranslateMessage.
   This is too late.
Comment 3 Fujii Hironori 2019-10-03 21:50:04 PDT
Created attachment 380184 [details]
WIP patch

This WIP patch removed queued WebEvent::Char events if WebEvent::RawKeyDown is handled.

This WIP patch works fine for MiniBrowser, but for WebKitTestRunner
because WebKitTestRunner processes IPC messages synchronously.
Comment 4 Fujii Hironori 2019-10-03 22:07:19 PDT
Created attachment 380185 [details]
Patch
Comment 5 Fujii Hironori 2019-10-03 22:08:12 PDT
Created attachment 380186 [details]
Patch
Comment 6 Fujii Hironori 2019-10-04 00:27:30 PDT
(In reply to Fujii Hironori from comment #2)
> In old WebKit2 approach, TranslateMessage was called if a keydown
> event isn't comsumed.
> 
> This has two problems:
> 1. This method can't be used in applications which is using TranslateMessage
>    normally.
>    For example and particularly, MiniBrowser can't use it because it
>    supports WK1 and WK2 windows.

This might be possible by checking the target window is WK1.

>    while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
>        if (isWebKit1BrowserWindow(msg.hwnd))
>            TranslateMessage(&msg);
>        DispatchMessage(&msg);
>    }
Comment 7 Fujii Hironori 2019-10-08 06:25:07 PDT
Comment on attachment 380186 [details]
Patch

This approach doesn't seem good for Bug 202183. Cleared r? flag.
Comment 8 Fujii Hironori 2019-12-01 19:21:41 PST
Fixed in r252976.

*** This bug has been marked as a duplicate of bug 204694 ***