Open Bug 1921161 Opened 2 months ago Updated 4 days ago

Add intercept keyboard event API for keyboard shortcut in browser (was Do not capture keyevent if webpage does not handle it)

Categories

(GeckoView :: IME, enhancement, P3)

Firefox 117
All
Android
enhancement

Tracking

(Not tracked)

UNCONFIRMED

People

(Reporter: lucius, Unassigned)

References

(Blocks 1 open bug)

Details

User Agent: Mozilla/5.0 (Android 14; Mobile; rv:132.0) Gecko/132.0 Firefox/132.0

Steps to reproduce:

This bug is related to https://bugzilla.mozilla.org/show_bug.cgi?id=1794664 in Fenix.

  1. Press any key on an external keyboard.
  2. The KeyEvent will be handled by onKeyDown, which after a few function calls, can be traced to https://searchfox.org/mozilla-central/source/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoEditable.java#2551 (processKey function).

It seems like the entry for GeckoView would be https://searchfox.org/mozilla-central/source/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoView.java#880.

Actual results:

All KeyEvents that are valid are captured.
I.e:
The invalid keyevents/ones that should not be captured return false.
Afterwards, a Runnable is posted to (presumably to another thread) to handle the event. Then true is returned immediately.
Thus we do not know if the event is handled or not.

Expected results:

Only if the webpage overriden/used that specific shortcut, then we return true.
This blocks https://bugzilla.mozilla.org/show_bug.cgi?id=1794664 because the application does not know when the webpage has overriden or handled the shortcuts, hence cannot meaningfully implement keyboard shortcuts up to web standards.

Blocks: 1794664

The severity field is not set for this bug.
:owlish, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(bugzeeeeee)
Component: General → IME
Flags: needinfo?(bugzeeeeee)

Could you please update the severity?
This issue blocks the long-awaited “keyboard shortcut” improvement 1794664.

I guess that parent process won't know whether consuming keyboard event on content process. So I guess that we must have same way of shortcut handling in Firefox desktop (XUL) then I might have an API (delegation?) for it.

Severity: -- → S3
Type: defect → enhancement
Priority: -- → P3

Nakano-san, I have a question. How handling of shortcut (in menubar) in Desktop? Before sending keyboard event to content process, does parent process handle shortcut of XUL menu?

Flags: needinfo?(masayuki)

First, shortcut keys are managed and handled by GlobalKeyListener which is attached to the root window or the XUL <keyset>.

In the parent process, it handles eKeyDown and eKeyPress. If the corresponding shortcut is "reserved", the event is marked and the event won't be sent to the focused remote process. Otherwise, the events are marked as "waiting for reply". Then, the key event will be sent to the focused remote process.

In the focused content process, the key event is dispatched into the DOM. Then, if the event is marked as "waiting for reply", it'll be sent back to the parent process.

Finally, in the parent process, the reply event is dispatched again in the DOM with marking it as "handled in remote process" and GlobalKeyListener executes the shortcut.

Flags: needinfo?(masayuki)

Thanks Nakano-san for the detailed response.

It's definitely very helpful.
I'll go look into it (or maybe someone else too).

Thanks for taking your time to point me in the right direction!

Does this mean that we do not only need to change the processKey function but need to have a complete new API?

I think we have to expose some kind of callback when the events are not captured on the webpage, or reserved (e.g. Ctrl+T). I'll need to look into Gecko and GeckoView source code to see where I can implement this though.

I don't think that no capture can implement browser's keyboard shortcut.

If browser implements shortcut, we should intercept keyboard handling before handling GeckoView / SessionTextInput.

So I think we should add some APIs (KeyboardIntercept?) in GeckoRuntime.

Summary: Do not capture keyevent if webpage does not handle it → Add intercept keyboard event for keyboard shortcut in browser (was Do not capture keyevent if webpage does not handle it)
Summary: Add intercept keyboard event for keyboard shortcut in browser (was Do not capture keyevent if webpage does not handle it) → Add intercept keyboard event API for keyboard shortcut in browser (was Do not capture keyevent if webpage does not handle it)

(Or override onKJey* method in inherited GeckoView class in app)

You need to log in before you can comment on or make changes to this bug.