Back to index

lightning-sunbird  0.9+nobinonly
nsSVGElement.h
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) 2001
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 #ifndef __NS_SVGELEMENT_H__
00040 #define __NS_SVGELEMENT_H__
00041 
00042 /*
00043   nsSVGElement is the base class for all SVG content elements.
00044   It implements all the common DOM interfaces and handles attributes.
00045 */
00046 
00047 #include "nsString.h"
00048 #include "nsCOMPtr.h"
00049 #include "nsIDOMSVGElement.h"
00050 #include "nsGenericElement.h"
00051 #include "nsISVGValue.h"
00052 #include "nsISVGValueObserver.h"
00053 #include "nsWeakReference.h"
00054 #include "nsISVGContent.h"
00055 #include "nsICSSStyleRule.h"
00056 
00057 class nsSVGElement : public nsGenericElement,    // :nsIXMLContent:nsIStyledContent:nsIContent
00058                      public nsISVGValueObserver, 
00059                      public nsSupportsWeakReference, // :nsISupportsWeakReference
00060                      public nsISVGContent
00061 {
00062 protected:
00063   nsSVGElement(nsINodeInfo *aNodeInfo);
00064   virtual ~nsSVGElement();
00065 
00066 public:
00067   // nsISupports
00068   NS_DECL_ISUPPORTS_INHERITED
00069 
00070   // nsIContent interface methods
00071 
00072   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
00073                               nsIContent* aBindingParent,
00074                               PRBool aCompileEventHandlers);
00075   virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
00076                               PRBool aNullParent = PR_TRUE);
00077   virtual nsIAtom *GetIDAttributeName() const;
00078   virtual nsIAtom *GetClassAttributeName() const;
00079   nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00080                    const nsAString& aValue, PRBool aNotify)
00081   {
00082     return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
00083   }
00084   virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00085                            nsIAtom* aPrefix, const nsAString& aValue,
00086                            PRBool aNotify);
00087   virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
00088                              PRBool aNotify);
00089   
00090   virtual PRBool IsContentOfType(PRUint32 aFlags) const;
00091   
00092   NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
00093   NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify);
00094   virtual nsICSSStyleRule* GetInlineStyleRule();
00095 
00096   static const MappedAttributeEntry sFillStrokeMap[];
00097   static const MappedAttributeEntry sGraphicsMap[];
00098   static const MappedAttributeEntry sTextContentElementsMap[];
00099   static const MappedAttributeEntry sFontSpecificationMap[];
00100   static const MappedAttributeEntry sGradientStopMap[];
00101   static const MappedAttributeEntry sViewportsMap[];
00102   static const MappedAttributeEntry sMarkersMap[];
00103   static const MappedAttributeEntry sColorMap[];
00104   
00105   // nsIDOMNode
00106   NS_IMETHOD IsSupported(const nsAString& aFeature, const nsAString& aVersion, PRBool* aReturn);
00107   
00108   // nsIDOMSVGElement
00109   NS_IMETHOD GetId(nsAString & aId);
00110   NS_IMETHOD SetId(const nsAString & aId);
00111   NS_IMETHOD GetOwnerSVGElement(nsIDOMSVGSVGElement** aOwnerSVGElement);
00112   NS_IMETHOD GetViewportElement(nsIDOMSVGElement** aViewportElement);
00113 
00114   // nsISVGValueObserver
00115   NS_IMETHOD WillModifySVGObservable(nsISVGValue* observable,
00116                                      nsISVGValue::modificationType aModType);
00117   NS_IMETHOD DidModifySVGObservable (nsISVGValue* observable,
00118                                      nsISVGValue::modificationType aModType);
00119 
00120   // nsISupportsWeakReference
00121   // implementation inherited from nsSupportsWeakReference
00122 
00123   // nsISVGContent
00124   virtual void ParentChainChanged(); 
00125   
00126 protected:
00127   // Hooks for subclasses
00128   virtual PRBool IsEventName(nsIAtom* aName);
00129 
00145   nsresult SetAttrAndNotify(PRInt32 aNamespaceID,
00146                             nsIAtom* aAttribute,
00147                             nsIAtom* aPrefix,
00148                             const nsAString& aOldValue,
00149                             nsAttrValue& aParsedValue,
00150                             PRBool aModification,
00151                             PRBool aFireMutation,
00152                             PRBool aNotify);
00153 
00154   void UpdateContentStyleRule();
00155   nsISVGValue* GetMappedAttribute(PRInt32 aNamespaceID, nsIAtom* aName);
00156   nsresult AddMappedSVGValue(nsIAtom* aName, nsISupports* aValue,
00157                              PRInt32 aNamespaceID = kNameSpaceID_None);
00158   
00159   static PRBool IsGraphicElementEventName(nsIAtom* aName);
00160   static nsIAtom* GetEventNameForAttr(nsIAtom* aAttr);
00161 
00162   nsCOMPtr<nsICSSStyleRule> mContentStyleRule;
00163   nsAttrAndChildArray mMappedAttributes;
00164 };
00165 
00169 #define NS_IMPL_NS_NEW_SVG_ELEMENT(_elementName)                             \
00170 nsresult                                                                     \
00171 NS_NewSVG##_elementName##Element(nsIContent **aResult,                       \
00172                                  nsINodeInfo *aNodeInfo)                     \
00173 {                                                                            \
00174   nsSVG##_elementName##Element *it =                                         \
00175     new nsSVG##_elementName##Element(aNodeInfo);                             \
00176   if (!it)                                                                   \
00177     return NS_ERROR_OUT_OF_MEMORY;                                           \
00178                                                                              \
00179   NS_ADDREF(it);                                                             \
00180                                                                              \
00181   nsresult rv = it->Init();                                                  \
00182                                                                              \
00183   if (NS_FAILED(rv)) {                                                       \
00184     NS_RELEASE(it);                                                          \
00185     return rv;                                                               \
00186   }                                                                          \
00187                                                                              \
00188   *aResult = it;                                                             \
00189                                                                              \
00190   return rv;                                                                 \
00191 }
00192 
00193 
00194 #endif // __NS_SVGELEMENT_H__