Back to index

lightning-sunbird  0.9+nobinonly
nsDOMAttribute.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 Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
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 #ifndef nsDOMAttribute_h___
00038 #define nsDOMAttribute_h___
00039 
00040 #include "nsIAttribute.h"
00041 #include "nsIDOMAttr.h"
00042 #include "nsIDOMText.h"
00043 #include "nsIDOMNodeList.h"
00044 #include "nsGenericDOMNodeList.h"
00045 #include "nsString.h"
00046 #include "nsCOMPtr.h"
00047 #include "nsINodeInfo.h"
00048 #include "nsIDOM3Node.h"
00049 #include "nsDOMAttributeMap.h"
00050 
00051 class nsDOMAttribute;
00052 
00053 // bogus child list for an attribute
00054 class nsAttributeChildList : public nsGenericDOMNodeList
00055 {
00056 public:
00057   nsAttributeChildList(nsDOMAttribute* aAttribute);
00058   virtual ~nsAttributeChildList();
00059 
00060   // interface nsIDOMNodeList
00061   NS_IMETHOD    GetLength(PRUint32* aLength);
00062   NS_IMETHOD    Item(PRUint32 aIndex, nsIDOMNode** aReturn);
00063 
00064   void DropReference();
00065 
00066 protected:
00067   nsDOMAttribute* mAttribute;
00068 };
00069 
00070 // Attribute helper class used to wrap up an attribute with a dom
00071 // object that implements nsIDOMAttr and nsIDOMNode
00072 class nsDOMAttribute : public nsIDOMAttr,
00073                        public nsIDOM3Node,
00074                        public nsIAttribute,
00075                        public nsIDOMGCParticipant
00076 {
00077 public:
00078   nsDOMAttribute(nsDOMAttributeMap* aAttrMap, nsINodeInfo *aNodeInfo,
00079                  const nsAString& aValue);
00080   virtual ~nsDOMAttribute();
00081 
00082   NS_DECL_ISUPPORTS
00083 
00084   // nsIDOMGCParticipant interface methods
00085   virtual nsIDOMGCParticipant* GetSCCIndex();
00086   virtual void AppendReachableList(nsCOMArray<nsIDOMGCParticipant>& aArray);
00087 
00088   // nsIDOMNode interface
00089   NS_DECL_NSIDOMNODE
00090 
00091   // nsIDOM3Node interface
00092   NS_DECL_NSIDOM3NODE
00093 
00094   // nsIDOMAttr interface
00095   NS_DECL_NSIDOMATTR
00096 
00097   // nsIAttribute interface
00098   void SetMap(nsDOMAttributeMap *aMap);
00099   nsIContent *GetContent() const;
00100 
00101   // Property functions, see nsPropertyTable.h
00102   virtual void* GetProperty(nsIAtom  *aPropertyName,
00103                             nsresult *aStatus = nsnull);
00104   virtual nsresult SetProperty(nsIAtom            *aPropertyName,
00105                                void               *aValue,
00106                                NSPropertyDtorFunc  aDtor);
00107   virtual nsresult DeleteProperty(nsIAtom  *aPropertyName);
00108   virtual void*    UnsetProperty(nsIAtom *aPropertyName,
00109                                  nsresult *aStatus = nsnull);
00110   static void Initialize();
00111   static void Shutdown();
00112 
00113 protected:
00114   static PRBool sInitialized;
00115 
00116 private:
00117   nsString mValue;
00118   // XXX For now, there's only a single child - a text
00119   // element representing the value
00120   nsIDOMText* mChild;
00121   nsAttributeChildList* mChildList;
00122 
00123   nsIContent *GetContentInternal() const
00124   {
00125     return mAttrMap ? mAttrMap->GetContent() : nsnull;
00126   }
00127 };
00128 
00129 
00130 #endif /* nsDOMAttribute_h___ */