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
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is the Mozilla SVG project.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Scooter Morris.
19 : * Portions created by the Initial Developer are Copyright (C) 2005
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Scooter Morris <scootermorris@comcast.net>
24 : *
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.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef __NS_SVGPATTERNFRAME_H__
40 : #define __NS_SVGPATTERNFRAME_H__
41 :
42 : #include "nsSVGPaintServerFrame.h"
43 : #include "gfxMatrix.h"
44 : #include "nsIDOMSVGAnimTransformList.h"
45 :
46 : class nsIFrame;
47 : class nsSVGLength2;
48 : class nsSVGElement;
49 : class gfxContext;
50 : class gfxASurface;
51 :
52 : namespace mozilla {
53 : class SVGAnimatedPreserveAspectRatio;
54 : class SVGAnimatedTransformList;
55 : } // namespace mozilla
56 :
57 : typedef nsSVGPaintServerFrame nsSVGPatternFrameBase;
58 :
59 : /**
60 : * Patterns can refer to other patterns. We create an nsSVGPaintingProperty
61 : * with property type nsGkAtoms::href to track the referenced pattern.
62 : */
63 : class nsSVGPatternFrame : public nsSVGPatternFrameBase
64 0 : {
65 : public:
66 : NS_DECL_FRAMEARENA_HELPERS
67 :
68 : friend nsIFrame* NS_NewSVGPatternFrame(nsIPresShell* aPresShell,
69 : nsStyleContext* aContext);
70 :
71 : nsSVGPatternFrame(nsStyleContext* aContext);
72 :
73 : // nsSVGPaintServerFrame methods:
74 : virtual already_AddRefed<gfxPattern>
75 : GetPaintServerPattern(nsIFrame *aSource,
76 : float aOpacity,
77 : const gfxRect *aOverrideBounds);
78 :
79 : public:
80 : typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
81 :
82 : // nsSVGContainerFrame methods:
83 : virtual gfxMatrix GetCanvasTM();
84 :
85 : // nsIFrame interface:
86 : virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext);
87 :
88 : NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
89 : nsIAtom* aAttribute,
90 : PRInt32 aModType);
91 :
92 : #ifdef DEBUG
93 : NS_IMETHOD Init(nsIContent* aContent,
94 : nsIFrame* aParent,
95 : nsIFrame* aPrevInFlow);
96 : #endif
97 :
98 : /**
99 : * Get the "type" of the frame
100 : *
101 : * @see nsGkAtoms::svgPatternFrame
102 : */
103 : virtual nsIAtom* GetType() const;
104 :
105 : #ifdef DEBUG
106 0 : NS_IMETHOD GetFrameName(nsAString& aResult) const
107 : {
108 0 : return MakeFrameName(NS_LITERAL_STRING("SVGPattern"), aResult);
109 : }
110 : #endif // DEBUG
111 :
112 : protected:
113 : // Internal methods for handling referenced patterns
114 : class AutoPatternReferencer;
115 : nsSVGPatternFrame* GetReferencedPattern();
116 : nsSVGPatternFrame* GetReferencedPatternIfNotInUse();
117 :
118 : // Accessors to lookup pattern attributes
119 : PRUint16 GetEnumValue(PRUint32 aIndex, nsIContent *aDefault);
120 0 : PRUint16 GetEnumValue(PRUint32 aIndex)
121 : {
122 0 : return GetEnumValue(aIndex, mContent);
123 : }
124 : mozilla::SVGAnimatedTransformList* GetPatternTransformList(
125 : nsIContent* aDefault);
126 : gfxMatrix GetPatternTransform();
127 : const nsSVGViewBox &GetViewBox(nsIContent *aDefault);
128 0 : const nsSVGViewBox &GetViewBox() { return GetViewBox(mContent); }
129 : const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio(
130 : nsIContent *aDefault);
131 0 : const SVGAnimatedPreserveAspectRatio &GetPreserveAspectRatio()
132 : {
133 0 : return GetPreserveAspectRatio(mContent);
134 : }
135 : const nsSVGLength2 *GetLengthValue(PRUint32 aIndex, nsIContent *aDefault);
136 0 : const nsSVGLength2 *GetLengthValue(PRUint32 aIndex)
137 : {
138 0 : return GetLengthValue(aIndex, mContent);
139 : }
140 :
141 : nsresult PaintPattern(gfxASurface **surface,
142 : gfxMatrix *patternMatrix,
143 : nsIFrame *aSource,
144 : float aGraphicOpacity,
145 : const gfxRect *aOverrideBounds);
146 : nsIFrame* GetPatternFirstChild();
147 : gfxRect GetPatternRect(const gfxRect &bbox,
148 : const gfxMatrix &callerCTM,
149 : nsIFrame *aTarget);
150 : gfxMatrix GetPatternMatrix(const gfxMatrix &patternTransform,
151 : const gfxRect &bbox,
152 : const gfxRect &callerBBox,
153 : const gfxMatrix &callerCTM);
154 : gfxMatrix ConstructCTM(const gfxRect &callerBBox,
155 : const gfxMatrix &callerCTM,
156 : nsIFrame *aTarget);
157 : nsresult GetTargetGeometry(gfxMatrix *aCTM,
158 : gfxRect *aBBox,
159 : nsIFrame *aTarget,
160 : const gfxRect *aOverrideBounds);
161 :
162 : private:
163 : // this is a *temporary* reference to the frame of the element currently
164 : // referencing our pattern. This must be temporary because different
165 : // referencing frames will all reference this one frame
166 : nsSVGGeometryFrame *mSource;
167 : nsAutoPtr<gfxMatrix> mCTM;
168 :
169 : protected:
170 : // This flag is used to detect loops in xlink:href processing
171 : bool mLoopFlag;
172 : bool mNoHRefURI;
173 : };
174 :
175 : #endif
|