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 IBM Corporation.
18 : * Portions created by the Initial Developer are Copyright (C) 2004
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either of the GNU General Public License Version 2 or later (the "GPL"),
25 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 : * in which case the provisions of the GPL or the LGPL are applicable instead
27 : * of those above. If you wish to allow use of your version of this file only
28 : * under the terms of either the GPL or the LGPL, and not to allow others to
29 : * use your version of this file under the terms of the MPL, indicate your
30 : * decision by deleting the provisions above and replace them with the notice
31 : * and other provisions required by the GPL or the LGPL. If you do not delete
32 : * the provisions above, a recipient may use your version of this file under
33 : * the terms of any one of the MPL, the GPL or the LGPL.
34 : *
35 : * ***** END LICENSE BLOCK ***** */
36 :
37 : #ifndef __NS_SVGMARKERELEMENT_H__
38 : #define __NS_SVGMARKERELEMENT_H__
39 :
40 : #include "gfxMatrix.h"
41 : #include "nsIDOMSVGFitToViewBox.h"
42 : #include "nsIDOMSVGMarkerElement.h"
43 : #include "nsSVGAngle.h"
44 : #include "nsSVGEnum.h"
45 : #include "nsSVGGraphicElement.h"
46 : #include "nsSVGLength2.h"
47 : #include "nsSVGViewBox.h"
48 : #include "SVGAnimatedPreserveAspectRatio.h"
49 :
50 : class nsSVGOrientType
51 : {
52 : public:
53 0 : nsSVGOrientType()
54 : : mAnimVal(nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE),
55 0 : mBaseVal(nsIDOMSVGMarkerElement::SVG_MARKER_ORIENT_ANGLE) {}
56 :
57 : nsresult SetBaseValue(PRUint16 aValue,
58 : nsSVGElement *aSVGElement);
59 :
60 : // XXX FIXME like https://bugzilla.mozilla.org/show_bug.cgi?id=545550 but
61 : // without adding an mIsAnimated member...?
62 0 : void SetBaseValue(PRUint16 aValue)
63 0 : { mAnimVal = mBaseVal = PRUint8(aValue); }
64 : // no need to notify, since nsSVGAngle does that
65 0 : void SetAnimValue(PRUint16 aValue)
66 0 : { mAnimVal = PRUint8(aValue); }
67 :
68 0 : PRUint16 GetBaseValue() const
69 0 : { return mBaseVal; }
70 0 : PRUint16 GetAnimValue() const
71 0 : { return mAnimVal; }
72 :
73 : nsresult ToDOMAnimatedEnum(nsIDOMSVGAnimatedEnumeration **aResult,
74 : nsSVGElement* aSVGElement);
75 :
76 : private:
77 : nsSVGEnumValue mAnimVal;
78 : nsSVGEnumValue mBaseVal;
79 :
80 : struct DOMAnimatedEnum : public nsIDOMSVGAnimatedEnumeration
81 0 : {
82 0 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
83 1464 : NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimatedEnum)
84 :
85 0 : DOMAnimatedEnum(nsSVGOrientType* aVal,
86 : nsSVGElement *aSVGElement)
87 0 : : mVal(aVal), mSVGElement(aSVGElement) {}
88 :
89 : nsSVGOrientType *mVal; // kept alive because it belongs to content
90 : nsRefPtr<nsSVGElement> mSVGElement;
91 :
92 0 : NS_IMETHOD GetBaseVal(PRUint16* aResult)
93 0 : { *aResult = mVal->GetBaseValue(); return NS_OK; }
94 0 : NS_IMETHOD SetBaseVal(PRUint16 aValue)
95 0 : { return mVal->SetBaseValue(aValue, mSVGElement); }
96 0 : NS_IMETHOD GetAnimVal(PRUint16* aResult)
97 0 : { *aResult = mVal->GetAnimValue(); return NS_OK; }
98 : };
99 : };
100 :
101 : typedef nsSVGGraphicElement nsSVGMarkerElementBase;
102 :
103 : class nsSVGMarkerElement : public nsSVGMarkerElementBase,
104 : public nsIDOMSVGMarkerElement,
105 : public nsIDOMSVGFitToViewBox
106 0 : {
107 : friend class nsSVGMarkerFrame;
108 :
109 : protected:
110 : friend nsresult NS_NewSVGMarkerElement(nsIContent **aResult,
111 : already_AddRefed<nsINodeInfo> aNodeInfo);
112 : nsSVGMarkerElement(already_AddRefed<nsINodeInfo> aNodeInfo);
113 :
114 : public:
115 : typedef mozilla::SVGAnimatedPreserveAspectRatio SVGAnimatedPreserveAspectRatio;
116 :
117 : // interfaces:
118 :
119 : NS_DECL_ISUPPORTS_INHERITED
120 : NS_DECL_NSIDOMSVGMARKERELEMENT
121 : NS_DECL_NSIDOMSVGFITTOVIEWBOX
122 :
123 : // xxx I wish we could use virtual inheritance
124 0 : NS_FORWARD_NSIDOMNODE(nsSVGElement::)
125 0 : NS_FORWARD_NSIDOMELEMENT(nsSVGElement::)
126 0 : NS_FORWARD_NSIDOMSVGELEMENT(nsSVGElement::)
127 :
128 : // nsIContent interface
129 : NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* name) const;
130 :
131 : virtual bool GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
132 : nsAString& aResult) const;
133 : virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
134 : bool aNotify);
135 :
136 : // nsSVGSVGElement methods:
137 : virtual bool HasValidDimensions() const;
138 :
139 : // public helpers
140 : gfxMatrix GetMarkerTransform(float aStrokeWidth,
141 : float aX, float aY, float aAutoAngle);
142 : nsSVGViewBoxRect GetViewBoxRect();
143 : gfxMatrix GetViewBoxTransform();
144 :
145 : virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
146 :
147 0 : nsSVGOrientType* GetOrientType() { return &mOrientType; }
148 :
149 : virtual nsXPCClassInfo* GetClassInfo();
150 : protected:
151 :
152 : virtual bool ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
153 : const nsAString& aValue,
154 : nsAttrValue& aResult);
155 :
156 : void SetParentCoordCtxProvider(nsSVGSVGElement *aContext);
157 :
158 : virtual LengthAttributesInfo GetLengthInfo();
159 : virtual AngleAttributesInfo GetAngleInfo();
160 : virtual EnumAttributesInfo GetEnumInfo();
161 : virtual nsSVGViewBox *GetViewBox();
162 : virtual SVGAnimatedPreserveAspectRatio *GetPreserveAspectRatio();
163 :
164 : enum { REFX, REFY, MARKERWIDTH, MARKERHEIGHT };
165 : nsSVGLength2 mLengthAttributes[4];
166 : static LengthInfo sLengthInfo[4];
167 :
168 : enum { MARKERUNITS };
169 : nsSVGEnum mEnumAttributes[1];
170 : static nsSVGEnumMapping sUnitsMap[];
171 : static EnumInfo sEnumInfo[1];
172 :
173 : enum { ORIENT };
174 : nsSVGAngle mAngleAttributes[1];
175 : static AngleInfo sAngleInfo[1];
176 :
177 : nsSVGViewBox mViewBox;
178 : SVGAnimatedPreserveAspectRatio mPreserveAspectRatio;
179 :
180 : // derived properties (from 'orient') handled separately
181 : nsSVGOrientType mOrientType;
182 :
183 : nsSVGSVGElement *mCoordCtx;
184 : nsAutoPtr<gfxMatrix> mViewBoxToViewportTransform;
185 : };
186 :
187 : #endif
|