2007-03-22 10:30:00 -07:00
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
|
// Main header first:
|
2011-08-11 06:29:50 -07:00
|
|
|
|
#include "nsSVGPatternFrame.h"
|
|
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
|
// Keep others in (case-insensitive) order:
|
|
|
|
|
#include "gfxContext.h"
|
|
|
|
|
#include "gfxMatrix.h"
|
|
|
|
|
#include "gfxPattern.h"
|
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#include "nsGkAtoms.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
|
#include "nsISVGChildFrame.h"
|
2012-03-20 05:15:55 -07:00
|
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#include "nsStyleContext.h"
|
2008-09-30 17:51:05 -07:00
|
|
|
|
#include "nsSVGEffects.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
#include "nsSVGGeometryFrame.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
|
#include "nsSVGPatternElement.h"
|
|
|
|
|
#include "nsSVGUtils.h"
|
|
|
|
|
#include "SVGAnimatedTransformList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2011-01-15 23:36:34 -08:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
// Helper classes
|
|
|
|
|
|
|
|
|
|
class nsSVGPatternFrame::AutoPatternReferencer
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
AutoPatternReferencer(nsSVGPatternFrame *aFrame)
|
|
|
|
|
: mFrame(aFrame)
|
|
|
|
|
{
|
|
|
|
|
// Reference loops should normally be detected in advance and handled, so
|
|
|
|
|
// we're not expecting to encounter them here
|
|
|
|
|
NS_ABORT_IF_FALSE(!mFrame->mLoopFlag, "Undetected reference loop!");
|
2011-10-17 07:59:28 -07:00
|
|
|
|
mFrame->mLoopFlag = true;
|
2011-01-15 23:36:34 -08:00
|
|
|
|
}
|
|
|
|
|
~AutoPatternReferencer() {
|
2011-10-17 07:59:28 -07:00
|
|
|
|
mFrame->mLoopFlag = false;
|
2011-01-15 23:36:34 -08:00
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
nsSVGPatternFrame *mFrame;
|
|
|
|
|
};
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
// Implementation
|
|
|
|
|
|
2008-10-11 04:29:35 -07:00
|
|
|
|
nsSVGPatternFrame::nsSVGPatternFrame(nsStyleContext* aContext) :
|
2007-03-22 10:30:00 -07:00
|
|
|
|
nsSVGPatternFrameBase(aContext),
|
2011-10-17 07:59:28 -07:00
|
|
|
|
mLoopFlag(false),
|
|
|
|
|
mNoHRefURI(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGPatternFrame)
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
// nsIFrame methods:
|
|
|
|
|
|
2008-10-13 15:03:28 -07:00
|
|
|
|
/* virtual */ void
|
2008-10-26 03:11:34 -07:00
|
|
|
|
nsSVGPatternFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2012-06-23 07:19:00 -07:00
|
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2008-10-26 03:11:34 -07:00
|
|
|
|
nsSVGPatternFrameBase::DidSetStyleContext(aOldStyleContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
|
nsSVGPatternFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
|
PRInt32 aModType)
|
|
|
|
|
{
|
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
|
(aAttribute == nsGkAtoms::patternUnits ||
|
|
|
|
|
aAttribute == nsGkAtoms::patternContentUnits ||
|
|
|
|
|
aAttribute == nsGkAtoms::patternTransform ||
|
|
|
|
|
aAttribute == nsGkAtoms::x ||
|
|
|
|
|
aAttribute == nsGkAtoms::y ||
|
|
|
|
|
aAttribute == nsGkAtoms::width ||
|
|
|
|
|
aAttribute == nsGkAtoms::height ||
|
|
|
|
|
aAttribute == nsGkAtoms::preserveAspectRatio ||
|
|
|
|
|
aAttribute == nsGkAtoms::viewBox)) {
|
2012-06-23 07:19:00 -07:00
|
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2008-09-30 17:51:05 -07:00
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
if (aNameSpaceID == kNameSpaceID_XLink &&
|
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
2008-09-30 17:51:05 -07:00
|
|
|
|
// Blow away our reference, if any
|
2010-03-28 18:46:55 -07:00
|
|
|
|
Properties().Delete(nsSVGEffects::HrefProperty());
|
2011-10-17 07:59:28 -07:00
|
|
|
|
mNoHRefURI = false;
|
2008-09-30 17:51:05 -07:00
|
|
|
|
// And update whoever references us
|
2012-06-23 07:19:00 -07:00
|
|
|
|
nsSVGEffects::InvalidateDirectRenderingObservers(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nsSVGPatternFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
|
aAttribute, aModType);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-19 10:31:34 -08:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
|
nsSVGPatternFrame::Init(nsIContent* aContent,
|
|
|
|
|
nsIFrame* aParent,
|
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
|
{
|
|
|
|
|
nsCOMPtr<nsIDOMSVGPatternElement> patternElement = do_QueryInterface(aContent);
|
|
|
|
|
NS_ASSERTION(patternElement, "Content is not an SVG pattern");
|
|
|
|
|
|
|
|
|
|
return nsSVGPatternFrameBase::Init(aContent, aParent, aPrevInFlow);
|
|
|
|
|
}
|
|
|
|
|
#endif /* DEBUG */
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
nsIAtom*
|
|
|
|
|
nsSVGPatternFrame::GetType() const
|
|
|
|
|
{
|
|
|
|
|
return nsGkAtoms::svgPatternFrame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
// nsSVGContainerFrame methods:
|
|
|
|
|
|
|
|
|
|
// If our GetCanvasTM is getting called, we
|
|
|
|
|
// need to return *our current* transformation
|
|
|
|
|
// matrix, which depends on our units parameters
|
|
|
|
|
// and X, Y, Width, and Height
|
2009-04-28 21:31:34 -07:00
|
|
|
|
gfxMatrix
|
2012-06-30 04:20:46 -07:00
|
|
|
|
nsSVGPatternFrame::GetCanvasTM(PRUint32 aFor)
|
2007-07-17 02:24:27 -07:00
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
|
if (mCTM) {
|
2011-09-25 14:04:32 -07:00
|
|
|
|
return *mCTM;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
2009-04-28 21:31:34 -07:00
|
|
|
|
|
|
|
|
|
// Do we know our rendering parent?
|
|
|
|
|
if (mSource) {
|
|
|
|
|
// Yes, use it!
|
2012-06-30 04:20:46 -07:00
|
|
|
|
return mSource->GetCanvasTM(aFor);
|
2009-04-28 21:31:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We get here when geometry in the <pattern> container is updated
|
|
|
|
|
return gfxMatrix();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-31 03:17:11 -07:00
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
// Helper functions
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// The SVG specification says that the 'patternContentUnits' attribute "has no effect if
|
|
|
|
|
// attribute <20>viewBox<6F> is specified". We still need to include a bbox scale
|
|
|
|
|
// if the viewBox is specified and _patternUnits_ is set to or defaults to
|
|
|
|
|
// objectBoundingBox though, since in that case the viewBox is relative to the bbox
|
|
|
|
|
static bool
|
|
|
|
|
IncludeBBoxScale(const nsSVGViewBox& aViewBox,
|
|
|
|
|
PRUint32 aPatternContentUnits, PRUint32 aPatternUnits)
|
|
|
|
|
{
|
|
|
|
|
return (!aViewBox.IsExplicitlySet() &&
|
|
|
|
|
aPatternContentUnits == nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) ||
|
|
|
|
|
(aViewBox.IsExplicitlySet() &&
|
|
|
|
|
aPatternUnits == nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Given the matrix for the pattern element's own transform, this returns a
|
|
|
|
|
// combined matrix including the transforms applicable to its target.
|
|
|
|
|
static gfxMatrix
|
|
|
|
|
GetPatternMatrix(PRUint16 aPatternUnits,
|
|
|
|
|
const gfxMatrix &patternTransform,
|
|
|
|
|
const gfxRect &bbox,
|
|
|
|
|
const gfxRect &callerBBox,
|
|
|
|
|
const gfxMatrix &callerCTM)
|
|
|
|
|
{
|
|
|
|
|
// We really want the pattern matrix to handle translations
|
|
|
|
|
gfxFloat minx = bbox.X();
|
|
|
|
|
gfxFloat miny = bbox.Y();
|
|
|
|
|
|
|
|
|
|
if (aPatternUnits == nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
|
|
|
|
|
minx += callerBBox.X();
|
|
|
|
|
miny += callerBBox.Y();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float scale = 1.0f / nsSVGUtils::MaxExpansion(callerCTM);
|
|
|
|
|
gfxMatrix patternMatrix = patternTransform;
|
|
|
|
|
patternMatrix.Scale(scale, scale);
|
|
|
|
|
patternMatrix.Translate(gfxPoint(minx, miny));
|
|
|
|
|
|
|
|
|
|
return patternMatrix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
|
GetTargetGeometry(gfxRect *aBBox,
|
|
|
|
|
const nsSVGViewBox &aViewBox,
|
|
|
|
|
PRUint16 aPatternContentUnits,
|
|
|
|
|
PRUint16 aPatternUnits,
|
|
|
|
|
nsIFrame *aTarget,
|
|
|
|
|
const gfxMatrix &aContextMatrix,
|
|
|
|
|
const gfxRect *aOverrideBounds)
|
|
|
|
|
{
|
|
|
|
|
*aBBox = aOverrideBounds ? *aOverrideBounds : nsSVGUtils::GetBBox(aTarget);
|
|
|
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
|
if (IncludeBBoxScale(aViewBox, aPatternContentUnits, aPatternUnits) &&
|
|
|
|
|
(aBBox->Width() <= 0 || aBBox->Height() <= 0)) {
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OK, now fix up the bounding box to reflect user coordinates
|
|
|
|
|
// We handle device unit scaling in pattern matrix
|
|
|
|
|
float scale = nsSVGUtils::MaxExpansion(aContextMatrix);
|
|
|
|
|
if (scale <= 0) {
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
aBBox->Scale(scale);
|
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
nsresult
|
2007-04-30 08:53:55 -07:00
|
|
|
|
nsSVGPatternFrame::PaintPattern(gfxASurface** surface,
|
|
|
|
|
gfxMatrix* patternMatrix,
|
2012-07-13 16:18:38 -07:00
|
|
|
|
const gfxMatrix &aContextMatrix,
|
2010-07-01 09:40:30 -07:00
|
|
|
|
nsIFrame *aSource,
|
2012-05-18 01:34:25 -07:00
|
|
|
|
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
|
2010-07-01 09:40:30 -07:00
|
|
|
|
float aGraphicOpacity,
|
|
|
|
|
const gfxRect *aOverrideBounds)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* General approach:
|
|
|
|
|
* Set the content geometry stuff
|
2008-09-30 17:51:05 -07:00
|
|
|
|
* Calculate our bbox (using x,y,width,height & patternUnits &
|
2007-03-22 10:30:00 -07:00
|
|
|
|
* patternTransform)
|
|
|
|
|
* Create the surface
|
|
|
|
|
* Calculate the content transformation matrix
|
|
|
|
|
* Get our children (we may need to get them from another Pattern)
|
|
|
|
|
* Call SVGPaint on all of our children
|
|
|
|
|
* Return
|
|
|
|
|
*/
|
2012-07-30 07:20:58 -07:00
|
|
|
|
*surface = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2009-10-26 12:37:31 -07:00
|
|
|
|
// Get the first child of the pattern data we will render
|
2011-10-27 15:57:10 -07:00
|
|
|
|
nsIFrame* firstKid = GetPatternFirstChild();
|
|
|
|
|
if (!firstKid)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return NS_ERROR_FAILURE; // Either no kids or a bad reference
|
|
|
|
|
|
2012-07-31 03:17:11 -07:00
|
|
|
|
const nsSVGViewBox& viewBox = GetViewBox();
|
|
|
|
|
|
|
|
|
|
PRUint16 patternContentUnits =
|
|
|
|
|
GetEnumValue(nsSVGPatternElement::PATTERNCONTENTUNITS);
|
|
|
|
|
PRUint16 patternUnits =
|
|
|
|
|
GetEnumValue(nsSVGPatternElement::PATTERNUNITS);
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
/*
|
|
|
|
|
* Get the content geometry information. This is a little tricky --
|
|
|
|
|
* our parent is probably a <defs>, but we are rendering in the context
|
|
|
|
|
* of some geometry source. Our content geometry information needs to
|
|
|
|
|
* come from our rendering parent as opposed to our content parent. We
|
|
|
|
|
* get that information from aSource, which is passed to us from the
|
|
|
|
|
* backend renderer.
|
|
|
|
|
*
|
|
|
|
|
* There are three "geometries" that we need:
|
|
|
|
|
* 1) The bounding box for the pattern. We use this to get the
|
|
|
|
|
* width and height for the surface, and as the return to
|
|
|
|
|
* GetBBox.
|
|
|
|
|
* 2) The transformation matrix for the pattern. This is not *quite*
|
|
|
|
|
* the same as the canvas transformation matrix that we will
|
|
|
|
|
* provide to our rendering children since we "fudge" it a little
|
|
|
|
|
* to get the renderer to handle the translations correctly for us.
|
|
|
|
|
* 3) The CTM that we return to our children who make up the pattern.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Get all of the information we need from our "caller" -- i.e.
|
|
|
|
|
// the geometry that is being rendered with a pattern
|
2009-06-11 08:21:03 -07:00
|
|
|
|
gfxRect callerBBox;
|
2012-07-13 16:18:38 -07:00
|
|
|
|
if (NS_FAILED(GetTargetGeometry(&callerBBox,
|
2012-07-31 03:17:11 -07:00
|
|
|
|
viewBox,
|
|
|
|
|
patternContentUnits, patternUnits,
|
2010-07-01 09:40:30 -07:00
|
|
|
|
aSource,
|
2012-07-13 16:18:38 -07:00
|
|
|
|
aContextMatrix,
|
2010-07-01 09:40:30 -07:00
|
|
|
|
aOverrideBounds)))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
|
|
// Construct the CTM that we will provide to our children when we
|
|
|
|
|
// render them into the tile.
|
2012-07-31 03:17:11 -07:00
|
|
|
|
gfxMatrix ctm = ConstructCTM(viewBox, patternContentUnits, patternUnits,
|
|
|
|
|
callerBBox, aContextMatrix, aSource);
|
2009-07-23 01:35:59 -07:00
|
|
|
|
if (ctm.IsSingular()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-07-23 01:35:59 -07:00
|
|
|
|
}
|
2009-10-26 12:37:31 -07:00
|
|
|
|
|
|
|
|
|
// Get the pattern we are going to render
|
|
|
|
|
nsSVGPatternFrame *patternFrame =
|
|
|
|
|
static_cast<nsSVGPatternFrame*>(firstKid->GetParent());
|
2011-09-25 14:04:32 -07:00
|
|
|
|
if (patternFrame->mCTM) {
|
|
|
|
|
*patternFrame->mCTM = ctm;
|
|
|
|
|
} else {
|
|
|
|
|
patternFrame->mCTM = new gfxMatrix(ctm);
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
// Get the bounding box of the pattern. This will be used to determine
|
|
|
|
|
// the size of the surface, and will also be used to define the bounding
|
|
|
|
|
// box for the pattern tile.
|
2012-07-31 03:17:11 -07:00
|
|
|
|
gfxRect bbox = GetPatternRect(patternUnits, callerBBox, aContextMatrix, aSource);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2011-10-27 01:51:46 -07:00
|
|
|
|
// Get the pattern transform
|
|
|
|
|
gfxMatrix patternTransform = GetPatternTransform();
|
|
|
|
|
|
2012-05-18 01:34:25 -07:00
|
|
|
|
// revert the vector effect transform so that the pattern appears unchanged
|
|
|
|
|
if (aFillOrStroke == &nsStyleSVG::mStroke) {
|
|
|
|
|
patternTransform.Multiply(nsSVGUtils::GetStrokeTransform(aSource).Invert());
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
// Get the transformation matrix that we will hand to the renderer's pattern
|
|
|
|
|
// routine.
|
2012-07-31 03:17:11 -07:00
|
|
|
|
*patternMatrix = GetPatternMatrix(patternUnits, patternTransform,
|
2012-07-13 16:18:38 -07:00
|
|
|
|
bbox, callerBBox, aContextMatrix);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
// Now that we have all of the necessary geometries, we can
|
|
|
|
|
// create our surface.
|
2011-10-27 01:51:46 -07:00
|
|
|
|
gfxFloat patternWidth = bbox.Width();
|
|
|
|
|
gfxFloat patternHeight = bbox.Height();
|
2007-06-13 02:02:48 -07:00
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
|
bool resultOverflows;
|
2007-06-13 02:02:48 -07:00
|
|
|
|
gfxIntSize surfaceSize =
|
2011-10-04 08:22:46 -07:00
|
|
|
|
nsSVGUtils::ConvertToSurfaceSize(
|
2011-10-27 01:51:46 -07:00
|
|
|
|
gfxSize(patternWidth * fabs(patternTransform.xx),
|
|
|
|
|
patternHeight * fabs(patternTransform.yy)),
|
2011-10-04 08:22:46 -07:00
|
|
|
|
&resultOverflows);
|
2007-06-13 02:02:48 -07:00
|
|
|
|
|
|
|
|
|
// 0 disables rendering, < 0 is an error
|
|
|
|
|
if (surfaceSize.width <= 0 || surfaceSize.height <= 0)
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
2009-12-23 03:30:44 -08:00
|
|
|
|
if (resultOverflows ||
|
|
|
|
|
patternWidth != surfaceSize.width ||
|
|
|
|
|
patternHeight != surfaceSize.height) {
|
|
|
|
|
// scale drawing to pattern surface size
|
2011-09-25 14:04:32 -07:00
|
|
|
|
gfxMatrix tempTM =
|
|
|
|
|
gfxMatrix(surfaceSize.width / patternWidth, 0.0f,
|
|
|
|
|
0.0f, surfaceSize.height / patternHeight,
|
|
|
|
|
0.0f, 0.0f);
|
|
|
|
|
patternFrame->mCTM->PreMultiply(tempTM);
|
2007-06-13 02:02:48 -07:00
|
|
|
|
|
2009-12-23 03:30:44 -08:00
|
|
|
|
// and rescale pattern to compensate
|
2007-06-13 02:02:48 -07:00
|
|
|
|
patternMatrix->Scale(patternWidth / surfaceSize.width,
|
|
|
|
|
patternHeight / surfaceSize.height);
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2007-04-30 08:53:55 -07:00
|
|
|
|
nsRefPtr<gfxASurface> tmpSurface =
|
2007-06-13 02:02:48 -07:00
|
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenSurface(surfaceSize,
|
2010-09-16 14:34:53 -07:00
|
|
|
|
gfxASurface::CONTENT_COLOR_ALPHA);
|
2007-07-17 02:24:27 -07:00
|
|
|
|
if (!tmpSurface || tmpSurface->CairoStatus())
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
2012-03-02 00:28:59 -08:00
|
|
|
|
nsRenderingContext context;
|
|
|
|
|
context.Init(aSource->PresContext()->DeviceContext(), tmpSurface);
|
|
|
|
|
gfxContext* gfx = context.ThebesContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2007-04-30 08:53:55 -07:00
|
|
|
|
// Fill with transparent black
|
2012-03-02 00:28:59 -08:00
|
|
|
|
gfx->SetOperator(gfxContext::OPERATOR_CLEAR);
|
|
|
|
|
gfx->Paint();
|
|
|
|
|
gfx->SetOperator(gfxContext::OPERATOR_OVER);
|
2007-04-30 08:53:55 -07:00
|
|
|
|
|
2007-04-24 01:11:22 -07:00
|
|
|
|
if (aGraphicOpacity != 1.0f) {
|
2012-03-02 00:28:59 -08:00
|
|
|
|
gfx->Save();
|
|
|
|
|
gfx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
2007-04-24 01:11:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
// OK, now render -- note that we use "firstKid", which
|
|
|
|
|
// we got at the beginning because it takes care of the
|
|
|
|
|
// referenced pattern situation for us
|
|
|
|
|
|
2010-07-01 09:40:30 -07:00
|
|
|
|
if (aSource->IsFrameOfType(nsIFrame::eSVGGeometry)) {
|
|
|
|
|
// Set the geometrical parent of the pattern we are rendering
|
|
|
|
|
patternFrame->mSource = static_cast<nsSVGGeometryFrame*>(aSource);
|
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2010-08-13 06:32:15 -07:00
|
|
|
|
// Delay checking NS_FRAME_DRAWING_AS_PAINTSERVER bit until here so we can
|
|
|
|
|
// give back a clear surface if there's a loop
|
|
|
|
|
if (!(patternFrame->GetStateBits() & NS_FRAME_DRAWING_AS_PAINTSERVER)) {
|
|
|
|
|
patternFrame->AddStateBits(NS_FRAME_DRAWING_AS_PAINTSERVER);
|
2008-09-30 17:51:05 -07:00
|
|
|
|
for (nsIFrame* kid = firstKid; kid;
|
|
|
|
|
kid = kid->GetNextSibling()) {
|
2010-12-22 21:48:31 -08:00
|
|
|
|
// The CTM of each frame referencing us can be different
|
|
|
|
|
nsISVGChildFrame* SVGFrame = do_QueryFrame(kid);
|
|
|
|
|
if (SVGFrame) {
|
2012-07-23 04:00:43 -07:00
|
|
|
|
SVGFrame->NotifySVGChanged(nsISVGChildFrame::TRANSFORM_CHANGED);
|
2010-12-22 21:48:31 -08:00
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
|
nsSVGUtils::PaintFrameWithEffects(&context, nullptr, kid);
|
2008-09-30 17:51:05 -07:00
|
|
|
|
}
|
2010-08-13 06:32:15 -07:00
|
|
|
|
patternFrame->RemoveStateBits(NS_FRAME_DRAWING_AS_PAINTSERVER);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
|
patternFrame->mSource = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2007-04-24 01:11:22 -07:00
|
|
|
|
if (aGraphicOpacity != 1.0f) {
|
2012-03-02 00:28:59 -08:00
|
|
|
|
gfx->PopGroupToSource();
|
|
|
|
|
gfx->Paint(aGraphicOpacity);
|
|
|
|
|
gfx->Restore();
|
2007-04-24 01:11:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-30 08:53:55 -07:00
|
|
|
|
// caller now owns the surface
|
2011-08-11 06:29:50 -07:00
|
|
|
|
tmpSurface.forget(surface);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
return NS_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Will probably need something like this... */
|
|
|
|
|
// How do we handle the insertion of a new frame?
|
|
|
|
|
// We really don't want to rerender this every time,
|
|
|
|
|
// do we?
|
2011-10-27 15:57:10 -07:00
|
|
|
|
nsIFrame*
|
|
|
|
|
nsSVGPatternFrame::GetPatternFirstChild()
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-09-30 04:28:20 -07:00
|
|
|
|
// Do we have any children ourselves?
|
2011-10-27 15:57:10 -07:00
|
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
|
|
|
|
if (kid)
|
|
|
|
|
return kid;
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
|
|
|
|
// No, see if we chain to someone who does
|
2011-01-15 23:36:34 -08:00
|
|
|
|
AutoPatternReferencer patternRef(this);
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
2011-10-27 15:57:10 -07:00
|
|
|
|
nsSVGPatternFrame* next = GetReferencedPatternIfNotInUse();
|
2011-01-15 23:36:34 -08:00
|
|
|
|
if (!next)
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr;
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
2011-10-27 15:57:10 -07:00
|
|
|
|
return next->GetPatternFirstChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PRUint16
|
2011-01-15 23:36:34 -08:00
|
|
|
|
nsSVGPatternFrame::GetEnumValue(PRUint32 aIndex, nsIContent *aDefault)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2011-01-15 23:36:34 -08:00
|
|
|
|
nsSVGEnum& thisEnum =
|
|
|
|
|
static_cast<nsSVGPatternElement *>(mContent)->mEnumAttributes[aIndex];
|
|
|
|
|
|
|
|
|
|
if (thisEnum.IsExplicitlySet())
|
|
|
|
|
return thisEnum.GetAnimValue();
|
|
|
|
|
|
|
|
|
|
AutoPatternReferencer patternRef(this);
|
|
|
|
|
|
|
|
|
|
nsSVGPatternFrame *next = GetReferencedPatternIfNotInUse();
|
|
|
|
|
return next ? next->GetEnumValue(aIndex, aDefault) :
|
|
|
|
|
static_cast<nsSVGPatternElement *>(aDefault)->
|
|
|
|
|
mEnumAttributes[aIndex].GetAnimValue();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-25 14:04:32 -07:00
|
|
|
|
SVGAnimatedTransformList*
|
2011-01-15 23:36:34 -08:00
|
|
|
|
nsSVGPatternFrame::GetPatternTransformList(nsIContent* aDefault)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2011-09-25 14:04:32 -07:00
|
|
|
|
SVGAnimatedTransformList *thisTransformList =
|
|
|
|
|
static_cast<nsSVGPatternElement *>(mContent)->GetAnimatedTransformList();
|
|
|
|
|
|
2012-07-29 17:35:26 -07:00
|
|
|
|
if (thisTransformList && thisTransformList->IsExplicitlySet())
|
2011-01-15 23:36:34 -08:00
|
|
|
|
return thisTransformList;
|
|
|
|
|
|
|
|
|
|
AutoPatternReferencer patternRef(this);
|
|
|
|
|
|
|
|
|
|
nsSVGPatternFrame *next = GetReferencedPatternIfNotInUse();
|
|
|
|
|
return next ? next->GetPatternTransformList(aDefault) :
|
|
|
|
|
static_cast<nsSVGPatternElement *>(aDefault)->mPatternTransform.get();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-30 08:53:55 -07:00
|
|
|
|
gfxMatrix
|
|
|
|
|
nsSVGPatternFrame::GetPatternTransform()
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2011-09-25 14:04:32 -07:00
|
|
|
|
SVGAnimatedTransformList* animTransformList =
|
2011-01-15 23:36:34 -08:00
|
|
|
|
GetPatternTransformList(mContent);
|
2011-09-25 14:04:32 -07:00
|
|
|
|
if (!animTransformList)
|
|
|
|
|
return gfxMatrix();
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
2011-09-25 14:04:32 -07:00
|
|
|
|
return animTransformList->GetAnimValue().GetConsolidationMatrix();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-03 06:42:24 -08:00
|
|
|
|
const nsSVGViewBox &
|
2011-01-15 23:36:34 -08:00
|
|
|
|
nsSVGPatternFrame::GetViewBox(nsIContent* aDefault)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2011-01-15 23:36:34 -08:00
|
|
|
|
const nsSVGViewBox &thisViewBox =
|
|
|
|
|
static_cast<nsSVGPatternElement *>(mContent)->mViewBox;
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
2012-05-03 09:05:40 -07:00
|
|
|
|
if (thisViewBox.IsExplicitlySet())
|
2011-01-15 23:36:34 -08:00
|
|
|
|
return thisViewBox;
|
|
|
|
|
|
|
|
|
|
AutoPatternReferencer patternRef(this);
|
|
|
|
|
|
|
|
|
|
nsSVGPatternFrame *next = GetReferencedPatternIfNotInUse();
|
|
|
|
|
return next ? next->GetViewBox(aDefault) :
|
|
|
|
|
static_cast<nsSVGPatternElement *>(aDefault)->mViewBox;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
|
const SVGAnimatedPreserveAspectRatio &
|
2011-01-15 23:36:34 -08:00
|
|
|
|
nsSVGPatternFrame::GetPreserveAspectRatio(nsIContent *aDefault)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2011-01-15 23:36:34 -08:00
|
|
|
|
const SVGAnimatedPreserveAspectRatio &thisPar =
|
|
|
|
|
static_cast<nsSVGPatternElement *>(mContent)->mPreserveAspectRatio;
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
2011-01-15 23:36:34 -08:00
|
|
|
|
if (thisPar.IsExplicitlySet())
|
|
|
|
|
return thisPar;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2011-01-15 23:36:34 -08:00
|
|
|
|
AutoPatternReferencer patternRef(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2011-01-15 23:36:34 -08:00
|
|
|
|
nsSVGPatternFrame *next = GetReferencedPatternIfNotInUse();
|
|
|
|
|
return next ? next->GetPreserveAspectRatio(aDefault) :
|
|
|
|
|
static_cast<nsSVGPatternElement *>(aDefault)->mPreserveAspectRatio;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-03 06:42:24 -08:00
|
|
|
|
const nsSVGLength2 *
|
2011-01-15 23:36:34 -08:00
|
|
|
|
nsSVGPatternFrame::GetLengthValue(PRUint32 aIndex, nsIContent *aDefault)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2011-01-15 23:36:34 -08:00
|
|
|
|
const nsSVGLength2 *thisLength =
|
|
|
|
|
&static_cast<nsSVGPatternElement *>(mContent)->mLengthAttributes[aIndex];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2011-01-15 23:36:34 -08:00
|
|
|
|
if (thisLength->IsExplicitlySet())
|
|
|
|
|
return thisLength;
|
|
|
|
|
|
|
|
|
|
AutoPatternReferencer patternRef(this);
|
|
|
|
|
|
|
|
|
|
nsSVGPatternFrame *next = GetReferencedPatternIfNotInUse();
|
|
|
|
|
return next ? next->GetLengthValue(aIndex, aDefault) :
|
|
|
|
|
&static_cast<nsSVGPatternElement *>(aDefault)->mLengthAttributes[aIndex];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Private (helper) methods
|
2008-09-30 17:51:05 -07:00
|
|
|
|
nsSVGPatternFrame *
|
|
|
|
|
nsSVGPatternFrame::GetReferencedPattern()
|
|
|
|
|
{
|
|
|
|
|
if (mNoHRefURI)
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr;
|
2008-09-30 04:28:20 -07:00
|
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
|
nsSVGPaintingProperty *property = static_cast<nsSVGPaintingProperty*>
|
|
|
|
|
(Properties().Get(nsSVGEffects::HrefProperty()));
|
2008-09-30 01:47:20 -07:00
|
|
|
|
|
2008-09-30 17:51:05 -07:00
|
|
|
|
if (!property) {
|
|
|
|
|
// Fetch our pattern element's xlink:href attribute
|
2008-10-11 04:29:35 -07:00
|
|
|
|
nsSVGPatternElement *pattern = static_cast<nsSVGPatternElement *>(mContent);
|
2009-01-21 16:56:51 -08:00
|
|
|
|
nsAutoString href;
|
|
|
|
|
pattern->mStringAttributes[nsSVGPatternElement::HREF].GetAnimValue(href, pattern);
|
2008-09-30 17:51:05 -07:00
|
|
|
|
if (href.IsEmpty()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
|
mNoHRefURI = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr; // no URL
|
2008-09-30 04:28:20 -07:00
|
|
|
|
}
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
|
|
|
|
// Convert href to an nsIURI
|
|
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
|
nsCOMPtr<nsIURI> base = mContent->GetBaseURI();
|
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), href,
|
|
|
|
|
mContent->GetCurrentDoc(), base);
|
|
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
|
property =
|
|
|
|
|
nsSVGEffects::GetPaintingProperty(targetURI, this, nsSVGEffects::HrefProperty());
|
2008-09-30 17:51:05 -07:00
|
|
|
|
if (!property)
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr;
|
2008-09-30 04:28:20 -07:00
|
|
|
|
}
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
|
|
|
|
nsIFrame *result = property->GetReferencedFrame();
|
|
|
|
|
if (!result)
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr;
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
|
|
|
|
nsIAtom* frameType = result->GetType();
|
|
|
|
|
if (frameType != nsGkAtoms::svgPatternFrame)
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr;
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
|
|
|
|
return static_cast<nsSVGPatternFrame*>(result);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-15 23:36:34 -08:00
|
|
|
|
nsSVGPatternFrame *
|
|
|
|
|
nsSVGPatternFrame::GetReferencedPatternIfNotInUse()
|
2008-09-30 17:51:05 -07:00
|
|
|
|
{
|
2011-01-15 23:36:34 -08:00
|
|
|
|
nsSVGPatternFrame *referenced = GetReferencedPattern();
|
|
|
|
|
if (!referenced)
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr;
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
2011-01-15 23:36:34 -08:00
|
|
|
|
if (referenced->mLoopFlag) {
|
|
|
|
|
// XXXjwatt: we should really send an error to the JavaScript Console here:
|
|
|
|
|
NS_WARNING("pattern reference loop detected while inheriting attribute!");
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr;
|
2011-01-15 23:36:34 -08:00
|
|
|
|
}
|
2008-09-30 17:51:05 -07:00
|
|
|
|
|
2011-01-15 23:36:34 -08:00
|
|
|
|
return referenced;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-11 08:21:03 -07:00
|
|
|
|
gfxRect
|
2012-07-31 03:17:11 -07:00
|
|
|
|
nsSVGPatternFrame::GetPatternRect(PRUint16 aPatternUnits,
|
|
|
|
|
const gfxRect &aTargetBBox,
|
2009-07-23 01:35:59 -07:00
|
|
|
|
const gfxMatrix &aTargetCTM,
|
2010-07-01 09:40:30 -07:00
|
|
|
|
nsIFrame *aTarget)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
|
|
|
|
// We need to initialize our box
|
|
|
|
|
float x,y,width,height;
|
|
|
|
|
|
|
|
|
|
// Get the pattern x,y,width, and height
|
2009-02-03 06:42:24 -08:00
|
|
|
|
const nsSVGLength2 *tmpX, *tmpY, *tmpHeight, *tmpWidth;
|
2011-01-15 23:36:34 -08:00
|
|
|
|
tmpX = GetLengthValue(nsSVGPatternElement::X);
|
|
|
|
|
tmpY = GetLengthValue(nsSVGPatternElement::Y);
|
|
|
|
|
tmpHeight = GetLengthValue(nsSVGPatternElement::HEIGHT);
|
|
|
|
|
tmpWidth = GetLengthValue(nsSVGPatternElement::WIDTH);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2012-07-31 03:17:11 -07:00
|
|
|
|
if (aPatternUnits == nsIDOMSVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
|
2009-06-11 08:21:03 -07:00
|
|
|
|
x = nsSVGUtils::ObjectSpace(aTargetBBox, tmpX);
|
|
|
|
|
y = nsSVGUtils::ObjectSpace(aTargetBBox, tmpY);
|
|
|
|
|
width = nsSVGUtils::ObjectSpace(aTargetBBox, tmpWidth);
|
|
|
|
|
height = nsSVGUtils::ObjectSpace(aTargetBBox, tmpHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
} else {
|
2009-06-11 08:21:03 -07:00
|
|
|
|
float scale = nsSVGUtils::MaxExpansion(aTargetCTM);
|
|
|
|
|
x = nsSVGUtils::UserSpace(aTarget, tmpX) * scale;
|
|
|
|
|
y = nsSVGUtils::UserSpace(aTarget, tmpY) * scale;
|
|
|
|
|
width = nsSVGUtils::UserSpace(aTarget, tmpWidth) * scale;
|
|
|
|
|
height = nsSVGUtils::UserSpace(aTarget, tmpHeight) * scale;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-11 08:21:03 -07:00
|
|
|
|
return gfxRect(x, y, width, height);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
gfxMatrix
|
2012-07-31 03:17:11 -07:00
|
|
|
|
nsSVGPatternFrame::ConstructCTM(const nsSVGViewBox& aViewBox,
|
|
|
|
|
PRUint16 aPatternContentUnits,
|
|
|
|
|
PRUint16 aPatternUnits,
|
|
|
|
|
const gfxRect &callerBBox,
|
2009-10-25 06:05:33 -07:00
|
|
|
|
const gfxMatrix &callerCTM,
|
2010-07-01 09:40:30 -07:00
|
|
|
|
nsIFrame *aTarget)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2009-07-23 01:35:59 -07:00
|
|
|
|
gfxMatrix tCTM;
|
2012-07-30 07:20:58 -07:00
|
|
|
|
nsSVGSVGElement *ctx = nullptr;
|
2010-10-18 15:08:52 -07:00
|
|
|
|
nsIContent* targetContent = aTarget->GetContent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
|
// The objectBoundingBox conversion must be handled in the CTM:
|
2012-07-31 03:17:11 -07:00
|
|
|
|
if (IncludeBBoxScale(aViewBox, aPatternContentUnits, aPatternUnits)) {
|
2009-07-23 01:35:59 -07:00
|
|
|
|
tCTM.Scale(callerBBox.Width(), callerBBox.Height());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
} else {
|
2010-10-18 15:08:52 -07:00
|
|
|
|
if (targetContent->IsSVG()) {
|
|
|
|
|
ctx = static_cast<nsSVGElement*>(targetContent)->GetCtx();
|
|
|
|
|
}
|
2007-10-02 07:57:47 -07:00
|
|
|
|
float scale = nsSVGUtils::MaxExpansion(callerCTM);
|
2009-07-23 01:35:59 -07:00
|
|
|
|
tCTM.Scale(scale, scale);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-31 03:17:11 -07:00
|
|
|
|
if (!aViewBox.IsExplicitlySet()) {
|
2012-03-31 04:23:37 -07:00
|
|
|
|
return tCTM;
|
2012-03-31 03:47:18 -07:00
|
|
|
|
}
|
2012-07-31 03:17:11 -07:00
|
|
|
|
const nsSVGViewBoxRect viewBoxRect = aViewBox.GetAnimValue();
|
2012-03-31 03:47:18 -07:00
|
|
|
|
|
|
|
|
|
if (viewBoxRect.height <= 0.0f || viewBoxRect.width <= 0.0f) {
|
|
|
|
|
return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
|
|
|
|
|
}
|
2009-12-29 01:56:25 -08:00
|
|
|
|
|
2011-04-09 13:57:51 -07:00
|
|
|
|
float viewportWidth, viewportHeight;
|
|
|
|
|
if (targetContent->IsSVG()) {
|
|
|
|
|
// If we're dealing with an SVG target only retrieve the context once.
|
|
|
|
|
// Calling the nsIFrame* variant of GetAnimValue would look it up on
|
|
|
|
|
// every call.
|
|
|
|
|
viewportWidth =
|
|
|
|
|
GetLengthValue(nsSVGPatternElement::WIDTH)->GetAnimValue(ctx);
|
|
|
|
|
viewportHeight =
|
|
|
|
|
GetLengthValue(nsSVGPatternElement::HEIGHT)->GetAnimValue(ctx);
|
|
|
|
|
} else {
|
|
|
|
|
// No SVG target, call the nsIFrame* variant of GetAnimValue.
|
|
|
|
|
viewportWidth =
|
|
|
|
|
GetLengthValue(nsSVGPatternElement::WIDTH)->GetAnimValue(aTarget);
|
|
|
|
|
viewportHeight =
|
|
|
|
|
GetLengthValue(nsSVGPatternElement::HEIGHT)->GetAnimValue(aTarget);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
2012-03-31 03:47:18 -07:00
|
|
|
|
|
|
|
|
|
if (viewportWidth <= 0.0f || viewportHeight <= 0.0f) {
|
|
|
|
|
return gfxMatrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); // singular
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-09 13:57:51 -07:00
|
|
|
|
gfxMatrix tm = nsSVGUtils::GetViewBoxTransform(
|
|
|
|
|
static_cast<nsSVGPatternElement*>(mContent),
|
|
|
|
|
viewportWidth, viewportHeight,
|
2012-03-31 03:47:18 -07:00
|
|
|
|
viewBoxRect.x, viewBoxRect.y,
|
|
|
|
|
viewBoxRect.width, viewBoxRect.height,
|
2011-04-09 13:57:51 -07:00
|
|
|
|
GetPreserveAspectRatio());
|
|
|
|
|
|
2009-12-29 01:56:25 -08:00
|
|
|
|
return tm * tCTM;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
// nsSVGPaintServerFrame methods:
|
|
|
|
|
|
2010-07-01 09:40:30 -07:00
|
|
|
|
already_AddRefed<gfxPattern>
|
|
|
|
|
nsSVGPatternFrame::GetPaintServerPattern(nsIFrame *aSource,
|
2012-07-13 16:18:38 -07:00
|
|
|
|
const gfxMatrix& aContextMatrix,
|
2012-05-18 01:34:25 -07:00
|
|
|
|
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
|
2010-07-01 09:40:30 -07:00
|
|
|
|
float aGraphicOpacity,
|
|
|
|
|
const gfxRect *aOverrideBounds)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
{
|
2008-02-08 13:52:04 -08:00
|
|
|
|
if (aGraphicOpacity == 0.0f) {
|
2010-07-01 09:40:30 -07:00
|
|
|
|
nsRefPtr<gfxPattern> pattern = new gfxPattern(gfxRGBA(0, 0, 0, 0));
|
|
|
|
|
return pattern.forget();
|
2008-02-08 13:52:04 -08:00
|
|
|
|
}
|
2007-04-24 01:11:22 -07:00
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
// Paint it!
|
2007-04-30 08:53:55 -07:00
|
|
|
|
nsRefPtr<gfxASurface> surface;
|
|
|
|
|
gfxMatrix pMatrix;
|
2012-07-13 16:18:38 -07:00
|
|
|
|
nsresult rv = PaintPattern(getter_AddRefs(surface), &pMatrix, aContextMatrix,
|
2012-05-18 01:34:25 -07:00
|
|
|
|
aSource, aFillOrStroke, aGraphicOpacity, aOverrideBounds);
|
2007-10-02 07:57:47 -07:00
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2007-04-30 08:53:55 -07:00
|
|
|
|
if (pMatrix.IsSingular()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
2007-10-02 07:57:47 -07:00
|
|
|
|
|
2007-04-30 08:53:55 -07:00
|
|
|
|
pMatrix.Invert();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2007-04-30 08:53:55 -07:00
|
|
|
|
nsRefPtr<gfxPattern> pattern = new gfxPattern(surface);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2008-03-17 10:15:43 -07:00
|
|
|
|
if (!pattern || pattern->CairoStatus())
|
2012-07-30 07:20:58 -07:00
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
2007-04-30 08:53:55 -07:00
|
|
|
|
pattern->SetMatrix(pMatrix);
|
|
|
|
|
pattern->SetExtend(gfxPattern::EXTEND_REPEAT);
|
2010-07-01 09:40:30 -07:00
|
|
|
|
return pattern.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
// Public functions
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
nsIFrame* NS_NewSVGPatternFrame(nsIPresShell* aPresShell,
|
|
|
|
|
nsStyleContext* aContext)
|
|
|
|
|
{
|
2008-10-11 04:29:35 -07:00
|
|
|
|
return new (aPresShell) nsSVGPatternFrame(aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
}
|
|
|
|
|
|