Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mediaqueries] Scroll bar type query #7697

Open
CendioOssman opened this issue Sep 5, 2022 · 10 comments
Open

[mediaqueries] Scroll bar type query #7697

CendioOssman opened this issue Sep 5, 2022 · 10 comments
Labels
mediaqueries-4 Current Work

Comments

@CendioOssman
Copy link

(spawned from Firefox discussion)

We (noVNC) need to be able to tell what kind of scroll bars the browser is presenting as we override some of the other methods for scrolling. For some cases, we then need to change the layout and behaviour of the page to return some scroll ability to the user. As this is about how the browser presents things, a media selector seems like the obvious choice of API.

noVNC is a VNC client, i.e. a way to access another (remote) computer. As such, it does some things that interfere with scrolling:

  • It sends all mouse wheel events to the remote computer, prevent wheel scrolling
  • It sends all touch events to the remote computer, preventing touch-and-drag scrolling
  • It sends all keyboard events to the remote computer, preventing keyboard scrolling

The only scroll method left is to use the scroll bar. However, this is not always available. We historically saw two types of scroll bars:

  1. Gutter scroll bars
  2. Purely visual scroll bars (no way to interact with them)

So, we found a method to detect the gutter, and if it wasn't present, we assumed a purely visual scroll bar and enabled some alternative methods for scrolling in our UI.

But there is now a third type of scroll bar:

  1. Overlay scroll bars

We are currently misdetecting these as purely visual scroll bars, as they have no gutter. Meaning, we activate our fallback methods needlessly.

Initially, only macOS had overlay scroll bars, but they are broken¹, so this misdetection turned out to be a feature there. However, Firefox now has properly working overlay scroll bars on Windows and Linux, causing practical issues for us.

¹ They only appear when another scrolling method is used, and as stated above, all other methods are overridden

@Loirooriol
Copy link
Contributor

Loirooriol commented Sep 5, 2022

A selector seems circular:

:overlay-scrollbar::-webkit-scrollbar {
  /* This forces classic scrollbar on WebKit and Blink */
  width: 12px;
  height: 12px;
  background-color: #aaa;
}

But it would be possible to have a media query to detect the default/preferred scrollbar type (even if it may be different in some elements).

@CendioOssman
Copy link
Author

A different layout issue caused by this unexpected change in scrollbar layout:

https://bugzilla.mozilla.org/show_bug.cgi?id=1790747

(content is now obscured by the scrollbar as the browser no longer allocates separate space for it)

Being able to style overlay vs gutter scrollbars differently could give page authors the tool to handle this.

@CendioOssman
Copy link
Author

A selector seems circular:

Sorry, confusion on my end. A media query was what I meant. Should I update the title?

@CendioOssman CendioOssman changed the title [selectors] selector for scroll bar types [mediaqueries] Scroll bar type query Oct 19, 2022
@CendioOssman
Copy link
Author

Changed the title now.

This might fit even better with the upcoming container queries, but I'll go with the classic method for now.

@bramus
Copy link
Contributor

bramus commented Nov 14, 2022

This type of media query came up during web-platform-tests/interop-2022-viewport#15

Combined with env(scrollbar-inline-size) – which would return the default classic scrollbar size – authors could combine both in order to work around the “100vw is causing pointless horizontal scrollbars” problem:

@media (scrollbars: overlay) {
   --100vw: 100vw;
}
@media (scrollbars: classic) {
   --100vw: calc(100vw - env(scrollbar-inline-size));
}

el {
  width: var(--100vw);
}

This “solution”, however, does assume that the root element is currently showing a vertical scrollbar.

@Loirooriol
Copy link
Contributor

@bramus At that point just use scrollbar-gutter: stable?

@CendioOssman
Copy link
Author

I am uncertain if that was a general or suggestion for this issue or not, but scrollbar-gutter unfortunately isn't able to disable overlay scrollbars. At least not for Firefox on Linux.

@Loirooriol
Copy link
Contributor

Not a general suggestion for this issue, just for bramus' testcase. scrollbar-gutter: stable having no effect with overlay scrollbars matches the @media logic.

@fantasai fantasai added the mediaqueries-4 Current Work label Nov 16, 2022
@bramus
Copy link
Contributor

bramus commented Nov 17, 2022

@bramus At that point just use scrollbar-gutter: stable?

Using scrollbar-gutter: stable currently does not affect the size of 100vw (ref. #5254), so you still need to subtract env(scrollbar-inline-size) from it. When using stable both-edges you even need to subtract it twice. Also see this thread with some of my findings.

@Loirooriol
Copy link
Contributor

But you wouldn't use 100vw, you would just use 100% or the initial auto and let it stretch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mediaqueries-4 Current Work
Projects
None yet
Development

No branches or pull requests

4 participants