Back to index

lightning-sunbird  0.9+nobinonly
nsXTFElementWrapper.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 XTF project.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Alex Fritze.
00019  * Portions created by the Initial Developer are Copyright (C) 2004
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Alex Fritze <alex@croczilla.com> (original author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * 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_XTFELEMENTWRAPPER_H__
00040 #define __NS_XTFELEMENTWRAPPER_H__
00041 
00042 #include "nsIXTFElementWrapper.h"
00043 #include "nsIXTFElementWrapperPrivate.h"
00044 #include "nsXMLElement.h"
00045 #include "nsIXTFAttributeHandler.h"
00046 #include "nsIXTFElement.h"
00047 #include "nsIXTFStyledElementWrapper.h"
00048 
00049 typedef nsXMLElement nsXTFElementWrapperBase;
00050 
00051 // Pseudo IID for nsXTFElementWrapper
00052 // {599EB85F-ABC0-4B52-A1B0-EA103D48E3AE}
00053 #define NS_XTFELEMENTWRAPPER_IID \
00054 { 0x599eb85f, 0xabc0, 0x4b52, { 0xa1, 0xb0, 0xea, 0x10, 0x3d, 0x48, 0xe3, 0xae } }
00055 
00056 
00057 class nsXTFElementWrapper : public nsXTFElementWrapperBase,
00058                             public nsIXTFElementWrapper,
00059                             public nsIXTFElementWrapperPrivate,
00060                             public nsIClassInfo
00061 {
00062 protected:
00063   nsXTFElementWrapper(nsINodeInfo* aNodeInfo);
00064   nsresult Init();
00065   
00066 public:
00067   NS_DEFINE_STATIC_IID_ACCESSOR(NS_XTFELEMENTWRAPPER_IID)
00068 
00069   // nsISupports interface
00070   NS_DECL_ISUPPORTS_INHERITED
00071 
00072   // nsIXTFElementWrapper
00073   NS_DECL_NSIXTFELEMENTWRAPPER
00074 
00075   // nsIXTFElementWrapperPrivate
00076   // to be implemented by subclass
00077   // virtual PRUint32 GetElementType() = 0;
00078     
00079   // nsIContent specializations:
00080   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
00081                               nsIContent* aBindingParent,
00082                               PRBool aCompileEventHandlers);
00083   virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
00084                               PRBool aNullParent = PR_TRUE);
00085   nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
00086                          PRBool aNotify);
00087   nsresult AppendChildTo(nsIContent* aKid, PRBool aNotify);
00088   nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify);
00089   nsIAtom *GetIDAttributeName() const;
00090   nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
00091                    nsIAtom* aPrefix, const nsAString& aValue,
00092                    PRBool aNotify);
00093   nsresult GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, 
00094                    nsAString& aResult) const;
00095   PRBool HasAttr(PRInt32 aNameSpaceID, nsIAtom* aName) const;
00096   nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr, 
00097                      PRBool aNotify);
00098   nsresult GetAttrNameAt(PRUint32 aIndex, PRInt32* aNameSpaceID,
00099                          nsIAtom** aName, nsIAtom** aPrefix) const;
00100   PRUint32 GetAttrCount() const;
00101   virtual already_AddRefed<nsINodeInfo> GetExistingAttrNameFromQName(const nsAString& aStr) const;
00102 
00103   virtual PRInt32 IntrinsicState() const;
00104 
00105   virtual void BeginAddingChildren();
00106   virtual void DoneAddingChildren();
00107   
00108   // nsIDOMNode specializations:
00109   NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode **aResult);
00110   
00111   // nsIDOMElement specializations:
00112   NS_IMETHOD GetAttribute(const nsAString& aName,
00113                           nsAString& aReturn);
00114   NS_IMETHOD RemoveAttribute(const nsAString& aName);
00115   NS_IMETHOD HasAttribute(const nsAString& aName, PRBool* aReturn);
00116   
00117   // nsIClassInfo interface
00118   NS_DECL_NSICLASSINFO
00119   
00120   virtual nsresult HandleDOMEvent(nsPresContext* aPresContext,
00121                                   nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
00122                                   PRUint32 aFlags,
00123                                   nsEventStatus* aEventStatus);
00124 
00125   nsresult CloneState(nsIDOMElement *aElement)
00126   {
00127     return GetXTFElement()->CloneState(aElement);
00128   }
00129 
00130 protected:
00131   // to be implemented by subclasses:
00132   virtual nsIXTFElement *GetXTFElement() const = 0;
00133   
00134   // implementation helpers:  
00135   PRBool QueryInterfaceInner(REFNSIID aIID, void** result);
00136 
00137   PRBool HandledByInner(nsIAtom* attr) const;
00138   
00139   PRUint32 mNotificationMask;
00140   nsCOMPtr<nsIXTFAttributeHandler> mAttributeHandler;
00141 
00142   /*
00143    * The intrinsic state of the element.
00144    * @see nsIContent::IntrinsicState()
00145    */
00146   PRInt32 mIntrinsicState;
00147 };
00148 
00149 class nsXTFStyledElementWrapper : public nsXTFElementWrapper
00150 {
00151 public:
00152   nsXTFStyledElementWrapper(nsINodeInfo* aNodeInfo);
00153 
00154   // for nsIStyledContent
00155   virtual nsIAtom *GetClassAttributeName() const;
00156   virtual const nsAttrValue* GetClasses() const;
00157   NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const;
00158   
00159   nsresult SetClassAttributeName(nsIAtom* aName);
00160 protected:
00161   nsCOMPtr<nsIAtom> mClassAttributeName;
00162 };
00163 
00164 #endif // __NS_XTFELEMENTWRAPPER_H__