Bug 473511. nsSVGInnerSVGFrame does not need to implement nsISVGValueObserver. r...
[mozilla-central.git] / layout / svg / base / src / nsSVGGradientFrame.h
blobdc510163d788f7a6d8f17e44ebdda2d22359f342
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 "nsWeakReference.h"
44 #include "nsSVGElement.h"
45 #include "gfxPattern.h"
47 class nsIDOMSVGStopElement;
49 typedef nsSVGPaintServerFrame nsSVGGradientFrameBase;
51 /**
52 * Gradients can refer to other gradients. We create an nsSVGPaintingProperty
53 * with property type nsGkAtoms::href to track the referenced gradient.
55 class nsSVGGradientFrame : public nsSVGGradientFrameBase
57 protected:
58 nsSVGGradientFrame(nsStyleContext* aContext);
60 public:
61 // nsSVGPaintServerFrame methods:
62 virtual PRBool SetupPaintServer(gfxContext *aContext,
63 nsSVGGeometryFrame *aSource,
64 float aGraphicOpacity);
66 // nsIFrame interface:
67 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
69 NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
70 nsIAtom* aAttribute,
71 PRInt32 aModType);
73 #ifdef DEBUG
74 // nsIFrameDebug interface:
75 NS_IMETHOD GetFrameName(nsAString& aResult) const
77 return MakeFrameName(NS_LITERAL_STRING("SVGGradient"), aResult);
79 #endif // DEBUG
81 private:
83 // Parse our xlink:href and set up our nsSVGPaintingProperty if we
84 // reference another gradient and we don't have a property. Return
85 // the referenced gradient's frame if available, null otherwise.
86 nsSVGGradientFrame* GetReferencedGradient();
88 // Helpers to look at our gradient and then along its reference chain (if any)
89 // to find the first gradient with the specified attribute.
90 // Returns aDefault if no content with that attribute is found
91 nsSVGGradientElement* GetGradientWithAttr(nsIAtom *aAttrName, nsIContent *aDefault);
93 // Some attributes are only valid on one type of gradient, and we *must* get
94 // the right type or we won't have the data structures we require.
95 // Returns aDefault if no content with that attribute is found
96 nsSVGGradientElement* GetGradientWithAttr(nsIAtom *aAttrName, nsIAtom *aGradType,
97 nsIContent *aDefault);
99 // Optionally get a stop frame (returns stop index/count)
100 PRInt32 GetStopFrame(PRInt32 aIndex, nsIFrame * *aStopFrame);
102 PRUint16 GetSpreadMethod();
103 PRUint32 GetStopCount();
104 void GetStopInformation(PRInt32 aIndex,
105 float *aOffset, nscolor *aColor, float *aStopOpacity);
106 gfxMatrix GetGradientTransform(nsSVGGeometryFrame *aSource);
108 protected:
109 virtual already_AddRefed<gfxPattern> CreateGradient() = 0;
111 // Use these inline methods instead of GetGradientWithAttr(..., aGradType)
112 nsSVGLinearGradientElement* GetLinearGradientWithAttr(nsIAtom *aAttrName, nsIContent *aDefault)
114 return static_cast<nsSVGLinearGradientElement*>(
115 GetGradientWithAttr(aAttrName, nsGkAtoms::svgLinearGradientFrame, aDefault));
117 nsSVGRadialGradientElement* GetRadialGradientWithAttr(nsIAtom *aAttrName, nsIContent *aDefault)
119 return static_cast<nsSVGRadialGradientElement*>(
120 GetGradientWithAttr(aAttrName, nsGkAtoms::svgRadialGradientFrame, aDefault));
123 // Get the value of our gradientUnits attribute
124 PRUint16 GetGradientUnits();
126 // The graphic element our gradient is (currently) being applied to
127 nsRefPtr<nsSVGElement> mSourceContent;
129 private:
130 // Flag to mark this frame as "in use" during recursive calls along our
131 // gradient's reference chain so we can detect reference loops. See:
132 // http://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementHrefAttribute
133 PRPackedBool mLoopFlag;
134 // Gradients often don't reference other gradients, so here we cache
135 // the fact that that isn't happening.
136 PRPackedBool mNoHRefURI;
140 // -------------------------------------------------------------------------
141 // Linear Gradients
142 // -------------------------------------------------------------------------
144 typedef nsSVGGradientFrame nsSVGLinearGradientFrameBase;
146 class nsSVGLinearGradientFrame : public nsSVGLinearGradientFrameBase
148 friend nsIFrame* NS_NewSVGLinearGradientFrame(nsIPresShell* aPresShell,
149 nsIContent* aContent,
150 nsStyleContext* aContext);
151 protected:
152 nsSVGLinearGradientFrame(nsStyleContext* aContext) :
153 nsSVGLinearGradientFrameBase(aContext) {}
155 public:
156 // nsIFrame interface:
157 virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgLinearGradientFrame
159 NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
160 nsIAtom* aAttribute,
161 PRInt32 aModType);
163 #ifdef DEBUG
164 // nsIFrameDebug interface:
165 NS_IMETHOD GetFrameName(nsAString& aResult) const
167 return MakeFrameName(NS_LITERAL_STRING("SVGLinearGradient"), aResult);
169 #endif // DEBUG
171 protected:
172 float GradientLookupAttribute(nsIAtom *aAtomName, PRUint16 aEnumName);
173 virtual already_AddRefed<gfxPattern> CreateGradient();
176 // -------------------------------------------------------------------------
177 // Radial Gradients
178 // -------------------------------------------------------------------------
180 typedef nsSVGGradientFrame nsSVGRadialGradientFrameBase;
182 class nsSVGRadialGradientFrame : public nsSVGRadialGradientFrameBase
184 friend nsIFrame* NS_NewSVGRadialGradientFrame(nsIPresShell* aPresShell,
185 nsIContent* aContent,
186 nsStyleContext* aContext);
187 protected:
188 nsSVGRadialGradientFrame(nsStyleContext* aContext) :
189 nsSVGRadialGradientFrameBase(aContext) {}
191 public:
192 // nsIFrame interface:
193 virtual nsIAtom* GetType() const; // frame type: nsGkAtoms::svgRadialGradientFrame
195 NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
196 nsIAtom* aAttribute,
197 PRInt32 aModType);
199 #ifdef DEBUG
200 // nsIFrameDebug interface:
201 NS_IMETHOD GetFrameName(nsAString& aResult) const
203 return MakeFrameName(NS_LITERAL_STRING("SVGRadialGradient"), aResult);
205 #endif // DEBUG
207 protected:
208 float GradientLookupAttribute(nsIAtom *aAtomName, PRUint16 aEnumName,
209 nsSVGRadialGradientElement *aElement = nsnull);
210 virtual already_AddRefed<gfxPattern> CreateGradient();
213 #endif // __NS_SVGGRADIENTFRAME_H__