Flexbox items don't seem to be getting subpixel positions when rounding. See the URL for an example. It's a flexbox that is 101 pixels wide and has 2 children, each should be the same size (50.5px each). Instead, they are both 51px.
For reference, in RenderFlexibleBox.cpp, we use setOverrideLogicalContent{Width,Height}() to set the width/height of children after we have computed the desired value. We use setLocation() to position each child. This happens in RenderFlexibleBox::layoutAndPlaceChildren.
It would be interesting to know where the rounding happens as both values seems to be rounded independently of each other.
Looking into it quickly it seems like the values are rounded before being passed into the layoutAndPlaceChildren method in the childSizes vector.
(In reply to comment #2)
> The problem might be the following code in RenderFlexibleBox::resolveFlexibleLengths:
>
> if (availableFreeSpace > 0 && totalFlexGrow > 0 && flexSign == PositiveFlexibility && isfinite(totalFlexGrow))
> childSize += static_cast<int>(lroundf(availableFreeSpace * child->style()->flexGrow() / totalFlexGrow));
> else if (availableFreeSpace < 0 && totalWeightedFlexShrink > 0 && flexSign == NegativeFlexibility && isfinite(totalWeightedFlexShrink))
> childSize += static_cast<int>(lroundf(availableFreeSpace * child->style()->flexShrink() * preferredChildSize / totalWeightedFlexShrink));
That seems likely. I'll see if I can track down the history of the lroundf usage.
turns out it is not quite that easy. Getting rid of that rounding makes both boxes return 50.5 and prevents the yellow box from being painted outside the container but it does cause the blue and yellow boxes to overlap by one pixel.
Changing childLocation on line 1022 from IntPoint to LayoutPoint, in addition to getting rid of the rounding, seems to fix the issue. Might be other edge cases though.
(In reply to comment #6)
> Changing childLocation on line 1022 from IntPoint to LayoutPoint, in addition to getting rid of the rounding, seems to fix the issue. Might be other edge cases though.
Magical! When I make both those changes, all the flexbox tests pass for me. I'll add a layout test for this and upload as a new patch. Thanks for the help!
(In reply to comment #8)
> (In reply to comment #6)
> > Changing childLocation on line 1022 from IntPoint to LayoutPoint, in addition to getting rid of the rounding, seems to fix the issue. Might be other edge cases though.
>
> Magical! When I make both those changes, all the flexbox tests pass for me. I'll add a layout test for this and upload as a new patch. Thanks for the help!
Nice! Glad I was able to help.
2012-07-24 15:33 PDT, Emil A Eklund
2012-07-25 16:45 PDT, Tony Chang