diff --git a/dom/base/ResizeObserver.cpp b/dom/base/ResizeObserver.cpp index 2034e58e156a7a..b1a11915b0fd07 100644 --- a/dom/base/ResizeObserver.cpp +++ b/dom/base/ResizeObserver.cpp @@ -68,7 +68,8 @@ static nsSize GetContentRectSize(const nsIFrame& aFrame) { /** * Returns |aTarget|'s size in the form of gfx::Size (in pixels). - * If the target is SVG, width and height are determined from bounding box. + * If the target is an SVG that does not participate in CSS layout, + * its width and height are determined from bounding box. * * https://www.w3.org/TR/resize-observer-1/#calculate-box-size */ @@ -81,10 +82,10 @@ static gfx::Size CalculateBoxSize(Element* aTarget, return size; } - if (aTarget->IsSVGElement()) { - // Per the spec, SVG size is always its bounding box size no matter what - // box option you choose, because SVG elements do not use standard CSS box - // model. + if (frame->HasAnyStateBits(NS_FRAME_SVG_LAYOUT)) { + // Per the spec, this target's SVG size is always its bounding box size no + // matter what box option you choose, because SVG elements do not use + // standard CSS box model. const gfxRect bbox = SVGUtils::GetBBox(frame); size.width = static_cast(bbox.width); size.height = static_cast(bbox.height); diff --git a/testing/web-platform/tests/resize-observer/svg-with-css-box-001.html b/testing/web-platform/tests/resize-observer/svg-with-css-box-001.html new file mode 100644 index 00000000000000..4ec0a7de72f746 --- /dev/null +++ b/testing/web-platform/tests/resize-observer/svg-with-css-box-001.html @@ -0,0 +1,91 @@ + +ResizeObserver for SVG elements with CSS box. + + + +
+ + + + + + + + + diff --git a/testing/web-platform/tests/resize-observer/svg-with-css-box-002.svg b/testing/web-platform/tests/resize-observer/svg-with-css-box-002.svg new file mode 100644 index 00000000000000..3c009641db3a92 --- /dev/null +++ b/testing/web-platform/tests/resize-observer/svg-with-css-box-002.svg @@ -0,0 +1,94 @@ + + +ResizeObserver for SVG elements with CSS box. + + + + + + + + + + + +