2007-03-22 10:30:00 -07: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"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsSVGUtils.h"
|
2007-04-27 01:42:51 -07:00
|
|
|
#include "nsSVGClipPathElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "nsIDOMSVGRect.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewSVGClipPathFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext)
|
|
|
|
{
|
2007-09-07 02:30:51 -07:00
|
|
|
nsCOMPtr<nsIDOMSVGClipPathElement> clipPath = do_QueryInterface(aContent);
|
|
|
|
if (!clipPath) {
|
|
|
|
NS_ERROR("Can't create frame! Content is not an SVG clipPath!");
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new (aPresShell) nsSVGClipPathFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2007-04-17 02:01:52 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGClipPathFrame::ClipPaint(nsSVGRenderState* aContext,
|
|
|
|
nsISVGChildFrame* aParent,
|
2007-04-17 02:01:52 -07:00
|
|
|
nsIDOMSVGMatrix *aMatrix)
|
2007-03-22 10:30:00 -07: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 02:01:52 -07:00
|
|
|
AutoClipPathReferencer clipRef(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mClipParent = aParent,
|
|
|
|
mClipParentMatrix = aMatrix;
|
|
|
|
|
2007-04-17 02:01:52 -07:00
|
|
|
PRBool isTrivial = IsTrivial();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoSVGRenderMode mode(aContext,
|
|
|
|
isTrivial ? nsSVGRenderState::CLIP
|
|
|
|
: nsSVGRenderState::CLIP_MASK);
|
|
|
|
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
|
|
|
nsISVGChildFrame* SVGFrame = nsnull;
|
|
|
|
CallQueryInterface(kid, &SVGFrame);
|
|
|
|
if (SVGFrame) {
|
2008-01-25 01:27:03 -08:00
|
|
|
// The CTM of each frame referencing us can be different.
|
|
|
|
SVGFrame->NotifySVGChanged(nsISVGChildFrame::SUPPRESS_INVALIDATION |
|
|
|
|
nsISVGChildFrame::TRANSFORM_CHANGED);
|
2007-03-22 10:30:00 -07:00
|
|
|
SVGFrame->PaintSVG(aContext, nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isTrivial) {
|
|
|
|
aContext->GetGfxContext()->Clip();
|
|
|
|
aContext->GetGfxContext()->NewPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-17 02:01:52 -07:00
|
|
|
PRBool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGClipPathFrame::ClipHitTest(nsISVGChildFrame* aParent,
|
2007-04-17 02:01:52 -07:00
|
|
|
nsIDOMSVGMatrix *aMatrix,
|
2008-08-25 02:23:54 -07:00
|
|
|
const nsPoint &aPoint)
|
2007-03-22 10:30:00 -07: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 02:01:52 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-04-17 02:01:52 -07:00
|
|
|
AutoClipPathReferencer clipRef(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mClipParent = aParent,
|
|
|
|
mClipParentMatrix = aMatrix;
|
|
|
|
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
|
|
|
nsISVGChildFrame* SVGFrame = nsnull;
|
|
|
|
CallQueryInterface(kid, &SVGFrame);
|
|
|
|
if (SVGFrame) {
|
|
|
|
// 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 01:27:03 -08:00
|
|
|
SVGFrame->NotifySVGChanged(nsISVGChildFrame::TRANSFORM_CHANGED);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
if (SVGFrame->GetFrameForPoint(aPoint))
|
2007-04-17 02:01:52 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-04-17 02:01:52 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-17 02:01:52 -07:00
|
|
|
PRBool
|
|
|
|
nsSVGClipPathFrame::IsTrivial()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PRBool foundChild = PR_FALSE;
|
|
|
|
|
|
|
|
for (nsIFrame* kid = mFrames.FirstChild(); kid;
|
|
|
|
kid = kid->GetNextSibling()) {
|
|
|
|
nsISVGChildFrame *svgChild = nsnull;
|
|
|
|
CallQueryInterface(kid, &svgChild);
|
|
|
|
|
|
|
|
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 02:01:52 -07:00
|
|
|
if (foundChild || svgChild->IsDisplayContainer())
|
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
foundChild = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2007-04-17 02:01:52 -07:00
|
|
|
return PR_TRUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGClipPathFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgClipPathFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIDOMSVGMatrix>
|
|
|
|
nsSVGClipPathFrame::GetCanvasTM()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mClipParentMatrix, "null parent matrix");
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsSVGClipPathElement *clipPath = static_cast<nsSVGClipPathElement*>
|
|
|
|
(mContent);
|
2007-04-27 01:42:51 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMSVGMatrix> localTM = clipPath->GetLocalTransformMatrix();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMSVGMatrix> canvasTM;
|
|
|
|
|
|
|
|
if (localTM)
|
|
|
|
mClipParentMatrix->Multiply(localTM, getter_AddRefs(canvasTM));
|
|
|
|
else
|
|
|
|
canvasTM = mClipParentMatrix;
|
|
|
|
|
2007-12-03 20:40:52 -08:00
|
|
|
return nsSVGUtils::AdjustMatrixForUnits(canvasTM,
|
|
|
|
&clipPath->mEnumAttributes[nsSVGClipPathElement::CLIPPATHUNITS],
|
|
|
|
mClipParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|