-
Notifications
You must be signed in to change notification settings - Fork 677
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
[css-values-4] Add new relative length units that are relative to the size of the system cursor #8315
Comments
Note that the cursor image may have some transparent areas, so visually the cursor can look smaller. cursor: url(http://www.javascriptkit.com/dhtmltutors/cursor-hand.gif) 10 4, auto So even if the cursor image is 25px wide, it will only extend 15px to the right, so that's the amount you probably want. |
Maybe instead of new units this could be solved via CSS Anchor Positioning. A new So positioning the tooltip could then look like this: .tooltip {
position: absolute;
left: calc(anchor(cursor right) + 10px);
top: calc(anchor(cursor bottom) + 10px);
} Not sure whether the cursor's hotspot really needs to be taken into account here but that could surely be expressed via keywords as well. The keyword probably would have to compute to itself in order to avoid fingerprinting. The big benefits of this approach are that it's a pure CSS solution and it's very concise in comparison to the JS solution. Also, Anchor Positioning already provides fallbacks for the case when the element would overflow its containing block. Sebastian |
I though about It but the problem is that this is dynamic value and could potentialy be used in few places at once and have diffrent values as You would want It to be stuck at first computed value or something like this as when You open context menu You want this menu to be anchored to this exact point and not move when moving cursor |
But if it affects the position, a script can always use |
Tangentially related: #4691, which would expose the scrollbar size. |
Though context menus are a totally different use case. And they normally also don't require to take the cursor size into account because they open at the pixel the user clicked.
Right. It would still be possible to calculate the size of the cursor and with that infer the OS. I guess there's no way around that then unless Sebastian |
Thanks for your sharing your ideas everyone!
The goal of this proposal is to expose the system cursor size, which web developers cannot know at all for the moment. If the CSS is altering the cursor (which is not recommended for accessibility), then the developer should know the characteristics of the cursor they are adding, which we cannot guess, so I think that is a case where using hardcoded values instead of the extra capabilities added by this proposal would be legitimate? Am I missing something here?
This is an interesting suggestion, in particular I think it reads well. This adds more new behaviors than the new units though: To me this looks more complex to implement than the first proposal as it implies having a pseudo-anchor element for the cursor that moves with every mouse move -- something that users currently simulate with JavaScript mouse move events. But the implementation complexity may be worth it, if the extra behaviors are desirable? |
Even if authors know the size of the image they are providing, the final cursor may be scaled:
Also, different elements can have different cursors, and even if they have the same size, they may have different |
As a matter of fact, trying to implement this change for Firefox's UI made me realize how important this comment was:
This is true even for "official" Windows cursors, e.g. the usual arrow pointer is a 32x32 bitmap with 19 transparent columns on the right side, 13 transparent rows at the bottom. So indeed I now understand why exposing bitmap width and height (e.g. 32x32) is not enough, instead we would ideally need to expose 4 coordinates that define a "non-transparent box" for the cursor within the bitmap. Sebastian's proposal is quite appealing in that regard although I'm still unsure about the dynamic part. |
What I dislike about this proposal is that it doesn't solve the original use case presented unless Javascript is also involved. To actually solve the use case, you would first need something like I'd also like to point out that there were proposals for a similar unit, |
The idea was that Sebastian |
[Related bug in Firefox]
There are currently two ways for web developers to get tooltip behavior for a website, as listed in this example StackOverflow thread:
use a
title
attribute, which yields a standardized text tooltip managed by the browser;create a CSS-customizable tooltip, listen to mouse move events with JavaScript to dynamically change the position of the tooltip, reveal it when some other element is hovered.
When computing the new position for a customizable tooltip with JavaScript, web developers will typically add an offset to account for the system cursor. However, because the system cursor size is not exposed, the offset they add is arbitrary and cannot account for varying cursor sizes. This causes problems for accessibility, as visually impaired users may set their cursors to a bigger size than the average and have their cursor cover the contents of the tooltip -- thus part of the information is not shown for them.
This can be seen in the StackOverflow thread listed above, where two different web developers answering the same question answered with a different arbitrary offset:
This issue proposes to add two new relative length units.
Browsers may let the option to users to use up-rounded or predefined system cursor sizes to limit fingerprinting.
The first example from above may then be changed to the following:
The second example could be partially adapted ...
... but, as you can see, the proposed change would not be enough on its own to completely adapt the second example. This code is trying to assess from JavaScript whether the tooltip would be partially positioned outside the limits of the rendered page and not get rendered completely -- and adjust its position accordingly. For this example to not use any arbitrary offset, I believe we would have to expose the system cursor size directly to JavaScript -- so I'd like to hear your opinions regarding this possibility as well.
Thanks!
The text was updated successfully, but these errors were encountered: