[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)
Test cases testing preventing a keydown event. fast/events/inputText-never-fired-on-keydown-cancel.html fast/events/keydown-keypress-preventDefault.html
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.
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.
Created attachment 380185 [details] Patch
Created attachment 380186 [details] Patch
(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 on attachment 380186 [details] Patch This approach doesn't seem good for Bug 202183. Cleared r? flag.
Fixed in r252976. *** This bug has been marked as a duplicate of bug 204694 ***