We have a component with a slider where the user can drag it to select some percentage. The JavaScript calculates the X coordinate as a percentage of the total width of the slider. This works fine as long as the widths are not too small. On a specific page this width is declared as width: calc(100% - 200px)
. Before HtmlUnit version 2.44.0 the CssParser would error on this statement and just drop it, making the width effectively auto
. This was fine for our tests since it was something non-0. But since HtmlUnit 2.44.0 the calc(100% - 200px)
value is accepted. But this gets effectively evaluated to 0px
.
I'm not entirely sure how or where to fix this. I get extremely confused if I look at the CSS size calculations :)
As best I can tell, the problem lies somewhere here:
ComputedCSSStyleDeclaration.getWidth()
calls pixelString(...)
on a custom CssValue
element.
calc(100% - 200px)
), but since it doesn't end with "px", it calls pixelValue(...)
instead
CssValue.get(...)
ComputedCSSStyleDeclaration.getWidth().CssValue.get(...)
(around line 916) it retrieves the "width" style, which is calc(100% - 200px)
.
auto
, it would return window default value (1256px), but it is not.calc(100% - 200px)
unmodifiedauto
and not empty, it returns pixelValue("calc(100% - 200px)")
"px"
, and returns "0px"
I honestly wouldn't know what the fix would be. Maybe CSSStyleDeclaration.pixelValue(Element, CssValue, boolean)
should detect s.startsWith("calc(")
or something and return value.getWindowDefaultValue()
? I'm not sure what the difference between getDefaultValue()
and getWindowDefaultValue()
is, but getDefaultValue()
also returns 0, which is also wrong. Note that with with a value of auto
CSSStyleDeclaration.pixelValue(Element, CssValue, boolean)
would return getDefaultValue() == 0
, but if it was auto
it would not get here in the first place, because ComputedCSSStyleDeclaration.getWidth().CssValue.get(...)
would've already returned the window default value.
Tested with HtmlUnit 2.50.0
If needed I can probably produce a sample HTML page and HtmlUnit test fragment showing the problem.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too