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)
Tracking
(Not tracked)
People
(Reporter: lucius, Assigned: m_kato)
References
(Blocks 1 open bug)
Details
Attachments
(2 external files, 1 obsolete file)
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.
- Press any key on an external keyboard.
- 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.
| Comment hidden (advocacy) |
Comment 2•2 years ago
|
||
The severity field is not set for this bug.
:owlish, could you have a look please?
For more information, please visit BugBot documentation.
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Updated•2 years ago
|
Comment 3•2 years ago
|
||
Could you please update the severity?
This issue blocks the long-awaited “keyboard shortcut” improvement 1794664.
| Assignee | ||
Comment 4•2 years ago
|
||
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.
| Assignee | ||
Comment 5•2 years ago
|
||
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?
Comment 6•2 years ago
|
||
| important | ||
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.
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!
Comment 8•2 years ago
|
||
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.
| Assignee | ||
Comment 10•1 year ago
|
||
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.
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 11•1 year ago
•
|
||
(Or override onKJey* method in inherited GeckoView class in app)
| Assignee | ||
Comment 12•1 year ago
|
||
I guess that we have to add GeckoView version of GlobalKeyListener or something. Then,
- a API to register shortcut key to callback default (In GeckoRuntime?)
- a Callback if content doesn't prevent default (In GeckoSession.ContentDelegate?)
| Assignee | ||
Updated•1 year ago
|
Updated•1 year ago
|
| Assignee | ||
Comment 14•6 months ago
|
||
When implementing shortcut key in GeckoView, browser has to know whether
web content doesn't handle shotcut key. Currently, GeckoView is
multi-process architecture, so Viw.onKey* cannot return false if its
dispatches to web content.
This adds GeckoSession.UnhandledKeyEventDelegate delegation to notify
app when web content doesn't handle key event.
Updated•6 months ago
|
| Assignee | ||
Comment 15•5 months ago
|
||
I would like to add a new feature to Android Components that allows web
content to not prevent browser shortcuts such as Ctrl+R.
This bug doesn't includes global shortcuts such as Ctrl+T, Ctrl+W, etc.
It will be other bugs.
Description
•