Bug 78631 - getCTM() on SVG root element with borders, paddings, and viewbox returns incorrect values
Summary: getCTM() on SVG root element with borders, paddings, and viewbox returns inco...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Max Vujovic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-14 14:07 PST by Max Vujovic
Modified: 2012-04-17 13:33 PDT (History)
5 users (show)

See Also:


Attachments
Reproduction (2.08 KB, text/html)
2012-02-14 14:07 PST, Max Vujovic
no flags Details
Patch (7.20 KB, patch)
2012-02-15 09:31 PST, Max Vujovic
no flags Details | Formatted Diff | Diff
Patch (7.24 KB, patch)
2012-02-15 11:55 PST, Max Vujovic
zimmermann: review-
Details | Formatted Diff | Diff
Patch (7.08 KB, patch)
2012-02-15 16:07 PST, Max Vujovic
krit: review-
krit: commit-queue-
Details | Formatted Diff | Diff
Patch (57.45 KB, patch)
2012-02-16 11:55 PST, Max Vujovic
eric: review+
webkit.review.bot: commit-queue-
Details | Formatted Diff | Diff
Patch (58.16 KB, patch)
2012-02-17 11:47 PST, Max Vujovic
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Max Vujovic 2012-02-14 14:07:59 PST
Created attachment 127041 [details]
Reproduction

Please see the attached reproduction for an example.

Note that the reproduction works properly in Opera.
Comment 1 Max Vujovic 2012-02-15 09:31:00 PST
Created attachment 127191 [details]
Patch

Added a proposed patch. The root cause of this bug was that SVGSVGElement::currentViewportSize was returning the size of the SVG viewport plus CSS borders and paddings, causing the CTM calculation to be off. In the patch, SVGSVGElement::currentViewportSize uses contentBoxRect instead of frameRect to compute the viewport size for SVG root elements.
Comment 2 WebKit Review Bot 2012-02-15 09:32:44 PST
Attachment 127191 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/update-webkit']" exit_code: 2

Updating OpenSource
git.webkit.org[0: 17.254.20.231]: errno=Connection refused
fatal: unable to connect a socket (Connection refused)
Died at Tools/Scripts/update-webkit line 162.


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Max Vujovic 2012-02-15 11:55:41 PST
Created attachment 127210 [details]
Patch

Trying the EWS bots again.
Comment 4 Nikolas Zimmermann 2012-02-15 14:43:49 PST
Comment on attachment 127210 [details]
Patch

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

Nice patch Max, almost there!

> LayoutTests/svg/dom/SVGLocatable-getCTM-svg-root.html:12
> +        <script src="../../fast/js/resources/js-test-pre.js"></script>

I think it would be helpful, if this testcase would use "window.enablePixelTesting = true" before including js-test-pre.js, to dump pixels as well.

> LayoutTests/svg/dom/SVGLocatable-getCTM-svg-root.html:32
> +        <svg id="svgRoot1" xmlns="http://www.w3.org/2000/svg"

Inside a HTML5 document, no xmlns is needed here.

> LayoutTests/svg/dom/SVGLocatable-getCTM-svg-root.html:34
> +             viewbox="0 0 100 100"">

Oh, when the HTML5 parses parses this file, lower case attributes are allowed?? The correct name is 'viewBox'.
I'm not sure if HTML5 explicitly allows this, if not please use "viewBox".

> Source/WebCore/ChangeLog:22
> +            SVGSVGElement::currentViewportSize was using the SVG root element's frameRect to compute
> +            the viewport size. However, the frameRect includes borders and paddings, which should
> +            not be considered part of the SVG viewport.
> +
> +            SVGSVGElement::currentViewportSize now uses the contentBoxRect instead of the frameRect.
> +            The contentBoxRect corresponds to the SVG viewport and does not include borders and
> +            paddings.

Double explanation, either is okay.

> Source/WebCore/svg/SVGSVGElement.cpp:557
>      FloatRect frameRect = toRenderSVGViewportContainer(renderer())->viewport();

