Closed Bug 889964 Opened 11 years ago Closed 8 years ago

"border-image-repeat: round" uses ceil instead of round in tile width calculation

Categories

(Core :: Web Painting, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: jbroman, Assigned: ethlin)

References

()

Details

Attachments

(3 files, 6 obsolete files)

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36

Steps to reproduce:

Launch Firefox (I used Nightly) and open a document in there is a border image with the 'round' repeat style, and the number of tiles which fit in the available length of a border is between k and k+1/2 for some integer k.

A trivial such example is
data:text/html,<div style="border:27px solid transparent; border-image:url(http://www.w3.org/TR/css3-background/border.png) 27 27 round; width:28px"></div>


Actual results:

One extra copy of the tile is rendered, and all tiles are rescaled to fit that extra copy.

In the example above, two narrow yellow diamonds are rendered instead of a single yellow diamond in each of the top and bottom borders (for a total of 8 diamonds visible).


Expected results:

The number of tiles to be rendered should conform to the specification:

"If X ≠ 0 is the width of the image after step one and W is the width of the background positioning area, then the rounded width X' = W / round(W / X) where round() is a function that returns the nearest natural number (integer greater than zero)." (http://www.w3.org/TR/css3-background/).

This formula applies to the border as well as background since the spec for border-image-repeat says "If the first keyword is ‘round’, the top, middle and bottom images are resized in width, so that exactly a whole number of them fit in the middle part of the border-image area, exactly as for ‘round’ in the ‘background-repeat’ property.".

In example given above, it is expected that one yellow diamond appear on each of the top and bottom edges of the border (for a total of 6 diamonds visible).

This appears to be a result of using "ceil" in the DrawBorderImageComponent in layout/base/nsCSSRendering.cpp, when what is desired is "round" (restricted to positive integers to avoid division by zero).
Component: General → Layout: View Rendering
OS: Linux → All
Hardware: x86_64 → All
Version: 25 Branch → Trunk
The code has now moved to the ComputeTile helper function just above DrawBorderImageComponent.

:ethlin, any chance you could fix this one as well given that you're in the area?  (It looks like this will make us match Chromium on the testcase; I didn't test Edge, although it's probably worth checking.)
Flags: needinfo?(ethlin)
Sure.
Assignee: nobody → ethlin
Flags: needinfo?(ethlin)
Attached patch Part 1. Fix round calculation. (obsolete) — Splinter Review
The round calculation of border-image-repeat is wrong. I applied the background-repeat calculation to fix it. I will write testcase later.
Comment on attachment 8758171 [details] [diff] [review]
Part 1. Fix round calculation.

Review of attachment 8758171 [details] [diff] [review]:
-----------------------------------------------------------------

I hope you don't mind the drive-by comment, but it seems like this should have changes to both the horizontal and vertical cases.

::: layout/base/nsCSSRendering.cpp
@@ +5409,5 @@
>      tile.width = aUnitSize.width;
>      break;
>    case NS_STYLE_BORDER_IMAGE_REPEAT_ROUND:
>      tile.x = aFill.x;
> +    tile.width = ComputeRoundedSize(aUnitSize.width, aFill.width);

There's a similar computation for tile.height a few lines down that presumably needs the same change.
(In reply to jbroman from comment #4)
> Comment on attachment 8758171 [details] [diff] [review]
> Part 1. Fix round calculation.
> 
> Review of attachment 8758171 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> I hope you don't mind the drive-by comment, but it seems like this should
> have changes to both the horizontal and vertical cases.
> 
> ::: layout/base/nsCSSRendering.cpp
> @@ +5409,5 @@
> >      tile.width = aUnitSize.width;
> >      break;
> >    case NS_STYLE_BORDER_IMAGE_REPEAT_ROUND:
> >      tile.x = aFill.x;
> > +    tile.width = ComputeRoundedSize(aUnitSize.width, aFill.width);
> 
> There's a similar computation for tile.height a few lines down that
> presumably needs the same change.

Okay. Thanks.
Attached patch Part 1. Fix round calculation. (obsolete) — Splinter Review
I applied the background-repeat calculation to border-image's round calculations.
Attachment #8758171 - Attachment is obsolete: true
Attachment #8758547 - Flags: review?(dbaron)
I added a testcase for border-image-repeat: round for this problem.
Attachment #8758550 - Flags: review?(dbaron)
Remove redundant settings.
Attachment #8758550 - Attachment is obsolete: true
Attachment #8758550 - Flags: review?(dbaron)
Attachment #8758556 - Flags: review?(dbaron)
Comment on attachment 8758547 [details] [diff] [review]
Part 1. Fix round calculation.

># HG changeset patch
># User Ethan Lin <ethlin@mozilla.com>
>
>Bug 889964 - Part 1. Fix the caluculation of boarder image: round. r=dbaron

Please fix the spelling of "calculation" (remove the first "u") and "border-image" (no "a", with "-")

r=dbaron with that
Attachment #8758547 - Flags: review?(dbaron) → review+
Comment on attachment 8758556 [details] [diff] [review]
Part 2. Add reftest for border-image-repeat: round

>+    <meta name="assert" content="The test checks whether border-image-repeat: 'round' works correctly or not.">

"works correctly or not" should be clearer.  Perhaps "uses the correct rounding formula"?

Does the test fail without the patch?  And does it test the <1 case (in particular, with something that's less than 0.5)?  If not, it should (for both questions).


Please put the test in the background/ directory instead of creating a new border-image/ directory.

(Note that for the creation of the border-image subdirectory to be correct, you would have needed to add to the parent directory's reftest.list.  But you shouldn't do that.)

r=dbaron with that
Attachment #8758556 - Flags: review?(dbaron) → review+
(In reply to David Baron :dbaron: ⌚️UTC-7 (review requests must explain patch) (vacation June 4-12) from comment #10)
> Comment on attachment 8758556 [details] [diff] [review]
> Part 2. Add reftest for border-image-repeat: round
> 
> >+    <meta name="assert" content="The test checks whether border-image-repeat: 'round' works correctly or not.">
> 
> "works correctly or not" should be clearer.  Perhaps "uses the correct
> rounding formula"?
> 
Okay, I'll change that.

> Does the test fail without the patch?  And does it test the <1 case (in
> particular, with something that's less than 0.5)?  If not, it should (for
> both questions).
> 
The test will fail without the patch, but it doesn't test <1 case. I will add <1 case.
> 
> Please put the test in the background/ directory instead of creating a new
> border-image/ directory.
> 
Okay, I'll move it.

> (Note that for the creation of the border-image subdirectory to be correct,
> you would have needed to add to the parent directory's reftest.list.  But
> you shouldn't do that.)
> 
> r=dbaron with that
Address :dbaron's comment.
Attachment #8758547 - Attachment is obsolete: true
I added another test case for <1 and moved the tests to background folder.
Attachment #8758556 - Attachment is obsolete: true
Attached patch Part 3. Turn on background tests (obsolete) — Splinter Review
I forget to include the reftest.list in bug 548372. Turn on it so try server will run it.
It was a wrong patch. Correct it.
Attachment #8759573 - Attachment is obsolete: true
Comment on attachment 8759579 [details] [diff] [review]
Part 3. Turn on background tests

Though, actually, instead of adding a new line at the bottom, this should uncomment:

# include background3/reftest.list

and remove the "3". in both that line and the comment line above it.
(In reply to David Baron :dbaron: ⌚️UTC-7 (review requests must explain patch) (vacation June 4-12) from comment #17)
> Comment on attachment 8759579 [details] [diff] [review]
> Part 3. Turn on background tests
> 
> Though, actually, instead of adding a new line at the bottom, this should
> uncomment:
> 
> # include background3/reftest.list
> 
> and remove the "3". in both that line and the comment line above it.

Okay, I'll change it.
Address :dbaron's comment.
Attachment #8759579 - Attachment is obsolete: true
Attachment #8759931 - Flags: review+
Keywords: checkin-needed
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: checkin-needed
Component: Layout: View Rendering → Layout: Web Painting
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: