diff options
Diffstat (limited to 'layout/svg/CSSClipPathInstance.cpp')
-rw-r--r-- | layout/svg/CSSClipPathInstance.cpp | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/layout/svg/CSSClipPathInstance.cpp b/layout/svg/CSSClipPathInstance.cpp index 77bde2bb54..a8e0306d3e 100644 --- a/layout/svg/CSSClipPathInstance.cpp +++ b/layout/svg/CSSClipPathInstance.cpp @@ -66,7 +66,7 @@ bool CSSClipPathInstance::HitTestBasicShapeOrPathClip(nsIFrame* aFrame, RefPtr<Path> path = instance.CreateClipPath( drawTarget, SVGUtils::GetCSSPxToDevPxMatrix(aFrame)); float pixelRatio = float(AppUnitsPerCSSPixel()) / - aFrame->PresContext()->AppUnitsPerDevPixel(); + float(aFrame->PresContext()->AppUnitsPerDevPixel()); return path && path->ContainsPoint(ToPoint(aPoint) * pixelRatio, Matrix()); } @@ -121,8 +121,10 @@ already_AddRefed<Path> CSSClipPathInstance::CreateClipPath( return CreateClipPathPolygon(aDrawTarget, r); case StyleBasicShape::Tag::Rect: return CreateClipPathInset(aDrawTarget, r); - case StyleBasicShape::Tag::Path: - return CreateClipPathPath(aDrawTarget, r); + case StyleBasicShape::Tag::PathOrShape: + return basicShape.AsPathOrShape().IsPath() + ? CreateClipPathPath(aDrawTarget, r) + : CreateClipPathShape(aDrawTarget, r); default: MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Unexpected shape type"); } @@ -175,18 +177,41 @@ already_AddRefed<Path> CSSClipPathInstance::CreateClipPathInset( already_AddRefed<Path> CSSClipPathInstance::CreateClipPathPath( DrawTarget* aDrawTarget, const nsRect& aRefBox) { - const auto& path = mClipPathStyle.AsShape()._0->AsPath(); + const auto& path = mClipPathStyle.AsShape()._0->AsPathOrShape().AsPath(); RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder( path.fill == StyleFillRule::Nonzero ? FillRule::FILL_WINDING : FillRule::FILL_EVEN_ODD); - nscoord appUnitsPerDevPixel = + const nscoord appUnitsPerDevPixel = mTargetFrame->PresContext()->AppUnitsPerDevPixel(); - float scale = float(AppUnitsPerCSSPixel()) / appUnitsPerDevPixel; - Point offset = Point(aRefBox.x, aRefBox.y) / appUnitsPerDevPixel; - + const Point offset = + LayoutDevicePoint::FromAppUnits(aRefBox.TopLeft(), appUnitsPerDevPixel) + .ToUnknownPoint(); + const float scale = mTargetFrame->Style()->EffectiveZoom().Zoom( + float(AppUnitsPerCSSPixel()) / float(appUnitsPerDevPixel)); return SVGPathData::BuildPath(path.path._0.AsSpan(), builder, - StyleStrokeLinecap::Butt, 0.0, offset, scale); + StyleStrokeLinecap::Butt, 0.0, {}, offset, + scale); +} + +already_AddRefed<Path> CSSClipPathInstance::CreateClipPathShape( + DrawTarget* aDrawTarget, const nsRect& aRefBox) { + const auto& shape = mClipPathStyle.AsShape()._0->AsPathOrShape().AsShape(); + + RefPtr<PathBuilder> builder = aDrawTarget->CreatePathBuilder( + shape.fill == StyleFillRule::Nonzero ? FillRule::FILL_WINDING + : FillRule::FILL_EVEN_ODD); + const nscoord appUnitsPerDevPixel = + mTargetFrame->PresContext()->AppUnitsPerDevPixel(); + const CSSSize basis = CSSSize::FromAppUnits(aRefBox.Size()); + const Point offset = + LayoutDevicePoint::FromAppUnits(aRefBox.TopLeft(), appUnitsPerDevPixel) + .ToUnknownPoint(); + const float scale = mTargetFrame->Style()->EffectiveZoom().Zoom( + float(AppUnitsPerCSSPixel()) / float(appUnitsPerDevPixel)); + return SVGPathData::BuildPath(shape.commands.AsSpan(), builder, + StyleStrokeLinecap::Butt, 0.0, basis, offset, + scale); } } // namespace mozilla |