From e0d9d3c032814c54b6478b550be0fc4dd9e2b2b7 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Thu, 25 Feb 2016 23:54:09 +1300 Subject: [PATCH] Bug 1250143. Account for border/padding on outer elements in GeometryUtils. r=mats MozReview-Commit-ID: KwEwnukNgeF --HG-- extra : rebase_source : d0ba2e4cd3e45280d8d030517c515caa04cb0b66 --- layout/base/GeometryUtils.cpp | 4 ++-- ...test_getBoxQuads_convertPointRectQuad.html | 21 ++++++++++++------- layout/svg/nsSVGUtils.cpp | 6 ++++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/layout/base/GeometryUtils.cpp b/layout/base/GeometryUtils.cpp index 74776eeb5667..fc320607cf05 100644 --- a/layout/base/GeometryUtils.cpp +++ b/layout/base/GeometryUtils.cpp @@ -140,8 +140,8 @@ GetBoxRectForFrame(nsIFrame** aFrame, CSSBoxType aType) { nsRect r; nsIFrame* f = nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(*aFrame, &r); - if (f) { - // For SVG, the BoxType is ignored. + if (f && f != *aFrame) { + // For non-outer SVG frames, the BoxType is ignored. *aFrame = f; return r; } diff --git a/layout/base/tests/test_getBoxQuads_convertPointRectQuad.html b/layout/base/tests/test_getBoxQuads_convertPointRectQuad.html index 295c0b392f31..7ec4f7b56d26 100644 --- a/layout/base/tests/test_getBoxQuads_convertPointRectQuad.html +++ b/layout/base/tests/test_getBoxQuads_convertPointRectQuad.html @@ -336,7 +336,7 @@ TextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextTextText
- + @@ -660,19 +660,26 @@ function runTest() { var svgContainerX = svgContainer.getBoundingClientRect().left; var svgContainerY = svgContainer.getBoundingClientRect().top; checkQuadIsRect("circle", {}, - svgContainerX + 30, svgContainerY + 30, 40, 40); + svgContainerX + 41, svgContainerY + 41, 40, 40); // Box types are ignored for SVG elements. checkQuadIsRect("circle", {box:"content"}, - svgContainerX + 30, svgContainerY + 30, 40, 40); + svgContainerX + 41, svgContainerY + 41, 40, 40); checkQuadIsRect("circle", {box:"padding"}, - svgContainerX + 30, svgContainerY + 30, 40, 40); + svgContainerX + 41, svgContainerY + 41, 40, 40); checkQuadIsRect("circle", {box:"margin"}, - svgContainerX + 30, svgContainerY + 30, 40, 40); + svgContainerX + 41, svgContainerY + 41, 40, 40); checkQuadIsRect("d", {toStr:"circle"}, - dX - (svgContainerX + 30), dY - (svgContainerY + 30), dW, dH); + dX - (svgContainerX + 41), dY - (svgContainerY + 41), dW, dH); // Test foreignObject inside an SVG transform. checkQuadIsRect("foreign", {}, - svgContainerX + 100, svgContainerY + 40, 200, 120); + svgContainerX + 111, svgContainerY + 51, 200, 120); + // Outer elements support padding and content boxes + checkQuadIsRect("svg", {box:"border"}, + svgContainerX, svgContainerY, 222, 222); + checkQuadIsRect("svg", {box:"padding"}, + svgContainerX + 7, svgContainerY + 7, 208, 208); + checkQuadIsRect("svg", {box:"content"}, + svgContainerX + 11, svgContainerY + 11, 200, 200); // XXX Test SVG text (probably broken; unclear what the best way is to handle it) diff --git a/layout/svg/nsSVGUtils.cpp b/layout/svg/nsSVGUtils.cpp index f4bd715454bb..91df103caa0a 100644 --- a/layout/svg/nsSVGUtils.cpp +++ b/layout/svg/nsSVGUtils.cpp @@ -384,8 +384,10 @@ nsSVGUtils::GetOuterSVGFrameAndCoveredRegion(nsIFrame* aFrame, nsRect* aRect) if (outer == svg) { return nullptr; } - *aRect = (aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) ? - nsRect(0, 0, 0, 0) : svg->GetCoveredRegion(); + nsMargin bp = outer->GetUsedBorderAndPadding(); + *aRect = ((aFrame->GetStateBits() & NS_FRAME_IS_NONDISPLAY) ? + nsRect(0, 0, 0, 0) : svg->GetCoveredRegion()) + + nsPoint(bp.left, bp.top); return outer; }