Skip to content

Commit 2751cb6

Browse files
[KeyEvent] Throttle keys repetition
In some apps it takes long time to handle key input (e.g. >500ms), longer than key repetition interval is. WebKit collects all key repetitions (KeyDown events) in m_keyEventQueue and sends them one by one to the WebProcess. This may take significant time, even after releasing all the buttons (keyboard/RCU) blocking web app UI and making the app unresponsive untill all repetitions are handled. Proposed solution is to simply detect key repetition (next KeyDown event without KeyUp) and skip it if the previous one wasn't handled yet.
1 parent 76d3b46 commit 2751cb6

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

Source/WebKit/Shared/WebKeyboardEvent.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,18 @@ bool WebKeyboardEvent::isKeyboardEventType(Type type)
223223
return type == RawKeyDown || type == KeyDown || type == KeyUp || type == Char;
224224
}
225225

226+
bool operator==(const WebKeyboardEvent& a, const WebKeyboardEvent& b)
227+
{
228+
return a.type() == b.type()
229+
&& a.modifiers() == b.modifiers()
230+
&& a.text() == b.text()
231+
&& a.unmodifiedText() == b.unmodifiedText()
232+
&& a.key() == b.key()
233+
&& a.code() == b.code()
234+
&& a.keyIdentifier() == b.keyIdentifier()
235+
&& a.windowsVirtualKeyCode() == b.windowsVirtualKeyCode()
236+
&& a.nativeVirtualKeyCode() == b.nativeVirtualKeyCode()
237+
&& a.macCharCode() == b.macCharCode();
238+
}
239+
226240
} // namespace WebKit

Source/WebKit/Shared/WebKeyboardEvent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class WebKeyboardEvent : public WebEvent {
8282

8383
static bool isKeyboardEventType(Type);
8484

85+
friend bool operator==(const WebKeyboardEvent&, const WebKeyboardEvent&);
8586
private:
8687
String m_text;
8788
String m_unmodifiedText;

Source/WebKit/UIProcess/WebPageProxy.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,6 +3111,11 @@ bool WebPageProxy::handleKeyboardEvent(const NativeWebKeyboardEvent& event)
31113111

31123112
LOG(KeyHandling, "WebPageProxy::handleKeyboardEvent: %s", webKeyboardEventTypeString(event.type()));
31133113

3114+
if (event.type() == WebEvent::KeyDown && !m_keyEventQueue.isEmpty() && m_keyEventQueue.last() == event) {
3115+
// Throtthe key repetition if we still have previous keypress pending
3116+
return true;
3117+
}
3118+
31143119
m_keyEventQueue.append(event);
31153120

31163121
m_process->startResponsivenessTimer(event.type() == WebEvent::KeyDown ? WebProcessProxy::UseLazyStop::Yes : WebProcessProxy::UseLazyStop::No);

0 commit comments

Comments
 (0)