Bug 1382534 - Add nsCSSClipPathInstance::GetBoundingRectForBasicShapeClip(). r=mstange
MozReview-Commit-ID: 85mhNcj5V2J
--- a/layout/svg/nsCSSClipPathInstance.cpp
+++ b/layout/svg/nsCSSClipPathInstance.cpp
@@ -64,16 +64,31 @@ nsCSSClipPathInstance::HitTestBasicShape
RefPtr<DrawTarget> drawTarget =
gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
RefPtr<Path> path = instance.CreateClipPath(drawTarget);
float pixelRatio = float(nsPresContext::AppUnitsPerCSSPixel()) /
aFrame->PresContext()->AppUnitsPerDevPixel();
return path->ContainsPoint(ToPoint(aPoint) * pixelRatio, Matrix());
}
+/* static */ Rect
+nsCSSClipPathInstance::GetBoundingRectForBasicShapeClip(nsIFrame* aFrame,
+ const StyleShapeSource& aClipPathStyle)
+{
+ MOZ_ASSERT(aClipPathStyle.GetType() == StyleShapeSourceType::Shape ||
+ aClipPathStyle.GetType() == StyleShapeSourceType::Box);
+
+ nsCSSClipPathInstance instance(aFrame, aClipPathStyle);
+
+ RefPtr<DrawTarget> drawTarget =
+ gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
+ RefPtr<Path> path = instance.CreateClipPath(drawTarget);
+ return path->GetBounds();
+}
+
already_AddRefed<Path>
nsCSSClipPathInstance::CreateClipPath(DrawTarget* aDrawTarget)
{
nsRect r =
nsLayoutUtils::ComputeGeometryBox(mTargetFrame,
mClipPathStyle.GetReferenceBox());
if (mClipPathStyle.GetType() != StyleShapeSourceType::Shape) {
--- a/layout/svg/nsCSSClipPathInstance.h
+++ b/layout/svg/nsCSSClipPathInstance.h
@@ -15,23 +15,27 @@ class nsIFrame;
class gfxContext;
namespace mozilla {
class nsCSSClipPathInstance
{
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::Path Path;
+ typedef mozilla::gfx::Rect Rect;
public:
static void ApplyBasicShapeClip(gfxContext& aContext,
nsIFrame* aFrame);
// aPoint is in CSS pixels.
static bool HitTestBasicShapeClip(nsIFrame* aFrame,
const gfxPoint& aPoint);
+
+ static Rect GetBoundingRectForBasicShapeClip(nsIFrame* aFrame,
+ const StyleShapeSource& aClipPathStyle);
private:
explicit nsCSSClipPathInstance(nsIFrame* aFrame,
const StyleShapeSource aClipPathStyle)
: mTargetFrame(aFrame)
, mClipPathStyle(aClipPathStyle)
{
}