Re: [css-houdini-drafts] [css-typed-om] Provide a way to resolve a CSSUnitValue and CSSMath* to a pixel value

The Houdini Task Force just discussed `Resolve values to a px with external information`.

<details><summary>The full IRC log of that discussion</summary>
&lt;TabAtkins> Topic: Resolve values to a px with external information<br>
&lt;TabAtkins> https://github.com/w3c/css-houdini-drafts/issues/798<br>
&lt;TabAtkins> github: https://github.com/w3c/css-houdini-drafts/issues/798<br>
&lt;heycam> TabAtkins: if all of the units you have in a math value are compatible with pixels e.g. then you can always resolve them to a single px<br>
&lt;heycam> ... if you have combinatons of values that aren't directly resolvable, there's no way to resolve them<br>
&lt;heycam> ... since the custom layout API works mostly in px values, it would be useful to give people more direct control over how they can simplify them down to px<br>
&lt;TabAtkins> https://github.com/w3c/css-houdini-drafts/issues/798#issuecomment-415555133<br>
&lt;heycam> ... so we add an options bag to the to and toSum functions<br>
&lt;heycam> ... giving extra information for resolving the values<br>
&lt;heycam> ... in particular, the element being resolved on (for ems etc.), the property it's on (so font-size can properly resolve to parent element), and what a % should resolve to<br>
&lt;heycam> ... going with this explicit % resolution thing to avoid some problems with some properties resolving %s against different sizes<br>
&lt;heycam> ... this makes it more explicit with cases like the layout API, where you have an available space, and you can just pass that in rather than finding a property to pretend it's being resolved as<br>
&lt;heycam> ... I think that lets us resolve all the units<br>
&lt;heycam> ... in particular, a comment further down suggests that we don't have a default value, so if you don't pass an element, resolve like MQs do, with no context<br>
&lt;heycam> ... right now, if you call to() without this information and it needs it, it throws<br>
&lt;heycam> emilio: the layout API doesn't have access to any element, right?<br>
&lt;heycam> TabAtkins: yes<br>
&lt;heycam> emilio: can we instead pass what the function depends on explicitly? what's the expected thing if you pass an element to there, I assume you have to do style updates etc.?<br>
&lt;heycam> ... what happens if that element's not in the flat tree etc.?<br>
&lt;heycam> ... would be nice to be more explicit about which data you're depending on<br>
&lt;heycam> ... then people can use the no context thing without having magic<br>
&lt;heycam> TabAtkins: there's a lot of information.  which font's being used.  it's possible to enumerate this<br>
&lt;heycam> emilio: instead of getting a font and doing font matching, you may as well .... I guess there's no way to get ex height without script<br>
&lt;heycam> TabAtkins: a possibility is to allow you to pass an element, but also enumerate all the things that the various relative units can depend on<br>
&lt;heycam> ... and if you don't pass a unit, that's the info you have to work with<br>
&lt;heycam> ... and if you use a unit but no way to determine what that is, continue to throw<br>
&lt;heycam> emilio: if you need to download fonts to make this work....<br>
&lt;heycam> TabAtkins: that's what we have to do<br>
&lt;heycam> ... normally you wait for a computed value, which triggers all that<br>
&lt;heycam> emilio: that only happens if you actually lay out the element<br>
&lt;heycam> TabAtkins: and the assumption here is you are doing something layouty but not with an element<br>
&lt;heycam> emilio: let's say you call this function from a layout worklet with a given font<br>
&lt;heycam> ... does the layout trigger the font load somewhere?<br>
&lt;heycam> TabAtkins: good question<br>
&lt;heycam> ... possibly<br>
&lt;heycam> emilio: does it do it sync? probably not<br>
&lt;heycam> ... you can't make it sync<br>
&lt;heycam> TabAtkins: I think then we should remove the element resolver, figure out what relative units we can easily resolve on, e.g. asking for font-size, other font relative ones are a bit hard for now<br>
&lt;heycam> ... and then if you try to use an ex unit to px, we just throw<br>
&lt;heycam> ... then we can remove the property too<br>
&lt;heycam> fremy: if you still want the behavior to pass an element, you can have another element, and ti returns the properties you would fill in<br>
&lt;heycam> TabAtkins: one of those dictionaries<br>
&lt;heycam> dbaron: I'm not convinced you canremove the property<br>
&lt;heycam> ... if you're doing it from the element, you still need to know font-size / line-height behave differently for em and lh units<br>
&lt;heycam> TabAtkins: I'm suggesting that just like the 100% line, where you explicitly indicate what the resolves to, you just supply what them resolves to<br>
&lt;heycam> ... and then also supply a function that can extract that from an element automatically<br>
&lt;heycam> fremy: CSSNumericValue -- is that calc or more stuff?<br>
&lt;heycam> TabAtkins: everything<br>
&lt;heycam> fremy: can just create a 1em and call to<br>
&lt;heycam> emilio: layout API functions could need 1vmax, you need to expose viewport size to those functions<br>
&lt;heycam> ... not sure if you want to?<br>
&lt;dbaron> The function to extract from an element automatically would need a property.<br>
&lt;heycam> iank_: no access to viewport info<br>
&lt;heycam> iank_: it's not necessary<br>
&lt;heycam> ... the side effect of exposiong that info is that when you resize that viewport, you'd need to call every layout function<br>
&lt;heycam> ... since it's a side input<br>
&lt;heycam> TabAtkins: this would be an implicity dependency<br>
&lt;heycam> ... unless we made it explicit somehow<br>
&lt;heycam> fremy: we could add a function in the worklet, before calling it viewport sizes are 0, and only after you can use it...<br>
&lt;heycam> TabAtkins: we have a case for later registrationt of dependencies<br>
&lt;heycam> iank_: probably you want to do this in the layout registration dictionry<br>
&lt;heycam> ... you don't know which global scope you're doing to run it in<br>
&lt;heycam> fremy: the other option is to create custom properties that would be 1vmin, etc., type them to be lengths, then you'll get the value<br>
&lt;heycam> ... it's a big handwavy but it does work<br>
&lt;heycam> iank_: if this becomes a common pattern, in layout options, say that resolve vw/vh against the real thing<br>
&lt;heycam> ... but part of the precedent for resolving to 0 is what happens when you set a font-size in an offscreen canvas context, it resolves to 0<br>
&lt;heycam> TabAtkins: that's different from how MQs work<br>
&lt;heycam> iank_: not saying that's good or bad but that's the precedent<br>
&lt;heycam> TabAtkins: I think that's all the feedback I need; I will come back with a more mature proposal in the future<br>
</details>


-- 
GitHub Notification of comment by css-meeting-bot
Please view or discuss this issue at https://github.com/w3c/css-houdini-drafts/issues/798#issuecomment-432976756 using your GitHub account

Received on Thursday, 25 October 2018 09:16:36 UTC