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__
|
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
#include "mozilla/Attributes.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;
|
|
|
|
|
|
|
|
struct gfxRect;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2013-04-14 22:56:34 +00:00
|
|
|
class nsSVGAnimatedTransformList;
|
2013-01-11 08:43:01 +00:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class SVGLinearGradientElement;
|
|
|
|
class SVGRadialGradientElement;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
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:
|
2014-09-01 03:36:37 +00:00
|
|
|
explicit 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>
|
2014-09-29 13:15:19 +00:00
|
|
|
GetPaintServerPattern(nsIFrame* aSource,
|
|
|
|
const DrawTarget* aDrawTarget,
|
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,
|
2014-09-29 13:15:19 +00:00
|
|
|
const gfxRect* aOverrideBounds) MOZ_OVERRIDE;
|
2006-05-11 20:01:12 +00:00
|
|
|
|
|
|
|
// nsIFrame interface:
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2014-02-18 08:36:33 +00:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) MOZ_OVERRIDE;
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
|
2006-05-11 20:01:12 +00:00
|
|
|
{
|
|
|
|
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)
|
2013-05-27 07:34:01 +00:00
|
|
|
void GetStopFrames(nsTArray<nsIFrame*>* aStopFrames);
|
2009-06-11 15:21:03 +00:00
|
|
|
|
2013-04-14 22:56:34 +00:00
|
|
|
const mozilla::nsSVGAnimatedTransformList* GetGradientTransformList(
|
2012-03-06 06:58:40 +00:00
|
|
|
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:
|
2013-05-27 07:34:01 +00:00
|
|
|
virtual bool GradientVectorLengthIsZero() = 0;
|
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
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t GetEnumValue(uint32_t aIndex, nsIContent *aDefault);
|
|
|
|
uint16_t GetEnumValue(uint32_t aIndex)
|
2012-03-06 06:58:40 +00:00
|
|
|
{
|
|
|
|
return GetEnumValue(aIndex, mContent);
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t GetGradientUnits();
|
|
|
|
uint16_t 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
|
2013-01-11 08:43:01 +00: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);
|
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:
|
2014-09-01 03:36:37 +00:00
|
|
|
explicit nsSVGLinearGradientFrame(nsStyleContext* aContext) :
|
2008-10-11 11:29:35 +00:00
|
|
|
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
|
2014-05-24 22:20:40 +00:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2009-01-19 18:31:34 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE; // frame type: nsGkAtoms::svgLinearGradientFrame
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2014-02-18 08:36:33 +00:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) MOZ_OVERRIDE;
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
|
2006-05-11 20:01:12 +00:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGLinearGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
protected:
|
2012-08-22 15:56:38 +00:00
|
|
|
float GetLengthValue(uint32_t aIndex);
|
2013-01-11 08:43:01 +00:00
|
|
|
virtual mozilla::dom::SVGLinearGradientElement* GetLinearGradientWithLength(
|
2013-05-29 19:37:49 +00:00
|
|
|
uint32_t aIndex, mozilla::dom::SVGLinearGradientElement* aDefault) MOZ_OVERRIDE;
|
|
|
|
virtual bool GradientVectorLengthIsZero() MOZ_OVERRIDE;
|
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient() MOZ_OVERRIDE;
|
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:
|
2014-09-01 03:36:37 +00:00
|
|
|
explicit nsSVGRadialGradientFrame(nsStyleContext* aContext) :
|
2008-10-11 11:29:35 +00:00
|
|
|
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
|
2014-05-24 22:20:40 +00:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2009-01-19 18:31:34 +00:00
|
|
|
#endif
|
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE; // frame type: nsGkAtoms::svgRadialGradientFrame
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2014-02-18 08:36:33 +00:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
int32_t aModType) MOZ_OVERRIDE;
|
2006-05-11 20:01:12 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
|
2006-05-11 20:01:12 +00:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGRadialGradient"), aResult);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
protected:
|
2012-08-22 15:56:38 +00:00
|
|
|
float GetLengthValue(uint32_t aIndex);
|
|
|
|
float GetLengthValue(uint32_t aIndex, float aDefaultValue);
|
|
|
|
float GetLengthValueFromElement(uint32_t aIndex,
|
2013-01-11 08:43:01 +00:00
|
|
|
mozilla::dom::SVGRadialGradientElement& aElement);
|
|
|
|
virtual mozilla::dom::SVGRadialGradientElement* GetRadialGradientWithLength(
|
2013-05-29 19:37:49 +00:00
|
|
|
uint32_t aIndex, mozilla::dom::SVGRadialGradientElement* aDefault) MOZ_OVERRIDE;
|
|
|
|
virtual bool GradientVectorLengthIsZero() MOZ_OVERRIDE;
|
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient() MOZ_OVERRIDE;
|
2006-05-11 20:01:12 +00:00
|
|
|
};
|
|
|
|
|
2004-10-14 23:02:53 +00:00
|
|
|
#endif // __NS_SVGGRADIENTFRAME_H__
|
|
|
|
|