2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla SVG project.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Scooter Morris.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Scooter Morris <scootermorris@comcast.net>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef __NS_SVGGRADIENTFRAME_H__
|
|
|
|
#define __NS_SVGGRADIENTFRAME_H__
|
|
|
|
|
|
|
|
#include "nsSVGPaintServerFrame.h"
|
|
|
|
#include "nsSVGElement.h"
|
2007-04-27 07:28:39 -07:00
|
|
|
#include "gfxPattern.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIDOMSVGStopElement;
|
|
|
|
|
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,
|
|
|
|
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
|
|
|
|
|
|
|
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-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)
|
|
|
|
PRInt32 GetStopFrame(PRInt32 aIndex, nsIFrame * *aStopFrame);
|
|
|
|
|
|
|
|
PRUint32 GetStopCount();
|
|
|
|
void GetStopInformation(PRInt32 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:
|
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
|
|
|
|
PRUint16 GetEnumValue(PRUint32 aIndex, nsIContent *aDefault);
|
|
|
|
PRUint16 GetEnumValue(PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
return GetEnumValue(aIndex, mContent);
|
|
|
|
}
|
|
|
|
PRUint16 GetGradientUnits()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-05 22:58:40 -08:00
|
|
|
// This getter is called every time the others are called - maybe cache it?
|
|
|
|
return GetEnumValue(nsSVGGradientElement::GRADIENTUNITS);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-03-05 22:58:40 -08:00
|
|
|
PRUint16 GetSpreadMethod()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-05 22:58:40 -08:00
|
|
|
return GetEnumValue(nsSVGGradientElement::SPREADMETHOD);
|
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(
|
|
|
|
PRUint32 aIndex, nsSVGLinearGradientElement* aDefault);
|
|
|
|
virtual nsSVGRadialGradientElement * GetRadialGradientWithLength(
|
|
|
|
PRUint32 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
|
|
|
|
|
|
|
|
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-05 22:58:40 -08:00
|
|
|
float GetLengthValue(PRUint32 aIndex);
|
|
|
|
virtual nsSVGLinearGradientElement * GetLinearGradientWithLength(
|
|
|
|
PRUint32 aIndex, nsSVGLinearGradientElement* aDefault);
|
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
|
|
|
|
|
|
|
|
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-05 22:58:40 -08: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 07:28:39 -07:00
|
|
|
virtual already_AddRefed<gfxPattern> CreateGradient();
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __NS_SVGGRADIENTFRAME_H__
|
|
|
|
|