I'd rename this as well for consistency to avoid confusion.
Comment 5 Dirk Schulze 2012-02-15 15:30:00 PST
(In reply to comment #4)
> (From update of attachment 127210 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=127210&action=review

> Oh, when the HTML5 parses parses this file, lower case attributes are allowed?? The correct name is 'viewBox'.
> I'm not sure if HTML5 explicitly allows this, if not please use "viewBox".

It allows it, yes. Everything is not case sensitive on HTML5. That is a great problem for us on other places. We have a bug report for "linearGradient" where is causes problems. Don't know the exact problem right now.
Comment 6 Max Vujovic 2012-02-15 16:07:40 PST
Created attachment 127263 [details]
Patch

(In reply to comment #4)
> (From update of attachment 127210 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=127210&action=review
> 
> Nice patch Max, almost there!

Thanks Nikolas!

> > LayoutTests/svg/dom/SVGLocatable-getCTM-svg-root.html:12
> > +        <script src="../../fast/js/resources/js-test-pre.js"></script>
> 
> I think it would be helpful, if this testcase would use "window.enablePixelTesting = true" before including js-test-pre.js, to dump pixels as well.

I've added this. Please forgive my newness, but what exactly does window.enablePixelTesting do? 

> > LayoutTests/svg/dom/SVGLocatable-getCTM-svg-root.html:32
> > +        <svg id="svgRoot1" xmlns="http://www.w3.org/2000/svg"
> 
> Inside a HTML5 document, no xmlns is needed here.
> 
> > LayoutTests/svg/dom/SVGLocatable-getCTM-svg-root.html:34
> > +             viewbox="0 0 100 100"">
> 
> Oh, when the HTML5 parses parses this file, lower case attributes are allowed?? The correct name is 'viewBox'.
> I'm not sure if HTML5 explicitly allows this, if not please use "viewBox".

I kept this as "viewbox" since the convention for HTML5 seems to be keeping all attribute names lowercase. 

The closest mention I found in the HTML5 spec was section 4.14.1 Case-sensitivity, which implies that "viewbox" should work:
"Attribute and element names of HTML elements in HTML documents must be treated as ASCII case-insensitive for the purposes of selector matching."
(http://www.whatwg.org/specs/web-apps/current-work/multipage/selectors.html#case-sensitivity)

Some search results I found suggest that lowercase is the convention:
"HTML5 attributes are case insensitive and may be written in all uppercase or mixed case, although the most common convention is to stick with lowercase."
(http://www.tutorialspoint.com/html5/html5_syntax.htm)

> > Source/WebCore/ChangeLog:22
> > +            SVGSVGElement::currentViewportSize was using the SVG root element's frameRect to compute
> > +            the viewport size. However, the frameRect includes borders and paddings, which should
> > +            not be considered part of the SVG viewport.
> > +
> > +            SVGSVGElement::currentViewportSize now uses the contentBoxRect instead of the frameRect.
> > +            The contentBoxRect corresponds to the SVG viewport and does not include borders and
> > +            paddings.
> 
> Double explanation, either is okay.

Removed the first paragraph. 

> > Source/WebCore/svg/SVGSVGElement.cpp:557
> >      FloatRect frameRect = toRenderSVGViewportContainer(renderer())->viewport();
> 
> I'd rename this as well for consistency to avoid confusion.

Good idea. I renamed "frameRect" to "viewportRect" in this section.
Comment 7 Max Vujovic 2012-02-15 16:14:19 PST
(In reply to comment #4)
> (From update of attachment 127210 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=127210&action=review
> > LayoutTests/svg/dom/SVGLocatable-getCTM-svg-root.html:32
> > +        <svg id="svgRoot1" xmlns="http://www.w3.org/2000/svg"
> 
> Inside a HTML5 document, no xmlns is needed here.

Oops, forgot to mention that I changed this as well. Now all the SVG tags fit on one line :)
Comment 8 Dirk Schulze 2012-02-15 16:18:39 PST
Comment on attachment 127263 [details]
Patch

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

r- because the pixel result is missing now. You enabled it explicitly with window.enablePixelTesting

> LayoutTests/ChangeLog:9
> +        * svg/dom/SVGLocatable-getCTM-svg-root-expected.txt: Added.
> +        * svg/dom/SVGLocatable-getCTM-svg-root.html: Added.

This is missing the pixel result now.
Comment 9 Max Vujovic 2012-02-15 16:50:42 PST
(In reply to comment #8)
> (From update of attachment 127263 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=127263&action=review
> 
> r- because the pixel result is missing now. You enabled it explicitly with window.enablePixelTesting
> 
> > LayoutTests/ChangeLog:9
> > +        * svg/dom/SVGLocatable-getCTM-svg-root-expected.txt: Added.
> > +        * svg/dom/SVGLocatable-getCTM-svg-root.html: Added.
> 
> This is missing the pixel result now.

Dirk - I'll update the patch with the pixel results. I'll also rearrange the elements in the test case so that they all fit in 800x600.

Nikolas - Dirk taught me how to create pixel tests, so no need to explain anymore :).
Comment 10 Max Vujovic 2012-02-16 11:55:35 PST
Created attachment 127424 [details]
Patch

- Updated the patch with the png expectation file under the platform/mac folder. I kept the expected.txt file in the same folder as the test because the text results should be the same on all platforms.
- Reduced the sizes of the elements in the test case so that they fit in the 800x600 snapshot.
- Removed the red rects that were previously under the SVG root elements. The red rects will not be rendered with the correct dimensions until bug 78613 is fixed, and they are not essential to testing getCTM() on the SVG root. Bug 78613 will provide specific tests for rendering SVG elements under an SVG root element with borders, paddings, and margins.
Comment 11 Eric Seidel (no email) 2012-02-16 13:17:18 PST
Comment on attachment 127424 [details]
Patch

LGTM.
Comment 12 Max Vujovic 2012-02-16 13:28:20 PST
(In reply to comment #11)
> (From update of attachment 127424 [details])
> LGTM.

Thanks, Eric!
Comment 13 WebKit Review Bot 2012-02-16 16:51:17 PST
Comment on attachment 127424 [details]
Patch

Attachment 127424 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/11534981

New failing tests:
svg/dom/SVGLocatable-getCTM-svg-root.html
Comment 14 Nikolas Zimmermann 2012-02-16 23:49:20 PST
Comment on attachment 127424 [details]
Patch

Phew, glad Eric gave r+ and not me - chromium expectations were not updated ;-)
Comment 15 Max Vujovic 2012-02-17 10:30:15 PST
(In reply to comment #14)
> (From update of attachment 127424 [details])
> Phew, glad Eric gave r+ and not me - chromium expectations were not updated ;-)

Sorry guys, this is my first patch with pixel tests.

Nikolas - I looked at bug 34714 where you described the procedure for generating chromium baselines. I'll do that, reupload a patch, and keep you from repeating yourself :)
Comment 16 Max Vujovic 2012-02-17 11:47:53 PST
Created attachment 127626 [details]
Patch

Trying again with the chromium bot.

Added the following lines to platform/chromium/test_expectations.txt:
+// New test, needs a rebaseline
+BUGWK78631 : svg/dom/SVGLocatable-getCTM-svg-root.html = IMAGE

Also, updated LayoutTests/ChangeLog to mention test_expectations.txt.
Comment 17 Max Vujovic 2012-02-17 16:39:40 PST
Comment on attachment 127626 [details]
Patch

Passed cr-linux. Setting r?, cq?.
Comment 18 WebKit Review Bot 2012-02-21 20:42:12 PST
Comment on attachment 127626 [details]
Patch

Clearing flags on attachment: 127626

Committed r108441: <http://trac.webkit.org/changeset/108441>
Comment 19 WebKit Review Bot 2012-02-21 20:42:18 PST
All reviewed patches have been landed.  Closing bug.
Comment 20 Stephen Chenney 2012-04-17 12:20:40 PDT
Committed r114411: <http://trac.webkit.org/changeset/114411>
Comment 21 Dirk Schulze 2012-04-17 13:33:03 PDT
(In reply to comment #20)
> Committed r114411: <http://trac.webkit.org/changeset/114411>

Can you be more explicit what you committed in the future please? This makes it easier to follow bug reports :) (Especially because the patch was already committed and you just updated the results).