Open Bug 381920 Opened 15 years ago Updated 6 years ago

physical units rounding error

Categories

(Core :: Layout, defect)

defect
Not set
normal

Tracking

()

People

(Reporter: fantasai.bugs, Unassigned)

Details

(Keywords: regression, testcase)

Attachments

(1 file)

602 bytes, application/xhtml+xml
Details
I'm getting off-by-one pixel errors when using physical layout units like points. It doesn't happen with pixels.

Tested on recent trunk builds on Linux. stefanh sees red on a May 19th build on Windows as well.

This is a regression from the 1.8 branch; Firefox 1.5 passes the test just fine.
Attached file testcase
sorry, s/windows/mac/
I think this is invalid; we're rounding border widths to pixels now.
Whatever we're doing, it should be consistent among borders, margins, and padding. -2pt + 2pt should equal zero.
I actually think it shouldn't be consistent among them:  we don't want to round percentage margins to the nearest pixel, because we want them not to add to more than 100%.  (Though maybe we could round non-percentage margins and padding to the nearest pixel.)
Flags: blocking1.9?
The way I would put it is that the second box has a top margin of -24pt, but 20pt + roundToPixel(2pt) + roundToPixel(2pt) != 24pt (and also != roundToPixel(24pt)).  Therefore, the tops of the two boxes aren't the same.
Eli, if authors expect something to work, and it's worked reliably in the past, we need to be pretty hesitant about just telling them they're wrong.  I think we should consider rounding non-percentage margins and padding.  Although then we'd face the issue of whether we want to round heights and widths too.  Maybe we do...
http://www.w3.org/TR/CSS21/cascade.html#actual-value

I think that we should use actual values for rendering, by it, this problem can be occurred.

But in layout time, should we use used values?
http://www.w3.org/TR/CSS21/cascade.html#used-value

Now, we use actual values in borders at layout time. But if we use it, following example is rendered as overlapped boxes.

div {
  margin: 0;
  border: 0.1px;
}

<body>
  <div/>
  <div/>
</body>

The top border of second div will overlap to the bottom border of first div. And we need to determine the borders should be rendered from border edge or padding edge.

I think that we should not use used values excepted that the percentage values at layout time.
(In reply to comment #7)
> Eli, if authors expect something to work, and it's worked reliably in the past,
> we need to be pretty hesitant about just telling them they're wrong.  I think
> we should consider rounding non-percentage margins and padding.

That wouldn't solve this bug, though. Well, it might solve this testcase but not the general issue.
(In reply to comment #7)
> Eli, if authors expect something to work, and it's worked reliably in the past,
> we need to be pretty hesitant about just telling them they're wrong.  I think
> we should consider rounding non-percentage margins and padding.  Although then
> we'd face the issue of whether we want to round heights and widths too.  Maybe
> we do...

No amount of additional rounding will fix this problem. It's a natural consequence of Bug 287624.  (I thought the whole point of that bug was that getting consistent border widths was decided to be a higher priority than keeping tests like this working.)
(In reply to comment #8)
> I think that we should use actual values for rendering, by it, this problem can
> be occurred.
> 
> But in layout time, should we use used values?\

So you're suggesting backing out Bug 287624 and rounding borders widths at paint time?  That a possibility, although then you'd probably get people complaining about borders overlapping their content.
borders generally don't overlap content because people generally also put padding when they have borders and text has a lot of whitespace in it anyway. You're more likely to get overlapping or gapping between adjacent borders, or reducing/increasing margin or padding by 1px.
(In reply to comment #11)
> (In reply to comment #8)
> > I think that we should use actual values for rendering, by it, this problem can
> > be occurred.
> > 
> > But in layout time, should we use used values?\
> 
> So you're suggesting backing out Bug 287624 and rounding borders widths at
> paint time?  That a possibility, although then you'd probably get people
> complaining about borders overlapping their content.

I think that the current approach is better than the using used values at layout time. But it can create this issue. I think that if we use same way for margin/padding/height, we will have more issues.

div#first {
  border: 0.4px;
  margin: 0.4px;
  padding: 0.4px;
  height: 0.4px;
}

What result is hoped for this case?
# the current code rounding the borders to 1px (* 2).
(In reply to comment #12)
> borders generally don't overlap content because people generally also put
> padding when they have borders and text has a lot of whitespace in it anyway.

We have following case:

div {
  border: 0.5px;
  margin: 0;
  padding: 0;
}

<div>
  <div/>
</div>

The outer div's border will be overwritten by inner div's border if we use the used value for layout.
Oops, right, what I proposed would only fix the case where an author is using a negative margin to match a single border, so, yeah, I agree with wontfix.
Flags: blocking1.9? → blocking1.9-
You need to log in before you can comment on or make changes to this bug.