Re: [svgwg] What is the unit type after setting an SVGAngle or SVGLength's value (#478)

Before I make the edits, it would be nice to resolve on the remaining undefined behavior.

To get us started, I put together a test of current browser behavior:

https://codepen.io/AmeliaBR/collab/a66bdb394be42522df116f8e583d1c6c?editors=0011

Results: inter-browser inconsistencies!

Regarding font-relative units on detached SVGLength objects:

- Chrome throws an error if you try to get or set the `value` when the unit type is font-relative
- Firefox throws an error if you try to get or set the `value` when the unit type is *anything* other than `px`
- Edge uses the default font metrics (e.g., 16px per em) to convert the font-relative unit to user units

I'd be happy with either the Chrome or Edge behavior.


More test regarding new units:
https://codepen.io/AmeliaBR/pen/569413ffe5ca29180aeecdf44942d29e?editors=0011

- All three browsers tested error out when setting the `valueAsString` of a detached object to `1vh` (last set of readings from the previous test)

- Chrome and Edge have no problem _drawing_ an SVG shape with lengths set in `vh`.

- Firefox treats the attribute as invalid.  In combination with the error on the setter, the DOM object can never be associated with the `vh` unit

- Chrome also has no problem computing the `value` and `valueInSpecifiedUnits` of the attribute, when getting or setting (on a length associated with a rendered element), but returns the string "0" for `valueAsString`, and still errors when setting `valueAsString = "15vh"`.

- Edge 17 crashes the browser tab when you try to manipulate an SVGLength that reflects an attribute that uses `vh` units, so I never got a chance to check the console for details.

I'd prefer the Chrome behavior except for getting/setting `valueAsString`.  The getter is returning a seemingly valid but incorrect/inconsistent result. It should either:

-  generate the string based on the internal units, even if those units don't have a `unitType` in the SVG DOM.
- return an obvious error value (empty string, null)
- error out

Similarly, it seems a shame that the `valueAsString` setter is erroring out when the browser has no problem parsing the same value in the attribute/CSS property.

-- 
GitHub Notification of comment by AmeliaBR
Please view or discuss this issue at https://github.com/w3c/svgwg/issues/478#issuecomment-459929674 using your GitHub account

Received on Saturday, 2 February 2019 03:04:21 UTC