Bug 1388985 - Use GetBBox to calcute the area of frame(s) that clip-path basic-shape should apply to. r?cjku draft
authorLouis Chang <lochang@mozilla.com>
Fri, 11 Aug 2017 18:33:34 +0800
changeset 644775 2d909ec24205e52e97a1d93829cbb89fea8a1a53
parent 644774 cb9e7abeaee84aaafa64f4da6169befa5ab93d49
child 725713 b3427d9a9b644cb282be05b3a2dd5eff25902fd2
push id73549
push userlochang@mozilla.com
push dateFri, 11 Aug 2017 10:34:27 +0000
reviewerscjku
bugs1388985
milestone57.0a1
Bug 1388985 - Use GetBBox to calcute the area of frame(s) that clip-path basic-shape should apply to. r?cjku MozReview-Commit-ID: 4pJnxSy6GQO
layout/svg/nsCSSClipPathInstance.cpp
layout/svg/nsCSSClipPathInstance.h
--- a/layout/svg/nsCSSClipPathInstance.cpp
+++ b/layout/svg/nsCSSClipPathInstance.cpp
@@ -36,17 +36,17 @@ nsCSSClipPathInstance::ApplyBasicShapeCl
   MOZ_ASSERT(type == StyleShapeSourceType::Shape ||
              type == StyleShapeSourceType::Box,
              "This function is used with basic-shape and geometry-box only.");
 #endif
 
   nsCSSClipPathInstance instance(aFrame, clipPathStyle);
 
   aContext.NewPath();
-  RefPtr<Path> path = instance.CreateClipPath(aContext.GetDrawTarget());
+  RefPtr<Path> path = instance.CreateClipPath(aContext.GetDrawTarget(), aFrame);
   aContext.SetPath(path);
   aContext.Clip();
 }
 
 /* static*/ bool
 nsCSSClipPathInstance::HitTestBasicShapeClip(nsIFrame* aFrame,
                                              const gfxPoint& aPoint)
 {
@@ -58,28 +58,37 @@ nsCSSClipPathInstance::HitTestBasicShape
   if (type == StyleShapeSourceType::URL) {
     return false;
   }
 
   nsCSSClipPathInstance instance(aFrame, clipPathStyle);
 
   RefPtr<DrawTarget> drawTarget =
     gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget();
-  RefPtr<Path> path = instance.CreateClipPath(drawTarget);
+  RefPtr<Path> path = instance.CreateClipPath(drawTarget, aFrame);
   float pixelRatio = float(nsPresContext::AppUnitsPerCSSPixel()) /
                      aFrame->PresContext()->AppUnitsPerDevPixel();
   return path->ContainsPoint(ToPoint(aPoint) * pixelRatio, Matrix());
 }
 
 already_AddRefed<Path>
-nsCSSClipPathInstance::CreateClipPath(DrawTarget* aDrawTarget)
+nsCSSClipPathInstance::CreateClipPath(DrawTarget* aDrawTarget, nsIFrame* aFrame)
 {
+/*
   nsRect r =
     nsLayoutUtils::ComputeGeometryBox(mTargetFrame,
                                       mClipPathStyle.GetReferenceBox());
+*/
+  uint32_t flags =
+    (aFrame->StyleBorder()->mBoxDecorationBreak == StyleBoxDecorationBreak::Clone)
+      ? nsSVGUtils::eBBoxIncludeFillGeometry |
+        nsSVGUtils::eIncludeOnlyCurrentFrameForNonSVGElement
+      : nsSVGUtils::eBBoxIncludeFillGeometry;
+  gfxRect bbox = nsSVGUtils::GetBBox(aFrame, flags);
+  nsRect r = nsLayoutUtils::RoundGfxRectToAppRect(bbox, AppUnitsPerCSSPixel());
 
   if (mClipPathStyle.GetType() != StyleShapeSourceType::Shape) {
     // TODO Clip to border-radius/reference box if no shape
     // was specified.
     RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder();
     return builder->Finish();
   }
 
--- a/layout/svg/nsCSSClipPathInstance.h
+++ b/layout/svg/nsCSSClipPathInstance.h
@@ -29,17 +29,18 @@ public:
 private:
   explicit nsCSSClipPathInstance(nsIFrame* aFrame,
                                  const StyleShapeSource aClipPathStyle)
     : mTargetFrame(aFrame)
     , mClipPathStyle(aClipPathStyle)
   {
   }
 
-  already_AddRefed<Path> CreateClipPath(DrawTarget* aDrawTarget);
+  already_AddRefed<Path> CreateClipPath(DrawTarget* aDrawTarget,
+                                        nsIFrame* aFrame);
 
   already_AddRefed<Path> CreateClipPathCircle(DrawTarget* aDrawTarget,
                                               const nsRect& aRefBox);
 
   already_AddRefed<Path> CreateClipPathEllipse(DrawTarget* aDrawTarget,
                                                const nsRect& aRefBox);
 
   already_AddRefed<Path> CreateClipPathPolygon(DrawTarget* aDrawTarget,