Back to index

lightning-sunbird  0.9+nobinonly
nsSVGTextPathElement.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Mozilla SVG project.
00016  *
00017  * The Initial Developer of the Original Code is IBM Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2005
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsSVGStylableElement.h"
00039 #include "nsSVGAtoms.h"
00040 #include "nsIDOMSVGTextPathElement.h"
00041 #include "nsSVGLength.h"
00042 #include "nsIDOMSVGURIReference.h"
00043 #include "nsSVGAnimatedLength.h"
00044 #include "nsSVGAnimatedString.h"
00045 #include "nsSVGAnimatedEnumeration.h"
00046 #include "nsSVGEnum.h"
00047 
00048 typedef nsSVGStylableElement nsSVGTextPathElementBase;
00049 
00050 class nsSVGTextPathElement : public nsSVGTextPathElementBase,
00051                              public nsIDOMSVGTextPathElement,
00052                              public nsIDOMSVGURIReference
00053 {
00054 protected:
00055   friend nsresult NS_NewSVGTextPathElement(nsIContent **aResult,
00056                                         nsINodeInfo *aNodeInfo);
00057   nsSVGTextPathElement(nsINodeInfo* aNodeInfo);
00058   virtual ~nsSVGTextPathElement();
00059   nsresult Init();
00060   
00061 public:
00062   // interfaces:
00063   
00064   NS_DECL_ISUPPORTS_INHERITED
00065   NS_DECL_NSIDOMSVGTEXTPATHELEMENT
00066   NS_DECL_NSIDOMSVGTEXTCONTENTELEMENT
00067   NS_DECL_NSIDOMSVGURIREFERENCE
00068 
00069   // xxx If xpcom allowed virtual inheritance we wouldn't need to
00070   // forward here :-(
00071   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGTextPathElementBase::)
00072   NS_FORWARD_NSIDOMELEMENT(nsSVGTextPathElementBase::)
00073   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGTextPathElementBase::)
00074 
00075   // nsIStyledContent interface
00076   NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
00077 
00078 protected:
00079   // nsSVGElement overrides
00080   virtual PRBool IsEventName(nsIAtom* aName);
00081 
00082   nsCOMPtr<nsIDOMSVGAnimatedLength> mStartOffset;
00083   nsCOMPtr<nsIDOMSVGAnimatedEnumeration> mMethod;
00084   nsCOMPtr<nsIDOMSVGAnimatedEnumeration> mSpacing;
00085   nsCOMPtr<nsIDOMSVGAnimatedString> mHref;
00086 };
00087 
00088 
00089 NS_IMPL_NS_NEW_SVG_ELEMENT(TextPath)
00090 
00091 
00092 //----------------------------------------------------------------------
00093 // nsISupports methods
00094 
00095 NS_IMPL_ADDREF_INHERITED(nsSVGTextPathElement,nsSVGTextPathElementBase)
00096 NS_IMPL_RELEASE_INHERITED(nsSVGTextPathElement,nsSVGTextPathElementBase)
00097 
00098 NS_INTERFACE_MAP_BEGIN(nsSVGTextPathElement)
00099   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
00100   NS_INTERFACE_MAP_ENTRY(nsIDOMElement)
00101   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGElement)
00102   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGTextPathElement)
00103   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGTextContentElement)
00104   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGURIReference)
00105   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGTextPathElement)
00106 NS_INTERFACE_MAP_END_INHERITING(nsSVGTextPathElementBase)
00107 
00108 //----------------------------------------------------------------------
00109 // Implementation
00110 
00111 nsSVGTextPathElement::nsSVGTextPathElement(nsINodeInfo *aNodeInfo)
00112   : nsSVGTextPathElementBase(aNodeInfo)
00113 {
00114 
00115 }
00116 
00117 nsSVGTextPathElement::~nsSVGTextPathElement()
00118 {
00119 }
00120 
00121   
00122 nsresult
00123 nsSVGTextPathElement::Init()
00124 {
00125   nsresult rv = nsSVGTextPathElementBase::Init();
00126   NS_ENSURE_SUCCESS(rv,rv);
00127 
00128   // enumeration mappings
00129   static struct nsSVGEnumMapping methodMap[] = {
00130     {&nsSVGAtoms::align, TEXTPATH_METHODTYPE_ALIGN},
00131     {&nsSVGAtoms::stretch, TEXTPATH_METHODTYPE_STRETCH},
00132     {nsnull, 0}
00133   };
00134   
00135   static struct nsSVGEnumMapping spacingMap[] = {
00136     {&nsSVGAtoms::_auto, TEXTPATH_SPACINGTYPE_AUTO},
00137     {&nsSVGAtoms::exact, TEXTPATH_SPACINGTYPE_EXACT},
00138     {nsnull, 0}
00139   };
00140 
00141   // Create mapped properties:
00142 
00143   // DOM property: nsIDOMSVGTextPathElement::startOffset, #IMPLIED attrib: startOffset
00144   {
00145     nsCOMPtr<nsISVGLength> length;
00146     rv = NS_NewSVGLength(getter_AddRefs(length), 0.0f);
00147     NS_ENSURE_SUCCESS(rv,rv);
00148     rv = NS_NewSVGAnimatedLength(getter_AddRefs(mStartOffset), length);
00149     NS_ENSURE_SUCCESS(rv,rv);
00150     rv = AddMappedSVGValue(nsSVGAtoms::startOffset, mStartOffset);
00151     NS_ENSURE_SUCCESS(rv,rv);
00152   }
00153 
00154   // DOM property: method, #IMPLIED attrib: method
00155   {
00156     nsCOMPtr<nsISVGEnum> units;
00157     rv = NS_NewSVGEnum(getter_AddRefs(units), TEXTPATH_METHODTYPE_ALIGN,
00158                        methodMap);
00159     NS_ENSURE_SUCCESS(rv,rv);
00160     rv = NS_NewSVGAnimatedEnumeration(getter_AddRefs(mMethod), units);
00161     NS_ENSURE_SUCCESS(rv,rv);
00162     rv = AddMappedSVGValue(nsSVGAtoms::method, mMethod);
00163     NS_ENSURE_SUCCESS(rv,rv);
00164   }
00165 
00166   // DOM property: spacing, #IMPLIED attrib: spacing
00167   {
00168     nsCOMPtr<nsISVGEnum> units;
00169     rv = NS_NewSVGEnum(getter_AddRefs(units), TEXTPATH_SPACINGTYPE_EXACT,
00170                        spacingMap);
00171     NS_ENSURE_SUCCESS(rv,rv);
00172     rv = NS_NewSVGAnimatedEnumeration(getter_AddRefs(mSpacing), units);
00173     NS_ENSURE_SUCCESS(rv,rv);
00174     rv = AddMappedSVGValue(nsSVGAtoms::spacing, mSpacing);
00175     NS_ENSURE_SUCCESS(rv,rv);
00176   }
00177 
00178   // nsIDOMSVGURIReference properties
00179 
00180   // DOM property: href , #REQUIRED attrib: xlink:href
00181   // XXX: enforce requiredness
00182   {
00183     rv = NS_NewSVGAnimatedString(getter_AddRefs(mHref));
00184     NS_ENSURE_SUCCESS(rv,rv);
00185     rv = AddMappedSVGValue(nsSVGAtoms::href, mHref, kNameSpaceID_XLink);
00186     NS_ENSURE_SUCCESS(rv,rv);
00187   }
00188   
00189   return rv;
00190 }
00191 
00192 //----------------------------------------------------------------------
00193 // nsIDOMNode methods
00194 
00195 NS_IMPL_DOM_CLONENODE_WITH_INIT(nsSVGTextPathElement)
00196 
00197 //----------------------------------------------------------------------
00198 // nsIDOMSVGURIReference methods
00199 
00200 /* readonly attribute nsIDOMSVGAnimatedString href; */
00201 NS_IMETHODIMP nsSVGTextPathElement::GetHref(nsIDOMSVGAnimatedString * *aHref)
00202 {
00203   *aHref = mHref;
00204   NS_IF_ADDREF(*aHref);
00205   return NS_OK;
00206 }
00207 
00208 //----------------------------------------------------------------------
00209 // nsIDOMSVGTextPathElement methods
00210 
00211 NS_IMETHODIMP nsSVGTextPathElement::GetStartOffset(nsIDOMSVGAnimatedLength * *aStartOffset)
00212 {
00213   *aStartOffset = mStartOffset;
00214   NS_IF_ADDREF(*aStartOffset);
00215   return NS_OK;
00216 }
00217 
00218 /* readonly attribute nsIDOMSVGAnimatedEnumeration method; */
00219 NS_IMETHODIMP nsSVGTextPathElement::GetMethod(nsIDOMSVGAnimatedEnumeration * *aMethod)
00220 {
00221   *aMethod = mMethod;
00222   NS_IF_ADDREF(*aMethod);
00223   return NS_OK;
00224 }
00225 
00226 /* readonly attribute nsIDOMSVGAnimatedEnumeration spacing; */
00227 NS_IMETHODIMP nsSVGTextPathElement::GetSpacing(nsIDOMSVGAnimatedEnumeration * *aSpacing)
00228 {
00229   *aSpacing = mSpacing;
00230   NS_IF_ADDREF(*aSpacing);
00231   return NS_OK;
00232 }
00233 
00234 //----------------------------------------------------------------------
00235 // nsIDOMSVGTextContentElement methods
00236 
00237 /* readonly attribute nsIDOMSVGAnimatedLength textLength; */
00238 NS_IMETHODIMP nsSVGTextPathElement::GetTextLength(nsIDOMSVGAnimatedLength * *aTextLength)
00239 {
00240   NS_NOTYETIMPLEMENTED("write me!");
00241   return NS_ERROR_UNEXPECTED;
00242 }
00243 
00244 /* readonly attribute nsIDOMSVGAnimatedEnumeration lengthAdjust; */
00245 NS_IMETHODIMP nsSVGTextPathElement::GetLengthAdjust(nsIDOMSVGAnimatedEnumeration * *aLengthAdjust)
00246 {
00247   NS_NOTYETIMPLEMENTED("write me!");
00248   return NS_ERROR_UNEXPECTED;
00249 }
00250 
00251 /* long getNumberOfChars (); */
00252 NS_IMETHODIMP nsSVGTextPathElement::GetNumberOfChars(PRInt32 *_retval)
00253 {
00254   NS_NOTYETIMPLEMENTED("write me!");
00255   return NS_ERROR_UNEXPECTED;
00256 }
00257 
00258 /* float getComputedTextLength (); */
00259 NS_IMETHODIMP nsSVGTextPathElement::GetComputedTextLength(float *_retval)
00260 {
00261   NS_NOTYETIMPLEMENTED("write me!");
00262   return NS_ERROR_UNEXPECTED;
00263 }
00264 
00265 /* float getSubStringLength (in unsigned long charnum, in unsigned long nchars); */
00266 NS_IMETHODIMP nsSVGTextPathElement::GetSubStringLength(PRUint32 charnum, PRUint32 nchars, float *_retval)
00267 {
00268   NS_NOTYETIMPLEMENTED("write me!");
00269   return NS_ERROR_UNEXPECTED;
00270 }
00271 
00272 /* nsIDOMSVGPoint getStartPositionOfChar (in unsigned long charnum); */
00273 NS_IMETHODIMP nsSVGTextPathElement::GetStartPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
00274 {
00275   NS_NOTYETIMPLEMENTED("write me!");
00276   return NS_ERROR_UNEXPECTED;
00277 }
00278 
00279 /* nsIDOMSVGPoint getEndPositionOfChar (in unsigned long charnum); */
00280 NS_IMETHODIMP nsSVGTextPathElement::GetEndPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
00281 {
00282   NS_NOTYETIMPLEMENTED("write me!");
00283   return NS_ERROR_UNEXPECTED;
00284 }
00285 
00286 /* nsIDOMSVGRect getExtentOfChar (in unsigned long charnum); */
00287 NS_IMETHODIMP nsSVGTextPathElement::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)
00288 {
00289   NS_NOTYETIMPLEMENTED("write me!");
00290   return NS_ERROR_UNEXPECTED;
00291 }
00292 
00293 /* float getRotationOfChar (in unsigned long charnum); */
00294 NS_IMETHODIMP nsSVGTextPathElement::GetRotationOfChar(PRUint32 charnum, float *_retval)
00295 {
00296   NS_NOTYETIMPLEMENTED("write me!");
00297   return NS_ERROR_UNEXPECTED;
00298 }
00299 
00300 /* long getCharNumAtPosition (in nsIDOMSVGPoint point); */
00301 NS_IMETHODIMP nsSVGTextPathElement::GetCharNumAtPosition(nsIDOMSVGPoint *point,
00302                                                       PRInt32 *_retval)
00303 {
00304   // null check when implementing - this method can be used by scripts!
00305   // if (!point)
00306   //   return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
00307 
00308   NS_NOTYETIMPLEMENTED("write me!");
00309   return NS_ERROR_UNEXPECTED;
00310 }
00311 
00312 /* void selectSubString (in unsigned long charnum, in unsigned long nchars); */
00313 NS_IMETHODIMP nsSVGTextPathElement::SelectSubString(PRUint32 charnum, PRUint32 nchars)
00314 {
00315   NS_NOTYETIMPLEMENTED("write me!");
00316   return NS_ERROR_UNEXPECTED;
00317 }
00318 
00319 //----------------------------------------------------------------------
00320 // nsIStyledContent methods
00321 
00322 NS_IMETHODIMP_(PRBool)
00323 nsSVGTextPathElement::IsAttributeMapped(const nsIAtom* name) const
00324 {
00325   static const MappedAttributeEntry* const map[] = {
00326     sFillStrokeMap,
00327     sGraphicsMap,
00328     sTextContentElementsMap,
00329     sFontSpecificationMap
00330   };
00331   
00332   return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
00333     nsSVGTextPathElementBase::IsAttributeMapped(name);
00334 }
00335 
00336 //----------------------------------------------------------------------
00337 // nsSVGElement overrides
00338 
00339 PRBool
00340 nsSVGTextPathElement::IsEventName(nsIAtom* aName)
00341 {
00342   return IsGraphicElementEventName(aName);
00343 }