Bug 1382534 - Add nsCSSClipPathInstance::GetBoundingRectForBasicShapeClip(). r=mstange draft
authorBotond Ballo <botond@mozilla.com>
Wed, 04 Oct 2017 16:46:44 -0400
changeset 690308 b4e868a89408e31aef1f26c3f701e1fb2daa2477
parent 690307 7a585b57308eeefe00c2cb5c334bcfa39f11ab93
child 690309 74baaea2647708d1cd024f9e6afd82508e95c74a
push id87277
push userbballo@mozilla.com
push dateWed, 01 Nov 2017 21:17:50 +0000
reviewersmstange
bugs1382534
milestone58.0a1
Bug 1382534 - Add nsCSSClipPathInstance::GetBoundingRectForBasicShapeClip(). r=mstange MozReview-Commit-ID: 85mhNcj5V2J
layout/svg/nsCSSClipPathInstance.cpp
layout/svg/nsCSSClipPathInstance.h
--- 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)
   {
   }