2005-01-25 03:55:03 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla SVG project.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is IBM Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMSVGClipPathElement.h"
|
|
|
|
#include "nsSVGClipPathFrame.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2006-01-20 21:37:46 +00:00
|
|
|
#include "nsSVGUtils.h"
|
2010-02-26 09:58:42 +00:00
|
|
|
#include "nsSVGEffects.h"
|
2007-04-27 08:42:51 +00:00
|
|
|
#include "nsSVGClipPathElement.h"
|
2006-11-27 17:30:57 +00:00
|
|
|
#include "gfxContext.h"
|
2005-01-25 03:55:03 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2005-11-11 02:36:29 +00:00
|
|
|
nsIFrame*
|
2009-01-19 18:31:34 +00:00
|
|
|
NS_NewSVGClipPathFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2005-01-25 03:55:03 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsSVGClipPathFrame(aContext);
|
2005-01-25 03:55:03 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGClipPathFrame)
|
|
|
|
|
2007-04-17 09:01:52 +00:00
|
|
|
nsresult
|
2006-11-27 17:30:57 +00:00
|
|
|
nsSVGClipPathFrame::ClipPaint(nsSVGRenderState* aContext,
|
2008-09-11 00:24:16 +00:00
|
|
|
nsIFrame* aParent,
|
2009-07-23 08:35:59 +00:00
|
|
|
const gfxMatrix &aMatrix)
|
2005-01-25 03:55:03 +00:00
|
|
|
{
|
2006-02-09 19:34:01 +00:00
|
|
|
// If the flag is set when we get here, it means this clipPath frame
|
|
|
|
// has already been used painting the current clip, and the document
|
|
|
|
// has a clip reference loop.
|
|
|
|
if (mInUse) {
|
|
|
|
NS_WARNING("Clip loop detected!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-04-17 09:01:52 +00:00
|
|
|
AutoClipPathReferencer clipRef(this);
|
2006-02-09 19:34:01 +00:00
|
|
|
|
2010-02-26 09:58:42 +00:00
|
|
|
mClipParent = aParent;
|
2011-09-25 21:04:32 +00:00
|
|
|
if (mClipParentMatrix) {
|
|
|
|
*mClipParentMatrix = aMatrix;
|
|
|
|
} else {
|
|
|
|
mClipParentMatrix = new gfxMatrix(aMatrix);
|
|
|
|
}
|
2005-01-25 03:55:03 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isTrivial = IsTrivial();
|
2006-01-20 17:00:43 +00:00
|
|
|
|
2006-11-27 17:30:57 +00:00
|
|
|
nsAutoSVGRenderMode mode(aContext,
|
|
|
|
isTrivial ? nsSVGRenderState::CLIP
|
|
|
|
: nsSVGRenderState::CLIP_MASK);
|
2005-01-25 03:55:03 +00:00
|
|
|
|
2010-02-26 09:58:42 +00:00
|
|
|
|
|
|
|
gfxContext *gfx = aContext->GetGfxContext();
|
|
|
|
|
|
|
|
nsSVGClipPathFrame *clipPathFrame =
|
2010-03-02 09:31:07 +00:00
|
|
|
nsSVGEffects::GetEffectProperties(this).GetClipPathFrame(nsnull);
|
2011-09-29 06:19:26 +00:00
|
|
|
bool referencedClipIsTrivial;
|
2010-02-26 09:58:42 +00:00
|
|
|
if (clipPathFrame) {
|
|
|
|
referencedClipIsTrivial = clipPathFrame->IsTrivial();
|
|
|
|
gfx->Save();
|
|
|
|
if (referencedClipIsTrivial) {
|
|
|
|
clipPathFrame->ClipPaint(aContext, aParent, aMatrix);
|
|
|
|
} else {
|
|
|
|
gfx->PushGroup(gfxASurface::CONTENT_ALPHA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-25 03:55:03 +00:00
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
2009-01-12 19:20:59 +00:00
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
|
2005-01-25 03:55:03 +00:00
|
|
|
if (SVGFrame) {
|
2008-01-25 09:27:03 +00:00
|
|
|
// The CTM of each frame referencing us can be different.
|
|
|
|
SVGFrame->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION |
|
|
|
|
nsISVGChildFrame::TRANSFORM_CHANGED);
|
2010-02-26 09:58:42 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isOK = true;
|
2010-02-26 09:58:42 +00:00
|
|
|
nsSVGClipPathFrame *clipPathFrame =
|
|
|
|
nsSVGEffects::GetEffectProperties(kid).GetClipPathFrame(&isOK);
|
2010-03-02 09:31:07 +00:00
|
|
|
if (!isOK) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-02-26 09:58:42 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isTrivial;
|
2010-02-26 09:58:42 +00:00
|
|
|
|
|
|
|
if (clipPathFrame) {
|
|
|
|
isTrivial = clipPathFrame->IsTrivial();
|
|
|
|
gfx->Save();
|
|
|
|
if (isTrivial) {
|
|
|
|
clipPathFrame->ClipPaint(aContext, aParent, aMatrix);
|
|
|
|
} else {
|
|
|
|
gfx->PushGroup(gfxASurface::CONTENT_ALPHA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-27 17:30:57 +00:00
|
|
|
SVGFrame->PaintSVG(aContext, nsnull);
|
2010-02-26 09:58:42 +00:00
|
|
|
|
|
|
|
if (clipPathFrame) {
|
|
|
|
if (!isTrivial) {
|
|
|
|
gfx->PopGroupToSource();
|
|
|
|
|
|
|
|
nsRefPtr<gfxPattern> clipMaskSurface;
|
|
|
|
gfx->PushGroup(gfxASurface::CONTENT_ALPHA);
|
|
|
|
|
|
|
|
clipPathFrame->ClipPaint(aContext, aParent, aMatrix);
|
|
|
|
clipMaskSurface = gfx->PopGroup();
|
|
|
|
|
|
|
|
if (clipMaskSurface) {
|
|
|
|
gfx->Mask(clipMaskSurface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gfx->Restore();
|
|
|
|
}
|
2005-01-25 03:55:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-26 09:58:42 +00:00
|
|
|
if (clipPathFrame) {
|
|
|
|
if (!referencedClipIsTrivial) {
|
|
|
|
gfx->PopGroupToSource();
|
|
|
|
|
|
|
|
nsRefPtr<gfxPattern> clipMaskSurface;
|
|
|
|
gfx->PushGroup(gfxASurface::CONTENT_ALPHA);
|
|
|
|
|
|
|
|
clipPathFrame->ClipPaint(aContext, aParent, aMatrix);
|
|
|
|
clipMaskSurface = gfx->PopGroup();
|
|
|
|
|
|
|
|
if (clipMaskSurface) {
|
|
|
|
gfx->Mask(clipMaskSurface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gfx->Restore();
|
|
|
|
}
|
|
|
|
|
2006-11-27 17:30:57 +00:00
|
|
|
if (isTrivial) {
|
2010-02-26 09:58:42 +00:00
|
|
|
gfx->Clip();
|
|
|
|
gfx->NewPath();
|
2006-11-27 17:30:57 +00:00
|
|
|
}
|
2005-01-25 03:55:03 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2008-09-11 00:24:16 +00:00
|
|
|
nsSVGClipPathFrame::ClipHitTest(nsIFrame* aParent,
|
2009-07-23 08:35:59 +00:00
|
|
|
const gfxMatrix &aMatrix,
|
2008-08-25 09:23:54 +00:00
|
|
|
const nsPoint &aPoint)
|
2005-01-25 03:55:03 +00:00
|
|
|
{
|
2006-02-09 19:34:01 +00:00
|
|
|
// If the flag is set when we get here, it means this clipPath frame
|
|
|
|
// has already been used in hit testing against the current clip,
|
|
|
|
// and the document has a clip reference loop.
|
|
|
|
if (mInUse) {
|
|
|
|
NS_WARNING("Clip loop detected!");
|
2007-04-17 09:01:52 +00:00
|
|
|
return PR_FALSE;
|
2006-02-09 19:34:01 +00:00
|
|
|
}
|
2007-04-17 09:01:52 +00:00
|
|
|
AutoClipPathReferencer clipRef(this);
|
2006-02-09 19:34:01 +00:00
|
|
|
|
2010-02-26 09:58:42 +00:00
|
|
|
mClipParent = aParent;
|
2011-09-25 21:04:32 +00:00
|
|
|
if (mClipParentMatrix) {
|
|
|
|
*mClipParentMatrix = aMatrix;
|
|
|
|
} else {
|
|
|
|
mClipParentMatrix = new gfxMatrix(aMatrix);
|
|
|
|
}
|
2005-01-25 03:55:03 +00:00
|
|
|
|
2010-02-26 09:58:42 +00:00
|
|
|
nsSVGClipPathFrame *clipPathFrame =
|
2010-03-02 09:31:07 +00:00
|
|
|
nsSVGEffects::GetEffectProperties(this).GetClipPathFrame(nsnull);
|
2010-02-26 09:58:42 +00:00
|
|
|
if (clipPathFrame && !clipPathFrame->ClipHitTest(aParent, aMatrix, aPoint))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2005-01-25 03:55:03 +00:00
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
2009-01-12 19:20:59 +00:00
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
|
2005-01-25 03:55:03 +00:00
|
|
|
if (SVGFrame) {
|
2005-11-16 19:57:47 +00:00
|
|
|
// Notify the child frame that we may be working with a
|
|
|
|
// different transform, so it can update its covered region
|
|
|
|
// (used to shortcut hit testing).
|
2008-01-25 09:27:03 +00:00
|
|
|
SVGFrame->NotifySVGChanged(nsISVGChildFrame::TRANSFORM_CHANGED);
|
2005-11-16 19:57:47 +00:00
|
|
|
|
2008-08-25 09:23:54 +00:00
|
|
|
if (SVGFrame->GetFrameForPoint(aPoint))
|
2007-04-17 09:01:52 +00:00
|
|
|
return PR_TRUE;
|
2005-01-25 03:55:03 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-17 09:01:52 +00:00
|
|
|
return PR_FALSE;
|
2005-01-25 03:55:03 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2007-04-17 09:01:52 +00:00
|
|
|
nsSVGClipPathFrame::IsTrivial()
|
2006-01-20 17:00:43 +00:00
|
|
|
{
|
2010-02-26 09:58:42 +00:00
|
|
|
// If the clip path is clipped then it's non-trivial
|
2010-03-02 09:31:07 +00:00
|
|
|
if (nsSVGEffects::GetEffectProperties(this).GetClipPathFrame(nsnull))
|
2010-02-26 09:58:42 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool foundChild = false;
|
2006-01-20 17:00:43 +00:00
|
|
|
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
2009-01-12 19:20:59 +00:00
|
|
|
nsISVGChildFrame *svgChild = do_QueryFrame(kid);
|
2006-06-28 22:04:48 +00: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 09:01:52 +00:00
|
|
|
if (foundChild || svgChild->IsDisplayContainer())
|
|
|
|
return PR_FALSE;
|
2010-02-26 09:58:42 +00:00
|
|
|
|
|
|
|
// or where the child is itself clipped
|
2010-03-02 09:31:07 +00:00
|
|
|
if (nsSVGEffects::GetEffectProperties(kid).GetClipPathFrame(nsnull))
|
2010-02-26 09:58:42 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2006-06-28 22:04:48 +00:00
|
|
|
foundChild = PR_TRUE;
|
2006-01-20 17:00:43 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-17 09:01:52 +00:00
|
|
|
return PR_TRUE;
|
2006-01-20 17:00:43 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-03-02 09:31:07 +00:00
|
|
|
nsSVGClipPathFrame::IsValid()
|
|
|
|
{
|
|
|
|
if (mInUse) {
|
|
|
|
NS_WARNING("Clip loop detected!");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
AutoClipPathReferencer clipRef(this);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isOK = true;
|
2010-03-02 09:31:07 +00:00
|
|
|
nsSVGEffects::GetEffectProperties(this).GetClipPathFrame(&isOK);
|
|
|
|
if (!isOK) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
|
|
|
|
|
|
|
nsIAtom *type = kid->GetType();
|
|
|
|
|
|
|
|
if (type == nsGkAtoms::svgUseFrame) {
|
2011-08-24 20:54:30 +00:00
|
|
|
for (nsIFrame* grandKid = kid->GetFirstPrincipalChild(); grandKid;
|
2010-03-02 09:31:07 +00:00
|
|
|
grandKid = grandKid->GetNextSibling()) {
|
|
|
|
|
|
|
|
nsIAtom *type = grandKid->GetType();
|
|
|
|
|
|
|
|
if (type != nsGkAtoms::svgPathGeometryFrame &&
|
|
|
|
type != nsGkAtoms::svgTextFrame) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (type != nsGkAtoms::svgPathGeometryFrame &&
|
|
|
|
type != nsGkAtoms::svgTextFrame) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-24 16:54:48 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGClipPathFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
|
|
|
{
|
2011-09-19 12:59:52 +00:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::transform) {
|
|
|
|
nsSVGUtils::NotifyChildrenOfSVGChange(this,
|
|
|
|
nsISVGChildFrame::TRANSFORM_CHANGED);
|
|
|
|
}
|
|
|
|
if (aAttribute == nsGkAtoms::clipPathUnits) {
|
|
|
|
nsSVGEffects::InvalidateRenderingObservers(this);
|
|
|
|
}
|
2010-03-24 16:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsSVGClipPathFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
|
|
|
}
|
|
|
|
|
2009-01-19 18:31:34 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGClipPathFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2010-12-06 20:57:18 +00:00
|
|
|
#ifdef DEBUG
|
2009-01-19 18:31:34 +00:00
|
|
|
nsCOMPtr<nsIDOMSVGClipPathElement> clipPath = do_QueryInterface(aContent);
|
|
|
|
NS_ASSERTION(clipPath, "Content is not an SVG clipPath!");
|
2010-12-06 20:57:18 +00:00
|
|
|
#endif
|
2009-01-19 18:31:34 +00:00
|
|
|
|
2010-12-06 20:57:18 +00:00
|
|
|
AddStateBits(NS_STATE_SVG_CLIPPATH_CHILD);
|
2009-01-19 18:31:34 +00:00
|
|
|
return nsSVGClipPathFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
}
|
|
|
|
|
2005-04-01 19:56:08 +00:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGClipPathFrame::GetType() const
|
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
return nsGkAtoms::svgClipPathFrame;
|
2005-04-01 19:56:08 +00:00
|
|
|
}
|
|
|
|
|
2009-04-29 04:31:34 +00:00
|
|
|
gfxMatrix
|
2005-01-25 03:55:03 +00:00
|
|
|
nsSVGClipPathFrame::GetCanvasTM()
|
|
|
|
{
|
2009-04-29 04:31:34 +00:00
|
|
|
nsSVGClipPathElement *content = static_cast<nsSVGClipPathElement*>(mContent);
|
2007-04-27 08:42:51 +00:00
|
|
|
|
2011-09-25 21:04:32 +00:00
|
|
|
gfxMatrix tm =
|
|
|
|
content->PrependLocalTransformTo(mClipParentMatrix ?
|
|
|
|
*mClipParentMatrix : gfxMatrix());
|
2006-04-20 15:24:51 +00:00
|
|
|
|
2009-07-23 08:35:59 +00:00
|
|
|
return nsSVGUtils::AdjustMatrixForUnits(tm,
|
2009-04-29 04:31:34 +00:00
|
|
|
&content->mEnumAttributes[nsSVGClipPathElement::CLIPPATHUNITS],
|
2007-12-04 04:40:52 +00:00
|
|
|
mClipParent);
|
2005-01-25 03:55:03 +00:00
|
|
|
}
|