2005-01-25 06:55:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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:
|
2012-03-20 16:15:55 +04:00
|
|
|
#include "nsSVGClipPathFrame.h"
|
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
#include "gfxContext.h"
|
2014-09-12 11:20:12 +04:00
|
|
|
#include "mozilla/dom/SVGClipPathElement.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsSVGEffects.h"
|
2014-09-29 17:15:19 +04:00
|
|
|
#include "nsSVGPathGeometryElement.h"
|
|
|
|
#include "nsSVGPathGeometryFrame.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2005-01-25 06:55:03 +03:00
|
|
|
|
2014-09-12 11:20:12 +04:00
|
|
|
using namespace mozilla;
|
2013-01-18 23:52:40 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-09-12 11:20:12 +04:00
|
|
|
using namespace mozilla::gfx;
|
2013-01-18 23:52:40 +04:00
|
|
|
|
2016-03-09 13:26:48 +03:00
|
|
|
// Arbitrary number
|
|
|
|
#define MAX_SVG_CLIP_PATH_REFERENCE_CHAIN_LENGTH int16_t(512)
|
|
|
|
|
2005-01-25 06:55:03 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2009-01-19 21:31:34 +03:00
|
|
|
NS_NewSVGClipPathFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2005-01-25 06:55:03 +03:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsSVGClipPathFrame(aContext);
|
2005-01-25 06:55:03 +03:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGClipPathFrame)
|
|
|
|
|
2016-01-26 20:27:44 +03:00
|
|
|
void
|
|
|
|
nsSVGClipPathFrame::ApplyClipPath(gfxContext& aContext,
|
|
|
|
nsIFrame* aClippedFrame,
|
|
|
|
const gfxMatrix& aMatrix)
|
2005-01-25 06:55:03 +03:00
|
|
|
{
|
2016-01-26 20:27:44 +03:00
|
|
|
MOZ_ASSERT(IsTrivial(), "Caller needs to use GetClipMask");
|
2010-02-26 12:58:42 +03:00
|
|
|
|
2016-01-26 20:27:44 +03:00
|
|
|
DrawTarget& aDrawTarget = *aContext.GetDrawTarget();
|
2010-02-26 12:58:42 +03:00
|
|
|
|
2016-03-09 13:26:48 +03:00
|
|
|
// No need for AutoReferenceLimiter since simple clip paths can't create
|
2016-01-28 12:30:47 +03:00
|
|
|
// a reference loop (they don't reference other clip paths).
|
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
|
|
|
|
2016-01-26 20:27:44 +03:00
|
|
|
nsISVGChildFrame* singleClipPathChild = nullptr;
|
|
|
|
IsTrivial(&singleClipPathChild);
|
|
|
|
|
|
|
|
if (singleClipPathChild) {
|
|
|
|
nsSVGPathGeometryFrame* pathFrame = do_QueryFrame(singleClipPathChild);
|
|
|
|
if (pathFrame) {
|
|
|
|
nsSVGPathGeometryElement* pathElement =
|
|
|
|
static_cast<nsSVGPathGeometryElement*>(pathFrame->GetContent());
|
|
|
|
gfxMatrix toChildsUserSpace = pathElement->
|
|
|
|
PrependLocalTransformsTo(GetClipPathTransform(aClippedFrame) * aMatrix,
|
|
|
|
eUserSpaceToParent);
|
|
|
|
gfxMatrix newMatrix =
|
|
|
|
aContext.CurrentMatrix().PreMultiply(toChildsUserSpace).NudgeToIntegers();
|
|
|
|
if (!newMatrix.IsSingular()) {
|
|
|
|
aContext.SetMatrix(newMatrix);
|
|
|
|
FillRule clipRule =
|
|
|
|
nsSVGUtils::ToFillRule(pathFrame->StyleSVG()->mClipRule);
|
|
|
|
clipPath = pathElement->GetOrBuildPath(aDrawTarget, 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
|
|
|
}
|
|
|
|
|
2016-11-17 09:50:35 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
|
|
|
nsSVGClipPathFrame::CreateClipMask(gfxContext& aReferenceContext,
|
|
|
|
IntPoint& aOffset)
|
2015-11-11 18:15:39 +03:00
|
|
|
{
|
2016-11-17 09:50:35 +03:00
|
|
|
gfxContextMatrixAutoSaveRestore autoRestoreMatrix(&aReferenceContext);
|
|
|
|
|
|
|
|
aReferenceContext.SetMatrix(gfxMatrix());
|
|
|
|
gfxRect rect = aReferenceContext.GetClipExtents();
|
|
|
|
IntRect bounds = RoundedOut(ToRect(rect));
|
|
|
|
if (bounds.IsEmpty()) {
|
|
|
|
// We don't need to create a mask surface, all drawing is clipped anyway.
|
|
|
|
return nullptr;
|
2016-07-14 07:47:06 +03:00
|
|
|
}
|
2016-01-26 20:27:44 +03:00
|
|
|
|
2016-11-17 09:50:35 +03:00
|
|
|
DrawTarget* referenceDT = aReferenceContext.GetDrawTarget();
|
|
|
|
RefPtr<DrawTarget> maskDT =
|
|
|
|
referenceDT->CreateSimilarDrawTarget(bounds.Size(), SurfaceFormat::A8);
|
|
|
|
|
|
|
|
aOffset = bounds.TopLeft();
|
|
|
|
|
|
|
|
return maskDT.forget();
|
|
|
|
}
|
|
|
|
|
2016-11-17 07:42:14 +03:00
|
|
|
static void
|
|
|
|
ComposeExtraMask(DrawTarget* aTarget, const gfxMatrix& aMaskTransfrom,
|
|
|
|
SourceSurface* aExtraMask, const Matrix& aExtraMasksTransform)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aExtraMask);
|
|
|
|
|
|
|
|
Matrix origin = aTarget->GetTransform();
|
|
|
|
aTarget->SetTransform(aExtraMasksTransform * aTarget->GetTransform());
|
|
|
|
aTarget->MaskSurface(ColorPattern(Color(0.0, 0.0, 0.0, 1.0)),
|
|
|
|
aExtraMask,
|
|
|
|
Point(0, 0),
|
|
|
|
DrawOptions(1.0, CompositionOp::OP_IN));
|
|
|
|
aTarget->SetTransform(origin);
|
|
|
|
}
|
|
|
|
|
2016-11-17 09:50:35 +03:00
|
|
|
DrawResult
|
|
|
|
nsSVGClipPathFrame::PaintClipMask(gfxContext& aMaskContext,
|
|
|
|
nsIFrame* aClippedFrame,
|
|
|
|
const gfxMatrix& aMatrix,
|
|
|
|
Matrix* aMaskTransform,
|
|
|
|
SourceSurface* aExtraMask,
|
|
|
|
const Matrix& aExtraMasksTransform)
|
|
|
|
{
|
2016-03-09 13:26:48 +03:00
|
|
|
// A clipPath can reference another clipPath. We re-enter this method for
|
|
|
|
// each clipPath in a reference chain, so here we limit chain length:
|
|
|
|
static int16_t sRefChainLengthCounter = AutoReferenceLimiter::notReferencing;
|
|
|
|
AutoReferenceLimiter
|
|
|
|
refChainLengthLimiter(&sRefChainLengthCounter,
|
|
|
|
MAX_SVG_CLIP_PATH_REFERENCE_CHAIN_LENGTH);
|
|
|
|
if (!refChainLengthLimiter.Reference()) {
|
2016-11-17 09:50:35 +03:00
|
|
|
return DrawResult::SUCCESS; // Reference chain is too long!
|
2016-03-09 13:26:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// And to prevent reference loops we check that this clipPath only appears
|
2016-03-09 13:26:48 +03:00
|
|
|
// once in the reference chain (if any) that we're currently processing:
|
|
|
|
AutoReferenceLimiter refLoopDetector(&mReferencing, 1);
|
|
|
|
if (!refLoopDetector.Reference()) {
|
2016-11-17 09:50:35 +03:00
|
|
|
return DrawResult::SUCCESS; // Reference loop!
|
2015-11-11 18:15:39 +03:00
|
|
|
}
|
|
|
|
|
2016-11-17 09:50:35 +03:00
|
|
|
DrawResult result = DrawResult::SUCCESS;
|
|
|
|
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:
|
2015-11-11 18:15:39 +03:00
|
|
|
{
|
2016-01-26 20:27:44 +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:
|
|
|
|
nsSVGClipPathFrame* clipPathThatClipsClipPath =
|
|
|
|
nsSVGEffects::GetEffectProperties(this).GetClipPathFrame(nullptr);
|
2016-11-17 10:11:34 +03:00
|
|
|
nsSVGUtils::MaskUsage maskUsage;
|
|
|
|
nsSVGUtils::DetermineMaskUsage(this, true, maskUsage);
|
|
|
|
|
|
|
|
if (maskUsage.shouldApplyClipPath) {
|
|
|
|
clipPathThatClipsClipPath->ApplyClipPath(aMaskContext, aClippedFrame,
|
|
|
|
aMatrix);
|
|
|
|
} else if (maskUsage.shouldGenerateClipMaskLayer) {
|
|
|
|
Matrix maskTransform;
|
|
|
|
RefPtr<SourceSurface> mask =
|
|
|
|
clipPathThatClipsClipPath->GetClipMask(aMaskContext, aClippedFrame,
|
|
|
|
aMatrix, &maskTransform);
|
|
|
|
aMaskContext.PushGroupForBlendBack(gfxContentType::ALPHA, 1.0,
|
|
|
|
mask, maskTransform);
|
|
|
|
// The corresponding PopGroupAndBlend call below will mask the
|
|
|
|
// blend using |mask|.
|
2016-01-26 20:27:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Paint our children into the mask:
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
2016-11-16 11:58:59 +03:00
|
|
|
result &= PaintFrameIntoMask(kid, aClippedFrame, aMaskContext, aMatrix);
|
2016-01-26 20:27:44 +03:00
|
|
|
}
|
|
|
|
|
2016-11-17 10:11:34 +03:00
|
|
|
if (maskUsage.shouldGenerateClipMaskLayer) {
|
|
|
|
aMaskContext.PopGroupAndBlend();
|
|
|
|
} else if (maskUsage.shouldApplyClipPath) {
|
|
|
|
aMaskContext.PopClip();
|
2016-01-26 20:27:44 +03:00
|
|
|
}
|
2015-11-11 18:15:39 +03:00
|
|
|
}
|
|
|
|
|
2016-01-26 20:27:44 +03:00
|
|
|
// Moz2D transforms in the opposite direction to Thebes
|
2016-11-17 09:50:35 +03:00
|
|
|
gfxMatrix maskTransfrom = aMaskContext.CurrentMatrix();
|
|
|
|
maskTransfrom.Invert();
|
2015-11-11 18:15:39 +03:00
|
|
|
|
2016-01-26 20:27:44 +03:00
|
|
|
if (aExtraMask) {
|
2016-11-17 07:42:14 +03:00
|
|
|
ComposeExtraMask(maskDT, maskTransfrom, aExtraMask, aExtraMasksTransform);
|
2015-11-11 18:15:39 +03:00
|
|
|
}
|
|
|
|
|
2016-11-17 09:50:35 +03:00
|
|
|
*aMaskTransform = ToMatrix(maskTransfrom);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-16 11:58:59 +03:00
|
|
|
DrawResult
|
|
|
|
nsSVGClipPathFrame::PaintFrameIntoMask(nsIFrame *aFrame,
|
|
|
|
nsIFrame* aClippedFrame,
|
|
|
|
gfxContext& aTarget,
|
|
|
|
const gfxMatrix& aMatrix)
|
|
|
|
{
|
|
|
|
nsISVGChildFrame* frame = do_QueryFrame(aFrame);
|
|
|
|
if (!frame) {
|
|
|
|
return DrawResult::SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The CTM of each frame referencing us can be different.
|
|
|
|
frame->NotifySVGChanged(nsISVGChildFrame::TRANSFORM_CHANGED);
|
|
|
|
|
|
|
|
bool isOK = true;
|
|
|
|
// Children of this clipPath may themselves be clipped.
|
|
|
|
nsSVGClipPathFrame *clipPathThatClipsChild =
|
|
|
|
nsSVGEffects::GetEffectProperties(aFrame).GetClipPathFrame(&isOK);
|
|
|
|
if (!isOK) {
|
|
|
|
return DrawResult::SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-11-17 10:11:34 +03:00
|
|
|
nsSVGUtils::MaskUsage maskUsage;
|
|
|
|
nsSVGUtils::DetermineMaskUsage(aFrame, true, maskUsage);
|
|
|
|
if (maskUsage.shouldApplyClipPath) {
|
|
|
|
clipPathThatClipsChild->ApplyClipPath(aTarget, aClippedFrame, aMatrix);
|
|
|
|
} else if (maskUsage.shouldGenerateClipMaskLayer) {
|
|
|
|
Matrix maskTransform;
|
|
|
|
RefPtr<SourceSurface> mask =
|
|
|
|
clipPathThatClipsChild->GetClipMask(aTarget, aClippedFrame,
|
|
|
|
aMatrix, &maskTransform);
|
|
|
|
aTarget.PushGroupForBlendBack(gfxContentType::ALPHA, 1.0,
|
|
|
|
mask, maskTransform);
|
|
|
|
// The corresponding PopGroupAndBlend call below will mask the
|
|
|
|
// blend using |mask|.
|
2016-11-16 11:58:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix toChildsUserSpace = mMatrixForChildren;
|
|
|
|
nsIFrame* child = do_QueryFrame(frame);
|
|
|
|
nsIContent* childContent = child->GetContent();
|
|
|
|
if (childContent->IsSVGElement()) {
|
|
|
|
toChildsUserSpace =
|
|
|
|
static_cast<const nsSVGElement*>(childContent)->
|
|
|
|
PrependLocalTransformsTo(mMatrixForChildren, eUserSpaceToParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Our children have NS_STATE_SVG_CLIPPATH_CHILD set on them, and
|
|
|
|
// nsSVGPathGeometryFrame::Render checks for that state bit and paints
|
|
|
|
// only the geometry (opaque black) if set.
|
|
|
|
DrawResult result = frame->PaintSVG(aTarget, toChildsUserSpace);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-11-17 09:50:35 +03:00
|
|
|
already_AddRefed<SourceSurface>
|
|
|
|
nsSVGClipPathFrame::GetClipMask(gfxContext& aReferenceContext,
|
|
|
|
nsIFrame* aClippedFrame,
|
|
|
|
const gfxMatrix& aMatrix,
|
|
|
|
Matrix* aMaskTransform,
|
|
|
|
SourceSurface* aExtraMask,
|
|
|
|
const Matrix& aExtraMasksTransform,
|
|
|
|
DrawResult* aResult)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!IsTrivial(), "Caller needs to use ApplyClipPath");
|
|
|
|
|
|
|
|
IntPoint offset;
|
|
|
|
RefPtr<DrawTarget> maskDT = CreateClipMask(aReferenceContext, offset);
|
|
|
|
if (!maskDT) {
|
|
|
|
if (aResult) {
|
|
|
|
*aResult = DrawResult::SUCCESS;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<gfxContext> maskContext = gfxContext::CreateOrNull(maskDT);
|
|
|
|
if (!maskContext) {
|
|
|
|
gfxCriticalError() << "SVGClipPath context problem " << gfx::hexa(maskDT);
|
|
|
|
if (aResult) {
|
|
|
|
*aResult = DrawResult::TEMPORARY_ERROR;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
maskContext->SetMatrix(aReferenceContext.CurrentMatrix() *
|
|
|
|
gfxMatrix::Translation(-offset));
|
|
|
|
|
|
|
|
DrawResult result = PaintClipMask(*maskContext, aClippedFrame, aMatrix,
|
|
|
|
aMaskTransform, aExtraMask,
|
|
|
|
aExtraMasksTransform);
|
|
|
|
if (aResult) {
|
|
|
|
*aResult = result;
|
|
|
|
}
|
|
|
|
|
2015-11-11 18:15:39 +03:00
|
|
|
return maskDT->Snapshot();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-08-07 11:09:31 +04:00
|
|
|
nsSVGClipPathFrame::PointIsInsideClipPath(nsIFrame* aClippedFrame,
|
|
|
|
const gfxPoint &aPoint)
|
2005-01-25 06:55:03 +03:00
|
|
|
{
|
2016-03-09 13:26:48 +03:00
|
|
|
// A clipPath can reference another clipPath. We re-enter this method for
|
|
|
|
// each clipPath in a reference chain, so here we limit chain length:
|
|
|
|
static int16_t sRefChainLengthCounter = AutoReferenceLimiter::notReferencing;
|
|
|
|
AutoReferenceLimiter
|
|
|
|
refChainLengthLimiter(&sRefChainLengthCounter,
|
|
|
|
MAX_SVG_CLIP_PATH_REFERENCE_CHAIN_LENGTH);
|
|
|
|
if (!refChainLengthLimiter.Reference()) {
|
|
|
|
return false; // Reference chain is too long!
|
|
|
|
}
|
|
|
|
|
|
|
|
// And to prevent reference loops we check that this clipPath only appears
|
2016-03-09 13:26:48 +03:00
|
|
|
// once in the reference chain (if any) that we're currently processing:
|
|
|
|
AutoReferenceLimiter refLoopDetector(&mReferencing, 1);
|
|
|
|
if (!refLoopDetector.Reference()) {
|
|
|
|
return true; // Reference loop!
|
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
|
|
|
}
|
2014-08-07 11:09:31 +04:00
|
|
|
gfxPoint point = matrix.Transform(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
|
|
|
|
// from recieving events at aPoint:
|
2010-02-26 12:58:42 +03:00
|
|
|
nsSVGClipPathFrame *clipPathFrame =
|
2012-07-30 18:20:58 +04:00
|
|
|
nsSVGEffects::GetEffectProperties(this).GetClipPathFrame(nullptr);
|
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()) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsISVGChildFrame* 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;
|
|
|
|
gfxMatrix m = static_cast<nsSVGElement*>(kid->GetContent())->
|
2015-12-03 01:36:23 +03:00
|
|
|
PrependLocalTransformsTo(gfxMatrix(), eUserSpaceToParent);
|
2014-08-07 11:09:31 +04:00
|
|
|
if (!m.IsIdentity()) {
|
|
|
|
if (!m.Invert()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
pointForChild = m.Transform(point);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-06-15 13:06:34 +04:00
|
|
|
nsSVGClipPathFrame::IsTrivial(nsISVGChildFrame **aSingleChild)
|
2006-01-20 20:00:43 +03:00
|
|
|
{
|
2010-02-26 12:58:42 +03:00
|
|
|
// If the clip path is clipped then it's non-trivial
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nsSVGEffects::GetEffectProperties(this).GetClipPathFrame(nullptr))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
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
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsISVGChildFrame *foundChild = nullptr;
|
2006-01-20 20:00:43 +03:00
|
|
|
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsISVGChildFrame *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())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-02-26 12:58:42 +03:00
|
|
|
|
|
|
|
// or where the child is itself clipped
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nsSVGEffects::GetEffectProperties(kid).GetClipPathFrame(nullptr))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
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
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-03-02 12:31:07 +03:00
|
|
|
nsSVGClipPathFrame::IsValid()
|
|
|
|
{
|
2016-03-09 13:26:48 +03:00
|
|
|
// A clipPath can reference another clipPath. We re-enter this method for
|
|
|
|
// each clipPath in a reference chain, so here we limit chain length:
|
|
|
|
static int16_t sRefChainLengthCounter = AutoReferenceLimiter::notReferencing;
|
|
|
|
AutoReferenceLimiter
|
|
|
|
refChainLengthLimiter(&sRefChainLengthCounter,
|
|
|
|
MAX_SVG_CLIP_PATH_REFERENCE_CHAIN_LENGTH);
|
|
|
|
if (!refChainLengthLimiter.Reference()) {
|
|
|
|
return false; // Reference chain is too long!
|
|
|
|
}
|
|
|
|
|
|
|
|
// And to prevent reference loops we check that this clipPath only appears
|
2016-03-09 13:26:48 +03:00
|
|
|
// once in the reference chain (if any) that we're currently processing:
|
|
|
|
AutoReferenceLimiter refLoopDetector(&mReferencing, 1);
|
|
|
|
if (!refLoopDetector.Reference()) {
|
2016-01-28 12:30:47 +03:00
|
|
|
return false; // Reference loop!
|
2010-03-02 12:31:07 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isOK = true;
|
2010-03-02 12:31:07 +03:00
|
|
|
nsSVGEffects::GetEffectProperties(this).GetClipPathFrame(&isOK);
|
|
|
|
if (!isOK) {
|
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()) {
|
|
|
|
|
2016-05-17 08:02:08 +03:00
|
|
|
nsIAtom* kidType = kid->GetType();
|
2010-03-02 12:31:07 +03:00
|
|
|
|
2016-05-17 08:02:08 +03:00
|
|
|
if (kidType == nsGkAtoms::svgUseFrame) {
|
2016-01-29 17:42:15 +03:00
|
|
|
for (nsIFrame* grandKid : kid->PrincipalChildList()) {
|
2010-03-02 12:31:07 +03:00
|
|
|
|
2016-05-17 08:02:08 +03:00
|
|
|
nsIAtom* grandKidType = grandKid->GetType();
|
2010-03-02 12:31:07 +03:00
|
|
|
|
2016-05-17 08:02:08 +03:00
|
|
|
if (grandKidType != nsGkAtoms::svgPathGeometryFrame &&
|
|
|
|
grandKidType != nsGkAtoms::svgTextFrame) {
|
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
|
|
|
|
|
|
|
if (kidType != nsGkAtoms::svgPathGeometryFrame &&
|
|
|
|
kidType != nsGkAtoms::svgTextFrame) {
|
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
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGClipPathFrame::AttributeChanged(int32_t aNameSpaceID,
|
2010-03-24 19:54:48 +03:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
2010-03-24 19:54:48 +03:00
|
|
|
{
|
2011-09-19 16:59:52 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::transform) {
|
2012-06-23 18:18:49 +04:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2011-09-19 16:59:52 +04:00
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(this,
|
|
|
|
nsISVGChildFrame::TRANSFORM_CHANGED);
|
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::clipPathUnits) {
|
2014-11-06 12:30:11 +03:00
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2011-09-19 16:59:52 +04:00
|
|
|
}
|
2010-03-24 19:54:48 +03:00
|
|
|
}
|
|
|
|
|
2016-04-18 09:54:51 +03:00
|
|
|
return nsSVGContainerFrame::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
2010-03-24 19:54:48 +03:00
|
|
|
}
|
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsSVGClipPathFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2009-01-19 21:31:34 +03:00
|
|
|
{
|
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);
|
2016-04-18 09:54:51 +03:00
|
|
|
nsSVGContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2009-01-19 21:31:34 +03:00
|
|
|
}
|
|
|
|
|
2005-04-01 23:56:08 +04:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGClipPathFrame::GetType() const
|
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::svgClipPathFrame;
|
2005-04-01 23:56:08 +04:00
|
|
|
}
|
|
|
|
|
2009-04-29 08:31:34 +04:00
|
|
|
gfxMatrix
|
2014-09-08 15:28:50 +04:00
|
|
|
nsSVGClipPathFrame::GetCanvasTM()
|
2005-01-25 06:55:03 +03:00
|
|
|
{
|
2014-08-13 16:34:52 +04:00
|
|
|
return mMatrixForChildren;
|
2005-01-25 06:55:03 +03:00
|
|
|
}
|
2014-05-13 05:24:35 +04:00
|
|
|
|
2014-08-07 11:09:31 +04:00
|
|
|
gfxMatrix
|
|
|
|
nsSVGClipPathFrame::GetClipPathTransform(nsIFrame* aClippedFrame)
|
|
|
|
{
|
|
|
|
SVGClipPathElement *content = static_cast<SVGClipPathElement*>(mContent);
|
|
|
|
|
|
|
|
gfxMatrix tm = content->PrependLocalTransformsTo(gfxMatrix());
|
|
|
|
|
|
|
|
nsSVGEnum* clipPathUnits =
|
|
|
|
&content->mEnumAttributes[SVGClipPathElement::CLIPPATHUNITS];
|
|
|
|
|
|
|
|
return nsSVGUtils::AdjustMatrixForUnits(tm, clipPathUnits, aClippedFrame);
|
|
|
|
}
|
|
|
|
|
2014-05-13 05:24:35 +04:00
|
|
|
SVGBBox
|
|
|
|
nsSVGClipPathFrame::GetBBoxForClipPathFrame(const SVGBBox &aBBox,
|
|
|
|
const gfxMatrix &aMatrix)
|
|
|
|
{
|
|
|
|
nsIContent* node = GetContent()->GetFirstChild();
|
|
|
|
SVGBBox unionBBox, tmpBBox;
|
|
|
|
for (; node; node = node->GetNextSibling()) {
|
|
|
|
nsIFrame *frame =
|
|
|
|
static_cast<nsSVGElement*>(node)->GetPrimaryFrame();
|
|
|
|
if (frame) {
|
|
|
|
nsISVGChildFrame *svg = do_QueryFrame(frame);
|
|
|
|
if (svg) {
|
|
|
|
tmpBBox = svg->GetBBoxContribution(mozilla::gfx::ToMatrix(aMatrix),
|
|
|
|
nsSVGUtils::eBBoxIncludeFill);
|
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(frame);
|
|
|
|
bool isOK = true;
|
|
|
|
nsSVGClipPathFrame *clipPathFrame =
|
|
|
|
effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
if (clipPathFrame && isOK) {
|
|
|
|
tmpBBox = clipPathFrame->GetBBoxForClipPathFrame(tmpBBox, aMatrix);
|
|
|
|
}
|
|
|
|
tmpBBox.Intersect(aBBox);
|
|
|
|
unionBBox.UnionEdges(tmpBBox);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsSVGEffects::EffectProperties props =
|
|
|
|
nsSVGEffects::GetEffectProperties(this);
|
|
|
|
if (props.mClipPath) {
|
|
|
|
bool isOK = true;
|
|
|
|
nsSVGClipPathFrame *clipPathFrame = props.GetClipPathFrame(&isOK);
|
|
|
|
if (clipPathFrame && isOK) {
|
|
|
|
tmpBBox = clipPathFrame->GetBBoxForClipPathFrame(aBBox, aMatrix);
|
|
|
|
unionBBox.Intersect(tmpBBox);
|
|
|
|
} else if (!isOK) {
|
|
|
|
unionBBox = SVGBBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return unionBBox;
|
|
|
|
}
|