2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-01-25 06:55:03 +03:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Main header first:
|
2020-07-07 16:49:30 +03:00
|
|
|
#include "SVGClipPathFrame.h"
|
2012-03-20 16:15:55 +04:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Keep others in (case-insensitive) order:
|
2017-02-17 16:15:18 +03:00
|
|
|
#include "AutoReferenceChainGuard.h"
|
2017-12-11 18:37:59 +03:00
|
|
|
#include "ImgDrawResult.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "gfxContext.h"
|
2019-04-16 10:24:49 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2020-07-07 16:49:30 +03:00
|
|
|
#include "mozilla/SVGGeometryFrame.h"
|
|
|
|
#include "mozilla/SVGObserverUtils.h"
|
2014-09-12 11:20:12 +04:00
|
|
|
#include "mozilla/dom/SVGClipPathElement.h"
|
2020-07-07 16:49:30 +03:00
|
|
|
#include "mozilla/dom/SVGGeometryElement.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsSVGUtils.h"
|
2005-01-25 06:55:03 +03:00
|
|
|
|
2013-01-18 23:52:40 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-09-12 11:20:12 +04:00
|
|
|
using namespace mozilla::gfx;
|
2016-11-29 22:41:16 +03:00
|
|
|
using namespace mozilla::image;
|
2013-01-18 23:52:40 +04:00
|
|
|
|
2005-01-25 06:55:03 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
nsIFrame* NS_NewSVGClipPathFrame(mozilla::PresShell* aPresShell,
|
|
|
|
mozilla::ComputedStyle* aStyle) {
|
2019-02-05 19:45:54 +03:00
|
|
|
return new (aPresShell)
|
2020-07-07 16:49:30 +03:00
|
|
|
mozilla::SVGClipPathFrame(aStyle, aPresShell->GetPresContext());
|
2005-01-25 06:55:03 +03:00
|
|
|
}
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
namespace mozilla {
|
2009-09-12 20:49:24 +04:00
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(SVGClipPathFrame)
|
|
|
|
|
|
|
|
void SVGClipPathFrame::ApplyClipPath(gfxContext& aContext,
|
|
|
|
nsIFrame* aClippedFrame,
|
|
|
|
const gfxMatrix& aMatrix) {
|
2016-01-26 20:27:44 +03:00
|
|
|
MOZ_ASSERT(IsTrivial(), "Caller needs to use GetClipMask");
|
2010-02-26 12:58:42 +03:00
|
|
|
|
2018-03-09 10:36:13 +03:00
|
|
|
const DrawTarget* drawTarget = aContext.GetDrawTarget();
|
2010-02-26 12:58:42 +03:00
|
|
|
|
2017-02-17 16:15:18 +03:00
|
|
|
// No need for AutoReferenceChainGuard since simple clip paths by definition
|
|
|
|
// don't reference another clip path.
|
2015-11-11 18:15:39 +03:00
|
|
|
|
2016-01-26 20:27:44 +03:00
|
|
|
// Restore current transform after applying clip path:
|
|
|
|
gfxContextMatrixAutoSaveRestore autoRestore(&aContext);
|
2010-02-26 12:58:42 +03:00
|
|
|
|
2016-01-26 20:27:44 +03:00
|
|
|
RefPtr<Path> clipPath;
|
2010-02-26 12:58:42 +03:00
|
|
|
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* singleClipPathChild = nullptr;
|
2016-01-26 20:27:44 +03:00
|
|
|
IsTrivial(&singleClipPathChild);
|
|
|
|
|
|
|
|
if (singleClipPathChild) {
|
2016-12-18 14:11:47 +03:00
|
|
|
SVGGeometryFrame* pathFrame = do_QueryFrame(singleClipPathChild);
|
2018-10-24 08:01:57 +03:00
|
|
|
if (pathFrame && pathFrame->StyleVisibility()->IsVisible()) {
|
2016-12-18 14:11:47 +03:00
|
|
|
SVGGeometryElement* pathElement =
|
|
|
|
static_cast<SVGGeometryElement*>(pathFrame->GetContent());
|
2019-04-23 02:59:38 +03:00
|
|
|
|
|
|
|
gfxMatrix toChildsUserSpace =
|
2019-04-27 10:22:53 +03:00
|
|
|
nsSVGUtils::GetTransformMatrixInUserSpace(pathFrame) *
|
2019-04-23 02:59:38 +03:00
|
|
|
(GetClipPathTransform(aClippedFrame) * aMatrix);
|
|
|
|
|
2017-11-11 05:14:09 +03:00
|
|
|
gfxMatrix newMatrix = aContext.CurrentMatrixDouble()
|
|
|
|
.PreMultiply(toChildsUserSpace)
|
|
|
|
.NudgeToIntegers();
|
2016-01-26 20:27:44 +03:00
|
|
|
if (!newMatrix.IsSingular()) {
|
2017-11-11 05:14:09 +03:00
|
|
|
aContext.SetMatrixDouble(newMatrix);
|
2016-01-26 20:27:44 +03:00
|
|
|
FillRule clipRule =
|
|
|
|
nsSVGUtils::ToFillRule(pathFrame->StyleSVG()->mClipRule);
|
2018-03-09 10:36:13 +03:00
|
|
|
clipPath = pathElement->GetOrBuildPath(drawTarget, clipRule);
|
2010-02-26 12:58:42 +03:00
|
|
|
}
|
2005-01-25 06:55:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-26 20:27:44 +03:00
|
|
|
if (clipPath) {
|
|
|
|
aContext.Clip(clipPath);
|
|
|
|
} else {
|
|
|
|
// The spec says clip away everything if we have no children or the
|
|
|
|
// clipping path otherwise can't be resolved:
|
|
|
|
aContext.Clip(Rect());
|
2010-02-26 12:58:42 +03:00
|
|
|
}
|
2005-01-25 06:55:03 +03:00
|
|
|
}
|
|
|
|
|
2017-11-11 05:14:09 +03:00
|
|
|
static void ComposeExtraMask(DrawTarget* aTarget, SourceSurface* aExtraMask,
|
2016-11-17 07:42:14 +03:00
|
|
|
const Matrix& aExtraMasksTransform) {
|
|
|
|
MOZ_ASSERT(aExtraMask);
|
|
|
|
|
|
|
|
Matrix origin = aTarget->GetTransform();
|
|
|
|
aTarget->SetTransform(aExtraMasksTransform * aTarget->GetTransform());
|
2020-03-09 17:16:17 +03:00
|
|
|
aTarget->MaskSurface(ColorPattern(DeviceColor(0.0, 0.0, 0.0, 1.0)),
|
|
|
|
aExtraMask, Point(0, 0),
|
|
|
|
DrawOptions(1.0, CompositionOp::OP_IN));
|
2016-11-17 07:42:14 +03:00
|
|
|
aTarget->SetTransform(origin);
|
|
|
|
}
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
void SVGClipPathFrame::PaintClipMask(gfxContext& aMaskContext,
|
|
|
|
nsIFrame* aClippedFrame,
|
|
|
|
const gfxMatrix& aMatrix,
|
|
|
|
SourceSurface* aExtraMask,
|
|
|
|
const Matrix& aExtraMasksTransform) {
|
2017-02-17 16:15:18 +03:00
|
|
|
static int16_t sRefChainLengthCounter = AutoReferenceChainGuard::noChain;
|
2017-02-16 14:18:33 +03:00
|
|
|
|
|
|
|
// A clipPath can reference another clipPath, creating a chain of clipPaths
|
|
|
|
// that must all be applied. We re-enter this method for each clipPath in a
|
2017-02-17 16:15:18 +03:00
|
|
|
// chain, so we need to protect against reference chain related crashes etc.:
|
|
|
|
AutoReferenceChainGuard refChainGuard(this, &mIsBeingProcessed,
|
|
|
|
&sRefChainLengthCounter);
|
|
|
|
if (MOZ_UNLIKELY(!refChainGuard.Reference())) {
|
2017-05-18 23:03:45 +03:00
|
|
|
return; // Break reference chain
|
2015-11-11 18:15:39 +03:00
|
|
|
}
|
|
|
|
|
2016-11-17 09:50:35 +03:00
|
|
|
DrawTarget* maskDT = aMaskContext.GetDrawTarget();
|
|
|
|
MOZ_ASSERT(maskDT->GetFormat() == SurfaceFormat::A8);
|
2015-11-11 18:15:39 +03:00
|
|
|
|
2016-11-17 09:50:35 +03:00
|
|
|
// Paint this clipPath's contents into aMaskDT:
|
2016-11-17 10:15:43 +03:00
|
|
|
// We need to set mMatrixForChildren here so that under the PaintSVG calls
|
|
|
|
// on our children (below) our GetCanvasTM() method will return the correct
|
|
|
|
// transform.
|
|
|
|
mMatrixForChildren = GetClipPathTransform(aClippedFrame) * aMatrix;
|
|
|
|
|
|
|
|
// Check if this clipPath is itself clipped by another clipPath:
|
2020-07-07 16:49:30 +03:00
|
|
|
SVGClipPathFrame* clipPathThatClipsClipPath;
|
2018-09-05 20:12:44 +03:00
|
|
|
// XXX check return value?
|
|
|
|
SVGObserverUtils::GetAndObserveClipPath(this, &clipPathThatClipsClipPath);
|
2016-11-17 10:15:43 +03:00
|
|
|
nsSVGUtils::MaskUsage maskUsage;
|
|
|
|
nsSVGUtils::DetermineMaskUsage(this, true, maskUsage);
|
|
|
|
|
|
|
|
if (maskUsage.shouldApplyClipPath) {
|
|
|
|
clipPathThatClipsClipPath->ApplyClipPath(aMaskContext, aClippedFrame,
|
|
|
|
aMatrix);
|
|
|
|
} else if (maskUsage.shouldGenerateClipMaskLayer) {
|
|
|
|
RefPtr<SourceSurface> maskSurface = clipPathThatClipsClipPath->GetClipMask(
|
2019-06-21 12:51:00 +03:00
|
|
|
aMaskContext, aClippedFrame, aMatrix);
|
|
|
|
// We want the mask to be untransformed so use the inverse of the current
|
|
|
|
// transform as the maskTransform to compensate.
|
|
|
|
Matrix maskTransform = aMaskContext.CurrentMatrix();
|
|
|
|
maskTransform.Invert();
|
2016-11-17 10:15:43 +03:00
|
|
|
aMaskContext.PushGroupForBlendBack(gfxContentType::ALPHA, 1.0, maskSurface,
|
2016-11-23 19:08:13 +03:00
|
|
|
maskTransform);
|
2016-11-17 10:15:43 +03:00
|
|
|
// The corresponding PopGroupAndBlend call below will mask the
|
2016-11-23 19:08:13 +03:00
|
|
|
// blend using |maskSurface|.
|
2016-11-17 10:15:43 +03:00
|
|
|
}
|
2016-01-26 20:27:44 +03:00
|
|
|
|
2016-11-17 10:15:43 +03:00
|
|
|
// Paint our children into the mask:
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) {
|
2019-03-19 04:18:21 +03:00
|
|
|
PaintFrameIntoMask(kid, aClippedFrame, aMaskContext);
|
2016-11-17 10:15:43 +03:00
|
|
|
}
|
2016-01-26 20:27:44 +03:00
|
|
|
|
2016-11-17 10:15:43 +03:00
|
|
|
if (maskUsage.shouldGenerateClipMaskLayer) {
|
|
|
|
aMaskContext.PopGroupAndBlend();
|
|
|
|
} else if (maskUsage.shouldApplyClipPath) {
|
|
|
|
aMaskContext.PopClip();
|
2015-11-11 18:15:39 +03:00
|
|
|
}
|
|
|
|
|
2016-01-26 20:27:44 +03:00
|
|
|
if (aExtraMask) {
|
2017-11-11 05:14:09 +03:00
|
|
|
ComposeExtraMask(maskDT, aExtraMask, aExtraMasksTransform);
|
2015-11-11 18:15:39 +03:00
|
|
|
}
|
2016-11-17 09:50:35 +03:00
|
|
|
}
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
void SVGClipPathFrame::PaintFrameIntoMask(nsIFrame* aFrame,
|
|
|
|
nsIFrame* aClippedFrame,
|
|
|
|
gfxContext& aTarget) {
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* frame = do_QueryFrame(aFrame);
|
2016-11-16 11:58:59 +03:00
|
|
|
if (!frame) {
|
2017-05-18 23:03:41 +03:00
|
|
|
return;
|
2016-11-16 11:58:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// The CTM of each frame referencing us can be different.
|
2017-02-09 21:24:31 +03:00
|
|
|
frame->NotifySVGChanged(nsSVGDisplayableFrame::TRANSFORM_CHANGED);
|
2016-11-16 11:58:59 +03:00
|
|
|
|
|
|
|
// Children of this clipPath may themselves be clipped.
|
2020-07-07 16:49:30 +03:00
|
|
|
SVGClipPathFrame* clipPathThatClipsChild;
|
2018-09-05 20:12:44 +03:00
|
|
|
// XXX check return value?
|
|
|
|
if (SVGObserverUtils::GetAndObserveClipPath(aFrame,
|
|
|
|
&clipPathThatClipsChild) ==
|
|
|
|
SVGObserverUtils::eHasRefsSomeInvalid) {
|
2017-05-18 23:03:41 +03:00
|
|
|
return;
|
2016-11-16 11:58:59 +03:00
|
|
|
}
|
|
|
|
|
2016-11-17 10:11:34 +03:00
|
|
|
nsSVGUtils::MaskUsage maskUsage;
|
|
|
|
nsSVGUtils::DetermineMaskUsage(aFrame, true, maskUsage);
|
|
|
|
if (maskUsage.shouldApplyClipPath) {
|
2019-03-19 04:18:21 +03:00
|
|
|
clipPathThatClipsChild->ApplyClipPath(aTarget, aClippedFrame,
|
|
|
|
mMatrixForChildren);
|
2016-11-17 10:11:34 +03:00
|
|
|
} else if (maskUsage.shouldGenerateClipMaskLayer) {
|
|
|
|
RefPtr<SourceSurface> maskSurface = clipPathThatClipsChild->GetClipMask(
|
2019-06-21 12:51:00 +03:00
|
|
|
aTarget, aClippedFrame, mMatrixForChildren);
|
|
|
|
|
|
|
|
// We want the mask to be untransformed so use the inverse of the current
|
|
|
|
// transform as the maskTransform to compensate.
|
|
|
|
Matrix maskTransform = aTarget.CurrentMatrix();
|
|
|
|
maskTransform.Invert();
|
2016-11-17 10:11:34 +03:00
|
|
|
aTarget.PushGroupForBlendBack(gfxContentType::ALPHA, 1.0, maskSurface,
|
2016-11-23 19:08:13 +03:00
|
|
|
maskTransform);
|
2016-11-17 10:11:34 +03:00
|
|
|
// The corresponding PopGroupAndBlend call below will mask the
|
2016-11-23 19:08:13 +03:00
|
|
|
// blend using |maskSurface|.
|
2016-11-16 11:58:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix toChildsUserSpace = mMatrixForChildren;
|
|
|
|
nsIFrame* child = do_QueryFrame(frame);
|
|
|
|
nsIContent* childContent = child->GetContent();
|
|
|
|
if (childContent->IsSVGElement()) {
|
|
|
|
toChildsUserSpace =
|
2019-04-27 10:22:53 +03:00
|
|
|
nsSVGUtils::GetTransformMatrixInUserSpace(child) * mMatrixForChildren;
|
2016-11-16 11:58:59 +03:00
|
|
|
}
|
|
|
|
|
2017-05-18 23:03:41 +03:00
|
|
|
// clipPath does not result in any image rendering, so we just use a dummy
|
|
|
|
// imgDrawingParams instead of requiring our caller to pass one.
|
|
|
|
image::imgDrawingParams imgParams;
|
|
|
|
|
2016-11-16 11:58:59 +03:00
|
|
|
// Our children have NS_STATE_SVG_CLIPPATH_CHILD set on them, and
|
2016-12-18 14:11:47 +03:00
|
|
|
// SVGGeometryFrame::Render checks for that state bit and paints
|
2016-11-16 11:58:59 +03:00
|
|
|
// only the geometry (opaque black) if set.
|
2017-05-18 23:03:41 +03:00
|
|
|
frame->PaintSVG(aTarget, toChildsUserSpace, imgParams);
|
2016-11-16 11:58:59 +03:00
|
|
|
|
2016-11-17 10:11:34 +03:00
|
|
|
if (maskUsage.shouldGenerateClipMaskLayer) {
|
|
|
|
aTarget.PopGroupAndBlend();
|
|
|
|
} else if (maskUsage.shouldApplyClipPath) {
|
|
|
|
aTarget.PopClip();
|
2016-11-16 11:58:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
already_AddRefed<SourceSurface> SVGClipPathFrame::GetClipMask(
|
2016-11-17 09:50:35 +03:00
|
|
|
gfxContext& aReferenceContext, nsIFrame* aClippedFrame,
|
2019-06-21 12:51:00 +03:00
|
|
|
const gfxMatrix& aMatrix, SourceSurface* aExtraMask,
|
2016-11-23 19:08:13 +03:00
|
|
|
const Matrix& aExtraMasksTransform) {
|
2019-06-21 12:51:00 +03:00
|
|
|
RefPtr<DrawTarget> maskDT =
|
|
|
|
aReferenceContext.GetDrawTarget()->CreateClippedDrawTarget(
|
|
|
|
Rect(), SurfaceFormat::A8);
|
2016-11-17 09:50:35 +03:00
|
|
|
if (!maskDT) {
|
2017-05-18 23:03:45 +03:00
|
|
|
return nullptr;
|
2016-11-17 09:50:35 +03:00
|
|
|
}
|
|
|
|
|
2019-06-21 12:51:00 +03:00
|
|
|
RefPtr<gfxContext> maskContext =
|
|
|
|
gfxContext::CreatePreservingTransformOrNull(maskDT);
|
2016-11-17 09:50:35 +03:00
|
|
|
if (!maskContext) {
|
|
|
|
gfxCriticalError() << "SVGClipPath context problem " << gfx::hexa(maskDT);
|
2017-05-18 23:03:45 +03:00
|
|
|
return nullptr;
|
2016-11-17 09:50:35 +03:00
|
|
|
}
|
|
|
|
|
2019-06-21 12:51:00 +03:00
|
|
|
PaintClipMask(*maskContext, aClippedFrame, aMatrix, aExtraMask,
|
|
|
|
aExtraMasksTransform);
|
2016-11-17 09:50:35 +03:00
|
|
|
|
2016-11-23 19:08:13 +03:00
|
|
|
RefPtr<SourceSurface> surface = maskDT->Snapshot();
|
2017-05-18 23:03:45 +03:00
|
|
|
return surface.forget();
|
2015-11-11 18:15:39 +03:00
|
|
|
}
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
bool SVGClipPathFrame::PointIsInsideClipPath(nsIFrame* aClippedFrame,
|
|
|
|
const gfxPoint& aPoint) {
|
2017-02-17 16:15:18 +03:00
|
|
|
static int16_t sRefChainLengthCounter = AutoReferenceChainGuard::noChain;
|
2017-02-16 14:18:33 +03:00
|
|
|
|
|
|
|
// A clipPath can reference another clipPath, creating a chain of clipPaths
|
|
|
|
// that must all be applied. We re-enter this method for each clipPath in a
|
2017-02-17 16:15:18 +03:00
|
|
|
// chain, so we need to protect against reference chain related crashes etc.:
|
|
|
|
AutoReferenceChainGuard refChainGuard(this, &mIsBeingProcessed,
|
|
|
|
&sRefChainLengthCounter);
|
|
|
|
if (MOZ_UNLIKELY(!refChainGuard.Reference())) {
|
|
|
|
return false; // Break reference chain
|
2006-02-09 22:34:01 +03:00
|
|
|
}
|
|
|
|
|
2014-08-07 11:09:31 +04:00
|
|
|
gfxMatrix matrix = GetClipPathTransform(aClippedFrame);
|
|
|
|
if (!matrix.Invert()) {
|
|
|
|
return false;
|
2011-09-26 01:04:32 +04:00
|
|
|
}
|
2017-07-05 18:18:49 +03:00
|
|
|
gfxPoint point = matrix.TransformPoint(aPoint);
|
2005-01-25 06:55:03 +03:00
|
|
|
|
2014-08-07 11:09:31 +04:00
|
|
|
// clipPath elements can themselves be clipped by a different clip path. In
|
|
|
|
// that case the other clip path further clips away the element that is being
|
|
|
|
// clipped by the original clipPath. If this clipPath is being clipped by a
|
|
|
|
// different clip path we need to check if it prevents the original element
|
2018-03-18 21:09:51 +03:00
|
|
|
// from receiving events at aPoint:
|
2020-07-07 16:49:30 +03:00
|
|
|
SVGClipPathFrame* clipPathFrame;
|
2018-09-05 20:12:44 +03:00
|
|
|
// XXX check return value?
|
|
|
|
SVGObserverUtils::GetAndObserveClipPath(this, &clipPathFrame);
|
2014-08-07 11:09:31 +04:00
|
|
|
if (clipPathFrame &&
|
|
|
|
!clipPathFrame->PointIsInsideClipPath(aClippedFrame, aPoint)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2014-08-07 11:09:31 +04:00
|
|
|
}
|
2010-02-26 12:58:42 +03:00
|
|
|
|
2005-01-25 06:55:03 +03:00
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) {
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* SVGFrame = do_QueryFrame(kid);
|
2005-01-25 06:55:03 +03:00
|
|
|
if (SVGFrame) {
|
2014-08-07 11:09:31 +04:00
|
|
|
gfxPoint pointForChild = point;
|
2019-04-23 02:59:38 +03:00
|
|
|
|
2019-04-27 10:22:53 +03:00
|
|
|
gfxMatrix m = nsSVGUtils::GetTransformMatrixInUserSpace(kid);
|
2014-08-07 11:09:31 +04:00
|
|
|
if (!m.IsIdentity()) {
|
|
|
|
if (!m.Invert()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-05 18:18:49 +03:00
|
|
|
pointForChild = m.TransformPoint(point);
|
2014-08-07 11:09:31 +04:00
|
|
|
}
|
|
|
|
if (SVGFrame->GetFrameForPoint(pointForChild)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2014-08-07 11:09:31 +04:00
|
|
|
}
|
2005-01-25 06:55:03 +03:00
|
|
|
}
|
|
|
|
}
|
2016-11-17 09:50:35 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2005-01-25 06:55:03 +03:00
|
|
|
}
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
bool SVGClipPathFrame::IsTrivial(nsSVGDisplayableFrame** aSingleChild) {
|
2010-02-26 12:58:42 +03:00
|
|
|
// If the clip path is clipped then it's non-trivial
|
2018-09-05 20:12:44 +03:00
|
|
|
if (SVGObserverUtils::GetAndObserveClipPath(this, nullptr) ==
|
|
|
|
SVGObserverUtils::eHasRefsAllValid) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2018-09-05 20:12:44 +03:00
|
|
|
}
|
2010-02-26 12:58:42 +03:00
|
|
|
|
2012-06-15 13:06:34 +04:00
|
|
|
if (aSingleChild) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aSingleChild = nullptr;
|
2012-06-15 13:06:34 +04:00
|
|
|
}
|
|
|
|
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* foundChild = nullptr;
|
2006-01-20 20:00:43 +03:00
|
|
|
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) {
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* svgChild = do_QueryFrame(kid);
|
2006-06-29 02:04:48 +04:00
|
|
|
if (svgChild) {
|
|
|
|
// We consider a non-trivial clipPath to be one containing
|
|
|
|
// either more than one svg child and/or a svg container
|
2007-04-17 13:01:52 +04:00
|
|
|
if (foundChild || svgChild->IsDisplayContainer()) {
|
|
|
|
return false;
|
2018-12-12 09:32:44 +03:00
|
|
|
}
|
2010-02-26 12:58:42 +03:00
|
|
|
|
|
|
|
// or where the child is itself clipped
|
2018-09-05 20:12:44 +03:00
|
|
|
if (SVGObserverUtils::GetAndObserveClipPath(kid, nullptr) ==
|
|
|
|
SVGObserverUtils::eHasRefsAllValid) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2018-09-05 20:12:44 +03:00
|
|
|
}
|
2010-02-26 12:58:42 +03:00
|
|
|
|
2012-06-15 13:06:34 +04:00
|
|
|
foundChild = svgChild;
|
2006-01-20 20:00:43 +03:00
|
|
|
}
|
|
|
|
}
|
2012-06-15 13:06:34 +04:00
|
|
|
if (aSingleChild) {
|
|
|
|
*aSingleChild = foundChild;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-01-20 20:00:43 +03:00
|
|
|
}
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
bool SVGClipPathFrame::IsValid() {
|
2017-02-17 16:15:18 +03:00
|
|
|
static int16_t sRefChainLengthCounter = AutoReferenceChainGuard::noChain;
|
2017-02-16 14:18:33 +03:00
|
|
|
|
|
|
|
// A clipPath can reference another clipPath, creating a chain of clipPaths
|
|
|
|
// that must all be applied. We re-enter this method for each clipPath in a
|
2017-02-17 16:15:18 +03:00
|
|
|
// chain, so we need to protect against reference chain related crashes etc.:
|
|
|
|
AutoReferenceChainGuard refChainGuard(this, &mIsBeingProcessed,
|
|
|
|
&sRefChainLengthCounter);
|
|
|
|
if (MOZ_UNLIKELY(!refChainGuard.Reference())) {
|
|
|
|
return false; // Break reference chain
|
2010-03-02 12:31:07 +03:00
|
|
|
}
|
|
|
|
|
2018-09-05 20:12:44 +03:00
|
|
|
if (SVGObserverUtils::GetAndObserveClipPath(this, nullptr) ==
|
|
|
|
SVGObserverUtils::eHasRefsSomeInvalid) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-03-02 12:31:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid; kid = kid->GetNextSibling()) {
|
2017-05-01 20:32:52 +03:00
|
|
|
LayoutFrameType kidType = kid->Type();
|
2010-03-02 12:31:07 +03:00
|
|
|
|
2017-05-01 20:32:52 +03:00
|
|
|
if (kidType == LayoutFrameType::SVGUse) {
|
2016-01-29 17:42:15 +03:00
|
|
|
for (nsIFrame* grandKid : kid->PrincipalChildList()) {
|
2017-05-01 20:32:52 +03:00
|
|
|
LayoutFrameType grandKidType = grandKid->Type();
|
2010-03-02 12:31:07 +03:00
|
|
|
|
2017-05-01 20:32:52 +03:00
|
|
|
if (grandKidType != LayoutFrameType::SVGGeometry &&
|
|
|
|
grandKidType != LayoutFrameType::SVGText) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-03-02 12:31:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2016-05-17 08:02:08 +03:00
|
|
|
|
2017-05-01 20:32:52 +03:00
|
|
|
if (kidType != LayoutFrameType::SVGGeometry &&
|
|
|
|
kidType != LayoutFrameType::SVGText) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-03-02 12:31:07 +03:00
|
|
|
}
|
|
|
|
}
|
2016-05-17 08:02:08 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-03-02 12:31:07 +03:00
|
|
|
}
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
nsresult SVGClipPathFrame::AttributeChanged(int32_t aNameSpaceID,
|
|
|
|
nsAtom* aAttribute,
|
|
|
|
int32_t aModType) {
|
2011-09-19 16:59:52 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::transform) {
|
2017-08-30 17:58:31 +03:00
|
|
|
SVGObserverUtils::InvalidateDirectRenderingObservers(this);
|
2011-09-19 16:59:52 +04:00
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(
|
2017-02-09 21:24:31 +03:00
|
|
|
this, nsSVGDisplayableFrame::TRANSFORM_CHANGED);
|
2011-09-19 16:59:52 +04:00
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::clipPathUnits) {
|
2017-08-30 17:58:31 +03:00
|
|
|
SVGObserverUtils::InvalidateDirectRenderingObservers(this);
|
2011-09-19 16:59:52 +04:00
|
|
|
}
|
2010-03-24 19:54:48 +03:00
|
|
|
}
|
|
|
|
|
2020-07-09 04:33:33 +03:00
|
|
|
return SVGContainerFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
2010-03-24 19:54:48 +03:00
|
|
|
}
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
void SVGClipPathFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) {
|
2015-03-03 14:08:59 +03:00
|
|
|
NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::clipPath),
|
2013-01-08 07:22:41 +04:00
|
|
|
"Content is not an SVG clipPath!");
|
2009-01-19 21:31:34 +03:00
|
|
|
|
2010-12-06 23:57:18 +03:00
|
|
|
AddStateBits(NS_STATE_SVG_CLIPPATH_CHILD);
|
2020-07-09 04:33:33 +03:00
|
|
|
SVGContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 21:31:34 +03:00
|
|
|
}
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
gfxMatrix SVGClipPathFrame::GetCanvasTM() { return mMatrixForChildren; }
|
2014-05-13 05:24:35 +04:00
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
gfxMatrix SVGClipPathFrame::GetClipPathTransform(nsIFrame* aClippedFrame) {
|
2017-08-27 01:58:38 +03:00
|
|
|
SVGClipPathElement* content = static_cast<SVGClipPathElement*>(GetContent());
|
2014-08-07 11:09:31 +04:00
|
|
|
|
2019-04-27 10:22:53 +03:00
|
|
|
gfxMatrix tm = content->PrependLocalTransformsTo({}, eChildToUserSpace) *
|
|
|
|
nsSVGUtils::GetTransformMatrixInUserSpace(this);
|
2014-08-07 11:09:31 +04:00
|
|
|
|
2019-04-04 20:40:56 +03:00
|
|
|
SVGAnimatedEnumeration* clipPathUnits =
|
2014-08-07 11:09:31 +04:00
|
|
|
&content->mEnumAttributes[SVGClipPathElement::CLIPPATHUNITS];
|
|
|
|
|
2017-08-17 04:52:17 +03:00
|
|
|
uint32_t flags = nsSVGUtils::eBBoxIncludeFillGeometry |
|
|
|
|
(aClippedFrame->StyleBorder()->mBoxDecorationBreak ==
|
|
|
|
StyleBoxDecorationBreak::Clone
|
|
|
|
? nsSVGUtils::eIncludeOnlyCurrentFrameForNonSVGElement
|
|
|
|
: 0);
|
|
|
|
|
|
|
|
return nsSVGUtils::AdjustMatrixForUnits(tm, clipPathUnits, aClippedFrame,
|
|
|
|
flags);
|
2014-08-07 11:09:31 +04:00
|
|
|
}
|
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
SVGBBox SVGClipPathFrame::GetBBoxForClipPathFrame(const SVGBBox& aBBox,
|
|
|
|
const gfxMatrix& aMatrix,
|
|
|
|
uint32_t aFlags) {
|
|
|
|
SVGClipPathFrame* clipPathThatClipsClipPath;
|
2018-09-05 20:12:44 +03:00
|
|
|
if (SVGObserverUtils::GetAndObserveClipPath(this,
|
|
|
|
&clipPathThatClipsClipPath) ==
|
|
|
|
SVGObserverUtils::eHasRefsSomeInvalid) {
|
|
|
|
return SVGBBox();
|
|
|
|
}
|
|
|
|
|
2014-05-13 05:24:35 +04:00
|
|
|
nsIContent* node = GetContent()->GetFirstChild();
|
|
|
|
SVGBBox unionBBox, tmpBBox;
|
|
|
|
for (; node; node = node->GetNextSibling()) {
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* svgNode = static_cast<SVGElement*>(node);
|
2017-09-20 19:39:59 +03:00
|
|
|
nsIFrame* frame = svgNode->GetPrimaryFrame();
|
2014-05-13 05:24:35 +04:00
|
|
|
if (frame) {
|
2017-02-09 21:24:31 +03:00
|
|
|
nsSVGDisplayableFrame* svg = do_QueryFrame(frame);
|
2014-05-13 05:24:35 +04:00
|
|
|
if (svg) {
|
2017-09-20 19:39:59 +03:00
|
|
|
gfxMatrix matrix =
|
2019-04-27 10:22:53 +03:00
|
|
|
nsSVGUtils::GetTransformMatrixInUserSpace(frame) * aMatrix;
|
2020-07-07 16:49:30 +03:00
|
|
|
tmpBBox = svg->GetBBoxContribution(gfx::ToMatrix(matrix),
|
2016-12-07 10:28:47 +03:00
|
|
|
nsSVGUtils::eBBoxIncludeFill);
|
2020-07-07 16:49:30 +03:00
|
|
|
SVGClipPathFrame* clipPathFrame;
|
2018-09-05 20:12:44 +03:00
|
|
|
if (SVGObserverUtils::GetAndObserveClipPath(frame, &clipPathFrame) !=
|
|
|
|
SVGObserverUtils::eHasRefsSomeInvalid &&
|
|
|
|
clipPathFrame) {
|
|
|
|
tmpBBox =
|
|
|
|
clipPathFrame->GetBBoxForClipPathFrame(tmpBBox, aMatrix, aFlags);
|
2016-12-07 10:28:47 +03:00
|
|
|
}
|
2018-05-12 01:55:30 +03:00
|
|
|
if (!(aFlags & nsSVGUtils::eDoNotClipToBBoxOfContentInsideClipPath)) {
|
|
|
|
tmpBBox.Intersect(aBBox);
|
|
|
|
}
|
2014-05-13 05:24:35 +04:00
|
|
|
unionBBox.UnionEdges(tmpBBox);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-07 10:28:47 +03:00
|
|
|
|
2018-09-05 20:12:44 +03:00
|
|
|
if (clipPathThatClipsClipPath) {
|
|
|
|
tmpBBox = clipPathThatClipsClipPath->GetBBoxForClipPathFrame(aBBox, aMatrix,
|
|
|
|
aFlags);
|
|
|
|
unionBBox.Intersect(tmpBBox);
|
2014-05-13 05:24:35 +04:00
|
|
|
}
|
|
|
|
return unionBBox;
|
|
|
|
}
|
2019-04-23 02:59:38 +03:00
|
|
|
|
2020-07-07 16:49:30 +03:00
|
|
|
bool SVGClipPathFrame::IsSVGTransformed(Matrix* aOwnTransforms,
|
|
|
|
Matrix* aFromParentTransforms) const {
|
2019-04-23 02:59:38 +03:00
|
|
|
auto e = static_cast<SVGElement const*>(GetContent());
|
|
|
|
Matrix m = ToMatrix(e->PrependLocalTransformsTo({}, eUserSpaceToParent));
|
|
|
|
|
|
|
|
if (m.IsIdentity()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOwnTransforms) {
|
|
|
|
*aOwnTransforms = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-07-07 16:49:30 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|