Bug 172901 - Percentages are calculated wrong in SVG transform CSS property
Summary: Percentages are calculated wrong in SVG transform CSS property
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Simon Fraser (smfr)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-04 00:47 PDT by kari.pihkala
Modified: 2017-06-06 10:44 PDT (History)
7 users (show)

See Also:


Attachments
CSS Transform Test Case (655 bytes, image/svg+xml)
2017-06-04 00:47 PDT, kari.pihkala
no flags Details
Patch (10.76 KB, patch)
2017-06-04 22:07 PDT, Simon Fraser (smfr)
no flags Details | Formatted Diff | Diff
Symbol Test Case (882 bytes, image/svg+xml)
2017-06-04 22:47 PDT, kari.pihkala
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description kari.pihkala 2017-06-04 00:47:12 PDT
Created attachment 311955 [details]
CSS Transform Test Case

The transform CSS property calculates percentages wrong in SVG. They should be relative to the parent viewport, but they seem to be relative to the element’s size. This can be seen by changing the blue rectangle’s width in the test case.

In the test case, the blue rectangles should be close to the middle line. The blue one on the right side of the line, the aqua colored at the center. The rectangles should follow the line if the browser window is resized.

Firefox can display the test case correctly.
Comment 1 kari.pihkala 2017-06-04 00:53:20 PDT
Chrome has a similar bug: https://bugs.chromium.org/p/chromium/issues/detail?id=729386
Comment 2 Simon Fraser (smfr) 2017-06-04 19:21:11 PDT
In a recent Safari Tech Preview, we now support transform-box and fix the behavior of percentages. However, this seems to be broken if the <svg> has no explicit viewBox.
Comment 3 Simon Fraser (smfr) 2017-06-04 22:07:51 PDT
Created attachment 311981 [details]
Patch
Comment 4 kari.pihkala 2017-06-04 22:47:14 PDT
Created attachment 311983 [details]
Symbol Test Case

Also <symbol> elements are affected. I've attached Symbol Test Case for it. I think your patch will fix them as well.
Comment 5 Simon Fraser (smfr) 2017-06-04 22:57:03 PDT
Yeah, that testcase looks fine with the fix.
Comment 6 WebKit Commit Bot 2017-06-04 23:09:04 PDT
Comment on attachment 311981 [details]
Patch

Clearing flags on attachment: 311981

Committed r217776: <http://trac.webkit.org/changeset/217776>
Comment 7 WebKit Commit Bot 2017-06-04 23:09:06 PDT
All reviewed patches have been landed.  Closing bug.
Comment 8 Darin Adler 2017-06-06 09:40:20 PDT
Comment on attachment 311981 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=311981&action=review

> Source/WebCore/svg/SVGGraphicsElement.cpp:94
> +            FloatSize viewportSize;
> +            SVGLengthContext(this).determineViewport(viewportSize);
> +            boundingBox.setSize(viewportSize);

What if determineViewport returns false? I ask because I want to do a bit of refactoring to use std::optional and I am wondering whether this code is asserting that determineViewport always returns true or if it is taking advantage of the fact that size will be 0x0 if it returns false.
Comment 9 Simon Fraser (smfr) 2017-06-06 10:44:50 PDT
(In reply to Darin Adler from comment #8)
> Comment on attachment 311981 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=311981&action=review
> 
> > Source/WebCore/svg/SVGGraphicsElement.cpp:94
> > +            FloatSize viewportSize;
> > +            SVGLengthContext(this).determineViewport(viewportSize);
> > +            boundingBox.setSize(viewportSize);
> 
> What if determineViewport returns false? I ask because I want to do a bit of
> refactoring to use std::optional and I am wondering whether this code is
> asserting that determineViewport always returns true or if it is taking
> advantage of the fact that size will be 0x0 if it returns false.

The latter.