Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / svg / base / src / nsSVGGradientFrame.h
blob0dd42fec812496f3d1bdb0a74821548226b4b348
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is the Mozilla SVG project.
17 * The Initial Developer of the Original Code is
18 * Scooter Morris.
19 * Portions created by the Initial Developer are Copyright (C) 2004
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Scooter Morris <scootermorris@comcast.net>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef __NS_SVGGRADIENTFRAME_H__
40 #define __NS_SVGGRADIENTFRAME_H__
42 #include "nsSVGPaintServerFrame.h"
43 #include "nsISVGValueObserver.h"
44 #include "nsWeakReference.h"
45 #include "nsSVGElement.h"
46 #include "gfxPattern.h"
48 class nsIDOMSVGStopElement;
50 typedef nsSVGPaintServerFrame nsSVGGradientFrameBase;
52 /**
53 * Gradients can refer to other gradients. We create an nsSVGPaintingProperty
54 * with property type nsGkAtoms::href to track the referenced gradient.
56 class nsSVGGradientFrame : public nsSVGGradientFrameBase
58 protected:
59 nsSVGGradientFrame(nsStyleContext* aContext);
61 public:
62 // nsSVGPaintServerFrame methods:
63 virtual PRBool SetupPaintServer(gfxContext *aContext,
64 nsSVGGeometryFrame *aSource,
65 float aGraphicOpacity);
67 // nsIFrame interface:
68 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
70 NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
71 nsIAtom* aAttribute,
72 PRInt32 aModType);
74 #ifdef DEBUG
75 // nsIFrameDebug interface:
76 NS_IMETHOD GetFrameName(nsAString& aResult) const
78 return MakeFrameName(NS_LITERAL_STRING("SVGGradient"), aResult);
80 #endif // DEBUG
82 private:
84 // Parse our xlink:href and set up our nsSVGPaintingProperty if we
85 // reference another gradient and we don't have a property. Return
86 // the referenced gradient's frame if available, null otherwise.
87 nsSVGGradientFrame* GetReferencedGradient();
89 // Helpers to look at our gradient and then along its reference chain (if any)
90 // to find the first gradient with the specified attribute.
91 // Returns aDefault if no content with that attribute is found
92 nsSVGGradientElement* GetGradientWithAttr(nsIAtom *aAttrName, nsIContent *aDefault);
94 // Some attributes are only valid on one type of gradient, and we *must* get
95 // the right type or we won't have the data structures we require.
96 // Returns aDefault if no content with that attribute is found
97 nsSVGGradientElement* GetGradientWithAttr(nsIAtom *aAttrName, nsIAtom *aGradType,
98 nsIContent *aDefault);
100 // Optionally get a stop frame (returns stop index/count)
101 PRInt32 GetStopFrame(PRInt32 aIndex, nsIFrame * *aStopFrame);
103 PRUint16 GetSpreadMethod();
104 PRUint32 GetStopCount();
105 void GetStopInformation(PRInt32 aIndex,
106 float *aOffset, nscolor *aColor, float *aStopOpacity);
107 gfxMatrix GetGradientTransform(nsSVGGeometryFrame *aSource);
109 protected:
110 virtual already_AddRefed<gfxPattern> CreateGradient() = 0;
112 // Use these inline methods instead of GetGradientWithAttr(..., aGradType)
113 nsSVGLinearGradientElement* GetLinearGradientWithAttr(nsIAtom *aAttrName, nsIContent *aDefault)
115 return static_cast<nsSVGLinearGradientElement*>(
116 GetGradientWithAttr(aAttrName, nsGkAtoms::svgLinearGradientFrame, aDefault));
118 nsSVGRadialGradientElement* GetRadialGradientWithAttr(nsIAtom *aAttrName, nsIContent *aDefault)
120 return static_cast<nsSVGRadialGradientElement*>(
121 GetGradientWithAttr(aAttrName, nsGkAtoms::svgRadialGradientFrame, aDefault));
124 // Get the value of our gradientUnits attribute
125 PRUint16 GetGradientUnits();
127 // The graphic element our gradient is (currently) being applied to
128 nsRefPtr<nsSVGElement> mSourceContent;
130 private:
131 // Flag to mark this frame as "in use" during recursive calls along our
132 // gradient's reference chain so we can detect reference loops. See:
133 // http://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementHrefAttribute
134 PRPackedBool mLoopFlag;
135 // Gradients often don't reference other gradients, so here we cache
136 // the fact that that isn't happening.
137 PRPackedBool mNoHRefURI;
141 // -------------------------------------------------------------------------
142 // Linear Gradients
143 // -------------------------------------------------------------------------
145 typedef nsSVGGradientFrame nsSVGLinearGradientFrameBase;
147 class nsSVGLinearGradientFrame : public nsSVGLinearGradientFrameBase
149 friend nsIFrame* NS_NewSVGLinearGradientFrame(nsIPresShell* aPresShell,
150 nsIContent* aContent,
151 nsStyleContext* aContext);
152 protected:
153 nsSVGLinearGradientFrame(nsStyleContext* aContext) :
154 nsSVGLinearGradientFrameBase(aContext) {}
156 public:
157 // nsIFrame interface:
158 virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgLinearGradientFrame
160 NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
161 nsIAtom* aAttribute,
162 PRInt32 aModType);
164 #ifdef DEBUG
165 // nsIFrameDebug interface:
166 NS_IMETHOD GetFrameName(nsAString& aResult) const
168 return MakeFrameName(NS_LITERAL_STRING("SVGLinearGradient"), aResult);
170 #endif // DEBUG
172 protected:
173 float GradientLookupAttribute(nsIAtom *aAtomName, PRUint16 aEnumName);
174 virtual already_AddRefed<gfxPattern> CreateGradient();
177 // -------------------------------------------------------------------------
178 // Radial Gradients
179 // -------------------------------------------------------------------------
181 typedef nsSVGGradientFrame nsSVGRadialGradientFrameBase;
183 class nsSVGRadialGradientFrame : public nsSVGRadialGradientFrameBase
185 friend nsIFrame* NS_NewSVGRadialGradientFrame(nsIPresShell* aPresShell,
186 nsIContent* aContent,
187 nsStyleContext* aContext);
188 protected:
189 nsSVGRadialGradientFrame(nsStyleContext* aContext) :
190 nsSVGRadialGradientFrameBase(aContext) {}
192 public:
193 // nsIFrame interface:
194 virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgRadialGradientFrame
196 NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
197 nsIAtom* aAttribute,
198 PRInt32 aModType);
200 #ifdef DEBUG
201 // nsIFrameDebug interface:
202 NS_IMETHOD GetFrameName(nsAString& aResult) const
204 return MakeFrameName(NS_LITERAL_STRING("SVGRadialGradient"), aResult);
206 #endif // DEBUG
208 protected:
209 float GradientLookupAttribute(nsIAtom *aAtomName, PRUint16 aEnumName,
210 nsSVGRadialGradientElement *aElement = nsnull);
211 virtual already_AddRefed<gfxPattern> CreateGradient();
214 #endif // __NS_SVGGRADIENTFRAME_H__