Skip to content

Commit

Permalink
Merge pull request #9026 from cajus/fix-195
Browse files Browse the repository at this point in the history
User getBoundingClientRect() for SVGElement
  • Loading branch information
oetiker committed May 30, 2016
2 parents c57ffc4 + 8a35a66 commit 0800b76
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions framework/source/class/qx/bom/element/Location.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
* * Internet Explorer 6.0 + 7.0 (both standard & quirks mode)
* * Opera 9.2
* * Safari 3.0 beta
*
* @ignore(SVGElement)
*/
qx.Bootstrap.define("qx.bom.element.Location",
{
Expand Down Expand Up @@ -246,8 +248,20 @@ qx.Bootstrap.define("qx.bom.element.Location",
var top = offset.top + body.top - scroll.top;
}

var right = left + elem.offsetWidth;
var bottom = top + elem.offsetHeight;
var elementWidth;
var elementHeight;
if (elem instanceof SVGElement) {
var rect = elem.getBoundingClientRect();
elementWidth = rect.width;
elementHeight = rect.height;
}
else {
elementWidth = elem.offsetWidth;
elementHeight = elem.offsetHeight;
}

var right = left + elementWidth;
var bottom = top + elementHeight;

if (mode)
{
Expand All @@ -257,12 +271,12 @@ qx.Bootstrap.define("qx.bom.element.Location",
{
var overX = qx.bom.element.Style.get(elem, "overflowX");
if (overX == "scroll" || overX == "auto") {
right += elem.scrollWidth - elem.offsetWidth + this.__num(elem, "borderLeftWidth") + this.__num(elem, "borderRightWidth");
right += elem.scrollWidth - elementWidth + this.__num(elem, "borderLeftWidth") + this.__num(elem, "borderRightWidth");
}

var overY = qx.bom.element.Style.get(elem, "overflowY");
if (overY == "scroll" || overY == "auto") {
bottom += elem.scrollHeight - elem.offsetHeight + this.__num(elem, "borderTopWidth") + this.__num(elem, "borderBottomWidth");
bottom += elem.scrollHeight - elementHeight + this.__num(elem, "borderTopWidth") + this.__num(elem, "borderBottomWidth");
}
}

Expand Down Expand Up @@ -434,6 +448,11 @@ qx.Bootstrap.define("qx.bom.element.Location",
*/
getOffsetParent : function(element)
{
// Ther is no offsetParent for SVG elements
if (element instanceof SVGElement) {
return document.body;
}

var offsetParent = element.offsetParent || document.body;
var Style = qx.bom.element.Style;

Expand Down

0 comments on commit 0800b76

Please sign in to comment.