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
|
|
|
|
|
|
|
#ifndef __NS_SVGGRADIENTFRAME_H__
|
|
|
|
#define __NS_SVGGRADIENTFRAME_H__
|
|
|
|
|
2012-03-20 05:15:55 -07:00
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsLiteralString.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGPaintServerFrame.h"
|
|
|
|
|
2012-03-20 05:15:55 -07:00
|
|
|
class gfxPattern;
|
|
|
|
class nsIAtom;
|
|
|
|
class nsIContent;
|
|
|
|
class nsIFrame;
|
|
|
|
class nsIPresShell;
|
|
|
|
class nsStyleContext;
|
|
|
|
class nsSVGLinearGradientElement;
|
|
|
|
class nsSVGRadialGradientElement;
|
|
|
|
|
|
|
|
struct gfxRect;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
class SVGAnimatedTransformList;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-30 17:51:05 -07:00
|
|
|
typedef nsSVGPaintServerFrame nsSVGGradientFrameBase;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-30 17:51:05 -07: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
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-25 02:16:02 -07:00
|
|
|
protected:
|
2008-10-11 04:29:35 -07:00
|
|
|
nsSVGGradientFrame(nsStyleContext* aContext);
|
2007-07-25 02:16:02 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsSVGPaintServerFrame methods:
|
2010-07-01 09:40:30 -07:00
|
|
|
virtual already_AddRefed<gfxPattern>
|
|
|
|
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
|
|
|
|
|
|
|
// nsIFrame interface:
|
2008-10-26 03:11:34 -07:00
|
|
|
virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2008-09-30 17:51:05 -07:00
|
|
|
private:
|
2008-09-30 04:28:20 -07:00
|
|
|
|
2008-09-30 17:51:05 -07: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();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Optionally get a stop frame (returns stop index/count)
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetStopFrame(int32_t aIndex, nsIFrame * *aStopFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void GetStopInformation(int32_t aIndex,
|
2007-04-24 01:11:22 -07:00
|
|
|
float *aOffset, nscolor *aColor, float *aStopOpacity);
|
2009-06-11 08:21:03 -07:00
|
|
|
|
2012-03-05 22:58:40 -08:00
|
|
|
const mozilla::SVGAnimatedTransformList* GetGradientTransformList(
|
|
|
|
nsIContent* aDefault);
|
2009-06-11 08:21:03 -07:00
|
|
|
// Will be singular for gradientUnits="objectBoundingBox" with an empty bbox.
|
2012-03-05 22:58:40 -08:00
|
|
|
gfxMatrix GetGradientTransform(nsIFrame *aSource,
|
|
|
|
const gfxRect *aOverrideBounds);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
2012-10-06 05:52:32 -07:00
|
|
|
uint32_t GetStopCount();
|
|
|
|
virtual bool IsSingleColour(uint32_t nStops) = 0;
|
2007-04-27 07:28:39 -07:00
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient() = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-05 22:58:40 -08:00
|
|
|
// Internal methods for handling referenced gradients
|
|
|
|
class AutoGradientReferencer;
|
|
|
|
nsSVGGradientFrame* GetReferencedGradientIfNotInUse();
|
|
|
|
|
|
|
|
// Accessors to lookup gradient attributes
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t GetEnumValue(uint32_t aIndex, nsIContent *aDefault);
|
|
|
|
uint16_t GetEnumValue(uint32_t aIndex)
|
2012-03-05 22:58:40 -08:00
|
|
|
{
|
|
|
|
return GetEnumValue(aIndex, mContent);
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t GetGradientUnits();
|
|
|
|
uint16_t GetSpreadMethod();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-05 22:58:40 -08:00
|
|
|
// Gradient-type-specific lookups since the length values differ between
|
|
|
|
// linear and radial gradients
|
|
|
|
virtual nsSVGLinearGradientElement * GetLinearGradientWithLength(
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndex, nsSVGLinearGradientElement* aDefault);
|
2012-03-05 22:58:40 -08:00
|
|
|
virtual nsSVGRadialGradientElement * GetRadialGradientWithLength(
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndex, nsSVGRadialGradientElement* aDefault);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-01 09:40:30 -07:00
|
|
|
// The frame our gradient is (currently) being applied to
|
|
|
|
nsIFrame* mSource;
|
2007-03-22 10:30:00 -07: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-28 23:19:26 -07:00
|
|
|
bool mLoopFlag;
|
2008-09-30 17:51:05 -07:00
|
|
|
// Gradients often don't reference other gradients, so here we cache
|
|
|
|
// the fact that that isn't happening.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mNoHRefURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Linear Gradients
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef nsSVGGradientFrame nsSVGLinearGradientFrameBase;
|
|
|
|
|
|
|
|
class nsSVGLinearGradientFrame : public nsSVGLinearGradientFrameBase
|
|
|
|
{
|
2008-09-30 17:51:05 -07:00
|
|
|
friend nsIFrame* NS_NewSVGLinearGradientFrame(nsIPresShell* aPresShell,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsStyleContext* aContext);
|
2007-07-25 02:16:02 -07:00
|
|
|
protected:
|
2008-10-11 04:29:35 -07:00
|
|
|
nsSVGLinearGradientFrame(nsStyleContext* aContext) :
|
|
|
|
nsSVGLinearGradientFrameBase(aContext) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-25 02:16:02 -07:00
|
|
|
public:
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIFrame interface:
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow);
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgLinearGradientFrame
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGLinearGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
float GetLengthValue(uint32_t aIndex);
|
2012-03-05 22:58:40 -08:00
|
|
|
virtual nsSVGLinearGradientElement * GetLinearGradientWithLength(
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndex, nsSVGLinearGradientElement* aDefault);
|
2012-10-06 05:52:32 -07:00
|
|
|
virtual bool IsSingleColour(uint32_t nStops);
|
2007-04-27 07:28:39 -07:00
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient();
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Radial Gradients
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef nsSVGGradientFrame nsSVGRadialGradientFrameBase;
|
|
|
|
|
|
|
|
class nsSVGRadialGradientFrame : public nsSVGRadialGradientFrameBase
|
|
|
|
{
|
2008-09-30 17:51:05 -07:00
|
|
|
friend nsIFrame* NS_NewSVGRadialGradientFrame(nsIPresShell* aPresShell,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsStyleContext* aContext);
|
2007-07-25 02:16:02 -07:00
|
|
|
protected:
|
2008-10-11 04:29:35 -07:00
|
|
|
nsSVGRadialGradientFrame(nsStyleContext* aContext) :
|
|
|
|
nsSVGRadialGradientFrameBase(aContext) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-25 02:16:02 -07:00
|
|
|
public:
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIFrame interface:
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow);
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgRadialGradientFrame
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGRadialGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
float GetLengthValue(uint32_t aIndex);
|
|
|
|
float GetLengthValue(uint32_t aIndex, float aDefaultValue);
|
|
|
|
float GetLengthValueFromElement(uint32_t aIndex,
|
2012-03-05 22:58:40 -08:00
|
|
|
nsSVGRadialGradientElement& aElement);
|
|
|
|
virtual nsSVGRadialGradientElement * GetRadialGradientWithLength(
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aIndex, nsSVGRadialGradientElement* aDefault);
|
2012-10-06 05:52:32 -07:00
|
|
|
virtual bool IsSingleColour(uint32_t nStops);
|
2007-04-27 07:28:39 -07:00
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient();
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __NS_SVGGRADIENTFRAME_H__
|
|
|
|
|