Last Comment Bug 700477 - getBoundingClientRect() wrong for XHTML embedded in SVG
: getBoundingClientRect() wrong for XHTML embedded in SVG
Product: Core
Classification: Components
Component: SVG (show other bugs)
: 7 Branch
: x86_64 Windows 7
-- normal (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
: Jet Villegas (:jet)
Depends on:
  Show dependency treegraph
Reported: 2011-11-07 15:38 PST by Gavin Kistner
Modified: 2011-11-24 17:25 PST (History)
2 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

html_location_in_svg_in_html.xhtml (2.52 KB, application/octet-stream)
2011-11-07 15:38 PST, Gavin Kistner
no flags Details

Description User image Gavin Kistner 2011-11-07 15:38:49 PST
Created attachment 572648 [details]

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.21 Safari/535.7

Steps to reproduce:

Embedded XHTML inside a <foreignObject> inside SVG and asked for the getBoundingClientRect() of an HTML element therein.

Actual results:

Received coordinates of the element within the embedded `<body>` inside the SVG document, not affected by the scaling or placement of the `<foreignObject>` inside the SVG container.

Expected results:

Received coordinates relative to the viewport of the browser window.
Comment 1 User image Gavin Kistner 2011-11-07 15:40:59 PST
View the test file hosted here:

The actual application was the desire to find the location in SVG coordinate space of embedded XHTML contents, in order to connect SVG elements to the embedded HTML contents, as seen here:

The proposed technique is to translate the embedded HTML element coordinates into screen space (using getBoundingClientRect()) and then transform those coordinates into a local SVG space. This works as intended on Chrome/Safari.
Comment 2 User image Boris Zbarsky [:bz] (still a bit busy) 2011-11-07 15:47:25 PST
This is the behavior the spec calls for, as far as I can tell.  In particular, says:

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

and says:

  Viewport and initial containing block are defined by CSS 2.1 unless there is an
  ancestor foreignObject element in the namespace in which
  case that element acts as viewport and initial containing block.
Comment 3 User image Boris Zbarsky [:bz] (still a bit busy) 2011-11-07 15:48:41 PST
Or in other words, the return value for getBoundingClientRect in a <foreignObject> is in the coordinate system of that <foreignObject>; you can then use its CTM to do whatever else you want as described in comment 1.
Comment 4 User image Gavin Kistner 2011-11-07 19:17:12 PST
Wow…right you are. I totally missed that definition of viewport. Looks like it's Webkit at fault here. :)
Comment 5 User image Boris Zbarsky [:bz] (still a bit busy) 2011-11-07 19:40:24 PST
Gavin, are you going to file a bug on WebKit, or should I?
Comment 6 User image Gavin Kistner 2011-11-07 20:05:09 PST
Boris: I am planning on filing a bug. I think I could make a slightly clearer use case/repro case for them first.
Comment 7 User image Boris Zbarsky [:bz] (still a bit busy) 2011-11-07 20:36:22 PST
Sounds good.  Thanks!
Comment 8 User image Gavin Kistner 2011-11-08 08:12:35 PST
FWIW the corresponding Webkit bug is
Comment 9 User image Boris Zbarsky [:bz] (still a bit busy) 2011-11-24 17:25:39 PST
Note also

Depending on the outcome of that, the spec (and our behavior) might change...

If you have thoughts on the issue, it'd be good to follow up on that mailing list.

Note You need to log in before you can comment on or make changes to this bug.