Bug 71819 - getBoundingClientRect() yields global coordinates for XHTML elements embedded in SVG
Summary: getBoundingClientRect() yields global coordinates for XHTML elements embedded...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Major
Assignee: Nobody
URL: http://phrogz.net/SVG/getBoundingClie...
Depends on:
Reported: 2011-11-08 08:11 PST by Gavin Kistner
Modified: 2013-09-13 21:45 PDT (History)
9 users (show)

See Also:

Test case with four foreignObjects in an SVG and displaying script output (1.86 KB, image/svg+xml)
2011-11-08 08:11 PST, Gavin Kistner
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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.