Closed Bug 1610093 Opened 5 years ago Closed 8 months ago

SVG getScreenCTM does not return correct position if parent is transformed

Categories

(Core :: SVG, defect, P3)

72 Branch
defect

Tracking

()

RESOLVED FIXED
126 Branch
Webcompat Priority P3
Tracking Status
firefox126 --- fixed

People

(Reporter: kris, Assigned: longsonr)

References

(Blocks 1 open bug)

Details

Attachments

(5 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36

Steps to reproduce:

  1. open this fiddle
    https://jsfiddle.net/kzima/h0cqbeka/
  2. Notice console log having wrong position

Actual results:

getScreenCTM() does not take to account parent's transform and shows wrong point position within SVG coordinate system.

Expected results:

getScreenCTM() should offset parent's transform so the point within coordinate system is correct.

Summary: SVG getScreenCTM does work if parent is transformed → SVG getScreenCTM does not return correct position if parent is transformed
Component: Untriaged → SVG
OS: Unspecified → All
Product: Firefox → Core
Hardware: Unspecified → All

The priority flag is not set for this bug.
:dholbert, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(dholbert)

(In reply to kris from comment #0)

Steps to reproduce:

  1. open this fiddle
    https://jsfiddle.net/kzima/h0cqbeka/
  2. Notice console log having wrong position

For the record -- I didn't see any position at all in the web console, and then I realized there's a missing step here:

Step 1.5: Click the red square.

After doing that, I see something like this in the Web Console, in Firefox Nightly:

Should print (67, 40), actual value: (117, 90)

(Whereas in Chrome, the should/actual values match.)

Here's the testcase, taken from jsfiddle, FWIW.

Flags: needinfo?(dholbert)

Here's a version of the testcase where I moved the transform styling from the #container to the svg element. With that change, we get EXPECTED RESULTS.

So: I think this is indeed a bug. Thanks for the report!

Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3

Duplicate of bug 1446011 ?

Flags: needinfo?(dholbert)

I don't think so, though I'm not entirely sure what that bug covers. Its initial comment references an inter-engine disagreement in interpretation, which we'd like to address, and I'm not sure what the details of that particular disagreement are. I'll mark it as a dependency to establish a relationship, at least, and we can dupe later if appropriate.

(In bug 1446011 comment 1, Robert mentioned bug 972041, whose description sounds quite similar to this issue (though that one's fixed, so it's not exactly a dupe). Anyway -- that bug was not considered a dupe of bug 1446011, so it seems like this one probably is not either.)

Depends on: 1446011
Flags: needinfo?(dholbert)
See Also: → 972041

In case it's helpful, here's a more visual illustration of the bug: http://jsfiddle.net/edemaine/vLjd1pa7/6/
The fiddle is based on an old Webkit bug (everything now works fine in Chrome): https://bugs.webkit.org/show_bug.cgi?id=96361
I also found that putting the transform on the <svg> element worked fine, but putting it on the parent doesn't work.
This makes it difficult to make interactive SVG interfaces that need to translate mouse events into SVG coordinate space.

Attached patch svg.diffSplinter Review

This fixes the testcase in this bug but it fails dom/svg/test_getCTM.html. I'm uploaded this for someone else to take over the finish line, I'm not planning to work on this further.

Attached patch svg2.diffSplinter Review

This is my stab in the dark to try to fix the test failure caused by the first patch, it didn't work, but it seems like it would be correct.

I investigated the failing test together with Timothy and what we found is, that the test case seems to be wrong.

Here is why:

  • my own math gives the same result as the patched version
  • NOT using an iframe to load the SVG but putting it directly into the dom gives the same result as the patched version. That means,by simply loading the SVG in an iframe the test result change in the unpatched version. And that should not happen
  • Chrome gives the same result for the patched version (when loaded via iframe. Funny enough, chrome gives completely different results when loading the SVG without iframe so they seem to have a similar problem - but backward)

Therefore I vote for changing the test and landing the patch

Flags: needinfo?(longsonr)

The failing test is in L116 of dom/svg/test/test_getCTM.html => https://searchfox.org/mozilla-central/rev/8f4c180b87e52f3345ef8a3432d6e54bd1eb18dc/dom/svg/test/test_getCTM.html#101
The correct values should be e=-4 and f=19

The calculation behind that is rather straight forward:

e f contribution
11 22 SVG root viewbox
3 4 transform of g
1 2 nested svg x and y
30 40 position of foreignObject
1 1 transform of foreignObject
-50 -50 viewbox of target
-4 19 Result

The code certainly looks about right. Happy to review formally.

Flags: needinfo?(longsonr)
Assignee: nobody → longsonr
Status: NEW → ASSIGNED
Severity: normal → S3
Webcompat Priority: --- → ?
Webcompat Priority: ? → P3
Attachment #9259300 - Attachment description: WIP: Bug 1610093 - Fix getScreenCTM when parent is transformed. → Bug 1610093 - Fix getScreenCTM when parent is transformed. r=dholbert
Attachment #9259300 - Attachment description: Bug 1610093 - Fix getScreenCTM when parent is transformed. r=dholbert → Bug 1610093 - Fix getScreenCTM when parent is transformed. r=emilio
Pushed by longsonr@gmail.com: https://hg.mozilla.org/integration/autoland/rev/6c172ec3a6db Fix getScreenCTM when parent is transformed. r=emilio
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/45165 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 8 months ago
Resolution: --- → FIXED
Target Milestone: --- → 126 Branch
Upstream PR merged by moz-wptsync-bot
Regressions: 1889781
Blocks: 1446011
No longer depends on: 1446011
QA Whiteboard: [qa-126b-p2]
Regressions: 1898409
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: