Back to index

lightning-sunbird  0.9+nobinonly
nsSVGTSpanElement.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
00018  * Crocodile Clips Ltd..
00019  * Portions created by the Initial Developer are Copyright (C) 2002
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Alex Fritze <alex.fritze@crocodile-clips.com> (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsSVGStylableElement.h"
00040 #include "nsSVGAtoms.h"
00041 #include "nsIDOMSVGTSpanElement.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsSVGAnimatedLengthList.h"
00044 #include "nsSVGLengthList.h"
00045 #include "nsISVGSVGElement.h"
00046 #include "nsSVGCoordCtxProvider.h"
00047 #include "nsIDocument.h"
00048 #include "nsIFrame.h"
00049 #include "nsISVGChildFrame.h"
00050 
00051 typedef nsSVGStylableElement nsSVGTSpanElementBase;
00052 
00053 class nsSVGTSpanElement : public nsSVGTSpanElementBase,
00054                           public nsIDOMSVGTSpanElement // : nsIDOMSVGTextPositioningElement
00055                                                        // : nsIDOMSVGTextContentElement
00056 {
00057 protected:
00058   friend nsresult NS_NewSVGTSpanElement(nsIContent **aResult,
00059                                         nsINodeInfo *aNodeInfo);
00060   nsSVGTSpanElement(nsINodeInfo* aNodeInfo);
00061   virtual ~nsSVGTSpanElement();
00062   nsresult Init();
00063   
00064 public:
00065   // interfaces:
00066   
00067   NS_DECL_ISUPPORTS_INHERITED
00068   NS_DECL_NSIDOMSVGTSPANELEMENT
00069   NS_DECL_NSIDOMSVGTEXTPOSITIONINGELEMENT
00070   NS_DECL_NSIDOMSVGTEXTCONTENTELEMENT
00071 
00072   // xxx If xpcom allowed virtual inheritance we wouldn't need to
00073   // forward here :-(
00074   NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsSVGTSpanElementBase::)
00075   NS_FORWARD_NSIDOMELEMENT(nsSVGTSpanElementBase::)
00076   NS_FORWARD_NSIDOMSVGELEMENT(nsSVGTSpanElementBase::)
00077 
00078   // nsIStyledContent interface
00079   NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
00080 
00081   // nsISVGContent specializations:
00082   virtual void ParentChainChanged();
00083 
00084 protected:
00085   // nsSVGElement overrides
00086   virtual PRBool IsEventName(nsIAtom* aName);
00087 
00088   // nsIDOMSVGTextPositioning properties:
00089   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mX;
00090   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mY;
00091   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mdX;
00092   nsCOMPtr<nsIDOMSVGAnimatedLengthList> mdY;
00093 
00094 };
00095 
00096 
00097 NS_IMPL_NS_NEW_SVG_ELEMENT(TSpan)
00098 
00099 
00100 //----------------------------------------------------------------------
00101 // nsISupports methods
00102 
00103 NS_IMPL_ADDREF_INHERITED(nsSVGTSpanElement,nsSVGTSpanElementBase)
00104 NS_IMPL_RELEASE_INHERITED(nsSVGTSpanElement,nsSVGTSpanElementBase)
00105 
00106 NS_INTERFACE_MAP_BEGIN(nsSVGTSpanElement)
00107   NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
00108   NS_INTERFACE_MAP_ENTRY(nsIDOMElement)
00109   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGElement)
00110   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGTSpanElement)
00111   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGTextPositioningElement)
00112   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGTextContentElement)
00113   NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGTSpanElement)
00114 NS_INTERFACE_MAP_END_INHERITING(nsSVGTSpanElementBase)
00115 
00116 //----------------------------------------------------------------------
00117 // Implementation
00118 
00119 nsSVGTSpanElement::nsSVGTSpanElement(nsINodeInfo *aNodeInfo)
00120   : nsSVGTSpanElementBase(aNodeInfo)
00121 {
00122 
00123 }
00124 
00125 nsSVGTSpanElement::~nsSVGTSpanElement()
00126 {
00127 }
00128 
00129   
00130 nsresult
00131 nsSVGTSpanElement::Init()
00132 {
00133   nsresult rv = nsSVGTSpanElementBase::Init();
00134   NS_ENSURE_SUCCESS(rv,rv);
00135 
00136   // Create mapped properties:
00137 
00138   // DOM property: nsIDOMSVGTextPositioningElement::x, #IMPLIED attrib: x
00139   {
00140     nsCOMPtr<nsISVGLengthList> lengthList;
00141     rv = NS_NewSVGLengthList(getter_AddRefs(lengthList));
00142     NS_ENSURE_SUCCESS(rv,rv);
00143     rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mX),
00144                                      lengthList);
00145     NS_ENSURE_SUCCESS(rv,rv);
00146     rv = AddMappedSVGValue(nsSVGAtoms::x, mX);
00147     NS_ENSURE_SUCCESS(rv,rv);
00148   }
00149   
00150   // DOM property: nsIDOMSVGTextPositioningElement::y, #IMPLIED attrib: y
00151   {
00152     nsCOMPtr<nsISVGLengthList> lengthList;
00153     rv = NS_NewSVGLengthList(getter_AddRefs(lengthList));
00154     NS_ENSURE_SUCCESS(rv,rv);
00155     rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mY),
00156                                      lengthList);
00157     NS_ENSURE_SUCCESS(rv,rv);
00158     rv = AddMappedSVGValue(nsSVGAtoms::y, mY);
00159     NS_ENSURE_SUCCESS(rv,rv);
00160   }
00161 
00162   // DOM property: nsIDOMSVGTextPositioningElement::dx, #IMPLIED attrib: dx
00163   {
00164     nsCOMPtr<nsISVGLengthList> lengthList;
00165     rv = NS_NewSVGLengthList(getter_AddRefs(lengthList));
00166     NS_ENSURE_SUCCESS(rv,rv);
00167     rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mdX),
00168                                      lengthList);
00169     NS_ENSURE_SUCCESS(rv,rv);
00170     rv = AddMappedSVGValue(nsSVGAtoms::dx, mdX);
00171     NS_ENSURE_SUCCESS(rv,rv);
00172   }
00173   
00174   // DOM property: nsIDOMSVGTextPositioningElement::dy, #IMPLIED attrib: dy
00175   {
00176     nsCOMPtr<nsISVGLengthList> lengthList;
00177     rv = NS_NewSVGLengthList(getter_AddRefs(lengthList));
00178     NS_ENSURE_SUCCESS(rv,rv);
00179     rv = NS_NewSVGAnimatedLengthList(getter_AddRefs(mdY),
00180                                      lengthList);
00181     NS_ENSURE_SUCCESS(rv,rv);
00182     rv = AddMappedSVGValue(nsSVGAtoms::dy, mdY);
00183     NS_ENSURE_SUCCESS(rv,rv);
00184   }
00185 
00186   return rv;
00187 }
00188 
00189 //----------------------------------------------------------------------
00190 // nsIDOMNode methods
00191 
00192 
00193 NS_IMPL_DOM_CLONENODE_WITH_INIT(nsSVGTSpanElement)
00194 
00195 
00196 //----------------------------------------------------------------------
00197 // nsIDOMSVGTSpanElement methods
00198 
00199 // - no methods -
00200 
00201 //----------------------------------------------------------------------
00202 // nsIDOMSVGTextPositioningElement methods
00203 
00204 /* readonly attribute nsIDOMSVGAnimatedLengthList x; */
00205 NS_IMETHODIMP nsSVGTSpanElement::GetX(nsIDOMSVGAnimatedLengthList * *aX)
00206 {
00207   *aX = mX;
00208   NS_IF_ADDREF(*aX);
00209   return NS_OK;
00210 }
00211 
00212 /* readonly attribute nsIDOMSVGAnimatedLengthList y; */
00213 NS_IMETHODIMP nsSVGTSpanElement::GetY(nsIDOMSVGAnimatedLengthList * *aY)
00214 {
00215   *aY = mY;
00216   NS_IF_ADDREF(*aY);
00217   return NS_OK;
00218 }
00219 
00220 /* readonly attribute nsIDOMSVGAnimatedLengthList dx; */
00221 NS_IMETHODIMP nsSVGTSpanElement::GetDx(nsIDOMSVGAnimatedLengthList * *aDx)
00222 {
00223   *aDx = mdX;
00224   NS_IF_ADDREF(*aDx);
00225   return NS_OK;
00226 }
00227 
00228 /* readonly attribute nsIDOMSVGAnimatedLengthList dy; */
00229 NS_IMETHODIMP nsSVGTSpanElement::GetDy(nsIDOMSVGAnimatedLengthList * *aDy)
00230 {
00231   *aDy = mdY;
00232   NS_IF_ADDREF(*aDy);
00233   return NS_OK;
00234 }
00235 
00236 /* readonly attribute nsIDOMSVGAnimatedNumberList rotate; */
00237 NS_IMETHODIMP nsSVGTSpanElement::GetRotate(nsIDOMSVGAnimatedNumberList * *aRotate)
00238 {
00239   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::GetRotate");
00240   return NS_ERROR_NOT_IMPLEMENTED;
00241 }
00242 
00243 //----------------------------------------------------------------------
00244 // nsIDOMSVGTextContentElement methods
00245 
00246 /* readonly attribute nsIDOMSVGAnimatedLength textLength; */
00247 NS_IMETHODIMP nsSVGTSpanElement::GetTextLength(nsIDOMSVGAnimatedLength * *aTextLength)
00248 {
00249   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::GetTextLength");
00250   return NS_ERROR_NOT_IMPLEMENTED;
00251 }
00252 
00253 /* readonly attribute nsIDOMSVGAnimatedEnumeration lengthAdjust; */
00254 NS_IMETHODIMP nsSVGTSpanElement::GetLengthAdjust(nsIDOMSVGAnimatedEnumeration * *aLengthAdjust)
00255 {
00256   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::GetLengthAdjust");
00257   return NS_ERROR_NOT_IMPLEMENTED;
00258 }
00259 
00260 /* long getNumberOfChars (); */
00261 NS_IMETHODIMP nsSVGTSpanElement::GetNumberOfChars(PRInt32 *_retval)
00262 {
00263   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::GetNumberOfChars");
00264   return NS_ERROR_NOT_IMPLEMENTED;
00265 }
00266 
00267 /* float getComputedTextLength (); */
00268 NS_IMETHODIMP nsSVGTSpanElement::GetComputedTextLength(float *_retval)
00269 {
00270   nsCOMPtr<nsIDOMSVGRect> bbox;
00271 
00272   nsIDocument* doc = GetCurrentDoc();
00273   if (!doc) return NS_ERROR_FAILURE;
00274   nsIPresShell *presShell = doc->GetShellAt(0);
00275   NS_ASSERTION(presShell, "no presShell");
00276   if (!presShell) return NS_ERROR_FAILURE;
00277 
00278   nsIFrame* frame;
00279   presShell->GetPrimaryFrameFor(NS_STATIC_CAST(nsIStyledContent*, this), &frame);
00280 
00281   NS_ASSERTION(frame, "can't get bounding box for element without frame");
00282 
00283   if (frame) {
00284     nsISVGChildFrame* svgframe;
00285     frame->QueryInterface(NS_GET_IID(nsISVGChildFrame),(void**)&svgframe);
00286     NS_ASSERTION(svgframe, "wrong frame type");
00287     if (svgframe) {
00288       svgframe->SetMatrixPropagation(PR_FALSE);
00289       svgframe->NotifyCanvasTMChanged();
00290       nsresult rv = svgframe->GetBBox(getter_AddRefs(bbox));
00291       svgframe->SetMatrixPropagation(PR_TRUE);
00292       svgframe->NotifyCanvasTMChanged();
00293     }
00294   }
00295 
00296   if (bbox)
00297     bbox->GetWidth(_retval);
00298   else
00299     *_retval = 0;
00300   
00301   return NS_OK;
00302 }
00303 
00304 /* float getSubStringLength (in unsigned long charnum, in unsigned long nchars); */
00305 NS_IMETHODIMP nsSVGTSpanElement::GetSubStringLength(PRUint32 charnum, PRUint32 nchars, float *_retval)
00306 {
00307   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::GetSubStringLength");
00308   return NS_ERROR_NOT_IMPLEMENTED;
00309 }
00310 
00311 /* nsIDOMSVGPoint getStartPositionOfChar (in unsigned long charnum); */
00312 NS_IMETHODIMP nsSVGTSpanElement::GetStartPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
00313 {
00314   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::GetStartPositionOfChar");
00315   return NS_ERROR_NOT_IMPLEMENTED;
00316 }
00317 
00318 /* nsIDOMSVGPoint getEndPositionOfChar (in unsigned long charnum); */
00319 NS_IMETHODIMP nsSVGTSpanElement::GetEndPositionOfChar(PRUint32 charnum, nsIDOMSVGPoint **_retval)
00320 {
00321   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::GetEndPositionOfChar");
00322   return NS_ERROR_NOT_IMPLEMENTED;
00323 }
00324 
00325 /* nsIDOMSVGRect getExtentOfChar (in unsigned long charnum); */
00326 NS_IMETHODIMP nsSVGTSpanElement::GetExtentOfChar(PRUint32 charnum, nsIDOMSVGRect **_retval)
00327 {
00328   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::GetExtentOfChar");
00329   return NS_ERROR_NOT_IMPLEMENTED;
00330 }
00331 
00332 /* float getRotationOfChar (in unsigned long charnum); */
00333 NS_IMETHODIMP nsSVGTSpanElement::GetRotationOfChar(PRUint32 charnum, float *_retval)
00334 {
00335   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::GetRotationOfChar");
00336   return NS_ERROR_NOT_IMPLEMENTED;
00337 }
00338 
00339 /* long getCharNumAtPosition (in nsIDOMSVGPoint point); */
00340 NS_IMETHODIMP nsSVGTSpanElement::GetCharNumAtPosition(nsIDOMSVGPoint *point,
00341                                                       PRInt32 *_retval)
00342 {
00343   // null check when implementing - this method can be used by scripts!
00344   // if (!point)
00345   //   return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;
00346 
00347   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::GetCharNumAtPosition");
00348   return NS_ERROR_NOT_IMPLEMENTED;
00349 }
00350 
00351 /* void selectSubString (in unsigned long charnum, in unsigned long nchars); */
00352 NS_IMETHODIMP nsSVGTSpanElement::SelectSubString(PRUint32 charnum, PRUint32 nchars)
00353 {
00354   NS_NOTYETIMPLEMENTED("nsSVGTSpanElement::SelectSubString");
00355   return NS_ERROR_NOT_IMPLEMENTED;
00356 }
00357 
00358 //----------------------------------------------------------------------
00359 // nsIStyledContent methods
00360 
00361 NS_IMETHODIMP_(PRBool)
00362 nsSVGTSpanElement::IsAttributeMapped(const nsIAtom* name) const
00363 {
00364   static const MappedAttributeEntry* const map[] = {
00365     sFillStrokeMap,
00366     sGraphicsMap,
00367     sTextContentElementsMap,
00368     sFontSpecificationMap
00369   };
00370   
00371   return FindAttributeDependence(name, map, NS_ARRAY_LENGTH(map)) ||
00372     nsSVGTSpanElementBase::IsAttributeMapped(name);
00373 }
00374 
00375 //----------------------------------------------------------------------
00376 // nsISVGContent methods
00377 
00378 void nsSVGTSpanElement::ParentChainChanged()
00379 {
00380   // set new context information on our length-properties:
00381   
00382   nsCOMPtr<nsIDOMSVGSVGElement> dom_elem;
00383   GetOwnerSVGElement(getter_AddRefs(dom_elem));
00384   if (!dom_elem) return;
00385 
00386   nsCOMPtr<nsSVGCoordCtxProvider> ctx = do_QueryInterface(dom_elem);
00387   NS_ASSERTION(ctx, "<svg> element missing interface");
00388 
00389   // x:
00390   {
00391     nsCOMPtr<nsIDOMSVGLengthList> dom_lengthlist;
00392     mX->GetAnimVal(getter_AddRefs(dom_lengthlist));
00393     nsCOMPtr<nsISVGLengthList> lengthlist = do_QueryInterface(dom_lengthlist);
00394     NS_ASSERTION(lengthlist, "svg lengthlist missing interface");
00395 
00396     lengthlist->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextX()));
00397   }
00398 
00399   // y:
00400   {
00401     nsCOMPtr<nsIDOMSVGLengthList> dom_lengthlist;
00402     mY->GetAnimVal(getter_AddRefs(dom_lengthlist));
00403     nsCOMPtr<nsISVGLengthList> lengthlist = do_QueryInterface(dom_lengthlist);
00404     NS_ASSERTION(lengthlist, "svg lengthlist missing interface");
00405     
00406     lengthlist->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextY()));
00407   }
00408 
00409   // dx:
00410   {
00411     nsCOMPtr<nsIDOMSVGLengthList> dom_lengthlist;
00412     mdX->GetAnimVal(getter_AddRefs(dom_lengthlist));
00413     nsCOMPtr<nsISVGLengthList> lengthlist = do_QueryInterface(dom_lengthlist);
00414     NS_ASSERTION(lengthlist, "svg lengthlist missing interface");
00415     
00416     lengthlist->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextX()));
00417   }
00418 
00419   // dy:
00420   {
00421     nsCOMPtr<nsIDOMSVGLengthList> dom_lengthlist;
00422     mdY->GetAnimVal(getter_AddRefs(dom_lengthlist));
00423     nsCOMPtr<nsISVGLengthList> lengthlist = do_QueryInterface(dom_lengthlist);
00424     NS_ASSERTION(lengthlist, "svg lengthlist missing interface");
00425     
00426     lengthlist->SetContext(nsRefPtr<nsSVGCoordCtx>(ctx->GetContextY()));
00427   }
00428 
00429   // recurse into child content:
00430   nsSVGTSpanElementBase::ParentChainChanged();
00431 }  
00432 
00433 //----------------------------------------------------------------------
00434 // nsSVGElement overrides
00435 
00436 PRBool
00437 nsSVGTSpanElement::IsEventName(nsIAtom* aName)
00438 {
00439   return IsGraphicElementEventName(aName);
00440 }