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__
|
|
|
|
|
2013-05-29 12:37:49 -07:00
|
|
|
#include "mozilla/Attributes.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;
|
|
|
|
|
|
|
|
struct gfxRect;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2013-04-14 15:56:34 -07:00
|
|
|
class nsSVGAnimatedTransformList;
|
2013-01-11 00:43:01 -08:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class SVGLinearGradientElement;
|
|
|
|
class SVGRadialGradientElement;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
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,
|
2013-05-29 12:37:49 -07:00
|
|
|
const gfxRect *aOverrideBounds) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIFrame interface:
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2013-05-29 12:37:49 -07:00
|
|
|
int32_t aModType) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2013-05-29 12:37:49 -07:00
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
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)
|
2013-05-27 00:34:01 -07:00
|
|
|
void GetStopFrames(nsTArray<nsIFrame*>* aStopFrames);
|
2009-06-11 08:21:03 -07:00
|
|
|
|
2013-04-14 15:56:34 -07:00
|
|
|
const mozilla::nsSVGAnimatedTransformList* GetGradientTransformList(
|
2012-03-05 22:58:40 -08:00
|
|
|
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:
|
2013-05-27 00:34:01 -07:00
|
|
|
virtual bool GradientVectorLengthIsZero() = 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
|
2013-01-11 00:43:01 -08:00
|
|
|
virtual mozilla::dom::SVGLinearGradientElement * GetLinearGradientWithLength(
|
|
|
|
uint32_t aIndex, mozilla::dom::SVGLinearGradientElement* aDefault);
|
|
|
|
virtual mozilla::dom::SVGRadialGradientElement * GetRadialGradientWithLength(
|
|
|
|
uint32_t aIndex, mozilla::dom::SVGRadialGradientElement* 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
|
2013-03-19 18:47:48 -07:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2009-01-19 10:31:34 -08:00
|
|
|
#endif
|
|
|
|
|
2013-05-29 12:37:49 -07:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE; // frame type: nsGkAtoms::svgLinearGradientFrame
|
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,
|
2013-05-29 12:37:49 -07:00
|
|
|
int32_t aModType) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2013-05-29 12:37:49 -07:00
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGLinearGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
float GetLengthValue(uint32_t aIndex);
|
2013-01-11 00:43:01 -08:00
|
|
|
virtual mozilla::dom::SVGLinearGradientElement* GetLinearGradientWithLength(
|
2013-05-29 12:37:49 -07:00
|
|
|
uint32_t aIndex, mozilla::dom::SVGLinearGradientElement* aDefault) MOZ_OVERRIDE;
|
|
|
|
virtual bool GradientVectorLengthIsZero() MOZ_OVERRIDE;
|
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient() MOZ_OVERRIDE;
|
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
|
2013-03-19 18:47:48 -07:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2009-01-19 10:31:34 -08:00
|
|
|
#endif
|
|
|
|
|
2013-05-29 12:37:49 -07:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE; // frame type: nsGkAtoms::svgRadialGradientFrame
|
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,
|
2013-05-29 12:37:49 -07:00
|
|
|
int32_t aModType) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2013-05-29 12:37:49 -07:00
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
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,
|
2013-01-11 00:43:01 -08:00
|
|
|
mozilla::dom::SVGRadialGradientElement& aElement);
|
|
|
|
virtual mozilla::dom::SVGRadialGradientElement* GetRadialGradientWithLength(
|
2013-05-29 12:37:49 -07:00
|
|
|
uint32_t aIndex, mozilla::dom::SVGRadialGradientElement* aDefault) MOZ_OVERRIDE;
|
|
|
|
virtual bool GradientVectorLengthIsZero() MOZ_OVERRIDE;
|
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient() MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __NS_SVGGRADIENTFRAME_H__
|
|
|
|
|