From 8f0a57337e2e36b48daa8b2257d2742ab3fd154f Mon Sep 17 00:00:00 2001 From: cku Date: Wed, 15 Mar 2017 18:36:53 +0800 Subject: [PATCH] Bug 1320036 - Part 1. Correct objectBoundingBox region of a filter applied to an outer SVG element. r=jwatt MozReview-Commit-ID: 8frACVe2gFE --HG-- extra : rebase_source : f796c7ae084cc2af0960a0702167fe8211aa083a extra : source : 43b17a8af53a4684abb4379a3fba95c9d424c77f --- layout/svg/nsFilterInstance.cpp | 4 +++- layout/svg/nsSVGIntegrationUtils.cpp | 4 ++-- layout/svg/nsSVGUtils.cpp | 5 ++++- layout/svg/nsSVGUtils.h | 6 +++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/layout/svg/nsFilterInstance.cpp b/layout/svg/nsFilterInstance.cpp index da8a559eeb46..8eeff3944501 100644 --- a/layout/svg/nsFilterInstance.cpp +++ b/layout/svg/nsFilterInstance.cpp @@ -182,7 +182,9 @@ nsFilterInstance::nsFilterInstance(nsIFrame *aTargetFrame, mTargetBBox = *aOverrideBBox; } else { MOZ_ASSERT(mTargetFrame, "Need to supply a frame when there's no aOverrideBBox"); - mTargetBBox = nsSVGUtils::GetBBox(mTargetFrame); + mTargetBBox = nsSVGUtils::GetBBox(mTargetFrame, + nsSVGUtils::eUseFrameBoundsForOuterSVG | + nsSVGUtils::eBBoxIncludeFillGeometry); } // Compute user space to filter space transforms. diff --git a/layout/svg/nsSVGIntegrationUtils.cpp b/layout/svg/nsSVGIntegrationUtils.cpp index 7fb8719c3ade..beee17eff9b8 100644 --- a/layout/svg/nsSVGIntegrationUtils.cpp +++ b/layout/svg/nsSVGIntegrationUtils.cpp @@ -192,8 +192,8 @@ nsSVGIntegrationUtils::GetSVGCoordContextForNonSVGFrame(nsIFrame* aNonSVGFrame) gfxRect nsSVGIntegrationUtils::GetSVGBBoxForNonSVGFrame(nsIFrame* aNonSVGFrame) { - NS_ASSERTION(!aNonSVGFrame->IsFrameOfType(nsIFrame::eSVG), - "SVG frames should not get here"); + NS_ASSERTION(!(aNonSVGFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT), + "Frames with SVG layout should not get here"); nsIFrame* firstFrame = nsLayoutUtils::FirstContinuationOrIBSplitSibling(aNonSVGFrame); // 'r' is in "user space": diff --git a/layout/svg/nsSVGUtils.cpp b/layout/svg/nsSVGUtils.cpp index 5bfb015dec36..ba5b12836c0a 100644 --- a/layout/svg/nsSVGUtils.cpp +++ b/layout/svg/nsSVGUtils.cpp @@ -1097,7 +1097,10 @@ nsSVGUtils::GetBBox(nsIFrame *aFrame, uint32_t aFlags) } gfxRect bbox; nsISVGChildFrame *svg = do_QueryFrame(aFrame); - if (svg || aFrame->IsSVGText()) { + const bool hasSVGLayout = aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT; + if (hasSVGLayout || aFrame->IsSVGText() || + // if we evaluate the following, |svg| can only be an outer- or null + (svg && !(aFlags & eUseFrameBoundsForOuterSVG))) { // It is possible to apply a gradient, pattern, clipping path, mask or // filter to text. When one of these facilities is applied to text // the bounding box is the entire text element in all diff --git a/layout/svg/nsSVGUtils.h b/layout/svg/nsSVGUtils.h index f72c63a6b2e6..5108a6d80a00 100644 --- a/layout/svg/nsSVGUtils.h +++ b/layout/svg/nsSVGUtils.h @@ -403,7 +403,11 @@ public: eBBoxIncludeStroke = 1 << 2, eBBoxIncludeStrokeGeometry = 1 << 3, eBBoxIncludeMarkers = 1 << 4, - eBBoxIncludeClipped = 1 << 5 + eBBoxIncludeClipped = 1 << 5, + // Normally a getBBox call on outer- should only return the + // bounds of the elements children. This flag will cause the + // element's bounds to be returned instead. + eUseFrameBoundsForOuterSVG = 1 << 6 }; /** * Get the SVG bbox (the SVG spec's simplified idea of bounds) of aFrame in