Bug 221456 - [GTK] event.ctrlKey and other are false in keydown event
Summary: [GTK] event.ctrlKey and other are false in keydown event
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Manuel Rego Casasnovas
URL:
Keywords:
Depends on:
Blocks: 221466
  Show dependency treegraph
 
Reported: 2021-02-05 02:08 PST by Manuel Rego Casasnovas
Modified: 2021-02-08 05:53 PST (History)
6 users (show)

See Also:


Attachments
Test case (443 bytes, text/html)
2021-02-05 02:08 PST, Manuel Rego Casasnovas
no flags Details
Patch (4.27 KB, patch)
2021-02-05 04:37 PST, Manuel Rego Casasnovas
no flags Details | Formatted Diff | Diff
Patch (8.81 KB, patch)
2021-02-05 07:30 PST, Manuel Rego Casasnovas
no flags Details | Formatted Diff | Diff
Patch (9.10 KB, patch)
2021-02-08 00:27 PST, Manuel Rego Casasnovas
no flags Details | Formatted Diff | Diff
Patch (8.90 KB, patch)
2021-02-08 00:36 PST, Manuel Rego Casasnovas
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel Rego Casasnovas 2021-02-05 02:08:26 PST
Created attachment 419376 [details]
Test case

Check the attached example and type things like Ctrl or Alt. The event.ctrlKey or event.altKey will be false.

This works fine on Mac and other browsers.
Comment 1 Manuel Rego Casasnovas 2021-02-05 04:37:22 PST
Created attachment 419387 [details]
Patch
Comment 2 Adrian Perez 2021-02-05 07:02:21 PST
Comment on attachment 419387 [details]
Patch

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

> Source/WebKit/Shared/gtk/WebEventFactory.cpp:70
> +    if (keyboardEvent) {

When ”keyboardEvent” is true, the event type will always be “GDK_KEY_PRESS” or
“GDK_KEY_RELEASE”; so instead of adding this ”keyboardEvent” flag to the function
signature, I think we can directly check for “GDK_KEY_PRESS” instead:

  if (gdk_event_get_event_type(const_cast<GdkEvent*>(event)) == GDK_KEY_PRESS) {
      guint keyval;
      gdk_event_get_keyval(event, &keyval);
      switch (keyval) {
          // ...
      }
  }

  return modifiers;

…or is there something else I am missing here?

> Source/WebKit/Shared/gtk/WebEventFactory.cpp:340
> +

Please remove this stray empty line before landing.
Comment 3 Manuel Rego Casasnovas 2021-02-05 07:30:57 PST
Created attachment 419402 [details]
Patch
Comment 4 Manuel Rego Casasnovas 2021-02-05 07:49:42 PST
Comment on attachment 419387 [details]
Patch

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

>> Source/WebKit/Shared/gtk/WebEventFactory.cpp:70
>> +    if (keyboardEvent) {
> 
> When ”keyboardEvent” is true, the event type will always be “GDK_KEY_PRESS” or
> “GDK_KEY_RELEASE”; so instead of adding this ”keyboardEvent” flag to the function
> signature, I think we can directly check for “GDK_KEY_PRESS” instead:
> 
>   if (gdk_event_get_event_type(const_cast<GdkEvent*>(event)) == GDK_KEY_PRESS) {
>       guint keyval;
>       gdk_event_get_keyval(event, &keyval);
>       switch (keyval) {
>           // ...
>       }
>   }
> 
>   return modifiers;
> 
> …or is there something else I am missing here?

True thing, the first version of this method was not getting the event.

I'll upload a new version doing that next week. Thanks for the review.
Comment 5 EWS Watchlist 2021-02-05 09:57:27 PST
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See https://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
Comment 6 Manuel Rego Casasnovas 2021-02-08 00:27:41 PST
Created attachment 419560 [details]
Patch
Comment 7 Manuel Rego Casasnovas 2021-02-08 00:36:40 PST
Created attachment 419561 [details]
Patch
Comment 8 Manuel Rego Casasnovas 2021-02-08 00:37:15 PST
Applied the suggested changes and added a test. PTAL, thanks!
Comment 9 Adrian Perez 2021-02-08 03:31:48 PST
Comment on attachment 419561 [details]
Patch

Very nice that the patch comes now with a layout test, thanks for that!
Comment 10 EWS 2021-02-08 05:52:59 PST
Committed r272489: <https://commits.webkit.org/r272489>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 419561 [details].