whatwg / html

HTML Standard
https://html.spec.whatwg.org/multipage/
Other
8.15k stars 2.67k forks source link

A read-only Navigator state for visibility of a virtual keyboard #4896

Open mustaqahmed opened 5 years ago

mustaqahmed commented 5 years ago

A Chromium bug for virtual keyboards asks for a way to detect the visibility of virtual keyboards on touch devices. This feature is requested by Google Docs. This is a follow-up proposal for #4876.

I am proposing a read-only attribute navigator.virtualKeyboardActive = {true, false} to solve this.

There seems to be some implementation challenges as noted by @dtapuska in the other spec issue above. I am cross-posting his post here:

We didn't expose a navigator.virtualKeyboardActive attribute in the past because

  • there was no reliable way on Android to tell if the keyboard was up
  • it might leak information cross frames about inputting text
  • what does it mean for floating keyboards on platforms that support them (ie. Windows)
mustaqahmed commented 5 years ago

An alternative (or additional) approach would be firing an event like virtualkeyboardstatechange which would let web-apps react to the visibility change more easily. Originally suggested by @NavidZ.

All the challenges mentioned in the last post apply to this approach too.

Yay295 commented 5 years ago

What would this be used for? Why does a website/app need to know the state of the keyboard? Should it also know whether I have a physical keyboard plugged into my computer or not?

rniwa commented 5 years ago

Yeah, it's unclear why this API is needed. Visual viewport API lets you query whether there is any part of the viewport that's being obscured by virtual keyboard.

It's strange to want to know the presence of a floating keyboard or a hardware keyboard since even native apps don't usually change their UI due to their presence.

@whsieh

snianu commented 4 years ago

@mustaqahmed @rniwa @smaug---- Could you please give us some feedback on this proposal that talks about firing an overlaygeometrychange event that would give the web authors details about the geometry of the VK and in that way web authors could also detect whether the VK was raised/dismissed? This is especially useful for dual screen devices where the VisualViewport won't be helpful for the web authors as described in the explainer with screenshots. Also, as far as floating keyboard is concerned, Please see this section for more details.