2004-10-14 23:02:53 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2004-10-14 23:02:53 +00:00
|
|
|
|
|
|
|
#ifndef __NS_SVGGRADIENTFRAME_H__
|
|
|
|
#define __NS_SVGGRADIENTFRAME_H__
|
|
|
|
|
2012-03-20 12:15:55 +00:00
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsLiteralString.h"
|
2006-05-16 15:55:01 +00:00
|
|
|
#include "nsSVGPaintServerFrame.h"
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2012-03-20 12:15:55 +00:00
|
|
|
class gfxPattern;
|
|
|
|
class nsIAtom;
|
|
|
|
class nsIContent;
|
|
|
|
class nsIFrame;
|
|
|
|
class nsIPresShell;
|
|
|
|
class nsStyleContext;
|
|
|
|
class nsSVGLinearGradientElement;
|
|
|
|
class nsSVGRadialGradientElement;
|
|
|
|
|
|
|
|
struct gfxRect;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
class SVGAnimatedTransformList;
|
|
|
|
}
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2008-10-01 00:51:05 +00:00
|
|
|
typedef nsSVGPaintServerFrame nsSVGGradientFrameBase;
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2008-10-01 00:51:05 +00:00
|
|
|
/**
|
|
|
|
* Gradients can refer to other gradients. We create an nsSVGPaintingProperty
|
|
|
|
* with property type nsGkAtoms::href to track the referenced gradient.
|
|
|
|
*/
|
|
|
|
class nsSVGGradientFrame : public nsSVGGradientFrameBase
|
2006-05-11 20:01:12 +00:00
|
|
|
{
|
2007-07-25 09:16:02 +00:00
|
|
|
protected:
|
2008-10-11 11:29:35 +00:00
|
|
|
nsSVGGradientFrame(nsStyleContext* aContext);
|
2007-07-25 09:16:02 +00:00
|
|
|
|
2006-05-11 20:01:12 +00:00
|
|
|
public:
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2006-05-16 15:55:01 +00:00
|
|
|
// nsSVGPaintServerFrame methods:
|
2010-07-01 16:40:30 +00:00
|
|
|
virtual already_AddRefed<gfxPattern>
|
|
|
|
GetPaintServerPattern(nsIFrame *aSource,
|
2012-07-13 23:18:38 +00:00
|
|
|
const gfxMatrix& aContextMatrix,
|
2012-05-18 08:34:25 +00:00
|
|
|
nsStyleSVGPaint nsStyleSVG::*aFillOrStroke,
|
2010-07-01 16:40:30 +00:00
|
|
|
float aGraphicOpacity,
|
|
|
|
const gfxRect *aOverrideBounds);
|
2006-05-11 20:01:12 +00:00
|
|
|
|
|
|
|
// nsIFrame interface:
|
2008-10-26 10:11:34 +00:00
|
|
|
virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
|
2006-05-11 20:01:12 +00:00
|
|
|
|
|
|
|
NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2008-10-01 00:51:05 +00:00
|
|
|
private:
|
2008-09-30 11:28:20 +00:00
|
|
|
|
2008-10-01 00:51:05 +00:00
|
|
|
// Parse our xlink:href and set up our nsSVGPaintingProperty if we
|
|
|
|
// reference another gradient and we don't have a property. Return
|
|
|
|
// the referenced gradient's frame if available, null otherwise.
|
|
|
|
nsSVGGradientFrame* GetReferencedGradient();
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2006-05-17 01:43:44 +00:00
|
|
|
// Optionally get a stop frame (returns stop index/count)
|
|
|
|
PRInt32 GetStopFrame(PRInt32 aIndex, nsIFrame * *aStopFrame);
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2006-05-16 15:55:01 +00:00
|
|
|
PRUint32 GetStopCount();
|
|
|
|
void GetStopInformation(PRInt32 aIndex,
|
2007-04-24 08:11:22 +00:00
|
|
|
float *aOffset, nscolor *aColor, float *aStopOpacity);
|
2009-06-11 15:21:03 +00:00
|
|
|
|
2012-03-06 06:58:40 +00:00
|
|
|
const mozilla::SVGAnimatedTransformList* GetGradientTransformList(
|
|
|
|
nsIContent* aDefault);
|
2009-06-11 15:21:03 +00:00
|
|
|
// Will be singular for gradientUnits="objectBoundingBox" with an empty bbox.
|
2012-03-06 06:58:40 +00:00
|
|
|
gfxMatrix GetGradientTransform(nsIFrame *aSource,
|
|
|
|
const gfxRect *aOverrideBounds);
|
2006-05-16 15:55:01 +00:00
|
|
|
|
2006-05-11 20:01:12 +00:00
|
|
|
protected:
|
2007-04-27 14:28:39 +00:00
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient() = 0;
|
2006-05-16 15:55:01 +00:00
|
|
|
|
2012-03-06 06:58:40 +00:00
|
|
|
// Internal methods for handling referenced gradients
|
|
|
|
class AutoGradientReferencer;
|
|
|
|
nsSVGGradientFrame* GetReferencedGradientIfNotInUse();
|
|
|
|
|
|
|
|
// Accessors to lookup gradient attributes
|
|
|
|
PRUint16 GetEnumValue(PRUint32 aIndex, nsIContent *aDefault);
|
|
|
|
PRUint16 GetEnumValue(PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
return GetEnumValue(aIndex, mContent);
|
|
|
|
}
|
2012-03-20 12:15:55 +00:00
|
|
|
PRUint16 GetGradientUnits();
|
|
|
|
PRUint16 GetSpreadMethod();
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2012-03-06 06:58:40 +00:00
|
|
|
// Gradient-type-specific lookups since the length values differ between
|
|
|
|
// linear and radial gradients
|
|
|
|
virtual nsSVGLinearGradientElement * GetLinearGradientWithLength(
|
|
|
|
PRUint32 aIndex, nsSVGLinearGradientElement* aDefault);
|
|
|
|
virtual nsSVGRadialGradientElement * GetRadialGradientWithLength(
|
|
|
|
PRUint32 aIndex, nsSVGRadialGradientElement* aDefault);
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2010-07-01 16:40:30 +00:00
|
|
|
// The frame our gradient is (currently) being applied to
|
|
|
|
nsIFrame* mSource;
|
2006-05-11 20:01:12 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Flag to mark this frame as "in use" during recursive calls along our
|
|
|
|
// gradient's reference chain so we can detect reference loops. See:
|
|
|
|
// http://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementHrefAttribute
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mLoopFlag;
|
2008-10-01 00:51:05 +00:00
|
|
|
// Gradients often don't reference other gradients, so here we cache
|
|
|
|
// the fact that that isn't happening.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mNoHRefURI;
|
2006-05-11 20:01:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Linear Gradients
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef nsSVGGradientFrame nsSVGLinearGradientFrameBase;
|
|
|
|
|
|
|
|
class nsSVGLinearGradientFrame : public nsSVGLinearGradientFrameBase
|
|
|
|
{
|
2008-10-01 00:51:05 +00:00
|
|
|
friend nsIFrame* NS_NewSVGLinearGradientFrame(nsIPresShell* aPresShell,
|
2006-09-08 13:19:47 +00:00
|
|
|
nsStyleContext* aContext);
|
2007-07-25 09:16:02 +00:00
|
|
|
protected:
|
2008-10-11 11:29:35 +00:00
|
|
|
nsSVGLinearGradientFrame(nsStyleContext* aContext) :
|
|
|
|
nsSVGLinearGradientFrameBase(aContext) {}
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2007-07-25 09:16:02 +00:00
|
|
|
public:
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2006-05-11 20:01:12 +00:00
|
|
|
// nsIFrame interface:
|
2009-01-19 18:31:34 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow);
|
|
|
|
#endif
|
|
|
|
|
2006-05-11 20:01:12 +00:00
|
|
|
virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgLinearGradientFrame
|
|
|
|
|
|
|
|
NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGLinearGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
protected:
|
2012-03-06 06:58:40 +00:00
|
|
|
float GetLengthValue(PRUint32 aIndex);
|
|
|
|
virtual nsSVGLinearGradientElement * GetLinearGradientWithLength(
|
|
|
|
PRUint32 aIndex, nsSVGLinearGradientElement* aDefault);
|
2007-04-27 14:28:39 +00:00
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient();
|
2006-05-11 20:01:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Radial Gradients
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef nsSVGGradientFrame nsSVGRadialGradientFrameBase;
|
|
|
|
|
|
|
|
class nsSVGRadialGradientFrame : public nsSVGRadialGradientFrameBase
|
|
|
|
{
|
2008-10-01 00:51:05 +00:00
|
|
|
friend nsIFrame* NS_NewSVGRadialGradientFrame(nsIPresShell* aPresShell,
|
2006-09-08 13:19:47 +00:00
|
|
|
nsStyleContext* aContext);
|
2007-07-25 09:16:02 +00:00
|
|
|
protected:
|
2008-10-11 11:29:35 +00:00
|
|
|
nsSVGRadialGradientFrame(nsStyleContext* aContext) :
|
|
|
|
nsSVGRadialGradientFrameBase(aContext) {}
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2007-07-25 09:16:02 +00:00
|
|
|
public:
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2006-05-11 20:01:12 +00:00
|
|
|
// nsIFrame interface:
|
2009-01-19 18:31:34 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow);
|
|
|
|
#endif
|
|
|
|
|
2006-05-11 20:01:12 +00:00
|
|
|
virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgRadialGradientFrame
|
|
|
|
|
|
|
|
NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGRadialGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
protected:
|
2012-03-06 06:58:40 +00:00
|
|
|
float GetLengthValue(PRUint32 aIndex);
|
|
|
|
float GetLengthValue(PRUint32 aIndex, float aDefaultValue);
|
|
|
|
float GetLengthValueFromElement(PRUint32 aIndex,
|
|
|
|
nsSVGRadialGradientElement& aElement);
|
|
|
|
virtual nsSVGRadialGradientElement * GetRadialGradientWithLength(
|
|
|
|
PRUint32 aIndex, nsSVGRadialGradientElement* aDefault);
|
2007-04-27 14:28:39 +00:00
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient();
|
2006-05-11 20:01:12 +00:00
|
|
|
};
|
|
|
|
|
2004-10-14 23:02:53 +00:00
|
|
|
#endif // __NS_SVGGRADIENTFRAME_H__
|
|
|
|
|