Bug 71819

Summary: getBoundingClientRect() yields global coordinates for XHTML elements embedded in SVG
Product: WebKit Reporter: Gavin Kistner <gavin>
Component: SVGAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Major CC: bzbarsky, donggwan.kim, fmalita, fred.wang, gavin, josh, rainmore24, schenney, simon.fraser, webkit-bug-importer, willy, zimmermann
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
URL: http://phrogz.net/SVG/getBoundingClientRect.svg
See Also: https://bugs.webkit.org/show_bug.cgi?id=261109
Attachments:
Description Flags
Test case with four foreignObjects in an SVG and displaying script output
none
Zoom foreignObject reproduction none

Description Gavin Kistner 2011-11-08 08:11:00 PST
Created attachment 114073 [details]
Test case with four foreignObjects in an SVG and displaying script output

Given an SVG document with XHTML content embedded via <foreignObject>, the getBoundingClientRect() method should return the coordinates of the element with respect to foreignObject's coordinate space. Instead, it currently is returning the bounding box for object transformed into the web browser viewport.

In the attachment (or hosted URL) the return value for getBoundingClientRect() should be the same for all four cases, always showing: {left:0, top:0, right:16, bottom:16}.


The CSSOM View Module spec[1] for getBoundingClientRect() says:

> The getClientRects() and getBoundingClientRect() methods provide information about the
> position of the border box edges of an element relative to the viewport.

…and elsewhere[2] explicitly defines _viewport_ as:

> [...] defined by CSS 2.1 unless there is an ancestor `foreignObject` element in the
> http://www.w3.org/2000/svg namespace in which case that element acts as viewport and
> initial containing block.


The current behavior is understandable, as it makes code like this[3] work more easily.
However the current behavior is
* …wrong, per the spec
* …different from Firefox v7 (which gets this right), and
* …less useful than the spec (scripter transformations can identify all four real screen
  corners of a rotated object, not the screen-aligned bounding box).


[1] http://www.w3.org/TR/cssom-view/#the-getclientrects-and-getboundingclientrect-methods
[2] http://www.w3.org/TR/cssom-view/#terminology
[3] http://phrogz.net/SVG/html_location_in_svg.svg
Comment 1 Stephen Chenney 2012-03-22 17:11:58 PDT
There are numerous Chromium bugs surrounding transforms of foreign objects and events. e.g. http://code.google.com/p/chromium/issues/detail?id=116566

My guess is that this is the same issue.
Comment 2 Josh K 2021-04-27 12:14:45 PDT
Created attachment 427180 [details]
Zoom foreignObject reproduction

I think this is the same or a closely related issue to https://bugs.webkit.org/show_bug.cgi?id=173841, and here is a modified reproduction of that issue but inside a <foreignObject>
Comment 3 Radar WebKit Bug Importer 2023-09-05 12:31:15 PDT
<rdar://problem/115000886>